Search in sources :

Example 11 with EasyCrudService

use of org.summerb.approaches.jdbccrud.api.EasyCrudService in project summerb by skarpushin.

the class EasyCrudServiceResolverSpringImpl method resolveByEntityType.

@Override
public EasyCrudService resolveByEntityType(String entityName) {
    EasyCrudService ret = getServicesMap().get(entityName);
    Preconditions.checkArgument(ret != null, "Serivce for that entity wasn't found: " + entityName);
    return ret;
}
Also used : EasyCrudService(org.summerb.approaches.jdbccrud.api.EasyCrudService)

Example 12 with EasyCrudService

use of org.summerb.approaches.jdbccrud.api.EasyCrudService in project summerb by skarpushin.

the class EasyCrudServiceResolverSpringImpl method discoverServices.

private Map<String, EasyCrudService> discoverServices() {
    Preconditions.checkState(applicationContext != null, "applicationContext expected to be injected");
    Map<String, EasyCrudService> foundBeans = applicationContext.getBeansOfType(EasyCrudService.class);
    Map<String, EasyCrudService> ret = new HashMap<>();
    for (Entry<String, EasyCrudService> entry : foundBeans.entrySet()) {
        EasyCrudService service = entry.getValue();
        EasyCrudService wasOverwritten = ret.put(service.getEntityTypeMessageCode(), service);
        if (wasOverwritten != null) {
            log.warn("Ambigious EasyCrudService for same entityTypeMessageCode 1st " + wasOverwritten + " and 2nd " + service + " named " + entry.getKey());
        }
    }
    return ret;
}
Also used : EasyCrudService(org.summerb.approaches.jdbccrud.api.EasyCrudService) HashMap(java.util.HashMap)

Example 13 with EasyCrudService

use of org.summerb.approaches.jdbccrud.api.EasyCrudService in project summerb by skarpushin.

the class DataSetLoaderImplTest method testLoadObjectsByIds_ExpectTwoDifferentObjectsLoadedOk.

@Test
public void testLoadObjectsByIds_ExpectTwoDifferentObjectsLoadedOk() throws Exception {
    DataSetLoaderImpl fixture = buildMockedInstance();
    EasyCrudService service1 = Mockito.mock(EasyCrudService.class);
    when(fixture.getEasyCrudServiceResolver().resolveByEntityType("dto1")).thenReturn(service1);
    TestDto1 dto1 = new TestDto1();
    dto1.setId("d1");
    when(service1.findById("d1")).thenReturn(dto1);
    EasyCrudService service2 = Mockito.mock(EasyCrudService.class);
    when(fixture.getEasyCrudServiceResolver().resolveByEntityType("dto2")).thenReturn(service2);
    TestDto2 dto2 = new TestDto2();
    dto2.setId(2L);
    when(service2.findById(2L)).thenReturn(dto2);
    DataSet ret = new DataSet();
    Map<String, Set<Object>> ids = new HashMap<>();
    ids.put("dto1", ids("d1"));
    ids.put("dto2", ids(2L));
    fixture.loadObjectsByIds(ids, ret);
    assertNotNull(ret.get("dto1"));
    assertNotNull(ret.get("dto1").find("d1"));
    assertNotNull(ret.get("dto2"));
    assertNotNull(ret.get("dto2").find(2L));
}
Also used : DataSetLoaderImpl(org.summerb.approaches.jdbccrud.impl.relations.DataSetLoaderImpl) EasyCrudService(org.summerb.approaches.jdbccrud.api.EasyCrudService) HashSet(java.util.HashSet) Set(java.util.Set) DataSet(org.summerb.approaches.jdbccrud.api.dto.datapackage.DataSet) DataSet(org.summerb.approaches.jdbccrud.api.dto.datapackage.DataSet) HashMap(java.util.HashMap) TestDto1(integr.org.summerb.jdbccrud.TestDto1) TestDto2(integr.org.summerb.jdbccrud.TestDto2) Test(org.junit.Test)

Example 14 with EasyCrudService

use of org.summerb.approaches.jdbccrud.api.EasyCrudService in project summerb by skarpushin.

the class DataSetLoaderImplTest method testLoadObjectsByIds_ExpectOneLoadNfe.

@Test(expected = GenericEntityNotFoundException.class)
public void testLoadObjectsByIds_ExpectOneLoadNfe() throws Exception {
    DataSetLoaderImpl fixture = buildMockedInstance();
    EasyCrudService service = Mockito.mock(EasyCrudService.class);
    when(fixture.getEasyCrudServiceResolver().resolveByEntityType("dto1")).thenReturn(service);
    when(service.findById(1)).thenReturn(null);
    fixture.loadObjectsByIds(ids(1), "dto1");
}
Also used : DataSetLoaderImpl(org.summerb.approaches.jdbccrud.impl.relations.DataSetLoaderImpl) EasyCrudService(org.summerb.approaches.jdbccrud.api.EasyCrudService) Test(org.junit.Test)

Example 15 with EasyCrudService

use of org.summerb.approaches.jdbccrud.api.EasyCrudService in project summerb by skarpushin.

the class DataSetLoaderImplTest method testLoadObjectsByIds_ExpectManyLoadByLongsNfe.

@Test(expected = GenericEntityNotFoundException.class)
public void testLoadObjectsByIds_ExpectManyLoadByLongsNfe() throws Exception {
    DataSetLoaderImpl fixture = buildMockedInstance();
    EasyCrudService service = Mockito.mock(EasyCrudService.class);
    when(fixture.getEasyCrudServiceResolver().resolveByEntityType("dto1")).thenReturn(service);
    PaginatedList mockret = new PaginatedList<>(new PagerParams(), Collections.emptyList(), 0);
    when(service.query(any(PagerParams.class), any(Query.class))).thenReturn(mockret);
    fixture.loadObjectsByIds(ids(1L, 2L), "dto1");
}
Also used : DataSetLoaderImpl(org.summerb.approaches.jdbccrud.impl.relations.DataSetLoaderImpl) EasyCrudService(org.summerb.approaches.jdbccrud.api.EasyCrudService) Query(org.summerb.approaches.jdbccrud.api.query.Query) PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) PaginatedList(org.summerb.approaches.jdbccrud.api.dto.PaginatedList) Test(org.junit.Test)

Aggregations

EasyCrudService (org.summerb.approaches.jdbccrud.api.EasyCrudService)16 Test (org.junit.Test)8 HasId (org.summerb.approaches.jdbccrud.api.dto.HasId)7 DataSetLoaderImpl (org.summerb.approaches.jdbccrud.impl.relations.DataSetLoaderImpl)7 TestDto1 (integr.org.summerb.jdbccrud.TestDto1)5 PaginatedList (org.summerb.approaches.jdbccrud.api.dto.PaginatedList)5 Query (org.summerb.approaches.jdbccrud.api.query.Query)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 PagerParams (org.summerb.approaches.jdbccrud.api.dto.PagerParams)3 DataSet (org.summerb.approaches.jdbccrud.api.dto.datapackage.DataSet)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Ref (org.summerb.approaches.jdbccrud.api.dto.relations.Ref)2 TestDto2 (integr.org.summerb.jdbccrud.TestDto2)1 Entry (java.util.Map.Entry)1 UUID (java.util.UUID)1 DataTable (org.summerb.approaches.jdbccrud.api.dto.datapackage.DataTable)1