@Test public void doFilter_givenUrlMidIsValid() throws Exception { final String mId = "fdfb4933"; fakeRequest(mId, null); when(mpSvcMock.getMarketplaceById(mId)).thenReturn(new VOMarketplace()); mpCtxFilter.doFilter(requestMock, responseMock, chainMock); verify(sessionMock, times(1)).setAttribute( Matchers.eq(Constants.REQ_PARAM_MARKETPLACE_ID), Matchers.eq(mId)); // no MPL portal request, thus no redirect required verify(responseMock, never()).sendRedirect( Matchers.contains(Marketplace.PUBLIC_CATALOG_SITE)); // if mId given, do not use fallback via subscription key or cookie verify(mpSvcMock, never()).getMarketplaceForSubscription( Matchers.anyLong(), Matchers.anyString()); verify(requestMock, times(1)).getCookies(); verify(sessionMock, never()).setAttribute( Constants.REQ_PARAM_MARKETPLACE_ID, Any.class); assertEquals(mId, sessionMid); }
@Test public void doFilter_noValidMidInGivenUrl_mIdStoredInCookie() throws Exception { final String cookieId = fakeSetCookieMid( Constants.REQ_PARAM_MARKETPLACE_ID, "myMpId"); fakeUserLogin("myOrgId"); fakeCreateMarketplace(cookieId); mpCtxFilter.doFilter(requestMock, responseMock, chainMock); verify(sessionMock, atLeastOnce()).setAttribute( Constants.REQ_PARAM_MARKETPLACE_ID, cookieId); verify(sessionMock, never()).setAttribute( Constants.REQ_PARAM_MARKETPLACE_ID, Any.class); assertEquals(cookieId, sessionMid); }
@Test public void doFilter_MpRedirect() throws Exception { when(requestMock.getServletPath()).thenReturn( BaseBean.MARKETPLACE_REDIRECT); mpCtxFilter.doFilter(requestMock, responseMock, chainMock); // MPL portal request, thus no redirect required verify(responseMock, times(1)).sendRedirect( Matchers.contains(Marketplace.MARKETPLACE_ROOT)); // if mId given, do not use fallback via subscription key or cookie verify(mpSvcMock, never()).getMarketplaceForSubscription( Matchers.anyLong(), Matchers.anyString()); verify(requestMock, times(1)).getCookies(); verify(sessionMock, never()).setAttribute( Constants.REQ_PARAM_MARKETPLACE_ID, Any.class); }
@Test public void doFilter_noValidMidInGivenUrl_previousmIdStoredInCookieButMpDeletedMeanwhile() throws Exception { final String cookieId = fakeSetCookieMid( Constants.REQ_PARAM_MARKETPLACE_ID, "myMpId"); fakeUserLogin("myOrgId"); fakeCreateMarketplace(cookieId); when(mpSvcMock.getMarketplaceById(cookieId)).thenThrow( new ObjectNotFoundException()); when(mpSvcMock.getMarketplaceById("myOrgId")).thenThrow( new ObjectNotFoundException()); mpCtxFilter.doFilter(requestMock, responseMock, chainMock); verify(sessionMock, never()).setAttribute( Constants.REQ_PARAM_MARKETPLACE_ID, cookieId); verify(sessionMock, never()).setAttribute( Constants.REQ_PARAM_MARKETPLACE_ID, Any.class); assertEquals(null, sessionMid); }
@SuppressWarnings("unchecked") public void test_getLegalEntitiesByExternalIdBundle() throws Exception { LegalEntityMaster mock = mock(LegalEntityMaster.class); LegalEntitySearchRequest request = new LegalEntitySearchRequest(); request.addExternalId(ID1); request.addExternalId(ID2); request.setVersionCorrection(VC); ManageableLegalEntity legalentity = example(); LegalEntitySearchResult result = new LegalEntitySearchResult(); result.getDocuments().add(new LegalEntityDocument(legalentity)); when(mock.search(Matchers.<LegalEntitySearchRequest>argThat(Any.ANY))).thenReturn(result); ArgumentCaptor<LegalEntitySearchRequest> legalEntitySearchRequest = ArgumentCaptor.forClass(LegalEntitySearchRequest.class); MasterLegalEntitySource test = new MasterLegalEntitySource(mock); Collection<LegalEntity> testResult = test.get(BUNDLE); verify(mock, times(1)).search(legalEntitySearchRequest.capture()); assertEquals(request.getAttributes(), legalEntitySearchRequest.getValue().getAttributes()); assertEquals(request.getExternalIdSearch(), legalEntitySearchRequest.getValue().getExternalIdSearch()); assertEquals(VersionCorrection.LATEST, legalEntitySearchRequest.getValue().getVersionCorrection()); assertEquals(UID, testResult.iterator().next().getUniqueId()); assertEquals("Test", testResult.iterator().next().getName()); }
@SuppressWarnings("unchecked") public void test_getLegalEntity_ExternalId() throws Exception { LegalEntityMaster mock = mock(LegalEntityMaster.class); LegalEntitySearchRequest request = new LegalEntitySearchRequest(); request.addExternalId(ID1); request.addExternalId(ID2); request.setVersionCorrection(VC); ManageableLegalEntity legalentity = example(); LegalEntitySearchResult result = new LegalEntitySearchResult(); result.getDocuments().add(new LegalEntityDocument(legalentity)); ArgumentCaptor<LegalEntitySearchRequest> legalEntitySearchRequest = ArgumentCaptor.forClass(LegalEntitySearchRequest.class); when(mock.search(Matchers.<LegalEntitySearchRequest>argThat(Any.ANY))).thenReturn(result); MasterLegalEntitySource test = new MasterLegalEntitySource(mock); LegalEntity testResult = test.getSingle(BUNDLE); verify(mock, times(1)).search(legalEntitySearchRequest.capture()); assertEquals(UID, testResult.getUniqueId()); assertEquals("Test", testResult.getName()); }
@Test public void doFilter_noMidInGivenUrl() throws Exception { mpCtxFilter.doFilter(requestMock, responseMock, chainMock); verify(mpSvcMock, never()).getMarketplaceById(any(String.class)); verify(sessionMock, never()).setAttribute( Constants.REQ_PARAM_MARKETPLACE_ID, Any.class); }
@Test public void doFilter_noValidMidInGivenUrl_noSessionMid_MPLcontext() throws Exception { fakeUserLogin("myOrgId"); fakeRequest(null, "/marketplace/index.jsf"); mpCtxFilter.doFilter(requestMock, responseMock, chainMock); verify(sessionMock, never()).setAttribute( Constants.REQ_PARAM_MARKETPLACE_ID, Any.class); }
@Test public void shouldSerializeObjectMock() throws Exception { // given Any mock = mock(Any.class); // when ByteArrayOutputStream serialized = serializeMock(mock); // then deserializeMock(serialized, Any.class); }
@Test public void shouldSerializeRealPartialMock() throws Exception { // given Any mock = mock(Any.class, withSettings().serializable()); when(mock.matches(anyObject())).thenCallRealMethod(); // when ByteArrayOutputStream serialized = serializeMock(mock); // then Any readObject = deserializeMock(serialized, Any.class); readObject.matches(""); }
@Test public void should_serialize_object_mock() throws Exception { // when ByteArrayOutputStream serialized = serializeMock(any); // then deserializeMock(serialized, Any.class); }
@Test public void should_serialize_real_partial_mock() throws Exception { // given when(anyMock.matches(anyObject())).thenCallRealMethod(); // when ByteArrayOutputStream serialized = serializeMock(anyMock); // then Any readObject = deserializeMock(serialized, Any.class); readObject.matches(""); }
@Test public void should_serialize_object_mock() throws Exception { // given Any mock = mock(Any.class); // when ByteArrayOutputStream serialized = serializeMock(mock); // then deserializeMock(serialized, Any.class); }
@Test public void should_serialize_real_partial_mock() throws Exception { // given Any mock = mock(Any.class, withSettings().serializable()); when(mock.matches(anyObject())).thenCallRealMethod(); // when ByteArrayOutputStream serialized = serializeMock(mock); // then Any readObject = deserializeMock(serialized, Any.class); readObject.matches(""); }