Search in sources :

Example 1 with DataSetLoader

use of org.summerb.easycrud.api.relations.DataSetLoader in project summerb by skarpushin.

the class DataSetLoaderTest method testLoadObjectsByIds_ExpectOneLoadedOk.

@Test
public void testLoadObjectsByIds_ExpectOneLoadedOk() throws EntityNotFoundException, NotAuthorizedException, FieldValidationException {
    DataSetLoader loader = buildLoaderCase1();
    TestDto2 d2i1 = new TestDto2();
    d2i1.setEnv("d2i1");
    d2i1.setLinkToFullDonwload("asdad");
    d2i1 = testDto2Service.create(d2i1);
    List<HasId> result = loader.loadObjectsByIds(ids(d2i1), testDto2Service.getEntityTypeMessageCode());
    assertNotNull(result);
    assertEquals(1, result.size());
}
Also used : HasId(org.summerb.easycrud.api.dto.HasId) DataSetLoader(org.summerb.easycrud.api.relations.DataSetLoader) Test(org.junit.Test)

Example 2 with DataSetLoader

use of org.summerb.easycrud.api.relations.DataSetLoader in project summerb by skarpushin.

the class DataSetLoaderTest method testResolveReferencedObjects_ExpectWillNotTryToLoadNullReferences.

@Test
public void testResolveReferencedObjects_ExpectWillNotTryToLoadNullReferences() throws EntityNotFoundException, NotAuthorizedException, FieldValidationException {
    DataSetLoader loader = buildLoaderCase1();
    TestDto2 d2i1 = new TestDto2();
    d2i1.setEnv("required");
    d2i1.setLinkToFullDonwload("required");
    d2i1 = testDto2Service.create(d2i1);
    TestDto3 d3i1 = new TestDto3();
    d3i1.setLinkToDtoTwo(d2i1.getId());
    d3i1 = testDto3Service.create(d3i1);
    DataSet result = new DataSet();
    Map<String, Set<Object>> idsToLoad = new HashMap<String, Set<Object>>();
    idsToLoad.put(testDto3Service.getEntityTypeMessageCode(), ids(d3i1.getId()));
    loader.loadObjectsByIds(idsToLoad, result);
    loader.resolveReferencedObjects(result, Refs.ref3to2mand, Refs.ref3to1);
    assertNotNull(result.get(testDto2Service.getEntityTypeMessageCode()).find(d2i1.getId()));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) DataSet(org.summerb.easycrud.api.dto.datapackage.DataSet) DataSet(org.summerb.easycrud.api.dto.datapackage.DataSet) HashMap(java.util.HashMap) DataSetLoader(org.summerb.easycrud.api.relations.DataSetLoader) Test(org.junit.Test)

Example 3 with DataSetLoader

use of org.summerb.easycrud.api.relations.DataSetLoader in project summerb by skarpushin.

the class DataSetLoaderTest method testResolveReferencedObjects_ExpectOneToManyTwoParentsOneChildLoadedOk.

@Test
public void testResolveReferencedObjects_ExpectOneToManyTwoParentsOneChildLoadedOk() throws EntityNotFoundException, NotAuthorizedException, FieldValidationException {
    DataSetLoader loader = buildLoaderCase1();
    TestDto2 d2i1 = new TestDto2();
    d2i1.setEnv("required");
    d2i1.setLinkToFullDonwload("required");
    d2i1 = testDto2Service.create(d2i1);
    TestDto1 d1i1 = new TestDto1();
    d1i1.setEnv("required");
    d1i1.setLinkToFullDonwload("required");
    d1i1 = testDto1Service.create(d1i1);
    TestDto3 d3i1 = new TestDto3();
    d3i1.setLinkToDtoTwo(d2i1.getId());
    d3i1 = testDto3Service.create(d3i1);
    TestDto3 d3i2 = new TestDto3();
    d3i2.setLinkToDtoTwo(d2i1.getId());
    d3i2.setLinkToDtoOneOptional(d1i1.getId());
    d3i2 = testDto3Service.create(d3i2);
    DataSet result = new DataSet();
    result.get(testDto2Service.getEntityTypeMessageCode()).put(d2i1);
    result.get(testDto1Service.getEntityTypeMessageCode()).put(d1i1);
    loader.resolveReferencedObjects(result, Refs.ref3to2mand.reverse(), Refs.ref3to1.reverse());
    assertNotNull(result.get(testDto3Service.getEntityTypeMessageCode()).find(d3i1.getId()));
    assertNotNull(result.get(testDto3Service.getEntityTypeMessageCode()).find(d3i2.getId()));
}
Also used : DataSet(org.summerb.easycrud.api.dto.datapackage.DataSet) DataSetLoader(org.summerb.easycrud.api.relations.DataSetLoader) Test(org.junit.Test)

Example 4 with DataSetLoader

use of org.summerb.easycrud.api.relations.DataSetLoader in project summerb by skarpushin.

the class DataSetLoaderTest method testLoadObjectsByIds_ExpectCoupleOneLevelObjectsLoadedOK.

@Test
public void testLoadObjectsByIds_ExpectCoupleOneLevelObjectsLoadedOK() throws EntityNotFoundException, NotAuthorizedException, FieldValidationException {
    DataSetLoader loader = buildLoaderCase1();
    TestDto2 d2i1 = new TestDto2();
    d2i1.setEnv("d2i1");
    d2i1.setLinkToFullDonwload("asdad");
    d2i1 = testDto2Service.create(d2i1);
    TestDto3 d3i1 = new TestDto3();
    d3i1.setLinkToDtoTwo(d2i1.getId());
    d3i1.setLinkToDtoTwo(0);
    d3i1 = testDto3Service.create(d3i1);
    DataSet result = new DataSet();
    Map<String, Set<Object>> idsToLoad = new HashMap<String, Set<Object>>();
    idsToLoad.put(testDto2Service.getEntityTypeMessageCode(), ids(d2i1.getId()));
    idsToLoad.put(testDto3Service.getEntityTypeMessageCode(), ids(d3i1.getId()));
    loader.loadObjectsByIds(idsToLoad, result);
    assertNotNull(result.get(testDto2Service.getEntityTypeMessageCode()).find(d2i1.getId()));
    assertNotNull(result.get(testDto3Service.getEntityTypeMessageCode()).find(d3i1.getId()));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) DataSet(org.summerb.easycrud.api.dto.datapackage.DataSet) DataSet(org.summerb.easycrud.api.dto.datapackage.DataSet) HashMap(java.util.HashMap) DataSetLoader(org.summerb.easycrud.api.relations.DataSetLoader) Test(org.junit.Test)

Example 5 with DataSetLoader

use of org.summerb.easycrud.api.relations.DataSetLoader 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)

Aggregations

DataSetLoader (org.summerb.easycrud.api.relations.DataSetLoader)13 Test (org.junit.Test)12 DataSet (org.summerb.easycrud.api.dto.datapackage.DataSet)9 HasId (org.summerb.easycrud.api.dto.HasId)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 EasyCrudServiceResolver (org.summerb.easycrud.api.EasyCrudServiceResolver)2 Ref (org.summerb.easycrud.api.dto.relations.Ref)2 Preconditions (com.google.common.base.Preconditions)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 BeansException (org.springframework.beans.BeansException)1 InitializingBean (org.springframework.beans.factory.InitializingBean)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ApplicationContextAware (org.springframework.context.ApplicationContextAware)1