Search in sources :

Example 91 with WebClient

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

the class SwaggerToOpenApiConversionTest method doTestSwagger2JSON.

private void doTestSwagger2JSON() throws Exception {
    final WebClient client = createWebClient("/swagger.json");
    AbstractSwagger2ServiceDescriptionTest.doTestApiListingIsProperlyReturnedJSON(client, false);
}
Also used : WebClient(org.apache.cxf.jaxrs.client.WebClient)

Example 92 with WebClient

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

the class SwaggerToOpenApiConversionTest method testOpenApiJSON.

@Test
public void testOpenApiJSON() throws Exception {
    final WebClient client = createWebClient("/openapi.json");
    String openApiResponse = client.get(String.class);
    JsonMapObject openApiJson = new JsonMapObjectReaderWriter().fromJsonToJsonObject(openApiResponse);
    assertEquals(6, openApiJson.size());
    // version
    assertEquals("3.0.0", openApiJson.getProperty("openapi"));
    // servers
    List<Map<String, Object>> servers = openApiJson.getListMapProperty("servers");
    assertEquals(1, servers.size());
    assertEquals(1, servers.get(0).size());
    assertEquals("http://localhost:" + PORT, servers.get(0).get("url"));
    // info
    JsonMapObject info = openApiJson.getJsonMapProperty("info");
    assertEquals(4, info.size());
    assertEquals(DESCRIPTION, info.getProperty("description"));
    assertEquals(TITLE, info.getProperty("title"));
    JsonMapObject contact = info.getJsonMapProperty("contact");
    assertEquals(1, contact.size());
    assertEquals(CONTACT, contact.getProperty("name"));
    JsonMapObject license = info.getJsonMapProperty("license");
    assertEquals(2, license.size());
    assertEquals(LICENSE, license.getProperty("name"));
    assertEquals(LICENSE_URL, license.getProperty("url"));
    // tags
    List<Map<String, Object>> tags = openApiJson.getListMapProperty("tags");
    assertEquals(1, tags.size());
    assertEquals(1, tags.get(0).size());
    assertEquals("bookstore", tags.get(0).get("name"));
    // paths
    JsonMapObject paths = openApiJson.getJsonMapProperty("paths");
    assertEquals(2, paths.size());
    // 1: bookstore
    JsonMapObject bookstore = paths.getJsonMapProperty("/bookstore");
    assertEquals(1, bookstore.size());
    // get
    verifyBookStoreGet(bookstore);
    // 2: bookstore/{id}
    JsonMapObject bookstoreId = paths.getJsonMapProperty("/bookstore/{id}");
    assertEquals(2, bookstoreId.size());
    // get
    verifyBookStoreIdGet(bookstoreId);
    // delete
    verifyBookStoreIdDelete(bookstoreId);
    // components
    JsonMapObject comps = openApiJson.getJsonMapProperty("components");
    assertEquals(3, comps.size());
    JsonMapObject requestBodies = comps.getJsonMapProperty("requestBodies");
    assertEquals(0, requestBodies.size());
    JsonMapObject schemas = comps.getJsonMapProperty("schemas");
    assertEquals(1, schemas.size());
    JsonMapObject secSchemes = comps.getJsonMapProperty("securitySchemes");
    assertEquals(1, secSchemes.size());
    // Finally check swagger.json can still be generated.
    doTestSwagger2JSON();
}
Also used : JsonMapObjectReaderWriter(org.apache.cxf.jaxrs.json.basic.JsonMapObjectReaderWriter) WebClient(org.apache.cxf.jaxrs.client.WebClient) Map(java.util.Map) JsonMapObject(org.apache.cxf.jaxrs.json.basic.JsonMapObject) Test(org.junit.Test)

Example 93 with WebClient

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

the class AbstractOpenApiServiceDescriptionTest method testUiResource.

@Test
public void testUiResource() {
    // Test that Swagger UI resources do not interfere with
    // application-specific ones and are accessible.
    WebClient uiClient = WebClient.create(getBaseUrl() + "/swagger-ui.css").accept("text/css");
    String css = uiClient.get(String.class);
    assertThat(css, containsString(".swagger-ui{"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 94 with WebClient

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

the class AbstractOpenApiServiceDescriptionTest method checkUiResource.

protected void checkUiResource() {
    WebClient uiClient = WebClient.create(getBaseUrl() + "/api-docs").accept(MediaType.WILDCARD);
    String uiHtml = uiClient.get(String.class);
    assertTrue(uiHtml.contains("<title>Swagger UI</title>"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient)

Example 95 with WebClient

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

the class JAXRSClientServerTikaTest method createWebClient.

private WebClient createWebClient(final String url) {
    WebClient wc = WebClient.create("http://localhost:" + PORT + url, Arrays.asList(new MultipartProvider(), new JacksonJsonProvider()));
    WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
    return wc;
}
Also used : JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) MultipartProvider(org.apache.cxf.jaxrs.provider.MultipartProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient)

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