SearchServiceFacadeImpl implements SearchServiceFacade { @Override public void saveQueryTemplates(List<DiskResourceQueryTemplate> queryTemplates, AsyncCallback<List<DiskResourceQueryTemplate>> callback) { String address = deProperties.getMuleServiceBaseUrl() + "saved-searches"; String payload = templateListToIndexedSplittablePayload(queryTemplates); ServiceCallWrapper wrapper = new ServiceCallWrapper(POST, address, payload); deServiceFacade.getServiceData(wrapper, new SavedSearchCallbackConverter(callback, queryTemplates, searchAbFactory)); } @Inject  SearchServiceFacadeImpl(final DiscEnvApiService deServiceFacade,
                                   final DEProperties deProperties,
                                   final SearchAutoBeanFactory searchAbFactory,
                                   final DiskResourceAutoBeanFactory drFactory,
                                   final UserInfo userInfo); @Override List<DiskResourceQueryTemplate> createFrozenList(List<DiskResourceQueryTemplate> queryTemplates); @Override void getSavedQueryTemplates(AsyncCallback<List<DiskResourceQueryTemplate>> callback); @Override void saveQueryTemplates(List<DiskResourceQueryTemplate> queryTemplates, AsyncCallback<List<DiskResourceQueryTemplate>> callback); @Override void deleteQueryTemplates(List<DiskResourceQueryTemplate> queryTemplates,
                                     AsyncCallback<List<DiskResourceQueryTemplate>> callback); @Override void submitSearchFromQueryTemplate(DiskResourceQueryTemplate queryTemplate, FilterPagingLoadConfigBean loadConfig, TYPE searchType, AsyncCallback<List<DiskResource>> callback);  }
@Test public void testSaveQueryTemplates_Case1() { unitUnderTest = new SearchServiceFacadeImpl(deServiceFacadeMock, deProperties, searchAbFactoryMock, drFactoryMock, userInfoMock){ String templateListToIndexedSplittablePayload(List<DiskResourceQueryTemplate> queryTemplates){ return "stubPayload"; } }; final String userName = "testSaveUsername"; when(userInfoMock.getUsername()).thenReturn(userName); final ArrayList<DiskResourceQueryTemplate> newArrayList = Lists.newArrayList(mock(DiskResourceQueryTemplate.class)); unitUnderTest.saveQueryTemplates(newArrayList, asyncQtListMock); ArgumentCaptor<ServiceCallWrapper> wrapperCaptor = ArgumentCaptor.forClass(ServiceCallWrapper.class); verify(deServiceFacadeMock).getServiceData(wrapperCaptor.capture(), asyncStringCaptor.capture()); final String expectedAddress = "saved-searches"; assertTrue("Verify expected endpoint construction", wrapperCaptor.getValue().getAddress().endsWith(expectedAddress)); assertEquals(Type.POST, wrapperCaptor.getValue().getType()); }
@Ignore("Unable to appropriately mock out Autobean factory") @Test public void testSaveQueryTemplates_Case2() { unitUnderTest = new SearchServiceFacadeImpl(deServiceFacadeMock, deProperties, searchAbFactoryMock, drFactoryMock, userInfoMock){ String templateListToIndexedSplittablePayload(List<DiskResourceQueryTemplate> queryTemplates){ return "stubPayload"; } }; DiskResourceQueryTemplate mock1 = mock(DiskResourceQueryTemplate.class); DiskResourceQueryTemplate mock2 = mock(DiskResourceQueryTemplate.class); when(mock1.getName()).thenReturn("a name"); final ArrayList<DiskResourceQueryTemplate> newArrayList = Lists.newArrayList(mock1, mock2); unitUnderTest.saveQueryTemplates(newArrayList, asyncQtListMock); ArgumentCaptor<ServiceCallWrapper> wrapperCaptor = ArgumentCaptor.forClass(ServiceCallWrapper.class); verify(deServiceFacadeMock).getServiceData(wrapperCaptor.capture(), asyncStringCaptor.capture()); String expectedBody = ""; assertEquals(expectedBody, wrapperCaptor.getValue().getBody()); }