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.
- Loading branch information
Showing
24 changed files
with
879 additions
and
131 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
98 changes: 98 additions & 0 deletions
98
...onalTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/BulkAccountTest.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,98 @@ | ||
package uk.gov.hmcts.reform.pip.account.management.controllers; | ||
|
||
import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.HttpHeaders; | ||
import io.restassured.response.Response; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import uk.gov.hmcts.reform.pip.account.management.utils.FunctionalTestBase; | ||
import uk.gov.hmcts.reform.pip.account.management.utils.OAuthClient; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@ActiveProfiles(profiles = "functional") | ||
@SpringBootTest(classes = {OAuthClient.class}) | ||
class BulkAccountTest extends FunctionalTestBase { | ||
private static final String USER_ID = UUID.randomUUID().toString(); | ||
private static final String EMAIL_PREFIX = "pip-am-test-email-"; | ||
private static final String TEST_SUITE_PREFIX = String.format("%s-", | ||
ThreadLocalRandom.current().nextInt(1000, 9999)); | ||
private static final String TEST_SUITE_EMAIL_PREFIX = EMAIL_PREFIX + TEST_SUITE_PREFIX; | ||
private static final String BULK_UPLOAD_URL = "account/media-bulk-upload"; | ||
private static final String TESTING_SUPPORT_ACCOUNT_URL = "/testing-support/account/"; | ||
private static final String BEARER = "Bearer "; | ||
private static final String ISSUER_ID = "x-issuer-id"; | ||
|
||
private String mockFile; | ||
private Map<String, String> bearer; | ||
private Map<String, String> issuerId; | ||
|
||
@BeforeAll | ||
void startUp() throws IOException { | ||
bearer = Map.of(HttpHeaders.AUTHORIZATION, BEARER + accessToken); | ||
issuerId = Map.of(ISSUER_ID, USER_ID); | ||
|
||
StringBuilder csvContent = new StringBuilder(400); | ||
csvContent.append("email,firstName,surname\n"); | ||
|
||
for (int i = 0; i < 5; i++) { | ||
String email = generateTestEmail(); | ||
csvContent.append(email).append(",testBulkFirstName,testBulkSurname\n"); | ||
} | ||
|
||
Path mockFilePath = Files.createTempFile("mock-bulk-upload", ".csv"); | ||
try (BufferedWriter writer = Files.newBufferedWriter(mockFilePath)) { | ||
writer.write(csvContent.toString()); | ||
} | ||
|
||
mockFile = mockFilePath.toString(); | ||
} | ||
|
||
private String generateTestEmail() { | ||
String prefix = String.format("%s", ThreadLocalRandom.current().nextInt(1000, 9999)); | ||
return TEST_SUITE_EMAIL_PREFIX + prefix + "@justice.gov.uk"; | ||
} | ||
|
||
@AfterAll | ||
public void teardown() throws IOException { | ||
doDeleteRequest(TESTING_SUPPORT_ACCOUNT_URL + TEST_SUITE_EMAIL_PREFIX, bearer); | ||
Files.deleteIfExists(Path.of(mockFile)); | ||
} | ||
|
||
@Test | ||
void createAccountsInBulk() { | ||
File mockBulkUploadFile = new File(mockFile); | ||
|
||
Response response = doPostMultipartForBulk(BULK_UPLOAD_URL, bearer, issuerId, mockBulkUploadFile); | ||
|
||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK.value()); | ||
assertThat(response.jsonPath().getList("CREATED_ACCOUNTS").size()).isEqualTo(5); | ||
assertThat(response.jsonPath().getList("ERRORED_ACCOUNTS").isEmpty()).isTrue(); | ||
} | ||
|
||
@Test | ||
void shouldReturnOkButNotCreateAccountsForDuplicates() { | ||
File mockBulkUploadFile = new File(mockFile); | ||
|
||
Response response = doPostMultipartForBulk(BULK_UPLOAD_URL, bearer, issuerId, mockBulkUploadFile); | ||
|
||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK.value()); | ||
assertThat(response.jsonPath().getList("CREATED_ACCOUNTS").isEmpty()).isTrue(); | ||
assertThat(response.jsonPath().getList("ERRORED_ACCOUNTS").isEmpty()).isTrue(); | ||
} | ||
} |
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
90 changes: 90 additions & 0 deletions
90
...k/gov/hmcts/reform/pip/account/management/controllers/SystemAdminAccountCreationTest.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,90 @@ | ||
package uk.gov.hmcts.reform.pip.account.management.controllers; | ||
|
||
import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.HttpHeaders; | ||
import io.restassured.response.Response; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import uk.gov.hmcts.reform.pip.account.management.utils.FunctionalTestBase; | ||
import uk.gov.hmcts.reform.pip.account.management.utils.OAuthClient; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@ActiveProfiles(profiles = "functional") | ||
@SpringBootTest(classes = {OAuthClient.class}) | ||
class SystemAdminAccountCreationTest extends FunctionalTestBase { | ||
private static final String TEST_USER_EMAIL_PREFIX = String.format( | ||
"pip-am-test-email-%s", ThreadLocalRandom.current().nextInt(1000, 9999)); | ||
private static final String TEST_USER_EMAIL = TEST_USER_EMAIL_PREFIX + "@justice.gov.uk"; | ||
private static final String TEST_USER_PROVENANCE_ID = UUID.randomUUID().toString(); | ||
|
||
private static final String TESTING_SUPPORT_ACCOUNT_URL = "/testing-support/account/"; | ||
private static final String ACCOUNT_URL = "/account"; | ||
private static final String SYSTEM_ADMIN_URL = ACCOUNT_URL + "/system-admin"; | ||
private static final String BEARER = "Bearer "; | ||
|
||
private Map<String, String> bearer; | ||
|
||
@BeforeAll | ||
public void startUp() { | ||
bearer = Map.of(HttpHeaders.AUTHORIZATION, BEARER + accessToken); | ||
} | ||
|
||
@AfterAll | ||
public void teardown() { | ||
doDeleteRequest(TESTING_SUPPORT_ACCOUNT_URL + TEST_USER_EMAIL, bearer); | ||
} | ||
|
||
@Test | ||
void createSystemAdminAccount() { | ||
String requestBody = """ | ||
{ | ||
"email": "%s", | ||
"provenanceUserId": "%s" | ||
} | ||
""".formatted(TEST_USER_EMAIL, TEST_USER_PROVENANCE_ID); | ||
|
||
Response response = doPostRequest(SYSTEM_ADMIN_URL, bearer, requestBody); | ||
|
||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK.value()); | ||
assertThat(response.jsonPath().getString("email")).isEqualTo(TEST_USER_EMAIL); | ||
assertThat(response.jsonPath().getString("provenanceUserId")).isEqualTo(TEST_USER_PROVENANCE_ID); | ||
} | ||
|
||
@Test | ||
void shouldFailToCreateSystemAdminAccountWithoutEmail() { | ||
String requestBody = """ | ||
{ | ||
"provenanceUserId": "%s" | ||
} | ||
""".formatted(TEST_USER_PROVENANCE_ID); | ||
|
||
Response response = doPostRequest(SYSTEM_ADMIN_URL, bearer, requestBody); | ||
|
||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); | ||
} | ||
|
||
@Test | ||
void shouldFailToCreateSystemAdminAccountWithoutProvenanceUserId() { | ||
String requestBody = """ | ||
{ | ||
"email": "%s" | ||
} | ||
""".formatted(TEST_USER_EMAIL); | ||
|
||
Response response = doPostRequest(SYSTEM_ADMIN_URL, bearer, requestBody); | ||
|
||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); | ||
} | ||
|
||
} |
128 changes: 128 additions & 0 deletions
128
...ov/hmcts/reform/pip/account/management/controllers/SystemAdminB2CAccountCreationTest.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,128 @@ | ||
package uk.gov.hmcts.reform.pip.account.management.controllers; | ||
|
||
import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.HttpHeaders; | ||
import io.restassured.response.Response; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import uk.gov.hmcts.reform.pip.account.management.utils.FunctionalTestBase; | ||
import uk.gov.hmcts.reform.pip.account.management.utils.OAuthClient; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@ActiveProfiles(profiles = "functional") | ||
@SpringBootTest(classes = {OAuthClient.class}) | ||
class SystemAdminB2CAccountCreationTest extends FunctionalTestBase { | ||
private static final String TEST_USER_EMAIL_PREFIX_1 = String.format( | ||
"pip-am-test-email-%s", ThreadLocalRandom.current().nextInt(1000, 9999)); | ||
private static final String TEST_USER_EMAIL_PREFIX_2 = String.format( | ||
"pip-am-test-email-%s", ThreadLocalRandom.current().nextInt(1000, 9999)); | ||
private static final String TEST_USER_EMAIL_PREFIX_3 = String.format( | ||
"pip-am-test-email-%s", ThreadLocalRandom.current().nextInt(1000, 9999)); | ||
private static final String TEST_USER_EMAIL_1 = TEST_USER_EMAIL_PREFIX_1 + "@justice.gov.uk"; | ||
private static final String TEST_USER_EMAIL_2 = TEST_USER_EMAIL_PREFIX_2 + "@justice.gov.uk"; | ||
private static final String TEST_USER_EMAIL_3 = TEST_USER_EMAIL_PREFIX_3 + "@justice.gov.uk"; | ||
private static final String TEST_USER_PROVENANCE_ID = UUID.randomUUID().toString(); | ||
|
||
private static final String TESTING_SUPPORT_ACCOUNT_URL = "/testing-support/account/"; | ||
private static final String ACCOUNT_URL = "/account"; | ||
private static final String SYSTEM_ADMIN_B2C_URL = ACCOUNT_URL + "/add/system-admin"; | ||
private static final String SYSTEM_ADMIN_SSO_URL = ACCOUNT_URL + "/system-admin"; | ||
private static final String BEARER = "Bearer "; | ||
private static final String ISSUER_ID = "x-issuer-id"; | ||
|
||
private Map<String, String> bearer; | ||
private Map<String, String> issuerId; | ||
|
||
@BeforeAll | ||
public void startUp() { | ||
bearer = Map.of(HttpHeaders.AUTHORIZATION, BEARER + accessToken); | ||
|
||
String requestBody = """ | ||
{ | ||
"email": "%s", | ||
"provenanceUserId": "%s" | ||
} | ||
""".formatted(TEST_USER_EMAIL_3, UUID.randomUUID().toString()); | ||
|
||
String userId = doPostRequest(SYSTEM_ADMIN_SSO_URL, bearer, requestBody) | ||
.jsonPath().getString("userId"); | ||
|
||
issuerId = Map.of(ISSUER_ID, userId); | ||
} | ||
|
||
@AfterAll | ||
public void teardown() { | ||
doDeleteRequest(TESTING_SUPPORT_ACCOUNT_URL + TEST_USER_EMAIL_1, bearer); | ||
doDeleteRequest(TESTING_SUPPORT_ACCOUNT_URL + TEST_USER_EMAIL_2, bearer); | ||
doDeleteRequest(TESTING_SUPPORT_ACCOUNT_URL + TEST_USER_EMAIL_3, bearer); | ||
} | ||
|
||
@Test | ||
void createSystemAdminB2CAccount() { | ||
String requestBody = """ | ||
{ | ||
"email": "%s", | ||
"provenanceUserId": "%s" | ||
} | ||
""".formatted(TEST_USER_EMAIL_1, TEST_USER_PROVENANCE_ID); | ||
|
||
Response response = doPostRequestForB2C(SYSTEM_ADMIN_B2C_URL, bearer, issuerId, requestBody); | ||
|
||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK.value()); | ||
assertThat(response.jsonPath().getString("email")).isEqualTo(TEST_USER_EMAIL_1); | ||
assertThat(response.jsonPath().getString("provenanceUserId")).isNotNull(); | ||
} | ||
|
||
@Test | ||
void shouldCreateSystemAdminB2CAccountWithoutProvenanceUserId() { | ||
String requestBody = """ | ||
{ | ||
"email": "%s" | ||
} | ||
""".formatted(TEST_USER_EMAIL_2); | ||
|
||
Response response = doPostRequestForB2C(SYSTEM_ADMIN_B2C_URL, bearer, issuerId, requestBody); | ||
|
||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK.value()); | ||
assertThat(response.jsonPath().getString("email")).isEqualTo(TEST_USER_EMAIL_2); | ||
assertThat(response.jsonPath().getString("provenanceUserId")).isNotNull(); | ||
} | ||
|
||
@Test | ||
void shouldFailToCreateSystemAdminB2CAccountWithoutEmail() { | ||
String requestBody = """ | ||
{ | ||
"provenanceUserId": "%s" | ||
} | ||
""".formatted(TEST_USER_PROVENANCE_ID); | ||
|
||
Response response = doPostRequestForB2C(SYSTEM_ADMIN_B2C_URL, bearer, issuerId, requestBody); | ||
|
||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); | ||
} | ||
|
||
@Test | ||
void shouldFailToCreateSystemAdminB2CAccountWithoutIssuerId() { | ||
String requestBody = """ | ||
{ | ||
"email": "%s", | ||
"provenanceUserId": "%s" | ||
} | ||
""".formatted(TEST_USER_EMAIL_1, TEST_USER_PROVENANCE_ID); | ||
|
||
Response response = doPostRequest(SYSTEM_ADMIN_B2C_URL, bearer, requestBody); | ||
|
||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); | ||
} | ||
} |
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
Oops, something went wrong.