diff options
Diffstat (limited to 'main/src/test/java')
17 files changed, 335 insertions, 335 deletions
diff --git a/main/src/test/java/org/onap/policy/api/contract/ApiContractTest.java b/main/src/test/java/org/onap/policy/api/contract/ApiContractTest.java index 3b90a106..08cb7f18 100644 --- a/main/src/test/java/org/onap/policy/api/contract/ApiContractTest.java +++ b/main/src/test/java/org/onap/policy/api/contract/ApiContractTest.java @@ -23,11 +23,10 @@ package org.onap.policy.api.contract; import static org.junit.Assert.assertEquals; +import jakarta.ws.rs.core.Response; import java.io.IOException; -import javax.ws.rs.core.Response; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.onap.policy.api.main.PolicyApiApplication; import org.onap.policy.api.main.rest.utils.CommonTestRestController; import org.onap.policy.common.utils.security.SelfSignedKeyStore; @@ -38,25 +37,22 @@ import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest(classes = PolicyApiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ActiveProfiles({ "test", "stub" }) +@ActiveProfiles({"test", "stub"}) @DirtiesContext(classMode = ClassMode.AFTER_CLASS) -public class ApiContractTest extends CommonTestRestController { +class ApiContractTest extends CommonTestRestController { protected static final String APP_JSON = "application/json"; protected static final String APP_YAML = "application/yaml"; private static final String TOSCA_NODE_TEMPLATE_RESOURCE = - "nodetemplates/nodetemplates.metadatasets.input.tosca.json"; + "nodetemplates/nodetemplates.metadatasets.input.tosca.json"; @LocalServerPort private int apiPort; private static SelfSignedKeyStore keystore; - - @BeforeClass + @BeforeAll public static void setupParameters() throws IOException, InterruptedException { keystore = new SelfSignedKeyStore(); } @@ -72,20 +68,20 @@ public class ApiContractTest extends CommonTestRestController { } @Test - public void testStubPolicyDesign() throws Exception { + void testStubPolicyDesign() throws Exception { checkStubJsonGet("policies"); checkStubJsonGet("policies/policyname/versions/1.0.2"); checkStubJsonGet("policytypes"); checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16"); checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/latest"); - checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0/"); + checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0"); checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0/policies"); checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0/policies/" + "9c65fa1f-2833-4076-a64d-5b62e35cd09b"); checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0/policies/" - + "9c65fa1f-2833-4076-a64d-5b62e35cd09b/versions/latest"); + + "9c65fa1f-2833-4076-a64d-5b62e35cd09b/versions/latest"); checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0/policies/" - + "9c65fa1f-2833-4076-a64d-5b62e35cd09b/versions/1.2.3"); + + "9c65fa1f-2833-4076-a64d-5b62e35cd09b/versions/1.2.3"); checkStubJsonGet("healthcheck"); checkStubJsonPost("policies"); @@ -95,11 +91,11 @@ public class ApiContractTest extends CommonTestRestController { checkStubJsonDelete("policies/policyname/versions/1.0.2"); checkStubJsonDelete("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0"); checkStubJsonDelete("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0/policies/" - + "9c65fa1f-2833-4076-a64d-5b62e35cd09b/versions/1.2.3"); + + "9c65fa1f-2833-4076-a64d-5b62e35cd09b/versions/1.2.3"); } @Test - public void testStubNodeTemplateDesign() throws Exception { + void testStubNodeTemplateDesign() throws Exception { checkStubJsonGet("nodetemplates"); checkStubJsonGet("nodetemplates/k8stemplate/versions/1.0.0"); @@ -111,7 +107,7 @@ public class ApiContractTest extends CommonTestRestController { } @Test - public void testErrors() throws Exception { + void testErrors() throws Exception { var responseYaml = super.readResource("policies", APP_YAML, apiPort); assertEquals(Response.Status.NOT_IMPLEMENTED.getStatusCode(), responseYaml.getStatus()); diff --git a/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiException.java b/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiException.java index 1212517c..47ca230d 100644 --- a/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiException.java +++ b/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiException.java @@ -3,6 +3,7 @@ * ONAP Policy API * ================================================================================ * 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. @@ -22,15 +23,14 @@ package org.onap.policy.api.main.exception; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.test.ExceptionsTester; -public class TestPolicyApiException { +class TestPolicyApiException { @Test - public void test() { - assertEquals(3, new ExceptionsTester().test(PolicyApiException.class)); + void test() { + Assertions.assertEquals(3, new ExceptionsTester().test(PolicyApiException.class)); } } diff --git a/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiRuntimeException.java b/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiRuntimeException.java index 3e78ab2b..9fa735bc 100644 --- a/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiRuntimeException.java +++ b/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiRuntimeException.java @@ -3,6 +3,7 @@ * ONAP Policy API * ================================================================================ * 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. @@ -22,15 +23,14 @@ package org.onap.policy.api.main.exception; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.test.ExceptionsTester; -public class TestPolicyApiRuntimeException { +class TestPolicyApiRuntimeException { @Test - public void test() { - assertEquals(2, new ExceptionsTester().test(PolicyApiRuntimeException.class)); + void test() { + Assertions.assertEquals(2, new ExceptionsTester().test(PolicyApiRuntimeException.class)); } } diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java index 7442a8cc..4bcd86ca 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019-2020,2022-2023 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2022-2023 Nordix Foundation. * Modifications Copyright (C) 2020-2023 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,21 +24,20 @@ package org.onap.policy.api.main.rest; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.Response.Status; import java.io.File; import java.io.IOException; import java.util.List; import java.util.Map; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.onap.policy.api.main.PolicyApiApplication; import org.onap.policy.api.main.rest.utils.CommonTestRestController; import org.onap.policy.common.endpoints.report.HealthCheckReport; @@ -56,18 +55,16 @@ import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; -import org.springframework.test.context.junit4.SpringRunner; /** * Class to perform unit test of {@link ApiRestController}. * * @author Chenfei Gao (cgao@research.att.com) */ -@RunWith(SpringRunner.class) @SpringBootTest(classes = PolicyApiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles({ "test", "default" }) @DirtiesContext(classMode = ClassMode.AFTER_CLASS) -public class TestApiRestServer extends CommonTestRestController { +class TestApiRestServer extends CommonTestRestController { private static final String ALIVE = "alive"; private static final String SELF = NetworkUtil.getHostname(); @@ -161,8 +158,8 @@ public class TestApiRestServer extends CommonTestRestController { * @throws IOException on I/O exceptions * @throws InterruptedException if interrupted */ - @BeforeClass - public static void setupParameters() throws IOException, InterruptedException { + @BeforeAll + static void setupParameters() throws IOException, InterruptedException { keystore = new SelfSignedKeyStore(); } @@ -177,12 +174,12 @@ public class TestApiRestServer extends CommonTestRestController { } @Test - public void testSwagger() throws Exception { + void testSwagger() throws Exception { super.testSwagger(apiPort); } @Test - public void testCreatePolicyTypes() throws Exception { + void testCreatePolicyTypes() throws Exception { for (String resrcName : TOSCA_POLICYTYPE_RESOURCE_NAMES) { Response rawResponse = createResource(POLICYTYPES, resrcName, apiPort); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); @@ -204,7 +201,7 @@ public class TestApiRestServer extends CommonTestRestController { } @Test - public void testCreatePolicies() throws Exception { + void testCreatePolicies() throws Exception { for (String resrcName : TOSCA_POLICY_RESOURCE_NAMES) { Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, apiPort); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); @@ -229,7 +226,7 @@ public class TestApiRestServer extends CommonTestRestController { } @Test - public void testSimpleCreatePolicies() throws Exception { + void testSimpleCreatePolicies() throws Exception { for (String resrcName : TOSCA_POLICIES_RESOURCE_NAMES) { Response rawResponse = createResource(POLICIES, resrcName, apiPort); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); @@ -255,7 +252,7 @@ public class TestApiRestServer extends CommonTestRestController { @SuppressWarnings("unchecked") @Test - public void testToscaCompliantOpDroolsPolicies() throws Exception { + void testToscaCompliantOpDroolsPolicies() throws Exception { Response rawResponse = createResource(POLICYTYPES, TOSCA_POLICYTYPE_OP_RESOURCE, apiPort); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); @@ -306,29 +303,29 @@ public class TestApiRestServer extends CommonTestRestController { } @Test - public void testHealthCheckSuccessJson() throws Exception { + void testHealthCheckSuccessJson() throws Exception { testHealthCheckSuccess(APP_JSON); } @Test - public void testHealthCheckSuccessYaml() throws Exception { + void testHealthCheckSuccessYaml() throws Exception { testHealthCheckSuccess(APP_YAML); } private void testHealthCheckSuccess(String mediaType) throws Exception { final Invocation.Builder invocationBuilder = sendHttpsRequest( - CONTEXT_PATH, HEALTHCHECK_ENDPOINT, mediaType, apiPort); + HEALTHCHECK_ENDPOINT, mediaType, apiPort); final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class); validateHealthCheckReport(NAME, SELF, true, 200, ALIVE, report); } @Test - public void testReadPolicyTypesJson() throws Exception { + void testReadPolicyTypesJson() throws Exception { testReadPolicyTypes(APP_JSON); } @Test - public void testReadPolicyTypesYaml() throws Exception { + void testReadPolicyTypesYaml() throws Exception { testReadPolicyTypes(APP_YAML); } @@ -379,12 +376,12 @@ public class TestApiRestServer extends CommonTestRestController { } @Test - public void testDeletePolicyTypeJson() throws Exception { + void testDeletePolicyTypeJson() throws Exception { testDeletePolicyType(APP_JSON); } @Test - public void testDeletePolicyTypeYaml() throws Exception { + void testDeletePolicyTypeYaml() throws Exception { testDeletePolicyType(APP_YAML); } @@ -410,12 +407,12 @@ public class TestApiRestServer extends CommonTestRestController { } @Test - public void testReadPoliciesJson() throws Exception { + void testReadPoliciesJson() throws Exception { testReadPolicies(APP_JSON); } @Test - public void testReadPoliciesYaml() throws Exception { + void testReadPoliciesYaml() throws Exception { testReadPolicies(APP_YAML); } @@ -443,7 +440,7 @@ public class TestApiRestServer extends CommonTestRestController { } @Test - public void testNamingPolicyGet() throws Exception { + void testNamingPolicyGet() throws Exception { Response rawResponse = readResource("policytypes/onap.policies.Naming/versions/1.0.0/" + "policies/SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP/versions/1.0.0", APP_JSON, apiPort); @@ -507,12 +504,12 @@ public class TestApiRestServer extends CommonTestRestController { } @Test - public void testDeletePoliciesJson() throws Exception { + void testDeletePoliciesJson() throws Exception { testDeletePolicies(APP_JSON); } @Test - public void testDeletePoliciesYaml() throws Exception { + void testDeletePoliciesYaml() throws Exception { testDeletePolicies(APP_YAML); } @@ -524,12 +521,12 @@ public class TestApiRestServer extends CommonTestRestController { } @Test - public void testDeletePolicyVersionJson() throws Exception { + void testDeletePolicyVersionJson() throws Exception { testDeletePolicyVersion(APP_JSON); } @Test - public void testDeletePolicyVersionYaml() throws Exception { + void testDeletePolicyVersionYaml() throws Exception { testDeletePolicyVersion(APP_YAML); } @@ -565,12 +562,12 @@ public class TestApiRestServer extends CommonTestRestController { } @Test - public void testGetAllVersionOfPolicyJson() throws Exception { + void testGetAllVersionOfPolicyJson() throws Exception { testGetAllVersionOfPolicy(APP_JSON); } @Test - public void testGetAllVersionOfPolicyYaml() throws Exception { + void testGetAllVersionOfPolicyYaml() throws Exception { testGetAllVersionOfPolicy(APP_YAML); } @@ -591,12 +588,12 @@ public class TestApiRestServer extends CommonTestRestController { } @Test - public void testGetPoliciesJson() throws Exception { + void testGetPoliciesJson() throws Exception { getPolicies(APP_JSON); } @Test - public void testGetPoliciesYaml() throws Exception { + void testGetPoliciesYaml() throws Exception { getPolicies(APP_YAML); } @@ -619,12 +616,12 @@ public class TestApiRestServer extends CommonTestRestController { } @Test - public void testGetSpecificPolicyJson() throws Exception { + void testGetSpecificPolicyJson() throws Exception { getSpecificPolicy(APP_JSON); } @Test - public void testGetSpecificPolicyYaml() throws Exception { + void testGetSpecificPolicyYaml() throws Exception { getSpecificPolicy(APP_YAML); } @@ -647,7 +644,7 @@ public class TestApiRestServer extends CommonTestRestController { } @Test - public void testDeleteSpecificPolicy() throws Exception { + void testDeleteSpecificPolicy() throws Exception { Response rawResponse; for (String resrcName : TOSCA_POLICYTYPE_RESOURCE_NAMES) { rawResponse = createResource(POLICYTYPES, resrcName, apiPort); diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java b/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java index 2213bbf9..bf1d49be 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java @@ -3,7 +3,7 @@ * ONAP Policy API * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications 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"); @@ -24,31 +24,29 @@ package org.onap.policy.api.main.rest; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - import java.util.UUID; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.springframework.http.ResponseEntity; /** * Class to perform unit testing of CommonRestController. */ -public class TestCommonRestController { - private CommonRestController crc = new CommonRestController(); +class TestCommonRestController { + private final CommonRestController crc = new CommonRestController(); @Test - public void testAddLoggingHeaders() { + void testAddLoggingHeaders() { UUID requestId = UUID.randomUUID(); ResponseEntity<Void> rb = crc.makeOkResponse(requestId, null); - assertEquals(requestId.toString(), rb.getHeaders().getFirst("X-ONAP-RequestID")); + Assertions.assertEquals(requestId.toString(), rb.getHeaders().getFirst("X-ONAP-RequestID")); } /* * Tests null response for null object */ @Test - public void testToJsonNull() { - assertNull(crc.toJson(null)); + void testToJsonNull() { + Assertions.assertNull(crc.toJson(null)); } }
\ No newline at end of file diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestNodeTemplateController.java b/main/src/test/java/org/onap/policy/api/main/rest/TestNodeTemplateController.java index c36fea17..8dd0d731 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/TestNodeTemplateController.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/TestNodeTemplateController.java @@ -23,18 +23,17 @@ package org.onap.policy.api.main.rest; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import jakarta.ws.rs.core.GenericType; +import jakarta.ws.rs.core.Response; import java.io.IOException; import java.util.List; -import javax.ws.rs.core.GenericType; -import javax.ws.rs.core.Response; -import org.junit.After; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.onap.policy.api.main.PolicyApiApplication; import org.onap.policy.api.main.rest.utils.CommonTestRestController; import org.onap.policy.api.main.service.ToscaServiceTemplateService; @@ -49,13 +48,11 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; -import org.springframework.test.context.junit4.SpringRunner; /** * Class to perform unit test of {@link NodeTemplateController}. * */ -@RunWith(SpringRunner.class) @SpringBootTest(classes = PolicyApiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles({ "test", "default" }) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @@ -92,7 +89,7 @@ public class TestNodeTemplateController extends CommonTestRestController { * @throws IOException on I/O exceptions * @throws InterruptedException if interrupted */ - @BeforeClass + @BeforeAll public static void setupParameters() throws IOException, InterruptedException { keystore = new SelfSignedKeyStore(); } @@ -101,7 +98,7 @@ public class TestNodeTemplateController extends CommonTestRestController { * Clean up the database. * */ - @After + @AfterEach public void clearDb() { for (String name : nodeTemplateKeys) { try { @@ -124,7 +121,7 @@ public class TestNodeTemplateController extends CommonTestRestController { @Test - public void testCreateToscaNodeTemplates() throws Exception { + void testCreateToscaNodeTemplates() throws Exception { Response rawResponse = createResource(NODE_TEMPLATES, TOSCA_NODE_TEMPLATE_RESOURCE, apiPort); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class); @@ -147,7 +144,7 @@ public class TestNodeTemplateController extends CommonTestRestController { @Test - public void testReadNodeTemplates() throws Exception { + void testReadNodeTemplates() throws Exception { Response rawResponse = readResource(NODE_TEMPLATES, APP_JSON, apiPort); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); List<?> nodeTemplates = rawResponse.readEntity(List.class); @@ -172,7 +169,7 @@ public class TestNodeTemplateController extends CommonTestRestController { } @Test - public void testUpdateNodeTemplates() throws Exception { + void testUpdateNodeTemplates() throws Exception { createResource(NODE_TEMPLATES, TOSCA_NODE_TEMPLATE_RESOURCE, apiPort); Response rawResponse = updateResource(NODE_TEMPLATES, TOSCA_UPDATE_NODE_TEMPLATES, APP_JSON, apiPort); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); @@ -197,7 +194,7 @@ public class TestNodeTemplateController extends CommonTestRestController { } @Test - public void testDeleteNodeTemplates() throws Exception { + void testDeleteNodeTemplates() throws Exception { createResource(NODE_TEMPLATES, TOSCA_NODE_TEMPLATE_RESOURCE, apiPort); Response rawResponse = deleteResource(SPECIFIC_NODE_TEMPLATE, APP_JSON, apiPort); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); diff --git a/main/src/test/java/org/onap/policy/api/main/rest/aaf/TestAafApiFilter.java b/main/src/test/java/org/onap/policy/api/main/rest/aaf/TestAafApiFilter.java index 18526971..7246cddd 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/aaf/TestAafApiFilter.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/aaf/TestAafApiFilter.java @@ -3,6 +3,7 @@ * ONAP Policy API * ================================================================================ * 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. @@ -22,15 +23,14 @@ package org.onap.policy.api.main.rest.aaf; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -import org.junit.Test; - -public class TestAafApiFilter { - private AafApiFilter aafApiFilter = new AafApiFilter(); +class TestAafApiFilter { + private final AafApiFilter aafApiFilter = new AafApiFilter(); @Test - public void testGetPermissionTypeRoot() { - assertEquals("org.onap.policy.policy-api", aafApiFilter.getPermissionTypeRoot()); + void testGetPermissionTypeRoot() { + Assertions.assertEquals("org.onap.policy.policy-api", aafApiFilter.getPermissionTypeRoot()); } } diff --git a/main/src/test/java/org/onap/policy/api/main/rest/utils/CommonTestRestController.java b/main/src/test/java/org/onap/policy/api/main/rest/utils/CommonTestRestController.java index 947ed6a5..8e9bf70d 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/utils/CommonTestRestController.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/utils/CommonTestRestController.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy API * ================================================================================ - * Copyright (C) 2022 Nordix Foundation. All rights reserved. + * Copyright (C) 2022-2023 Nordix Foundation. 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. @@ -22,19 +22,18 @@ package org.onap.policy.api.main.rest.utils; -import static org.junit.Assert.assertTrue; - +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.Response; import java.security.SecureRandom; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Response; import org.glassfish.jersey.client.ClientProperties; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import org.junit.jupiter.api.Assertions; import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler; import org.onap.policy.common.gson.GsonMessageBodyHandler; import org.onap.policy.common.utils.coder.CoderException; @@ -46,7 +45,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; /** * Util class to perform REST unit tests. - * */ public class CommonTestRestController { @@ -60,9 +58,10 @@ public class CommonTestRestController { protected static final String CONTEXT_PATH = "/policy/api/v1/"; protected void testSwagger(final int apiPort) throws Exception { - final Invocation.Builder invocationBuilder = sendHttpsRequest(CONTEXT_PATH, "v3/api-docs", APP_JSON, apiPort); + final Invocation.Builder invocationBuilder = sendHttpsRequest("v3/api-docs", APP_JSON, apiPort); final String resp = invocationBuilder.get(String.class); - assertTrue((resp).contains("{\"openapi\":\"3.0.1\",\"info\":{\"title\":\"Policy Framework Lifecycle API\"")); + Assertions.assertTrue( + (resp).contains("{\"openapi\":\"3.0.1\",\"info\":{\"title\":\"Policy Framework Lifecycle API\"")); } protected Response createResource(String endpoint, String resourceName, int apiPort) @@ -70,10 +69,10 @@ public class CommonTestRestController { ToscaServiceTemplate rawServiceTemplate = getRawServiceTemplate(resourceName); String mediaType = getMediaType(resourceName); - mediaType = mediaType == null ? APP_JSON : mediaType; + mediaType = mediaType == null ? APP_JSON : mediaType; final Invocation.Builder invocationBuilder; - invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort); + invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort); Entity<ToscaServiceTemplate> entity = Entity.entity(rawServiceTemplate, mediaType); return invocationBuilder.post(entity); } @@ -81,14 +80,14 @@ public class CommonTestRestController { protected Response readResource(String endpoint, String mediaType, int apiPort) throws Exception { final Invocation.Builder invocationBuilder; - invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort); + invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort); return invocationBuilder.get(); } protected Response deleteResource(String endpoint, String mediaType, int apiPort) throws Exception { final Invocation.Builder invocationBuilder; - invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort); + invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort); return invocationBuilder.delete(); } @@ -98,7 +97,7 @@ public class CommonTestRestController { ToscaServiceTemplate rawServiceTemplate = getRawServiceTemplate(resourceName); final Invocation.Builder invocationBuilder; - invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort); + invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort); Entity<ToscaServiceTemplate> entity = Entity.entity(rawServiceTemplate, mediaType); return invocationBuilder.put(entity); } @@ -112,7 +111,7 @@ public class CommonTestRestController { } protected Invocation.Builder sendHttpsRequest( - final String context, final String endpoint, String mediaType, int apiPort) throws Exception { + final String endpoint, String mediaType, int apiPort) throws Exception { final TrustManager[] noopTrustManager = NetworkUtil.getAlwaysTrustingManager(); @@ -131,7 +130,7 @@ public class CommonTestRestController { client.register(YamlMessageBodyHandler.class); } - final WebTarget webTarget = client.target(HTTPS_PREFIX + apiPort + context + endpoint); + final WebTarget webTarget = client.target(HTTPS_PREFIX + apiPort + CONTEXT_PATH + endpoint); final Invocation.Builder invocationBuilder = webTarget.request(mediaType); @@ -148,7 +147,7 @@ public class CommonTestRestController { } else if (APP_YAML.equals(getMediaType(resourceName))) { rawServiceTemplate = decodeYaml(resourceName); } - return rawServiceTemplate; + return rawServiceTemplate; } private String getMediaType(String resourceName) { diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestCommonToscaServiceTemplateService.java b/main/src/test/java/org/onap/policy/api/main/service/TestCommonToscaServiceTemplateService.java index 4af30937..5c92bad1 100644 --- a/main/src/test/java/org/onap/policy/api/main/service/TestCommonToscaServiceTemplateService.java +++ b/main/src/test/java/org/onap/policy/api/main/service/TestCommonToscaServiceTemplateService.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022 Bell Canada. All rights reserved. + * Copyright (C) 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. @@ -21,9 +22,11 @@ package org.onap.policy.api.main.service; import java.util.Optional; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; import org.onap.policy.api.main.repository.ToscaServiceTemplateRepository; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -50,17 +53,20 @@ public class TestCommonToscaServiceTemplateService { @Mock protected NodeTemplateService nodeTemplateService; + AutoCloseable autoCloseable; + /** - * Setup the DB TOSCA service template object post create, and delete request. - * @param dbSvcTemplate ToscaServiceTemplate object to update + * Set up the DB TOSCA service template object post create, and delete request. + * + * @param dbSvcTemplate ToscaServiceTemplate object to update * @param svcTemplateFragment the CRUD operation response ToscaServiceTemplate object - * @param operation the CRUD operation performed + * @param operation the CRUD operation performed */ protected void mockDbServiceTemplate(ToscaServiceTemplate dbSvcTemplate, ToscaServiceTemplate svcTemplateFragment, - TestToscaServiceTemplateServiceForPolicyCrud.Operation operation) { + TestToscaServiceTemplateServiceForPolicyCrud.Operation operation) { if (operation != null) { switch (operation) { - case CREATE_POLICY_TYPE: + case CREATE_POLICY_TYPE -> { dbSvcTemplate.getPolicyTypes().putAll(svcTemplateFragment.getPolicyTypes()); if (svcTemplateFragment.getDataTypes() != null) { if (dbSvcTemplate.getDataTypes() == null) { @@ -69,18 +75,14 @@ public class TestCommonToscaServiceTemplateService { dbSvcTemplate.getDataTypes().putAll(svcTemplateFragment.getDataTypes()); } } - break; - case DELETE_POLICY_TYPE: + } + case DELETE_POLICY_TYPE -> dbSvcTemplate.getPolicyTypes().keySet().removeAll(svcTemplateFragment.getPolicyTypes().keySet()); - break; - case CREATE_POLICY: + case CREATE_POLICY -> dbSvcTemplate.setToscaTopologyTemplate(svcTemplateFragment.getToscaTopologyTemplate()); - break; - case DELETE_POLICY: - dbSvcTemplate.getToscaTopologyTemplate().setPolicies(null); - break; - default: - break; + case DELETE_POLICY -> dbSvcTemplate.getToscaTopologyTemplate().setPolicies(null); + default -> { + } } } Mockito.when(toscaServiceTemplateRepository.findById(new PfConceptKey(JpaToscaServiceTemplate.DEFAULT_NAME, @@ -91,9 +93,15 @@ public class TestCommonToscaServiceTemplateService { /** * Setup to return empty DB service template. */ - @Before + @BeforeEach public void setUp() { + autoCloseable = MockitoAnnotations.openMocks(this); Mockito.when(toscaServiceTemplateRepository.findById(new PfConceptKey(JpaToscaServiceTemplate.DEFAULT_NAME, JpaToscaServiceTemplate.DEFAULT_VERSION))).thenReturn(Optional.of(new JpaToscaServiceTemplate())); } + + @AfterEach + public void tearDown() throws Exception { + autoCloseable.close(); + } }
\ No newline at end of file diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java b/main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java index 7d85eef2..265f5271 100644 --- a/main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java +++ b/main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy API * ================================================================================ - * Copyright (C) 2022 Nordix Foundation. All rights reserved. + * Copyright (C) 2022-2023 Nordix Foundation. 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. @@ -27,13 +27,13 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import java.util.Optional; -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.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.MockitoAnnotations; import org.onap.policy.api.main.repository.NodeTemplateRepository; import org.onap.policy.api.main.repository.NodeTypeRepository; import org.onap.policy.common.utils.coder.CoderException; @@ -41,14 +41,12 @@ import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; -@RunWith(MockitoJUnitRunner.class) -public class TestNodeTemplateService { +class TestNodeTemplateService { @Mock private NodeTemplateRepository nodeTemplateRepository; @@ -63,17 +61,20 @@ public class TestNodeTemplateService { private static final String UPDATED_NODE_TEMPLATE_JSON = "nodetemplates/nodetemplates.metadatasets.update.json"; private static ToscaServiceTemplate updatedToscaServiceTemplate; - private StandardCoder standardCoder; - private YamlJsonTranslator yamlJsonTranslator = new YamlJsonTranslator(); + private final YamlJsonTranslator yamlJsonTranslator = new YamlJsonTranslator(); ToscaServiceTemplate policyServiceTemplate; + AutoCloseable closeable; + /** * Set up for tests. + * * @throws CoderException if error in json parsing */ - @Before + @BeforeEach public void setUp() throws CoderException { - standardCoder = new StandardCoder(); + closeable = MockitoAnnotations.openMocks(this); + StandardCoder standardCoder = new StandardCoder(); policyServiceTemplate = yamlJsonTranslator.fromYaml(ResourceUtils.getResourceAsString(POLICY_WITH_METADATA_SET_REF), ToscaServiceTemplate.class); @@ -82,11 +83,15 @@ public class TestNodeTemplateService { ToscaServiceTemplate.class); } + @AfterEach + void tearDown() throws Exception { + closeable.close(); + } + @Test - public void testVerifyNodeType() { - assertThatThrownBy(() -> { - nodeTemplateService.verifyNodeTypeInDbTemplate(new JpaToscaNodeTemplate()); - }).hasMessageMatching("^NODE_TYPE .* for toscaNodeTemplate .* does not exist$"); + void testVerifyNodeType() { + assertThatThrownBy(() -> nodeTemplateService.verifyNodeTypeInDbTemplate(new JpaToscaNodeTemplate())) + .hasMessageMatching("^NODE_TYPE .* for toscaNodeTemplate .* does not exist$"); JpaToscaNodeTemplate jpaToscaNodeTemplate = new JpaToscaNodeTemplate(); PfConceptKey nodeType = new PfConceptKey("dummyType", "1.0.0"); @@ -97,19 +102,19 @@ public class TestNodeTemplateService { } @Test - public void testNodeTemplateUsedInPolicy() { + void testNodeTemplateUsedInPolicy() { assertDoesNotThrow(() -> nodeTemplateService.assertNodeTemplateNotUsedInPolicy("dummyName", "1.0.0", new JpaToscaServiceTemplate(policyServiceTemplate))); - assertThatThrownBy(() -> { - nodeTemplateService.assertNodeTemplateNotUsedInPolicy("apexMetadata_decisionMaker", "1.0.0", - new JpaToscaServiceTemplate(policyServiceTemplate)); - }).hasMessage("Node template is in use, it is referenced in Tosca Policy operational.apex.decisionMaker " - + "version 1.0.0"); + assertThatThrownBy(() -> nodeTemplateService + .assertNodeTemplateNotUsedInPolicy("apexMetadata_decisionMaker", "1.0.0", + new JpaToscaServiceTemplate(policyServiceTemplate))) + .hasMessage("Node template is in use, it is referenced in Tosca Policy operational.apex.decisionMaker " + + "version 1.0.0"); } @Test - public void testNodeTemplateUpdate() throws PfModelException { + void testNodeTemplateUpdate() { Mockito.when(nodeTypeRepository.findById(Mockito.any())).thenReturn(Optional.of(new JpaToscaNodeType())); Mockito.when(nodeTemplateRepository.findById(Mockito.any())).thenReturn(Optional.of( diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestPdpGroupService.java b/main/src/test/java/org/onap/policy/api/main/service/TestPdpGroupService.java index 4c04a08e..d46592fc 100644 --- a/main/src/test/java/org/onap/policy/api/main/service/TestPdpGroupService.java +++ b/main/src/test/java/org/onap/policy/api/main/service/TestPdpGroupService.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022 Bell Canada. All rights reserved. + * Copyright (C) 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. @@ -26,12 +27,12 @@ import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.List; -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.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.MockitoAnnotations; import org.onap.policy.api.main.repository.PdpGroupRepository; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -39,8 +40,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.pdp.concepts.PdpGroups; import org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup; -@RunWith(MockitoJUnitRunner.class) -public class TestPdpGroupService { +class TestPdpGroupService { @Mock private PdpGroupRepository pdpGroupRepository; @@ -48,12 +48,16 @@ public class TestPdpGroupService { @InjectMocks private PdpGroupService pdpGroupService; + AutoCloseable closeable; + /** * Test setup. + * * @throws CoderException decode errors */ - @Before + @BeforeEach public void setUp() throws CoderException { + closeable = MockitoAnnotations.openMocks(this); var pdpGroups = new StandardCoder().decode(ResourceUtils.getResourceAsString("pdpgroups/PdpGroups.json"), PdpGroups.class).getGroups(); List<JpaPdpGroup> jpaPdpGroupList = new ArrayList<>(); @@ -62,8 +66,13 @@ public class TestPdpGroupService { when(pdpGroupRepository.findAll()).thenReturn(jpaPdpGroupList); } + @AfterEach + void tearDown() throws Exception { + closeable.close(); + } + @Test - public void testAssertPolicyTypeNotSupportedInPdpGroup() { + void testAssertPolicyTypeNotSupportedInPdpGroup() { assertThatCode(() -> pdpGroupService.assertPolicyTypeNotSupportedInPdpGroup("policy_type_not_supported", "1.0.0")).doesNotThrowAnyException(); @@ -73,7 +82,7 @@ public class TestPdpGroupService { } @Test - public void testAssertPolicyNotDeployedInPdpGroup() { + void testAssertPolicyNotDeployedInPdpGroup() { assertThatCode(() -> pdpGroupService.assertPolicyNotDeployedInPdpGroup("policy_not_deployed", "1.0.0")) .doesNotThrowAnyException(); diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestPolicyService.java b/main/src/test/java/org/onap/policy/api/main/service/TestPolicyService.java index f9baf76a..6820ad3f 100644 --- a/main/src/test/java/org/onap/policy/api/main/service/TestPolicyService.java +++ b/main/src/test/java/org/onap/policy/api/main/service/TestPolicyService.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022 Bell Canada. All rights reserved. + * Copyright (C) 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. @@ -22,26 +23,37 @@ package org.onap.policy.api.main.service; import static org.assertj.core.api.Assertions.assertThatCode; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; +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.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.MockitoAnnotations; import org.onap.policy.api.main.repository.PolicyRepository; import org.onap.policy.models.base.PfConceptKey; -@RunWith(MockitoJUnitRunner.class) -public class TestPolicyService { +class TestPolicyService { @Mock private PolicyRepository policyRepository; - @InjectMocks + @Mock private PolicyService policyService; + AutoCloseable autoCloseable; + + @BeforeEach + void before() { + autoCloseable = MockitoAnnotations.openMocks(this); + } + + @AfterEach + void after() throws Exception { + autoCloseable.close(); + } + @Test - public void testDeletePolicy() { + void testDeletePolicy() { PfConceptKey id = new PfConceptKey("dummy", "1.0.0"); Mockito.doNothing().when(policyRepository).deleteById(id); assertThatCode(() -> policyService.deletePolicy(id)).doesNotThrowAnyException(); diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestPolicyTypeService.java b/main/src/test/java/org/onap/policy/api/main/service/TestPolicyTypeService.java index 21f1ba4d..278d5971 100644 --- a/main/src/test/java/org/onap/policy/api/main/service/TestPolicyTypeService.java +++ b/main/src/test/java/org/onap/policy/api/main/service/TestPolicyTypeService.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022 Bell Canada. All rights reserved. + * Copyright (C) 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. @@ -22,17 +23,17 @@ package org.onap.policy.api.main.service; import static org.assertj.core.api.Assertions.assertThatCode; -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.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.MockitoAnnotations; import org.onap.policy.api.main.repository.PolicyTypeRepository; import org.onap.policy.models.base.PfConceptKey; -@RunWith(MockitoJUnitRunner.class) -public class TestPolicyTypeService { +class TestPolicyTypeService { @Mock private PolicyTypeRepository policyTypeRepository; @@ -40,8 +41,20 @@ public class TestPolicyTypeService { @InjectMocks private PolicyTypeService policyTypeService; + AutoCloseable closeable; + + @BeforeEach + public void setUp() { + closeable = MockitoAnnotations.openMocks(this); + } + + @AfterEach + void tearDown() throws Exception { + closeable.close(); + } + @Test - public void testDeletePolicy() { + void testDeletePolicy() { PfConceptKey id = new PfConceptKey("dummy", "1.0.0"); Mockito.doNothing().when(policyTypeRepository).deleteById(id); assertThatCode(() -> policyTypeService.deletePolicyType(id)).doesNotThrowAnyException(); diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateForNodeTemplate.java b/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateForNodeTemplate.java index 8f8fc464..fee7f403 100644 --- a/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateForNodeTemplate.java +++ b/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateForNodeTemplate.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy API * ================================================================================ - * Copyright (C) 2022 Nordix Foundation. All rights reserved. + * Copyright (C) 2022-2023 Nordix Foundation. 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. @@ -24,16 +24,14 @@ package org.onap.policy.api.main.service; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -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.assertTrue; import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; -import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; @@ -42,20 +40,17 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate; -@RunWith(MockitoJUnitRunner.class) -public class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServiceTemplateService { +class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServiceTemplateService { private static final String NODE_TEMPLATES_JSON = "nodetemplates/nodetemplates.metadatasets.input.tosca.json"; private static final String UPDATED_NODE_TEMPLATE_JSON = "nodetemplates/nodetemplates.metadatasets.update.json"; private static ToscaServiceTemplate toscaServiceTemplate; private static ToscaServiceTemplate updatedToscaServiceTemplate; - private StandardCoder standardCoder; @InjectMocks private ToscaServiceTemplateService toscaServiceTemplateService; - - @Before + @BeforeEach public void setUp() { super.setUp(); } @@ -65,9 +60,9 @@ public class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServ * * @throws CoderException when error parsing the json */ - @Before - public void fetchToscaNodeTemplateJson() throws CoderException { - standardCoder = new StandardCoder(); + @BeforeEach + void fetchToscaNodeTemplateJson() throws CoderException { + StandardCoder standardCoder = new StandardCoder(); toscaServiceTemplate = standardCoder.decode(ResourceUtils.getResourceAsString(NODE_TEMPLATES_JSON), ToscaServiceTemplate.class); updatedToscaServiceTemplate = @@ -76,7 +71,7 @@ public class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServ } @Test - public void testToscaNodeTemplatesGet() throws Exception { + void testToscaNodeTemplatesGet() throws Exception { assertNotNull(toscaServiceTemplate); var createdTemplate = toscaServiceTemplateService.createToscaNodeTemplates(toscaServiceTemplate); @@ -99,11 +94,10 @@ public class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServ } @Test - public void testToscaNodeTemplatesCreate() throws Exception { + void testToscaNodeTemplatesCreate() throws Exception { - assertThatThrownBy(() -> { - toscaServiceTemplateService.createToscaNodeTemplates(null); - }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> toscaServiceTemplateService.createToscaNodeTemplates(null)) + .hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); ToscaServiceTemplate createdNodeTemplates = toscaServiceTemplateService.createToscaNodeTemplates(toscaServiceTemplate); @@ -113,11 +107,10 @@ public class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServ } @Test - public void testToscaNodeTemplateUpdate() throws Exception { + void testToscaNodeTemplateUpdate() throws Exception { - assertThatThrownBy(() -> { - toscaServiceTemplateService.updateToscaNodeTemplates(null); - }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> toscaServiceTemplateService.updateToscaNodeTemplates(null)) + .hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); JpaToscaNodeTemplate jpaNodeTemplate = new JpaToscaNodeTemplate(); PfConceptKey key = new PfConceptKey("apexMetadata_grpc", "1.0.0"); @@ -131,21 +124,18 @@ public class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServ } @Test - public void testToscaNodeTemplateDelete() throws Exception { + void testToscaNodeTemplateDelete() throws Exception { - assertThatThrownBy(() -> { - toscaServiceTemplateService.deleteToscaNodeTemplate(null, null); - }).hasMessageMatching("^name is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> toscaServiceTemplateService.deleteToscaNodeTemplate(null, null)) + .hasMessageMatching("^name is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> { - toscaServiceTemplateService.deleteToscaNodeTemplate("name", null); - }).hasMessageMatching("^version is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> toscaServiceTemplateService.deleteToscaNodeTemplate("name", null)) + .hasMessageMatching("^version is marked .*on.*ull but is null$"); var createdTemplate = toscaServiceTemplateService.createToscaNodeTemplates(toscaServiceTemplate); mockDbServiceTemplate(createdTemplate, null, null); - assertThatThrownBy(() -> { - toscaServiceTemplateService.deleteToscaNodeTemplate("dummyname", "1.0.1"); - }).hasMessage("node template dummyname:1.0.1 not found"); + assertThatThrownBy(() -> toscaServiceTemplateService.deleteToscaNodeTemplate("dummyname", "1.0.1")) + .hasMessage("node template dummyname:1.0.1 not found"); ToscaServiceTemplate responseTemplate = toscaServiceTemplateService.deleteToscaNodeTemplate("apexMetadata_decisionMaker", "1.0.0"); diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyCrud.java b/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyCrud.java index 69864282..14d9056e 100644 --- a/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyCrud.java +++ b/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyCrud.java @@ -3,8 +3,8 @@ * ONAP Policy API * ================================================================================ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019-2021 Nordix Foundation. - * Modifications Copyright (C) 2020,2022 Bell Canada. + * Modifications Copyright (C) 2019-2021, 2023 Nordix Foundation. + * Modifications Copyright (C) 2020, 2022 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,24 +27,21 @@ package org.onap.policy.api.main.service; 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.assertFalse; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import jakarta.ws.rs.core.Response; import java.util.Optional; -import javax.ws.rs.core.Response; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.StandardYamlCoder; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; @@ -54,11 +51,10 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; * * @author Chenfei Gao (cgao@research.att.com) */ -@RunWith(MockitoJUnitRunner.class) -public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonToscaServiceTemplateService { +class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonToscaServiceTemplateService { - private static StandardCoder standardCoder = new StandardCoder(); - private static StandardYamlCoder standardYamlCoder = new StandardYamlCoder(); + private static final StandardCoder standardCoder = new StandardCoder(); + private static final StandardYamlCoder standardYamlCoder = new StandardYamlCoder(); private static final String POLICY_RESOURCE = "policies/vCPE.policy.monitoring.input.tosca.json"; private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policies.monitoring.tcagen2.yaml"; @@ -83,48 +79,43 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc @InjectMocks private ToscaServiceTemplateService toscaServiceTemplateService; - @Before + @BeforeEach public void setUp() { super.setUp(); } @Test - public void testFetchPolicies() { + void testFetchPolicies() { Mockito.when(toscaServiceTemplateRepository.findById(new PfConceptKey(JpaToscaServiceTemplate.DEFAULT_NAME, JpaToscaServiceTemplate.DEFAULT_VERSION))).thenReturn(Optional.empty()); - assertThatThrownBy(() -> { - toscaServiceTemplateService.fetchPolicies("dummy", "1.0.0", null, null, null); - }).hasMessage("service template not found in database"); + assertThatThrownBy(() -> toscaServiceTemplateService.fetchPolicies("dummy", "1.0.0", null, null, null)) + .hasMessage("service template not found in database"); - assertThatThrownBy(() -> { - toscaServiceTemplateService.fetchPolicies("dummy", "1.0.0", "dummy", null, null); - }).hasMessage("service template not found in database"); + assertThatThrownBy(() -> toscaServiceTemplateService.fetchPolicies("dummy", "1.0.0", "dummy", null, null)) + .hasMessage("service template not found in database"); - assertThatThrownBy(() -> { - toscaServiceTemplateService.fetchPolicies("dummy", "1.0.0", "dummy", "1.0.0", null); - }).hasMessage("service template not found in database"); + assertThatThrownBy(() -> toscaServiceTemplateService.fetchPolicies("dummy", "1.0.0", "dummy", "1.0.0", null)) + .hasMessage("service template not found in database"); - assertThatThrownBy(() -> { - toscaServiceTemplateService.fetchPolicies(null, null, "dummy", "1.0.0", null); - }).hasMessage("service template not found in database"); + assertThatThrownBy(() -> toscaServiceTemplateService.fetchPolicies(null, null, "dummy", "1.0.0", null)) + .hasMessage("service template not found in database"); } @Test - public void testFetchLatestPolicies() { + void testFetchLatestPolicies() { Mockito.when(toscaServiceTemplateRepository.findById(new PfConceptKey(JpaToscaServiceTemplate.DEFAULT_NAME, JpaToscaServiceTemplate.DEFAULT_VERSION))).thenReturn(Optional.empty()); - assertThatThrownBy(() -> { - toscaServiceTemplateService.fetchLatestPolicies("dummy", "dummy", "dummy", null); - }).hasMessage("service template not found in database"); + assertThatThrownBy(() -> toscaServiceTemplateService.fetchLatestPolicies("dummy", "dummy", "dummy", null)) + .hasMessage("service template not found in database"); } @Test - public void testCreatePolicy() throws Exception { - assertThatThrownBy(() -> { - toscaServiceTemplateService.createPolicy("dummy", "1.0.0", new ToscaServiceTemplate()); - }).hasMessage("topology template not specified on service template"); + void testCreatePolicy() throws Exception { + assertThatThrownBy(() -> toscaServiceTemplateService + .createPolicy("dummy", "1.0.0", new ToscaServiceTemplate())) + .hasMessage("topology template not specified on service template"); var policyTypeServiceTemplate = standardYamlCoder .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class); @@ -179,7 +170,7 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc } @Test - public void testCreateOperationalDroolsPolicy() throws CoderException { + void testCreateOperationalDroolsPolicy() throws CoderException { var policyTypeServiceTemplate = standardYamlCoder.decode( ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL_COMMON), ToscaServiceTemplate.class); @@ -199,7 +190,7 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc } @Test - public void testSimpleCreatePolicy() throws Exception { + void testSimpleCreatePolicy() throws Exception { assertThatThrownBy(() -> { String multiPoliciesString = ResourceUtils.getResourceAsString(MULTIPLE_POLICIES_RESOURCE); @@ -291,11 +282,10 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc } @Test - public void testDeletePolicy() throws CoderException, PfModelException { + void testDeletePolicy() throws CoderException { - assertThatThrownBy(() -> { - toscaServiceTemplateService.deletePolicy("dummy", "1.0.0", "dummy", "1.0.0"); - }).hasMessage("no policies found"); + assertThatThrownBy(() -> toscaServiceTemplateService.deletePolicy("dummy", "1.0.0", "dummy", "1.0.0")) + .hasMessage("no policies found"); var policyTypeServiceTemplate = standardYamlCoder .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class); @@ -312,10 +302,10 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc var exceptionMessage = "policy is in use, it is deployed in PDP group dummy subgroup dummy"; Mockito.doThrow(new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, exceptionMessage)) .when(pdpGroupService).assertPolicyNotDeployedInPdpGroup("onap.restart.tca", "1.0.0"); - assertThatThrownBy(() -> { - toscaServiceTemplateService.deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", - "onap.restart.tca", "1.0.0"); - }).hasMessage(exceptionMessage); + assertThatThrownBy(() -> toscaServiceTemplateService + .deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca", "1.0.0")) + .hasMessage(exceptionMessage); + Mockito.doNothing().when(pdpGroupService).assertPolicyNotDeployedInPdpGroup("onap.restart.tca", "1.0.0"); var deletePolicyResponseFragment = toscaServiceTemplateService @@ -323,14 +313,13 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc assertFalse(deletePolicyResponseFragment.getToscaTopologyTemplate().getPolicies().get(0).isEmpty()); mockDbServiceTemplate(serviceTemplate, deletePolicyResponseFragment, Operation.DELETE_POLICY); - assertThatThrownBy(() -> { - toscaServiceTemplateService.deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", - "onap.restart.tca", "1.0.0"); - }).hasMessageContaining("no policies found"); + assertThatThrownBy(() -> toscaServiceTemplateService + .deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca", "1.0.0")) + .hasMessageContaining("no policies found"); } @Test - public void testFetchAllPolicies() throws Exception { + void testFetchAllPolicies() throws Exception { // Create Policy Type var policyTypeServiceTemplate = standardYamlCoder .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class); @@ -353,7 +342,7 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc } @Test - public void testFetchSpecificPolicy_availablePolicy() throws Exception { + void testFetchSpecificPolicy_availablePolicy() throws Exception { // Create Policy Type var policyTypeServiceTemplate = standardYamlCoder .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class); @@ -375,7 +364,7 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc } @Test - public void testFetchSpecificPolicy_unavailablePolicy() throws Exception { + void testFetchSpecificPolicy_unavailablePolicy() throws Exception { // Create Policy Type var policyTypeServiceTemplate = standardYamlCoder .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class); @@ -397,7 +386,7 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc } @Test - public void testDeleteSpecificPolicy_availablePolicy() throws Exception { + void testDeleteSpecificPolicy_availablePolicy() throws Exception { var policyTypeServiceTemplate = standardYamlCoder .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class); var serviceTemplate = toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate); @@ -415,7 +404,7 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc } @Test - public void testDeleteSpecificPolicy_unavailablePolicy() throws Exception { + void testDeleteSpecificPolicy_unavailablePolicy() throws Exception { var policyTypeServiceTemplate = standardYamlCoder .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class); var serviceTemplate = toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate); diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyTypeCrud.java b/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyTypeCrud.java index cea2bcf0..9dcb4333 100644 --- a/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyTypeCrud.java +++ b/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyTypeCrud.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022 Bell Canada. All rights reserved. + * Copyright (C) 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. @@ -21,22 +22,19 @@ package org.onap.policy.api.main.service; 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.assertNotNull; - -import javax.ws.rs.core.Response; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import jakarta.ws.rs.core.Response; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardYamlCoder; import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -45,10 +43,9 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; * * @author Chenfei Gao (cgao@research.att.com) */ -@RunWith(MockitoJUnitRunner.class) -public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommonToscaServiceTemplateService { +class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommonToscaServiceTemplateService { - private static StandardYamlCoder coder = new StandardYamlCoder(); + private static final StandardYamlCoder coder = new StandardYamlCoder(); private static final String POLICY_TYPE_VERSION = "1.0.0"; private static final String POLICY_RESOURCE_MONITORING = "policies/vCPE.policy.monitoring.input.tosca.yaml"; @@ -76,20 +73,18 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon /** * Test setup. */ - @Before + @BeforeEach public void setUp() { super.setUp(); } @Test - public void testFetchPolicyTypes() throws PfModelException { - assertThatThrownBy(() -> { - toscaServiceTemplateService.fetchPolicyTypes("dummy", null); - }).hasMessage("policy types for filter ToscaEntityFilter(name=dummy, version=null) do not exist"); + void testFetchPolicyTypes() { + assertThatThrownBy(() -> toscaServiceTemplateService.fetchPolicyTypes("dummy", null)) + .hasMessage("policy types for filter ToscaEntityFilter(name=dummy, version=null) do not exist"); - assertThatThrownBy(() -> { - toscaServiceTemplateService.fetchPolicyTypes("dummy", "dummy"); - }).hasMessage("policy types for filter ToscaEntityFilter(name=dummy, version=dummy) do not exist"); + assertThatThrownBy(() -> toscaServiceTemplateService.fetchPolicyTypes("dummy", "dummy")) + .hasMessage("policy types for filter ToscaEntityFilter(name=dummy, version=dummy) do not exist"); // FIXME // ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(null, null); @@ -97,15 +92,13 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon } @Test - public void testFetchLatestPolicyTypes() { - - assertThatThrownBy(() -> { - toscaServiceTemplateService.fetchLatestPolicyTypes("dummy"); - }).hasMessage("policy types for filter ToscaEntityFilter(name=dummy, version=LATEST) do not exist"); + void testFetchLatestPolicyTypes() { + assertThatThrownBy(() -> toscaServiceTemplateService.fetchLatestPolicyTypes("dummy")) + .hasMessage("policy types for filter ToscaEntityFilter(name=dummy, version=LATEST) do not exist"); } @Test - public void testCreatePolicyType() throws CoderException { + void testCreatePolicyType() throws CoderException { var policyTypeServiceTemplate = coder .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_MONITORING), ToscaServiceTemplate.class); var serviceTemplate = toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate); @@ -116,10 +109,9 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon policyTypeServiceTemplate.getPolicyTypes().get("onap.policies.monitoring.tcagen2") .setDescription("Some other description"); - assertThatThrownBy(() -> { - toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate); - }).hasMessageContaining("item \"entity\" value \"onap.policies.monitoring.tcagen2:1.0.0\" INVALID, " - + "does not equal existing entity"); + assertThatThrownBy(() -> toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate)) + .hasMessageContaining("item \"entity\" value \"onap.policies.monitoring.tcagen2:1.0.0\" INVALID, " + + "does not equal existing entity"); assertThatThrownBy(() -> { ToscaServiceTemplate badPolicyType = @@ -132,7 +124,7 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon } @Test - public void testCreateOperationalPolicyTypes() throws CoderException { + void testCreateOperationalPolicyTypes() throws CoderException { ToscaServiceTemplate policyTypeServiceTemplate = coder.decode( ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL_COMMON), ToscaServiceTemplate.class); ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate); @@ -152,7 +144,7 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon } @Test - public void testCreateApexOperationalPolicyTypes() throws CoderException { + void testCreateApexOperationalPolicyTypes() throws CoderException { var policyTypeServiceTemplate = coder.decode( ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL_COMMON), ToscaServiceTemplate.class); var serviceTemplate = toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate); @@ -168,7 +160,7 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon } @Test - public void testDeletePolicyType() throws CoderException { + void testDeletePolicyType() throws CoderException { var policyTypeServiceTemplate = coder .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_MONITORING), ToscaServiceTemplate.class); var serviceTemplate = toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate); @@ -183,9 +175,8 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon mockDbServiceTemplate(serviceTemplate, createPolicyResponseFragment, Operation.CREATE_POLICY); var exceptionMessage = "policy type onap.policies.monitoring.tcagen2:1.0.0 is in use, " + "it is referenced in policy onap.restart.tca:1.0.0"; - assertThatThrownBy(() -> { - toscaServiceTemplateService.deletePolicyType("onap.policies.monitoring.tcagen2", "1.0.0"); - }).hasMessage(exceptionMessage); + assertThatThrownBy(() -> toscaServiceTemplateService.deletePolicyType("onap.policies.monitoring.tcagen2", + "1.0.0")).hasMessage(exceptionMessage); var deletePolicyResponseFragment = toscaServiceTemplateService .deletePolicy("onap.policies.monitoring.tcagen2", "1.0.0", "onap.restart.tca", "1.0.0"); @@ -195,9 +186,8 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon exceptionMessage = "policy type is in use, it is referenced in PDP group dummy subgroup dummy"; Mockito.doThrow(new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, exceptionMessage)) .when(pdpGroupService).assertPolicyTypeNotSupportedInPdpGroup("onap.policies.monitoring.tcagen2", "1.0.0"); - assertThatThrownBy(() -> { - toscaServiceTemplateService.deletePolicyType("onap.policies.monitoring.tcagen2", "1.0.0"); - }).hasMessage(exceptionMessage); + assertThatThrownBy(() -> toscaServiceTemplateService.deletePolicyType("onap.policies.monitoring.tcagen2", + "1.0.0")).hasMessage(exceptionMessage); Mockito.doNothing().when(pdpGroupService) .assertPolicyTypeNotSupportedInPdpGroup("onap.policies.monitoring.tcagen2", "1.0.0"); @@ -206,8 +196,7 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon assertFalse(deletePolicyTypeResponseFragment.getPolicyTypes().isEmpty()); mockDbServiceTemplate(serviceTemplate, deletePolicyTypeResponseFragment, Operation.DELETE_POLICY_TYPE); - assertThatThrownBy(() -> { - toscaServiceTemplateService.deletePolicyType("onap.policies.monitoring.tcagen2", "1.0.0"); - }).hasMessage("policy type onap.policies.monitoring.tcagen2:1.0.0 not found"); + assertThatThrownBy(() -> toscaServiceTemplateService.deletePolicyType("onap.policies.monitoring.tcagen2", + "1.0.0")).hasMessage("policy type onap.policies.monitoring.tcagen2:1.0.0 not found"); } }
\ No newline at end of file diff --git a/main/src/test/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializerTest.java b/main/src/test/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializerTest.java index aa86d739..d7df3d81 100644 --- a/main/src/test/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializerTest.java +++ b/main/src/test/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializerTest.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 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. @@ -23,21 +24,18 @@ package org.onap.policy.api.main.startstop; import static org.assertj.core.api.Assertions.assertThatCode; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.onap.policy.api.main.PolicyApiApplication; import org.onap.policy.api.main.config.PolicyPreloadConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest(classes = PolicyApiApplication.class) @ActiveProfiles("test") @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) -public class ApiDatabaseInitializerTest { +class ApiDatabaseInitializerTest { @Autowired private PolicyPreloadConfig params; @@ -46,7 +44,7 @@ public class ApiDatabaseInitializerTest { private ApiDatabaseInitializer adi; @Test - public void testInitializeApiDatabase() { + void testInitializeApiDatabase() { assertThatCode(() -> adi.initializeApiDatabase(params.getPolicyTypes(), params.getPolicies())).doesNotThrowAnyException(); |