diff --git a/src/main/java/it/gov/pagopa/rtp/activator/RtpActivatorApplication.java b/src/main/java/it/gov/pagopa/rtp/activator/RtpActivatorApplication.java index 79fbcab..0401379 100644 --- a/src/main/java/it/gov/pagopa/rtp/activator/RtpActivatorApplication.java +++ b/src/main/java/it/gov/pagopa/rtp/activator/RtpActivatorApplication.java @@ -4,12 +4,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; -import com.azure.spring.data.cosmos.repository.config.EnableReactiveCosmosRepositories; import reactor.core.publisher.Hooks; @SpringBootApplication -@EnableReactiveCosmosRepositories @ConfigurationPropertiesScan() public class RtpActivatorApplication { diff --git a/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfig.java b/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfig.java index 92a7aff..b9a7280 100644 --- a/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfig.java +++ b/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfig.java @@ -10,10 +10,10 @@ import com.azure.identity.DefaultAzureCredential; import com.azure.identity.DefaultAzureCredentialBuilder; import com.azure.spring.data.cosmos.config.AbstractCosmosConfiguration; -import com.azure.spring.data.cosmos.repository.config.EnableCosmosRepositories; +import com.azure.spring.data.cosmos.repository.config.EnableReactiveCosmosRepositories; @Configuration -@EnableCosmosRepositories +@EnableReactiveCosmosRepositories public class CosmosDBConfig extends AbstractCosmosConfiguration { @Autowired diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7cbf751..50a738d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -14,4 +14,4 @@ cosmos.credential.db-name=${DB_NAME:rtp} cosmos.credential.endpoint=${COSMOS_CONNECTION_STRING:""} -activation.base-url=${BASE_URL:"http://localhost"} \ No newline at end of file +activation.base-url=${BASE_URL:"http://localhost"} diff --git a/src/test/java/it/gov/pagopa/rtp/activator/RtpActivatorApplicationTest.java b/src/test/java/it/gov/pagopa/rtp/activator/RtpActivatorApplicationTest.java new file mode 100644 index 0000000..0c4c5a2 --- /dev/null +++ b/src/test/java/it/gov/pagopa/rtp/activator/RtpActivatorApplicationTest.java @@ -0,0 +1,14 @@ +package it.gov.pagopa.rtp.activator; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +class RtpActivatorApplicationTests { + + @Test + void contextLoads() { + } + +} \ No newline at end of file diff --git a/src/test/java/it/gov/pagopa/rtp/activator/controller/ActivationAPIControllerImplTest.java b/src/test/java/it/gov/pagopa/rtp/activator/controller/ActivationAPIControllerImplTest.java index 3425e39..af92492 100644 --- a/src/test/java/it/gov/pagopa/rtp/activator/controller/ActivationAPIControllerImplTest.java +++ b/src/test/java/it/gov/pagopa/rtp/activator/controller/ActivationAPIControllerImplTest.java @@ -9,14 +9,14 @@ import it.gov.pagopa.rtp.activator.model.generated.PayerDto; import it.gov.pagopa.rtp.activator.repository.ActivationDBRepository; import it.gov.pagopa.rtp.activator.service.ActivationPayerService; -import it.gov.pagopa.rtp.activator.service.ActivationPayerServiceImpl; + import it.gov.pagopa.rtp.activator.utils.Users; import reactor.core.publisher.Mono; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -25,11 +25,11 @@ import org.springframework.context.annotation.Import; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; + import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.aot.DisabledInAotMode; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.reactive.server.WebTestClient; -import org.springframework.web.reactive.function.BodyInserters; import java.time.Instant; import java.util.UUID; @@ -42,8 +42,12 @@ @ExtendWith(SpringExtension.class) @WebFluxTest(controllers = { ActivationAPIControllerImpl.class }) @Import({ SecurityConfig.class }) +@DisabledInAotMode class ActivationAPIControllerImplTest { + @MockBean + private ActivationDBRepository activationDBRepository; + @MockBean private ActivationPayerService activationPayerService; @@ -75,72 +79,53 @@ public void testActivatePayerSuccessful() { when(activationPropertiesConfig.getBaseUrl()).thenReturn("http://localhost:8080/"); webTestClient.post() - .uri(uriBuilder -> uriBuilder.path("/activation") - .queryParam("requestId", UUID.randomUUID().toString()) - .queryParam("version", "v1").build()) - .contentType(MediaType.APPLICATION_JSON).body(BodyInserters.fromValue(generateActivationRequest())) + .uri("/activations") + .header("RequestId", UUID.randomUUID().toString()) + .header("Version", "v1") + .bodyValue(generateActivationRequest()) .exchange() .expectStatus().isCreated().expectHeader() .location("http://localhost:8080/" + payer.payerID().toString()); } - /* - * @Test - * - * @Users.RtpWriter - * public void testActivatePayerAlreadyExists() { - * when(activationPayerService.activatePayer(any(String.class), - * any(String.class))) - * .thenReturn(Mono.error(new PayerAlreadyExists())); - * webTestClient.post() - * .uri(uriBuilder -> uriBuilder.path("/activation") - * .queryParam("requestId", UUID.randomUUID().toString()) - * .queryParam("version", "v1").build()) - * .contentType(MediaType.APPLICATION_JSON).body(BodyInserters.fromValue( - * activationReqDto)) - * .exchange() - * .expectStatus().isEqualTo(409); - * } - * - * @Test - * - * @Users.RtpWriter - * void shouldCreateNewActivation() { - * webTestClient.post() - * .uri("/activations") - * .header("RequestId", UUID.randomUUID().toString()) - * .header("Version", "v1") - * .bodyValue(generateActivationRequest()) - * .exchange() - * .expectStatus().isEqualTo(HttpStatus.CREATED) - * .expectHeader().exists(HttpHeaders.LOCATION); - * } - * - * @Test - * - * @WithMockUser(value = "another", roles = Users.ACTIVATION_WRITE_ROLE) - * void authorizedUserShouldNotActivateForAnotherServiceProvider() { - * webTestClient.post() - * .uri("/activations") - * .header("RequestId", UUID.randomUUID().toString()) - * .header("Version", "v1") - * .bodyValue(generateActivationRequest()) - * .exchange() - * .expectStatus().isEqualTo(HttpStatus.FORBIDDEN); - * } - * - * @Test - * - * @WithMockUser - * void userWithoutEnoughPermissionShouldNotCreateNewActivation() { - * webTestClient.post() - * .uri("/activations") - * .header("RequestId", UUID.randomUUID().toString()) - * .header("Version", "v1") - * .bodyValue(generateActivationRequest()) - * .exchange() - * .expectStatus().isEqualTo(HttpStatus.FORBIDDEN); - * } - */ + + @Test + @Users.RtpWriter + public void testActivatePayerAlreadyExists() { + when(activationPayerService.activatePayer(any(String.class), + any(String.class))) + .thenReturn(Mono.error(new PayerAlreadyExists())); + webTestClient.post() + .uri("/activations") + .header("RequestId", UUID.randomUUID().toString()) + .header("Version", "v1") + .bodyValue(generateActivationRequest()) + .exchange() + .expectStatus().isEqualTo(409); + } + + @Test + @WithMockUser(value = "another", roles = Users.ACTIVATION_WRITE_ROLE) + void authorizedUserShouldNotActivateForAnotherServiceProvider() { + webTestClient.post() + .uri("/activations") + .header("RequestId", UUID.randomUUID().toString()) + .header("Version", "v1") + .bodyValue(generateActivationRequest()) + .exchange() + .expectStatus().isEqualTo(HttpStatus.FORBIDDEN); + } + + @Test + @WithMockUser + void userWithoutEnoughPermissionShouldNotCreateNewActivation() { + webTestClient.post() + .uri("/activations") + .header("RequestId", UUID.randomUUID().toString()) + .header("Version", "v1") + .bodyValue(generateActivationRequest()) + .exchange() + .expectStatus().isEqualTo(HttpStatus.FORBIDDEN); + } private ActivationReqDto generateActivationRequest() { return new ActivationReqDto(new PayerDto("RSSMRA85T10A562S", SERVICE_PROVIDER_ID)); diff --git a/src/test/java/it/gov/pagopa/rtp/activator/utils/Users.java b/src/test/java/it/gov/pagopa/rtp/activator/utils/Users.java index 3ef1898..7e8596f 100644 --- a/src/test/java/it/gov/pagopa/rtp/activator/utils/Users.java +++ b/src/test/java/it/gov/pagopa/rtp/activator/utils/Users.java @@ -7,7 +7,7 @@ public class Users { - public static final String SERVICE_PROVIDER_ID = "1234"; + public static final String SERVICE_PROVIDER_ID = "984500A9EB6B07AC2G71"; public static final String ACTIVATION_WRITE_ROLE = "write_rtp_activations"; public static final String ACTIVATION_READ_ROLE = "read_rtp_activations";