* ONAP PAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021,2023 Nordix Foundation.
+ * Modifications Copyright (C) 2021, 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.pap.main.comm.CommonRequestBase;
-@RunWith(MockitoJUnitRunner.class)
-public class UpdateReqTest extends CommonRequestBase {
+class UpdateReqTest extends CommonRequestBase {
private UpdateReq data;
private PdpUpdate update;
* @throws Exception if an error occurs
*/
@Override
- @Before
+ @BeforeEach
public void setUp() throws Exception {
super.setUp();
response.setPdpGroup(update.getPdpGroup());
response.setPdpSubgroup(update.getPdpSubgroup());
response.setPolicies(
- update.getPoliciesToBeDeployed().stream().map(ToscaPolicy::getIdentifier)
- .collect(Collectors.toList()));
+ update.getPoliciesToBeDeployed().stream().map(ToscaPolicy::getIdentifier)
+ .collect(Collectors.toList()));
data = new UpdateReq(reqParams, MY_REQ_NAME, update);
data.setNotifier(notifier);
}
@Test
- public void testGetMessage() {
+ void testGetMessage() {
assertEquals(MY_REQ_NAME, data.getName());
assertSame(update, data.getMessage());
}
@Test
- public void testCheckResponse() {
+ void testCheckResponse() {
assertNull(data.checkResponse(response));
assertTrue(data.getUndeployPolicies().isEmpty());
verifyResponse();
}
@Test
- public void testCheckResponse_NullName() {
+ void testCheckResponse_NullName() {
response.setName(null);
assertEquals("null PDP name", data.checkResponse(response));
}
@Test
- public void testCheckResponse_NullMsgName() {
+ void testCheckResponse_NullMsgName() {
update.setName(null);
- assertEquals(null, data.checkResponse(response));
+ assertNull(data.checkResponse(response));
assertTrue(data.getUndeployPolicies().isEmpty());
verifyResponse();
}
@Test
- public void testUpdateReqCheckResponse_MismatchedGroup() {
+ void testUpdateReqCheckResponse_MismatchedGroup() {
response.setPdpGroup(DIFFERENT);
assertEquals("group does not match", data.checkResponse(response));
}
@Test
- public void testUpdateReqCheckResponse_MismatchedSubGroup() {
+ void testUpdateReqCheckResponse_MismatchedSubGroup() {
response.setPdpSubgroup(DIFFERENT);
assertEquals("subgroup does not match", data.checkResponse(response));
}
@Test
- public void testCheckResponse_NullSubGroup() {
+ void testCheckResponse_NullSubGroup() {
update.setPdpSubgroup(null);
response.setPdpSubgroup(null);
// different policy list - should have no impact
response.setPolicies(Collections.emptyList());
- assertEquals(null, data.checkResponse(response));
+ assertNull(data.checkResponse(response));
assertTrue(data.getUndeployPolicies().isEmpty());
verifyNoResponse();
}
@Test
- public void testUpdateReqCheckResponse_MismatchedPolicies() {
+ void testUpdateReqCheckResponse_MismatchedPolicies() {
ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPoliciesToBeDeployed());
policies.set(0, makePolicy(DIFFERENT, "10.0.0"));
// the first policy from the original update is all that should be undeployed
assertEquals(Collections.singleton(update.getPoliciesToBeDeployed().get(0).getIdentifier()).toString(),
- data.getUndeployPolicies().toString());
+ data.getUndeployPolicies().toString());
}
@Test
- public void testUpdateReqCheckResponse_MismatchedPolicies_Null_NotNull() {
+ void testUpdateReqCheckResponse_MismatchedPolicies_Null_NotNull() {
update.setPoliciesToBeDeployed(null);
- assertEquals(null, data.checkResponse(response));
+ assertNull(data.checkResponse(response));
assertTrue(data.getUndeployPolicies().isEmpty());
verifyResponse();
}
@Test
- public void testUpdateReqCheckResponse_MismatchedPolicies_NotNull_Null() {
+ void testUpdateReqCheckResponse_MismatchedPolicies_NotNull_Null() {
response.setPolicies(null);
assertEquals("policies do not match", data.checkResponse(response));
// all policies in the update should be undeployed
assertEquals(update.getPoliciesToBeDeployed().stream().map(ToscaPolicy::getIdentifier)
- .collect(Collectors.toList())
- .toString(), new TreeSet<>(data.getUndeployPolicies()).toString());
+ .toList().toString(), new TreeSet<>(data.getUndeployPolicies()).toString());
}
@Test
- public void testReconfigure() {
+ void testReconfigure() {
// different message type should fail and leave message unchanged
assertFalse(data.reconfigure(new PdpStateChange()));
assertSame(update, data.getMessage());
}
@Test
- public void testReconfigureIsFullSameAsDeployList() {
+ void testReconfigureIsFullSameAsDeployList() {
PdpUpdate msg2 = new PdpUpdate(update);
ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPoliciesToBeDeployed());
}
@Test
- public void testListsNewVsResult() {
+ void testListsNewVsResult() {
PdpUpdate msg2 = new PdpUpdate(update);
ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPoliciesToBeDeployed());
policies.clear();
policies = new ArrayList<>(update.getPoliciesToBeDeployed());
List<ToscaConceptIdentifier> polsToUndep = policies.parallelStream()
- .map(ToscaPolicy::getIdentifier)
- .collect(Collectors.toList());
+ .map(ToscaPolicy::getIdentifier)
+ .collect(Collectors.toList());
msg2.setPoliciesToBeUndeployed(polsToUndep);
assertTrue(data.reconfigure(msg2));
// some items in both undeploy and newMessage.undeploy
List<ToscaConceptIdentifier> pols = policies.stream().map(ToscaPolicy::getIdentifier)
- .collect(Collectors.toList());
+ .collect(Collectors.toList());
msg2.setPoliciesToBeUndeployed(pols);
pols.add(makePolicy("policy-zz-1", "1.1.0").getIdentifier());
data.getMessage().setPoliciesToBeUndeployed(pols);
// some items in both undeploy and newMessage.deploy
policies = new ArrayList<>(update.getPoliciesToBeDeployed());
List<ToscaConceptIdentifier> polsToUndep2 = policies.parallelStream()
- .map(ToscaPolicy::getIdentifier)
- .collect(Collectors.toList());
+ .map(ToscaPolicy::getIdentifier)
+ .collect(Collectors.toList());
data.getMessage().setPoliciesToBeUndeployed(polsToUndep2);
List<ToscaPolicy> polsToDep2 = new LinkedList<>();
assertTrue(data.reconfigure(msg2));
List<ToscaConceptIdentifier> dataPols2 = data.getMessage().getPoliciesToBeDeployed().stream()
- .map(ToscaPolicy::getIdentifier)
- .collect(Collectors.toList());
+ .map(ToscaPolicy::getIdentifier)
+ .collect(Collectors.toList());
assertThat(data.getMessage().getPoliciesToBeUndeployed())
- .doesNotContainAnyElementsOf(dataPols2);
+ .doesNotContainAnyElementsOf(dataPols2);
// some items only in undeploy
pols = policies.stream().map(ToscaPolicy::getIdentifier)
- .collect(Collectors.toList());
+ .collect(Collectors.toList());
msg2.setPoliciesToBeUndeployed(pols);
data.getMessage().setPoliciesToBeUndeployed(new LinkedList<>());
assertTrue(data.reconfigure(msg2));
}
@Test
- public void testIsSameContent() {
+ void testIsSameContent() {
data = new UpdateReq(reqParams, MY_REQ_NAME, update);
data.setNotifier(notifier);
}
@Test
- public void testIsSameContent_BothGroupNamesNull() {
+ void testIsSameContent_BothGroupNamesNull() {
PdpUpdate msg2 = new PdpUpdate(update);
msg2.setPdpGroup(null);
update.setPdpGroup(null);
}
@Test
- public void testIsSameContent_BothSubGroupNamesNull() {
+ void testIsSameContent_BothSubGroupNamesNull() {
PdpUpdate msg2 = new PdpUpdate(update);
msg2.setPdpSubgroup(null);
update.setPdpSubgroup(null);
}
@Test
- public void testIsSameContent_DiffGroup() {
+ void testIsSameContent_DiffGroup() {
PdpUpdate msg2 = new PdpUpdate(update);
msg2.setPdpGroup(null);
assertFalse(data.isSameContent(msg2));
}
@Test
- public void testIsSameContent_DiffSubGroup() {
+ void testIsSameContent_DiffSubGroup() {
PdpUpdate msg2 = new PdpUpdate(update);
msg2.setPdpSubgroup(null);
assertFalse(data.isSameContent(msg2));
}
@Test
- public void testIsSameContent_DiffPolicies() {
+ void testIsSameContent_DiffPolicies() {
PdpUpdate msg2 = new PdpUpdate(update);
ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPoliciesToBeDeployed());
}
@Test
- public void testIsSameContent_DiffPolicies_NotNull_Null() {
+ void testIsSameContent_DiffPolicies_NotNull_Null() {
PdpUpdate msg2 = new PdpUpdate(update);
msg2.setPoliciesToBeDeployed(null);
}
@Test
- public void testIsSameContent_DiffPolicies_Null_NotNull() {
+ void testIsSameContent_DiffPolicies_Null_NotNull() {
final PdpUpdate msg2 = new PdpUpdate(update);
update.setPoliciesToBeDeployed(null);