Search in sources :

Example 6 with EasyCrudService

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

the class GenericCrudServiceTestTemplate method testServiceResolver_expectOneServicesFound.

@SuppressWarnings("rawtypes")
@Test
public void testServiceResolver_expectOneServicesFound() {
    EasyCrudService service = easyCrudServiceResolver.resolveByEntityType(TestDto1.class.getCanonicalName());
    assertNotNull(service);
    assertEquals(TestDto1.class.getCanonicalName(), service.getEntityTypeMessageCode());
}
Also used : EasyCrudService(org.summerb.easycrud.api.EasyCrudService) Test(org.junit.Test)

Example 7 with EasyCrudService

use of org.summerb.easycrud.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 : EasyCrudService(org.summerb.easycrud.api.EasyCrudService) Test(org.junit.Test)

Example 8 with EasyCrudService

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

Example 9 with EasyCrudService

use of org.summerb.easycrud.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());
}
Also used : HasId(org.summerb.easycrud.api.dto.HasId) EasyCrudService(org.summerb.easycrud.api.EasyCrudService) Query(org.summerb.easycrud.api.query.Query) PagerParams(org.summerb.easycrud.api.dto.PagerParams) PaginatedList(org.summerb.easycrud.api.dto.PaginatedList) TestDto1(integr.org.summerb.easycrud.TestDto1) Test(org.junit.Test)

Example 10 with EasyCrudService

use of org.summerb.easycrud.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());
}
Also used : HasId(org.summerb.easycrud.api.dto.HasId) EasyCrudService(org.summerb.easycrud.api.EasyCrudService) Query(org.summerb.easycrud.api.query.Query) PagerParams(org.summerb.easycrud.api.dto.PagerParams) PaginatedList(org.summerb.easycrud.api.dto.PaginatedList) TestDto1(integr.org.summerb.easycrud.TestDto1) Test(org.junit.Test)

Aggregations

EasyCrudService (org.summerb.easycrud.api.EasyCrudService)17 Test (org.junit.Test)8 HasId (org.summerb.easycrud.api.dto.HasId)8 TestDto1 (integr.org.summerb.easycrud.TestDto1)5 PaginatedList (org.summerb.easycrud.api.dto.PaginatedList)5 Query (org.summerb.easycrud.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.easycrud.api.dto.PagerParams)3 DataSet (org.summerb.easycrud.api.dto.datapackage.DataSet)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Ref (org.summerb.easycrud.api.dto.relations.Ref)2 TestDto2 (integr.org.summerb.easycrud.TestDto2)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Entry (java.util.Map.Entry)1 UUID (java.util.UUID)1