org.springframework.data.mongodb.UncategorizedMongoDbException Java Examples

The following examples show how to use org.springframework.data.mongodb.UncategorizedMongoDbException. 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: CustomDailyStatisticRepositoryTest.java    From microcks with Apache License 2.0 6 votes vote down vote up
@Test
public void testAggregateDailyStatistics(){
   try {
      DailyStatistic stat = repository.aggregateDailyStatistics("20140930");
   } catch (ConverterNotFoundException cvnfe){
      // For now, mapReduce in Fongo is experimental. MapReduce execution is working
      // but SpringData cannot convert Fongo Rhino result into Java object
      // ("No converter found capable of converting from type org.mozilla.javascript.UniqueTag to type java.lang.Integer")
   } catch (UncategorizedMongoDbException ume){
      // For now, mapReduce in Fongo is experimental. MapReduce execution is not working
      // ("org.mozilla.javascript.EcmaError: TypeError: Cannot read property "0" from undefined")
   } catch (RuntimeException re){
      // For now, mapReduce in Fongo is experimental. MapReduce execution is working
      // but SpringData cannot convert Fongo Rhino result into Java object
      // ("json can't serialize type : class org.mozilla.javascript.UniqueTag")
   }
}
 
Example #2
Source File: FeatureRepositoryCustomImpl.java    From osiris with Apache License 2.0 6 votes vote down vote up
@Override
public Feature save(String idApplication, Feature feature) throws MongoGeospatialException {
	// TODO Auto-generated method stub
	if(!mongoTemplate.collectionExists(collectionName+idApplication)){
		DBCollection dbCollection = mongoTemplate.getCollection(collectionName+idApplication); 
		DBObject obj = new BasicDBObject();		
		obj.put("geometry", "2dsphere");
		dbCollection.ensureIndex(obj);
	}
	try{
		mongoTemplate.save(feature, collectionName+idApplication);
	}
	catch(UncategorizedMongoDbException uncategorizedMongoDbException){
		throw new MongoGeospatialException();
	}
	return feature;
}
 
Example #3
Source File: FeatureRepositoryCustomImplTest.java    From osiris with Apache License 2.0 6 votes vote down vote up
@Test(expected=MongoGeospatialException.class)
public void shouldThrowErrorWhenGeospatialIndexNotCreated() throws Exception{
	
	String idApplication = "1";  
	//Fixture
	Feature feature=Mockito.mock(Feature.class);
	DBCollection dbCollection=Mockito.mock(DBCollection.class);
	BasicDBObject obj=Mockito.mock(BasicDBObject.class);
	Mockito.when(mongoTemplate.collectionExists(collectionName+idApplication)).thenReturn(false);
	Mockito.when(mongoTemplate.getCollection(collectionName+idApplication)).thenReturn(dbCollection);
	PowerMockito.whenNew(BasicDBObject.class).withNoArguments().thenReturn(obj);
	Mockito.doThrow(UncategorizedMongoDbException.class).when(mongoTemplate).save(feature,collectionName+idApplication);
	//Experimentation
	featureRepository.save(idApplication, feature);
	//Expectation
	Mockito.verify(mongoTemplate).collectionExists(collectionName+idApplication);
	Mockito.verify(mongoTemplate).save(feature,collectionName+idApplication);
}
 
Example #4
Source File: FeatureRepositoryCustomImplTest.java    From osiris with Apache License 2.0 6 votes vote down vote up
@Test(expected=MongoGeospatialException.class)
public void shouldThrowErrorWhenGeospatialIndexNotCreated() throws Exception{
	
	String idApplication = "1";  
	//Fixture
	Feature feature=Mockito.mock(Feature.class);
	DBCollection dbCollection=Mockito.mock(DBCollection.class);
	BasicDBObject obj=Mockito.mock(BasicDBObject.class);
	Mockito.when(mongoTemplate.collectionExists(collectionName+idApplication)).thenReturn(false);
	Mockito.when(mongoTemplate.getCollection(collectionName+idApplication)).thenReturn(dbCollection);
	PowerMockito.whenNew(BasicDBObject.class).withNoArguments().thenReturn(obj);
	Mockito.doThrow(UncategorizedMongoDbException.class).when(mongoTemplate).save(feature,collectionName+idApplication);
	//Experimentation
	featureRepository.save(idApplication, feature);
	//Expectation
	Mockito.verify(mongoTemplate).collectionExists(collectionName+idApplication);
	Mockito.verify(mongoTemplate).save(feature,collectionName+idApplication);
}
 
Example #5
Source File: ImportRepositoryCustomImplTest.java    From osiris with Apache License 2.0 5 votes vote down vote up
@Test
public void importRepositoryMongoGeospatialExceptionThenContinue() throws Exception {
	
	String appIdentifier = "1";		
	String collectionNameMap = collectionMap+appIdentifier;

	List<Feature> featureCollection = new ArrayList<Feature>();
	featureCollection.add(feature1);			 
	
	//Fixture		
	Mockito.when(mongoTemplate.collectionExists(collectionNameMap)).thenReturn(true);
	Mockito.when(mongoTemplate.getCollection(collectionNameMap)).thenReturn(dbCollection);
	PowerMockito.whenNew(BasicDBObject.class).withNoArguments().thenReturn(obj);
	Mockito.when(obj.put("geometry", "2dsphere")).thenReturn(obj);
	
	Mockito.when(feature1.getGeometry()).thenReturn(geometry1);					
	Mockito.doThrow(UncategorizedMongoDbException.class).when(mongoTemplate).save(feature1,collectionNameMap);		
									
	//Experimentation
	importRepositoryCustom.saveGeoJson(appIdentifier, featureCollection );
			
	//Expectation		
	verify(mongoTemplate).dropCollection(collectionNameMap);	
	verify(mongoTemplate).createCollection(collectionNameMap);
	verify(dbCollection).ensureIndex(obj);
	verify(mongoTemplate).save(feature1,collectionNameMap);
}
 
Example #6
Source File: UncategorizedMongoExceptionHandler.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
@Override
public Response toResponse(UncategorizedMongoDbException exception) {
    Status errorStatus = Status.SERVICE_UNAVAILABLE;
    LOG.error("Could not access database", exception);
    return Response
            .status(errorStatus)
            .entity(new ErrorResponse(errorStatus.getStatusCode(), errorStatus.getReasonPhrase(),
                    "Could not access database:" + exception.getMessage())).build();
}