Search in sources :

Example 1 with StringIdAliasDao

use of org.summerb.microservices.properties.impl.dao.StringIdAliasDao in project summerb by skarpushin.

the class StringIdAliasServiceEagerImplFactory method createDaoMock.

private static StringIdAliasDao createDaoMock() {
    StringIdAliasDao ret = Mockito.mock(StringIdAliasDao.class);
    when(ret.createAliasFor(NAME)).thenReturn(NAME_ALIAS);
    when(ret.findAliasFor(NAME)).thenReturn(NAME_ALIAS);
    when(ret.loadAllAliases(any(PagerParams.class))).thenAnswer(new Answer<PaginatedList<Entry<String, Long>>>() {

        @Override
        public PaginatedList<Entry<String, Long>> answer(InvocationOnMock invocation) throws Throwable {
            PagerParams pagerParams = (PagerParams) invocation.getArguments()[0];
            // Synthetic pause, simulate
            Thread.sleep(250);
            PaginatedList<Entry<String, Long>> result = new PaginatedList<Entry<String, Long>>();
            result.setPagerParams(pagerParams);
            result.setTotalResults(150);
            ArrayList<Entry<String, Long>> items = new ArrayList<Entry<String, Long>>();
            result.setItems(items);
            long offset = pagerParams.getOffset();
            long max = -1;
            if (offset == 0) {
                max = 100;
            } else if (offset == 100) {
                max = 50;
            } else {
                fail();
            }
            for (long i = offset; i < max; i++) {
                items.add(new AliasEntry("str" + i, i));
            }
            return result;
        }
    });
    return ret;
}
Also used : PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) ArrayList(java.util.ArrayList) StringIdAliasDao(org.summerb.microservices.properties.impl.dao.StringIdAliasDao) AliasEntry(org.summerb.microservices.properties.impl.dao.AliasEntry) Entry(java.util.Map.Entry) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PaginatedList(org.summerb.approaches.jdbccrud.api.dto.PaginatedList) AliasEntry(org.summerb.microservices.properties.impl.dao.AliasEntry)

Example 2 with StringIdAliasDao

use of org.summerb.microservices.properties.impl.dao.StringIdAliasDao in project summerb by skarpushin.

the class StringIdAliasServiceEagerImplTest method testLoadAllAliases_whitebox_expectExceptionOnException.

@Test(expected = RuntimeException.class)
public void testLoadAllAliases_whitebox_expectExceptionOnException() {
    StringIdAliasServiceEagerImpl fixture = new StringIdAliasServiceEagerImpl();
    StringIdAliasDao stringIdAliasDao = Mockito.mock(StringIdAliasDao.class);
    when(stringIdAliasDao.loadAllAliases(any(PagerParams.class))).thenThrow(new IllegalStateException("test exception"));
    fixture.loadAllAliases();
    fail();
}
Also used : PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) StringIdAliasDao(org.summerb.microservices.properties.impl.dao.StringIdAliasDao) Test(org.junit.Test)

Example 3 with StringIdAliasDao

use of org.summerb.microservices.properties.impl.dao.StringIdAliasDao in project summerb by skarpushin.

the class StringIdAliasServiceEagerImplTest method testGetAliases_whitebox_expectExceptionOnException.

@Test(expected = RuntimeException.class)
public void testGetAliases_whitebox_expectExceptionOnException() {
    StringIdAliasServiceEagerImpl fixture = new StringIdAliasServiceEagerImpl();
    StringIdAliasDao stringIdAliasDao = Mockito.mock(StringIdAliasDao.class);
    when(stringIdAliasDao.loadAllAliases(any(PagerParams.class))).thenThrow(new IllegalStateException("test exception"));
    fixture.getAliases();
    fail();
}
Also used : PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) StringIdAliasDao(org.summerb.microservices.properties.impl.dao.StringIdAliasDao) Test(org.junit.Test)

Aggregations

PagerParams (org.summerb.approaches.jdbccrud.api.dto.PagerParams)3 StringIdAliasDao (org.summerb.microservices.properties.impl.dao.StringIdAliasDao)3 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 PaginatedList (org.summerb.approaches.jdbccrud.api.dto.PaginatedList)1 AliasEntry (org.summerb.microservices.properties.impl.dao.AliasEntry)1