Search in sources :

Example 1 with Record

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

the class MdsRestFacadeTest method shouldDoUpdateOperation.

@Test
public void shouldDoUpdateOperation() throws IOException {
    setUpCrudAccess(false, false, true, false);
    try (InputStream recordAsStream = toInputStream(recordOne)) {
        mdsRestFacade.update(recordAsStream);
    }
    ArgumentCaptor<Record> captor = ArgumentCaptor.forClass(Record.class);
    ArgumentCaptor<Set> fieldsToCopyCaptor = ArgumentCaptor.forClass(Set.class);
    verify(dataService).updateFromTransient(captor.capture(), fieldsToCopyCaptor.capture());
    assertNotNull(captor.getValue());
    assertNotNull(fieldsToCopyCaptor.getValue());
    assertEquals("restTest", captor.getValue().getValue());
    assertEquals(3, fieldsToCopyCaptor.getValue().size());
    assertTrue(fieldsToCopyCaptor.getValue().contains("value"));
    assertTrue(fieldsToCopyCaptor.getValue().contains("date"));
    assertFalse(fieldsToCopyCaptor.getValue().contains("dateIgnoredByRest"));
}
Also used : Set(java.util.Set) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Record(org.motechproject.mds.testutil.records.Record) Test(org.junit.Test)

Example 2 with Record

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

the class MdsRestFacadeTest method shouldDoCreateOperation.

@Test
public void shouldDoCreateOperation() throws IOException {
    setUpCrudAccess(true, false, false, false);
    recordOne.setBlob(blobFieldValue);
    try (InputStream recordAsStream = toInputStream(recordOne)) {
        mdsRestFacade.create(recordAsStream);
    }
    ArgumentCaptor<Record> captor = ArgumentCaptor.forClass(Record.class);
    verify(dataService).create(captor.capture());
    assertNotNull(captor.getValue());
    assertEquals("restTest", captor.getValue().getValue());
    assertArrayEquals(blobFieldValue, captor.getValue().getBlob());
    assertNull(captor.getValue().getDateIgnoredByRest());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Record(org.motechproject.mds.testutil.records.Record) Test(org.junit.Test)

Example 3 with Record

use of org.motechproject.mds.testutil.records.Record 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 4 with Record

use of org.motechproject.mds.testutil.records.Record 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 5 with Record

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

the class InMemoryQueryFilterTest method shouldOrderByAsc.

@Test
public void shouldOrderByAsc() {
    QueryParams queryParams = new QueryParams(new Order("value", Order.Direction.ASC));
    List<Record> result = InMemoryQueryFilter.filter(testCollection, queryParams);
    assertListByValues(result, asList("aaa", "hmm", "hmm", "nullRecord", "something", "test", "zet"));
    assertListByIds(result, asList(4L, 5L, 6L, null, 3L, 2L, 1L));
}
Also used : Order(org.motechproject.mds.util.Order) Record(org.motechproject.mds.testutil.records.Record) Test(org.junit.Test)

Aggregations

Record (org.motechproject.mds.testutil.records.Record)20 Test (org.junit.Test)16 HashMap (java.util.HashMap)4 Order (org.motechproject.mds.util.Order)4 Date (java.util.Date)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Entity (org.motechproject.mds.domain.Entity)2 Field (org.motechproject.mds.domain.Field)2 Type (org.motechproject.mds.domain.Type)2 Record__Trash (org.motechproject.mds.testutil.records.history.Record__Trash)2 Set (java.util.Set)1 Before (org.junit.Before)1 Matchers.anyLong (org.mockito.Matchers.anyLong)1 FieldDto (org.motechproject.mds.dto.FieldDto)1 LookupDto (org.motechproject.mds.dto.LookupDto)1 TypeDto (org.motechproject.mds.dto.TypeDto)1 QueryParams (org.motechproject.mds.query.QueryParams)1