Search in sources :

Example 16 with Time

use of org.motechproject.commons.date.model.Time in project motech by motech.

the class InstanceServiceTest method testUpdateCreate.

private void testUpdateCreate(boolean edit) throws ClassNotFoundException {
    final DateTime dtValue = DateUtil.now();
    mockSampleFields();
    mockDataService();
    mockEntity();
    when(motechDataService.retrieve("id", INSTANCE_ID)).thenReturn(new TestSample());
    List<FieldRecord> fieldRecords = asList(FieldTestHelper.fieldRecord("strField", String.class.getName(), "", "this is a test"), FieldTestHelper.fieldRecord("intField", Integer.class.getName(), "", 16), FieldTestHelper.fieldRecord("timeField", Time.class.getName(), "", "10:17"), FieldTestHelper.fieldRecord("dtField", DateTime.class.getName(), "", dtValue));
    Long id = (edit) ? INSTANCE_ID : null;
    EntityRecord record = new EntityRecord(id, ENTITY_ID, fieldRecords);
    MDSClassLoader.getInstance().loadClass(TestSample.class.getName());
    instanceService.saveInstance(record);
    ArgumentCaptor<TestSample> captor = ArgumentCaptor.forClass(TestSample.class);
    if (edit) {
        verify(motechDataService).update(captor.capture());
    } else {
        verify(motechDataService).create(captor.capture());
    }
    TestSample sample = captor.getValue();
    assertEquals("this is a test", sample.getStrField());
    assertEquals(Integer.valueOf(16), sample.getIntField());
    assertEquals(new Time(10, 17), sample.getTimeField());
    assertEquals(dtValue, sample.getDtField());
}
Also used : BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) EntityRecord(org.motechproject.mds.web.domain.EntityRecord) Matchers.anyLong(org.mockito.Matchers.anyLong) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) DateTime(org.joda.time.DateTime)

Aggregations

Time (org.motechproject.commons.date.model.Time)16 DateTime (org.joda.time.DateTime)12 Test (org.junit.Test)10 LocalDateTime (java.time.LocalDateTime)6 LocalDate (org.joda.time.LocalDate)6 MotechEvent (org.motechproject.event.MotechEvent)5 Date (java.util.Date)4 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)4 DayOfWeekSchedulableJob (org.motechproject.scheduler.contract.DayOfWeekSchedulableJob)4 ZonedDateTime (java.time.ZonedDateTime)3 ArrayList (java.util.ArrayList)3 Arrays.asList (java.util.Arrays.asList)3 Collections.singletonList (java.util.Collections.singletonList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 TimeFaker.stopFakingTime (org.motechproject.testing.utils.TimeFaker.stopFakingTime)3 DayOfWeek (org.motechproject.commons.date.model.DayOfWeek)2 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1