org.springframework.data.mongodb.core.query.BasicQuery Java Examples

The following examples show how to use org.springframework.data.mongodb.core.query.BasicQuery. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImportRepositoryCustomImplTest.java    From osiris with Apache License 2.0 6 votes vote down vote up
@Test
public void deleteLockImportProcess() throws Exception{
	
	String idApplication = "1";		
	String strQuery = "{ '_id':'" + idApplication + "'}";
	
	//Fixture		
	PowerMockito.whenNew(BasicQuery.class).withArguments(strQuery).thenReturn(basicQuery);	
	Mockito.when(mongoTemplate.collectionExists(collectionLock)).thenReturn(true);
									
	//Experimentation
	importRepositoryCustom.deleteLockImportProcess(idApplication);
	
	//Expectations
	verify(mongoTemplate).collectionExists(collectionLock);
	verify(mongoTemplate).remove(basicQuery,collectionLock);
	
}
 
Example #2
Source File: ForceFocusCreditCalculator.java    From biliob_backend with MIT License 6 votes vote down vote up
@Override
ResponseEntity execute(Long id, ObjectId objectId) {

    BasicDBObject fieldsObject = new BasicDBObject();
    BasicDBObject dbObject = new BasicDBObject();
    dbObject.put("mid", id);
    fieldsObject.put("forceFocus", true);
    Author author =
            mongoTemplate.findOne(
                    new BasicQuery(dbObject.toJson(), fieldsObject.toJson()), Author.class);
    if (author == null) {
        mongoTemplate.remove(Query.query(Criteria.where("_id").is(objectId)), "user_record");
        return new ResponseEntity<>(new Result<>(ResultEnum.AUTHOR_NOT_FOUND), HttpStatus.ACCEPTED);
    } else if (author.getForceFocus() != null && author.getForceFocus()) {
        mongoTemplate.remove(Query.query(Criteria.where("_id").is(objectId)), "user_record");
        return new ResponseEntity<>(new Result<>(ResultEnum.ALREADY_FORCE_FOCUS), HttpStatus.ACCEPTED);
    }

    mongoTemplate.updateFirst(query(where("mid").is(id)), update("forceFocus", true), Author.class);
    super.setExecuted(objectId);
    upsertAuthorFreq(id, SECOND_OF_MINUTES * 60 * 12);
    return null;
}
 
Example #3
Source File: ProjectionsBenchmark.java    From spring-data-dev-tools with Apache License 2.0 6 votes vote down vote up
@Setup
public void setUp() {

	client = MongoClients.create();
	template = new MongoTemplate(client, DB_NAME);

	source = new Person();
	source.firstname = "luke";
	source.lastname = "skywalker";

	source.address = new Address();
	source.address.street = "melenium falcon 1";
	source.address.city = "deathstar";

	template.save(source, COLLECTION_NAME);

	asPerson = template.query(Person.class).inCollection(COLLECTION_NAME);
	asDtoProjection = template.query(Person.class).inCollection(COLLECTION_NAME).as(DtoProjection.class);
	asClosedProjection = template.query(Person.class).inCollection(COLLECTION_NAME).as(ClosedProjection.class);
	asOpenProjection = template.query(Person.class).inCollection(COLLECTION_NAME).as(OpenProjection.class);

	asPersonWithFieldsRestriction = template.query(Person.class).inCollection(COLLECTION_NAME)
			.matching(new BasicQuery(new Document(), fields));

	mongoCollection = client.getDatabase(DB_NAME).getCollection(COLLECTION_NAME);
}
 
Example #4
Source File: GenericResourceRepositoryImpl.java    From microcks with Apache License 2.0 6 votes vote down vote up
@Override
public List<GenericResource> findByServiceIdAndJSONQuery(String serviceId, String jsonQuery) {
   // First parse query document and prepare a list of key to rename then remove.
   Document query = Document.parse(jsonQuery);
   ArrayList<String> keysToRemove = new ArrayList<>();

   // Collect the keys of document that should be updated.
   for (String key : query.keySet()) {
      keysToRemove.add(key);
   }
   // Prefix all keys by payload. that is the nested document where we put resource in
   // and remove all modified keys.
   for (String keyToRemove : keysToRemove) {
      query.append("payload." + keyToRemove, query.get(keyToRemove));
      query.remove(keyToRemove);
   }

   // Finally, append serviceId criterion before launching selection.
   query.append("serviceId", serviceId);

   return template.find(new BasicQuery(query.toJson()), GenericResource.class);
}
 
Example #5
Source File: MapRepositoryCustomImplTest.java    From osiris with Apache License 2.0 6 votes vote down vote up
@Test
public void findByIDAppAndQueryTest() throws Exception{
	
	String idApplication = "1";  
	String queryJSON = "{ geometry:{ $geoWithin:{ $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	Integer pageIndex=5;
	Integer pageSize= 20;
	int skipElementsValue = pageIndex*pageSize;		 
		
	//Fixture		 	    
    Query querySkip=Mockito.mock(Query.class);
    Query queryLimit=Mockito.mock(Query.class);
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenReturn(basicQuery);				
	Mockito.when(basicQuery.skip(skipElementsValue)).thenReturn(querySkip);
	Mockito.when(querySkip.limit(pageSize)).thenReturn(queryLimit);				
	Mockito.when(mongoTemplate.find(queryLimit, Feature.class, collectionMap+idApplication)).thenReturn(features);
	
	//Experimentation
	Collection<Feature> featuresResponse=mapRepositoryCustomImpl.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize);
	
	//Expectations
	Mockito.verify(mongoTemplate).find(queryLimit, Feature.class, collectionMap+idApplication);
	Assert.assertEquals("Features must be equals", featuresResponse, features);
	
}
 
Example #6
Source File: MapRepositoryCustomImplTest.java    From osiris with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test(expected=QueryException.class)
public void findByIDAppAndQueryErrorQueryTesTest() throws Exception{

	String idApplication = "1";  
	String queryJSON = "{ geometry:{ $geoWithin: $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	Integer pageIndex=5;
	Integer pageSize= 20;		
				
	//Fixture		 	    	    	    	    
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenThrow(Exception.class);						
					 		
	//Experimentation
	mapRepositoryCustomImpl.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize);
	
	//Expectations

}
 
Example #7
Source File: MapRepositoryCustomImplTest.java    From osiris with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test(expected=QueryException.class)
public void findByIDAppAndQueryErrorQueryTesTest() throws Exception{

	String idApplication = "1";  
	String queryJSON = "{ geometry:{ $geoWithin: $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	Integer pageIndex=5;
	Integer pageSize= 20;		
				
	//Fixture		 	    	    	    	    
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenThrow(Exception.class);						
					 		
	//Experimentation
	mapRepositoryCustomImpl.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize);
	
	//Expectations

}
 
Example #8
Source File: MapRepositoryCustomImplTest.java    From osiris with Apache License 2.0 6 votes vote down vote up
@Test
public void findByIDAppAndQueryTest() throws Exception{
	
	String idApplication = "1";  
	String queryJSON = "{ geometry:{ $geoWithin:{ $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	Integer pageIndex=5;
	Integer pageSize= 20;
	int skipElementsValue = pageIndex*pageSize;		 
		
	//Fixture		 	    
    Query querySkip=Mockito.mock(Query.class);
    Query queryLimit=Mockito.mock(Query.class);
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenReturn(basicQuery);				
	Mockito.when(basicQuery.skip(skipElementsValue)).thenReturn(querySkip);
	Mockito.when(querySkip.limit(pageSize)).thenReturn(queryLimit);				
	Mockito.when(mongoTemplate.find(queryLimit, Feature.class, collectionMap+idApplication)).thenReturn(features);
	
	//Experimentation
	Collection<Feature> featuresResponse=mapRepositoryCustomImpl.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize);
	
	//Expectations
	Mockito.verify(mongoTemplate).find(queryLimit, Feature.class, collectionMap+idApplication);
	Assert.assertEquals("Features must be equals", featuresResponse, features);
	
}
 
Example #9
Source File: Mongo.java    From sagacity-sqltoy with Apache License 2.0 5 votes vote down vote up
/**
 * @todo 取top记录
 * @param mongoTemplate
 * @param sqlToyConfig
 * @param topSize
 * @param mql
 * @param resultClass
 * @return
 */
private List<?> findTop(MongoTemplate mongoTemplate, SqlToyConfig sqlToyConfig, Float topSize, String mql,
		Class resultClass) throws Exception {
	BasicQuery query = new BasicQuery(mql);
	if (topSize != null) {
		if (topSize > 1) {
			query.limit(topSize.intValue());
		} else {
			// 按比例提取
			long count = mongoTemplate.count(query, sqlToyConfig.getNoSqlConfigModel().getCollection());
			query.limit(Double.valueOf(count * topSize.floatValue()).intValue());
		}
	}
	if (sqlToyContext.isDebug()) {
		if (logger.isDebugEnabled()) {
			logger.debug("findTopByMongo script=" + query.getQueryObject());
		} else {
			System.out.println("findTopByMongo script=" + query.getQueryObject());
		}
	}
	List<Document> rs = mongoTemplate.find(query, Document.class,
			sqlToyConfig.getNoSqlConfigModel().getCollection());
	if (rs == null || rs.isEmpty()) {
		return null;
	}
	return extractFieldValues(sqlToyConfig, rs.iterator(), resultClass);
}
 
Example #10
Source File: ImportRepositoryCustomImplTest.java    From osiris with Apache License 2.0 5 votes vote down vote up
@Test
public void isImportProcessLockedSpentTheTime() throws Exception{
	
	String idApplication = "1";		
	String strQuery = "{ '_id':'" + idApplication + "'}";	
	String strNow = DateTime.now().toString();
	
	
	//Fixture
	Query query=Mockito.mock(Query.class);	    
	PowerMockito.whenNew(BasicQuery.class).withArguments(strQuery).thenReturn(basicQuery);								
	Mockito.when(mongoTemplate.find(query, LockImport.class, collectionLock)).thenReturn(lockImportList);		
	Mockito.when(mongoTemplate.collectionExists(collectionLock)).thenReturn(true);
	Mockito.when(mongoTemplate.getCollection(collectionLock)).thenReturn(dbCollection);
	PowerMockito.whenNew(LockImport.class).withNoArguments().thenReturn(lockImport);
	PowerMockito.mockStatic(DateTime.class);
	Mockito.when(DateTime.now()).thenReturn(now);
	Mockito.when(now.toString()).thenReturn(strNow);
					
	//Experimentation
	importRepositoryCustom.isImportProcessLocked(idApplication);
	
	//Expectations		
	
	
}
 
Example #11
Source File: FeatureRepositoryCustomImplTest.java    From osiris with Apache License 2.0 5 votes vote down vote up
@Test
public void findByIDAppAndQueryWithOrderTest() throws Exception{
	
	 String idApplication = "1";  
	 String queryJSON = "{ geometry:{ $geoWithin:{ $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	 Integer pageIndex=5;
	 Integer pageSize= 20;
	 int skipElementsValue = pageIndex*pageSize;
	 String orderField = "_id"; 
	 String order = "ASC";
	 
		
	//Fixture		 	    
    Query querySkip=Mockito.mock(Query.class);
    Query queryLimit=Mockito.mock(Query.class);
    Query query=Mockito.mock(Query.class);
    Sort  sort = Mockito.mock(Sort.class);
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenReturn(basicQuery);				
	Mockito.when(basicQuery.skip(skipElementsValue)).thenReturn(querySkip);
	Mockito.when(querySkip.limit(pageSize)).thenReturn(queryLimit);				
	PowerMockito.whenNew(Sort.class).withArguments(Sort.Direction.valueOf(order), orderField).thenReturn(sort);
	Mockito.when(queryLimit.with(sort)).thenReturn(query);		
	Mockito.when(mongoTemplate.find(query, Feature.class, collectionName+idApplication)).thenReturn(features);
			
	//Experimentation
	Collection<Feature> featuresResponse=featureRepository.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize, orderField, order);
	
	//Expectations
	Mockito.verify(mongoTemplate).find(query, Feature.class, collectionName+idApplication);
	Assert.assertEquals("Features must be equals", featuresResponse, features);

}
 
Example #12
Source File: FeatureRepositoryCustomImplTest.java    From osiris with Apache License 2.0 5 votes vote down vote up
@Test
public void findByIDAppAndQueryTest() throws Exception{
	
	 String idApplication = "1";  
	 String queryJSON = "{ geometry:{ $geoWithin:{ $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	 Integer pageIndex=5;
	 Integer pageSize= 20;
	 int skipElementsValue = pageIndex*pageSize;
	 
		
	//Fixture		 	    
    Query querySkip=Mockito.mock(Query.class);
    Query queryLimit=Mockito.mock(Query.class);
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenReturn(basicQuery);				
	Mockito.when(basicQuery.skip(skipElementsValue)).thenReturn(querySkip);
	Mockito.when(querySkip.limit(pageSize)).thenReturn(queryLimit);				
	Mockito.when(mongoTemplate.find(queryLimit, Feature.class, collectionName+idApplication)).thenReturn(features);
	
	
	
	//Experimentation
	Collection<Feature> featuresResponse=featureRepository.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize);
	
	//Expectations
	Mockito.verify(mongoTemplate).find(queryLimit, Feature.class, collectionName+idApplication);
	Assert.assertEquals("Features must be equals", featuresResponse, features);
	
}
 
Example #13
Source File: MapRepositoryCustomImplTest.java    From osiris with Apache License 2.0 5 votes vote down vote up
@Test
public void findByIDAppAndQueryWithOrderTest() throws Exception{
	
	String idApplication = "1";  
	String queryJSON = "{ geometry:{ $geoWithin:{ $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	Integer pageIndex=5;
	Integer pageSize= 20;
	int skipElementsValue = pageIndex*pageSize;
	String orderField = "_id"; 
	String order = "ASC";
				
	//Fixture		 	    
    Query querySkip=Mockito.mock(Query.class);
    Query queryLimit=Mockito.mock(Query.class);
    Query query=Mockito.mock(Query.class);
    Sort  sort = Mockito.mock(Sort.class);
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenReturn(basicQuery);				
	Mockito.when(basicQuery.skip(skipElementsValue)).thenReturn(querySkip);
	Mockito.when(querySkip.limit(pageSize)).thenReturn(queryLimit);				
	PowerMockito.whenNew(Sort.class).withArguments(Sort.Direction.valueOf(order), orderField).thenReturn(sort);
	Mockito.when(queryLimit.with(sort)).thenReturn(query);		
	Mockito.when(mongoTemplate.find(query, Feature.class, collectionMap+idApplication)).thenReturn(features);
			
	//Experimentation
	Collection<Feature> featuresResponse=mapRepositoryCustomImpl.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize, orderField, order);
	
	//Expectations
	Mockito.verify(mongoTemplate).find(query, Feature.class, collectionMap+idApplication);
	Assert.assertEquals("Features must be equals", featuresResponse, features);
}
 
Example #14
Source File: FeatureRepositoryCustomImplTest.java    From osiris with Apache License 2.0 5 votes vote down vote up
@Test
public void findByIDAppAndQueryWithOrderTest() throws Exception{
	
	 String idApplication = "1";  
	 String queryJSON = "{ geometry:{ $geoWithin:{ $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	 Integer pageIndex=5;
	 Integer pageSize= 20;
	 int skipElementsValue = pageIndex*pageSize;
	 String orderField = "_id"; 
	 String order = "ASC";
	 
		
	//Fixture		 	    
    Query querySkip=Mockito.mock(Query.class);
    Query queryLimit=Mockito.mock(Query.class);
    Query query=Mockito.mock(Query.class);
    Sort  sort = Mockito.mock(Sort.class);
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenReturn(basicQuery);				
	Mockito.when(basicQuery.skip(skipElementsValue)).thenReturn(querySkip);
	Mockito.when(querySkip.limit(pageSize)).thenReturn(queryLimit);				
	PowerMockito.whenNew(Sort.class).withArguments(Sort.Direction.valueOf(order), orderField).thenReturn(sort);
	Mockito.when(queryLimit.with(sort)).thenReturn(query);		
	Mockito.when(mongoTemplate.find(query, Feature.class, collectionName+idApplication)).thenReturn(features);
			
	//Experimentation
	Collection<Feature> featuresResponse=featureRepository.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize, orderField, order);
	
	//Expectations
	Mockito.verify(mongoTemplate).find(query, Feature.class, collectionName+idApplication);
	Assert.assertEquals("Features must be equals", featuresResponse, features);

}
 
Example #15
Source File: FeatureRepositoryCustomImplTest.java    From osiris with Apache License 2.0 5 votes vote down vote up
@Test
public void findByIDAppAndQueryTest() throws Exception{
	
	 String idApplication = "1";  
	 String queryJSON = "{ geometry:{ $geoWithin:{ $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	 Integer pageIndex=5;
	 Integer pageSize= 20;
	 int skipElementsValue = pageIndex*pageSize;
	 
		
	//Fixture		 	    
    Query querySkip=Mockito.mock(Query.class);
    Query queryLimit=Mockito.mock(Query.class);
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenReturn(basicQuery);				
	Mockito.when(basicQuery.skip(skipElementsValue)).thenReturn(querySkip);
	Mockito.when(querySkip.limit(pageSize)).thenReturn(queryLimit);				
	Mockito.when(mongoTemplate.find(queryLimit, Feature.class, collectionName+idApplication)).thenReturn(features);
	
	
	
	//Experimentation
	Collection<Feature> featuresResponse=featureRepository.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize);
	
	//Expectations
	Mockito.verify(mongoTemplate).find(queryLimit, Feature.class, collectionName+idApplication);
	Assert.assertEquals("Features must be equals", featuresResponse, features);
	
}
 
Example #16
Source File: MapRepositoryCustomImplTest.java    From osiris with Apache License 2.0 5 votes vote down vote up
@Test
public void findByIDAppAndQueryWithOrderTest() throws Exception{
	
	String idApplication = "1";  
	String queryJSON = "{ geometry:{ $geoWithin:{ $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	Integer pageIndex=5;
	Integer pageSize= 20;
	int skipElementsValue = pageIndex*pageSize;
	String orderField = "_id"; 
	String order = "ASC";
				
	//Fixture		 	    
    Query querySkip=Mockito.mock(Query.class);
    Query queryLimit=Mockito.mock(Query.class);
    Query query=Mockito.mock(Query.class);
    Sort  sort = Mockito.mock(Sort.class);
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenReturn(basicQuery);				
	Mockito.when(basicQuery.skip(skipElementsValue)).thenReturn(querySkip);
	Mockito.when(querySkip.limit(pageSize)).thenReturn(queryLimit);				
	PowerMockito.whenNew(Sort.class).withArguments(Sort.Direction.valueOf(order), orderField).thenReturn(sort);
	Mockito.when(queryLimit.with(sort)).thenReturn(query);		
	Mockito.when(mongoTemplate.find(query, Feature.class, collectionMap+idApplication)).thenReturn(features);
			
	//Experimentation
	Collection<Feature> featuresResponse=mapRepositoryCustomImpl.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize, orderField, order);
	
	//Expectations
	Mockito.verify(mongoTemplate).find(query, Feature.class, collectionMap+idApplication);
	Assert.assertEquals("Features must be equals", featuresResponse, features);
}
 
Example #17
Source File: GenericService.java    From HA-DB with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Result<Docs> page(String collectionName, Document queryDoc, Pageable pageable) {
	Result<Docs> result = new Result<>(); // 结果集
	Query query = new BasicQuery(new Document() , queryDoc); // 组装query
	query.with(pageable); // 组装分页
	Long count = mongoTemplate.count(query, collectionName); // 统计
	List<Docs> dtos = (List<Docs>) mongoTemplate.find(query, clasz, collectionName); // 映射结果集
	result.setData(dtos); // 组装返回
	result.setCount(count); // 填充统计
	return result;
}
 
Example #18
Source File: Mongo.java    From sagacity-sqltoy with Apache License 2.0 5 votes vote down vote up
/**
 * @todo 分页查询
 * @param mongoTemplate
 * @param sqlToyConfig
 * @param pageModel
 * @param mql
 * @param resultClass
 * @return
 * @throws Exception
 */
private PaginationModel findPage(MongoTemplate mongoTemplate, SqlToyConfig sqlToyConfig, PaginationModel pageModel,
		String mql, Class resultClass) throws Exception {
	PaginationModel result = new PaginationModel();
	result.setPageNo(pageModel.getPageNo());
	result.setPageSize(pageModel.getPageSize());
	BasicQuery query = new BasicQuery(mql);
	result.setRecordCount(mongoTemplate.count(query, sqlToyConfig.getNoSqlConfigModel().getCollection()));

	// 设置分页
	if (result.getPageNo() == -1) {
		query.skip(0).limit(Long.valueOf(result.getRecordCount()).intValue());
	} else {
		query.skip((pageModel.getPageNo() - 1) * pageModel.getPageSize()).limit(pageModel.getPageSize());
	}
	if (sqlToyContext.isDebug()) {
		if (logger.isDebugEnabled()) {
			logger.debug("findPageByMongo script=" + query.getQueryObject());
		} else {
			System.out.println("findPageByMongo script=" + query.getQueryObject());
		}
	}
	List<Document> rs = mongoTemplate.find(query, Document.class,
			sqlToyConfig.getNoSqlConfigModel().getCollection());
	if (rs == null || rs.isEmpty()) {
		return result;
	}
	result.setRows(extractFieldValues(sqlToyConfig, rs.iterator(), resultClass));
	return result;
}
 
Example #19
Source File: FeatureRepositoryCustomImplTest.java    From osiris with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test(expected=QueryException.class)
public void findByIDAppAndQueryErrorQueryTesTest() throws Exception{

	String idApplication = "1";  
	 String queryJSON = "{ geometry:{ $geoWithin: $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	 Integer pageIndex=5;
	 Integer pageSize= 20;		
	  
		
	//Fixture		 	    	    	    	    
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenThrow(Exception.class);						
					 		
	//Experimentation
	featureRepository.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize);
	
	//Expectations

}
 
Example #20
Source File: FeatureRepositoryCustomImplTest.java    From osiris with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test(expected=QueryException.class)
public void findByIDAppAndQueryErrorQueryTest() throws Exception{
	
	 String idApplication = "1";  
	 String queryJSON = "{ geometry:{ $geoWithin: $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	 Integer pageIndex=5;
	 Integer pageSize= 20;		
	
	 String orderField = "_id"; 
	 String order = "ASC";
	  
		
	//Fixture		 	    	    	    	    
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenThrow(Exception.class);						
					 		
	//Experimentation
	featureRepository.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize, orderField, order);
	
	//Expectations

}
 
Example #21
Source File: MapRepositoryCustomImplTest.java    From osiris with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test(expected=QueryException.class)
public void findByIDAppAndQueryErrorQueryTest() throws Exception{
	
	 String idApplication = "1";  
	 String queryJSON = "{ geometry:{ $geoWithin: $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	 Integer pageIndex=5;
	 Integer pageSize= 20;		
	
	 String orderField = "_id"; 
	 String order = "ASC";
	  
		
	//Fixture		 	    	    	    	    
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenThrow(Exception.class);						
					 		
	//Experimentation
	mapRepositoryCustomImpl.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize, orderField, order);
	
	//Expectations

}
 
Example #22
Source File: BaseService.java    From HA-DB with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public List<T> findALL(String collectionName, Document queryDoc, T claz, Pageable pageable) {
	Query query = new BasicQuery(queryDoc);
	query.with(pageable);
	List<T> result = mongoTemplate.find(query, (Class<T>) claz, collectionName);
	return result;
}
 
Example #23
Source File: MapRepositoryCustomImplTest.java    From osiris with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test(expected=QueryException.class)
public void findByIDAppAndQueryErrorQueryTest() throws Exception{
	
	 String idApplication = "1";  
	 String queryJSON = "{ geometry:{ $geoWithin: $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	 Integer pageIndex=5;
	 Integer pageSize= 20;		
	
	 String orderField = "_id"; 
	 String order = "ASC";
	  
		
	//Fixture		 	    	    	    	    
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenThrow(Exception.class);						
					 		
	//Experimentation
	mapRepositoryCustomImpl.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize, orderField, order);
	
	//Expectations

}
 
Example #24
Source File: GenericService.java    From HA-DB with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public List<Docs> pageNoCount(String collectionName, Document queryDoc, Pageable pageable) {
	Query query = new BasicQuery(new Document() , queryDoc); // 组装query
	query.with(pageable); // 组装分页
	List<Docs> dtos = (List<Docs>) mongoTemplate.find(query, clasz, collectionName); // 映射结果集
	return dtos;
}
 
Example #25
Source File: FeatureRepositoryCustomImplTest.java    From osiris with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test(expected=QueryException.class)
public void findByIDAppAndQueryErrorQueryTesTest() throws Exception{

	String idApplication = "1";  
	 String queryJSON = "{ geometry:{ $geoWithin: $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	 Integer pageIndex=5;
	 Integer pageSize= 20;		
	  
		
	//Fixture		 	    	    	    	    
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenThrow(Exception.class);						
					 		
	//Experimentation
	featureRepository.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize);
	
	//Expectations

}
 
Example #26
Source File: FeatureRepositoryCustomImplTest.java    From osiris with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test(expected=QueryException.class)
public void findByIDAppAndQueryErrorQueryTest() throws Exception{
	
	 String idApplication = "1";  
	 String queryJSON = "{ geometry:{ $geoWithin: $centerSphere:[ [20.05,20.01] , 0.05]} } }";	
	 Integer pageIndex=5;
	 Integer pageSize= 20;		
	
	 String orderField = "_id"; 
	 String order = "ASC";
	  
		
	//Fixture		 	    	    	    	    
	PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenThrow(Exception.class);						
					 		
	//Experimentation
	featureRepository.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize, orderField, order);
	
	//Expectations

}
 
Example #27
Source File: ImportRepositoryCustomImplTest.java    From osiris with Apache License 2.0 4 votes vote down vote up
@Test
public void isImportProcessLocked() throws Exception{
	
	String idApplication = "1";		
	String strQuery = "{ '_id':'" + idApplication + "'}";
	
	//Fixture
	Query query=Mockito.mock(Query.class);	    
	PowerMockito.whenNew(BasicQuery.class).withArguments(strQuery).thenReturn(basicQuery);								
	Mockito.when(mongoTemplate.find(query, LockImport.class, collectionLock)).thenReturn(lockImportList);
	Mockito.when(lockImportList.get(0)).thenReturn(lockImport);
					
	//Experimentation
	importRepositoryCustom.isImportProcessLocked(idApplication);
	
	//Expectations
	
	
	
}
 
Example #28
Source File: GenericService.java    From HA-DB with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Docs findByIdAndQuery(String doc, String id, Document query) {
	Query q = new BasicQuery(new Document(), query);
	q.addCriteria(Criteria.where(Opations.ID_FIELD).is(id));
	return mongoTemplate.findOne(q, clasz , doc);
}
 
Example #29
Source File: StoreRepositoryTests.java    From spring-data-examples with Apache License 2.0 3 votes vote down vote up
/**
 * The {@code $geoIntersects} keyword is not yet available via {@link Criteria} we need to fall back to manual
 * creation of the query using the registered {@link MongoConverter} for {@link GeoJson} conversion.
 */
@Test
public void findStoresThatIntersectGivenPolygon() {

	Document geoJsonDbo = new Document();

	operations.getConverter().write(GEO_JSON_POLYGON, geoJsonDbo);

	BasicQuery bq = new BasicQuery(
			new Document("location", new Document("$geoIntersects", new Document("$geometry", geoJsonDbo))));

	operations.find(bq, Store.class).forEach(System.out::println);
}
 
Example #30
Source File: MongoGenericDao.java    From howsun-javaee-framework with Apache License 2.0 2 votes vote down vote up
/**
 * e.g.:
 * Query query = parseQuery("{'tracks.name' : 'Wheels'}");
 * Query query = parseQuery("{'_id' : { '$oid' : '%s' }}", bigWhiskey.getId());
 * Query query = parseQuery("{'tracks.name' : 'Wheels'}");
 * Query query = parseQuery("{'tracks.name' : { '$regex' : '.*it.*' , '$options' : '' }}");
 * Query build = new Query(where("_id").is(bigWhiskey.getId()));
 *
 * @param query
 * @param arguments
 * @return
 */
public static Query parseQuery(String query, Object... arguments) {
	return new BasicQuery(String.format(query, arguments));
}