Search in sources :

Example 1 with EasyCrudServiceResolver

use of org.summerb.easycrud.api.EasyCrudServiceResolver in project summerb by skarpushin.

the class DomLoaderDeviceGatewayTest method testDiscoverDomFields.

@Test
public void testDiscoverDomFields() throws Exception {
    DataSetLoader dataSetLoader = mock(DataSetLoader.class);
    EasyCrudServiceResolver easyCrudServiceResolver = mock(EasyCrudServiceResolver.class);
    DomLoaderImpl f = new DomLoaderImpl(dataSetLoader, easyCrudServiceResolver);
    Map<String, Ref> refs = Collections.singletonMap(Refs.envDevices.getName(), Refs.envDevices);
    List<Pair<Ref, PropertyDescriptor>> domFields = f.discoverDomFields(Env.class, refs);
    assertNotNull(domFields);
    assertEquals(1, domFields.size());
    assertEquals("devices", domFields.get(0).getValue().getName());
}
Also used : Ref(org.summerb.easycrud.api.dto.relations.Ref) EasyCrudServiceResolver(org.summerb.easycrud.api.EasyCrudServiceResolver) DataSetLoader(org.summerb.easycrud.api.relations.DataSetLoader) Pair(org.summerb.utils.Pair) Test(org.junit.Test)

Example 2 with EasyCrudServiceResolver

use of org.summerb.easycrud.api.EasyCrudServiceResolver in project summerb by skarpushin.

the class DomLoaderDeviceGatewayTest method testResolveCollectionElementType_expectCorrectFieldTypeResolution.

@Test
public void testResolveCollectionElementType_expectCorrectFieldTypeResolution() {
    // Deps and fixture
    DataSetLoader dataSetLoader = mock(DataSetLoader.class);
    EasyCrudServiceResolver easyCrudServiceResolver = mock(EasyCrudServiceResolver.class);
    DomLoaderImpl f = new DomLoaderImpl(dataSetLoader, easyCrudServiceResolver);
    PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(Env.class, "devices");
    // test
    Class<HasId<Object>> elType = f.resolveCollectionElementType(pd);
    assertEquals(Device.class, elType);
}
Also used : HasId(org.summerb.easycrud.api.dto.HasId) EasyCrudServiceResolver(org.summerb.easycrud.api.EasyCrudServiceResolver) PropertyDescriptor(java.beans.PropertyDescriptor) DataSetLoader(org.summerb.easycrud.api.relations.DataSetLoader) Test(org.junit.Test)

Example 3 with EasyCrudServiceResolver

use of org.summerb.easycrud.api.EasyCrudServiceResolver 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());
}
Also used : ReferencesRegistry(org.summerb.easycrud.api.relations.ReferencesRegistry) EnvService(org.summerb.easycrud.impl.relations.example.EnvService) EasyCrudServiceResolver(org.summerb.easycrud.api.EasyCrudServiceResolver) Refs(org.summerb.easycrud.impl.relations.example.Refs) DeviceRow(org.summerb.easycrud.impl.relations.example.DeviceRow) Device(org.summerb.easycrud.impl.relations.example.Device) DeviceService(org.summerb.easycrud.impl.relations.example.DeviceService) Env(org.summerb.easycrud.impl.relations.example.Env) EnvironmentRow(org.summerb.easycrud.impl.relations.example.EnvironmentRow) Test(org.junit.Test)

Example 4 with EasyCrudServiceResolver

use of org.summerb.easycrud.api.EasyCrudServiceResolver in project summerb by skarpushin.

the class DataSetLoaderImplTest method buildMockedInstance.

private DataSetLoaderImpl buildMockedInstance() {
    DataSetLoaderImpl ret = new DataSetLoaderImpl();
    EasyCrudServiceResolver easyCrudServiceResolver = Mockito.mock(EasyCrudServiceResolver.class);
    ret.setEasyCrudServiceResolver(easyCrudServiceResolver);
    ReferencesRegistry referencesRegistry = Mockito.mock(ReferencesRegistry.class);
    ret.setReferencesRegistry(referencesRegistry);
    return ret;
}
Also used : ReferencesRegistry(org.summerb.easycrud.api.relations.ReferencesRegistry) EasyCrudServiceResolver(org.summerb.easycrud.api.EasyCrudServiceResolver)

Aggregations

EasyCrudServiceResolver (org.summerb.easycrud.api.EasyCrudServiceResolver)4 Test (org.junit.Test)3 DataSetLoader (org.summerb.easycrud.api.relations.DataSetLoader)2 ReferencesRegistry (org.summerb.easycrud.api.relations.ReferencesRegistry)2 PropertyDescriptor (java.beans.PropertyDescriptor)1 HasId (org.summerb.easycrud.api.dto.HasId)1 Ref (org.summerb.easycrud.api.dto.relations.Ref)1 Device (org.summerb.easycrud.impl.relations.example.Device)1 DeviceRow (org.summerb.easycrud.impl.relations.example.DeviceRow)1 DeviceService (org.summerb.easycrud.impl.relations.example.DeviceService)1 Env (org.summerb.easycrud.impl.relations.example.Env)1 EnvService (org.summerb.easycrud.impl.relations.example.EnvService)1 EnvironmentRow (org.summerb.easycrud.impl.relations.example.EnvironmentRow)1 Refs (org.summerb.easycrud.impl.relations.example.Refs)1 Pair (org.summerb.utils.Pair)1