Java Code Examples for org.jboss.arquillian.container.test.api.RunAsClient

The following examples show how to use org.jboss.arquillian.container.test.api.RunAsClient. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Verifies the custom health integration with CDI at the scope of a server runtime
 */
@Test
@RunAsClient
public void testSuccessResponsePayload() {
    Response response = getUrlCustomHealthContents("group1");

    // status code
    Assert.assertEquals(response.getStatus(), 200);

    JsonObject json = readJson(response);

    // response size
    JsonArray checks = json.getJsonArray("checks");
    Assert.assertEquals(checks.size(), 1, "Expected a single check response");

    // single procedure response
    assertSuccessfulCheck(checks.getJsonObject(0), "successful-check");

    assertOverallSuccess(json);
}
 
Example 2
Source Project: smallrye-health   Source File: WellnessFailedTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verifies the wellness integration with CDI at the scope of a server runtime
 */
@Test
@RunAsClient
public void testFailedResponsePayload() {
    Response response = getUrlWellContents();

    // status code
    Assert.assertEquals(response.getStatus(), 503);

    JsonObject json = readJson(response);

    // response size
    JsonArray checks = json.getJsonArray("checks");
    Assert.assertEquals(checks.size(), 1, "Expected a single check response");

    // single procedure response
    assertFailureCheck(checks.getJsonObject(0), "failed-check");

    assertOverallFailure(json);
}
 
Example 3
Source Project: smallrye-health   Source File: WellnessSuccessfulTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verifies the wellness integration with CDI at the scope of a server runtime
 */
@Test
@RunAsClient
public void testSuccessResponsePayload() {
    Response response = getUrlWellContents();

    // status code
    Assert.assertEquals(response.getStatus(), 200);

    JsonObject json = readJson(response);

    // response size
    JsonArray checks = json.getJsonArray("checks");
    Assert.assertEquals(checks.size(), 2, "Expected two check responses");

    // single procedure response
    assertSuccessfulCheck(checks.getJsonObject(0), "successful-check");
    assertSuccessfulCheck(checks.getJsonObject(1), "successful-check");

    assertOverallSuccess(json);
}
 
Example 4
Source Project: microprofile1.4-samples   Source File: BasicHelloTest.java    License: MIT License 6 votes vote down vote up
@Test
@RunAsClient
public void testServerInternal() throws IOException {
    String response =
            newClient()
                 .target(
                     URI.create(new URL(base.getProtocol(), base.getHost(), base.getPort(), "/openapi").toExternalForm()))
                 .request(TEXT_PLAIN)
                 .get(String.class);

    System.out.println("-------------------------------------------------------------------------");
    System.out.println("Response: " + response);
    System.out.println("-------------------------------------------------------------------------");

    assertTrue(
        response.contains("hello-world")
    );
}
 
Example 5
Source Project: microprofile1.4-samples   Source File: JaxRsTest.java    License: MIT License 6 votes vote down vote up
@Test
@RunAsClient
public void testProtectedResourceNotLoggedin() throws IOException {

    System.out.println("-------------------------------------------------------------------------");
    System.out.println("Base URL: " + base);
    System.out.println("-------------------------------------------------------------------------");

    Response response =
            newClient()
                 .target(
                     URI.create(new URL(base, "resource/protected").toExternalForm()))
                 .request(TEXT_PLAIN)
                 .get();

    // Not logged-in thus should not be accessible.
    assertFalse(
        "Not authenticated, so should not have been able to access protected resource",
        response.readEntity(String.class).contains("This is a protected resource")
    );
}
 
Example 6
Source Project: microprofile1.4-samples   Source File: JaxRsTest.java    License: MIT License 6 votes vote down vote up
@Test
@RunAsClient
public void testPublicResourceNotLoggedin() throws IOException {

    Response response =
            newClient()
                 .target(
                     URI.create(new URL(base, "resource/public").toExternalForm()))
                 .request(TEXT_PLAIN)
                 .get();

    // Public resource, no log-in needed
    assertTrue(
        "Public resource is not constrained (protected) so should be accessible without sending the JWT token",
        response.readEntity(String.class).contains("This is a public resource")
    );
}
 
Example 7
Source Project: microprofile1.4-samples   Source File: BasicAuthenticationTest.java    License: MIT License 6 votes vote down vote up
@Test
@RunAsClient
public void testProtectedPageNotLoggedin() throws IOException {

    Response response =
            newClient()
                 .target(
                     URI.create(new URL(base, "servlet").toExternalForm()))
                 .request(TEXT_PLAIN)
                 .get();

    // Not logged-in thus should not be accessible.
    assertFalse(
        "Not authenticated, so should not have been able to access protected resource",
        response.readEntity(String.class).contains("This is a protected servlet")
    );
}
 
Example 8
@Test
@RunAsClient
public void testProtectedPageNotLoggedin() throws IOException {

    Response response =
            newClient()
                 .target(
                     URI.create(new URL(base, "servlet").toExternalForm()))
                 .request(TEXT_PLAIN)
                 .get();

    // Not logged-in thus should not be accessible.
    assertFalse(
        "Not authenticated, so should not have been able to access protected resource",
        response.readEntity(String.class).contains("This is a protected servlet")
    );
}
 
Example 9
Source Project: microprofile1.4-samples   Source File: ServerInternalTest.java    License: MIT License 6 votes vote down vote up
@Test
@RunAsClient
public void testServerInternal() throws IOException {

    String response =
            newClient()
                 .target(
                     URI.create(new URL(base, "api/client").toExternalForm()))
                 .request(TEXT_PLAIN)
                 .get(String.class);

    System.out.println("-------------------------------------------------------------------------");
    System.out.println("Response: " + response);
    System.out.println("-------------------------------------------------------------------------");

    assertTrue(
        response.contains("Hello World!")
    );
}
 
Example 10
Source Project: microprofile1.4-samples   Source File: ClientServerAsyncTest.java    License: MIT License 6 votes vote down vote up
@Test
@RunAsClient
public void testClientServerAsync() throws IOException, IllegalStateException, RestClientDefinitionException, URISyntaxException, InterruptedException, ExecutionException {

    HelloService remoteApi = RestClientBuilder.newBuilder()
            .baseUrl(base)
            .build(HelloService.class);


    String response =
        remoteApi.helloAsync("Programmer (Async)")
                 .thenApply(String::toUpperCase)
                 .toCompletableFuture()
                 .get();

    System.out.println("-------------------------------------------------------------------------");
    System.out.println("Response: " + response);
    System.out.println("-------------------------------------------------------------------------");

    assertTrue(
        response.contains("HELLO PROGRAMMER (ASYNC)!")
    );
}
 
Example 11
Source Project: microprofile1.4-samples   Source File: ClientServerTest.java    License: MIT License 6 votes vote down vote up
@Test
@RunAsClient
public void testClientServer() throws IOException, IllegalStateException, RestClientDefinitionException, URISyntaxException {

    HelloService remoteApi = RestClientBuilder.newBuilder()
            .baseUrl(base)
            .build(HelloService.class);

    String response  =  remoteApi.hello("Programmer");



    System.out.println("-------------------------------------------------------------------------");
    System.out.println("Response: " + response);
    System.out.println("-------------------------------------------------------------------------");

    assertTrue(
        response.contains("Hello Programmer!")
    );
}
 
Example 12
Source Project: microprofile1.4-samples   Source File: ServerInternalAsyncTest.java    License: MIT License 6 votes vote down vote up
@Test
@RunAsClient
public void testServerInternalAsync() throws IOException {

    String response =
            newClient()
                 .target(
                     URI.create(new URL(base, "api/clientAsync").toExternalForm()))
                 .request(TEXT_PLAIN)
                 .get(String.class);

    System.out.println("-------------------------------------------------------------------------");
    System.out.println("Response: " + response);
    System.out.println("-------------------------------------------------------------------------");

    assertTrue(
        response.contains("HELLO WORLD (ASYNC)!")
    );
}
 
Example 13
@RunAsClient
@Test(priority = 1)
public void testResponse() throws IOException {
    LOG.log(Level.INFO, "Fetching schema from {0}", uri);
    this.schema = getSchemaContent();
    saveSchemaFile();
    
    // Check that there is some content
    Assert.assertTrue(schema.length() > 0, "No Content in the GraphQL Schema downloaded from [" + uri + "]");
}
 
Example 14
@RunAsClient
@Test(priority = 2, dataProvider = "schemaSnippets", dataProviderClass = SchemaTestDataProvider.class)
public void testPartsOfSchema(TestData input) {
    Assert.assertNotNull(schema, "No schema avalailable to test against");
    String snippet = schema; // default search against the whole schema
    if(input.getSnippetSearchTerm()!=null){
        snippet = getSchemaSnippet(schema, input.getSnippetSearchTerm());
    }
    
    Assert.assertTrue(matchCondition(input,snippet), "[" + input.getHeader() + "] " + input.getErrorMessage());    
}
 
Example 15
Source Project: smallrye-graphql   Source File: MetricTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@RunAsClient
@InSequence(100)
public void invokeApi() throws Exception {
    SimpleGraphQLClient client = new SimpleGraphQLClient(testingURL);
    client.query("{get {version}}");
    client.query("{get {version}}");
    client.query("mutation {mutate{version}}");
    client.query("mutation {mutate{version}}");
    client.query("{get {description}}");
}
 
Example 16
Source Project: smallrye-jwt   Source File: TestApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@RunAsClient
public void servlet() throws Exception {
    String uri = baseURL.toExternalForm() + "servlet";
    System.out.println("uri = " + uri);
    WebTarget echoEndpointTarget = ClientBuilder.newClient().target(uri);
    Response response = echoEndpointTarget.request(TEXT_PLAIN).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
}
 
Example 17
Source Project: smallrye-jwt   Source File: TestApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@RunAsClient
public void rest() throws Exception {
    String uri = baseURL.toExternalForm() + "rest";
    System.out.println("uri = " + uri);
    WebTarget echoEndpointTarget = ClientBuilder.newClient().target(uri);
    Response response = echoEndpointTarget.request(TEXT_PLAIN).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
}
 
Example 18
Source Project: microprofile-starter   Source File: TestMatrixTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@RunAsClient
@InSequence(35)
public void wildflyHealthchecks() throws IOException, InterruptedException {
    testRuntime("WILDFLY", "wildfly",
            SpecSelection.HEALTH_CHECKS, new int[]{9990});
}
 
Example 19
Source Project: smallrye-health   Source File: AllCustomFailedTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Verifies the custom health integration with CDI at the scope of a server runtime, by retrieving all the custom checks.
 */
@Test
@RunAsClient
public void testFailureResponsePayload() {
    Response response = getUrlAllCustomHealthContents();

    // status code
    Assert.assertEquals(response.getStatus(), 503);

    JsonObject json = readJson(response);

    // response size
    JsonArray checks = json.getJsonArray("checks");
    Assert.assertEquals(checks.size(), 2, "Expected two check responses");

    for (JsonObject check : checks.getValuesAs(JsonObject.class)) {
        String id = check.getString("name");
        switch (id) {
            case "successful-check":
                verifySuccessStatus(check);
                break;
            case "failed-check":
                verifyFailureStatus(check);
                break;
            default:
                Assert.fail("Unexpected response payload structure");
        }
    }

    assertOverallFailure(json);
}
 
Example 20
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testDirectIgnore(String type) {
    ValidatableResponse vr = this.callEndpoint(type);
    String schemaPath = "components.schemas.DirectIgnore.properties";
    vr.body(schemaPath + ".dontIgnoreMe", notNullValue());
    vr.body(schemaPath + ".ignoreMe", nullValue());
}
 
Example 21
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testInheritedIgnore(String type) {
    ValidatableResponse vr = this.callEndpoint(type);
    String schemaPath = "components.schemas.InheritIgnore.properties";
    vr.body(schemaPath + ".dontIgnoreMe", notNullValue());
    vr.body(schemaPath + ".ignoreMe", nullValue());
}
 
Example 22
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testInheritedIgnoreOverride(String type) {
    ValidatableResponse vr = this.callEndpoint(type);
    String schemaPath = "components.schemas.InheritIgnoreOverride.properties";
    vr.body(schemaPath + ".dontIgnoreMe", nullValue());
    vr.body(schemaPath + ".ignoreMe", notNullValue());
}
 
Example 23
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testPathItems(String type) {
    ValidatableResponse vr = this.callEndpoint(type);
    vr.body("paths.'/restapi/v1/apppaths'.get", org.hamcrest.Matchers.nullValue());
    vr.body("paths.'/apppaths'.get", org.hamcrest.Matchers.notNullValue());
}
 
Example 24
Source Project: smallrye-open-api   Source File: ExtensionsTest.java    License: Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testTypeExtensions(String type) {
    ValidatableResponse vr = this.callEndpoint(type);
    String operation = "paths.'/extensions/typeExtension'.get";
    vr.body(operation + ".x-operation-extension", nullValue());
    vr.body(operation + ".x-type-extension", equalTo("Type extension value."));
}
 
Example 25
Source Project: smallrye-open-api   Source File: ExtensionsTest.java    License: Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testOperationExtensions(String type) {
    ValidatableResponse vr = this.callEndpoint(type);
    String operation = "paths.'/extensions/opExtension'.get";
    vr.body(operation + ".x-operation-extension", equalTo("Operation extension value."));
    vr.body(operation + ".x-type-extension", nullValue());
}
 
Example 26
Source Project: smallrye-open-api   Source File: ExtensionsTest.java    License: Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testOperationWrapperExtensions(String type) {
    ValidatableResponse vr = this.callEndpoint(type);
    String operation = "paths.'/extensions/opWrapperExtension'.get";
    vr.body(operation + ".x-operation-extension-1", equalTo("Operation extension wrapper value (1)."));
    vr.body(operation + ".x-operation-extension-2", equalTo("Operation extension wrapper value (2)."));
    vr.body(operation + ".x-type-extension", nullValue());
}
 
Example 27
Source Project: smallrye-open-api   Source File: ExtensionsTest.java    License: Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testPathParamExtensions(String type) {
    ValidatableResponse vr = this.callEndpoint(type);
    String operation = "paths.'/extensions/pathParamExtension/{param}'.get";
    vr.body(operation + ".x-parameter-extension", nullValue());
    vr.body(operation + ".parameters[0].x-parameter-extension", equalTo("Parameter extension value."));
}
 
Example 28
Source Project: smallrye-open-api   Source File: ApplicationPathTest.java    License: Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testPathItems(String type) {
    ValidatableResponse vr = this.callEndpoint(type);
    vr.body("paths.'/restapi/v1/apppaths'.get", org.hamcrest.Matchers.notNullValue());
    vr.body("paths.'/apppaths'.get", org.hamcrest.Matchers.nullValue());
}
 
Example 29
Source Project: microprofile-starter   Source File: TestMatrixTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@RunAsClient
@InSequence(38)
public void wildflyOpenAPI() throws IOException, InterruptedException {
    testRuntime("WILDFLY", "wildfly",
            SpecSelection.OPEN_API, new int[]{9990});
}
 
Example 30
Source Project: smallrye-open-api   Source File: JaxRsTest.java    License: Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void test200IterableResponse(String type) {
    ValidatableResponse vr = this.callEndpoint(type);
    vr.body("paths.'/jaxrs/widgets/iter'.get.responses.'200'.description", equalTo("OK"));
    vr.body("paths.'/jaxrs/widgets/iter'.get.responses.'200'.content.'*/*'.schema.type", equalTo("array"));
    vr.body("paths.'/jaxrs/widgets/iter'.get.responses.'200'.content.'*/*'.schema.items.'$ref'",
            equalTo("#/components/schemas/Widget"));
}