Search in sources :

Example 1 with Record__Trash

use of org.motechproject.mds.testutil.records.history.Record__Trash in project motech by motech.

the class TrashServiceTest method shouldMoveObjectToTrash.

@Test
public void shouldMoveObjectToTrash() throws Exception {
    doReturn(Record__Trash.class).when(classLoader).loadClass(Record__Trash.class.getName());
    Entity entity = mock(Entity.class);
    Field field = mock(Field.class);
    Type type = mock(Type.class);
    doReturn(17L).when(entity).getEntityVersion();
    doReturn(field).when(entity).getField("id");
    doReturn(field).when(entity).getField("value");
    doReturn(type).when(field).getType();
    doReturn(false).when(type).isRelationship();
    doReturn(entity).when(allEntities).retrieveByClassName(anyString());
    Record instance = new Record();
    trashService.moveToTrash(instance, 1L);
    verify(manager).makePersistent(trashCaptor.capture());
    Record__Trash trash = trashCaptor.getValue();
    assertEquals(instance.getValue(), trash.getValue());
}
Also used : Record__Trash(org.motechproject.mds.testutil.records.history.Record__Trash) Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field) Type(org.motechproject.mds.domain.Type) Record(org.motechproject.mds.testutil.records.Record) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with Record__Trash

use of org.motechproject.mds.testutil.records.history.Record__Trash in project motech by motech.

the class TrashServiceTest method shouldMoveObjectFromTrash.

@Test
public void shouldMoveObjectFromTrash() {
    Record instance = new Record();
    Record__Trash trash = new Record__Trash();
    doReturn(entity).when(allEntities).retrieveByClassName(anyString());
    doReturn(true).when(entity).isRecordHistory();
    trashService.removeFromTrash(trash);
    verify(manager).deletePersistent(trashCaptor.capture());
    Record__Trash captor = trashCaptor.getValue();
    assertEquals(captor.getValue(), trash.getValue());
}
Also used : Record__Trash(org.motechproject.mds.testutil.records.history.Record__Trash) Record(org.motechproject.mds.testutil.records.Record) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with Record__Trash

use of org.motechproject.mds.testutil.records.history.Record__Trash in project motech by motech.

the class TrashServiceTest method shouldFindTrashEntityById.

@Test
public void shouldFindTrashEntityById() throws Exception {
    doReturn(Record__Trash.class).when(classLoader).loadClass("org.test.history.TestEntity__Trash");
    doReturn(query).when(manager).newQuery(Record__Trash.class);
    Entity entity = mock(Entity.class);
    Field field = mock(Field.class);
    Type type = mock(Type.class);
    doReturn(17L).when(entity).getEntityVersion();
    doReturn("org.test.TestEntity").when(entity).getClassName();
    doReturn(field).when(entity).getField("id");
    doReturn(field).when(entity).getField("value");
    doReturn(type).when(field).getType();
    doReturn(false).when(type).isRelationship();
    doReturn(entity).when(allEntities).retrieveById(1L);
    doReturn(new Record__Trash()).when(query).execute(anyLong());
    Object trash = trashService.findTrashById(1L, "org.test.TestEntity");
    assertNotNull(trash);
}
Also used : Record__Trash(org.motechproject.mds.testutil.records.history.Record__Trash) Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field) Type(org.motechproject.mds.domain.Type) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 Record__Trash (org.motechproject.mds.testutil.records.history.Record__Trash)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Entity (org.motechproject.mds.domain.Entity)2 Field (org.motechproject.mds.domain.Field)2 Type (org.motechproject.mds.domain.Type)2 Record (org.motechproject.mds.testutil.records.Record)2