Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import net.serenitybdd.rest.SerenityRest;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import uk.gov.hmcts.reform.wataskmanagementapi.controllers.request.AssignTaskRequest;
import uk.gov.hmcts.reform.wataskmanagementapi.utils.TaskFunctionalTestsUserUtils;

import static net.serenitybdd.rest.SerenityRest.given;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -17,6 +19,9 @@ public class EndpointSecurityTest extends SpringBootFunctionalBaseTest {
@Value("${targets.instance}")
private String testUrl;

@Autowired
TaskFunctionalTestsUserUtils taskFunctionalTestsUserUtils;

@Before
public void setUp() {

Expand Down Expand Up @@ -112,7 +117,7 @@ public void should_return_401_when_bearer_token_is_provided_but_no_service_token

given()
.relaxedHTTPSValidation()
.header(authorizationProvider.getCaseworkerAuthorizationOnly("wa-ft-test-"))
.header(taskFunctionalTestsUserUtils.getAuthorizationHeaders())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.baseUri(testUrl)
.when()
Expand All @@ -123,7 +128,7 @@ public void should_return_401_when_bearer_token_is_provided_but_no_service_token

given()
.relaxedHTTPSValidation()
.header(authorizationProvider.getCaseworkerAuthorizationOnly("wa-ft-test-"))
.header(taskFunctionalTestsUserUtils.getAuthorizationHeaders())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.baseUri(testUrl)
.pathParam("task-id", taskId)
Expand All @@ -135,7 +140,7 @@ public void should_return_401_when_bearer_token_is_provided_but_no_service_token

given()
.relaxedHTTPSValidation()
.header(authorizationProvider.getCaseworkerAuthorizationOnly("wa-ft-test-"))
.header(taskFunctionalTestsUserUtils.getAuthorizationHeaders())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.baseUri(testUrl)
.pathParam("task-id", taskId)
Expand All @@ -147,7 +152,7 @@ public void should_return_401_when_bearer_token_is_provided_but_no_service_token

given()
.relaxedHTTPSValidation()
.header(authorizationProvider.getCaseworkerAuthorizationOnly("wa-ft-test-"))
.header(taskFunctionalTestsUserUtils.getAuthorizationHeaders())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.baseUri(testUrl)
.pathParam("task-id", taskId)
Expand All @@ -159,7 +164,7 @@ public void should_return_401_when_bearer_token_is_provided_but_no_service_token

given()
.relaxedHTTPSValidation()
.header(authorizationProvider.getCaseworkerAuthorizationOnly("wa-ft-test-"))
.header(taskFunctionalTestsUserUtils.getAuthorizationHeaders())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.baseUri(testUrl)
.pathParam("task-id", taskId)
Expand All @@ -172,7 +177,7 @@ public void should_return_401_when_bearer_token_is_provided_but_no_service_token

given()
.relaxedHTTPSValidation()
.header(authorizationProvider.getCaseworkerAuthorizationOnly("wa-ft-test-"))
.header(taskFunctionalTestsUserUtils.getAuthorizationHeaders())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.baseUri(testUrl)
.pathParam("task-id", taskId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
import io.restassured.http.Header;
import io.restassured.response.Response;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import uk.gov.hmcts.reform.wataskmanagementapi.SpringBootFunctionalBaseTest;
import uk.gov.hmcts.reform.wataskmanagementapi.utils.TaskFunctionalTestsApiUtils;

public class SwaggerTest extends SpringBootFunctionalBaseTest {

@Autowired
TaskFunctionalTestsApiUtils taskFunctionalTestsApiUtils;

private static final String SWAGGER_URL = "/swagger-ui/index.html";

@Test
public void swagger_ui_should_be_accessible_with_no_auth_long_url() {

Response result = restApiActions.get(
Response result = taskFunctionalTestsApiUtils.getRestApiActions().get(
SWAGGER_URL,
new Header("Content-type", "application/json")
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package uk.gov.hmcts.reform.wataskmanagementapi.watasks.controllers;

import io.restassured.response.Response;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import uk.gov.hmcts.reform.wataskmanagementapi.SpringBootFunctionalBaseTest;
import uk.gov.hmcts.reform.wataskmanagementapi.controllers.request.TerminateTaskRequest;
import uk.gov.hmcts.reform.wataskmanagementapi.controllers.request.options.TerminateInfo;
import uk.gov.hmcts.reform.wataskmanagementapi.domain.TestAuthenticationCredentials;
import uk.gov.hmcts.reform.wataskmanagementapi.domain.TestVariables;
import uk.gov.hmcts.reform.wataskmanagementapi.utils.TaskFunctionalTestsApiUtils;
import uk.gov.hmcts.reform.wataskmanagementapi.utils.TaskFunctionalTestsUserUtils;

import java.util.Map;

Expand All @@ -19,25 +22,25 @@

public class DeleteTaskByIdControllerTest extends SpringBootFunctionalBaseTest {

@Autowired
TaskFunctionalTestsUserUtils taskFunctionalTestsUserUtils;

@Autowired
TaskFunctionalTestsApiUtils taskFunctionalTestsApiUtils;

private static final String ENDPOINT_BEING_TESTED = "task/{task-id}";

private TestAuthenticationCredentials caseWorkerWithCftOrgRoles;

@Before
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need @before method here?

public void setUp() {
waCaseworkerCredentials = authorizationProvider.getNewTribunalCaseworker(EMAIL_PREFIX_R3_5);
}

@After
public void cleanUp() {
common.clearAllRoleAssignments(waCaseworkerCredentials.getHeaders());
authorizationProvider.deleteAccount(waCaseworkerCredentials.getAccount().getUsername());

common.clearAllRoleAssignments(baseCaseworkerCredentials.getHeaders());
authorizationProvider.deleteAccount(baseCaseworkerCredentials.getAccount().getUsername());
caseWorkerWithCftOrgRoles = taskFunctionalTestsUserUtils.getTestUser(
TaskFunctionalTestsUserUtils.USER_WITH_CFT_ORG_ROLES);
}

@Test
public void should_succeed_when_terminate_reason_is_cancelled() {
TestVariables taskVariables = common.setupWATaskAndRetrieveIds();
TestVariables taskVariables = taskFunctionalTestsApiUtils.getCommon().setupWATaskAndRetrieveIds();
initiateTask(taskVariables);

claimAndCancelTask(taskVariables);
Expand All @@ -48,11 +51,11 @@ public void should_succeed_when_terminate_reason_is_cancelled() {
new TerminateInfo("cancelled")
);

Response result = restApiActions.delete(
Response result = taskFunctionalTestsApiUtils.getRestApiActions().delete(
ENDPOINT_BEING_TESTED,
taskVariables.getTaskId(),
terminateTaskRequest,
waCaseworkerCredentials.getHeaders()
caseWorkerWithCftOrgRoles.getHeaders()
);

result.then().assertThat()
Expand All @@ -63,7 +66,7 @@ public void should_succeed_when_terminate_reason_is_cancelled() {

@Test
public void should_succeed_when_terminate_reason_is_completed() {
TestVariables taskVariables = common.setupWATaskAndRetrieveIds();
TestVariables taskVariables = taskFunctionalTestsApiUtils.getCommon().setupWATaskAndRetrieveIds();
initiateTask(taskVariables);
TestVariables testVariables = claimAndCompleteTask(taskVariables);
checkHistoryVariable(testVariables.getTaskId(), "cftTaskState", "pendingTermination");
Expand All @@ -72,11 +75,11 @@ public void should_succeed_when_terminate_reason_is_completed() {
new TerminateInfo("completed")
);

Response result = restApiActions.delete(
Response result = taskFunctionalTestsApiUtils.getRestApiActions().delete(
ENDPOINT_BEING_TESTED,
testVariables.getTaskId(),
terminateTaskRequest,
waCaseworkerCredentials.getHeaders()
caseWorkerWithCftOrgRoles.getHeaders()
);

result.then().assertThat()
Expand All @@ -93,10 +96,10 @@ private void checkHistoryVariable(String taskId, String variable, String value)
"taskIdIn", singleton(taskId)
);

Response result = camundaApiActions.post(
Response result = taskFunctionalTestsApiUtils.getCamundaApiActions().post(
"/history/variable-instance",
request,
waCaseworkerCredentials.getHeaders()
caseWorkerWithCftOrgRoles.getHeaders()
);

if (value == null) {
Expand All @@ -121,17 +124,15 @@ private void checkHistoryVariable(String taskId, String variable, String value)
private TestVariables claimAndCancelTask(TestVariables taskVariables) {
String taskId = taskVariables.getTaskId();

common.setupCFTOrganisationalRoleAssignment(waCaseworkerCredentials.getHeaders(),
WA_JURISDICTION, WA_CASE_TYPE);
given.iClaimATaskWithIdAndAuthorization(
taskFunctionalTestsApiUtils.getGiven().iClaimATaskWithIdAndAuthorization(
taskId,
waCaseworkerCredentials.getHeaders(),
caseWorkerWithCftOrgRoles.getHeaders(),
HttpStatus.NO_CONTENT
);
Response result = restApiActions.post(
Response result = taskFunctionalTestsApiUtils.getRestApiActions().post(
"task/{task-id}/cancel",
taskId,
waCaseworkerCredentials.getHeaders()
caseWorkerWithCftOrgRoles.getHeaders()
);

result.then().assertThat()
Expand All @@ -143,23 +144,22 @@ private TestVariables claimAndCancelTask(TestVariables taskVariables) {

private TestVariables claimAndCompleteTask(TestVariables taskVariables) {
String taskId = taskVariables.getTaskId();
common.setupCFTOrganisationalRoleAssignment(waCaseworkerCredentials.getHeaders(),
WA_JURISDICTION, WA_CASE_TYPE);
given.iClaimATaskWithIdAndAuthorization(
taskFunctionalTestsApiUtils.getGiven().iClaimATaskWithIdAndAuthorization(
taskId,
waCaseworkerCredentials.getHeaders(),
caseWorkerWithCftOrgRoles.getHeaders(),
HttpStatus.NO_CONTENT
);
Response result = restApiActions.post(
Response result = taskFunctionalTestsApiUtils.getRestApiActions().post(
"task/{task-id}/complete",
taskId,
waCaseworkerCredentials.getHeaders()
caseWorkerWithCftOrgRoles.getHeaders()
);

result.then().assertThat()
.statusCode(HttpStatus.NO_CONTENT.value());

assertions.taskVariableWasUpdated(taskVariables.getProcessInstanceId(), "taskState", "completed");
taskFunctionalTestsApiUtils.getAssertions().taskVariableWasUpdated(
taskVariables.getProcessInstanceId(), "taskState", "completed");

return taskVariables;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,50 @@

import io.restassured.http.Header;
import io.restassured.response.Response;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import uk.gov.hmcts.reform.wataskmanagementapi.SpringBootFunctionalBaseTest;
import uk.gov.hmcts.reform.wataskmanagementapi.controllers.request.DeleteCaseTasksAction;
import uk.gov.hmcts.reform.wataskmanagementapi.controllers.request.DeleteTasksRequest;
import uk.gov.hmcts.reform.wataskmanagementapi.domain.TestAuthenticationCredentials;
import uk.gov.hmcts.reform.wataskmanagementapi.domain.TestVariables;
import uk.gov.hmcts.reform.wataskmanagementapi.utils.TaskFunctionalTestsApiUtils;
import uk.gov.hmcts.reform.wataskmanagementapi.utils.TaskFunctionalTestsUserUtils;

import static uk.gov.hmcts.reform.wataskmanagementapi.config.SecurityConfiguration.AUTHORIZATION;

public class DeleteTasksByCaseIdControllerTest extends SpringBootFunctionalBaseTest {

@Autowired
TaskFunctionalTestsUserUtils taskFunctionalTestsUserUtils;

@Autowired
TaskFunctionalTestsApiUtils taskFunctionalTestsApiUtils;

private static final String ENDPOINT_BEING_TESTED = "task/delete";
private TestAuthenticationCredentials caseworkerCredentials;

private TestAuthenticationCredentials caseworkerWithNoRoles;

@Before
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this @before method in few places , which I believe is uneccessary

public void setUp() {
caseworkerCredentials = authorizationProvider.getNewTribunalCaseworker("wa-ft-test-r2-");
}

@After
public void cleanUp() {
common.clearAllRoleAssignments(caseworkerCredentials.getHeaders());
authorizationProvider.deleteAccount(caseworkerCredentials.getAccount().getUsername());
caseworkerWithNoRoles = taskFunctionalTestsUserUtils.getTestUser(
TaskFunctionalTestsUserUtils.USER_WITH_NO_ROLES);
}

@Test
public void should_return_201_when_task_deleted() {
final TestVariables taskVariables = common.setupWATaskAndRetrieveIds();
final TestVariables taskVariables = taskFunctionalTestsApiUtils.getCommon().setupWATaskAndRetrieveIds();
initiateTask(taskVariables);

final DeleteTasksRequest deleteTasksRequest = new DeleteTasksRequest(new DeleteCaseTasksAction(
taskVariables.getCaseId()));

final Response result = restApiActions.post(
final Response result = taskFunctionalTestsApiUtils.getRestApiActions().post(
ENDPOINT_BEING_TESTED,
deleteTasksRequest,
caseworkerCredentials.getHeaders()
caseworkerWithNoRoles.getHeaders()
);

result.then().assertThat().statusCode(HttpStatus.CREATED.value());
Expand All @@ -53,7 +56,7 @@ public void should_return_401_when_when_service_unauthorized() {
final DeleteTasksRequest deleteTasksRequest = new DeleteTasksRequest(new DeleteCaseTasksAction(
"1234567891234567"));

final Response result = restApiActions.post(
final Response result = taskFunctionalTestsApiUtils.getRestApiActions().post(
ENDPOINT_BEING_TESTED,
deleteTasksRequest,
new Header(AUTHORIZATION, "some_invalid_token")
Expand Down
Loading