Skip to content

Commit

Permalink
Added unit test for preset operation deletion.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnisLucidi01 committed Aug 29, 2023
1 parent f654d1d commit b0f610e
Showing 1 changed file with 97 additions and 51 deletions.
148 changes: 97 additions & 51 deletions src/test/java/it/pagopa/swclient/mil/preset/PresetsResourceTest.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,52 @@ void createPreset_201() {

}

/* **** preset **** */
@Test
@TestSecurity(user = "userJwt", roles = {"InstitutionPortal"})
void deletePreset_204() {

Mockito
.when(presetRepository.delete(Mockito.any(String.class), Mockito.any(Object.class)))
.thenReturn(Uni.createFrom().item(1L));

final String PRESET_ID = "77457c64-0870-407a-b2cb-0f948b04fb9a";

Response response = given()
.contentType(ContentType.JSON)
.headers(presetHeaders)
.and()
.pathParam("presetId", PRESET_ID)
.when()
.delete("/{presetId}")
.then()
.extract()
.response();




Assertions.assertEquals(204, response.statusCode());
}


@Test
@TestSecurity(user = "userJwt", roles = {"InstitutionPortal"})
void deletePreset_404() {


Response response = given()
.contentType(ContentType.JSON)
.headers(presetHeaders)
.when()
.delete("774e7c64-0870-407a-b2cb-0f948b04fb9a")
.then()
.extract()
.response();

Assertions.assertEquals(404, response.statusCode());
}


@Test
@TestSecurity(user = "userJwt", roles = {"InstitutionPortal"})
Expand Down Expand Up @@ -250,8 +296,8 @@ void createPreset_200_dbError_updateSubscriber() {
}

@TestSecurity(user = "userJwt", roles = {"InstitutionPortal"})
@ParameterizedTest
@MethodSource("it.pagopa.swclient.mil.preset.util.TestUtils#provideHeaderValidationErrorCases")
@ParameterizedTest
@MethodSource("it.pagopa.swclient.mil.preset.util.TestUtils#provideHeaderValidationErrorCases")
void createPreset_400_invalidHeaders(Map<String, String> invalidHeaders, String errorCode) {

CreatePresetRequest request = new CreatePresetRequest();
Expand All @@ -271,16 +317,16 @@ void createPreset_400_invalidHeaders(Map<String, String> invalidHeaders, String
.extract()
.response();

Assertions.assertEquals(400, response.statusCode());
Assertions.assertEquals(1, response.jsonPath().getList("errors").size());
Assertions.assertTrue(response.jsonPath().getList("errors").contains(errorCode));
Assertions.assertEquals(400, response.statusCode());
Assertions.assertEquals(1, response.jsonPath().getList("errors").size());
Assertions.assertTrue(response.jsonPath().getList("errors").contains(errorCode));
Assertions.assertNull(response.getHeader("Location"));

}

@ParameterizedTest
@TestSecurity(user = "userJwt", roles = {"InstitutionPortal"})
@MethodSource("it.pagopa.swclient.mil.preset.util.TestUtils#provideActivateRequestValidationErrorCases")
@MethodSource("it.pagopa.swclient.mil.preset.util.TestUtils#provideActivateRequestValidationErrorCases")
void createPreset_400_invalidRequest(CreatePresetRequest request, String errorCode) {

Response response = given()
Expand All @@ -294,8 +340,8 @@ void createPreset_400_invalidRequest(CreatePresetRequest request, String errorCo
.response();

Assertions.assertEquals(400, response.statusCode());
Assertions.assertEquals(1, response.jsonPath().getList("errors").size());
Assertions.assertTrue(response.jsonPath().getList("errors").contains(errorCode));
Assertions.assertEquals(1, response.jsonPath().getList("errors").size());
Assertions.assertTrue(response.jsonPath().getList("errors").contains(errorCode));
Assertions.assertNull(response.getHeader("Location"));
}

Expand Down Expand Up @@ -530,8 +576,8 @@ void getPresets_200_emptyPresets() {

}

@ParameterizedTest
@MethodSource("it.pagopa.swclient.mil.preset.util.TestUtils#provideHeaderValidationErrorCases")
@ParameterizedTest
@MethodSource("it.pagopa.swclient.mil.preset.util.TestUtils#provideHeaderValidationErrorCases")
@TestSecurity(user = "userJwt", roles = {"InstitutionPortal"})
void getPresets_400_invalidHeaders(Map<String, String> invalidHeaders, String errorCode) {

Expand All @@ -546,33 +592,33 @@ void getPresets_400_invalidHeaders(Map<String, String> invalidHeaders, String er
.extract()
.response();

Assertions.assertEquals(400, response.statusCode());
Assertions.assertEquals(1, response.jsonPath().getList("errors").size());
Assertions.assertTrue(response.jsonPath().getList("errors").contains(errorCode));
Assertions.assertEquals(400, response.statusCode());
Assertions.assertEquals(1, response.jsonPath().getList("errors").size());
Assertions.assertTrue(response.jsonPath().getList("errors").contains(errorCode));
Assertions.assertNull(response.getHeader("Location"));
}
@ParameterizedTest
@MethodSource("it.pagopa.swclient.mil.preset.util.TestUtils#providePaTaxCodeSubscriberIdValidationErrorCases")

@ParameterizedTest
@MethodSource("it.pagopa.swclient.mil.preset.util.TestUtils#providePaTaxCodeSubscriberIdValidationErrorCases")
@TestSecurity(user = "userJwt", roles = {"InstitutionPortal"})
void getPresets_400_invalidPathParams(String paTaxCode, String subscriberId, String errorCode) {
Response response = given()
.contentType(ContentType.JSON)
.headers(presetHeaders)
.pathParam("paTaxCode", paTaxCode)
.pathParam("subscriberId", subscriberId)
.when()
.get("/{paTaxCode}/{subscriberId}")
.then()
.extract()
.response();

Assertions.assertEquals(400, response.statusCode());
Assertions.assertEquals(1, response.jsonPath().getList("errors").size());
Assertions.assertTrue(response.jsonPath().getList("errors").contains(errorCode));
Assertions.assertNull(response.getHeader("Location"));
}
Response response = given()
.contentType(ContentType.JSON)
.headers(presetHeaders)
.pathParam("paTaxCode", paTaxCode)
.pathParam("subscriberId", subscriberId)
.when()
.get("/{paTaxCode}/{subscriberId}")
.then()
.extract()
.response();

Assertions.assertEquals(400, response.statusCode());
Assertions.assertEquals(1, response.jsonPath().getList("errors").size());
Assertions.assertTrue(response.jsonPath().getList("errors").contains(errorCode));
Assertions.assertNull(response.getHeader("Location"));
}

@Test
@TestSecurity(user = "userJwt", roles = {"InstitutionPortal"})
void getPresets_500_dbError_listPresets() {
Expand Down Expand Up @@ -652,11 +698,11 @@ void getLastPresetsOperation_200() {

}

@ParameterizedTest
@MethodSource("it.pagopa.swclient.mil.preset.util.TestUtils#provideAllHeaderValidationErrorCases")
@ParameterizedTest
@MethodSource("it.pagopa.swclient.mil.preset.util.TestUtils#provideAllHeaderValidationErrorCases")
@TestSecurity(user = "userJwt", roles = {"SlavePos"})
void getLastPresetsOperation_400_invalidHeaders(Map<String, String> invalidHeaders, String errorCode) {
Response response = given()
Response response = given()
.contentType(ContentType.JSON)
.headers(invalidHeaders)
.pathParam("paTaxCode", PA_TAX_CODE)
Expand All @@ -666,19 +712,19 @@ void getLastPresetsOperation_400_invalidHeaders(Map<String, String> invalidHeade
.then()
.extract()
.response();
Assertions.assertEquals(400, response.statusCode());
Assertions.assertEquals(1, response.jsonPath().getList("errors").size());
Assertions.assertTrue(response.jsonPath().getList("errors").contains(errorCode));

Assertions.assertEquals(400, response.statusCode());
Assertions.assertEquals(1, response.jsonPath().getList("errors").size());
Assertions.assertTrue(response.jsonPath().getList("errors").contains(errorCode));
Assertions.assertNull(response.getHeader("Location"));

}
@ParameterizedTest
@MethodSource("it.pagopa.swclient.mil.preset.util.TestUtils#providePaTaxCodeSubscriberIdValidationErrorCases")
}

@ParameterizedTest
@MethodSource("it.pagopa.swclient.mil.preset.util.TestUtils#providePaTaxCodeSubscriberIdValidationErrorCases")
@TestSecurity(user = "userJwt", roles = {"SlavePos"})
void getLastPresetsOperation_400_invalidPathParams(String paTaxCode, String subscriberId, String errorCode) {
Response response = given()
Response response = given()
.contentType(ContentType.JSON)
.headers(commonHeaders)
.pathParam("paTaxCode", paTaxCode)
Expand All @@ -688,14 +734,14 @@ void getLastPresetsOperation_400_invalidPathParams(String paTaxCode, String subs
.then()
.extract()
.response();
Assertions.assertEquals(400, response.statusCode());
Assertions.assertEquals(1, response.jsonPath().getList("errors").size());
Assertions.assertTrue(response.jsonPath().getList("errors").contains(errorCode));

Assertions.assertEquals(400, response.statusCode());
Assertions.assertEquals(1, response.jsonPath().getList("errors").size());
Assertions.assertTrue(response.jsonPath().getList("errors").contains(errorCode));
Assertions.assertNull(response.getHeader("Location"));

}
}

@Test
@TestSecurity(user = "userJwt", roles = {"SlavePos"})
void getLastPresetsOperation_404_presetNotFound() {
Expand Down

0 comments on commit b0f610e

Please sign in to comment.