Search in sources :

Example 36 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.

the class TestGeoNamesWebService method testGeoNamesQueryNoInternetConnection.

@Test
public void testGeoNamesQueryNoInternetConnection() {
    WebClient mockWebClient = mock(WebClient.class);
    when(mockWebClient.acceptEncoding(anyString())).thenReturn(mockWebClient);
    when(mockWebClient.accept(anyString())).thenReturn(mockWebClient);
    doThrow(WebApplicationException.class).when(mockWebClient).get(String.class);
    doReturn(mockWebClient).when(webServiceSpy).createWebClient(anyString());
    Optional<String> countryCode = webServiceSpy.getCountryCode(QUERY_TEST_LOCATION, 10);
    assertThat(countryCode, is(Optional.empty()));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 37 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.

the class RestSecurityTest method testSetSubjectOnClient.

@Test
public void testSetSubjectOnClient() throws Exception {
    Element samlToken = readDocument("/saml.xml").getDocumentElement();
    Subject subject = mock(Subject.class);
    SecurityAssertion assertion = mock(SecurityAssertion.class);
    SecurityToken token = new SecurityToken(UUID.randomUUID().toString(), samlToken, new Date(), new Date());
    when(assertion.getSecurityToken()).thenReturn(token);
    when(subject.getPrincipals()).thenReturn(new SimplePrincipalCollection(assertion, "sts"));
    WebClient client = WebClient.create("https://example.org");
    RestSecurity.setSubjectOnClient(subject, client);
    assertNotNull(client.getHeaders().get(RestSecurity.AUTH_HEADER));
    ArrayList headers = (ArrayList) client.getHeaders().get(RestSecurity.AUTH_HEADER);
    boolean containsSaml = false;
    for (Object header : headers) {
        if (StringUtils.contains(header.toString(), RestSecurity.SAML_HEADER_PREFIX)) {
            containsSaml = true;
        }
    }
    assertTrue(containsSaml);
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SecurityAssertion(ddf.security.assertion.SecurityAssertion) WebClient(org.apache.cxf.jaxrs.client.WebClient) Subject(ddf.security.Subject) Date(java.util.Date) Test(org.junit.Test)

Example 38 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project midpoint by Evolveum.

the class TestAbstractRestService method test121AddUserDarthAdder.

@Test
public void test121AddUserDarthAdder() throws Exception {
    final String TEST_NAME = "test121AddUserDarthAdder";
    displayTestTile(this, TEST_NAME);
    WebClient client = prepareClient();
    client.path("/users");
    getDummyAuditService().clear();
    TestUtil.displayWhen(TEST_NAME);
    Response response = client.post(getRepoFile(USER_DARTHADDER_FILE));
    TestUtil.displayThen(TEST_NAME);
    displayResponse(response);
    assertStatus(response, 201);
    IntegrationTestTools.display("Audit", getDummyAuditService());
    getDummyAuditService().assertRecords(4);
    getDummyAuditService().assertLoginLogout(SchemaConstants.CHANNEL_REST_URI);
    getDummyAuditService().assertHasDelta(1, ChangeType.ADD, UserType.class);
}
Also used : Response(javax.ws.rs.core.Response) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.testng.annotations.Test)

Example 39 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project midpoint by Evolveum.

the class TestAbstractRestService method test513validateValueImplicitMulti.

@Test
public void test513validateValueImplicitMulti() throws Exception {
    final String TEST_NAME = "test513validateValueImplicitMulti";
    displayTestTile(this, TEST_NAME);
    WebClient client = prepareClient();
    client.path("/users/" + USER_DARTHADDER_OID + "/validate");
    getDummyAuditService().clear();
    TestUtil.displayWhen(TEST_NAME);
    Response response = client.post(getRepoFile(POLICY_ITEM_DEFINITION_VALIDATE_IMPLICIT_MULTI));
    TestUtil.displayThen(TEST_NAME);
    displayResponse(response);
    traceResponse(response);
    assertEquals("Expected 200 but got " + response.getStatus(), 200, response.getStatus());
    IntegrationTestTools.display("Audit", getDummyAuditService());
    getDummyAuditService().assertRecords(2);
    getDummyAuditService().assertLoginLogout(SchemaConstants.CHANNEL_REST_URI);
}
Also used : Response(javax.ws.rs.core.Response) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.testng.annotations.Test)

Example 40 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project midpoint by Evolveum.

the class TestAbstractRestService method test132DarthAdderEnableByAdministrator.

@Test
public void test132DarthAdderEnableByAdministrator() throws Exception {
    final String TEST_NAME = "test132DarthAdderEnableByAdministrator";
    displayTestTile(this, TEST_NAME);
    WebClient client = prepareClient();
    client.path("/users/" + USER_DARTHADDER_OID);
    getDummyAuditService().clear();
    TestUtil.displayWhen(TEST_NAME);
    Response response = client.post(MiscUtil.readFile(getRequestFile(MODIFICATION_ENABLE)));
    TestUtil.displayThen(TEST_NAME);
    displayResponse(response);
    assertStatus(response, 204);
    IntegrationTestTools.display("Audit", getDummyAuditService());
    getDummyAuditService().assertRecords(4);
    getDummyAuditService().assertLoginLogout(SchemaConstants.CHANNEL_REST_URI);
    getDummyAuditService().assertHasDelta(1, ChangeType.MODIFY, UserType.class);
    OperationResult result = new OperationResult("test");
    PrismObject<UserType> user = getRepositoryService().getObject(UserType.class, USER_DARTHADDER_OID, null, result);
    assertEquals("Wrong administrativeStatus", ActivationStatusType.ENABLED, user.asObjectable().getActivation().getAdministrativeStatus());
}
Also used : Response(javax.ws.rs.core.Response) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WebClient(org.apache.cxf.jaxrs.client.WebClient) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Aggregations

WebClient (org.apache.cxf.jaxrs.client.WebClient)723 Test (org.junit.Test)400 Response (javax.ws.rs.core.Response)351 URL (java.net.URL)198 HashMap (java.util.HashMap)100 Book (org.apache.cxf.systest.jaxrs.security.Book)94 ArrayList (java.util.ArrayList)88 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)87 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)77 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)60 Bus (org.apache.cxf.Bus)48 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)46 Test (org.testng.annotations.Test)46 Form (javax.ws.rs.core.Form)44 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)42 JwtClaims (org.apache.cxf.rs.security.jose.jwt.JwtClaims)40 JwtAuthenticationClientFilter (org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter)32 InputStream (java.io.InputStream)28 ResponseProcessingException (javax.ws.rs.client.ResponseProcessingException)28 Document (org.w3c.dom.Document)27