@Test public void testCreateGroupsWithoutMetaGroups() { Map<String, String> expected = Maps.newHashMap(); expected.put("foo", "foo"); Map<String, String> actual = GroupsHelper.createGroups(Collections.emptyMap(), Collections.singletonList("foo")); assertThat(actual).containsAllEntriesOf(expected); }
@Test(dataProvider = "getTestData") public void testCreateGroupsWithMetaGroups( String metaGrpName, List<String> grpName, Map<String, String> expected) { Map<String, List<String>> metaGroups = Maps.newHashMap(); metaGroups.put(metaGrpName, Collections.singletonList(metaGrpName)); Map<String, String> actual = GroupsHelper.createGroups(metaGroups, grpName); assertThat(actual).containsAllEntriesOf(expected); }
@Test public void addStatisticsToMonitorShouldAddToInternalMap() { this.mbeanStatsMonitor.addStatisticsToMonitor(this.stats); assertThat(mbeanStatsMonitor.statsMap).containsAllEntriesOf(this.expectedStatsMap); }
@Test public void constructorWhenAllParametersProvidedAndValidThenCreated() { OidcUserRequest userRequest = new OidcUserRequest( this.clientRegistration, this.accessToken, this.idToken, this.additionalParameters); assertThat(userRequest.getClientRegistration()).isEqualTo(this.clientRegistration); assertThat(userRequest.getAccessToken()).isEqualTo(this.accessToken); assertThat(userRequest.getIdToken()).isEqualTo(this.idToken); assertThat(userRequest.getAdditionalParameters()).containsAllEntriesOf(this.additionalParameters); } }
@Test public void constructorWhenAllParametersProvidedAndValidThenCreated() { OAuth2UserRequest userRequest = new OAuth2UserRequest( this.clientRegistration, this.accessToken, this.additionalParameters); assertThat(userRequest.getClientRegistration()).isEqualTo(this.clientRegistration); assertThat(userRequest.getAccessToken()).isEqualTo(this.accessToken); assertThat(userRequest.getAdditionalParameters()).containsAllEntriesOf(this.additionalParameters); } }
@Test public void authenticateWhenTokenSuccessResponseThenAdditionalParametersAddedToUserRequest() { Map<String, Object> claims = new HashMap<>(); claims.put(IdTokenClaimNames.ISS, "https://provider.com"); claims.put(IdTokenClaimNames.SUB, "subject1"); claims.put(IdTokenClaimNames.AUD, Arrays.asList("client1", "client2")); claims.put(IdTokenClaimNames.AZP, "client1"); this.setUpIdToken(claims); OidcUser principal = mock(OidcUser.class); List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER"); when(principal.getAuthorities()).thenAnswer( (Answer<List<GrantedAuthority>>) invocation -> authorities); ArgumentCaptor<OidcUserRequest> userRequestArgCaptor = ArgumentCaptor.forClass(OidcUserRequest.class); when(this.userService.loadUser(userRequestArgCaptor.capture())).thenReturn(principal); this.authenticationProvider.authenticate(new OAuth2LoginAuthenticationToken( this.clientRegistration, this.authorizationExchange)); assertThat(userRequestArgCaptor.getValue().getAdditionalParameters()).containsAllEntriesOf( this.accessTokenResponse.getAdditionalParameters()); }
@Test public void authenticateWhenTokenSuccessResponseThenAdditionalParametersAddedToUserRequest() { OAuth2AccessTokenResponse accessTokenResponse = this.accessTokenSuccessResponse(); when(this.accessTokenResponseClient.getTokenResponse(any())).thenReturn(accessTokenResponse); OAuth2User principal = mock(OAuth2User.class); List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER"); when(principal.getAuthorities()).thenAnswer( (Answer<List<GrantedAuthority>>) invocation -> authorities); ArgumentCaptor<OAuth2UserRequest> userRequestArgCaptor = ArgumentCaptor.forClass(OAuth2UserRequest.class); when(this.userService.loadUser(userRequestArgCaptor.capture())).thenReturn(principal); this.authenticationProvider.authenticate( new OAuth2LoginAuthenticationToken(this.clientRegistration, this.authorizationExchange)); assertThat(userRequestArgCaptor.getValue().getAdditionalParameters()).containsAllEntriesOf( accessTokenResponse.getAdditionalParameters()); }
@Test public void ensureGroupsPresentInInheritedMethods() { TestNG testng = create(ChildTest.class); LocalListener listener = new LocalListener(); testng.addListener(listener); testng.run(); Map<String, List<String>> expected = Maps.newHashMap(); expected.put("parentTestMethod", Collections.singletonList(MY_GROUP)); expected.put("childTestMethod", Collections.singletonList(MY_GROUP)); assertThat(listener.getMapping()).containsAllEntriesOf(expected); }
@Test public void testNegativeFlowForNativeInjectionOnTestMethods() { Map<String, String> failures = Maps.newHashMap(); failures.put( "m1", "Cannot inject @Test annotated Method [m1] with [interface org.testng.ITestResult]."); failures.put("m2", "Cannot inject @Test annotated Method [m2] with [int]."); TestNG testng = create(NegativeNativeInjectionTestSample.class); Github1649TestListener listener = new Github1649TestListener(); testng.addListener(listener); testng.run(); assertThat(listener.failures).containsAllEntriesOf(failures); }
@Test public void authenticateWhenTokenSuccessResponseThenAdditionalParametersAddedToUserRequest() { Map<String, Object> additionalParameters = new HashMap<>(); additionalParameters.put("param1", "value1"); additionalParameters.put("param2", "value2"); OAuth2AccessTokenResponse accessTokenResponse = OAuth2AccessTokenResponse.withToken("foo") .tokenType(OAuth2AccessToken.TokenType.BEARER) .additionalParameters(additionalParameters) .build(); when(this.accessTokenResponseClient.getTokenResponse(any())).thenReturn(Mono.just(accessTokenResponse)); DefaultOAuth2User user = new DefaultOAuth2User(AuthorityUtils.createAuthorityList("ROLE_USER"), Collections.singletonMap("user", "rob"), "user"); ArgumentCaptor<OAuth2UserRequest> userRequestArgCaptor = ArgumentCaptor.forClass(OAuth2UserRequest.class); when(this.userService.loadUser(userRequestArgCaptor.capture())).thenReturn(Mono.just(user)); this.manager.authenticate(loginToken()).block(); assertThat(userRequestArgCaptor.getValue().getAdditionalParameters()) .containsAllEntriesOf(accessTokenResponse.getAdditionalParameters()); }
@Test(description = "GITHUB-1878") public void testEnsureTestStatusIsSetProperlyForSkippedTests() { TestNG testng = create(TestClassSample.class); ReasonReporter reporter = new ReasonReporter(); testng.addListener(reporter); testng.run(); Map<String, Integer> actual = reporter.getResults(); Map<String, Integer> expected = Maps.newHashMap(); expected.put("test1min", ITestResult.SKIP); expected.put("test2min", ITestResult.SKIP); expected.put("setup", ITestResult.FAILURE); assertThat(actual).containsAllEntriesOf(expected); }
@Test public void authenticateWhenTokenSuccessResponseThenAdditionalParametersAddedToUserRequest() { ClientRegistration clientRegistration = this.registration.build(); Map<String, Object> additionalParameters = new HashMap<>(); additionalParameters.put(OidcParameterNames.ID_TOKEN, this.idToken.getTokenValue()); additionalParameters.put("param1", "value1"); additionalParameters.put("param2", "value2"); OAuth2AccessTokenResponse accessTokenResponse = OAuth2AccessTokenResponse.withToken("foo") .tokenType(OAuth2AccessToken.TokenType.BEARER) .additionalParameters(additionalParameters) .build(); Map<String, Object> claims = new HashMap<>(); claims.put(IdTokenClaimNames.ISS, "https://issuer.example.com"); claims.put(IdTokenClaimNames.SUB, "rob"); claims.put(IdTokenClaimNames.AUD, Arrays.asList(clientRegistration.getClientId())); Instant issuedAt = Instant.now(); Instant expiresAt = Instant.from(issuedAt).plusSeconds(3600); Jwt idToken = new Jwt("id-token", issuedAt, expiresAt, claims, claims); when(this.accessTokenResponseClient.getTokenResponse(any())).thenReturn(Mono.just(accessTokenResponse)); DefaultOidcUser user = new DefaultOidcUser(AuthorityUtils.createAuthorityList("ROLE_USER"), this.idToken); ArgumentCaptor<OidcUserRequest> userRequestArgCaptor = ArgumentCaptor.forClass(OidcUserRequest.class); when(this.userService.loadUser(userRequestArgCaptor.capture())).thenReturn(Mono.just(user)); when(this.jwtDecoder.decode(any())).thenReturn(Mono.just(idToken)); this.manager.setJwtDecoderFactory(c -> this.jwtDecoder); this.manager.authenticate(loginToken()).block(); assertThat(userRequestArgCaptor.getValue().getAdditionalParameters()) .containsAllEntriesOf(accessTokenResponse.getAdditionalParameters()); }
@Test(description = "GITHUB-1878") public void ensureSkipInfoHasFailedTestDetailsWhenInvolvingGroups() { XmlSuite xmlSuite = createXmlSuite("sample_suite"); createXmlTest(xmlSuite, "sample_test", TestClassWithGroupFailures.class); xmlSuite.getIncludedGroups().addAll(Arrays.asList("unit", "integration")); TestNG testng = create(xmlSuite); ReasonReporter reporter = new ReasonReporter(); testng.addListener(reporter); testng.run(); Map<String, String> expected = Maps.newHashMap(); expected.put("integrationTests", "unitTests"); assertThat(reporter.getSkippedInfo()).containsAllEntriesOf(expected); }
@Test public void testToEnsureProperTestResultIsReferredInNativeInjection() { TestNG testng = create(ChildClassSample.class); LocalReporter reporter = new LocalReporter(); testng.addListener(reporter); testng.run(); assertThat(reporter.getAttributes()).containsAllEntriesOf(expected()); }
@Test public void testClientRequest() throws Exception { tracingClientSOAPHandler.handleOutboundSOAPMessage(soapRequest); tracingClientSOAPHandler.handleInboundSOAPMessage(soapResponse); tracingClientSOAPHandler.close(soapResponse); verify(soapRequest).put(eq(MessageContext.HTTP_REQUEST_HEADERS), any()); assertThat(mockTracer.finishedSpans()).hasSize(1); final MockSpan span = mockTracer.finishedSpans().get(0); assertThat(span.operationName()).isEqualTo("operationName"); assertThat(span.tags()).containsAllEntriesOf(new HashMap<String, Object>() {{ put(SpanUtils.OPERATION_TYPE, "soap"); put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT); }}); assertThat(span.tags()).doesNotContainKeys("soap.request", "soap.response"); }
private static void runTest(Map<String, String> expected, Class<?>... clazz) { TestNG testng = create(clazz); ReasonReporter reporter = new ReasonReporter(); testng.addListener(reporter); testng.run(); assertThat(reporter.getSkippedInfo()).containsAllEntriesOf(expected); }
@Test public void testServerRequest() throws Exception { tracingServerSOAPHandler.handleInboundSOAPMessage(soapRequest); tracingServerSOAPHandler.handleOutboundSOAPMessage(soapResponse); tracingServerSOAPHandler.close(soapResponse); assertThat(mockTracer.finishedSpans()).hasSize(1); final MockSpan span = mockTracer.finishedSpans().get(0); assertThat(span.operationName()).isEqualTo("operationName"); assertThat(span.tags()).containsAllEntriesOf(new HashMap<String, Object>() {{ put(SpanUtils.OPERATION_TYPE, "soap"); put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); }}); assertThat(span.tags()).doesNotContainKeys("soap.request", "soap.response"); }
assertThat(processBuilder.environment) .contains(entry("VAR1", "valueOfVar1")) .containsAllEntriesOf(command.getEnvVariables());
private void assertHeaders() { WebTestClient client = buildClient(); FluxExchangeResult<String> response = client.get() .uri("https://example.com/") .exchange() .returnResult(String.class); Map<String, List<String>> responseHeaders = response.getResponseHeaders(); if (!this.expectedHeaders.isEmpty()) { assertThat(responseHeaders).describedAs(response.toString()) .containsAllEntriesOf(this.expectedHeaders); } if (!this.headerNamesNotPresent.isEmpty()) { assertThat(responseHeaders.keySet()).doesNotContainAnyElementsOf(this.headerNamesNotPresent); } }
private void assertHeaders() { WebTestClient client = buildClient(); FluxExchangeResult<String> response = client.get() .uri("https://example.com/") .headers(h -> h.setOrigin("https://origin.example.com")) .exchange() .returnResult(String.class); Map<String, List<String>> responseHeaders = response.getResponseHeaders(); if (!this.expectedHeaders.isEmpty()) { assertThat(responseHeaders).describedAs(response.toString()) .containsAllEntriesOf(this.expectedHeaders); } if (!this.headerNamesNotPresent.isEmpty()) { assertThat(responseHeaders.keySet()).doesNotContainAnyElementsOf(this.headerNamesNotPresent); } }