Search in sources :

Example 1 with TestDto1

use of integr.org.summerb.jdbccrud.TestDto1 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());
}
Also used : HasId(org.summerb.approaches.jdbccrud.api.dto.HasId) 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) TestDto1(integr.org.summerb.jdbccrud.TestDto1) Test(org.junit.Test)

Example 2 with TestDto1

use of integr.org.summerb.jdbccrud.TestDto1 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());
}
Also used : HasId(org.summerb.approaches.jdbccrud.api.dto.HasId) DataSetLoaderImpl(org.summerb.approaches.jdbccrud.impl.relations.DataSetLoaderImpl) EasyCrudService(org.summerb.approaches.jdbccrud.api.EasyCrudService) UUID(java.util.UUID) TestDto1(integr.org.summerb.jdbccrud.TestDto1) Test(org.junit.Test)

Example 3 with TestDto1

use of integr.org.summerb.jdbccrud.TestDto1 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());
}
Also used : HasId(org.summerb.approaches.jdbccrud.api.dto.HasId) 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) TestDto1(integr.org.summerb.jdbccrud.TestDto1) Test(org.junit.Test)

Example 4 with TestDto1

use of integr.org.summerb.jdbccrud.TestDto1 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));
}
Also used : HasId(org.summerb.approaches.jdbccrud.api.dto.HasId) DataSetLoaderImpl(org.summerb.approaches.jdbccrud.impl.relations.DataSetLoaderImpl) EasyCrudService(org.summerb.approaches.jdbccrud.api.EasyCrudService) TestDto1(integr.org.summerb.jdbccrud.TestDto1) Test(org.junit.Test)

Example 5 with TestDto1

use of integr.org.summerb.jdbccrud.TestDto1 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)

Aggregations

TestDto1 (integr.org.summerb.jdbccrud.TestDto1)5 Test (org.junit.Test)5 EasyCrudService (org.summerb.approaches.jdbccrud.api.EasyCrudService)5 DataSetLoaderImpl (org.summerb.approaches.jdbccrud.impl.relations.DataSetLoaderImpl)5 HasId (org.summerb.approaches.jdbccrud.api.dto.HasId)4 PagerParams (org.summerb.approaches.jdbccrud.api.dto.PagerParams)2 PaginatedList (org.summerb.approaches.jdbccrud.api.dto.PaginatedList)2 Query (org.summerb.approaches.jdbccrud.api.query.Query)2 TestDto2 (integr.org.summerb.jdbccrud.TestDto2)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 UUID (java.util.UUID)1 DataSet (org.summerb.approaches.jdbccrud.api.dto.datapackage.DataSet)1