Skip to content

Commit

Permalink
Integrate alt user tokens (#228)
Browse files Browse the repository at this point in the history
* tidying gradle test tasks

* PO-220 integrate get token with defined user

* checkstyle

* junit report issue

* fixing spelling mistake in BearerTokenStepDef
  • Loading branch information
CadeFaulkner authored Feb 28, 2024
1 parent 0d57371 commit c376035
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 36 deletions.
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ task functionalOpal(type: Test) {
group = "Verification"
testClassesDirs = sourceSets.functionalTest.output.classesDirs
classpath = sourceSets.functionalTest.runtimeClasspath
reports.junitXml.getOutputLocation().set(layout.buildDirectory.dir("test-results/functional"))
testLogging.showStandardStreams = true
gradle.startParameter.continueOnFailure = true
systemProperty "cucumber.filter.tags", "@Opal and not @Smoke and not @Ignore"
Expand All @@ -96,6 +97,7 @@ task functionalLegacy(type: Test) {
group = "Verification"
testClassesDirs = sourceSets.functionalTest.output.classesDirs
classpath = sourceSets.functionalTest.runtimeClasspath
reports.junitXml.getOutputLocation().set(layout.buildDirectory.dir("test-results/functional"))
gradle.startParameter.continueOnFailure = true
testLogging.showStandardStreams = true
systemProperty "cucumber.filter.tags", "@Legacy and not @Smoke and not @Ignore"
Expand All @@ -107,10 +109,9 @@ task copyFunctionalReport(type: Copy){
logger.quiet("Functional Test Report available at - file://${rootDir}/functional-test-report/index.html")
}

task functional(type: Test) {
task functional() {
description = "Runs functional tests"
group = "Verification"
testLogging.showStandardStreams = true
gradle.startParameter.continueOnFailure = true
dependsOn('clearReports','functionalOpal', 'functionalLegacy', 'aggregate', 'copyFunctionalReport')
tasks.functionalOpal.mustRunAfter clearReports
Expand All @@ -124,6 +125,7 @@ task smokeOpal(type: Test) {
group = "Verification"
testClassesDirs = sourceSets.functionalTest.output.classesDirs
classpath = sourceSets.functionalTest.runtimeClasspath
reports.junitXml.getOutputLocation().set(layout.buildDirectory.dir("test-results/smoke"))
testLogging.showStandardStreams = true
gradle.startParameter.continueOnFailure = true
systemProperty "cucumber.filter.tags", "@Smoke and not @Ignore"
Expand All @@ -134,10 +136,9 @@ task copySmokeReport(type: Copy){
logger.quiet("Smoke Test Report available at - file://${rootDir}/smoke-test-report/index.html")
}

task smoke(type: Test) {
task smoke() {
description = "Runs Smoke Tests"
group = "Verification"
testLogging.showStandardStreams = true
gradle.startParameter.continueOnFailure = true
dependsOn('clearReports','smokeOpal', 'aggregate', 'copySmokeReport')
tasks.smokeOpal.mustRunAfter clearReports
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package uk.gov.hmcts.opal.steps;

import io.cucumber.java.BeforeAll;
import io.cucumber.java.en.When;
import net.serenitybdd.rest.SerenityRest;

import static net.serenitybdd.rest.SerenityRest.then;


public class BearerTokenStepDef extends BaseStepDef {
protected static String TOKEN;
protected static ThreadLocal<String> ALT_TOKEN = new ThreadLocal<>();

@BeforeAll
public static void setToken() {
SerenityRest.given()
.accept("*/*")
.contentType("application/json")
.when()
.get(getTestUrl() + "/api/testing-support/token/test-user");
then().assertThat().statusCode(200);
TOKEN = then().extract().body().jsonPath().getString("access_token");
}

protected static String getToken() {
if (ALT_TOKEN.get() == null) {
return TOKEN;
} else {
return ALT_TOKEN.get();
}
}

@When("I am testing as the {string} user")
public void setTokenWithUser(String user) {
SerenityRest.given()
.accept("*/*")
.header("X-User-Email", user)
.contentType("application/json")
.when()
.get(getTestUrl() + "/api/testing-support/token/user");
then().assertThat().statusCode(200);
ALT_TOKEN.set(then().extract().body().jsonPath().getString("access_token"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import static net.serenitybdd.rest.SerenityRest.then;
import static org.junit.Assert.assertEquals;
import static uk.gov.hmcts.opal.steps.BearerTokenStefDef.getToken;
import static uk.gov.hmcts.opal.steps.BearerTokenStepDef.getToken;

public class DefendantAccountAddNoteStepDef extends BaseStepDef {
@When("I make a request to the defendant account add notes api with")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import static net.serenitybdd.rest.SerenityRest.then;
import static org.junit.Assert.assertEquals;
import static uk.gov.hmcts.opal.steps.BearerTokenStefDef.getToken;
import static uk.gov.hmcts.opal.steps.BearerTokenStepDef.getToken;


public class DefendantAccountDetailsStefDef extends BaseStepDef {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.Map;

import static net.serenitybdd.rest.SerenityRest.then;
import static uk.gov.hmcts.opal.steps.BearerTokenStefDef.getToken;
import static uk.gov.hmcts.opal.steps.BearerTokenStepDef.getToken;

public class DefendantSearchApiStepDef extends BaseStepDef {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.serenitybdd.rest.SerenityRest;
import org.hamcrest.Matchers;

import static uk.gov.hmcts.opal.steps.BearerTokenStefDef.getToken;
import static uk.gov.hmcts.opal.steps.BearerTokenStepDef.getToken;

public class HealthApiStepDef extends BaseStepDef {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.Map;

import static net.serenitybdd.rest.SerenityRest.then;
import static uk.gov.hmcts.opal.steps.BearerTokenStefDef.getToken;
import static uk.gov.hmcts.opal.steps.BearerTokenStepDef.getToken;

public class NotesApiStepDef extends BaseStepDef {

Expand Down

0 comments on commit c376035

Please sign in to comment.