generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding methods and steps for creating test data and asserting the responses * adding default test data * addming mechanism to clean up data after test, even if test fails * adding tests * tidying up * correcting uri * checkstyle
- Loading branch information
1 parent
3d41ae1
commit 0fb7b51
Showing
12 changed files
with
311 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/functionalTest/java/uk/gov/hmcts/opal/steps/draftaccount/DraftAccountDeleteSteps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package uk.gov.hmcts.opal.steps.draftaccount; | ||
|
||
import io.cucumber.java.en.Then; | ||
import io.cucumber.java.en.When; | ||
import net.serenitybdd.rest.SerenityRest; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import uk.gov.hmcts.opal.steps.BaseStepDef; | ||
import uk.gov.hmcts.opal.utils.DraftAccountUtils; | ||
|
||
import java.util.ArrayList; | ||
|
||
import static uk.gov.hmcts.opal.config.Constants.DRAFT_ACCOUNT_URI; | ||
import static uk.gov.hmcts.opal.steps.BearerTokenStepDef.getToken; | ||
|
||
public class DraftAccountDeleteSteps extends BaseStepDef { | ||
static Logger log = LoggerFactory.getLogger(DraftAccountDeleteSteps.class.getName()); | ||
|
||
@When("I delete the draft account {string}") | ||
public static void deleteDraftAccount(String draftAccountId) { | ||
SerenityRest | ||
.given() | ||
.header("Authorization", "Bearer " + getToken()) | ||
.accept("*/*") | ||
.contentType("application/json") | ||
.when() | ||
.delete(getTestUrl() + DRAFT_ACCOUNT_URI + "/" + draftAccountId + "?ignoreMissing=true"); | ||
} | ||
|
||
@Then("I delete the created draft accounts") | ||
public static void deleteAllCreatedDraftAccounts() { | ||
ArrayList<String> accounts = DraftAccountUtils.getAllDraftAccountIds(); | ||
for (String account : accounts) { | ||
log.info("Deleting draft account: {}", account); | ||
deleteDraftAccount(account); | ||
} | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/functionalTest/java/uk/gov/hmcts/opal/steps/draftaccount/DraftAccountGetSteps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package uk.gov.hmcts.opal.steps.draftaccount; | ||
|
||
import io.cucumber.datatable.DataTable; | ||
import io.cucumber.java.en.When; | ||
import net.serenitybdd.rest.SerenityRest; | ||
import uk.gov.hmcts.opal.steps.BaseStepDef; | ||
import uk.gov.hmcts.opal.utils.DraftAccountUtils; | ||
|
||
import java.util.Map; | ||
|
||
import static net.serenitybdd.rest.SerenityRest.then; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static uk.gov.hmcts.opal.config.Constants.DRAFT_ACCOUNT_URI; | ||
import static uk.gov.hmcts.opal.steps.BearerTokenStepDef.getToken; | ||
|
||
public class DraftAccountGetSteps extends BaseStepDef { | ||
@When("I get the draft account {string}") | ||
public void getDraftAccount(String draftAccountId) { | ||
SerenityRest | ||
.given() | ||
.header("Authorization", "Bearer " + getToken()) | ||
.accept("*/*") | ||
.contentType("application/json") | ||
.when() | ||
.get(getTestUrl() + DRAFT_ACCOUNT_URI + "/" + draftAccountId); | ||
} | ||
|
||
@When("I get the single created draft account and the response contains") | ||
public void getSingleDraftAccount(DataTable data) { | ||
assertEquals( | ||
1, | ||
DraftAccountUtils.getAllDraftAccountIds().size(), | ||
"There should be only one draft account but found multiple: " + DraftAccountUtils.getAllDraftAccountIds() | ||
); | ||
String draftAccountId = DraftAccountUtils.getAllDraftAccountIds().getFirst(); | ||
SerenityRest | ||
.given() | ||
.header("Authorization", "Bearer " + getToken()) | ||
.accept("*/*") | ||
.contentType("application/json") | ||
.when() | ||
.get(getTestUrl() + DRAFT_ACCOUNT_URI + "/" + draftAccountId); | ||
|
||
Map<String, String> expectedData = data.asMap(String.class, String.class); | ||
|
||
for (String key : expectedData.keySet()) { | ||
String apiResponseValue = then().extract().body().jsonPath().getString(key); | ||
assertEquals(expectedData.get(key), apiResponseValue, "Values are not equal : "); | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/functionalTest/java/uk/gov/hmcts/opal/steps/draftaccount/DraftAccountPostSteps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package uk.gov.hmcts.opal.steps.draftaccount; | ||
|
||
import io.cucumber.datatable.DataTable; | ||
import io.cucumber.java.en.Then; | ||
import io.cucumber.java.en.When; | ||
import net.serenitybdd.rest.SerenityRest; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import uk.gov.hmcts.opal.steps.BaseStepDef; | ||
import uk.gov.hmcts.opal.utils.DraftAccountUtils; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.Map; | ||
|
||
import static net.serenitybdd.rest.SerenityRest.then; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static uk.gov.hmcts.opal.config.Constants.DRAFT_ACCOUNT_URI; | ||
import static uk.gov.hmcts.opal.steps.BearerTokenStepDef.getToken; | ||
|
||
public class DraftAccountPostSteps extends BaseStepDef { | ||
@When("I create a draft account with the following details") | ||
public void postDraftAccount(DataTable accountData) throws JSONException, IOException { | ||
Map<String, String> dataToPost = accountData.asMap(String.class, String.class); | ||
JSONObject postBody = new JSONObject(); | ||
|
||
postBody.put( | ||
"business_unit_id", | ||
dataToPost.get("business_unit_id") != null ? dataToPost.get("business_unit_id") : "" | ||
); | ||
postBody.put("submitted_by", dataToPost.get("submitted_by") != null ? dataToPost.get("submitted_by") : ""); | ||
postBody.put("account_type", dataToPost.get("account_type") != null ? dataToPost.get("account_type") : ""); | ||
postBody.put( | ||
"account_status", | ||
dataToPost.get("account_status") != null ? dataToPost.get("account_status") : "" | ||
); | ||
|
||
|
||
String accountFilePath = "build/resources/functionalTest/features/opalMode/manualAccountCreation/" | ||
+ dataToPost.get( | ||
"account"); | ||
String account = new String(Files.readAllBytes(Paths.get(accountFilePath))); | ||
JSONObject accountObject = new JSONObject(account); | ||
|
||
JSONObject timelineObject; | ||
if (dataToPost.get("timeline_data") != null) { | ||
String timelineFilePath = "build/resources/functionalTest/features/opalMode/manualAccountCreation/" | ||
+ dataToPost.get( | ||
"account"); | ||
String timeline = new String(Files.readAllBytes(Paths.get(timelineFilePath))); | ||
timelineObject = new JSONObject(timeline); | ||
} else { | ||
String timelineFilePath = "build/resources/functionalTest/features/opalMode/manualAccountCreation" | ||
+ "/draftAccounts/timelineJson/default.json"; | ||
String timeline = new String(Files.readAllBytes(Paths.get(timelineFilePath))); | ||
timelineObject = new JSONObject(timeline); | ||
} | ||
postBody.put("account", accountObject); | ||
postBody.put("timeline_data", timelineObject); | ||
|
||
SerenityRest | ||
.given() | ||
.header("Authorization", "Bearer " + getToken()) | ||
.accept("*/*") | ||
.contentType("application/json") | ||
.body(postBody.toString()) | ||
.when() | ||
.post(getTestUrl() + DRAFT_ACCOUNT_URI); | ||
} | ||
|
||
@Then("I store the created draft account ID") | ||
public void storeDraftAccountId() { | ||
String draftAccountId = then().extract().body().jsonPath().getString("draft_account_id"); | ||
DraftAccountUtils.addDraftAccountId(draftAccountId); | ||
} | ||
|
||
@Then("The draft account response contains the following data") | ||
public void draftAccountResponseContains(DataTable data) { | ||
Map<String, String> expectedData = data.asMap(String.class, String.class); | ||
|
||
for (String key : expectedData.keySet()) { | ||
String apiResponseValue = then().extract().body().jsonPath().getString(key); | ||
assertEquals(expectedData.get(key), apiResponseValue, "Values are not equal : "); | ||
} | ||
} | ||
|
||
@Then("The draft account response returns 201") | ||
public void draftAccountResponseCreated() { | ||
then().assertThat() | ||
.statusCode(201); | ||
} | ||
|
||
@Then("The draft account response returns 400") | ||
public void draftAccountResponseBadRequest() { | ||
then().assertThat() | ||
.statusCode(400); | ||
} | ||
|
||
@Then("The draft account response returns 500") | ||
public void draftAccountResponseInternalServerError() { | ||
then().assertThat() | ||
.statusCode(500); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/functionalTest/java/uk/gov/hmcts/opal/utils/DataCleanUp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package uk.gov.hmcts.opal.utils; | ||
|
||
import io.cucumber.java.After; | ||
import uk.gov.hmcts.opal.steps.BaseStepDef; | ||
import uk.gov.hmcts.opal.steps.draftaccount.DraftAccountDeleteSteps; | ||
|
||
public class DataCleanUp extends BaseStepDef { | ||
|
||
@After("@cleanUpData") | ||
public void cleanUpData() { | ||
DraftAccountDeleteSteps.deleteAllCreatedDraftAccounts(); | ||
DraftAccountUtils.clearDraftAccountIds(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/functionalTest/java/uk/gov/hmcts/opal/utils/DraftAccountUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package uk.gov.hmcts.opal.utils; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class DraftAccountUtils { | ||
private static final ThreadLocal<ArrayList<String>> draftAccountId = ThreadLocal.withInitial(ArrayList::new); | ||
|
||
public static void addDraftAccountId(String id) { | ||
draftAccountId.get().add(id); | ||
} | ||
|
||
public static ArrayList<String> getAllDraftAccountIds() { | ||
return draftAccountId.get(); | ||
} | ||
|
||
public static void clearDraftAccountIds() { | ||
draftAccountId.remove(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...rces/features/opalMode/manualAccountCreation/draftAccounts/PO-559_getDraftAccount.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@Opal | ||
Feature: PO-559 get draft account | ||
|
||
@PO-559 @cleanUpData | ||
Scenario: Get draft account - happy path | ||
Given I am testing as the "opal-test@hmcts.net" user | ||
When I create a draft account with the following details | ||
| business_unit_id | 73 | | ||
| account | draftAccounts/accountJson/adultAccount.json | | ||
| account_type | Fine | | ||
| account_status | | | ||
| submitted_by | | | ||
| timeline_data | | | ||
Then The draft account response returns 201 | ||
And I store the created draft account ID | ||
|
||
Then I get the single created draft account and the response contains | ||
| business_unit_id | 73 | | ||
| account_type | Fine | | ||
| account_status | Submitted | | ||
| account_snapshot.DefendantName | LNAME, FNAME | | ||
| account_snapshot.DateOfBirth | 01/01/2000 | | ||
| account_snapshot.AccountType | Fine | | ||
| account_snapshot.SubmittedBy | opal-test@HMCTS.NET | | ||
| account_snapshot.BusinessUnitName | MBEC London | | ||
|
||
Then I delete the created draft accounts | ||
|
||
|
29 changes: 29 additions & 0 deletions
29
...s/features/opalMode/manualAccountCreation/draftAccounts/PO-591_createDraftAccount.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@Opal | ||
Feature: PO-591 create draft account | ||
|
||
@PO-591 @cleanUpData | ||
Scenario: Create draft account - happy path | ||
Given I am testing as the "opal-test@hmcts.net" user | ||
When I create a draft account with the following details | ||
| business_unit_id | 73 | | ||
| account | draftAccounts/accountJson/adultAccount.json | | ||
| account_type | Fine | | ||
| account_status | | | ||
| submitted_by | | | ||
| timeline_data | | | ||
Then The draft account response returns 201 | ||
And I store the created draft account ID | ||
|
||
And The draft account response contains the following data | ||
| business_unit_id | 73 | | ||
| account_type | Fine | | ||
| account_status | Submitted | | ||
| account_snapshot.DefendantName | LNAME, FNAME | | ||
| account_snapshot.DateOfBirth | 01/01/2000 | | ||
| account_snapshot.AccountType | Fine | | ||
| account_snapshot.SubmittedBy | opal-test@HMCTS.NET | | ||
| account_snapshot.BusinessUnitName | MBEC London | | ||
|
||
Then I delete the created draft accounts | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
...urces/features/opalMode/manualAccountCreation/draftAccounts/accountJson/adultAccount.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"accountCreateRequest": { | ||
"Defendant": { | ||
"Surname": "LNAME", | ||
"Forenames": "FNAME", | ||
"DOB": "01/01/2000" | ||
}, | ||
"Account": { | ||
"AccountType": "Fine" | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...resources/features/opalMode/manualAccountCreation/draftAccounts/timelineJson/default.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"timeline": [ | ||
{ | ||
"username": "", | ||
"status": "", | ||
"status_date": "", | ||
"reason_text": "" | ||
} | ||
] | ||
} |