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

The following are top voted examples for showing how to use org.jboss.arquillian.container.test.api.RunAsClient. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: microprofile-jwt-auth   File: JsonValueInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
    description = "Verify that the injected jti claim is as expected")
public void verifyInjectedJTI() throws Exception {
    Reporter.log("Begin verifyInjectedJTI\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedJTI";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.jti.name(), "a-123")
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 2
Project: Mastering-Java-EE-Development-with-WildFly   File: ComponentTestCase.java   Source Code and License 6 votes vote down vote up
@Test
@RunAsClient
public void testGet() throws Exception {
	logger.info("Registering Client Level Filters");
	Client client = newClient();
	client.register(new OtherClientResponseFilter());
	WebTarget target = client.target(url + "myjaxrs/simple/");
	target.register(new OtherClientRequestFilter());

	WebTarget resourceTarget = target.path("/valuesget");
	resourceTarget = resourceTarget.queryParam("OrderID", "111").queryParam("UserName", "Luke");
	resourceTarget.register(new MyClientResponseFilter());
	resourceTarget.register(new MyClientRequestFilter());

	logger.info("Invoking REST Service: " + resourceTarget.getUri().toString());
	Invocation invocation = resourceTarget.request().buildGet();
	Response response = invocation.invoke();
	String respContent = "";

	if (response.hasEntity())
		respContent = response.readEntity(String.class);

	assertEquals("Response--> ", "111-Luke", respContent);
	assertEquals("Content Type after changing in ClientResponseFilter: ", TEXT_HTML,
			response.getHeaderString(CONTENT_TYPE_STRING));
}
 
Example 3
Project: microprofile-jwt-auth   File: ProviderInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected raw token claim is as expected")
public void verifyInjectedOptionalAuthTime2() throws Exception {
    Reporter.log("Begin verifyInjectedOptionalAuthTime\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedOptionalAuthTime";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 4
Project: Mastering-Java-EE-Development-with-WildFly   File: RemotingNamingTestCase.java   Source Code and License 6 votes vote down vote up
@Test
@RunAsClient
public void testStatelessRemoteNaming() throws Exception {
	logger.info("starting remoting ejb client test");

	try {
		createInitialContext();
		Machine machine = lookup(Machine.class, "machine");
		logger.info(machine + "");
		int result = machine.go(1);
		assertEquals(machine.getSpeed(), 1);
		logger.info(result + "");
		machine = lookup(Machine.class, "machine");
		logger.info(machine + "");
		assertEquals(machine.getSpeed(), 1);
	} finally {
		closeContext();
	}
}
 
Example 5
Project: Mastering-Java-EE-Development-with-WildFly   File: RemotingNamingTestCase.java   Source Code and License 6 votes vote down vote up
@Test
@RunAsClient
public void testStatefulRemoteNaming() throws Exception {
	logger.info("starting remoting ejb client test");

	try {
		createInitialContext();
		StateMachine machine = lookup(StateMachine.class, "stateMachine");
		logger.info(machine + "");
		int result = machine.go(1);
		assertEquals(machine.getSpeed(), 1);
		logger.info(result + "");
		machine = lookup(StateMachine.class, "stateMachine");
		logger.info(machine + "");
		assertEquals(machine.getSpeed(), 0);
	} finally {
		closeContext();
	}
}
 
Example 6
Project: microprofile-jwt-auth   File: JsonValueInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
    description = "Verify that the injected raw token claim is as expected from Token2")
public void verifyInjectedRawToken2() throws Exception {
    Reporter.log("Begin verifyInjectedRawToken2\n");
    String token2 = TokenUtils.generateTokenString("/Token2.json");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedRawToken";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.raw_token.name(), token2)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token2).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 7
Project: Mastering-Java-EE-Development-with-WildFly   File: XMLTestCase.java   Source Code and License 6 votes vote down vote up
@Test
@RunAsClient
public void testRemoteXML() throws Exception {
	logger.info("starting remoting ejb client test");

	try {
		createInitialContext();
		String hostname = getLocalHost().getHostName().toLowerCase();
		final UserTransaction userTransaction = getUserTransaction(hostname);
		XMLRemote bean = lookup(XMLRemote.class, "bank");
		assertEquals(STATUS_NO_TRANSACTION, bean.transactionStatus());

		try {
			userTransaction.begin();
			bean.transactionStatus();
			fail("the transaction is not supported");
		} catch (EJBException | IllegalStateException e) {
			logger.info("the transaction is not supported");
		}
	} finally {
		closeContext();
	}
}
 
Example 8
Project: microprofile-jwt-auth   File: RequiredClaimsTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_JWT,
        description = "Verify that the exp claim is as expected")
public void verifyExpiration() throws Exception {
    Reporter.log("Begin verifyExpiration\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyExpiration";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
            .target(uri)
            .queryParam(Claims.exp.name(), expClaim)
            .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 9
Project: microprofile-open-api   File: OASConfigExcludeClassesTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testExcludedClasses(String type) throws InterruptedException {
    vr = callEndpoint(type);
    vr.body("openapi", equalTo("3.0.0"));
    vr.body("info.title", equalTo("AirlinesRatingApp API"));
    vr.body("info.version", equalTo("1.0"));
    
    vr.body("paths.", aMapWithSize(10));
    vr.body("paths.'/reviews'", nullValue());
    vr.body("paths.'/reviews/{id}'", nullValue());
    vr.body("paths.'/reviews/{user}'", nullValue());
    vr.body("paths.'/reviews/{airline}'", nullValue());
    vr.body("paths.'/reviews/{user}/{airlines}'", nullValue());
    
    vr.body("paths.'/availability'", nullValue());

    
    
}
 
Example 10
Project: microprofile-jwt-auth   File: PrimitiveInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected sub claim is as expected")
public void verifyInjectedSUB() throws Exception {
    Reporter.log("Begin verifyInjectedSUB\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedSUB";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.sub.name(), "24400320")
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 11
Project: microprofile-jwt-auth   File: ProviderInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected aud claim is as expected")
public void verifyInjectedAudience() throws Exception {
    Reporter.log("Begin verifyInjectedAudience\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedAudience";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.aud.name(), "s6BhdRkqt3")
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 12
Project: microprofile-jwt-auth   File: ClaimValueInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    description = "Verify that the injected sub claim is as expected")
public void verifyInjectedOptionalSubject() throws Exception {
    Reporter.log("Begin verifyInjectedOptionalSubject\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedOptionalSubject";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.sub.name(), "24400320")
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 13
Project: microprofile-jwt-auth   File: ClaimValueInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    description = "Verify that the injected customInteger claim is as expected")
public void verifyInjectedCustomInteger() throws Exception {
    Reporter.log("Begin verifyInjectedCustomInteger\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedCustomInteger";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("value", 123456789)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 14
Project: microprofile-open-api   File: ModelReaderAppTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testTagDeclarations(String type) {
    ValidatableResponse vr = callEndpoint(type);
    String tagsPath = "tags.find { it.name == '";
    String desc = "' }.description";
    vr.body(tagsPath + "user" + desc, equalTo("Operations about user"));
    vr.body(tagsPath + "create" + desc, equalTo("Operations about create"));
    vr.body(tagsPath + "Airlines" + desc, equalTo("All the airlines methods"));
    vr.body(tagsPath + "Availability" + desc, equalTo("All the availability methods"));
    vr.body(tagsPath + "Get Flights" + desc, equalTo("method to retrieve all flights available"));
    vr.body(tagsPath + "Get Flights" + "' }.externalDocs.description", equalTo("A list of all the flights offered by the app"));
    vr.body(tagsPath + "Get Flights" + "' }.externalDocs.url", equalTo("http://airlinesratingapp.com/ourflights"));
    vr.body(tagsPath + "Bookings" + desc, equalTo("All the bookings methods"));
    vr.body(tagsPath + "Get Airlines" + desc, equalTo("method to get all airlines"));
    vr.body(tagsPath + "Retrieve Airlines" + desc, equalTo("method to retrieve all airlines"));
}
 
Example 15
Project: microprofile-jwt-auth   File: RequiredClaimsTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_JWT,
        description = "Verify that the jti claim is as expected")
public void verifyJTI() throws Exception {
    Reporter.log("Begin verifyJTI\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyJTI";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
            .target(uri)
            .queryParam(Claims.jti.name(), "a-f2b2180c")
            .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 16
Project: arquillian-reporter   File: ArquillianCoreReporterLifecycleManager.java   Source Code and License 6 votes vote down vote up
public void startTestMethod(@Observes(precedence = Integer.MAX_VALUE) Before event) {

        Method testMethod = event.getTestMethod();
        boolean runAsClient = event.getTestMethod().isAnnotationPresent(RunAsClient.class);
        String deploymentName = "_DEFAULT_";
        if (event.getTestMethod().isAnnotationPresent(OperateOnDeployment.class)) {
            deploymentName = event.getTestMethod().getAnnotation(OperateOnDeployment.class).value();
        }

        Reporter
            .createReport(new TestMethodReport(testMethod.getName()))
            .addKeyValueEntry(TEST_METHOD_OPERATES_ON_DEPLOYMENT, deploymentName)
            .addKeyValueEntry(TEST_METHOD_RUNS_AS_CLIENT, runAsClient)
            .inSection(new TestMethodSection(testMethod))
            .fire(sectionEvent);
    }
 
Example 17
Project: microprofile-open-api   File: AirlinesAppTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testOperationBookingResource(String type) {
    ValidatableResponse vr = callEndpoint(type);
    vr.body("paths.'/bookings'.get.summary", equalTo("Retrieve all bookings for current user"));
    vr.body("paths.'/bookings'.get.operationId", equalTo("getAllBookings"));

    vr.body("paths.'/bookings'.post.summary", equalTo("Create a booking"));
    vr.body("paths.'/bookings'.post.description", equalTo("Create a new booking record with the booking information provided."));
    vr.body("paths.'/bookings'.post.operationId", equalTo("createBooking"));

    vr.body("paths.'/bookings/{id}'.get.summary", equalTo("Get a booking with ID"));
    vr.body("paths.'/bookings/{id}'.get.operationId", equalTo("getBookingById"));

    vr.body("paths.'/bookings/{id}'.put.summary", equalTo("Update a booking with ID"));
    vr.body("paths.'/bookings/{id}'.put.operationId", equalTo("updateBookingId"));

    vr.body("paths.'/bookings/{id}'.delete.summary", equalTo("Delete a booking with ID"));
    vr.body("paths.'/bookings/{id}'.delete.operationId", equalTo("deleteBookingById"));
}
 
Example 18
Project: microprofile-open-api   File: AirlinesAppTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testOperationReviewResource(String type) {
    ValidatableResponse vr = callEndpoint(type);
    vr.body("paths.'/reviews'.get.summary", equalTo("get all the reviews"));
    vr.body("paths.'/reviews'.get.operationId", equalTo("getAllReviews"));

    vr.body("paths.'/reviews'.post.summary", equalTo("Create a Review"));
    vr.body("paths.'/reviews'.post.operationId", equalTo("createReview"));

    vr.body("paths.'/reviews/{id}'.get.summary", equalTo("Get a review with ID"));
    vr.body("paths.'/reviews/{id}'.get.operationId", equalTo("getReviewById"));

    vr.body("paths.'/reviews/{id}'.delete.summary", equalTo("Delete a Review with ID"));
    vr.body("paths.'/reviews/{id}'.delete.operationId", equalTo("deleteReview"));

    vr.body("paths.'/reviews/{user}'.get.summary", equalTo("Get all reviews by user"));
    vr.body("paths.'/reviews/{user}'.get.operationId", equalTo("getReviewByUser"));

    vr.body("paths.'/reviews/{airline}'.get.summary", equalTo("Get all reviews by airlines"));
    vr.body("paths.'/reviews/{airline}'.get.operationId", equalTo("getReviewByAirline"));

    vr.body("paths.'/reviews/{user}/{airlines}'.get.summary", equalTo("Get all reviews for an airline by User"));
    vr.body("paths.'/reviews/{user}/{airlines}'.get.operationId", equalTo("getReviewByAirlineAndUser"));
}
 
Example 19
Project: microprofile-jwt-auth   File: RequiredClaimsTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_JWT,
        description = "Verify that the uPN claim is as expected")
public void verifyUPN() throws Exception {
    Reporter.log("Begin verifyUPN\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyUPN";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
            .target(uri)
            .queryParam(Claims.upn.name(), "[email protected]")
            .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 20
Project: microprofile-jwt-auth   File: ProviderInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected raw token claim is as expected")
public void verifyInjectedOptionalAuthTime() throws Exception {
    Reporter.log("Begin verifyInjectedOptionalAuthTime\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedOptionalAuthTime";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 21
Project: microprofile-jwt-auth   File: RequiredClaimsTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_JWT,
        description = "Verify that the iat claim is as expected")
public void verifyIssuedAt() throws Exception {
    Reporter.log("Begin verifyIssuedAt\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyIssuedAt";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
            .target(uri)
            .queryParam(Claims.iat.name(), iatClaim)
            .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 22
Project: microprofile-open-api   File: AirlinesAppTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testCallbackAnnotations(String type) {
    ValidatableResponse vr = callEndpoint(type);
    String endpoint = "paths.'/streams'.post.callbacks";
    vr.body(endpoint, hasKey("onData"));
    vr.body(endpoint + ".onData", hasKey("{$request.query.callbackUrl}/data"));

    endpoint = "paths.'/reviews'.post.callbacks";
    vr.body(endpoint, hasKey("testCallback"));
    vr.body(endpoint + ".testCallback", hasKey("http://localhost:9080/oas3-airlines/reviews"));

    endpoint = "paths.'/bookings'.post.callbacks";
    vr.body(endpoint, hasKey("bookingCallback"));
    vr.body(endpoint + ".'bookingCallback'", hasKey("http://localhost:9080/airlines/bookings"));
}
 
Example 23
Project: microprofile-jwt-auth   File: JsonValueInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
    description = "Verify that the injected token issuer claim is as expected")
public void verifyIssuerClaim() throws Exception {
    Reporter.log("Begin verifyIssuerClaim");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedIssuer";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.iss.name(), TCKConstants.TEST_ISSUER)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 24
Project: microprofile-open-api   File: AirlinesAppTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testSecurityScheme(String type) {
    ValidatableResponse vr = callEndpoint(type);
    String http = "components.securitySchemes.httpSchemeForTest.";
    vr.body(http + "type", equalTo("http"));
    vr.body(http + "description", equalTo("user security scheme"));
    vr.body(http + "scheme", equalTo("testScheme"));

    String booking = "components.securitySchemes.bookingSecurityScheme.";
    vr.body(booking + "type", equalTo("openIdConnect"));
    vr.body(booking + "description", equalTo("Security Scheme for booking resource"));
    vr.body(booking + "openIdConnectUrl", equalTo("http://openidconnect.com/testurl"));

    String auth = "components.securitySchemes.airlinesRatingApp_auth.";
    vr.body(auth + "type", equalTo("apiKey"));
    vr.body(auth + "description", equalTo("authentication needed to access Airlines app"));
    vr.body(auth + "name", equalTo("api_key"));
    vr.body(auth + "in", equalTo("header"));

    String reviewoauth2 = "components.securitySchemes.reviewoauth2.";
    vr.body(reviewoauth2 + "type", equalTo("oauth2"));
    vr.body(reviewoauth2 + "description", equalTo("authentication needed to create and delete reviews"));
}
 
Example 25
Project: microprofile-metrics   File: MpMetricTest.java   Source Code and License 6 votes vote down vote up
@Test
@RunAsClient
@InSequence(26)
public void testApplicationHistogramUnitNonePrometheus() {

    String prefix = "metric_test_test1_histogram2";

    given().header("Accept", TEXT_PLAIN).when().get("/metrics/application/metricTest.test1.histogram2")
        .then().statusCode(200)
        .and()
        .body(containsString(prefix + "_count"))
        .body(containsString("# TYPE application:" + prefix + " summary"))
        .body(containsString(prefix + "_mean"))
        .body(containsString(prefix + "_min"))
        .body(containsString(prefix + "_max"))
        .body(containsString(prefix + "_stddev"))
        .body(containsString(prefix + "{tier=\"integration\",quantile=\"0.5\"}"))
        .body(containsString(prefix + "{tier=\"integration\",quantile=\"0.75\"}"))
        .body(containsString(prefix + "{tier=\"integration\",quantile=\"0.95\"}"))
        .body(containsString(prefix + "{tier=\"integration\",quantile=\"0.98\"}"))
        .body(containsString(prefix + "{tier=\"integration\",quantile=\"0.99\"}"))
        .body(containsString(prefix + "{tier=\"integration\",quantile=\"0.999\"}"))
    ;
}
 
Example 26
Project: microprofile-open-api   File: AirlinesAppTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testEncodingResponses(String type) {
    ValidatableResponse vr = callEndpoint(type);
    String s = "paths.'/user/{username}'.put.responses.'200'.content.'application/json'.encoding.password.";
    vr.body(s + "contentType", equalTo("text/plain"));
    vr.body(s + "style", equalTo("form"));
    vr.body(s + "explode", equalTo(true));
    vr.body(s + "allowReserved", equalTo(true));

    String t = "paths.'/user/{username}'.put.responses.'200'.content.'application/xml'.encoding.password.";
    vr.body(t + "contentType", equalTo("text/plain"));
    vr.body(t + "style", equalTo("form"));
    vr.body(t + "explode", equalTo(true));
    vr.body(t + "allowReserved", equalTo(true));
}
 
Example 27
Project: microprofile-open-api   File: AirlinesAppTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testLink(String type) {
    ValidatableResponse vr = callEndpoint(type);
    String s = "paths.'/user/{id}'.get.responses.'200'.links.'User name'.";
    vr.body(s + "operationId", equalTo("getUserByName"));
    vr.body(s + "description", equalTo("The username corresponding to provided user id"));

    String t = "paths.'/user/{id}'.get.responses.'200'.links.Review.";
    vr.body(t + "operationRef", equalTo("/db/reviews/{userName}"));
    vr.body(t + "description", equalTo("The reviews provided by user"));

    String k = "paths.'/reviews'.post.responses.'201'.links.Review.";
    vr.body(k + "operationId", equalTo("getReviewById"));
    vr.body(k + "description", equalTo("get the review that was added"));
}
 
Example 28
Project: microprofile-jwt-auth   File: ClaimValueInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    description = "Verify that the injected raw token claim using @Claim(standard) is as expected")
public void verifyInjectedAuthTimeStandard() throws Exception {
    Reporter.log("Begin verifyInjectedAuthTimeStandard\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedAuthTimeStandard";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 29
Project: microprofile-jwt-auth   File: PrimitiveInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected customString claim is as expected")
public void verifyInjectedCustomString() throws Exception {
    Reporter.log("Begin verifyInjectedCustomString\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedCustomString";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("value", "customStringValue")
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 30
Project: microprofile-open-api   File: AirlinesAppTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testTagDeclarations(String type) {
    ValidatableResponse vr = callEndpoint(type);
    String tagsPath = "tags.find { it.name == '";
    String desc = "' }.description";
    vr.body(tagsPath + "user" + desc, equalTo("Operations about user"));
    vr.body(tagsPath + "create" + desc, equalTo("Operations about create"));
    vr.body(tagsPath + "Airlines" + desc, equalTo("All the airlines methods"));
    vr.body(tagsPath + "Availability" + desc, equalTo("All the availability methods"));
    vr.body(tagsPath + "Get Flights" + desc, equalTo("method to retrieve all flights available"));
    vr.body(tagsPath + "Get Flights" + "' }.externalDocs.description", equalTo("A list of all the flights offered by the app"));
    vr.body(tagsPath + "Get Flights" + "' }.externalDocs.url", equalTo("http://airlinesratingapp.com/ourflights"));
    vr.body(tagsPath + "Bookings" + desc, equalTo("All the bookings methods"));
    vr.body(tagsPath + "Reservations" + desc, equalTo("All the reservation methods"));
    vr.body(tagsPath + "Reviews" + desc, equalTo("All the review methods"));
    vr.body(tagsPath + "Ratings" + desc, equalTo("All the ratings methods"));
}
 
Example 31
Project: microprofile-jwt-auth   File: ClaimValueInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    description = "Verify that the injected sub claim using @Claim(standard) is as expected")
public void verifyInjectedSubjectStandard() throws Exception {
    Reporter.log("Begin verifyInjectedSubjectStandard\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedSubjectStandard";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.sub.name(), "24400320")
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 32
Project: microprofile-jwt-auth   File: JsonValueInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
    description = "Verify that the injected customString claim is as expected from Token2")
public void verifyInjectedCustomString2() throws Exception {
    Reporter.log("Begin verifyInjectedCustomString2\n");
    String token2 = TokenUtils.generateTokenString("/Token2.json");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedCustomString";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("value", "customStringValue2")
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token2).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 33
Project: microprofile-health   File: NoProcedureSuccessfulTest.java   Source Code and License 6 votes vote down vote up
/**
 * Verifies the health integration with CDI at the scope of a server runtime
 */
@Test
@RunAsClient
public void testSuccessResponsePayload() throws Exception {
    Response response = getUrlContents();

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

    JsonReader jsonReader = Json.createReader(new StringReader(response.getBody().get()));
    JsonObject json = jsonReader.readObject();
    System.out.println(json);

    Assert.assertEquals(json.getString("outcome"), "UP","Expected outcome UP");
    Assert.assertTrue(json.getJsonArray("checks").isEmpty(), "Expected empty checks array");

}
 
Example 34
Project: microprofile-jwt-auth   File: ProviderInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected customDouble claim is as expected")
public void verifyInjectedCustomDouble() throws Exception {
    Reporter.log("Begin verifyInjectedCustomDouble\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedCustomDouble";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("value", 3.141592653589793)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 35
Project: microprofile-open-api   File: AirlinesAppTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testContentInAPIResponse(String type) {
    ValidatableResponse vr = callEndpoint(type);

    String content1 = "paths.'/availability'.get.responses.'200'.content.'application/json'";
    vr.body(content1, notNullValue());
    vr.body(content1 + ".schema.type", equalTo("array"));
    vr.body(content1 + ".schema.items.$ref", equalTo("#/components/schemas/Flight"));

    String content2 = "paths.'/user/{username}'.put.responses.'200'.content";
    vr.body(content2, notNullValue());
    vr.body(content2 + ".'application/json'", notNullValue());
    vr.body(content2 + ".'application/json'.schema.$ref", equalTo("#/components/schemas/User"));
    vr.body(content2 + ".'application/json'.encoding.password", notNullValue());

    vr.body(content2, notNullValue());
    vr.body(content2 + ".'application/xml'", notNullValue());
    vr.body(content2 + ".'application/xml'.schema.$ref", equalTo("#/components/schemas/User"));
    vr.body(content2 + ".'application/xml'.encoding.password", notNullValue());
}
 
Example 36
Project: microprofile-jwt-auth   File: JsonValueInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
    description = "Verify that the injected customInteger claim is as expected from Token2")
public void verifyInjectedCustomInteger2() throws Exception {
    Reporter.log("Begin verifyInjectedCustomInteger2\n");
    String token2 = TokenUtils.generateTokenString("/Token2.json");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedCustomInteger";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("value", 1234567892)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token2).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 37
Project: microprofile-health   File: EnforceQualifierTest.java   Source Code and License 6 votes vote down vote up
/**
 * Verifies the health integration with CDI at the scope of a server runtime
 */
@Test
@RunAsClient
public void testFailureResponsePayload() throws Exception {
    Response response = getUrlContents();

    // the procedure with an annotation shold not be discovered
    Assert.assertEquals(response.getStatus(), 200);

    JsonReader jsonReader = Json.createReader(new StringReader(response.getBody().get()));
    JsonObject json = jsonReader.readObject();
    System.out.println(json);

    Assert.assertEquals(json.getString("outcome"), "UP","Expected outcome UP");
    Assert.assertTrue(json.getJsonArray("checks").isEmpty(), "Expected empty checks array");

}
 
Example 38
Project: microprofile-jwt-auth   File: JsonValueInjectionTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
    description = "Verify that the injected customDoubleArray claim is as expected")
public void verifyInjectedCustomDoubleArray() throws Exception {
    Reporter.log("Begin verifyInjectedCustomIntegerArray\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedCustomDoubleArray";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("value", 0.1, 1.1, 2.2, 3.3, 4.4)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 39
Project: microprofile-open-api   File: PetStoreAppTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testSchema(String type) {
    ValidatableResponse vr = callEndpoint(type);
    // Schema and DiscriminatorMapping annotation tests
    // Basic properties
    vr.body("paths.'/pet/findByTags'.get.parameters.find{ it.name == 'tags' }.schema.default", equalTo("Dog"));
    vr.body("paths.'/pet/findByTags'.get.parameters.find{ it.name == 'tags' }.schema.enum", hasItems("Cat", "Dog", "Lizard"));
    vr.body("paths.'/pet/findByTags'.get.parameters.find{ it.name == 'tags' }.schema.externalDocs.description", equalTo("Pet Types"));
    vr.body("paths.'/pet/findByTags'.get.parameters.find{ it.name == 'tags' }.schema.deprecated", equalTo(true));
    vr.body("paths.'/store/order/{orderId}'.get.responses.'900'.schema", nullValue());

    // Numerical properties
    vr.body("paths.'/pet/{petId}'.get.parameters.find{ it.name == 'petId' }.schema.maximum", equalTo(101));
    vr.body("paths.'/pet/{petId}'.get.parameters.find{ it.name == 'petId' }.schema.exclusiveMaximum", equalTo(true));
    vr.body("paths.'/pet/{petId}'.get.parameters.find{ it.name == 'petId' }.schema.minimum", equalTo(9));
    vr.body("paths.'/pet/{petId}'.get.parameters.find{ it.name == 'petId' }.schema.exclusiveMinimum", equalTo(true));
    vr.body("paths.'/pet/{petId}'.get.parameters.find{ it.name == 'petId' }.schema.multipleOf", equalTo(10));

    // String properties
    vr.body("paths.'/pet/{petId}'.delete.parameters.find{ it.name == 'apiKey' }.schema.maxLength", equalTo(256));
    vr.body("paths.'/pet/{petId}'.delete.parameters.find{ it.name == 'apiKey' }.schema.minLength", equalTo(32));

}
 
Example 40
Project: microprofile-open-api   File: PetStoreAppTest.java   Source Code and License 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testSecurityRequirement(String type) {
    ValidatableResponse vr = callEndpoint(type);

    vr.body("paths.'/pet'.put.security.petsHttp[0][0]", equalTo(null));

    vr.body("paths.'/pet'.post.security.petsApiKey[0][0]", equalTo(null));

    vr.body("paths.'/pet/{petId}'.delete.security.petsOAuth2[0][0]", equalTo("write:pets"));

    vr.body("paths.'/store/inventory'.get.security.storeOpenIdConnect[0]", hasSize(2));
    vr.body("paths.'/store/inventory'.get.security.storeOpenIdConnect[0][0]", equalTo("write:store"));
    vr.body("paths.'/store/inventory'.get.security.storeOpenIdConnect[0][1]", equalTo("read:store"));
    vr.body("paths.'/store/inventory'.get.security.storeHttp[0]", equalTo(null));

    vr.body("paths.'/store/order/{orderId}'.get.security.storeOpenIdConnect", hasSize(2));
    vr.body("paths.'/store/order/{orderId}'.get.security.storeOpenIdConnect[0][0]", equalTo("write:store"));
    vr.body("paths.'/store/order/{orderId}'.get.security.storeOpenIdConnect[0][1]", equalTo("read:store"));
    vr.body("paths.'/store/order/{orderId}'.get.security.find { it.storeHttp != null }.storeHttp", empty());
    
    vr.body("paths.'/user'.post.security.find { it.userApiKey != null }.userApiKey", empty());
    vr.body("paths.'/user'.post.security.find { it.userBasicHttp != null }.userBasicHttp", empty());
    vr.body("paths.'/user'.post.security.find { it.userBearerHttp != null }.userBearerHttp", empty());
}