JUnit additions for PAP-REST,REST,XACML 73/33473/3
authorbobbymander <bobby.mander@att.com>
Wed, 28 Feb 2018 21:31:24 +0000 (16:31 -0500)
committerbobbymander <bobby.mander@att.com>
Thu, 1 Mar 2018 13:35:39 +0000 (08:35 -0500)
Issue-ID: POLICY-603
Change-Id: I78c5e302c474613cbb22a80e0d931b4f47dd3b63
Signed-off-by: bobbymander <bobby.mander@att.com>
ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicyTest.java [new file with mode: 0644]
ONAP-REST/src/main/java/org/onap/policy/rest/XACMLRestProperties.java
ONAP-REST/src/test/java/org/onap/policy/rest/XACMLRestTest.java
ONAP-REST/src/test/java/org/onap/policy/rest/adapter/ClosedLoopPolicyAdaptersTest.java
ONAP-XACML/src/main/java/org/onap/policy/xacml/api/XACMLErrorConstants.java
ONAP-XACML/src/test/java/org/onap/policy/xacml/test/api/XACMLErrorConstantsTest.java [new file with mode: 0644]

diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicyTest.java
new file mode 100644 (file)
index 0000000..9c5f71f
--- /dev/null
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PAP-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.pap.xacml.rest.components;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import java.io.IOException;
+import org.onap.policy.rest.adapter.PolicyRestAdapter;
+import com.att.research.xacml.api.pap.PAPException;
+import java.nio.charset.StandardCharsets;
+
+public class ClosedLoopPolicyTest {
+       @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+       @Test
+       public void testConstructor1() {
+               thrown.expect(NullPointerException.class);
+               ClosedLoopPolicy policy = new ClosedLoopPolicy();
+               policy.getCorrectPolicyDataObject();
+       }
+       
+       @Test
+       public void testConstructor2() {
+               PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
+               ClosedLoopPolicy policy = new ClosedLoopPolicy(policyAdapter);
+               assertNull(policy.getCorrectPolicyDataObject());
+       }
+       
+       @Test
+       public void testReadFile() throws IOException {
+               thrown.expect(IOException.class);
+               String read = ClosedLoopPolicy.readFile("/foo",  StandardCharsets.UTF_8);
+               fail("Expecting an exception.");
+       }
+       
+       @Test
+       public void testPrepareToSave() throws PAPException {
+               PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
+               ClosedLoopPolicy policy = new ClosedLoopPolicy(policyAdapter);
+               policyAdapter.setHighestVersion(1);
+               policyAdapter.setPolicyType("Config");
+               policyAdapter.setNewFileName("foo.xml");
+               policy.prepareToSave();
+               assertEquals(policy.isPreparedToSave(), true);
+       }
+}
\ No newline at end of file
index 73cb0f0..e52a411 100644 (file)
@@ -452,4 +452,9 @@ public class XACMLRestProperties extends XACMLProperties {
         * */
        public static final String PROP_PAP_INCOMINGNOTIFICATION_TRIES = "xacml.rest.pap.incomingnotification.tries";
        
+       
+       // Static class, hide constructor
+    private XACMLRestProperties() {
+       super();
+    }
 }
index 419b14d..9b4cc3f 100644 (file)
 
 package org.onap.policy.rest;
 
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -95,6 +99,13 @@ public class XACMLRestTest extends Mockito{
                } catch (Exception e) {
                        fail();
                }
-
+       }
+       
+       @Test
+       public void testConstructorIsPrivate() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
+               Constructor<XACMLRestProperties> constructor = XACMLRestProperties.class.getDeclaredConstructor();
+               assertTrue(Modifier.isPrivate(constructor.getModifiers()));
+               constructor.setAccessible(true);
+               constructor.newInstance();
        }
 }
\ No newline at end of file
index a153efe..320c302 100644 (file)
@@ -21,6 +21,10 @@ package org.onap.policy.rest.adapter;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -164,4 +168,12 @@ public class ClosedLoopPolicyAdaptersTest {
                assertEquals(ClosedLoopPolicyStatus.ACTIVE.toString(), "active");
                assertEquals(ClosedLoopPolicyStatus.INACTIVE.toString(), "inactive");
        }
+       
+       @Test
+       public void testConstructorIsPrivate() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
+         Constructor<ClosedLoopPerformanceMetrics> constructor = ClosedLoopPerformanceMetrics.class.getDeclaredConstructor();
+         assertTrue(Modifier.isPrivate(constructor.getModifiers()));
+         constructor.setAccessible(true);
+         constructor.newInstance();
+       }
 }
index 77c0da4..0cbba2f 100644 (file)
@@ -52,5 +52,9 @@ public class XACMLErrorConstants {
        //Captures all the errors that not related to the list of above error codes
        public static final String ERROR_UNKNOWN = "PE900 - Unknown Error: ";
        
+       // Static class, hide constructor
+    private XACMLErrorConstants() {
+       super();
+    }
 
 }
diff --git a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/api/XACMLErrorConstantsTest.java b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/api/XACMLErrorConstantsTest.java
new file mode 100644 (file)
index 0000000..2214817
--- /dev/null
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-XACML
+ * ================================================================================
+ * 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.xacml.test.api;
+
+import static org.junit.Assert.assertTrue;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
+import org.junit.Test;
+import org.onap.policy.xacml.api.XACMLErrorConstants;
+
+public class XACMLErrorConstantsTest {
+       @Test
+       public void testConstructorIsPrivate1() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
+         Constructor<XACMLErrorConstants> constructor = XACMLErrorConstants.class.getDeclaredConstructor();
+         assertTrue(Modifier.isPrivate(constructor.getModifiers()));
+         constructor.setAccessible(true);
+         constructor.newInstance();
+       }
+}