* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. 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.
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.Set;
+import java.util.TreeSet;
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
/**
* Sets up.
+ *
* @throws Exception if an error occurs
*/
@Before
update.getPolicies().stream().map(ToscaPolicy::getIdentifier).collect(Collectors.toList()));
data = new UpdateReq(reqParams, MY_REQ_NAME, update);
+ data.setNotifier(notifier);
}
@Test
@Test
public void testCheckResponse() {
assertNull(data.checkResponse(response));
+ assertTrue(data.getUndeployPolicies().isEmpty());
+ verifyResponse();
+
+ // both policy lists null
+ update.setPolicies(null);
+ response.setPolicies(null);
+ assertNull(data.checkResponse(response));
+ assertTrue(data.getUndeployPolicies().isEmpty());
}
@Test
response.setName(null);
assertEquals("null PDP name", data.checkResponse(response));
+ assertTrue(data.getUndeployPolicies().isEmpty());
+ verifyNoResponse();
}
@Test
update.setName(null);
assertEquals(null, data.checkResponse(response));
+ assertTrue(data.getUndeployPolicies().isEmpty());
+ verifyResponse();
}
@Test
response.setPdpGroup(DIFFERENT);
assertEquals("group does not match", data.checkResponse(response));
+ assertTrue(data.getUndeployPolicies().isEmpty());
+ verifyResponse();
}
@Test
response.setPdpSubgroup(DIFFERENT);
assertEquals("subgroup does not match", data.checkResponse(response));
+ assertTrue(data.getUndeployPolicies().isEmpty());
+ verifyResponse();
+ }
+
+ @Test
+ public 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));
+ assertTrue(data.getUndeployPolicies().isEmpty());
+ verifyResponse();
}
@Test
response.setPolicies(policies.stream().map(ToscaPolicy::getIdentifier).collect(Collectors.toList()));
assertEquals("policies do not match", data.checkResponse(response));
+ verifyResponse();
+
+ // the first policy from the original update is all that should be undeployed
+ assertEquals(Collections.singleton(update.getPolicies().get(0).getIdentifier()).toString(),
+ data.getUndeployPolicies().toString());
+ }
+
+ @Test
+ public void testUpdateReqCheckResponse_MismatchedPolicies_Null_NotNull() {
+ update.setPolicies(null);
+
+ assertEquals("policies do not match", data.checkResponse(response));
+ assertTrue(data.getUndeployPolicies().isEmpty());
+ verifyResponse();
+ }
+
+ @Test
+ public void testUpdateReqCheckResponse_MismatchedPolicies_NotNull_Null() {
+ response.setPolicies(null);
+
+ assertEquals("policies do not match", data.checkResponse(response));
+ verifyResponse();
+
+ // all policies in the update should be undeployed
+ assertEquals(update.getPolicies().stream().map(ToscaPolicy::getIdentifier).collect(Collectors.toList())
+ .toString(), new TreeSet<>(data.getUndeployPolicies()).toString());
}
@Test
- public void isSameContent() {
+ public void testReconfigure() {
+ // different message type should fail and leave message unchanged
+ assertFalse(data.reconfigure(new PdpStateChange()));
+ assertSame(update, data.getMessage());
+
+ // same content - should succeed, but leave message unchanged
+ PdpUpdate msg2 = new PdpUpdate(update);
+ assertTrue(data.reconfigure(msg2));
+ assertSame(update, data.getMessage());
+
+ // different content - should succeed and install NEW message
+ msg2.setPdpGroup(DIFFERENT);
+ assertTrue(data.reconfigure(msg2));
+ assertSame(msg2, data.getMessage());
+ }
+
+ @Test
+ public void testIsSameContent() {
PdpUpdate msg2 = new PdpUpdate(update);
msg2.setName("world");
- assertTrue(data.isSameContent(new UpdateReq(reqParams, MY_REQ_NAME, msg2)));
+ assertTrue(data.isSameContent(msg2));
- // different request type
- assertFalse(data.isSameContent(new StateChangeReq(reqParams, MY_REQ_NAME, new PdpStateChange())));
+ // both policy lists null
+ update.setPolicies(null);
+ msg2.setPolicies(null);
+ assertTrue(data.isSameContent(msg2));
}
@Test
- public void isSameContent_BothGroupNamesNull() {
+ public void testIsSameContent_BothGroupNamesNull() {
PdpUpdate msg2 = new PdpUpdate(update);
msg2.setPdpGroup(null);
update.setPdpGroup(null);
- assertTrue(data.isSameContent(new UpdateReq(reqParams, MY_REQ_NAME, msg2)));
+ assertTrue(data.isSameContent(msg2));
}
@Test
- public void isSameContent_BothSubGroupNamesNull() {
+ public void testIsSameContent_BothSubGroupNamesNull() {
PdpUpdate msg2 = new PdpUpdate(update);
msg2.setPdpSubgroup(null);
update.setPdpSubgroup(null);
- assertTrue(data.isSameContent(new UpdateReq(reqParams, MY_REQ_NAME, msg2)));
+ assertTrue(data.isSameContent(msg2));
}
@Test
- public void isSameContent_DiffGroup() {
+ public void testIsSameContent_DiffGroup() {
PdpUpdate msg2 = new PdpUpdate(update);
msg2.setPdpGroup(null);
- assertFalse(data.isSameContent(new UpdateReq(reqParams, MY_REQ_NAME, msg2)));
+ assertFalse(data.isSameContent(msg2));
msg2.setPdpGroup(DIFFERENT);
- assertFalse(data.isSameContent(new UpdateReq(reqParams, MY_REQ_NAME, msg2)));
+ assertFalse(data.isSameContent(msg2));
update.setPdpGroup(null);
- assertFalse(data.isSameContent(new UpdateReq(reqParams, MY_REQ_NAME, msg2)));
+ assertFalse(data.isSameContent(msg2));
}
@Test
- public void isSameContent_DiffSubGroup() {
+ public void testIsSameContent_DiffSubGroup() {
PdpUpdate msg2 = new PdpUpdate(update);
msg2.setPdpSubgroup(null);
- assertFalse(data.isSameContent(new UpdateReq(reqParams, MY_REQ_NAME, msg2)));
+ assertFalse(data.isSameContent(msg2));
msg2.setPdpSubgroup(DIFFERENT);
- assertFalse(data.isSameContent(new UpdateReq(reqParams, MY_REQ_NAME, msg2)));
+ assertFalse(data.isSameContent(msg2));
update.setPdpSubgroup(null);
- assertFalse(data.isSameContent(new UpdateReq(reqParams, MY_REQ_NAME, msg2)));
+ assertFalse(data.isSameContent(msg2));
}
@Test
- public void isSameContent_DiffPolicies() {
+ public void testIsSameContent_DiffPolicies() {
PdpUpdate msg2 = new PdpUpdate(update);
ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPolicies());
policies.set(0, makePolicy(DIFFERENT, "10.0.0"));
msg2.setPolicies(policies);
- assertFalse(data.isSameContent(new UpdateReq(reqParams, MY_REQ_NAME, msg2)));
+ assertFalse(data.isSameContent(msg2));
}
@Test
- public void testGetPriority() {
- assertTrue(data.getPriority() > new StateChangeReq(reqParams, MY_REQ_NAME, new PdpStateChange()).getPriority());
+ public void testIsSameContent_DiffPolicies_NotNull_Null() {
+ PdpUpdate msg2 = new PdpUpdate(update);
+ msg2.setPolicies(null);
+
+ assertFalse(data.isSameContent(msg2));
+ }
+
+ @Test
+ public void testIsSameContent_DiffPolicies_Null_NotNull() {
+ PdpUpdate msg2 = new PdpUpdate(update);
+
+ update.setPolicies(null);
+
+ assertFalse(data.isSameContent(msg2));
+ }
+
+ @SuppressWarnings("unchecked")
+ private void verifyResponse() {
+ verify(notifier).processResponse(any(), any(Set.class));
+ }
+
+ @SuppressWarnings("unchecked")
+ private void verifyNoResponse() {
+ verify(notifier, never()).processResponse(any(), any(Set.class));
}
/**