aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org/onap/policy/pap/main/service
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/test/java/org/onap/policy/pap/main/service')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/service/PdpGroupServiceTest.java61
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/service/PolicyAuditServiceTest.java10
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/service/PolicyStatusServiceTest.java8
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/service/ToscaNodeTemplateServiceTest.java27
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/service/ToscaServiceTemplateServiceTest.java36
5 files changed, 75 insertions, 67 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/service/PdpGroupServiceTest.java b/main/src/test/java/org/onap/policy/pap/main/service/PdpGroupServiceTest.java
index 4edb05dc..2846e506 100644
--- a/main/src/test/java/org/onap/policy/pap/main/service/PdpGroupServiceTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/service/PdpGroupServiceTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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.
@@ -26,8 +26,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.Collections;
import java.util.List;
-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.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.pdp.concepts.Pdp;
@@ -40,10 +40,12 @@ import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.pap.main.rest.CommonPapRestServer;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
@ActiveProfiles("test")
-public class PdpGroupServiceTest extends CommonPapRestServer {
+@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
+class PdpGroupServiceTest extends CommonPapRestServer {
private static final String FIELD_IS_NULL = "%s is marked non-null but is null";
@@ -62,7 +64,7 @@ public class PdpGroupServiceTest extends CommonPapRestServer {
private PdpGroups groupsToCreate;
- private StandardCoder coder = new StandardCoder();
+ private final StandardCoder coder = new StandardCoder();
/**
* Setup before tests.
@@ -70,7 +72,7 @@ public class PdpGroupServiceTest extends CommonPapRestServer {
* @throws Exception the exception
*/
@Override
- @Before
+ @BeforeEach
public void setUp() throws Exception {
super.setUp();
PdpGroups defaultGroup = coder.decode(ResourceUtils.getResourceAsString("e2e/PdpGroups.json"), PdpGroups.class);
@@ -79,7 +81,7 @@ public class PdpGroupServiceTest extends CommonPapRestServer {
}
@Test
- public void testPdpGroupsCrudSuccess() {
+ void testPdpGroupsCrudSuccess() {
List<PdpGroup> pdpGroups = pdpGroupService.getPdpGroups();
assertThat(pdpGroups).hasSize(1);
@@ -118,7 +120,7 @@ public class PdpGroupServiceTest extends CommonPapRestServer {
}
@Test
- public void testPdpGroupsCrudFailure() {
+ void testPdpGroupsCrudFailure() {
PdpState pdpState = null;
assertThatThrownBy(() -> pdpGroupService.getPdpGroups(pdpState))
.hasMessage(String.format(FIELD_IS_NULL, "pdpState"));
@@ -140,23 +142,17 @@ public class PdpGroupServiceTest extends CommonPapRestServer {
}
@Test
- public void testUpdatePdp() {
+ void testUpdatePdp() {
+ assertThatThrownBy(() -> pdpGroupService.updatePdp(null, null, new Pdp()))
+ .hasMessage(String.format(FIELD_IS_NULL, "pdpGroupName"));
- assertThatThrownBy(() -> {
- pdpGroupService.updatePdp(null, null, new Pdp());
- }).hasMessage(String.format(FIELD_IS_NULL, "pdpGroupName"));
+ assertThatThrownBy(() -> pdpGroupService.updatePdp(NAME, null, new Pdp()))
+ .hasMessage(String.format(FIELD_IS_NULL, "pdpSubGroup"));
- assertThatThrownBy(() -> {
- pdpGroupService.updatePdp(NAME, null, new Pdp());
- }).hasMessage(String.format(FIELD_IS_NULL, "pdpSubGroup"));
+ assertThatThrownBy(() -> pdpGroupService.updatePdp(NAME, TYPE, null))
+ .hasMessage(String.format(FIELD_IS_NULL, "pdp"));
- assertThatThrownBy(() -> {
- pdpGroupService.updatePdp(NAME, TYPE, null);
- }).hasMessage(String.format(FIELD_IS_NULL, "pdp"));
-
- assertThatThrownBy(() -> {
- pdpGroupService.updatePdp(NAME, TYPE, new Pdp());
- }).hasMessage(LOCALNAME_IS_NULL);
+ assertThatThrownBy(() -> pdpGroupService.updatePdp(NAME, TYPE, new Pdp())).hasMessage(LOCALNAME_IS_NULL);
pdpGroupService.createPdpGroups(groupsToCreate.getGroups());
assertThat(pdpGroupService.getPdpGroups()).hasSize(2);
@@ -174,18 +170,15 @@ public class PdpGroupServiceTest extends CommonPapRestServer {
}
@Test
- public void testUpdateSubGroup() {
- assertThatThrownBy(() -> {
- pdpGroupService.updatePdpSubGroup(null, null);
- }).hasMessage(String.format(FIELD_IS_NULL, "pdpGroupName"));
-
- assertThatThrownBy(() -> {
- pdpGroupService.updatePdpSubGroup(NAME, null);
- }).hasMessage(String.format(FIELD_IS_NULL, "pdpSubGroup"));
-
- assertThatThrownBy(() -> {
- pdpGroupService.updatePdpSubGroup(NAME, new PdpSubGroup());
- }).hasMessage(LOCALNAME_IS_NULL);
+ void testUpdateSubGroup() {
+ assertThatThrownBy(() -> pdpGroupService.updatePdpSubGroup(null, null))
+ .hasMessage(String.format(FIELD_IS_NULL, "pdpGroupName"));
+
+ assertThatThrownBy(() -> pdpGroupService.updatePdpSubGroup(NAME, null))
+ .hasMessage(String.format(FIELD_IS_NULL, "pdpSubGroup"));
+
+ assertThatThrownBy(() -> pdpGroupService.updatePdpSubGroup(NAME, new PdpSubGroup()))
+ .hasMessage(LOCALNAME_IS_NULL);
pdpGroupService.createPdpGroups(groupsToCreate.getGroups());
assertThat(pdpGroupService.getPdpGroups()).hasSize(2);
diff --git a/main/src/test/java/org/onap/policy/pap/main/service/PolicyAuditServiceTest.java b/main/src/test/java/org/onap/policy/pap/main/service/PolicyAuditServiceTest.java
index 8c351e24..79037af3 100644
--- a/main/src/test/java/org/onap/policy/pap/main/service/PolicyAuditServiceTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/service/PolicyAuditServiceTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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.
@@ -23,13 +23,13 @@ package org.onap.policy.pap.main.service;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
-import org.junit.After;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+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;
@@ -59,7 +59,7 @@ public class PolicyAuditServiceTest extends CommonPapRestServer {
* Teardown after tests.
*/
@Override
- @After
+ @AfterEach
public void tearDown() {
policyAuditRepository.deleteAll();
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/service/PolicyStatusServiceTest.java b/main/src/test/java/org/onap/policy/pap/main/service/PolicyStatusServiceTest.java
index 6166580e..06eb887b 100644
--- a/main/src/test/java/org/onap/policy/pap/main/service/PolicyStatusServiceTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/service/PolicyStatusServiceTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2022-2023 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.
@@ -26,8 +26,8 @@ import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.List;
-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.base.PfModelRuntimeException;
import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -55,7 +55,7 @@ public class PolicyStatusServiceTest extends CommonPapRestServer {
* @throws Exception the exception
*/
@Override
- @Before
+ @BeforeEach
public void setUp() throws Exception {
super.setUp();
ToscaConceptIdentifier policyType = new ToscaConceptIdentifier("MyPolicyType", "1.2.4");
diff --git a/main/src/test/java/org/onap/policy/pap/main/service/ToscaNodeTemplateServiceTest.java b/main/src/test/java/org/onap/policy/pap/main/service/ToscaNodeTemplateServiceTest.java
index d5c19fe3..7aefdc4c 100644
--- a/main/src/test/java/org/onap/policy/pap/main/service/ToscaNodeTemplateServiceTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/service/ToscaNodeTemplateServiceTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * 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.
@@ -25,12 +25,14 @@ 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.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -44,7 +46,7 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate;
import org.onap.policy.pap.main.repository.ToscaNodeTemplateRepository;
@RunWith(MockitoJUnitRunner.class)
-public class ToscaNodeTemplateServiceTest {
+class ToscaNodeTemplateServiceTest {
private static final String NODE_TEMPLATE_NAME = "tca_metadata";
private static final String NODE_TEMPLATE_VERSION = "1.0.0";
@@ -57,24 +59,31 @@ public class ToscaNodeTemplateServiceTest {
private ToscaNodeTemplate nodeTemplate = new ToscaNodeTemplate();
- private StandardCoder coder = new StandardYamlCoder();
+ private final StandardCoder coder = new StandardYamlCoder();
+
+ AutoCloseable autoCloseable;
/**
* Set up for tests.
- *
*/
- @Before
+ @BeforeEach
public void setup() throws CoderException {
+ autoCloseable = MockitoAnnotations.openMocks(this);
coder.decode(ResourceUtils.getResourceAsString("e2e/policyMetadataSet.yaml"),
- ToscaServiceTemplate.class).getToscaTopologyTemplate().getNodeTemplates()
+ ToscaServiceTemplate.class).getToscaTopologyTemplate().getNodeTemplates()
.forEach((key, value) -> nodeTemplate = value);
Mockito.when(nodeTemplateRepository.findById(new PfConceptKey(NODE_TEMPLATE_NAME, NODE_TEMPLATE_VERSION)))
.thenReturn(Optional.of(new JpaToscaNodeTemplate(nodeTemplate)));
}
+ @AfterEach
+ public void tearDown() throws Exception {
+ autoCloseable.close();
+ }
+
@Test
- public void testGetToscaNodeTemplate() {
+ void testGetToscaNodeTemplate() {
assertDoesNotThrow(() -> nodeTemplateService.getToscaNodeTemplate(NODE_TEMPLATE_NAME, NODE_TEMPLATE_VERSION));
assertThat(nodeTemplateService.getToscaNodeTemplate(NODE_TEMPLATE_NAME, NODE_TEMPLATE_VERSION).getMetadata())
diff --git a/main/src/test/java/org/onap/policy/pap/main/service/ToscaServiceTemplateServiceTest.java b/main/src/test/java/org/onap/policy/pap/main/service/ToscaServiceTemplateServiceTest.java
index b64ad287..20bd2257 100644
--- a/main/src/test/java/org/onap/policy/pap/main/service/ToscaServiceTemplateServiceTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/service/ToscaServiceTemplateServiceTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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.
@@ -24,16 +24,18 @@ package org.onap.policy.pap.main.service;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import jakarta.ws.rs.core.Response;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import javax.ws.rs.core.Response;
-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.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -49,7 +51,7 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
import org.onap.policy.pap.main.repository.ToscaServiceTemplateRepository;
@RunWith(MockitoJUnitRunner.class)
-public class ToscaServiceTemplateServiceTest {
+class ToscaServiceTemplateServiceTest {
private static final String VERSION_1 = "1.0.0";
@@ -72,22 +74,22 @@ public class ToscaServiceTemplateServiceTest {
@Mock
private ToscaNodeTemplateService nodeTemplateService;
- private ToscaServiceTemplate serviceTemplate;
-
private ToscaNodeTemplate nodeTemplate;
- private StandardCoder coder = new StandardYamlCoder();
+ private final StandardCoder coder = new StandardYamlCoder();
+
+ AutoCloseable autoCloseable;
/**
* Set up for tests.
*
* @throws CoderException the exception
*/
- @Before
+ @BeforeEach
public void setup() throws CoderException {
-
+ autoCloseable = MockitoAnnotations.openMocks(this);
coder.decode(ResourceUtils.getResourceAsString("e2e/policyMetadataSet.yaml"),
- ToscaServiceTemplate.class).getToscaTopologyTemplate().getNodeTemplates()
+ ToscaServiceTemplate.class).getToscaTopologyTemplate().getNodeTemplates()
.forEach((key, value) -> nodeTemplate = value);
ToscaServiceTemplate toscaPolicyType =
@@ -100,7 +102,7 @@ public class ToscaServiceTemplateServiceTest {
toscaPolicy.getToscaTopologyTemplate().getPolicies().forEach(e -> e.entrySet().iterator().next().getValue()
.getMetadata().putAll(Map.of("metadataSetName", NODE_TEMPLATE_NAME,
"metadataSetVersion", NODE_TEMPLATE_VERSION)));
- serviceTemplate = new ToscaServiceTemplate(toscaPolicyType);
+ ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(toscaPolicyType);
serviceTemplate.setToscaTopologyTemplate(toscaPolicy.getToscaTopologyTemplate());
Mockito
.when(toscaRepository.findById(
@@ -112,9 +114,13 @@ public class ToscaServiceTemplateServiceTest {
.thenReturn(nodeTemplate);
}
+ @AfterEach
+ public void tearDown() throws Exception {
+ autoCloseable.close();
+ }
@Test
- public void testGetPolicyList() throws PfModelException {
+ void testGetPolicyList() throws PfModelException {
assertThatThrownBy(() -> toscaService.getPolicyList(NAME, VERSION))
.isInstanceOf(PfModelRuntimeException.class).hasRootCauseMessage(INVALID_VERSION_ERR_MSG);
@@ -124,7 +130,7 @@ public class ToscaServiceTemplateServiceTest {
}
@Test
- public void testPolicyForMetadataSet() throws PfModelException {
+ void testPolicyForMetadataSet() throws PfModelException {
List<ToscaPolicy> policies = toscaService.getPolicyList("onap.restart.tca", VERSION_1);
assertThat(policies.get(0).getMetadata()).containsEntry("metadataSet", nodeTemplate.getMetadata());
@@ -140,7 +146,7 @@ public class ToscaServiceTemplateServiceTest {
}
@Test
- public void testGetPolicyTypeList() throws PfModelException {
+ void testGetPolicyTypeList() throws PfModelException {
assertThatThrownBy(() -> toscaService.getPolicyTypeList(NAME, VERSION))
.isInstanceOf(PfModelRuntimeException.class).hasRootCauseMessage(INVALID_VERSION_ERR_MSG);