use of org.summerb.easycrud.impl.relations.example.EnvService in project summerb by skarpushin.
the class DomLoaderDeviceGatewayTest method testMapDtoToDom_expectCorrectFieldTypeResolution.
@Test
public void testMapDtoToDom_expectCorrectFieldTypeResolution() throws Exception {
// Deps and fixture
ReferencesRegistry referencesRegistry = new Refs();
EasyCrudServiceResolver easyCrudServiceResolver = mock(EasyCrudServiceResolver.class);
DeviceService deviceService = mock(DeviceService.class);
when(deviceService.getEntityTypeMessageCode()).thenReturn(DeviceService.ENTITY_TYPE_MESSAGE_CODE);
when(easyCrudServiceResolver.resolveByDtoClass(DeviceRow.class)).thenReturn(deviceService);
when(easyCrudServiceResolver.resolveByEntityType(DeviceService.ENTITY_TYPE_MESSAGE_CODE)).thenReturn(deviceService);
EnvService envService = mock(EnvService.class);
when(envService.getEntityTypeMessageCode()).thenReturn(EnvService.ENTITY_TYPE_MESSAGE_CODE);
when(easyCrudServiceResolver.resolveByDtoClass(EnvironmentRow.class)).thenReturn(envService);
when(easyCrudServiceResolver.resolveByEntityType(EnvService.ENTITY_TYPE_MESSAGE_CODE)).thenReturn(envService);
DataSetLoaderImpl dataSetLoader = new DataSetLoaderImpl();
dataSetLoader.setEasyCrudServiceResolver(easyCrudServiceResolver);
dataSetLoader.setReferencesRegistry(referencesRegistry);
DomLoaderImpl f = new DomLoaderImpl(dataSetLoader, easyCrudServiceResolver);
// Setup DataSet
// DataSet ds = new DataSet();
EnvironmentRow envRow = new EnvironmentRow();
envRow.setId(1L);
envRow.setName("Hurray");
when(envService.query(any(), any(), any())).thenReturn(new PaginatedList<>(PagerParams.ALL, Arrays.asList(envRow), 1));
when(envService.findById(1L)).thenReturn(envRow);
// ds.get(EnvService.ENTITY_TYPE_MESSAGE_CODE).put(envRow);
DeviceRow deviceRow = new DeviceRow();
deviceRow.setId(2L);
deviceRow.setEnvId(1);
deviceRow.setName("Yes it is");
when(deviceService.query(any(), any())).thenReturn(new PaginatedList<>(PagerParams.ALL, Arrays.asList(deviceRow), 1));
when(deviceService.findById(2L)).thenReturn(deviceRow);
// ds.get(DeviceService.ENTITY_TYPE_MESSAGE_CODE).put(deviceRow);
// when(dataSetLoader.loadObjectsByIds(any(),
// anyString())).thenReturn(Arrays.asList(envRow));
// Now let's invoke it
Env env = f.load(Env.class, 1L, Refs.envDevices, Refs.deviceEnv);
// verify(deviceService, times(1)).query(any(), any(), any());
// verify(envService, times(1)).query(any(), any(), any());
// Verify
assertNotNull(env);
assertEquals("Hurray", env.getName());
assertNotNull(env.getDevices());
assertEquals(1, env.getDevices().size());
Device device = env.getDevices().get(0);
assertEquals("Yes it is", device.getName());
assertNotNull(device.getEnv());
assertEquals(env, device.getEnv());
}
Aggregations