diff options
Diffstat (limited to 'main/src/test/java/org/onap/policy/pap/main/rest')
35 files changed, 1169 insertions, 1142 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java b/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java index ca81ab7d..fe22cd89 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2019,2023 Nordix Foundation. + * Copyright (C) 2019, 2023 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. * ================================================================================ @@ -22,28 +22,29 @@ package org.onap.policy.pap.main.rest; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import java.io.File; import java.io.FileOutputStream; import java.nio.charset.StandardCharsets; import java.security.SecureRandom; +import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; import javax.net.ssl.SSLContext; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import org.glassfish.jersey.client.ClientProperties; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler; @@ -61,7 +62,6 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; /** @@ -69,7 +69,6 @@ import org.springframework.test.util.ReflectionTestUtils; * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ -@RunWith(SpringRunner.class) @SpringBootTest(classes = PolicyPapApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"db.initialize=false"}) @DirtiesContext(classMode = ClassMode.AFTER_CLASS) @@ -98,7 +97,7 @@ public abstract class CommonPapRestServer { * * @throws Exception if an error occurs */ - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { keystore = new SelfSignedKeyStore(); CommonTestData.newDb(); @@ -122,7 +121,7 @@ public abstract class CommonPapRestServer { * * @throws Exception if an error occurs */ - @Before + @BeforeEach public void setUp() throws Exception { httpsPrefix = "https://localhost:" + port + "/"; papActivator = Registry.get(PapConstants.REG_PAP_ACTIVATOR, PapActivator.class); @@ -132,11 +131,16 @@ public abstract class CommonPapRestServer { /** * Restores the activator's "alive" state. */ - @After + @AfterEach public void tearDown() { markActivator(activatorWasAlive); } + @AfterAll + public static void cleanRegistry() { + Registry.newRegistry(); + } + /** * Verifies that an endpoint appears within the swagger response. * @@ -145,7 +149,7 @@ public abstract class CommonPapRestServer { */ protected void testSwagger(final String endpoint) throws Exception { final Invocation.Builder invocationBuilder = sendFqeRequest(httpsPrefix - + ENDPOINT_PREFIX + "v3/api-docs", true, MediaType.APPLICATION_JSON); + + ENDPOINT_PREFIX + "v3/api-docs", true, MediaType.APPLICATION_JSON); final String resp = invocationBuilder.get(String.class); assertTrue(resp.contains(endpoint)); } @@ -175,7 +179,8 @@ public abstract class CommonPapRestServer { private void markActivator(boolean wasAlive) { Object manager = ReflectionTestUtils.getField(papActivator, "serviceManager"); - AtomicBoolean running = (AtomicBoolean) ReflectionTestUtils.getField(manager, "running"); + AtomicBoolean running = (AtomicBoolean) ReflectionTestUtils + .getField(Objects.requireNonNull(manager), "running"); running.set(wasAlive); } @@ -183,13 +188,13 @@ public abstract class CommonPapRestServer { * Verifies that unauthorized requests fail. * * @param endpoint the target end point - * @param sender function that sends the requests to the target + * @param sender function that sends the requests to the target * @throws Exception if an error occurs */ protected void checkUnauthRequest(final String endpoint, Function<Invocation.Builder, Response> sender) - throws Exception { + throws Exception { assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), - sender.apply(sendNoAuthRequest(endpoint)).getStatus()); + sender.apply(sendNoAuthRequest(endpoint)).getStatus()); } /** @@ -206,7 +211,7 @@ public abstract class CommonPapRestServer { /** * Sends a request to an endpoint. * - * @param endpoint the target endpoint + * @param endpoint the target endpoint * @param mediaType the media type for the request * @return a request builder * @throws Exception if an error occurs @@ -230,21 +235,21 @@ public abstract class CommonPapRestServer { * Sends a request to a fully qualified endpoint. * * @param fullyQualifiedEndpoint the fully qualified target endpoint - * @param includeAuth if authorization header should be included + * @param includeAuth if authorization header should be included * @return a request builder * @throws Exception if an error occurs */ protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth, - String mediaType) throws Exception { + String mediaType) throws Exception { final SSLContext sc = SSLContext.getInstance("TLSv1.2"); sc.init(null, NetworkUtil.getAlwaysTrustingManager(), new SecureRandom()); final ClientBuilder clientBuilder = - ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier((host, session) -> true); + ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier((host, session) -> true); final Client client = clientBuilder.build(); client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true"); client.register((mediaType.equalsIgnoreCase(MediaType.APPLICATION_JSON) ? GsonMessageBodyHandler.class - : YamlMessageBodyHandler.class)); + : YamlMessageBodyHandler.class)); if (includeAuth) { final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("policyadmin", "zb!XztG34"); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/PapRestControllerV1Test.java b/main/src/test/java/org/onap/policy/pap/main/rest/PapRestControllerV1Test.java index d1d29f0c..93f73b08 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/PapRestControllerV1Test.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/PapRestControllerV1Test.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,20 +23,20 @@ package org.onap.policy.pap.main.rest; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import jakarta.ws.rs.core.SecurityContext; import java.util.UUID; -import javax.ws.rs.core.SecurityContext; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity.BodyBuilder; -public class PapRestControllerV1Test { +class PapRestControllerV1Test { @Mock SecurityContext mockSecurityContext; @@ -44,19 +44,19 @@ public class PapRestControllerV1Test { private AutoCloseable closeable; private BodyBuilder bldr; - @Before + @BeforeEach public void setUp() { bldr = ResponseEntity.ok(); closeable = MockitoAnnotations.openMocks(this); } - @After + @AfterEach public void after() throws Exception { closeable.close(); } @Test - public void testAddVersionControlHeaders() { + void testAddVersionControlHeaders() { ResponseEntity<Object> resp = PapRestControllerV1.addVersionControlHeaders(bldr).build(); assertEquals("0", resp.getHeaders().get(PapRestControllerV1.VERSION_MINOR_NAME).get(0)); assertEquals("0", resp.getHeaders().get(PapRestControllerV1.VERSION_PATCH_NAME).get(0)); @@ -64,20 +64,20 @@ public class PapRestControllerV1Test { } @Test - public void testAddLoggingHeaders_Null() { + void testAddLoggingHeaders_Null() { ResponseEntity<Object> resp = PapRestControllerV1.addLoggingHeaders(bldr, null).build(); assertNotNull(resp.getHeaders().get(PapRestControllerV1.REQUEST_ID_NAME)); } @Test - public void testAddLoggingHeaders_NonNull() { + void testAddLoggingHeaders_NonNull() { UUID uuid = UUID.randomUUID(); ResponseEntity<Object> resp = PapRestControllerV1.addLoggingHeaders(bldr, uuid).build(); assertEquals(uuid.toString(), resp.getHeaders().get(PapRestControllerV1.REQUEST_ID_NAME).get(0)); } @Test - public void testGetPrincipal() { + void testGetPrincipal() { assertThat(new PapRestControllerV1().getPrincipal()).isEmpty(); } } diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java b/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java index 60de563e..e5a83305 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021-2022 Nordix Foundation. + * Modifications Copyright (C) 2021-2023 Nordix Foundation. * Modifications Copyright (C) 2022-2023 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ package org.onap.policy.pap.main.rest; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -37,7 +37,8 @@ import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; @@ -95,15 +96,17 @@ public class ProviderSuper { protected ToscaPolicy policy1; protected MeterRegistry meterRegistry; + AutoCloseable closeable; + /** * Configures DAO, captors, and various mocks. */ - @Before + @BeforeEach public void setUp() throws Exception { Registry.newRegistry(); - MockitoAnnotations.openMocks(this); + closeable = MockitoAnnotations.openMocks(this); reqmap = mock(PdpModifyRequestMap.class); @@ -125,6 +128,11 @@ public class ProviderSuper { } + @AfterEach + public void tearDown() throws Exception { + closeable.close(); + } + /** * Initialize services to the provider for tests. * @@ -280,7 +288,7 @@ public class ProviderSuper { * Loads an object from a JSON file. * * @param fileName name of the file from which to load - * @param clazz the class of the object to be loaded + * @param clazz the class of the object to be loaded * @return the object that was loaded from the file */ protected <T> T loadFile(String fileName, Class<T> clazz) { diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestActuatorEndpoints.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestActuatorEndpoints.java index 3fdb1f42..a1a16bf5 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestActuatorEndpoints.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestActuatorEndpoints.java @@ -20,33 +20,34 @@ package org.onap.policy.pap.main.rest; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.services.Registry; +import org.onap.policy.pap.main.PolicyPapApplication; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.RequestPostProcessor; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT) +@SpringBootTest(classes = PolicyPapApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = {"db.initialize=false"}) @ActiveProfiles("test") @AutoConfigureMockMvc +@AutoConfigureObservability @ContextConfiguration @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class TestActuatorEndpoints { @@ -57,7 +58,10 @@ public class TestActuatorEndpoints { @Autowired private MockMvc mock; - @BeforeClass + private final RequestPostProcessor mockSecurity = SecurityMockMvcRequestPostProcessors + .httpBasic("policyAdmin", "zb!XztG34"); + + @BeforeAll public static void setupClass() { Registry.newRegistry(); } @@ -68,17 +72,16 @@ public class TestActuatorEndpoints { } @Test - public void testMetricsEndpoint() throws Exception { - mock.perform(get("/plain-metrics").with(SecurityMockMvcRequestPostProcessors.httpBasic( - "policyAdmin", "zb!XztG34"))) + void testMetricsEndpoint() throws Exception { + mock.perform(get("/plain-metrics").with(mockSecurity)) .andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$").isNotEmpty()); } @Test - public void testPrometheusEndpoint() throws Exception { - mock.perform(get("/metrics").with(SecurityMockMvcRequestPostProcessors.httpBasic("policyAdmin", "zb!XztG34"))) + void testPrometheusEndpoint() throws Exception { + mock.perform(get("/metrics").with(mockSecurity)) .andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$").isNotEmpty()); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestGroupData.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestGroupData.java index 5eb5611f..4a33e9f1 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestGroupData.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestGroupData.java @@ -3,6 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,15 +22,15 @@ package org.onap.policy.pap.main.rest; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.models.pdp.concepts.PdpGroup; -public class TestGroupData { +class TestGroupData { private static final String NAME = "my-name"; private PdpGroup oldGroup; @@ -39,7 +40,7 @@ public class TestGroupData { /** * Sets up. */ - @Before + @BeforeEach public void setUp() { oldGroup = new PdpGroup(); oldGroup.setName(NAME); @@ -50,7 +51,7 @@ public class TestGroupData { } @Test - public void testNew() { + void testNew() { data = new GroupData(oldGroup, true); assertSame(oldGroup, data.getGroup()); @@ -74,7 +75,7 @@ public class TestGroupData { } @Test - public void testUpdateOnly() { + void testUpdateOnly() { assertTrue(data.isUnchanged()); assertFalse(data.isUpdated()); assertSame(oldGroup, data.getGroup()); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestHealthCheckRestControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestHealthCheckRestControllerV1.java index e5823bc3..c1058a78 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestHealthCheckRestControllerV1.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestHealthCheckRestControllerV1.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2019, 2022 Nordix Foundation. + * Copyright (C) 2019, 2022-2023 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ @@ -23,12 +23,12 @@ package org.onap.policy.pap.main.rest; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.SyncInvoker; -import org.junit.Test; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.client.SyncInvoker; +import org.junit.jupiter.api.Test; import org.onap.policy.common.endpoints.report.HealthCheckReport; import org.onap.policy.models.base.PfModelRuntimeException; import org.springframework.boot.test.mock.mockito.MockBean; @@ -39,8 +39,8 @@ import org.springframework.test.context.ActiveProfiles; * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ -@ActiveProfiles({ "test", "default" }) -public class TestHealthCheckRestControllerV1 extends CommonPapRestServer { +@ActiveProfiles({"test", "default"}) +class TestHealthCheckRestControllerV1 extends CommonPapRestServer { private static final String HEALTHCHECK_ENDPOINT = "healthcheck"; @@ -48,12 +48,12 @@ public class TestHealthCheckRestControllerV1 extends CommonPapRestServer { private PolicyStatusProvider policyStatusProvider; @Test - public void testSwagger() throws Exception { + void testSwagger() throws Exception { super.testSwagger(HEALTHCHECK_ENDPOINT); } @Test - public void testHealthCheckSuccess() throws Exception { + void testHealthCheckSuccess() throws Exception { final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT); final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class); validateHealthCheckReport(true, 200, ALIVE, report); @@ -63,7 +63,7 @@ public class TestHealthCheckRestControllerV1 extends CommonPapRestServer { } @Test - public void testHealthCheckActivatorFailure() throws Exception { + void testHealthCheckActivatorFailure() throws Exception { markActivatorDead(); @@ -75,7 +75,7 @@ public class TestHealthCheckRestControllerV1 extends CommonPapRestServer { } @Test - public void testHealthCheckDbConnectionFailure() throws Exception { + void testHealthCheckDbConnectionFailure() throws Exception { when(policyStatusProvider.getPolicyStatus()).thenThrow(PfModelRuntimeException.class); final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT); var response = invocationBuilder.get(); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateControllerV1.java index c5442fad..67f637a1 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateControllerV1.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateControllerV1.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2019, 2022 Nordix Foundation. + * Copyright (C) 2019, 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,15 +20,15 @@ package org.onap.policy.pap.main.rest; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import java.util.List; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.models.pap.concepts.PdpGroupUpdateResponse; import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpGroups; @@ -39,17 +39,17 @@ import org.springframework.test.context.ActiveProfiles; * Note: this tests failure cases; success cases are tested by tests in the "e2e" package. */ @ActiveProfiles({ "test", "default" }) -public class TestPdpGroupCreateOrUpdateControllerV1 extends CommonPapRestServer { +class TestPdpGroupCreateOrUpdateControllerV1 extends CommonPapRestServer { private static final String CREATEORUPDATE_GROUPS_ENDPOINT = "pdps/groups/batch"; @Test - public void testSwagger() throws Exception { + void testSwagger() throws Exception { super.testSwagger(CREATEORUPDATE_GROUPS_ENDPOINT); } @Test - public void testCreateOrUpdateGroups() throws Exception { + void testCreateOrUpdateGroups() throws Exception { Entity<PdpGroups> entgrp = makePdpGroupsEntity(); Invocation.Builder invocationBuilder = sendRequest(CREATEORUPDATE_GROUPS_ENDPOINT); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java index 7666dc2a..445a921f 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java @@ -1,561 +1,562 @@ -/*
- * ============LICENSE_START=======================================================
- * ONAP PAP
- * ================================================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
- * Modifications Copyright (C) 2021 AT&T Intellectual Property.
- * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.pap.main.rest;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.TreeMap;
-import javax.ws.rs.core.Response.Status;
-import org.assertj.core.api.Assertions;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.policy.common.utils.services.Registry;
-import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.pdp.concepts.PdpGroup;
-import org.onap.policy.models.pdp.concepts.PdpGroups;
-import org.onap.policy.models.pdp.concepts.PdpStateChange;
-import org.onap.policy.models.pdp.concepts.PdpSubGroup;
-import org.onap.policy.models.pdp.concepts.PdpUpdate;
-import org.onap.policy.models.pdp.enums.PdpState;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.pap.main.PapConstants;
-
-public class TestPdpGroupCreateOrUpdateProvider extends ProviderSuper {
- private static final String EXPECTED_EXCEPTION = "expected exception";
-
- private static final String PDP2 = "pdpB";
- private static final String PDP4 = "pdpD";
-
- private PdpGroupCreateOrUpdateProvider prov;
-
-
- - @AfterClass
- public static void tearDownAfterClass() {
- Registry.newRegistry();
- }
-
- /**
- * Configures mocks and objects.
- *
- * @throws Exception if an error occurs
- */
- @Before
- @Override
- public void setUp() throws Exception {
super.setUp();
- prov = new PdpGroupCreateOrUpdateProvider();
- super.initialize(prov);
- when(toscaService.getPolicyTypeList("typeA", "100.2.3"))
- .thenReturn(Arrays.asList(loadPolicyType("daoPolicyType.json")));
}
-
- @Test
- public void testCreateOrUpdateGroups() throws Exception {
- prov.createOrUpdateGroups(loadPdpGroups("emptyGroups.json"));
-
- // no groups, so no action should have been taken
- assertNoGroupAction();
- }
-
- @Test
- public void testCreateOrUpdateGroups_InvalidRequest() throws Exception {
- assertThatThrownBy(() -> prov.createOrUpdateGroups(new PdpGroups())).isInstanceOf(PfModelException.class)
- .hasMessageContaining("is null");
-
- assertNoGroupAction();
- }
-
- @Test
- public void testCreateOrUpdate_Invalid() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- groups.getGroups().get(0).setPdpGroupState(PdpState.TERMINATED);
-
- assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class)
- .hasMessageContaining("pdpGroupState");
-
- assertNoGroupAction();
- }
-
- @Test
- public void testAddGroup() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- PdpGroup group = groups.getGroups().get(0);
- group.setPdpGroupState(PdpState.PASSIVE);
-
- prov.createOrUpdateGroups(groups);
-
- // should not have updated the state
- assertEquals(PdpState.PASSIVE, group.getPdpGroupState());
-
- assertSame(group, getGroupCreates().get(0));
- }
-
- @Test
- public void testAddGroup_Invalid() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- groups.getGroups().get(0).setPdpGroupState(PdpState.TERMINATED);
-
- assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class)
- .hasMessageContaining("pdpGroupState");
-
- assertNoGroupAction();
- }
-
- @Test
- public void testAddGroup_InvalidSubGroup() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
-
- groups.getGroups().get(0).getPdpSubgroups().get(0).getSupportedPolicyTypes().get(0).setVersion("99.99.99");
-
- assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class)
- .hasMessageContaining("unknown policy type");
-
- assertNoGroupAction();
- }
-
- @Test
- public void testValidateGroupOnly_NullState() {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- groups.getGroups().get(0).setPdpGroupState(null);
- Assertions.assertThatCode(() -> prov.createOrUpdateGroups(groups)).doesNotThrowAnyException();
- }
-
- @Test
- public void testValidateGroupOnly_Active() {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- groups.getGroups().get(0).setPdpGroupState(PdpState.ACTIVE);
- Assertions.assertThatCode(() -> prov.createOrUpdateGroups(groups)).doesNotThrowAnyException();
- }
-
- @Test
- public void testValidateGroupOnly_Passive() {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- groups.getGroups().get(0).setPdpGroupState(PdpState.PASSIVE);
- Assertions.assertThatCode(() -> prov.createOrUpdateGroups(groups)).doesNotThrowAnyException();
- }
-
- @Test
- public void testValidateGroupOnly_Invalid() {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- groups.getGroups().get(0).setPdpGroupState(PdpState.TERMINATED);
-
- assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class)
- .hasMessageContaining("pdpGroupState");
- }
-
- @Test
- public void testUpdateGroup() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
-
- // DB group = new group
- PdpGroup group = new PdpGroup(groups.getGroups().get(0));
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- prov.createOrUpdateGroups(groups);
-
- assertNoGroupAction();
- }
-
- @Test
- public void testUpdateGroup_PropertiesChanged() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
-
- PdpGroup group = new PdpGroup(groups.getGroups().get(0));
- group.setProperties(new TreeMap<>());
-
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class)
- .hasMessageContaining("properties");
-
- assertNoGroupAction();
- }
-
- @Test
- public void testUpdateGroup_NewDescription() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- PdpGroup newgrp = groups.getGroups().get(0);
- PdpGroup group = new PdpGroup(newgrp);
- group.setDescription("old description");
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- prov.createOrUpdateGroups(groups);
-
- assertGroupUpdateOnly(group);
-
- assertEquals("my description", group.getDescription());
- assertEquals(newgrp.toString(), group.toString());
- }
-
- @Test
- public void testUpdateGroup_NewState() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- PdpGroup newgrp = groups.getGroups().get(0);
- PdpGroup group = new PdpGroup(newgrp);
- group.setPdpGroupState(PdpState.TEST);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- prov.createOrUpdateGroups(groups);
-
- assertGroupUpdateOnly(group);
-
- assertEquals(PdpState.ACTIVE, group.getPdpGroupState());
- assertEquals(newgrp.toString(), group.toString());
- }
-
- @Test
- public void testUpdateGroup_NewSubGroup() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroupsNewSub.json");
- PdpGroup group = loadPdpGroups("createGroups.json").getGroups().get(0);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- prov.createOrUpdateGroups(groups);
-
- PdpGroup newgrp = groups.getGroups().get(0);
- assertEquals(newgrp.toString(), group.toString());
- assertGroupUpdateOnly(group);
- }
-
- @Test
- public void testUpdateGroup_UpdatedSubGroup() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- PdpGroup newgrp = groups.getGroups().get(0);
- PdpGroup group = new PdpGroup(newgrp);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- // something different in this subgroup
- group.getPdpSubgroups().get(0).setDesiredInstanceCount(10);
-
- prov.createOrUpdateGroups(groups);
-
- assertEquals(newgrp.toString(), group.toString());
- assertGroupUpdateOnly(group);
- }
-
- @Test
- public void testUpdateGroup_notifyPdpsDelSubGroups() throws Exception {
- PdpGroup dbgroup = new PdpGroup(loadPdpGroups("createGroupsDelSub.json").getGroups().get(0));
- when(pdpGroupService.getPdpGroups(dbgroup.getName())).thenReturn(Arrays.asList(dbgroup));
-
- PdpGroups groups = loadPdpGroups("createGroups.json");
-
- prov.createOrUpdateGroups(groups);
-
- // verify that DB group was updated
- List<PdpGroup> updates = getGroupUpdates();
- assertEquals(1, updates.size());
- dbgroup = updates.get(0);
-
- PdpGroup newgrp = groups.getGroups().get(0);
-
- Collections.sort(newgrp.getPdpSubgroups().get(0).getPolicies());
- Collections.sort(dbgroup.getPdpSubgroups().get(0).getPolicies());
-
- assertEquals(newgrp.toString(), dbgroup.toString());
-
- // no deployment notifications
- checkEmptyNotification();
-
- // this requires a PDP UPDATE message
- List<PdpUpdate> pdpUpdates = getUpdateRequests(2);
- assertEquals(2, pdpUpdates.size());
-
- PdpUpdate pdpUpdate = pdpUpdates.get(0);
- assertEquals(PapConstants.PAP_NAME, pdpUpdate.getSource());
- assertEquals(PDP2, pdpUpdate.getName());
- assertNull(pdpUpdate.getPdpGroup());
-
- pdpUpdate = pdpUpdates.get(1);
- assertEquals(PapConstants.PAP_NAME, pdpUpdate.getSource());
- assertEquals(PDP4, pdpUpdate.getName());
- assertNull(pdpUpdate.getPdpGroup());
-
- // it also requires a PDP STATE-CHANGE message
- List<PdpStateChange> changes = getStateChangeRequests(2);
- assertEquals(2, changes.size());
-
- PdpStateChange change = changes.get(0);
- assertEquals(PapConstants.PAP_NAME, change.getSource());
- assertEquals(PDP2, change.getName());
- assertEquals(PdpState.PASSIVE, change.getState());
-
- change = changes.get(1);
- assertEquals(PapConstants.PAP_NAME, change.getSource());
- assertEquals(PDP4, change.getName());
- assertEquals(PdpState.PASSIVE, change.getState());
- }
-
- @Test
- public void testUpdateField_Unchanged() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- PdpGroup newgrp = groups.getGroups().get(0);
- PdpGroup group = new PdpGroup(newgrp);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- prov.createOrUpdateGroups(groups);
-
- assertNoGroupAction();
- }
-
- @Test
- public void testUpdateField_WasNull() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- PdpGroup newgrp = groups.getGroups().get(0);
- PdpGroup group = new PdpGroup(newgrp);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- group.setDescription(null);
-
- prov.createOrUpdateGroups(groups);
-
- assertEquals(newgrp.toString(), group.toString());
- assertGroupUpdateOnly(group);
- }
-
- @Test
- public void testUpdateField_NowNull() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- PdpGroup newgrp = groups.getGroups().get(0);
- PdpGroup group = new PdpGroup(newgrp);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- newgrp.setDescription(null);
-
- prov.createOrUpdateGroups(groups);
-
- assertEquals(newgrp.toString(), group.toString());
- assertGroupUpdateOnly(group);
- }
-
- @Test
- public void testUpdateField_Changed() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- PdpGroup newgrp = groups.getGroups().get(0);
- PdpGroup group = new PdpGroup(newgrp);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- newgrp.setDescription(group.getDescription() + "-changed");
-
- prov.createOrUpdateGroups(groups);
-
- assertEquals(newgrp.toString(), group.toString());
- assertGroupUpdateOnly(group);
- }
-
- @Test
- public void testAddSubGroup() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroupsNewSub.json");
- PdpGroup group = loadPdpGroups("createGroups.json").getGroups().get(0);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- prov.createOrUpdateGroups(groups);
-
- PdpGroup newgrp = groups.getGroups().get(0);
-
- PdpSubGroup newsub = newgrp.getPdpSubgroups().get(1);
- newsub.setCurrentInstanceCount(0);
- newsub.setPdpInstances(new ArrayList<>(0));
-
- assertEquals(newgrp.toString(), group.toString());
- assertGroupUpdateOnly(group);
- }
-
- /**
- * Tests addSubgroup() when the new subgroup has a wild-card policy type.
- *
- * @throws Exception if an error occurs
- */
- @Test
- public void testAddSubGroupWildCardPolicyType() throws Exception {
- when(toscaService.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyListWildCard.json"));
- when(toscaService.getPolicyTypeList("some.*", "2.3.4")).thenReturn(Collections.emptyList());
-
- PdpGroups groups = loadPdpGroups("createGroupsWildCard.json");
- PdpGroup group = loadPdpGroups("createGroups.json").getGroups().get(0);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- prov.createOrUpdateGroups(groups);
-
- PdpGroup newgrp = groups.getGroups().get(0);
-
- PdpSubGroup newsub = newgrp.getPdpSubgroups().get(1);
- newsub.setCurrentInstanceCount(0);
- newsub.setPdpInstances(new ArrayList<>(0));
-
- assertEquals(newgrp.toString(), group.toString());
- }
-
- @Test
- public void testAddSubGroup_ValidationPolicyTypeNotFound() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroupsNewSub.json");
- PdpGroup group = loadPdpGroups("createGroups.json").getGroups().get(0);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- when(toscaService.getPolicyTypeList(any(), any())).thenReturn(Collections.emptyList());
-
- assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).hasMessageContaining("unknown policy type");
- }
-
- @Test
- public void testAddSubGroup_ValidationPolicyTypeDaoEx() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroupsNewSub.json");
- PdpGroup group = loadPdpGroups("createGroups.json").getGroups().get(0);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- PfModelException exc = new PfModelException(Status.CONFLICT, EXPECTED_EXCEPTION);
- when(toscaService.getPolicyTypeList(any(), any())).thenThrow(exc);
-
- assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isSameAs(exc);
- }
-
- @Test
- public void testAddSubGroup_ValidateVersionPrefixMatch() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- PdpGroup newgrp = groups.getGroups().get(0);
- PdpGroup dbgroup = new PdpGroup(newgrp);
- when(pdpGroupService.getPdpGroups(dbgroup.getName())).thenReturn(Arrays.asList(dbgroup));
-
- when(toscaService.getFilteredPolicyList(any())).thenReturn(loadPolicies("createGroupNewPolicy.json"))
- .thenReturn(loadPolicies("daoPolicyList.json")).thenReturn(loadPolicies("createGroupNewPolicy.json"));
-
- PdpGroups reqgroups = loadPdpGroups("createGroupsVersPrefix.json");
-
- prov.createOrUpdateGroups(reqgroups);
-
- Collections.sort(newgrp.getPdpSubgroups().get(0).getPolicies());
- Collections.sort(dbgroup.getPdpSubgroups().get(0).getPolicies());
-
- assertEquals(newgrp.toString(), dbgroup.toString());
- }
-
- @Test
- public void testUpdateSubGroup_Invalid() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- PdpGroup newgrp = groups.getGroups().get(0);
- PdpGroup group = new PdpGroup(newgrp);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- // change properties
- newgrp.getPdpSubgroups().get(0).setProperties(new TreeMap<>());
-
- assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class)
- .hasMessageContaining("properties");
-
- assertNoGroupAction();
- }
-
- @Test
- public void testUpdateSubGroup_SupportedPolicies() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- PdpGroup newgrp = groups.getGroups().get(0);
- PdpGroup group = new PdpGroup(newgrp);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- newgrp.getPdpSubgroups().get(0).getSupportedPolicyTypes()
- .add(new ToscaConceptIdentifier("typeX.*", "9.8.7"));
-
- // the group is updated with a new supported policy type in subgroup
- assertEquals(2, newgrp.getPdpSubgroups().get(0).getSupportedPolicyTypes().size());
- prov.createOrUpdateGroups(groups);
- // PdpGroup update doesn't allow supported policy type modifications
- // during pdp group update, the ones in db is maintained
- assertEquals(1, newgrp.getPdpSubgroups().get(0).getSupportedPolicyTypes().size());
- assertEquals(newgrp.toString(), group.toString());
- }
-
- @Test
- public void testUpdateSubGroup_DesiredCount() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- PdpGroup newgrp = groups.getGroups().get(0);
- PdpGroup group = new PdpGroup(newgrp);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- newgrp.getPdpSubgroups().get(0).setDesiredInstanceCount(20);
-
- prov.createOrUpdateGroups(groups);
-
- assertEquals(newgrp.toString(), group.toString());
- assertGroupUpdateOnly(group);
- }
-
- @Test
- public void testUpdateSubGroup_Unchanged() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- PdpGroup newgrp = groups.getGroups().get(0);
- PdpGroup group = new PdpGroup(newgrp);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- prov.createOrUpdateGroups(groups);
-
- Collections.sort(newgrp.getPdpSubgroups().get(0).getPolicies());
- Collections.sort(group.getPdpSubgroups().get(0).getPolicies());
-
- assertEquals(newgrp.toString(), group.toString());
-
- // no notifications
- checkEmptyNotification();
-
- // no group updates
- assertNoGroupAction();
- }
-
- @Test
- public void testValidateSubGroup_PropertiesMismatch() throws Exception {
- PdpGroups groups = loadPdpGroups("createGroups.json");
- PdpGroup newgrp = groups.getGroups().get(0);
- PdpGroup group = new PdpGroup(newgrp);
- when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group));
-
- newgrp.setProperties(new TreeMap<>());
-
- assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class)
- .hasMessageContaining("properties");
-
- assertNoGroupAction();
- }
-
- private void assertNoGroupAction() throws Exception {
- verify(pdpGroupService, never()).createPdpGroups(any());
- verify(pdpGroupService, never()).updatePdpGroups(any());
- verify(reqmap, never()).addRequest(any(), any());
- }
-
- private void assertGroupUpdateOnly(PdpGroup group) throws Exception {
- verify(pdpGroupService, never()).createPdpGroups(any());
- verify(reqmap, never()).addRequest(any(), any());
-
- List<PdpGroup> updates = getGroupUpdates();
- assertEquals(Arrays.asList(group), updates);
- }
-}
+/* + * ============LICENSE_START======================================================= + * ONAP PAP + * ================================================================================ + * Copyright (C) 2019-2021, 2023 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. + * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.pap.main.rest; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import jakarta.ws.rs.core.Response.Status; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.TreeMap; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.services.Registry; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.pdp.concepts.PdpGroup; +import org.onap.policy.models.pdp.concepts.PdpGroups; +import org.onap.policy.models.pdp.concepts.PdpStateChange; +import org.onap.policy.models.pdp.concepts.PdpSubGroup; +import org.onap.policy.models.pdp.concepts.PdpUpdate; +import org.onap.policy.models.pdp.enums.PdpState; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.pap.main.PapConstants; + +public class TestPdpGroupCreateOrUpdateProvider extends ProviderSuper { + private static final String EXPECTED_EXCEPTION = "expected exception"; + + private static final String PDP2 = "pdpB"; + private static final String PDP4 = "pdpD"; + + private PdpGroupCreateOrUpdateProvider prov; + + + @AfterAll + public static void tearDownAfterClass() { + Registry.newRegistry(); + } + + /** + * Configures mocks and objects. + * + * @throws Exception if an error occurs + */ + @BeforeEach + @Override + public void setUp() throws Exception { + super.setUp(); + prov = new PdpGroupCreateOrUpdateProvider(); + super.initialize(prov); + when(toscaService.getPolicyTypeList("typeA", "100.2.3")) + .thenReturn(Arrays.asList(loadPolicyType("daoPolicyType.json"))); + } + + @Test + void testCreateOrUpdateGroups() throws Exception { + prov.createOrUpdateGroups(loadPdpGroups("emptyGroups.json")); + + // no groups, so no action should have been taken + assertNoGroupAction(); + } + + @Test + void testCreateOrUpdateGroups_InvalidRequest() throws Exception { + assertThatThrownBy(() -> prov.createOrUpdateGroups(new PdpGroups())).isInstanceOf(PfModelException.class) + .hasMessageContaining("is null"); + + assertNoGroupAction(); + } + + @Test + void testCreateOrUpdate_Invalid() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + groups.getGroups().get(0).setPdpGroupState(PdpState.TERMINATED); + + assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class) + .hasMessageContaining("pdpGroupState"); + + assertNoGroupAction(); + } + + @Test + void testAddGroup() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup group = groups.getGroups().get(0); + group.setPdpGroupState(PdpState.PASSIVE); + + prov.createOrUpdateGroups(groups); + + // should not have updated the state + assertEquals(PdpState.PASSIVE, group.getPdpGroupState()); + + assertSame(group, getGroupCreates().get(0)); + } + + @Test + void testAddGroup_Invalid() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + groups.getGroups().get(0).setPdpGroupState(PdpState.TERMINATED); + + assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class) + .hasMessageContaining("pdpGroupState"); + + assertNoGroupAction(); + } + + @Test + void testAddGroup_InvalidSubGroup() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + + groups.getGroups().get(0).getPdpSubgroups().get(0).getSupportedPolicyTypes().get(0).setVersion("99.99.99"); + + assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class) + .hasMessageContaining("unknown policy type"); + + assertNoGroupAction(); + } + + @Test + void testValidateGroupOnly_NullState() { + PdpGroups groups = loadPdpGroups("createGroups.json"); + groups.getGroups().get(0).setPdpGroupState(null); + Assertions.assertThatCode(() -> prov.createOrUpdateGroups(groups)).doesNotThrowAnyException(); + } + + @Test + void testValidateGroupOnly_Active() { + PdpGroups groups = loadPdpGroups("createGroups.json"); + groups.getGroups().get(0).setPdpGroupState(PdpState.ACTIVE); + Assertions.assertThatCode(() -> prov.createOrUpdateGroups(groups)).doesNotThrowAnyException(); + } + + @Test + void testValidateGroupOnly_Passive() { + PdpGroups groups = loadPdpGroups("createGroups.json"); + groups.getGroups().get(0).setPdpGroupState(PdpState.PASSIVE); + Assertions.assertThatCode(() -> prov.createOrUpdateGroups(groups)).doesNotThrowAnyException(); + } + + @Test + void testValidateGroupOnly_Invalid() { + PdpGroups groups = loadPdpGroups("createGroups.json"); + groups.getGroups().get(0).setPdpGroupState(PdpState.TERMINATED); + + assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class) + .hasMessageContaining("pdpGroupState"); + } + + @Test + void testUpdateGroup() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + + // DB group = new group + PdpGroup group = new PdpGroup(groups.getGroups().get(0)); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + prov.createOrUpdateGroups(groups); + + assertNoGroupAction(); + } + + @Test + void testUpdateGroup_PropertiesChanged() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + + PdpGroup group = new PdpGroup(groups.getGroups().get(0)); + group.setProperties(new TreeMap<>()); + + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class) + .hasMessageContaining("properties"); + + assertNoGroupAction(); + } + + @Test + void testUpdateGroup_NewDescription() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup group = new PdpGroup(newgrp); + group.setDescription("old description"); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + prov.createOrUpdateGroups(groups); + + assertGroupUpdateOnly(group); + + assertEquals("my description", group.getDescription()); + assertEquals(newgrp.toString(), group.toString()); + } + + @Test + void testUpdateGroup_NewState() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup group = new PdpGroup(newgrp); + group.setPdpGroupState(PdpState.TEST); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + prov.createOrUpdateGroups(groups); + + assertGroupUpdateOnly(group); + + assertEquals(PdpState.ACTIVE, group.getPdpGroupState()); + assertEquals(newgrp.toString(), group.toString()); + } + + @Test + void testUpdateGroup_NewSubGroup() throws Exception { + PdpGroups groups = loadPdpGroups("createGroupsNewSub.json"); + PdpGroup group = loadPdpGroups("createGroups.json").getGroups().get(0); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + prov.createOrUpdateGroups(groups); + + PdpGroup newgrp = groups.getGroups().get(0); + assertEquals(newgrp.toString(), group.toString()); + assertGroupUpdateOnly(group); + } + + @Test + void testUpdateGroup_UpdatedSubGroup() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup group = new PdpGroup(newgrp); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + // something different in this subgroup + group.getPdpSubgroups().get(0).setDesiredInstanceCount(10); + + prov.createOrUpdateGroups(groups); + + assertEquals(newgrp.toString(), group.toString()); + assertGroupUpdateOnly(group); + } + + @Test + void testUpdateGroup_notifyPdpsDelSubGroups() throws Exception { + PdpGroup dbgroup = new PdpGroup(loadPdpGroups("createGroupsDelSub.json").getGroups().get(0)); + when(pdpGroupService.getPdpGroups(dbgroup.getName())).thenReturn(Arrays.asList(dbgroup)); + + PdpGroups groups = loadPdpGroups("createGroups.json"); + + prov.createOrUpdateGroups(groups); + + // verify that DB group was updated + List<PdpGroup> updates = getGroupUpdates(); + assertEquals(1, updates.size()); + dbgroup = updates.get(0); + + PdpGroup newgrp = groups.getGroups().get(0); + + Collections.sort(newgrp.getPdpSubgroups().get(0).getPolicies()); + Collections.sort(dbgroup.getPdpSubgroups().get(0).getPolicies()); + + assertEquals(newgrp.toString(), dbgroup.toString()); + + // no deployment notifications + checkEmptyNotification(); + + // this requires a PDP UPDATE message + List<PdpUpdate> pdpUpdates = getUpdateRequests(2); + assertEquals(2, pdpUpdates.size()); + + PdpUpdate pdpUpdate = pdpUpdates.get(0); + assertEquals(PapConstants.PAP_NAME, pdpUpdate.getSource()); + assertEquals(PDP2, pdpUpdate.getName()); + assertNull(pdpUpdate.getPdpGroup()); + + pdpUpdate = pdpUpdates.get(1); + assertEquals(PapConstants.PAP_NAME, pdpUpdate.getSource()); + assertEquals(PDP4, pdpUpdate.getName()); + assertNull(pdpUpdate.getPdpGroup()); + + // it also requires a PDP STATE-CHANGE message + List<PdpStateChange> changes = getStateChangeRequests(2); + assertEquals(2, changes.size()); + + PdpStateChange change = changes.get(0); + assertEquals(PapConstants.PAP_NAME, change.getSource()); + assertEquals(PDP2, change.getName()); + assertEquals(PdpState.PASSIVE, change.getState()); + + change = changes.get(1); + assertEquals(PapConstants.PAP_NAME, change.getSource()); + assertEquals(PDP4, change.getName()); + assertEquals(PdpState.PASSIVE, change.getState()); + } + + @Test + void testUpdateField_Unchanged() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup group = new PdpGroup(newgrp); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + prov.createOrUpdateGroups(groups); + + assertNoGroupAction(); + } + + @Test + void testUpdateField_WasNull() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup group = new PdpGroup(newgrp); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + group.setDescription(null); + + prov.createOrUpdateGroups(groups); + + assertEquals(newgrp.toString(), group.toString()); + assertGroupUpdateOnly(group); + } + + @Test + void testUpdateField_NowNull() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup group = new PdpGroup(newgrp); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + newgrp.setDescription(null); + + prov.createOrUpdateGroups(groups); + + assertEquals(newgrp.toString(), group.toString()); + assertGroupUpdateOnly(group); + } + + @Test + void testUpdateField_Changed() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup group = new PdpGroup(newgrp); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + newgrp.setDescription(group.getDescription() + "-changed"); + + prov.createOrUpdateGroups(groups); + + assertEquals(newgrp.toString(), group.toString()); + assertGroupUpdateOnly(group); + } + + @Test + void testAddSubGroup() throws Exception { + PdpGroups groups = loadPdpGroups("createGroupsNewSub.json"); + PdpGroup group = loadPdpGroups("createGroups.json").getGroups().get(0); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + prov.createOrUpdateGroups(groups); + + PdpGroup newgrp = groups.getGroups().get(0); + + PdpSubGroup newsub = newgrp.getPdpSubgroups().get(1); + newsub.setCurrentInstanceCount(0); + newsub.setPdpInstances(new ArrayList<>(0)); + + assertEquals(newgrp.toString(), group.toString()); + assertGroupUpdateOnly(group); + } + + /** + * Tests addSubgroup() when the new subgroup has a wild-card policy type. + * + * @throws Exception if an error occurs + */ + @Test + void testAddSubGroupWildCardPolicyType() throws Exception { + when(toscaService.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyListWildCard.json")); + when(toscaService.getPolicyTypeList("some.*", "2.3.4")).thenReturn(Collections.emptyList()); + + PdpGroups groups = loadPdpGroups("createGroupsWildCard.json"); + PdpGroup group = loadPdpGroups("createGroups.json").getGroups().get(0); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + prov.createOrUpdateGroups(groups); + + PdpGroup newgrp = groups.getGroups().get(0); + + PdpSubGroup newsub = newgrp.getPdpSubgroups().get(1); + newsub.setCurrentInstanceCount(0); + newsub.setPdpInstances(new ArrayList<>(0)); + + assertEquals(newgrp.toString(), group.toString()); + } + + @Test + void testAddSubGroup_ValidationPolicyTypeNotFound() throws Exception { + PdpGroups groups = loadPdpGroups("createGroupsNewSub.json"); + PdpGroup group = loadPdpGroups("createGroups.json").getGroups().get(0); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + when(toscaService.getPolicyTypeList(any(), any())).thenReturn(Collections.emptyList()); + + assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).hasMessageContaining("unknown policy type"); + } + + @Test + void testAddSubGroup_ValidationPolicyTypeDaoEx() throws Exception { + PdpGroups groups = loadPdpGroups("createGroupsNewSub.json"); + PdpGroup group = loadPdpGroups("createGroups.json").getGroups().get(0); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + PfModelException exc = new PfModelException(Status.CONFLICT, EXPECTED_EXCEPTION); + when(toscaService.getPolicyTypeList(any(), any())).thenThrow(exc); + + assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isSameAs(exc); + } + + @Test + void testAddSubGroup_ValidateVersionPrefixMatch() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup dbgroup = new PdpGroup(newgrp); + when(pdpGroupService.getPdpGroups(dbgroup.getName())).thenReturn(Arrays.asList(dbgroup)); + + when(toscaService.getFilteredPolicyList(any())).thenReturn(loadPolicies("createGroupNewPolicy.json")) + .thenReturn(loadPolicies("daoPolicyList.json")).thenReturn(loadPolicies("createGroupNewPolicy.json")); + + PdpGroups reqgroups = loadPdpGroups("createGroupsVersPrefix.json"); + + prov.createOrUpdateGroups(reqgroups); + + Collections.sort(newgrp.getPdpSubgroups().get(0).getPolicies()); + Collections.sort(dbgroup.getPdpSubgroups().get(0).getPolicies()); + + assertEquals(newgrp.toString(), dbgroup.toString()); + } + + @Test + void testUpdateSubGroup_Invalid() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup group = new PdpGroup(newgrp); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + // change properties + newgrp.getPdpSubgroups().get(0).setProperties(new TreeMap<>()); + + assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class) + .hasMessageContaining("properties"); + + assertNoGroupAction(); + } + + @Test + void testUpdateSubGroup_SupportedPolicies() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup group = new PdpGroup(newgrp); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + newgrp.getPdpSubgroups().get(0).getSupportedPolicyTypes() + .add(new ToscaConceptIdentifier("typeX.*", "9.8.7")); + + // the group is updated with a new supported policy type in subgroup + assertEquals(2, newgrp.getPdpSubgroups().get(0).getSupportedPolicyTypes().size()); + prov.createOrUpdateGroups(groups); + // PdpGroup update doesn't allow supported policy type modifications + // during pdp group update, the ones in db is maintained + assertEquals(1, newgrp.getPdpSubgroups().get(0).getSupportedPolicyTypes().size()); + assertEquals(newgrp.toString(), group.toString()); + } + + @Test + void testUpdateSubGroup_DesiredCount() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup group = new PdpGroup(newgrp); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + newgrp.getPdpSubgroups().get(0).setDesiredInstanceCount(20); + + prov.createOrUpdateGroups(groups); + + assertEquals(newgrp.toString(), group.toString()); + assertGroupUpdateOnly(group); + } + + @Test + void testUpdateSubGroup_Unchanged() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup group = new PdpGroup(newgrp); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + prov.createOrUpdateGroups(groups); + + Collections.sort(newgrp.getPdpSubgroups().get(0).getPolicies()); + Collections.sort(group.getPdpSubgroups().get(0).getPolicies()); + + assertEquals(newgrp.toString(), group.toString()); + + // no notifications + checkEmptyNotification(); + + // no group updates + assertNoGroupAction(); + } + + @Test + void testValidateSubGroup_PropertiesMismatch() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup group = new PdpGroup(newgrp); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + newgrp.setProperties(new TreeMap<>()); + + assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class) + .hasMessageContaining("properties"); + + assertNoGroupAction(); + } + + private void assertNoGroupAction() throws Exception { + verify(pdpGroupService, never()).createPdpGroups(any()); + verify(pdpGroupService, never()).updatePdpGroups(any()); + verify(reqmap, never()).addRequest(any(), any()); + } + + private void assertGroupUpdateOnly(PdpGroup group) throws Exception { + verify(pdpGroupService, never()).createPdpGroups(any()); + verify(reqmap, never()).addRequest(any(), any()); + + List<PdpGroup> updates = getGroupUpdates(); + assertEquals(Arrays.asList(group), updates); + } +} diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java index 21640bf9..104fd86e 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2019, 2022 Nordix Foundation. + * Copyright (C) 2019, 2022-2023 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,12 +21,12 @@ package org.onap.policy.pap.main.rest; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.SyncInvoker; -import javax.ws.rs.core.Response; -import org.junit.Test; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.client.SyncInvoker; +import jakarta.ws.rs.core.Response; +import org.junit.jupiter.api.Test; import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse; import org.springframework.test.context.ActiveProfiles; @@ -34,22 +34,21 @@ import org.springframework.test.context.ActiveProfiles; * Note: this tests failure cases; success cases are tested by tests in the "e2e" package. */ @ActiveProfiles({ "test", "default" }) -public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer { +class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer { private static final String GROUP_NOT_FOUND = "group not found"; private static final String DELETE_GROUP_ENDPOINT = "pdps/groups"; private static final String DELETE_POLICIES_ENDPOINT = "pdps/policies"; @Test - public void testSwagger() throws Exception { + void testSwagger() throws Exception { super.testSwagger(DELETE_GROUP_ENDPOINT + "/{name}"); - super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}"); super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}/versions/{version}"); } @Test - public void testDeleteGroup() throws Exception { + void testDeleteGroup() throws Exception { String uri = DELETE_GROUP_ENDPOINT + "/my-name"; Invocation.Builder invocationBuilder = sendRequest(uri); @@ -68,7 +67,7 @@ public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer { } @Test - public void testDeletePolicy() throws Exception { + void testDeletePolicy() throws Exception { String uri = DELETE_POLICIES_ENDPOINT + "/my-name"; Invocation.Builder invocationBuilder = sendRequest(uri); @@ -87,7 +86,7 @@ public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer { } @Test - public void testDeletePolicyVersion() throws Exception { + void testDeletePolicyVersion() throws Exception { String uri = DELETE_POLICIES_ENDPOINT + "/my-name/versions/3"; Invocation.Builder invocationBuilder = sendRequest(uri); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteProvider.java index 0b6c57e7..aff3fa2b 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteProvider.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020-2022 Nordix Foundation. + * Modifications Copyright (C) 2020-2023 Nordix Foundation. * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,10 +23,10 @@ package org.onap.policy.pap.main.rest; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doThrow; @@ -35,12 +35,12 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import jakarta.ws.rs.core.Response.Status; import java.util.List; import java.util.Set; -import javax.ws.rs.core.Response.Status; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; @@ -71,7 +71,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { private ToscaConceptIdentifier ident; private Updater updater; - @AfterClass + @AfterAll public static void tearDownAfterClass() { Registry.newRegistry(); } @@ -81,7 +81,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { * * @throws Exception if an error occurs */ - @Before + @BeforeEach @Override public void setUp() throws Exception { super.setUp(); @@ -96,7 +96,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { } @Test - public void testDeleteGroup_Active() throws Exception { + void testDeleteGroup_Active() throws Exception { PdpGroup group = loadGroup("deleteGroup.json"); group.setPdpGroupState(PdpState.ACTIVE); @@ -104,19 +104,19 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { when(session.getGroup(GROUP1_NAME)).thenReturn(group); assertThatThrownBy(() -> prov.deleteGroup(GROUP1_NAME)).isInstanceOf(PfModelException.class) - .hasMessage("group is still ACTIVE"); + .hasMessage("group is still ACTIVE"); } @Test - public void testDeleteGroup_NotFound() { + void testDeleteGroup_NotFound() { assertThatThrownBy(() -> prov.deleteGroup(GROUP1_NAME)).isInstanceOf(PfModelException.class) - .hasMessage("group not found") - .extracting(ex -> ((PfModelException) ex).getErrorResponse().getResponseCode()) - .isEqualTo(Status.NOT_FOUND); + .hasMessage("group not found") + .extracting(ex -> ((PfModelException) ex).getErrorResponse().getResponseCode()) + .isEqualTo(Status.NOT_FOUND); } @Test - public void testDeleteGroup_Inactive() throws Exception { + void testDeleteGroup_Inactive() throws Exception { PdpGroup group = loadGroup("deleteGroup.json"); when(session.getGroup(GROUP1_NAME)).thenReturn(group); @@ -130,7 +130,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { } @Test - public void testDeleteGroup_Ex() throws Exception { + void testDeleteGroup_Ex() throws Exception { PdpGroup group = loadGroup("deleteGroup.json"); when(session.getGroup(GROUP1_NAME)).thenReturn(group); @@ -147,7 +147,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { * @throws Exception if an error occurs */ @Test - public void testUndeploy_Full() throws Exception { + void testUndeploy_Full() throws Exception { when(toscaService.getFilteredPolicyList(any())).thenReturn(List.of(policy1)); PdpGroup group = loadGroup("undeploy.json"); @@ -179,15 +179,15 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { } @Test - public void testUndeployPolicy_NotFound() { + void testUndeployPolicy_NotFound() { when(session.isUnchanged()).thenReturn(true); assertThatThrownBy(() -> prov.undeploy(optIdent, DEFAULT_USER)).isInstanceOf(PfModelException.class) - .hasMessage("policy does not appear in any PDP group: policyA null"); + .hasMessage("policy does not appear in any PDP group: policyA null"); } @Test - public void testUndeployPolicy_DaoEx() throws Exception { + void testUndeployPolicy_DaoEx() throws Exception { PfModelException exc = new PfModelException(Status.BAD_REQUEST, EXPECTED_EXCEPTION); prov = spy(prov); @@ -197,7 +197,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { } @Test - public void testUndeployPolicy_RtEx() throws Exception { + void testUndeployPolicy_RtEx() throws Exception { RuntimeException exc = new RuntimeException(EXPECTED_EXCEPTION); prov = spy(prov); @@ -205,11 +205,11 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { // process method catches RuntimeException and re-throws as PfModelException assertThatThrownBy(() -> prov.undeploy(fullIdent, null)).isInstanceOf(PfModelException.class) - .hasRootCauseMessage(EXPECTED_EXCEPTION); + .hasRootCauseMessage(EXPECTED_EXCEPTION); } @Test - public void testMakeUpdater_WithVersion() throws PfModelException { + void testMakeUpdater_WithVersion() throws PfModelException { /* * this group has two matching policies and one policy with a different name. */ @@ -230,7 +230,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { } @Test - public void testMakeUpdater_NullVersion() throws PfModelException { + void testMakeUpdater_NullVersion() throws PfModelException { /* * this group has two matching policies and one policy with a different name. */ @@ -249,7 +249,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { } @Test - public void testMakeUpdater_NotFound() throws PfModelException { + void testMakeUpdater_NotFound() throws PfModelException { /* * this group has one policy with a different name and one with a different * version, but not the policy of interest. @@ -279,7 +279,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { @Override protected void processPolicy(SessionData data, ToscaConceptIdentifierOptVersion desiredPolicy) - throws PfModelException { + throws PfModelException { // do nothing } } diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java index 61d204c9..338f2028 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2019-2022 Nordix Foundation. + * Copyright (C) 2019-2023 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,16 +21,16 @@ package org.onap.policy.pap.main.rest; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import java.util.Arrays; import java.util.List; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.models.pap.concepts.PdpDeployPolicies; import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse; import org.onap.policy.models.pdp.concepts.DeploymentGroup; @@ -43,19 +43,19 @@ import org.springframework.test.context.ActiveProfiles; * Note: this tests failure cases; success cases are tested by tests in the "e2e" package. */ @ActiveProfiles({ "test", "default" }) -public class TestPdpGroupDeployControllerV1 extends CommonPapRestServer { +class TestPdpGroupDeployControllerV1 extends CommonPapRestServer { private static final String DEPLOY_GROUP_ENDPOINT = "pdps/deployments/batch"; private static final String DEPLOY_POLICIES_ENDPOINT = "pdps/policies"; @Test - public void testSwagger() throws Exception { + void testSwagger() throws Exception { super.testSwagger(DEPLOY_GROUP_ENDPOINT); super.testSwagger(DEPLOY_POLICIES_ENDPOINT); } @Test - public void testUpdateGroupPolicies() throws Exception { + void testUpdateGroupPolicies() throws Exception { Entity<DeploymentGroups> entgrp = makeDeploymentGroupsEntity(); Invocation.Builder invocationBuilder = sendRequest(DEPLOY_GROUP_ENDPOINT); @@ -74,7 +74,7 @@ public class TestPdpGroupDeployControllerV1 extends CommonPapRestServer { } @Test - public void testDeployPolicies() throws Exception { + void testDeployPolicies() throws Exception { Entity<PdpDeployPolicies> entgrp = makePdpPoliciesEntity(); Invocation.Builder invocationBuilder = sendRequest(DEPLOY_POLICIES_ENDPOINT); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployProvider.java index b828509b..0de42396 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployProvider.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2021-2023 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,21 +25,21 @@ package org.onap.policy.pap.main.rest; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import jakarta.ws.rs.core.Response.Status; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import javax.ws.rs.core.Response.Status; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.services.Registry; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; @@ -72,7 +72,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { private PdpGroupDeployProvider prov; - @AfterClass + @AfterAll public static void tearDownAfterClass() { Registry.newRegistry(); } @@ -83,7 +83,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { * @throws Exception if an error occurs */ @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); @@ -92,18 +92,18 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { when(toscaService.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyList2.json")); when(toscaService.getPolicyTypeList("typeA", "100.2.3")) - .thenReturn(Arrays.asList(loadPolicyType("daoPolicyType.json"))); + .thenReturn(List.of(loadPolicyType("daoPolicyType.json"))); } /** * Tests updateGroupPolicies when policies are being added. */ @Test - public void testUpdateGroupPoliciesAdd() throws Exception { + void testUpdateGroupPoliciesAdd() throws Exception { PdpGroups groups = loadPdpGroups("deployGroups.json"); PdpGroup newgrp = groups.getGroups().get(0); PdpGroup dbgroup = new PdpGroup(newgrp); - when(pdpGroupService.getPdpGroups(dbgroup.getName())).thenReturn(Arrays.asList(dbgroup)); + when(pdpGroupService.getPdpGroups(dbgroup.getName())).thenReturn(List.of(dbgroup)); // add new policies List<ToscaConceptIdentifier> policies = newgrp.getPdpSubgroups().get(0).getPolicies(); @@ -127,7 +127,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { * Tests updateGroupPolicies when policies are being deleted. */ @Test - public void testUpdateGroupPoliciesDelete() throws Exception { + void testUpdateGroupPoliciesDelete() throws Exception { PdpGroups groups = loadPdpGroups("deployGroups.json"); PdpGroup newgrp = groups.getGroups().get(0); @@ -137,7 +137,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { policies.add(new ToscaConceptIdentifier(POLICY3_NAME, POLICY3_VERSION)); PdpGroup dbgroup = new PdpGroup(newgrp); - when(pdpGroupService.getPdpGroups(dbgroup.getName())).thenReturn(Arrays.asList(dbgroup)); + when(pdpGroupService.getPdpGroups(dbgroup.getName())).thenReturn(List.of(dbgroup)); // policy that should be left final ToscaConceptIdentifier policyId1 = policies.remove(0); @@ -163,7 +163,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { * subgroup. */ @Test - public void testUpdateGroupPoliciesAddAndDelete() throws Exception { + void testUpdateGroupPoliciesAddAndDelete() throws Exception { PdpGroups groups = loadPdpGroups("deployGroups.json"); PdpGroup newgrp = groups.getGroups().get(0); PdpSubGroup subgrp = newgrp.getPdpSubgroups().get(0); @@ -171,7 +171,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { // put policy3 into db subgroup subgrp.getPolicies().add(new ToscaConceptIdentifier(POLICY3_NAME, POLICY3_VERSION)); PdpGroup dbgroup = new PdpGroup(newgrp); - when(pdpGroupService.getPdpGroups(dbgroup.getName())).thenReturn(Arrays.asList(dbgroup)); + when(pdpGroupService.getPdpGroups(dbgroup.getName())).thenReturn(List.of(dbgroup)); // now make the subgrp reflect our final expectation subgrp.getPolicies().remove(1); @@ -181,19 +181,19 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { DeploymentSubGroup depsub1 = new DeploymentSubGroup(); depsub1.setAction(Action.POST); depsub1.setPdpType(subgrp.getPdpType()); - depsub1.setPolicies(Arrays.asList(new ToscaConceptIdentifier(POLICY2_NAME, POLICY2_VERSION))); + depsub1.setPolicies(List.of(new ToscaConceptIdentifier(POLICY2_NAME, POLICY2_VERSION))); DeploymentSubGroup depsub2 = new DeploymentSubGroup(); depsub2.setAction(Action.DELETE); depsub2.setPdpType(subgrp.getPdpType()); - depsub2.setPolicies(Arrays.asList(new ToscaConceptIdentifier(POLICY3_NAME, POLICY3_VERSION))); + depsub2.setPolicies(List.of(new ToscaConceptIdentifier(POLICY3_NAME, POLICY3_VERSION))); DeploymentGroup depgroup = new DeploymentGroup(); depgroup.setName(newgrp.getName()); depgroup.setDeploymentSubgroups(Arrays.asList(depsub1, depsub2)); DeploymentGroups depgroups = new DeploymentGroups(); - depgroups.setGroups(Arrays.asList(depgroup)); + depgroups.setGroups(List.of(depgroup)); when(toscaService.getFilteredPolicyList(any())).thenReturn(loadPolicies("createGroupNewPolicy.json")) .thenReturn(loadPolicies("daoPolicyList.json")).thenReturn(loadPolicies("createGroupNewPolicy2.json")); @@ -205,11 +205,11 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testUpdateGroupPolicies() throws Exception { + void testUpdateGroupPolicies() throws Exception { PdpGroups groups = loadPdpGroups("deployGroups.json"); PdpGroup newgrp = groups.getGroups().get(0); PdpGroup group = new PdpGroup(newgrp); - when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(List.of(group)); // something different in this subgroup group.getPdpSubgroups().get(0).getPolicies().add(new ToscaConceptIdentifier(POLICY2_NAME, POLICY2_VERSION)); @@ -221,7 +221,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testUpdateGroupPolicies_EmptyRequest() throws Exception { + void testUpdateGroupPolicies_EmptyRequest() throws Exception { prov.updateGroupPolicies(toDeploymentGroups(loadPdpGroups("emptyGroups.json")), DEFAULT_USER); // no groups, so no action should have been taken @@ -229,7 +229,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testUpdateGroupPolicies_InvalidRequest() throws Exception { + void testUpdateGroupPolicies_InvalidRequest() throws Exception { assertThatThrownBy(() -> prov.updateGroupPolicies(new DeploymentGroups(), DEFAULT_USER)) .isInstanceOf(PfModelException.class).hasMessageContaining("is null"); @@ -237,7 +237,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testUpdateGroup_UnknownGroup() throws Exception { + void testUpdateGroup_UnknownGroup() throws Exception { PdpGroups groups = loadPdpGroups("deployGroups.json"); String groupName = groups.getGroups().get(0).getName(); @@ -253,12 +253,12 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testUpdateGroup() throws Exception { + void testUpdateGroup() throws Exception { PdpGroups groups = loadPdpGroups("deployGroups.json"); // DB group = new group PdpGroup group = new PdpGroup(groups.getGroups().get(0)); - when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(List.of(group)); prov.updateGroupPolicies(toDeploymentGroups(groups), DEFAULT_USER); @@ -266,10 +266,10 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testUpdateGroup_NewSubGroup() throws Exception { + void testUpdateGroup_NewSubGroup() throws Exception { PdpGroups groups = loadPdpGroups("createGroupsNewSub.json"); PdpGroup group = loadPdpGroups("deployGroups.json").getGroups().get(0); - when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(List.of(group)); assertThatThrownBy(() -> prov.updateGroupPolicies(toDeploymentGroups(groups), DEFAULT_USER)) .isInstanceOf(PfModelException.class).hasMessageContaining("pdpTypeB") @@ -279,11 +279,11 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testUpdateGroup_UpdatedSubGroup() throws Exception { + void testUpdateGroup_UpdatedSubGroup() throws Exception { PdpGroups groups = loadPdpGroups("deployGroups.json"); PdpGroup newgrp = groups.getGroups().get(0); PdpGroup group = new PdpGroup(newgrp); - when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(List.of(group)); // something different in this subgroup group.getPdpSubgroups().get(0).getPolicies().add(new ToscaConceptIdentifier(POLICY2_NAME, POLICY2_VERSION)); @@ -295,14 +295,14 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testUpdateSubGroup_Invalid() throws Exception { + void testUpdateSubGroup_Invalid() throws Exception { PdpGroups groups = loadPdpGroups("deployGroups.json"); PdpGroup newgrp = groups.getGroups().get(0); PdpGroup group = new PdpGroup(newgrp); // group has no policies yet group.getPdpSubgroups().get(0).getPolicies().clear(); - when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(List.of(group)); // unknown policy when(toscaService.getFilteredPolicyList(any())).thenReturn(Collections.emptyList()); @@ -316,7 +316,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testUpdateSubGroup_Policies() throws Exception { + void testUpdateSubGroup_Policies() throws Exception { PdpGroups groups = loadPdpGroups("deployGroups.json"); PdpGroup newgrp = groups.getGroups().get(0); @@ -327,7 +327,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { newgrp.getPdpSubgroups().add(subgrp2); PdpGroup group = new PdpGroup(newgrp); - when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(List.of(group)); // add two new policies ToscaConceptIdentifier policyId2 = new ToscaConceptIdentifier(POLICY2_NAME, POLICY2_VERSION); @@ -354,12 +354,12 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testUpdateSubGroup_PolicyVersionPrefix() throws Exception { + void testUpdateSubGroup_PolicyVersionPrefix() throws Exception { PdpGroups groups = loadPdpGroups("deployGroups.json"); PdpGroup newgrp = groups.getGroups().get(0); PdpGroup group = new PdpGroup(newgrp); - when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(List.of(group)); // use version prefix PdpSubGroup subgrp = newgrp.getPdpSubgroups().get(0); @@ -381,12 +381,12 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testUpdateSubGroup_PolicyVersionPrefixMismatch() throws Exception { + void testUpdateSubGroup_PolicyVersionPrefixMismatch() throws Exception { PdpGroups groups = loadPdpGroups("deployGroups.json"); PdpGroup newgrp = groups.getGroups().get(0); PdpGroup group = new PdpGroup(newgrp); - when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(List.of(group)); // use incorrect version prefix newgrp.getPdpSubgroups().get(0).getPolicies().get(0).setVersion("9"); @@ -398,11 +398,11 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testUpdateSubGroup_Unchanged() throws Exception { + void testUpdateSubGroup_Unchanged() throws Exception { PdpGroups dbgroups = loadPdpGroups("deployGroups.json"); PdpGroup newgrp = dbgroups.getGroups().get(0); PdpGroup group = new PdpGroup(newgrp); - when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + when(pdpGroupService.getPdpGroups(group.getName())).thenReturn(List.of(group)); prov.updateGroupPolicies(toDeploymentGroups(dbgroups), DEFAULT_USER); @@ -419,11 +419,11 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testUpdateSubGroup_PolicyVersionMismatch() throws Exception { + void testUpdateSubGroup_PolicyVersionMismatch() throws Exception { PdpGroups dbgroups = loadPdpGroups("deployGroups.json"); PdpGroup newgrp = dbgroups.getGroups().get(0); PdpGroup dbgroup = new PdpGroup(newgrp); - when(pdpGroupService.getPdpGroups(dbgroup.getName())).thenReturn(Arrays.asList(dbgroup)); + when(pdpGroupService.getPdpGroups(dbgroup.getName())).thenReturn(List.of(dbgroup)); // arrange for DB policy version to be different PdpSubGroup dbsubgrp = dbgroup.getPdpSubgroups().get(0); @@ -438,11 +438,11 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testUpdateSubGroup_UnsupportedType() throws Exception { + void testUpdateSubGroup_UnsupportedType() throws Exception { PdpGroups dbgroups = loadPdpGroups("deployGroups.json"); PdpGroup newgrp = dbgroups.getGroups().get(0); PdpGroup dbgroup = new PdpGroup(newgrp); - when(pdpGroupService.getPdpGroups(dbgroup.getName())).thenReturn(Arrays.asList(dbgroup)); + when(pdpGroupService.getPdpGroups(dbgroup.getName())).thenReturn(List.of(dbgroup)); final DeploymentGroups groups = toDeploymentGroups(dbgroups); @@ -464,7 +464,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testDeployPolicies() throws PfModelException { + void testDeployPolicies() { assertThatCode(() -> prov.deployPolicies(loadEmptyRequest(), DEFAULT_USER)).doesNotThrowAnyException(); } @@ -472,7 +472,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { * Tests deployPolicies() when the policies are invalid. */ @Test - public void testDeployPoliciesInvalidPolicies() throws Exception { + void testDeployPoliciesInvalidPolicies() { // valid list PdpDeployPolicies policies0 = loadFile("PapPoliciesList.json", PdpDeployPolicies.class); assertThatCode(() -> prov.deployPolicies(policies0, DEFAULT_USER)).doesNotThrowAnyException(); @@ -512,7 +512,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { * @throws Exception if an error occurs */ @Test - public void testDeployPoliciesWildCard() throws Exception { + void testDeployPoliciesWildCard() throws Exception { when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(loadGroups("deployPoliciesWildCard.json")); when(toscaService.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyListWildCard.json")); when(toscaService.getPolicyTypeList(any(), any())).thenReturn(Collections.emptyList()); @@ -537,12 +537,12 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testDeploySimplePolicies() throws Exception { + void testDeploySimplePolicies() { assertThatCode(() -> prov.deployPolicies(loadEmptyRequest(), DEFAULT_USER)).doesNotThrowAnyException(); } @Test - public void testDeploySimplePolicies_PfRtEx() throws Exception { + void testDeploySimplePolicies_PfRtEx() { PfModelRuntimeException exc = new PfModelRuntimeException(Status.BAD_REQUEST, EXPECTED_EXCEPTION); when(pdpGroupService.getFilteredPdpGroups(any())).thenThrow(exc); @@ -550,7 +550,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testDeploySimplePolicies_RuntimeEx() throws Exception { + void testDeploySimplePolicies_RuntimeEx() throws Exception { RuntimeException exc = new RuntimeException(EXPECTED_EXCEPTION); when(toscaService.getFilteredPolicyList(any())).thenThrow(exc); @@ -559,7 +559,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testDeploySimplePolicies_NoGroups() throws Exception { + void testDeploySimplePolicies_NoGroups() { when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(loadGroups("emptyGroups.json")); assertThatThrownBy(() -> prov.deployPolicies(loadRequest(), DEFAULT_USER)).isInstanceOf(PfModelException.class) @@ -567,7 +567,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testMakeUpdater() throws Exception { + void testMakeUpdater() throws Exception { /* * Each subgroup has a different PDP type and name. * @@ -595,7 +595,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testMakeUpdater_PolicyVersionMismatch() throws Exception { + void testMakeUpdater_PolicyVersionMismatch() { // subgroup has a different version of the Policy when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(loadGroups("upgradeGroupDao_DiffVers.json")); @@ -610,7 +610,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } @Test - public void testMakeUpdater_NoPdps() throws Exception { + void testMakeUpdater_NoPdps() { // subgroup has no PDPs when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(loadGroups("upgradeGroup_NoPdpsDao.json")); @@ -634,13 +634,13 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { assertThat(update.getPoliciesToBeDeployed()).contains(policy1); } - private void assertNoGroupAction() throws Exception { + private void assertNoGroupAction() { verify(pdpGroupService, never()).createPdpGroups(any()); verify(pdpGroupService, never()).updatePdpGroups(any()); verify(reqmap, never()).addRequest(any(), any()); } - private void assertGroupUpdate(PdpGroup group, PdpSubGroup subgrp) throws Exception { + private void assertGroupUpdate(PdpGroup group, PdpSubGroup subgrp) { verify(pdpGroupService, never()).createPdpGroups(any()); assertEquals(0, getStateChangeRequests(1).size()); @@ -655,13 +655,12 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { assertEquals(subgrp.getPdpType(), pdpUpdate.getPdpSubgroup()); List<ToscaConceptIdentifier> pdpPolicies = pdpUpdate.getPoliciesToBeDeployed().stream() - .map(ToscaPolicy::getIdentifier).collect(Collectors.toList()); - Collections.sort(pdpPolicies); + .map(ToscaPolicy::getIdentifier).sorted().collect(Collectors.toList()); assertThat(subgrp.getPolicies()).containsAll(pdpPolicies); List<PdpGroup> updates = getGroupUpdates(); - assertEquals(Arrays.asList(group), updates); + assertEquals(List.of(group), updates); } /** diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupHealthCheckControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupHealthCheckControllerV1.java index f935f923..e0854538 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupHealthCheckControllerV1.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupHealthCheckControllerV1.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019, 2022 Nordix Foundation. + * Copyright (C) 2019, 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,13 +20,13 @@ package org.onap.policy.pap.main.rest; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.SyncInvoker; -import javax.ws.rs.core.Response; -import org.junit.Test; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.client.SyncInvoker; +import jakarta.ws.rs.core.Response; +import org.junit.jupiter.api.Test; import org.onap.policy.models.pdp.concepts.Pdps; import org.springframework.test.context.ActiveProfiles; @@ -36,17 +36,17 @@ import org.springframework.test.context.ActiveProfiles; * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ @ActiveProfiles({ "test", "default" }) -public class TestPdpGroupHealthCheckControllerV1 extends CommonPapRestServer { +class TestPdpGroupHealthCheckControllerV1 extends CommonPapRestServer { private static final String ENDPOINT = "pdps/healthcheck"; @Test - public void testSwagger() throws Exception { + void testSwagger() throws Exception { super.testSwagger(ENDPOINT); } @Test - public void testPdpGroupHealthCheck() throws Exception { + void testPdpGroupHealthCheck() throws Exception { final String uri = ENDPOINT; final Invocation.Builder invocationBuilder = sendRequest(uri); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupHealthCheckProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupHealthCheckProvider.java index 0040beae..dff023cc 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupHealthCheckProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupHealthCheckProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019, 2023 Nordix Foundation. * Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -22,17 +22,18 @@ package org.onap.policy.pap.main.rest; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; import java.io.File; import java.util.List; import org.apache.commons.lang3.tuple.Pair; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.MockitoAnnotations; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -51,28 +52,34 @@ import org.springframework.http.HttpStatus; * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ -@RunWith(MockitoJUnitRunner.class) -public class TestPdpGroupHealthCheckProvider { +class TestPdpGroupHealthCheckProvider { @Mock private PdpGroupService pdpGroupService; private List<PdpGroup> groups; - private Coder coder = new StandardCoder(); + private final Coder coder = new StandardCoder(); + + AutoCloseable autoCloseable; /** * Configures DAO and mocks. */ - @Before + @BeforeEach public void setUp() throws Exception { - + autoCloseable = MockitoAnnotations.openMocks(this); Registry.newRegistry(); - groups = loadFile("pdpGroup.json").getGroups(); + groups = loadFile().getGroups(); when(pdpGroupService.getPdpGroups()).thenReturn(groups); } + @AfterEach + public void tearDown() throws Exception { + autoCloseable.close(); + } + @Test - public void testFetchPdpGroupHealthStatus() throws Exception { + void testFetchPdpGroupHealthStatus() throws Exception { final PdpGroupHealthCheckProvider provider = new PdpGroupHealthCheckProvider(pdpGroupService); final Pair<HttpStatus, Pdps> pair = provider.fetchPdpGroupHealthStatus(); assertEquals(HttpStatus.OK, pair.getLeft()); @@ -81,15 +88,21 @@ public class TestPdpGroupHealthCheckProvider { private void verifyPdps(final List<Pdp> pdpList, final List<PdpGroup> groups) { assertEquals(6, pdpList.size()); - for (final PdpGroup group : groups) { - for (final PdpSubGroup subGroup : group.getPdpSubgroups()) { - pdpList.containsAll(subGroup.getPdpInstances()); + boolean containsAll = false; + + do { + for (final PdpGroup group : groups) { + for (final PdpSubGroup subGroup : group.getPdpSubgroups()) { + containsAll = pdpList.containsAll(subGroup.getPdpInstances()); + } } - } + } while (!containsAll); + + assertTrue(containsAll); } - private PdpGroups loadFile(final String fileName) { - final File propFile = new File(ResourceUtils.getFilePath4Resource("rest/" + fileName)); + private PdpGroups loadFile() { + final File propFile = new File(ResourceUtils.getFilePath4Resource("rest/" + "pdpGroup.json")); try { return coder.decode(propFile, PdpGroups.class); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupQueryControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupQueryControllerV1.java index 30cd5944..0dd311c4 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupQueryControllerV1.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupQueryControllerV1.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019, 2022 Nordix Foundation. + * Copyright (C) 2019, 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,13 +20,13 @@ package org.onap.policy.pap.main.rest; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.SyncInvoker; -import javax.ws.rs.core.Response; -import org.junit.Test; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.client.SyncInvoker; +import jakarta.ws.rs.core.Response; +import org.junit.jupiter.api.Test; import org.onap.policy.models.pdp.concepts.PdpGroups; import org.springframework.test.context.ActiveProfiles; @@ -35,18 +35,18 @@ import org.springframework.test.context.ActiveProfiles; * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ -@ActiveProfiles({ "test", "default" }) -public class TestPdpGroupQueryControllerV1 extends CommonPapRestServer { +@ActiveProfiles({"test", "default"}) +class TestPdpGroupQueryControllerV1 extends CommonPapRestServer { private static final String GROUP_ENDPOINT = "pdps"; @Test - public void testSwagger() throws Exception { + void testSwagger() throws Exception { super.testSwagger(GROUP_ENDPOINT); } @Test - public void testChangeGroupState() throws Exception { + void testChangeGroupState() throws Exception { final String uri = GROUP_ENDPOINT; final Invocation.Builder invocationBuilder = sendRequest(uri); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupStateChangeControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupStateChangeControllerV1.java index a92731ab..0701bd97 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupStateChangeControllerV1.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupStateChangeControllerV1.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019, 2022 Nordix Foundation. + * Copyright (C) 2019, 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,13 +20,13 @@ package org.onap.policy.pap.main.rest; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.Response; -import org.junit.Test; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.core.Response; +import org.junit.jupiter.api.Test; import org.onap.policy.models.pap.concepts.PdpGroupStateChangeResponse; import org.springframework.test.context.ActiveProfiles; @@ -35,18 +35,18 @@ import org.springframework.test.context.ActiveProfiles; * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ -@ActiveProfiles({ "test", "default" }) -public class TestPdpGroupStateChangeControllerV1 extends CommonPapRestServer { +@ActiveProfiles({"test", "default"}) +class TestPdpGroupStateChangeControllerV1 extends CommonPapRestServer { private static final String GROUP_ENDPOINT = "pdps/groups"; @Test - public void testSwagger() throws Exception { + void testSwagger() throws Exception { super.testSwagger(GROUP_ENDPOINT + "/{name}"); } @Test - public void testChangeGroupState() throws Exception { + void testChangeGroupState() throws Exception { final String uri = GROUP_ENDPOINT + "/my-name?state=ACTIVE"; final Invocation.Builder invocationBuilder = sendRequest(uri); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyAuditControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyAuditControllerV1.java index 3764e211..8c4cd821 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyAuditControllerV1.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyAuditControllerV1.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2022 Nordix Foundation. + * Modifications Copyright (C) 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,24 +19,23 @@ package org.onap.policy.pap.main.rest; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.Response; -import org.junit.Test; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.core.Response; +import org.junit.jupiter.api.Test; import org.springframework.test.context.ActiveProfiles; /** * Note: this tests failure cases; success cases are tested by tests in the "e2e" package. */ -@ActiveProfiles({ "test", "default" }) -public class TestPolicyAuditControllerV1 extends CommonPapRestServer { +@ActiveProfiles({"test", "default"}) +class TestPolicyAuditControllerV1 extends CommonPapRestServer { private static final String POLICY_AUDIT_ENDPOINT = "policies/audit"; @Test - public void testSwagger() throws Exception { - + void testSwagger() throws Exception { super.testSwagger(POLICY_AUDIT_ENDPOINT); super.testSwagger(POLICY_AUDIT_ENDPOINT + "/{pdpGroupName}"); super.testSwagger(POLICY_AUDIT_ENDPOINT + "/{pdpGroupName}/{policyName}/{policyVersion}"); @@ -44,7 +43,7 @@ public class TestPolicyAuditControllerV1 extends CommonPapRestServer { } @Test - public void testGetAllAuditRecords() throws Exception { + void testGetAllAuditRecords() throws Exception { String uri = POLICY_AUDIT_ENDPOINT; // verify it fails when no authorization info is included @@ -52,12 +51,12 @@ public class TestPolicyAuditControllerV1 extends CommonPapRestServer { } @Test - public void testGetAuditRecordsByGroup() throws Exception { + void testGetAuditRecordsByGroup() throws Exception { checkRequest(POLICY_AUDIT_ENDPOINT + "/my-group-name"); } @Test - public void testGetAuditRecordsOfPolicy() throws Exception { + void testGetAuditRecordsOfPolicy() throws Exception { checkRequest(POLICY_AUDIT_ENDPOINT + "/my-group-name/my-name/1.2.3"); checkRequest(POLICY_AUDIT_ENDPOINT + "/my-name/1.2.3"); } diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyAuditManager.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyAuditManager.java index 4f844fbc..12b9b351 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyAuditManager.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyAuditManager.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,19 +23,18 @@ package org.onap.policy.pap.main.rest; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.services.Registry; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.pap.concepts.PolicyAudit.AuditAction; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - public class TestPolicyAuditManager extends ProviderSuper { private static final ToscaConceptIdentifier MY_POLICY = new ToscaConceptIdentifier("myPolicy", "1.0.0"); @@ -50,19 +49,19 @@ public class TestPolicyAuditManager extends ProviderSuper { * Setup the test variables. */ @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); auditManager = new PolicyAuditManager(policyAuditService); } - @AfterClass + @AfterAll public static void tearDownAfterClass() { Registry.newRegistry(); } @Test - public void testDeployments() { + void testDeployments() { auditManager.addDeploymentAudit(MY_POLICY, GROUP_A, PDP_TYPE, USER); auditManager.addUndeploymentAudit(MY_POLICY, GROUP_B, PDP_TYPE, USER); @@ -76,15 +75,16 @@ public class TestPolicyAuditManager extends ProviderSuper { } @Test - public void testSaveRecordsToDb_EmptyList() { - assertThat(auditManager.getAuditRecords()).isEmpty();; + void testSaveRecordsToDb_EmptyList() { + assertThat(auditManager.getAuditRecords()).isEmpty(); + ; auditManager.saveRecordsToDb(); assertThatCode(() -> auditManager.saveRecordsToDb()).doesNotThrowAnyException(); } @Test - public void testSaveRecordsToDb_Exception() { + void testSaveRecordsToDb_Exception() { auditManager.addDeploymentAudit(MY_POLICY, GROUP_A, PDP_TYPE, USER); assertThat(auditManager.getAuditRecords()).hasSize(1); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckControllerV1.java index ff91ebe9..b0928071 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckControllerV1.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckControllerV1.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020, 2022 Nordix Foundation. + * Copyright (C) 2019-2020, 2022-2023 Nordix Foundation. * Modifications Copyright (C) 2020-2021 AT&T Inc. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ @@ -22,16 +22,16 @@ package org.onap.policy.pap.main.rest; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.core.GenericType; +import jakarta.ws.rs.core.Response; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.GenericType; -import javax.ws.rs.core.Response; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.endpoints.parameters.RestClientParameters; import org.onap.policy.pap.main.parameters.PapParameterGroup; import org.springframework.beans.factory.annotation.Autowired; @@ -43,7 +43,7 @@ import org.springframework.test.context.ActiveProfiles; * @author Yehui Wang (yehui.wang@est.tech) */ @ActiveProfiles({ "test", "default" }) -public class TestPolicyComponentsHealthCheckControllerV1 extends CommonPapRestServer { +class TestPolicyComponentsHealthCheckControllerV1 extends CommonPapRestServer { private static final String ENDPOINT = "components/healthcheck"; private List<RestClientParameters> savedRestClientParameters; @@ -52,13 +52,13 @@ public class TestPolicyComponentsHealthCheckControllerV1 extends CommonPapRestSe private PapParameterGroup papParameterGroup; @Test - public void testSwagger() throws Exception { + void testSwagger() throws Exception { super.testSwagger(ENDPOINT); } @Test @SuppressWarnings("unchecked") - public void testPolicyComponentsHealthCheck() throws Exception { + void testPolicyComponentsHealthCheck() throws Exception { // take out the other components for healthcheck savedRestClientParameters = papParameterGroup.getHealthCheckRestClientParameters(); papParameterGroup.setHealthCheckRestClientParameters(null); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java index 3db1ed83..41597218 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020, 2022 Nordix Foundation. + * Copyright (C) 2020, 2022-2023 Nordix Foundation. * Modifications Copyright (C) 2020-2021 AT&T Corp. * Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved. * ================================================================================ @@ -22,24 +22,23 @@ package org.onap.policy.pap.main.rest; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; +import jakarta.ws.rs.core.Response; import java.io.File; import java.net.HttpURLConnection; import java.util.ArrayList; import java.util.List; import java.util.Map; -import javax.ws.rs.core.Response; import org.apache.commons.lang3.tuple.Pair; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.MockitoAnnotations; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; import org.onap.policy.common.endpoints.report.HealthCheckReport; @@ -61,8 +60,7 @@ import org.onap.policy.pap.main.startstop.PapActivator; import org.springframework.http.HttpStatus; import org.springframework.test.util.ReflectionTestUtils; -@RunWith(MockitoJUnitRunner.class) -public class TestPolicyComponentsHealthCheckProvider { +class TestPolicyComponentsHealthCheckProvider { private static final String CLIENT_1 = "client1"; private static final String PDP_GROUP_DATA_FILE = "rest/pdpGroup.json"; @@ -102,13 +100,16 @@ public class TestPolicyComponentsHealthCheckProvider { private PolicyComponentsHealthCheckProvider provider; + AutoCloseable autoCloseable; + /** * Configures mocks and objects. * * @throws Exception if an error occurs */ - @Before + @BeforeEach public void setUp() throws Exception { + autoCloseable = MockitoAnnotations.openMocks(this); groups = loadPdpGroupsFromFile().getGroups(); when(pdpGroupService.getPdpGroups()).thenReturn(groups); @@ -155,26 +156,27 @@ public class TestPolicyComponentsHealthCheckProvider { /** * Tear down. */ - @After - public void tearDown() { + @AfterEach + public void tearDown() throws Exception { if (savedPapParameterGroup != null) { ParameterService.register(savedPapParameterGroup, true); } else { ParameterService.deregister(PAP_GROUP_PARAMS_NAME); } provider.cleanup(); + autoCloseable.close(); } @Test - public void testFetchPolicyComponentsHealthStatus_allHealthy() { + void testFetchPolicyComponentsHealthStatus_allHealthy() { Pair<HttpStatus, Map<String, Object>> ret = provider.fetchPolicyComponentsHealthStatus(); assertEquals(HttpStatus.OK, ret.getLeft()); assertTrue((Boolean) ret.getRight().get(HEALTHY)); } @Test - public void testFetchPolicyComponentsHealthStatus_unhealthyClient() { + void testFetchPolicyComponentsHealthStatus_unhealthyClient() { when(response1.getStatus()).thenReturn(HttpURLConnection.HTTP_INTERNAL_ERROR); when(response1.readEntity(HealthCheckReport.class)) .thenReturn(createReport(HttpURLConnection.HTTP_INTERNAL_ERROR, false)); @@ -207,7 +209,7 @@ public class TestPolicyComponentsHealthCheckProvider { @SuppressWarnings("unchecked") @Test - public void testFetchPolicyComponentsHealthStatus_unhealthyPdps() { + void testFetchPolicyComponentsHealthStatus_unhealthyPdps() { // Get a PDP and set it unhealthy groups.get(0).getPdpSubgroups().get(0).getPdpInstances().get(0).setHealthy(PdpHealthStatus.NOT_HEALTHY); Map<String, Object> result = callFetchPolicyComponentsHealthStatus(); @@ -217,7 +219,7 @@ public class TestPolicyComponentsHealthCheckProvider { } @Test - public void testFetchPolicyComponentsHealthStatus_PdpDown() { + void testFetchPolicyComponentsHealthStatus_PdpDown() { // Set currentInstanceCount as 0 to simulate PDP down groups.get(0).getPdpSubgroups().get(0).setCurrentInstanceCount(0); Map<String, Object> result = callFetchPolicyComponentsHealthStatus(); @@ -225,7 +227,7 @@ public class TestPolicyComponentsHealthCheckProvider { } @Test - public void testFetchPolicyComponentsHealthStatus_unhealthyPap() { + void testFetchPolicyComponentsHealthStatus_unhealthyPap() { when(papActivator.isAlive()).thenReturn(false); Map<String, Object> result = callFetchPolicyComponentsHealthStatus(); assertFalse((Boolean) result.get(HEALTHY)); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java index 41cfd39d..08ec80a4 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2019, 2021-2022 Nordix Foundation. + * Copyright (C) 2019, 2021-2023 Nordix Foundation. * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ @@ -23,25 +23,25 @@ package org.onap.policy.pap.main.rest; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.SyncInvoker; -import javax.ws.rs.core.Response; -import org.junit.Test; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.client.SyncInvoker; +import jakarta.ws.rs.core.Response; +import org.junit.jupiter.api.Test; import org.springframework.test.context.ActiveProfiles; /** * Note: this tests failure cases; success cases are tested by tests in the "e2e" package. */ @ActiveProfiles({ "test", "default" }) -public class TestPolicyStatusControllerV1 extends CommonPapRestServer { +class TestPolicyStatusControllerV1 extends CommonPapRestServer { private static final String POLICY_STATUS_ENDPOINT = "policies/deployed"; private static final String POLICY_DEPLOYMENT_STATUS_ENDPOINT = "policies/status"; @Test - public void testSwagger() throws Exception { + void testSwagger() throws Exception { super.testSwagger(POLICY_STATUS_ENDPOINT); super.testSwagger(POLICY_STATUS_ENDPOINT + "/{name}"); super.testSwagger(POLICY_STATUS_ENDPOINT + "/{name}/{version}"); @@ -53,40 +53,40 @@ public class TestPolicyStatusControllerV1 extends CommonPapRestServer { } @Test - public void testQueryAllDeployedPolicies() throws Exception { + void testQueryAllDeployedPolicies() throws Exception { // verify it fails when no authorization info is included checkUnauthRequest(POLICY_STATUS_ENDPOINT, SyncInvoker::get); checkRequest(POLICY_STATUS_ENDPOINT); } @Test - public void testQueryAllDeployedPoliciesWithRegex() throws Exception { + void testQueryAllDeployedPoliciesWithRegex() throws Exception { checkRequest(POLICY_STATUS_ENDPOINT + "?regex=my.(1)name"); checkEmptyRegexRequest(POLICY_STATUS_ENDPOINT + "?regex="); checkInvalidRegexRequest(POLICY_STATUS_ENDPOINT + "?regex=my-(name"); } @Test - public void testQueryDeployedPolicies() throws Exception { + void testQueryDeployedPolicies() throws Exception { checkRequest(POLICY_STATUS_ENDPOINT + "/my-name"); checkRequest(POLICY_STATUS_ENDPOINT + "/my-name/1.2.3"); } @Test - public void testGetStatusOfAllPolicies() throws Exception { + void testGetStatusOfAllPolicies() throws Exception { // verify it fails when no authorization info is included checkUnauthRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT, SyncInvoker::get); } @Test - public void testGetStatusOfPolicies() throws Exception { + void testGetStatusOfPolicies() throws Exception { checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name"); checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name/my-name"); checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name/my-name/1.2.3"); } @Test - public void testGetStatusOfPoliciesWithRegex() throws Exception { + void testGetStatusOfPoliciesWithRegex() throws Exception { checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name?regex=my-%3F%5Bmn%5Da.%7B1%7De"); checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name?regex=my.(1)name"); // my-?[mna.{1}e diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusProvider.java index 1f2c08ed..9b809095 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusProvider.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021, 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,21 +23,20 @@ package org.onap.policy.pap.main.rest; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; +import java.util.Comparator; import java.util.Iterator; import java.util.List; import lombok.NonNull; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.services.Registry; -import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.pap.concepts.PolicyStatus; import org.onap.policy.models.pdp.concepts.PdpPolicyStatus; import org.onap.policy.models.pdp.concepts.PdpPolicyStatus.PdpPolicyStatusBuilder; @@ -59,7 +58,7 @@ public class TestPolicyStatusProvider extends ProviderSuper { private PolicyStatusProvider prov; - @AfterClass + @AfterAll public static void tearDownAfterClass() { Registry.newRegistry(); } @@ -70,7 +69,7 @@ public class TestPolicyStatusProvider extends ProviderSuper { * @throws Exception if an error occurs */ @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); @@ -79,12 +78,12 @@ public class TestPolicyStatusProvider extends ProviderSuper { } @Test - public void testGetStatus_testAccumulate() throws PfModelException { + void testGetStatus_testAccumulate() { buildPolicyStatusToReturn1(); List<PolicyStatus> result = new ArrayList<>(prov.getStatus()); - Collections.sort(result, (rec1, rec2) -> rec1.getPolicy().compareTo(rec2.getPolicy())); + result.sort(Comparator.comparing(PolicyStatus::getPolicy)); assertThat(result).hasSize(3); @@ -113,7 +112,7 @@ public class TestPolicyStatusProvider extends ProviderSuper { } @Test - public void testGetStatusToscaConceptIdentifierOptVersion() throws PfModelException { + void testGetStatusToscaConceptIdentifierOptVersion() { ToscaConceptIdentifierOptVersion optIdent = buildPolicyStatusToReturn2(); @@ -131,12 +130,12 @@ public class TestPolicyStatusProvider extends ProviderSuper { } @Test - public void testGetPolicyStatus() throws PfModelException { + void testGetPolicyStatus() { buildPolicyStatusToReturn1(); List<PdpPolicyStatus> result = new ArrayList<>(prov.getPolicyStatus()); - Collections.sort(result, (rec1, rec2) -> rec1.getPolicy().compareTo(rec2.getPolicy())); + result.sort(Comparator.comparing(PdpPolicyStatus::getPolicy)); assertThat(result).hasSize(5); Iterator<PdpPolicyStatus> iter = result.iterator(); @@ -170,7 +169,7 @@ public class TestPolicyStatusProvider extends ProviderSuper { } @Test - public void testGetPolicyStatusByGroupAndPolicyIdVersion() throws PfModelException { + void testGetPolicyStatusByGroupAndPolicyIdVersion() { ToscaConceptIdentifierOptVersion optIdent = buildPolicyStatusToReturn2(); @@ -199,7 +198,7 @@ public class TestPolicyStatusProvider extends ProviderSuper { } @Test - public void testGetPolicyStatusByRegexNoMatch() throws PfModelException { + void testGetPolicyStatusByRegexNoMatch() { buildPolicyStatusToReturn1(); final String pattern = "Hello"; @@ -208,7 +207,7 @@ public class TestPolicyStatusProvider extends ProviderSuper { } @Test - public void testGetPolicyStatusOneMatch() throws PfModelException { + void testGetPolicyStatusOneMatch() { buildPolicyStatusToReturn1(); final String pattern = "My(We|Po)[li]{0,3}c.A"; @@ -220,7 +219,7 @@ public class TestPolicyStatusProvider extends ProviderSuper { } @Test - public void testGetPolicyStatusAllMatch() throws PfModelException { + void testGetPolicyStatusAllMatch() { buildPolicyStatusToReturn1(); final String pattern = "My(We|Po)[li]{0,3}c.{2}0*"; @@ -229,7 +228,7 @@ public class TestPolicyStatusProvider extends ProviderSuper { assertThat(actual).hasSize(3); } - private void buildPolicyStatusToReturn1() throws PfModelException { + private void buildPolicyStatusToReturn1() { PdpPolicyStatusBuilder builder = PdpPolicyStatus.builder().pdpGroup(MY_GROUP).pdpType(MY_PDP_TYPE) .policyType(POLICY_TYPE).state(State.WAITING); @@ -250,7 +249,7 @@ public class TestPolicyStatusProvider extends ProviderSuper { // @formatter:on } - private ToscaConceptIdentifierOptVersion buildPolicyStatusToReturn2() throws PfModelException { + private ToscaConceptIdentifierOptVersion buildPolicyStatusToReturn2() { PdpPolicyStatusBuilder builder = PdpPolicyStatus.builder().pdpGroup(MY_GROUP).pdpType(MY_PDP_TYPE).policy(POLICY_A).policyType(POLICY_TYPE); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyUndeployerImpl.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyUndeployerImpl.java index 9ae64452..eab65a3d 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyUndeployerImpl.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyUndeployerImpl.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021, 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,20 +21,20 @@ package org.onap.policy.pap.main.rest; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.util.Arrays; import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Set; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; @@ -66,7 +66,7 @@ public class TestPolicyUndeployerImpl extends ProviderSuper { private MyProvider prov; - @AfterClass + @AfterAll public static void tearDownAfterClass() { Registry.newRegistry(); } @@ -77,7 +77,7 @@ public class TestPolicyUndeployerImpl extends ProviderSuper { * @throws Exception if an error occurs */ @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); @@ -96,15 +96,15 @@ public class TestPolicyUndeployerImpl extends ProviderSuper { Pdp pdp1 = new Pdp(); pdp1.setInstanceId(PDP1); - subgroup.setPdpInstances(Arrays.asList(pdp1)); + subgroup.setPdpInstances(List.of(pdp1)); // this subgroup should never be touched PdpSubGroup subgroup0 = new PdpSubGroup(); subgroup0.setPdpType(MY_SUBGROUP0); - subgroup0.setPolicies(Collections.unmodifiableList(Arrays.asList(ident1, ident2, ident3, ident4))); - subgroup.setPdpInstances(Arrays.asList(pdp1)); + subgroup0.setPolicies(List.of(ident1, ident2, ident3, ident4)); + subgroup.setPdpInstances(List.of(pdp1)); - group.setPdpSubgroups(Arrays.asList(subgroup0, subgroup)); + group.setPdpSubgroups(List.of(subgroup0, subgroup)); when(session.getGroup(MY_GROUP)).thenReturn(group); when(session.getPolicy(any())).thenReturn(policy1); @@ -113,16 +113,16 @@ public class TestPolicyUndeployerImpl extends ProviderSuper { } @Test - public void testUndeployPolicies() throws PfModelException { - subgroup.setPolicies(new LinkedList<>(Arrays.asList(ident1, ident2, ident3, ident4))); + void testUndeployPolicies() throws PfModelException { + subgroup.setPolicies(new LinkedList<>(List.of(ident1, ident2, ident3, ident4))); - prov.undeploy(MY_GROUP, MY_SUBGROUP, Arrays.asList(ident1, ident2)); + prov.undeploy(MY_GROUP, MY_SUBGROUP, List.of(ident1, ident2)); // group should have been updated verify(session).update(group); // subgroup should only have remaining policies - assertEquals(Arrays.asList(ident3, ident4).toString(), subgroup.getPolicies().toString()); + assertEquals(List.of(ident3, ident4).toString(), subgroup.getPolicies().toString()); // should have generated PDP-UPDATE for the PDP verify(session).addUpdate(any()); @@ -132,11 +132,11 @@ public class TestPolicyUndeployerImpl extends ProviderSuper { * Tests undeployPolicies() when the policies do not exist in the subgroup. */ @Test - public void testUndeployPoliciesUnchanged() throws PfModelException { - List<ToscaConceptIdentifier> origlist = Arrays.asList(ident3, ident4); + void testUndeployPoliciesUnchanged() throws PfModelException { + List<ToscaConceptIdentifier> origlist = List.of(ident3, ident4); subgroup.setPolicies(new LinkedList<>(origlist)); - prov.undeploy(MY_GROUP, MY_SUBGROUP, Arrays.asList(ident1, ident2)); + prov.undeploy(MY_GROUP, MY_SUBGROUP, List.of(ident1, ident2)); // group NOT should have been updated verify(session, never()).update(group); @@ -152,13 +152,13 @@ public class TestPolicyUndeployerImpl extends ProviderSuper { * Tests undeployPolicies() when the group is not found. */ @Test - public void testUndeployPoliciesGroupNotFound() throws PfModelException { + void testUndeployPoliciesGroupNotFound() throws PfModelException { // force exception to be thrown if the list is changed - subgroup.setPolicies(Collections.unmodifiableList(Arrays.asList(ident1, ident2, ident3, ident4))); + subgroup.setPolicies(List.of(ident1, ident2, ident3, ident4)); when(session.getGroup(any())).thenReturn(null); - prov.undeploy(MY_GROUP, MY_SUBGROUP, Arrays.asList(ident1, ident2)); + prov.undeploy(MY_GROUP, MY_SUBGROUP, List.of(ident1, ident2)); // group should have been updated verify(session, never()).update(group); @@ -171,13 +171,13 @@ public class TestPolicyUndeployerImpl extends ProviderSuper { * Tests undeployPolicies() when the subgroup is not found. */ @Test - public void testUndeployPoliciesSubGroupNotFound() throws PfModelException { + void testUndeployPoliciesSubGroupNotFound() throws PfModelException { // force exception to be thrown if the list is changed - subgroup.setPolicies(Collections.unmodifiableList(Arrays.asList(ident1, ident2, ident3, ident4))); + subgroup.setPolicies(Collections.unmodifiableList(List.of(ident1, ident2, ident3, ident4))); subgroup.setPdpType(MY_SUBGROUP + "X"); - prov.undeploy(MY_GROUP, MY_SUBGROUP, Arrays.asList(ident1, ident2)); + prov.undeploy(MY_GROUP, MY_SUBGROUP, List.of(ident1, ident2)); // group should have been updated verify(session, never()).update(group); @@ -186,12 +186,11 @@ public class TestPolicyUndeployerImpl extends ProviderSuper { verify(session, never()).addUpdate(any()); } - @Test(expected = UnsupportedOperationException.class) - public void testMakeUpdater() { - prov.makeUpdater(null, null, null); + @Test + void testMakeUpdater() { + assertThrows(UnsupportedOperationException.class, () -> prov.makeUpdater(null, null, null)); } - private class MyProvider extends PolicyUndeployerImpl { @Override diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestProviderBase.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestProviderBase.java index d969c565..9a95590e 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestProviderBase.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestProviderBase.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021,2023 Nordix Foundation. + * Modifications Copyright (C) 2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,23 +23,22 @@ package org.onap.policy.pap.main.rest; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.util.Arrays; +import jakarta.ws.rs.core.Response.Status; import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Queue; -import javax.ws.rs.core.Response.Status; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.services.Registry; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; @@ -71,7 +70,7 @@ public class TestProviderBase extends ProviderSuper { private MyProvider prov; - @AfterClass + @AfterAll public static void tearDownAfterClass() { Registry.newRegistry(); } @@ -82,7 +81,7 @@ public class TestProviderBase extends ProviderSuper { * @throws Exception if an error occurs */ @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); prov = new MyProvider(); @@ -91,13 +90,13 @@ public class TestProviderBase extends ProviderSuper { } @Test - public void testProviderBase() { + void testProviderBase() { assertSame(lockit, ReflectionTestUtils.getField(prov, "updateLock")); assertSame(reqmap, ReflectionTestUtils.getField(prov, "requestMap")); } @Test - public void testProcess() throws Exception { + void testProcess() throws Exception { prov.process(loadRequest(), this::handle); assertGroup(getGroupUpdates(), GROUP1_NAME); @@ -108,7 +107,7 @@ public class TestProviderBase extends ProviderSuper { } @Test - public void testProcess_PfRtEx() throws Exception { + void testProcess_PfRtEx() throws Exception { PfModelRuntimeException ex = new PfModelRuntimeException(Status.BAD_REQUEST, EXPECTED_EXCEPTION); when(pdpGroupService.updatePdpGroups(any())).thenThrow(ex); @@ -116,7 +115,7 @@ public class TestProviderBase extends ProviderSuper { } @Test - public void testProcess_RuntimeEx() throws Exception { + void testProcess_RuntimeEx() throws Exception { RuntimeException ex = new RuntimeException(EXPECTED_EXCEPTION); when(pdpGroupService.updatePdpGroups(any())).thenThrow(ex); @@ -125,7 +124,7 @@ public class TestProviderBase extends ProviderSuper { } @Test - public void testProcessPolicy_NoGroups() throws Exception { + void testProcessPolicy_NoGroups() throws Exception { when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(Collections.emptyList()); SessionData session = @@ -137,7 +136,7 @@ public class TestProviderBase extends ProviderSuper { } @Test - public void testGetPolicy() throws Exception { + void testGetPolicy() throws Exception { PfModelException exc = new PfModelException(Status.CONFLICT, EXPECTED_EXCEPTION); when(toscaService.getFilteredPolicyList(any())).thenThrow(exc); @@ -147,7 +146,7 @@ public class TestProviderBase extends ProviderSuper { } @Test - public void testGetPolicy_NotFound() throws Exception { + void testGetPolicy_NotFound() throws Exception { when(toscaService.getFilteredPolicyList(any())).thenReturn(Collections.emptyList()); ToscaConceptIdentifierOptVersion req = loadRequest(); @@ -158,7 +157,7 @@ public class TestProviderBase extends ProviderSuper { } @Test - public void testGetGroup() throws Exception { + void testGetGroup() throws Exception { when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(loadGroups("getGroupDao.json")) .thenReturn(loadGroups("groups.json")); @@ -168,7 +167,7 @@ public class TestProviderBase extends ProviderSuper { } @Test - public void testUpgradeGroup() throws Exception { + void testUpgradeGroup() throws Exception { /* * Each subgroup has a different PDP type and name. * @@ -196,7 +195,7 @@ public class TestProviderBase extends ProviderSuper { } @Test - public void testUpgradeGroup_Multiple() throws Exception { + void testUpgradeGroup_Multiple() throws Exception { /* * Policy data in the DB: policy1=type1, policy2=type2, policy3=type3, * policy4=type1 @@ -254,7 +253,7 @@ public class TestProviderBase extends ProviderSuper { } @Test - public void testUpgradeGroup_NothingUpdated() throws Exception { + void testUpgradeGroup_NothingUpdated() throws Exception { prov.clear(); prov.add(false); @@ -319,8 +318,8 @@ public class TestProviderBase extends ProviderSuper { private static class MyProvider extends ProviderBase { /** - * Used to determine whether or not to make an update when - * {@link #makeUpdater(ToscaPolicy)} is called. The updater function removes an + * Used to determine whether to make an update when + * makeUpdater() is called. The updater function removes an * item from this queue each time it is invoked. */ private final Queue<Boolean> shouldUpdate = new LinkedList<>(); @@ -339,7 +338,7 @@ public class TestProviderBase extends ProviderSuper { } public void add(Boolean... update) { - shouldUpdate.addAll(Arrays.asList(update)); + shouldUpdate.addAll(List.of(update)); } @Override diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestSessionData.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestSessionData.java index ec79c03a..82f34616 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestSessionData.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestSessionData.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,11 +26,11 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.mock; @@ -39,17 +39,16 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import jakarta.ws.rs.core.Response.Status; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; -import javax.ws.rs.core.Response.Status; import org.apache.commons.lang3.tuple.Pair; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.pap.concepts.PolicyNotification; @@ -64,7 +63,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; import org.onap.policy.pap.main.notification.DeploymentStatus; import org.onap.policy.pap.main.service.PolicyStatusService; -public class TestSessionData extends ProviderSuper { +class TestSessionData extends ProviderSuper { private static final String GROUP_NAME = "groupA"; private static final String PDP_TYPE = "MySubGroup"; private static final String PDP1 = "pdp_1"; @@ -90,7 +89,7 @@ public class TestSessionData extends ProviderSuper { * @throws Exception if an error occurs */ @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); @@ -104,9 +103,9 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testGetPolicyType() throws Exception { + void testGetPolicyType() throws Exception { ToscaPolicyType policy1 = makePolicyType(POLICY_TYPE, POLICY_TYPE_VERSION); - when(toscaService.getPolicyTypeList(POLICY_TYPE, POLICY_TYPE_VERSION)).thenReturn(Arrays.asList(policy1)); + when(toscaService.getPolicyTypeList(POLICY_TYPE, POLICY_TYPE_VERSION)).thenReturn(List.of(policy1)); assertSame(policy1, session.getPolicyType(type)); @@ -115,14 +114,14 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testGetPolicyType_NotFound() throws Exception { + void testGetPolicyType_NotFound() throws Exception { when(toscaService.getPolicyTypeList(any(), any())).thenReturn(Collections.emptyList()); assertNull(session.getPolicyType(type)); } @Test - public void testGetPolicyType_DaoEx() throws Exception { + void testGetPolicyType_DaoEx() throws Exception { PfModelException ex = new PfModelException(Status.INTERNAL_SERVER_ERROR, EXPECTED_EXCEPTION); when(toscaService.getPolicyTypeList(POLICY_TYPE, POLICY_TYPE_VERSION)).thenThrow(ex); @@ -130,9 +129,9 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testGetPolicy_NullVersion() throws Exception { + void testGetPolicy_NullVersion() throws Exception { ToscaPolicy policy1 = makePolicy(POLICY_NAME, POLICY_VERSION); - when(toscaService.getFilteredPolicyList(any())).thenReturn(Arrays.asList(policy1)); + when(toscaService.getFilteredPolicyList(any())).thenReturn(List.of(policy1)); ident.setVersion(null); assertSame(policy1, session.getPolicy(ident)); @@ -140,7 +139,7 @@ public class TestSessionData extends ProviderSuper { ToscaTypedEntityFilter<ToscaPolicy> filter = getPolicyFilter(); assertEquals(POLICY_NAME, filter.getName()); assertEquals(ToscaTypedEntityFilter.LATEST_VERSION, filter.getVersion()); - assertEquals(null, filter.getVersionPrefix()); + assertNull(filter.getVersionPrefix()); // retrieve a second time using full version - should use cache assertSame(policy1, session.getPolicy(new ToscaConceptIdentifierOptVersion(policy1.getIdentifier()))); @@ -148,9 +147,9 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testGetPolicy_MajorVersion() throws Exception { + void testGetPolicy_MajorVersion() throws Exception { ToscaPolicy policy1 = makePolicy(POLICY_NAME, POLICY_VERSION); - when(toscaService.getFilteredPolicyList(any())).thenReturn(Arrays.asList(policy1)); + when(toscaService.getFilteredPolicyList(any())).thenReturn(List.of(policy1)); ident.setVersion("1"); assertSame(policy1, session.getPolicy(ident)); @@ -166,9 +165,9 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testGetPolicy_MajorMinorVersion() throws Exception { + void testGetPolicy_MajorMinorVersion() throws Exception { ToscaPolicy policy1 = makePolicy(POLICY_NAME, POLICY_VERSION); - when(toscaService.getFilteredPolicyList(any())).thenReturn(Arrays.asList(policy1)); + when(toscaService.getFilteredPolicyList(any())).thenReturn(List.of(policy1)); ident.setVersion(POLICY_VERSION); assertSame(policy1, session.getPolicy(ident)); @@ -176,7 +175,7 @@ public class TestSessionData extends ProviderSuper { ToscaTypedEntityFilter<ToscaPolicy> filter = getPolicyFilter(); assertEquals(POLICY_NAME, filter.getName()); assertEquals(POLICY_VERSION, filter.getVersion()); - assertEquals(null, filter.getVersionPrefix()); + assertNull(filter.getVersionPrefix()); // retrieve a second time using full version - should use cache assertSame(policy1, session.getPolicy(new ToscaConceptIdentifierOptVersion(policy1.getIdentifier()))); @@ -184,14 +183,14 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testGetPolicy_NotFound() throws Exception { + void testGetPolicy_NotFound() throws Exception { when(toscaService.getFilteredPolicyList(any())).thenReturn(Collections.emptyList()); assertNull(session.getPolicy(ident)); } @Test - public void testGetPolicy_DaoEx() throws Exception { + void testGetPolicy_DaoEx() throws Exception { PfModelException ex = new PfModelException(Status.INTERNAL_SERVER_ERROR, EXPECTED_EXCEPTION); when(toscaService.getFilteredPolicyList(any())).thenThrow(ex); @@ -199,7 +198,7 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testIsVersionPrefix() { + void testIsVersionPrefix() { assertTrue(SessionData.isVersionPrefix("1")); assertTrue(SessionData.isVersionPrefix("12")); assertTrue(SessionData.isVersionPrefix("1.2")); @@ -213,7 +212,7 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testAddRequests_testGetPdpStateChanges_testGetPdpUpdates() { + void testAddRequests_testGetPdpStateChanges_testGetPdpUpdates() { // pre-load with a update and state-change for other PDPs PdpUpdate update2 = makeUpdate(PDP2); session.addUpdate(update2); @@ -262,15 +261,15 @@ public class TestSessionData extends ProviderSuper { assertSame(change3, pair.getRight()); // verify individual lists - List<PdpUpdate> updates = Arrays.asList(update, update2); + List<PdpUpdate> updates = List.of(update, update2); assertEquals(sort(updates, this::compare), sort(session.getPdpUpdates(), this::compare)); - List<PdpStateChange> changes = Arrays.asList(change, change3); + List<PdpStateChange> changes = List.of(change, change3); assertEquals(sort(changes, this::compare), sort(session.getPdpStateChanges(), this::compare)); } @Test - public void testAddRequests_MismatchedNames() { + void testAddRequests_MismatchedNames() { PdpUpdate update = makeUpdate(PDP1); PdpStateChange change = makeStateChange(PDP2); assertThatIllegalArgumentException().isThrownBy(() -> session.addRequests(update, change)) @@ -278,7 +277,7 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testAddUpdate_testGetPdpUpdates() { + void testAddUpdate_testGetPdpUpdates() { // several different updates, but one duplicate PdpUpdate update1 = makeUpdate(PDP1); session.addUpdate(update1); @@ -290,18 +289,18 @@ public class TestSessionData extends ProviderSuper { session.addUpdate(update3); List<PdpUpdate> lst = sort(getUpdateRequests(), this::compare); - assertEquals(Arrays.asList(update1, update2, update3).toString(), lst.toString()); + assertEquals(List.of(update1, update2, update3).toString(), lst.toString()); // overwrite one update2 = makeUpdate(PDP2); session.addUpdate(update2); lst = sort(getUpdateRequests(), this::compare); - assertEquals(Arrays.asList(update1, update2, update3).toString(), lst.toString()); + assertEquals(List.of(update1, update2, update3).toString(), lst.toString()); } @Test - public void testAddStateChange_testGetPdpStateChanges() { + void testAddStateChange_testGetPdpStateChanges() { // several different changes, but one duplicate PdpStateChange change1 = makeStateChange(PDP1); session.addStateChange(change1); @@ -313,14 +312,14 @@ public class TestSessionData extends ProviderSuper { session.addStateChange(change3); List<PdpStateChange> lst = sort(getStateChangeRequests(), this::compare); - assertEquals(Arrays.asList(change1, change2, change3).toString(), lst.toString()); + assertEquals(List.of(change1, change2, change3).toString(), lst.toString()); // overwrite one change2 = makeStateChange(PDP2); session.addStateChange(change2); lst = sort(getStateChangeRequests(), this::compare); - assertEquals(Arrays.asList(change1, change2, change3).toString(), lst.toString()); + assertEquals(List.of(change1, change2, change3).toString(), lst.toString()); } private ToscaPolicyType makePolicyType(String name, String version) { @@ -342,7 +341,7 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testCreate() throws Exception { + void testCreate() throws Exception { assertTrue(session.isUnchanged()); session.create(group1); @@ -361,17 +360,17 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testUpdate() throws Exception { + void testUpdate() { assertTrue(session.isUnchanged()); // force the groups into the cache - when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1, group2)); + when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(List.of(group1, group2)); session.getActivePdpGroupsByPolicyType(type); /* * try group 1 */ - when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1)); + when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(List.of(group1)); PdpGroup newgrp = new PdpGroup(group1); session.update(newgrp); assertFalse(session.isUnchanged()); @@ -384,7 +383,7 @@ public class TestSessionData extends ProviderSuper { /* * try group 2 */ - when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group2)); + when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(List.of(group2)); newgrp = new PdpGroup(group2); session.update(newgrp); assertFalse(session.isUnchanged()); @@ -396,16 +395,16 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testUpdate_NotInCache() throws Exception { - when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1)); + void testUpdate_NotInCache() { + when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(List.of(group1)); assertThatIllegalStateException().isThrownBy(() -> session.update(new PdpGroup(group1))) .withMessage("group not cached: groupA"); } @Test - public void testGetGroup() throws Exception { - when(pdpGroupService.getPdpGroups(GROUP_NAME)).thenReturn(Arrays.asList(group1)); + void testGetGroup() throws Exception { + when(pdpGroupService.getPdpGroups(GROUP_NAME)).thenReturn(List.of(group1)); assertSame(group1, session.getGroup(GROUP_NAME)); verify(pdpGroupService).getPdpGroups(any(String.class)); @@ -418,7 +417,7 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testGetGroup_NotFound() throws Exception { + void testGetGroup_NotFound() throws Exception { when(pdpGroupService.getPdpGroups(GROUP_NAME)).thenReturn(Collections.emptyList()); assertNull(session.getGroup(GROUP_NAME)); @@ -431,14 +430,14 @@ public class TestSessionData extends ProviderSuper { verify(pdpGroupService, times(2)).getPdpGroups(GROUP_NAME); // find it this time - when(pdpGroupService.getPdpGroups(GROUP_NAME)).thenReturn(Arrays.asList(group1)); + when(pdpGroupService.getPdpGroups(GROUP_NAME)).thenReturn(List.of(group1)); assertSame(group1, session.getGroup(GROUP_NAME)); verify(pdpGroupService, times(3)).getPdpGroups(GROUP_NAME); } @Test - public void testGetActivePdpGroupsByPolicyType() throws Exception { - List<PdpGroup> groups = Arrays.asList(group1, group2); + void testGetActivePdpGroupsByPolicyType() { + List<PdpGroup> groups = List.of(group1, group2); when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(groups); // repeat @@ -451,8 +450,8 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testAddGroup() throws Exception { - List<PdpGroup> groups = Arrays.asList(group1, group2); + void testAddGroup() { + List<PdpGroup> groups = List.of(group1, group2); when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(groups); // query by each type @@ -469,10 +468,10 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testUpdateDb() throws Exception { + void testUpdateDb() { // force the groups into the cache PdpGroup group3 = loadGroup("group3.json"); - when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1, group2, group3)); + when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(List.of(group1, group2, group3)); session.getActivePdpGroupsByPolicyType(type); // create groups 4 & 5 @@ -483,7 +482,7 @@ public class TestSessionData extends ProviderSuper { session.create(group5); // update group 1 - when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1)); + when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(List.of(group1)); PdpGroup newgrp1 = new PdpGroup(group1); session.update(newgrp1); @@ -492,12 +491,12 @@ public class TestSessionData extends ProviderSuper { session.update(newgrp1); // update group 3 - when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group3)); + when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(List.of(group3)); PdpGroup newgrp3 = new PdpGroup(group3); session.update(newgrp3); // update group 5 - when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group5)); + when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(List.of(group5)); PdpGroup newgrp5 = new PdpGroup(group5); session.update(newgrp5); @@ -520,9 +519,9 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testUpdateDb_Empty() throws Exception { + void testUpdateDb_Empty() { // force data into the cache - when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1, group2)); + when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(List.of(group1, group2)); session.getActivePdpGroupsByPolicyType(type); PolicyNotification notif = new PolicyNotification(); @@ -534,19 +533,19 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testDeleteGroupFromDb() throws Exception { + void testDeleteGroupFromDb() { session.deleteGroupFromDb(group1); verify(pdpGroupService).deletePdpGroup(group1.getName()); } @Test - public void testTrackDeploy() throws PfModelException { + void testTrackDeploy() throws PfModelException { testTrack(true); } @Test - public void testTrackUndeploy() throws PfModelException { + void testTrackUndeploy() throws PfModelException { testTrack(false); } @@ -566,10 +565,10 @@ public class TestSessionData extends ProviderSuper { policy.setType(POLICY_TYPE); policy.setTypeVersion(POLICY_TYPE_VERSION); - when(toscaService.getFilteredPolicyList(any())).thenReturn(Arrays.asList(policy)); + when(toscaService.getFilteredPolicyList(any())).thenReturn(List.of(policy)); ToscaConceptIdentifier policyId = new ToscaConceptIdentifier(POLICY_NAME, POLICY_VERSION); - List<String> pdps = Arrays.asList(PDP1, PDP2); + List<String> pdps = List.of(PDP1, PDP2); ToscaPolicy testPolicy = session.getPolicy(new ToscaConceptIdentifierOptVersion(policyId)); @@ -626,7 +625,7 @@ public class TestSessionData extends ProviderSuper { private <T> List<T> sort(Collection<T> collection, Comparator<T> comparator) { List<T> lst = new ArrayList<>(collection); - Collections.sort(lst, comparator); + lst.sort(comparator); return lst; } diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java index 2b339f82..1aa40a28 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019-2020, 2022 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2022-2023 Nordix Foundation. * Modifications Copyright (C) 2021-2023 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,7 +30,7 @@ import java.io.IOException; import java.util.List; import java.util.Optional; import lombok.Getter; -import org.junit.After; +import org.junit.jupiter.api.AfterEach; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; @@ -56,7 +56,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ActiveProfiles; import org.yaml.snakeyaml.Yaml; -@ActiveProfiles({ "test-e2e", "default" }) +@ActiveProfiles({"test-e2e", "default"}) public abstract class End2EndBase extends CommonPapRestServer { private static final Logger logger = LoggerFactory.getLogger(End2EndBase.class); @@ -99,7 +99,7 @@ public abstract class End2EndBase extends CommonPapRestServer { * Tears down. */ @Override - @After + @AfterEach public void tearDown() { if (context != null) { try { @@ -194,7 +194,7 @@ public abstract class End2EndBase extends CommonPapRestServer { * Loads an object from a YAML file. * * @param fileName name of the file from which to load - * @param clazz the class of the object to be loaded + * @param clazz the class of the object to be loaded * @return the object that was loaded from the file */ protected static <T> T loadYamlFile(final String fileName, final Class<T> clazz) { @@ -223,7 +223,7 @@ public abstract class End2EndBase extends CommonPapRestServer { * Loads an object from a JSON file. * * @param fileName name of the file from which to load - * @param clazz the class of the object to be loaded + * @param clazz the class of the object to be loaded * @return the object that was loaded from the file */ protected static <T> T loadJsonFile(final String fileName, final Class<T> clazz) { diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndContext.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndContext.java index c910a7b4..c0c98adc 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndContext.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndContext.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2022 Nordix Foundation. + * Modifications Copyright (C) 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,9 @@ package org.onap.policy.pap.main.rest.e2e; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.LinkedList; diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/HealthCheckTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/HealthCheckTest.java index 296a6609..d1c89b21 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/HealthCheckTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/HealthCheckTest.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2022 Nordix Foundation. + * Modifications Copyright (C) 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,19 +21,19 @@ package org.onap.policy.pap.main.rest.e2e; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import jakarta.ws.rs.client.Invocation; import java.net.HttpURLConnection; -import javax.ws.rs.client.Invocation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.endpoints.report.HealthCheckReport; -public class HealthCheckTest extends End2EndBase { +class HealthCheckTest extends End2EndBase { private static final String HEALTHCHECK_ENDPOINT = "healthcheck"; @Test - public void testHealthCheckSuccess() throws Exception { + void testHealthCheckSuccess() throws Exception { final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT); final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupCreateOrUpdateTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupCreateOrUpdateTest.java index 650dd41a..e7fc09c6 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupCreateOrUpdateTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupCreateOrUpdateTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP PAP * ================================================================================ - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019, 2023 Nordix Foundation. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,18 +21,18 @@ package org.onap.policy.pap.main.rest.e2e; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import java.util.Optional; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.models.pap.concepts.PdpGroupUpdateResponse; import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpGroups; @@ -40,7 +40,7 @@ import org.onap.policy.models.pdp.enums.PdpState; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class PdpGroupCreateOrUpdateTest extends End2EndBase { +class PdpGroupCreateOrUpdateTest extends End2EndBase { private static final Logger logger = LoggerFactory.getLogger(PdpGroupCreateOrUpdateTest.class); private static final String CREATEORUPDATE_GROUPS_ENDPOINT = "pdps/groups/batch"; @@ -52,7 +52,7 @@ public class PdpGroupCreateOrUpdateTest extends End2EndBase { * Sets up. */ @Override - @Before + @BeforeEach public void setUp() throws Exception { addToscaPolicyTypes("monitoring.policy-type.yaml"); super.setUp(); @@ -64,7 +64,7 @@ public class PdpGroupCreateOrUpdateTest extends End2EndBase { * Deletes the deployed group. */ @Override - @After + @AfterEach public void tearDown() { // delete the group that was inserted try { @@ -77,13 +77,13 @@ public class PdpGroupCreateOrUpdateTest extends End2EndBase { } @Test - public void testCreateGroupsJson() throws Exception { + void testCreateGroupsJson() throws Exception { createPdpGroups("createGroups.json", MediaType.APPLICATION_JSON); } @Test - public void testCreateGroupsYaml() throws Exception { + void testCreateGroupsYaml() throws Exception { createPdpGroups("createGroups.yaml", "application/yaml"); } diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java index 5e2ca38f..647a60e8 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021-2022 Nordix Foundation. + * Modifications Copyright (C) 2021-2023 Nordix Foundation. * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,18 +23,18 @@ package org.onap.policy.pap.main.rest.e2e; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.core.Response; import java.util.Collections; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.Response; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories; import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSink; import org.onap.policy.common.utils.coder.StandardCoder; @@ -46,7 +46,7 @@ import org.onap.policy.models.pdp.concepts.PdpStatus; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.pap.main.rest.PdpGroupDeployControllerV1; -public class PdpGroupDeleteTest extends End2EndBase { +class PdpGroupDeleteTest extends End2EndBase { private static final String DELETE_GROUP_ENDPOINT = "pdps/groups"; private static final String DELETE_POLICIES_ENDPOINT = "pdps/policies"; @@ -54,7 +54,7 @@ public class PdpGroupDeleteTest extends End2EndBase { * Sets up. */ @Override - @Before + @BeforeEach public void setUp() throws Exception { addToscaPolicyTypes("monitoring.policy-type.yaml"); addToscaPolicies("monitoring.policy.yaml"); @@ -64,7 +64,7 @@ public class PdpGroupDeleteTest extends End2EndBase { } @Test - public void testDeleteGroup() throws Exception { + void testDeleteGroup() throws Exception { addGroups("deleteGroup.json"); context.addPdp("pdpAA_1", "pdpTypeA"); @@ -95,7 +95,7 @@ public class PdpGroupDeleteTest extends End2EndBase { } @Test - public void testDeletePolicy() throws Exception { + void testDeletePolicy() throws Exception { addGroups("undeployPolicy.json"); PdpStatus status1 = new PdpStatus(); @@ -156,7 +156,7 @@ public class PdpGroupDeleteTest extends End2EndBase { } @Test - public void testDeletePolicyVersion() throws Exception { + void testDeletePolicyVersion() throws Exception { addGroups("undeployPolicyVersion.json"); PdpStatus status1 = new PdpStatus(); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java index f28ccd14..5bc8dd09 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021-2022 Nordix Foundation. + * Modifications Copyright (C) 2021-2023 Nordix Foundation. * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,20 +23,20 @@ package org.onap.policy.pap.main.rest.e2e; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import java.util.List; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories; import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSink; import org.onap.policy.common.utils.coder.StandardCoder; @@ -51,7 +51,7 @@ import org.onap.policy.models.pdp.enums.PdpState; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.pap.main.rest.PdpGroupDeployControllerV1; -public class PdpGroupDeployTest extends End2EndBase { +class PdpGroupDeployTest extends End2EndBase { private static final String DEPLOY_GROUP_ENDPOINT = "pdps/deployments/batch"; private static final String DEPLOY_POLICIES_ENDPOINT = "pdps/policies"; private static final String DEPLOY_SUBGROUP = "pdpTypeA"; @@ -60,7 +60,7 @@ public class PdpGroupDeployTest extends End2EndBase { * Sets up. */ @Override - @Before + @BeforeEach public void setUp() throws Exception { addToscaPolicyTypes("monitoring.policy-type.yaml"); addToscaPolicies("monitoring.policy.yaml"); @@ -70,7 +70,7 @@ public class PdpGroupDeployTest extends End2EndBase { } @Test - public void testUpdateGroupPolicies() throws Exception { + void testUpdateGroupPolicies() throws Exception { addGroups("deployGroups.json"); @@ -132,7 +132,7 @@ public class PdpGroupDeployTest extends End2EndBase { } @Test - public void testDeployPolicies() throws Exception { + void testDeployPolicies() throws Exception { addGroups("deployPolicies.json"); PdpStatus status11 = new PdpStatus(); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupQueryTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupQueryTest.java index d6472ce1..cf466c29 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupQueryTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupQueryTest.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,19 +22,19 @@ package org.onap.policy.pap.main.rest.e2e; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.core.Response; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.Response; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.models.pdp.concepts.Pdp; import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpGroups; @@ -43,7 +43,7 @@ import org.onap.policy.models.pdp.enums.PdpHealthStatus; import org.onap.policy.models.pdp.enums.PdpState; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -public class PdpGroupQueryTest extends End2EndBase { +class PdpGroupQueryTest extends End2EndBase { private static final String GROUP_ENDPOINT = "pdps"; /** @@ -52,7 +52,7 @@ public class PdpGroupQueryTest extends End2EndBase { * @throws Exception the exception */ @Override - @Before + @BeforeEach public void setUp() throws Exception { addToscaPolicyTypes("monitoring.policy-type.yaml"); @@ -63,7 +63,7 @@ public class PdpGroupQueryTest extends End2EndBase { } @Test - public void test() throws Exception { + void test() throws Exception { Invocation.Builder invocationBuilder = sendRequest(GROUP_ENDPOINT); Response rawresp = invocationBuilder.get(); PdpGroups resp = rawresp.readEntity(PdpGroups.class); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupStateChangeTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupStateChangeTest.java index 2fa7cfb4..63abc917 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupStateChangeTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupStateChangeTest.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,22 +22,22 @@ package org.onap.policy.pap.main.rest.e2e; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.core.Response; import java.util.Collections; import java.util.List; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.Response; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.models.pap.concepts.PdpGroupStateChangeResponse; import org.onap.policy.models.pdp.concepts.PdpStatus; import org.onap.policy.models.pdp.enums.PdpState; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -public class PdpGroupStateChangeTest extends End2EndBase { +class PdpGroupStateChangeTest extends End2EndBase { private static final String PDP1 = "pdpAA_1"; private static final String PDP2 = "pdpAA_2"; private static final String PDP3 = "pdpAB_1"; @@ -50,7 +50,7 @@ public class PdpGroupStateChangeTest extends End2EndBase { * Sets up. */ @Override - @Before + @BeforeEach public void setUp() throws Exception { addToscaPolicyTypes("monitoring.policy-type.yaml"); addToscaPolicies("monitoring.policy.yaml"); @@ -60,7 +60,7 @@ public class PdpGroupStateChangeTest extends End2EndBase { } @Test - public void testMakePassive() throws Exception { + void testMakePassive() throws Exception { addGroups("stateChangeGroupDeactivate.json"); ToscaConceptIdentifier policy = diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyAuditTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyAuditTest.java index b0a135d2..f036d552 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyAuditTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyAuditTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021-2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,15 +21,15 @@ package org.onap.policy.pap.main.rest.e2e; import static org.assertj.core.api.Assertions.assertThat; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.core.GenericType; +import jakarta.ws.rs.core.Response; import java.time.Instant; import java.util.ArrayList; import java.util.List; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.GenericType; -import javax.ws.rs.core.Response; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.pap.concepts.PolicyAudit; import org.onap.policy.models.pap.concepts.PolicyAudit.AuditAction; @@ -38,7 +39,7 @@ import org.onap.policy.pap.main.rest.PolicyAuditControllerV1; import org.onap.policy.pap.main.service.PolicyAuditService; import org.springframework.beans.factory.annotation.Autowired; -public class PolicyAuditTest extends End2EndBase { +class PolicyAuditTest extends End2EndBase { private static final String TEST_GROUP = "testGroup"; private static final String TEST_PDP_TYPE = "testPdpType"; private static final ToscaConceptIdentifier POLICY_A = new ToscaConceptIdentifier("PolicyA", "1.0.0"); @@ -49,8 +50,8 @@ public class PolicyAuditTest extends End2EndBase { private static final String QUERY_PARAMS_INVALID = "?recordCount=5&startTime=2021-07-25T01:25:15"; private static final String QUERY_PARAMS_CORRECT = "?recordCount=5&startTime=1627219515&endTime=1627478715"; private static final String QUERY_PARAMS_INCORRECT = "?recordCount=5&startTime=1627478715&endTime=1627565115"; - private static int NOT_FOUND_STATUS_CODE = 404; - private static int BAD_REQUEST_STATUS_CODE = 400; + private static final int NOT_FOUND_STATUS_CODE = 404; + private static final int BAD_REQUEST_STATUS_CODE = 400; private static final String BAD_REQUEST_MSG = "NumberFormatException For"; @Autowired @@ -60,7 +61,7 @@ public class PolicyAuditTest extends End2EndBase { private PolicyAuditRepository policyAuditRepository; @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); setupEnv(); @@ -70,7 +71,7 @@ public class PolicyAuditTest extends End2EndBase { * Teardown after tests. */ @Override - @After + @AfterEach public void tearDown() { policyAuditRepository.deleteAll(); super.tearDown(); @@ -96,13 +97,13 @@ public class PolicyAuditTest extends End2EndBase { } @Test - public void testGetAllAuditRecords() throws Exception { + void testGetAllAuditRecords() throws Exception { String uri = POLICY_AUDIT_ENDPOINT; sendAndValidateSuccess(uri, 2); } @Test - public void testGetAllAuditRecordsWithParams() throws Exception { + void testGetAllAuditRecordsWithParams() throws Exception { // try with correct dates in query, should result in 2 records String uri = POLICY_AUDIT_ENDPOINT + QUERY_PARAMS_CORRECT; sendAndValidateSuccess(uri, 2); @@ -117,13 +118,13 @@ public class PolicyAuditTest extends End2EndBase { } @Test - public void testGetAuditRecordsByGroup() throws Exception { + void testGetAuditRecordsByGroup() throws Exception { String uri = POLICY_AUDIT_ENDPOINT + URI_SEPERATOR + TEST_GROUP; sendAndValidateSuccess(uri, 2); } @Test - public void testGetAuditRecordsByGroupWithParams() throws Exception { + void testGetAuditRecordsByGroupWithParams() throws Exception { // try with correct dates in query, should result in 2 records String uri = POLICY_AUDIT_ENDPOINT + URI_SEPERATOR + TEST_GROUP + QUERY_PARAMS_CORRECT; sendAndValidateSuccess(uri, 2); @@ -138,14 +139,14 @@ public class PolicyAuditTest extends End2EndBase { } @Test - public void testGetAuditRecordsOfPolicyWithGroup() throws Exception { + void testGetAuditRecordsOfPolicyWithGroup() throws Exception { String uri = POLICY_AUDIT_ENDPOINT + URI_SEPERATOR + TEST_GROUP + URI_SEPERATOR + POLICY_A.getName() + URI_SEPERATOR + POLICY_A.getVersion(); sendAndValidateSuccess(uri, 1); } @Test - public void testGetAuditRecordsOfPolicyWithGroupWithParams() throws Exception { + void testGetAuditRecordsOfPolicyWithGroupWithParams() throws Exception { // try with correct dates in query, should result in 1 record String uri = POLICY_AUDIT_ENDPOINT + URI_SEPERATOR + TEST_GROUP + URI_SEPERATOR + POLICY_A.getName() + URI_SEPERATOR + POLICY_A.getVersion() + QUERY_PARAMS_CORRECT; @@ -163,13 +164,13 @@ public class PolicyAuditTest extends End2EndBase { } @Test - public void testGetAuditRecordsOfPolicyWithoutGroup() throws Exception { + void testGetAuditRecordsOfPolicyWithoutGroup() throws Exception { String uri = POLICY_AUDIT_ENDPOINT + URI_SEPERATOR + POLICY_A.getName() + URI_SEPERATOR + POLICY_A.getVersion(); sendAndValidateSuccess(uri, 1); } @Test - public void testGetAuditRecordsOfPolicyWithoutGroupWithParams() throws Exception { + void testGetAuditRecordsOfPolicyWithoutGroupWithParams() throws Exception { // try with correct dates in query, should result in 1 record String uri = POLICY_AUDIT_ENDPOINT + URI_SEPERATOR + POLICY_A.getName() + URI_SEPERATOR + POLICY_A.getVersion() + QUERY_PARAMS_CORRECT; diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java index 09c8a2ac..513fb62c 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2022 Nordix Foundation. + * Modifications Copyright (C) 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,20 +22,20 @@ package org.onap.policy.pap.main.rest.e2e; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.core.GenericType; +import jakarta.ws.rs.core.Response; import java.util.List; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.GenericType; -import javax.ws.rs.core.Response; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.models.pap.concepts.PolicyStatus; import org.onap.policy.models.pdp.concepts.PdpPolicyStatus; import org.onap.policy.models.pdp.concepts.PdpPolicyStatus.State; -public class PolicyStatusTest extends End2EndBase { +class PolicyStatusTest extends End2EndBase { private static final String POLICY_NAME = "onap.restart.tca"; private static final String POLICY_TYPE_NAME = "onap.policies.monitoring.cdap.tca.hi.lo.app"; private static final String VERSION = "1.0.0"; @@ -43,14 +43,14 @@ public class PolicyStatusTest extends End2EndBase { private static final String POLICY_DEPLOYMENT_STATUS_ENDPOINT = "policies/status"; @Override - @Before + @BeforeEach public void setUp() throws Exception { addPdpPolicyStatus("policyStatus.json"); super.setUp(); } @Test - public void testQueryAllDeployedPolicies() throws Exception { + void testQueryAllDeployedPolicies() throws Exception { Invocation.Builder invocationBuilder = sendRequest(POLICY_STATUS_ENDPOINT); Response rawresp = invocationBuilder.get(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); @@ -61,7 +61,7 @@ public class PolicyStatusTest extends End2EndBase { } @Test - public void testQueryDeployedPolicies() throws Exception { + void testQueryDeployedPolicies() throws Exception { String uri = POLICY_STATUS_ENDPOINT + "/onap.restart.tca"; Invocation.Builder invocationBuilder = sendRequest(uri); @@ -74,7 +74,7 @@ public class PolicyStatusTest extends End2EndBase { } @Test - public void testQueryDeployedPolicy() throws Exception { + void testQueryDeployedPolicy() throws Exception { String uri = POLICY_STATUS_ENDPOINT + "/onap.restart.tca/1.0.0"; Invocation.Builder invocationBuilder = sendRequest(uri); @@ -86,7 +86,7 @@ public class PolicyStatusTest extends End2EndBase { } @Test - public void testGetStatusOfAllDeployedPolicies() throws Exception { + void testGetStatusOfAllDeployedPolicies() throws Exception { Invocation.Builder invocationBuilder = sendRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT); Response rawresp = invocationBuilder.get(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); @@ -97,7 +97,7 @@ public class PolicyStatusTest extends End2EndBase { } @Test - public void testGetStatusOfDeployedPolicies() throws Exception { + void testGetStatusOfDeployedPolicies() throws Exception { String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/policyStatus/onap.restart.tca"; Invocation.Builder invocationBuilder = sendRequest(uri); @@ -110,7 +110,7 @@ public class PolicyStatusTest extends End2EndBase { } @Test - public void testGetStatusOfDeployedPolicy() throws Exception { + void testGetStatusOfDeployedPolicy() throws Exception { String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/policyStatus/onap.restart.tca/1.0.0"; Invocation.Builder invocationBuilder = sendRequest(uri); |