use of org.mockito.ArgumentCaptor in project Gaffer by gchq.
the class AbstractSampleElementsForSplitPointsHandlerTest method shouldUseFullSampleOfAllElementsByDefault.
@Test
public void shouldUseFullSampleOfAllElementsByDefault() throws OperationException {
// Given
final int numSplits = 3;
final List<Element> elements = IntStream.range(0, numSplits).mapToObj(i -> new Entity(TestGroups.ENTITY, "vertex_" + i)).collect(Collectors.toList());
final AbstractSampleElementsForSplitPointsHandler<?, S> handler = createHandler();
final SampleElementsForSplitPoints operation = new SampleElementsForSplitPoints.Builder<>().input(elements).numSplits(numSplits).build();
final S store = createStore();
// When
handler.doOperation(operation, new Context(), store);
// Then
final ArgumentCaptor<GenerateSplitPointsFromSample> generateSplitPointsFromSampleCaptor = ArgumentCaptor.forClass(GenerateSplitPointsFromSample.class);
verify(store).execute(generateSplitPointsFromSampleCaptor.capture(), any(Context.class));
assertExpectedNumberOfSplitPointsAndSampleSize(generateSplitPointsFromSampleCaptor, numSplits, elements.size());
}
use of org.mockito.ArgumentCaptor in project Gaffer by gchq.
the class AbstractSampleElementsForSplitPointsHandlerTest method shouldFilterOutNulls.
@Test
public void shouldFilterOutNulls() throws OperationException {
// Given
final int numSplits = 3;
final List<Element> elements = IntStream.range(0, numSplits).mapToObj(i -> new Entity(TestGroups.ENTITY, "vertex_" + i)).collect(Collectors.toList());
final List<Element> elementsWithNulls = new ArrayList<>();
elementsWithNulls.add(null);
elementsWithNulls.addAll(elements);
elementsWithNulls.add(null);
final AbstractSampleElementsForSplitPointsHandler<?, S> handler = createHandler();
final SampleElementsForSplitPoints operation = new SampleElementsForSplitPoints.Builder<>().input(elementsWithNulls).numSplits(numSplits).build();
final S store = createStore();
// When
handler.doOperation(operation, new Context(), store);
// Then
final ArgumentCaptor<GenerateSplitPointsFromSample> generateSplitPointsFromSampleCaptor = ArgumentCaptor.forClass(GenerateSplitPointsFromSample.class);
verify(store).execute(generateSplitPointsFromSampleCaptor.capture(), any(Context.class));
assertExpectedNumberOfSplitPointsAndSampleSize(generateSplitPointsFromSampleCaptor, numSplits, elements.size());
}
use of org.mockito.ArgumentCaptor in project ddf by codice.
the class OAuthPluginTest method testNoStoredTokensExistingTokenUnderDifferentSourceExpiredTokens.
@Test(expected = OAuthPluginException.class)
public void testNoStoredTokensExistingTokenUnderDifferentSourceExpiredTokens() throws Exception {
OAuthFederatedSource source = oauthPlugin.oauthSource;
Subject subject = getSubject();
QueryRequest input = mock(QueryRequest.class);
when(input.getProperties()).thenReturn(ImmutableMap.of(SECURITY_SUBJECT, subject));
String accessToken = getAccessTokenBuilder().withExpiresAt(new Date(Instant.now().minus(1, ChronoUnit.MINUTES).toEpochMilli())).sign(validAlgorithm);
String refreshToken = getRefreshTokenBuilder().withExpiresAt(new Date(Instant.now().minus(1, ChronoUnit.MINUTES).toEpochMilli())).sign(validAlgorithm);
TokenInformation.TokenEntry tokenEntry = new TokenInformationImpl.TokenEntryImpl(accessToken, refreshToken, METADATA_ENDPOINT);
TokenInformation tokenInformation = mock(TokenInformation.class);
when(tokenInformation.getDiscoveryUrls()).thenReturn(Collections.singleton(METADATA_ENDPOINT));
when(tokenInformation.getTokenEntries()).thenReturn(Collections.singletonMap("OS", tokenEntry));
Map<String, Map<String, Object>> stateMap = mock(Map.class);
when(tokenStorage.getStateMap()).thenReturn(stateMap);
when(tokenStorage.read(SESSION, SOURCE_ID)).thenReturn(null);
when(tokenStorage.read(SESSION)).thenReturn(tokenInformation);
try {
oauthPlugin.process(source, input);
} catch (OAuthPluginException e) {
assertEquals(e.getSourceId(), CSW_SOURCE);
assertEquals(e.getErrorType().getStatusCode(), 401);
ArgumentCaptor<Map<String, Object>> captor = ArgumentCaptor.forClass(Map.class);
verify(stateMap, times(1)).put(anyString(), captor.capture());
assertUrl(e, captor.getValue());
throw e;
}
}
use of org.mockito.ArgumentCaptor in project ddf by codice.
the class OAuthPluginTest method testDifferentDiscoveryUrl.
@Test(expected = OAuthPluginException.class)
public void testDifferentDiscoveryUrl() throws Exception {
OAuthFederatedSource source = oauthPlugin.oauthSource;
Subject subject = getSubject();
QueryRequest input = mock(QueryRequest.class);
when(input.getProperties()).thenReturn(ImmutableMap.of(SECURITY_SUBJECT, subject));
Map<String, Map<String, Object>> stateMap = mock(Map.class);
String accessToken = getAccessTokenBuilder().sign(validAlgorithm);
TokenInformation.TokenEntry tokenEntry = new TokenInformationImpl.TokenEntryImpl(accessToken, "refresh_token", "http://example.com");
when(tokenStorage.read(SESSION, CSW_SOURCE)).thenReturn(tokenEntry);
when(tokenStorage.getStateMap()).thenReturn(stateMap);
try {
oauthPlugin.process(source, input);
} catch (OAuthPluginException e) {
verify(tokenStorage, times(1)).delete(SESSION, CSW_SOURCE);
verify(tokenStorage, times(1)).getStateMap();
ArgumentCaptor<Map<String, Object>> captor = ArgumentCaptor.forClass(Map.class);
verify(stateMap, times(1)).put(anyString(), captor.capture());
assertUrl(e, captor.getValue());
throw e;
}
}
use of org.mockito.ArgumentCaptor in project spring-data-mongodb by spring-projects.
the class ReactiveChangeStreamOperationSupportUnitTests method optionsShouldBeCombinedCorrectly.
// DATAMONGO-2089
@Test
void optionsShouldBeCombinedCorrectly() {
Document filter = new Document("$match", new Document("operationType", "insert"));
Instant resumeTimestamp = Instant.now();
changeStreamSupport.changeStream(Document.class).withOptions(options -> {
options.filter(filter);
}).resumeAt(resumeTimestamp).listen().subscribe();
ArgumentCaptor<ChangeStreamOptions> optionsArgumentCaptor = ArgumentCaptor.forClass(ChangeStreamOptions.class);
verify(template).changeStream(isNull(), optionsArgumentCaptor.capture(), eq(Document.class));
assertThat(optionsArgumentCaptor.getValue()).satisfies(it -> {
assertThat(it.getFilter().get()).isEqualTo(Collections.singletonList(filter));
assertThat(it.getResumeTimestamp()).contains(resumeTimestamp);
});
}
Aggregations