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

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

Introduction

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

Prototype

<T> T save(T objectToSave, String collectionName);

Source Link

Document

Save the object to the specified collection.

Usage

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

@SuppressWarnings("unchecked")
@Test//  ww  w .  j a  v a  2s . c  o 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);
    }
}