Example usage for org.springframework.data.mongodb.core MongoOperations collectionExists

List of usage examples for org.springframework.data.mongodb.core MongoOperations collectionExists

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core MongoOperations collectionExists.

Prototype

boolean collectionExists(String collectionName);

Source Link

Document

Check to see if a collection with a given name exists.

Usage

From source file:com.comcast.video.dawg.service.house.MongoHouseServiceTest.java

@SuppressWarnings("unchecked")
@Test//  w w w .  ja  v  a2 s  .  co  m
public void testUpsertStb() {
    MongoHouseService service = new MongoHouseService();
    MongoOperations operations = EasyMock.createMock(MongoOperations.class);
    EasyMock.expect(operations.collectionExists((Class) EasyMock.anyObject())).andReturn(false);
    EasyMock.expect(operations.createCollection((Class) EasyMock.anyObject())).andReturn(null);

    operations.save((PersistableDevice) EasyMock.anyObject(), (String) EasyMock.anyObject());
    EasyMock.expectLastCall();
    EasyMock.expect(operations.findById((Object) EasyMock.anyObject(), (Class) EasyMock.anyObject(),
            (String) EasyMock.anyObject())).andReturn(null);
    EasyMock.replay(operations);
    ReflectionTestUtils.setField(service, "template", operations);

    ParkService mockParkService = EasyMock.createMock(ParkService.class);
    EasyMock.expect(mockParkService.getModelById((String) EasyMock.anyObject())).andReturn(null);
    EasyMock.replay(mockParkService);
    ReflectionTestUtils.setField(service, "parkService", mockParkService);

    DawgDevice[] stb = new DawgDevice[1];
    stb[0] = new PersistableDevice();

    try {
        service.upsertStb(stb);
    } catch (Exception e) {
        Assert.fail(e.getMessage(), e);
    }
}