use of org.summerb.approaches.jdbccrud.api.EasyCrudService in project summerb by skarpushin.
the class DataSetLoaderImplTest method testLoadObjectsByIds_ExpectManyLoadByStrings.
@Test
public void testLoadObjectsByIds_ExpectManyLoadByStrings() throws Exception {
DataSetLoaderImpl fixture = buildMockedInstance();
EasyCrudService service = Mockito.mock(EasyCrudService.class);
when(fixture.getEasyCrudServiceResolver().resolveByEntityType("dto1")).thenReturn(service);
Matcher<Query> matcher = IsEqual.equalTo(Query.n().in(HasId.FN_ID, new String[] { "s1", "s2" }));
PaginatedList mockret = new PaginatedList<>(new PagerParams(), Arrays.asList(new TestDto1(), new TestDto1()), 2);
when(service.query(any(PagerParams.class), argThat(matcher))).thenReturn(mockret);
List<HasId> ret = fixture.loadObjectsByIds(ids("s1", "s2"), "dto1");
assertNotNull(ret);
assertEquals(2, ret.size());
}
use of org.summerb.approaches.jdbccrud.api.EasyCrudService in project summerb by skarpushin.
the class DataSetLoaderImplTest method testLoadObjectsByIds_ExpectManyLoadByUnknownType.
@Test
public void testLoadObjectsByIds_ExpectManyLoadByUnknownType() throws Exception {
DataSetLoaderImpl fixture = buildMockedInstance();
EasyCrudService service = Mockito.mock(EasyCrudService.class);
when(fixture.getEasyCrudServiceResolver().resolveByEntityType("dto1")).thenReturn(service);
UUID d1 = UUID.randomUUID();
UUID d2 = UUID.randomUUID();
when(service.findById(d1)).thenReturn(new TestDto1());
when(service.findById(d2)).thenReturn(new TestDto1());
List<HasId> ret = fixture.loadObjectsByIds(ids(d1, d2), "dto1");
assertNotNull(ret);
assertEquals(2, ret.size());
}
use of org.summerb.approaches.jdbccrud.api.EasyCrudService in project summerb by skarpushin.
the class DataSetLoaderImplTest method testLoadObjectsByIds_ExpectManyLoadByLongsOk.
@Test
public void testLoadObjectsByIds_ExpectManyLoadByLongsOk() throws Exception {
DataSetLoaderImpl fixture = buildMockedInstance();
EasyCrudService service = Mockito.mock(EasyCrudService.class);
when(fixture.getEasyCrudServiceResolver().resolveByEntityType("dto1")).thenReturn(service);
Matcher<Query> matcher = IsEqual.equalTo(Query.n().in(HasId.FN_ID, new Long[] { 1L, 2L }));
PaginatedList mockret = new PaginatedList<>(new PagerParams(), Arrays.asList(new TestDto1(), new TestDto1()), 2);
when(service.query(any(PagerParams.class), argThat(matcher))).thenReturn(mockret);
List<HasId> ret = fixture.loadObjectsByIds(ids(1L, 2L), "dto1");
assertNotNull(ret);
assertEquals(2, ret.size());
}
use of org.summerb.approaches.jdbccrud.api.EasyCrudService in project summerb by skarpushin.
the class DataSetLoaderImplTest method testLoadObjectsByIds_ExpectOneLoadOk.
@Test
public void testLoadObjectsByIds_ExpectOneLoadOk() throws Exception {
DataSetLoaderImpl fixture = buildMockedInstance();
EasyCrudService service = Mockito.mock(EasyCrudService.class);
when(fixture.getEasyCrudServiceResolver().resolveByEntityType("dto1")).thenReturn(service);
TestDto1 dto = new TestDto1();
when(service.findById(1)).thenReturn(dto);
List<HasId> ret = fixture.loadObjectsByIds(ids(1), "dto1");
assertNotNull(ret);
assertEquals(1, ret.size());
assertEquals(dto, ret.get(0));
}
use of org.summerb.approaches.jdbccrud.api.EasyCrudService in project summerb by skarpushin.
the class DataSetLoaderImpl method loadManyToManyReferences.
private ManyToManyRefToReferenceesMap loadManyToManyReferences(Map<Ref, Set<Object>> manyToManyReferences) {
// NOTE: Queries to same types of referencees are not grouped. Should we
// impl this like we did for one2many?
ManyToManyRefToReferenceesMap ret = new ManyToManyRefToReferenceesMap();
for (Entry<Ref, Set<Object>> refToReferencersEntry : manyToManyReferences.entrySet()) {
EasyCrudService m2mServiceTmp = easyCrudServiceResolver.resolveByEntityType(refToReferencersEntry.getKey().getM2mEntity());
Preconditions.checkState(m2mServiceTmp instanceof EasyCrudM2mService);
EasyCrudM2mService m2mService = (EasyCrudM2mService) m2mServiceTmp;
Map<Object, List<HasId>> referenceeMap = m2mService.findReferenceeByReferencers(refToReferencersEntry.getValue());
ret.put(refToReferencersEntry.getKey(), referenceeMap);
}
return ret;
}
Aggregations