Java Code Examples for org.testng.Reporter#log()

The following examples show how to use org.testng.Reporter#log() . 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
Source File: AudValidationTest.java    From microprofile-jwt-auth with Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CONFIG,
    description = "Validate that JWT with aud that is contained in mp.jwt.verify.audiences returns HTTP_OK")
public void testRequiredAudMatch() throws Exception {
    Reporter.log("testRequiredAudMatch, expect HTTP_OK");

    String uri = baseURL.toExternalForm() + "endp/verifyAudIsOk";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        ;
    Response response = echoEndpointTarget.request(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
Source File: BenchmarkTestListener.java    From oxAuth with MIT License 6 votes vote down vote up
@Override
public void onFinish(ITestContext context) {
	final long takes = (context.getEndDate().getTime() - context.getStartDate().getTime()) / 1000;
       Reporter.log("Test '" + context.getName() + "' finished in " + takes + " seconds", true);
       Reporter.log("================================================================================", true);

       for (String methodName : this.methodNames) {
   		final long methodTakes = this.methodTakes.get(methodName);
   		final long methodInvoked = this.methodInvoked.get(methodName);
   		final long methodThreads = getMethodThreqads(context, methodName);

   		long oneExecutionMethodTakes = methodTakes == 0 ? 0 : methodTakes / methodInvoked;
   		Reporter.log("BENCHMARK REPORT | " + " Method: '" + methodName + "' | Takes:" + methodTakes + " | Invoked: " + methodInvoked + " | Threads: " + methodThreads + " | Average method execution: " + oneExecutionMethodTakes  , true);
       }
       Reporter.log("================================================================================", true);

}
 
Example 3
Source File: ClaimValueInjectionTest.java    From microprofile-jwt-auth with Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    description = "Verify that the injected aud claim using @Claim(standard) is as expected")
public void verifyInjectedAudienceStandard() throws Exception {
    Reporter.log("Begin verifyInjectedAudienceStandard\n");
    String uri = baseURL.toExternalForm() + "endp/verifyInjectedAudienceStandard";
    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();
    System.out.println(reply);
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 4
Source File: IssNoValidationBadIssTest.java    From microprofile-jwt-auth with Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CONFIG,
    description = "Validate that JWK with iss and no validation returns HTTP_OK",
    enabled = false
)
public void testNotRequiredIssIgnored() throws Exception {
    Reporter.log("testNotRequiredIssIgnored, expect HTTP_OK");

    String uri = baseURL.toExternalForm() + "endp/verifyBadIssIsOk";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        ;
    Response response = echoEndpointTarget.request(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 5
Source File: ECPublicKeyAsJWKLocationTest.java    From microprofile-jwt-auth with Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CONFIG,
    description = "Validate specifying the mp.jwt.verify.publickey.location as resource path to a JWK key")
public void testKeyAsLocation() throws Exception {
    Reporter.log("testKeyAsLocation, expect HTTP_OK");

    PrivateKey privateKey = TokenUtils.readECPrivateKey("/ecPrivateKey.pem");
    String kid = "eckey";
    String token = TokenUtils.signClaims(privateKey, kid, "/Token1.json");

    String uri = baseURL.toExternalForm() + "jwks/endp/verifyKeyLocationAsJWKResource";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("kid", kid)
        ;
    Response response = echoEndpointTarget.request(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 6
Source File: ClaimValueInjectionTest.java    From microprofile-jwt-auth with Apache License 2.0 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 verifyInjectedRawTokenStandard() throws Exception {
    Reporter.log("Begin verifyInjectedRawTokenStandard\n");
    String uri = baseURL.toExternalForm() + "endp/verifyInjectedRawTokenStandard";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.raw_token.name(), token)
        .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 7
Source File: ClaimValueInjectionTest.java    From microprofile-jwt-auth with Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    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 8
Source File: PublicKeyAsBase64JWKTest.java    From microprofile-jwt-auth with Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CONFIG,
    description = "Validate that the embedded base64 JWK key is used to verify the JWT signature")
public void testKeyAsBase64JWK() throws Exception {
    Reporter.log("testKeyAsBase64JWK, expect HTTP_OK");

    PrivateKey privateKey = TokenUtils.readPrivateKey("/privateKey4k.pem");
    String kid = "publicKey4k";
    HashMap<String, Long> timeClaims = new HashMap<>();
    String token = TokenUtils.generateTokenString(privateKey, kid, "/Token1.json", null, timeClaims);

    String uri = baseURL.toExternalForm() + "jwks/endp/verifyKeyAsBase64JWK";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("kid", kid)
        ;
    Response response = echoEndpointTarget.request(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
Source File: JsonValueInjectionTest.java    From microprofile-jwt-auth with Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
    description = "Verify that the injected customDouble claim is as expected")
public void verifyInjectedCustomDouble2() throws Exception {
    Reporter.log("Begin verifyInjectedCustomDouble2\n");
    String token2 = TokenUtils.generateTokenString("/Token2.json");
    String uri = baseURL.toExternalForm() + "endp/verifyInjectedCustomDouble";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("value", 3.241592653589793)
        .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 10
Source File: PublicKeyAsPEMLocationURLTest.java    From microprofile-jwt-auth with Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CONFIG, dependsOnMethods = { "validateLocationUrlContents" },
    description = "Validate specifying the mp.jwt.verify.publickey.location as remote URL to a PEM key")
public void testKeyAsLocationUrl() throws Exception {
    Reporter.log("testKeyAsLocationUrl, expect HTTP_OK");

    PrivateKey privateKey = TokenUtils.readPrivateKey("/privateKey4k.pem");
    String kid = "/privateKey4k.pem";
    HashMap<String, Long> timeClaims = new HashMap<>();
    String token = TokenUtils.generateTokenString(privateKey, kid, "/Token1.json", null, timeClaims);

    String uri = baseURL.toExternalForm() + "pem/endp/verifyKeyLocationAsPEMUrl";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        ;
    Response response = echoEndpointTarget.request(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
Source File: RolesAllowedTest.java    From microprofile-jwt-auth with Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_JAXRS,
    description = "Validate a request with MP-JWT succeeds with HTTP_OK, and replies with hello, user={token upn claim}")
public void callEcho() throws Exception {
    Reporter.log("callEcho, expect HTTP_OK");

    String uri = baseURL.toExternalForm() + "endp/echo";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("input", "hello")
        ;
    Response response = echoEndpointTarget.request(TEXT_PLAIN).header(HttpHeaders.AUTHORIZATION, "Bearer "+token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String reply = response.readEntity(String.class);
    // Must return hello, user={token upn claim}
    Assert.assertEquals(reply, "hello, [email protected]");
}
 
Example 12
Source File: ConsoleUtils.java    From Quantum with MIT License 5 votes vote down vote up
public static synchronized void logThread(String msg) {
	Reporter.log(msg, false);
	System.out.println(Thread.currentThread().getName() + ": " + msg);
	System.out.flush();
}
 
Example 13
Source File: BenchmarkTestListener.java    From oxAuth with MIT License 5 votes vote down vote up
@Override
public void onStart(ITestContext context) {
	Reporter.log("Test '" + context.getName() + "' started ...", true);

	this.methodNames = new ArrayList<String>();
	this.methodTakes = new HashMap<String, Long>();
	this.methodInvoked = new HashMap<String, Long>();
}
 
Example 14
Source File: RolesAllowedSignEncryptTest.java    From microprofile-jwt-auth with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_JAXRS, description = "Validate a request with MP-JWT Token2 calling echo fails with HTTP_FORBIDDEN")
public void echoWithToken2() throws Exception {
    Reporter.log("echoWithToken2, expect HTTP_FORBIDDEN");
    String token2 = signEncryptClaims("/Token2.json");

    String uri = baseURL.toExternalForm() + "endp/echo";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("input", "hello");
    Response response = echoEndpointTarget.request(TEXT_PLAIN).header(HttpHeaders.AUTHORIZATION, "Bearer "+token2).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_FORBIDDEN);
}
 
Example 15
Source File: RolesAllowedEncryptTest.java    From microprofile-jwt-auth with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    description = "Validate that accessing secured method has HTTP_OK and injected JsonWebToken principal")
public void getInjectedPrincipal() {
    Reporter.log("getInjectedPrincipal, expect HTTP_OK");
    String uri = baseURL.toExternalForm() + "endp/getInjectedPrincipal";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri);
    Response response = echoEndpointTarget.request(TEXT_PLAIN).header(HttpHeaders.AUTHORIZATION, "Bearer "+token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String reply = response.readEntity(String.class);
    Assert.assertEquals(reply, "isJsonWebToken:true");
}
 
Example 16
Source File: MyCoursesTestSuiteBase.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Recovery Scenario for all the screens if any of the test case fails
 * 
 * @throws Throwable
 */
@AfterMethod(alwaysRun = true)
public void recoveryScenario(ITestResult rs) throws Throwable {
	if (rs.getStatus() == 2) {
		gotoMyCoursesView();
		Reporter.log("Failed Test: " + rs.getTestName());
	}
}
 
Example 17
Source File: WebControllerBase.java    From stevia with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * uses Reporter to log the screenshot of a failed log entry (error(...)) to
 * the logs
 * 
 * @param file
 *            file must exist
 */
protected void reportLogScreenshot(File file) {
	Reporter.log("<a href=\"" + makeRelativePath(file) + "\"><p align=\"left\">Error screenshot at " + new Date() + "</p>");
	Reporter.log("<p><img width=\"1024\" src=\"" + makeRelativePath(file) + "\" alt=\"screenshot at " + new Date() + "\"/></p></a><br />");
	WEB_CONTROLLER_BASE_LOG.warn("Screenshot has been generated, path is {}", file.getAbsolutePath());
	// LOG.warn("Screenshot generated from this ", new Exception
	// ("STACKTRACE"));
}
 
Example 18
Source File: ReportLog.java    From teamengine with Apache License 2.0 4 votes vote down vote up
/**
 * Creates report logs that consists of test statics by extracting information from 
 * the Test suite results. These Report logs are then printed in the TestNG HTML reports.
 * 
 * @param suite is the test suite from which you want to extract test results information.
 */
public void generateLogs(ISuite suite) {
    Reporter.clear(); // clear output from previous test runs
    Reporter.log("The result of the test is-\n\n");

    //Following code gets the suite name
    String suiteName = suite.getName();
    //Getting the results for the said suite
    Map<String, ISuiteResult> suiteResults = suite.getResults();
    String input = null;
    String result;
    String failReport = null;
    String failReportConformance2=",";
    int passedTest = 0;
    int failedTest = 0;
    int skippedTest = 0;
    int finalPassedTest=0;
    int finalSkippedTest=0;
    int finalFailedTest=0;
    int count = 0;
    String date = null;
    for (ISuiteResult sr : suiteResults.values()) {
        count++;
        ITestContext tc = sr.getTestContext();
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Calendar cal = Calendar.getInstance();
        if (count == 1) {
            date = dateFormat.format(cal.getTime());
            input = tc.getAttribute("Input").toString();
            failReport = tc.getAttribute("TestResultReport").toString();
            passedTest = tc.getPassedTests().getAllResults().size();
            skippedTest = tc.getSkippedTests().getAllResults().size();
            failedTest = tc.getFailedTests().getAllResults().size();

        } else {
            int no_of_failedTest = tc.getFailedTests().getAllResults().size();
            int no_of_skippedTest = tc.getSkippedTests().getAllResults().size();
            int no_of_passedTest = tc.getPassedTests().getAllResults().size();
            if(no_of_failedTest!=0 || no_of_passedTest !=0)
            {
                if (no_of_failedTest == 0 && no_of_passedTest !=0 ) {
                failReportConformance2 = failReportConformance2+", "+input + " conform to the clause A." + count + " of "+suiteName;
            } else {
                    failReportConformance2 = failReportConformance2+", "+input + " does not conform to the clause A." + count + " of "+suiteName;
                
            }
            finalPassedTest = finalPassedTest + no_of_passedTest;
            finalSkippedTest = finalSkippedTest + no_of_skippedTest;
            finalFailedTest = finalFailedTest + no_of_failedTest;
        }
        }

    }
    failedTest+=finalFailedTest;
    skippedTest+=finalSkippedTest;
    passedTest+=finalPassedTest;
    if(failedTest>0){
      result="Fail";
    }else{
      result="Pass";
    }
    Reporter.log("**RESULT: " + result);
    Reporter.log("**INPUT: " + input);
    Reporter.log("**TEST NAME AND VERSION    :" + suiteName);
    Reporter.log("**DATE AND TIME PERFORMED  :" + date);
    Reporter.log("Passed tests for suite '" + suiteName
            + "' is:" + passedTest);

    Reporter.log("Failed tests for suite '" + suiteName
            + "' is:"
            + failedTest);

    Reporter.log("Skipped tests for suite '" + suiteName
            + "' is:"
            + skippedTest);
    Reporter.log("\nREASON:\n\n");
    Reporter.log(failReport);
    Reporter.log(failReportConformance2);

}
 
Example 19
Source File: LoggerBase.java    From functional-tests-core with Apache License 2.0 2 votes vote down vote up
/**
 * TODO(): Add docs.
 *
 * @param msg
 */
public void warn(String msg) {
    this.logger.warn(msg);
    Reporter.log(formatLoggerMessage(msg, "WARN"));
}
 
Example 20
Source File: Verify.java    From stevia with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Info.
 *
 * @param message the message
 */
public void info(String message) {
	VERIFY_LOG.info(message);
	Reporter.log("<p class=\"testOutput\" style=\"color:green; font-size:1em;\">"+ message + "</p>");
}