summaryrefslogtreecommitdiffstats
path: root/ONAP-PDP-REST/src/test/java/org/onap
diff options
context:
space:
mode:
authorMAGNUSEN <dm741q@att.com>2018-02-26 09:19:16 -0600
committerMagnusen, Drew (dm741q) <dm741q@att.com>2018-02-26 13:34:36 -0600
commit40db08bfb61c6cdd48b7ee0388fedb37d354e35b (patch)
treebab04f5bd3e786738bfeefaf5b089ca1a6a4f4ed /ONAP-PDP-REST/src/test/java/org/onap
parentfa54ede568ac252870b5ab4ab00878d471659143 (diff)
Added junits to increase coverage
This commit adds some junits which touch several classes in the notifications package in the ONAP-PDP-REST project. Issue-ID: POLICY-602 Change-Id: Ie99ddd03841d4063aba64781bf08a38d2a25f0ed Signed-off-by: Magnusen, Drew (dm741q) <dm741q@att.com>
Diffstat (limited to 'ONAP-PDP-REST/src/test/java/org/onap')
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java98
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/notifications/test/NotificationTest.java77
2 files changed, 160 insertions, 15 deletions
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java
index e8747f736..3f01f0f94 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -46,10 +46,15 @@ import org.onap.policy.common.im.IntegrityMonitor;
import org.onap.policy.common.im.IntegrityMonitorException;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.policy.rest.XACMLRestProperties;
+import org.onap.policy.xacml.std.pap.StdPDPPolicy;
+import org.onap.policy.xacml.std.pap.StdPDPStatus;
import org.powermock.api.mockito.PowerMockito;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletConfig;
+
+import com.att.research.xacml.util.XACMLProperties;
import com.mockrunner.mock.web.MockServletInputStream;
import junit.framework.TestCase;
@@ -81,10 +86,19 @@ public class XACMLPdpServletTest extends TestCase{
private static final String DEFAULT_DB_USER = "sa";
private static final String DEFAULT_DB_PWD = "";
-
+ private StdPDPStatus status;
+ private StdPDPPolicy foobarPolicy;
+
@Before
public void setUp(){
-
+ status = new StdPDPStatus();
+ foobarPolicy = new StdPDPPolicy();
+ foobarPolicy.setId("foobar");
+ foobarPolicy.setVersion("123");
+ foobarPolicy.setName("nothing");
+ status.addLoadedPolicy(foobarPolicy);
+
+
properties = new Properties();
properties.put(IntegrityAuditProperties.DB_DRIVER, XACMLPdpServletTest.DEFAULT_DB_DRIVER);
properties.put(IntegrityAuditProperties.DB_URL, "jdbc:h2:file:./sql/xacmlTest");
@@ -170,12 +184,13 @@ public class XACMLPdpServletTest extends TestCase{
}
Mockito.doNothing().when(im).endTransaction();
}
-
+
@Test
public void testInit(){
LOGGER.info("XACMLPdpServletTest - testInit");
try {
pdpServlet.init(servletConfig);
+
assertTrue(true);
} catch (Exception e) {
LOGGER.error("Exception Occured"+e);
@@ -184,7 +199,60 @@ public class XACMLPdpServletTest extends TestCase{
}
}
+
+ @Test
+ public void testUebNotification() {
+ System.out.println("drewtest1");
+ LOGGER.info("XACMLPdpServletTest - drewTest1");
+ try {
+
+ XACMLProperties.reloadProperties();
+ System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml.pdp.ueb.properties");
+ XACMLProperties.getProperties();
+ XACMLProperties.setProperty(XACMLRestProperties.PROP_NOTIFICATION_TYPE, "ueb");
+
+ pdpServlet.init(servletConfig);
+
+ status.setStatus(com.att.research.xacml.api.pap.PDPStatus.Status.UPDATING_CONFIGURATION);
+
+ XACMLPdpLoader.validatePolicies(properties, status);
+ XACMLPdpLoader.sendNotification();
+ assertTrue(true);
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured"+e);
+ fail();
+
+ }
+
+ }
+
+ @Test
+ public void testDmaapNotification() {
+ System.out.println("drewtest2");
+ LOGGER.info("XACMLPdpServletTest - drewTest2");
+ try {
+
+ XACMLProperties.reloadProperties();
+ System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml.pdp.dmaap.properties");
+ XACMLProperties.getProperties();
+ XACMLProperties.setProperty(XACMLRestProperties.PROP_NOTIFICATION_TYPE, "dmaap");
+
+ pdpServlet.init(servletConfig);
+
+ status.setStatus(com.att.research.xacml.api.pap.PDPStatus.Status.UPDATING_CONFIGURATION);
+
+ XACMLPdpLoader.validatePolicies(properties, status);
+ XACMLPdpLoader.sendNotification();
+ assertTrue(true);
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured"+e);
+ fail();
+
+ }
+
+ }
+
@Test
public void testDoGetNoTypeError(){
LOGGER.info("XACMLPdpServletTest - testDoGetNoTypeError");
@@ -200,7 +268,7 @@ public class XACMLPdpServletTest extends TestCase{
fail();
}
}
-
+
@Test
public void testDoGetConfigType(){
LOGGER.info("XACMLPdpServletTest - testDoGetConfigType");
@@ -218,7 +286,7 @@ public class XACMLPdpServletTest extends TestCase{
}
}
-
+
@Test
public void testDoGetTypeHb(){
LOGGER.info("XACMLPdpServletTest - testDoGetTypeHb");
@@ -234,7 +302,7 @@ public class XACMLPdpServletTest extends TestCase{
fail();
}
}
-
+
@Test
public void testDoGetTypeStatus(){
LOGGER.info("XACMLPdpServletTest - testDoGetTypeStatus");
@@ -250,7 +318,7 @@ public class XACMLPdpServletTest extends TestCase{
fail();
}
}
-
+
@Test
public void testDoPost(){
LOGGER.info("XACMLPdpServletTest - testDoPost");
@@ -264,7 +332,7 @@ public class XACMLPdpServletTest extends TestCase{
fail();
}
}
-
+
@Test
public void testDoPostToLong(){
LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
@@ -281,7 +349,7 @@ public class XACMLPdpServletTest extends TestCase{
fail();
}
}
-
+
@Test
public void testDoPostContentLengthNegative(){
LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
@@ -298,7 +366,7 @@ public class XACMLPdpServletTest extends TestCase{
fail();
}
}
-
+
@Test
public void testDoPostContentTypeNonValid(){
LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
@@ -315,7 +383,7 @@ public class XACMLPdpServletTest extends TestCase{
fail();
}
}
-
+
@Test
public void testDoPostContentTypeConfigurationError(){
LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
@@ -332,7 +400,7 @@ public class XACMLPdpServletTest extends TestCase{
fail();
}
}
-
+
@Test
public void testDoPutCacheEmpty(){
LOGGER.info("XACMLPdpServletTest - testDoPutCacheEmpty");
@@ -352,7 +420,7 @@ public class XACMLPdpServletTest extends TestCase{
fail();
}
}
-
+
@Test
public void testDoPutConfigPolicies(){
LOGGER.info("XACMLPdpServletTest - testDoPutConfigPolicies");
@@ -413,7 +481,7 @@ public class XACMLPdpServletTest extends TestCase{
fail();
}
}
-
+
@Test
public void testDestroy(){
LOGGER.info("XACMLPdpServletTest - testDestroy");
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/notifications/test/NotificationTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/notifications/test/NotificationTest.java
new file mode 100644
index 000000000..a18f93275
--- /dev/null
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/notifications/test/NotificationTest.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PDP-REST
+ * ================================================================================
+ * Copyright (C) 2018 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.pdp.rest.notifications.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import org.onap.policy.api.NotificationType;
+import org.onap.policy.pdp.rest.notifications.Notification;
+import org.onap.policy.pdp.rest.notifications.Removed;
+import org.onap.policy.pdp.rest.notifications.Updated;
+
+public class NotificationTest {
+
+
+ @Test
+ public void test() {
+ List<Removed> removedPolicies = new ArrayList<>();
+ List<Updated> loadedPolicies = new ArrayList<>();
+
+ Updated u1 = new Updated();
+ Removed r1 = new Removed();
+ Notification n = new Notification();
+
+ u1.setPolicyName("update");
+ u1.setVersionNo("1");
+ u1.setMatches(null);
+ u1.setUpdateType(null);
+
+ assertEquals("update", u1.getPolicyName());
+ assertEquals("1", u1.getVersionNo());
+ assertEquals(null, u1.getMatches());
+ assertEquals(null, u1.getUpdateType());
+
+ loadedPolicies.add(u1);
+
+ r1.setPolicyName("removed");
+ r1.setVersionNo("1");
+ assertEquals(r1.getPolicyName(),"removed");
+ assertEquals(r1.getVersionNo(),"1");
+
+ removedPolicies.add(r1);
+
+ n.setLoadedPolicies(loadedPolicies);
+ n.setRemovedPolicies(removedPolicies);
+ n.setNotificationType(NotificationType.BOTH);
+
+ assertEquals(removedPolicies, n.getRemovedPolicies());
+ assertEquals(loadedPolicies, n.getLoadedPolicies());
+ assertEquals(NotificationType.BOTH, n.getNotificationType());
+
+
+
+ }
+}