aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-REST/src/test/java/org/onap/policy/rest
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-REST/src/test/java/org/onap/policy/rest')
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/XACMLRestTest.java111
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/XacmlAdminAuthorizationTest.java38
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/XacmlRestTest.java303
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/adapter/PolicyRestAdapterTest.java104
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/dao/PolicyDbExceptionTest.java (renamed from ONAP-REST/src/test/java/org/onap/policy/rest/dao/PolicyDBExceptionTest.java)53
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImplTest.java912
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionBodyEntityTest.java70
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionDictionaryJpaTest.java (renamed from ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionDictionaryJPATest.java)181
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/BrmsDictionaryJpaTest.java (renamed from ONAP-REST/src/test/java/org/onap/policy/rest/jpa/BRMSDictionaryJPATest.java)59
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ClosedLoopPolicyDictionaryJpaTest.java (renamed from ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ClosedLoopPolicyDictionaryJPATest.java)114
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/CommonDictionaryJpaTest.java (renamed from ONAP-REST/src/test/java/org/onap/policy/rest/jpa/CommonDictionaryJPATest.java)117
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ConfigurationDataEntityTest.java83
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DecisionDictionaryJpaTest.java (renamed from ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DecisionDictionaryJPATest.java)38
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DictionaryDataTest.java4
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DummyIdentifier.java46
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/FwDictionaryJpaTest.java (renamed from ONAP-REST/src/test/java/org/onap/policy/rest/jpa/FWDictionaryJPATest.java)129
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/GetterSetterToStringTest.java57
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroServiceDictionaryJpaTest.java (renamed from ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroServiceDictionaryJPATest.java)125
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroserviceHeaderdeFaultsTest.java54
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/OptimizationModelsJpaTest.java (renamed from ONAP-REST/src/test/java/org/onap/policy/rest/jpa/OptimizationModelsJPATest.java)26
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PIPConfigurationTest.java121
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PipConfigurationTest.java196
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PipJpaTest.java (renamed from ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PIPJPATest.java)131
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyAuditlogTest.java3
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyEntityJPATest.java206
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyEntityJpaTest.java528
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyUtilsJPATest.java190
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyUtilsJpaTest.java320
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/util/DummyPolicyContainer.java77
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/util/MsAttributeObjectTest.java (renamed from ONAP-REST/src/test/java/org/onap/policy/rest/util/MSAttributeObjectTest.java)13
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/util/MsModelUtilsTest.java (renamed from ONAP-REST/src/test/java/org/onap/policy/rest/util/MSModelUtilsTest.java)47
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/util/PDPPolicyContainerTest.java138
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/util/ParserExceptionTest.java34
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/util/PdpPolicyContainerTest.java267
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/util/PolicyItemSetChangeNotifierTest.java69
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/util/PolicyValidationRequestWrapperTest.java422
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/util/PolicyValidationTest.java1234
37 files changed, 5004 insertions, 1616 deletions
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/XACMLRestTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/XACMLRestTest.java
deleted file mode 100644
index 5b8513823..000000000
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/XACMLRestTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP-REST
- * ================================================================================
- * 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.
- * 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.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;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.springframework.mock.web.MockHttpServletResponse;
-import org.springframework.mock.web.MockServletConfig;
-
-public class XACMLRestTest extends Mockito{
- private static Log logger = LogFactory.getLog(XACMLRestTest.class);
-
- private List<String> headers = new ArrayList<>();
-
- private HttpServletRequest httpServletRequest;
- private HttpServletResponse httpServletResponse;
- private ServletOutputStream mockOutput;
- private ServletConfig servletConfig;
-
-
- @Before
- public void setUp(){
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- Mockito.when(httpServletRequest.getMethod()).thenReturn("POST");
- Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers));
- Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers));
-
- mockOutput = Mockito.mock(ServletOutputStream.class);
-
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
-
- try {
- Mockito.when(httpServletResponse.getOutputStream()).thenReturn(mockOutput);
- } catch (IOException e) {
- fail();
- }
-
- servletConfig = Mockito.mock(MockServletConfig.class);
- Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers));
- Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.pdp.properties");
-
- System.setProperty("xacml.properties", "xacml.pdp.properties");
- System.setProperty("xacml.rest.pdp.config", "config_testing");
- System.setProperty("xacml.rest.pep.idfile", "testclient.properties");
- System.setProperty("xacml.rest.pdp.webapps", "/webapps");
- System.setProperty("xacml.rootPolicies", "test_PolicyEngine.xml");
- System.setProperty("xacml.referencedPolicies", "test_PolicyEngine.xml");
- System.setProperty("test_PolicyEngine.xml.file", "config_testing\\test_PolicyEngine.xml");
- System.setProperty("xacml.rest.pdp.register", "false");
- }
-
- @Test
- public void testXacmlInit(){
- logger.info("XACMLRestTest - testInit");
- try {
- XACMLRest.xacmlInit(servletConfig);
- Logger.getRootLogger().setLevel(Level.DEBUG);
- XACMLRest.dumpRequest(httpServletRequest);
- XACMLRest.loadXacmlProperties(null, null);
- } 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
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/XacmlAdminAuthorizationTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/XacmlAdminAuthorizationTest.java
new file mode 100644
index 000000000..75abb4f53
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/XacmlAdminAuthorizationTest.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+/**
+ * Test the XacmlAdminAuthorizaiton class.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class XacmlAdminAuthorizationTest {
+
+ @Test
+ public void test() {
+ assertNotNull(new XacmlAdminAuthorization());
+ }
+}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/XacmlRestTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/XacmlRestTest.java
new file mode 100644
index 000000000..3b03bdcc8
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/XacmlRestTest.java
@@ -0,0 +1,303 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-REST
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.rest;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import com.att.research.xacml.util.XACMLProperties;
+
+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.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.mock.web.MockServletConfig;
+
+public class XacmlRestTest extends Mockito {
+ private static Log logger = LogFactory.getLog(XacmlRestTest.class);
+
+ private List<String> headers = new ArrayList<>();
+
+ private HttpServletRequest httpServletRequest;
+ private HttpServletResponse httpServletResponse;
+ private ServletOutputStream mockOutput;
+ private ServletConfig servletConfig;
+ private ServletInputStream servletInputStream;
+
+ /**
+ * Prepare for the test.
+ */
+ @Before
+ public void setUp() {
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("POST");
+ Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers));
+ Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers));
+
+ mockOutput = Mockito.mock(ServletOutputStream.class);
+
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+
+ try {
+ Mockito.when(httpServletResponse.getOutputStream()).thenReturn(mockOutput);
+ } catch (IOException e) {
+ fail();
+ }
+
+ servletConfig = Mockito.mock(MockServletConfig.class);
+ Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers));
+ Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.pdp.properties");
+
+ System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "xacml.pdp.properties");
+ System.setProperty("xacml.rest.pdp.config", "config_testing");
+ System.setProperty("xacml.rest.pep.idfile", "testclient.properties");
+ System.setProperty("xacml.rest.pdp.webapps", "/webapps");
+ System.setProperty("xacml.rootPolicies", "test_PolicyEngine.xml");
+ System.setProperty("xacml.referencedPolicies", "test_PolicyEngine.xml");
+ System.setProperty("test_PolicyEngine.xml.file", "config_testing\\test_PolicyEngine.xml");
+ System.setProperty("xacml.rest.pdp.register", "false");
+
+ servletInputStream = Mockito.mock(ServletInputStream.class);
+ }
+
+ @Test
+ public void testXacmlInit() {
+ logger.info("XACMLRestTest - testInit");
+
+ try {
+ XacmlRest.xacmlInit(servletConfig);
+ Logger.getRootLogger().setLevel(Level.DEBUG);
+ XacmlRest.dumpRequest(httpServletRequest);
+ XacmlRest.loadXacmlProperties(null, null);
+ } catch (Exception e) {
+ fail("Normal case of initiation of XACML REST failed");
+ }
+
+ System.clearProperty(XACMLProperties.XACML_PROPERTIES_NAME);
+ try {
+ XacmlRest.xacmlInit(servletConfig);
+ Logger.getRootLogger().setLevel(Level.DEBUG);
+ XacmlRest.dumpRequest(httpServletRequest);
+ XacmlRest.loadXacmlProperties(null, null);
+ } catch (Exception e) {
+ fail("Normal case of initiation of XACML REST failed");
+ }
+
+ System.clearProperty(XACMLProperties.XACML_PROPERTIES_NAME);
+ try {
+ Logger.getRootLogger().setLevel(Level.INFO);
+ XacmlRest.xacmlInit(servletConfig);
+ Logger.getRootLogger().setLevel(Level.DEBUG);
+ XacmlRest.dumpRequest(httpServletRequest);
+ XacmlRest.loadXacmlProperties(null, null);
+ } catch (Exception e) {
+ fail("Normal case of initiation of XACML REST failed");
+ }
+
+ System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "xacml.pdp.properties");
+
+ try {
+ Logger.getRootLogger().setLevel(Level.DEBUG);
+ XacmlRest.xacmlInit(servletConfig);
+ XacmlRest.dumpRequest(httpServletRequest);
+ XacmlRest.loadXacmlProperties(null, null);
+ } catch (Exception e) {
+ fail("Normal case of initiation of XACML REST failed");
+ }
+
+ Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn(null);
+ try {
+ XacmlRest.xacmlInit(servletConfig);
+ Logger.getRootLogger().setLevel(Level.DEBUG);
+ XacmlRest.dumpRequest(httpServletRequest);
+ XacmlRest.loadXacmlProperties(null, null);
+ } catch (Exception e) {
+ fail("Normal case of initiation of XACML REST failed");
+ }
+
+ try {
+ Logger.getRootLogger().setLevel(Level.INFO);
+ XacmlRest.xacmlInit(servletConfig);
+ Logger.getRootLogger().setLevel(Level.DEBUG);
+ XacmlRest.dumpRequest(httpServletRequest);
+ XacmlRest.loadXacmlProperties(null, null);
+ } catch (Exception e) {
+ fail("Normal case of initiation of XACML REST failed");
+ }
+
+ Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.pdp.properties");
+
+ List<String> parNameList = new ArrayList<String>() {
+ private static final long serialVersionUID = 1L;
+
+ {
+ add("Name0");
+ add("Name1");
+ add("Name2");
+ add("XACML_PROPERTIES_NAME");
+ }
+ };
+
+ Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(parNameList));
+ Mockito.when(servletConfig.getInitParameter("Name0")).thenReturn("Value0");
+ Mockito.when(servletConfig.getInitParameter("Name1")).thenReturn("Value1");
+ Mockito.when(servletConfig.getInitParameter("Name2")).thenReturn("Value2");
+ try {
+ XacmlRest.xacmlInit(servletConfig);
+ Logger.getRootLogger().setLevel(Level.DEBUG);
+ XacmlRest.dumpRequest(httpServletRequest);
+ XacmlRest.loadXacmlProperties(null, null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Normal case of initiation of XACML REST failed");
+ }
+
+ }
+
+ @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();
+ }
+
+ @Test
+ public void testLoadXacmlProperties() {
+ XacmlRest.xacmlInit(servletConfig);
+ XacmlRest.loadXacmlProperties(null, null);
+
+ XacmlRest.loadXacmlProperties(new Properties(), new Properties());
+
+ Logger.getRootLogger().setLevel(Level.INFO);
+ XacmlRest.loadXacmlProperties(new Properties(), new Properties());
+ }
+
+ @Test
+ public void testDumpRequest() throws IOException {
+ XacmlRest.xacmlInit(servletConfig);
+
+ Logger.getRootLogger().setLevel(Level.INFO);
+ XacmlRest.dumpRequest(httpServletRequest);
+ Logger.getRootLogger().setLevel(Level.DEBUG);
+
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("GET");
+ XacmlRest.dumpRequest(httpServletRequest);
+ Mockito.when(httpServletRequest.getParameter("type")).thenReturn("hb");
+ XacmlRest.dumpRequest(httpServletRequest);
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("POST");
+
+ List<String> headerNameList = new ArrayList<String>() {
+ private static final long serialVersionUID = 1L;
+
+ {
+ add("Name0");
+ add("Name1");
+ }
+ };
+
+ List<String> header0List = new ArrayList<String>() {
+ private static final long serialVersionUID = 1L;
+
+ {
+ add("Name0H0");
+ add("Name0H1");
+ add("Name0H2");
+ }
+ };
+
+ List<String> header1List = new ArrayList<String>() {
+ private static final long serialVersionUID = 1L;
+
+ {
+ add("Name1H0");
+ add("Name1H1");
+ add("Name1H2");
+ }
+ };
+
+ Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headerNameList));
+ Mockito.when(httpServletRequest.getHeaders("Name0")).thenReturn(Collections.enumeration(header0List));
+ Mockito.when(httpServletRequest.getHeaders("Name1")).thenReturn(Collections.enumeration(header1List));
+ XacmlRest.dumpRequest(httpServletRequest);
+
+ List<String> attributeList = new ArrayList<String>() {
+ private static final long serialVersionUID = 1L;
+
+ {
+ add("Attribute0");
+ add("Attribute1");
+ }
+ };
+ Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(attributeList));
+ Mockito.when(httpServletRequest.getAttribute("Attribute0")).thenReturn("AttributeValue0");
+ Mockito.when(httpServletRequest.getAttribute("Attribute1")).thenReturn("AttributeValue1");
+ XacmlRest.dumpRequest(httpServletRequest);
+
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(servletInputStream);
+ XacmlRest.dumpRequest(httpServletRequest);
+
+ Mockito.when(httpServletRequest.getInputStream()).thenThrow(new IOException());
+ XacmlRest.dumpRequest(httpServletRequest);
+
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
+ XacmlRest.dumpRequest(httpServletRequest);
+
+ Map<String, String[]> parameterMap = new LinkedHashMap<>();
+ String[] mapValue0 =
+ { "MapValue0" };
+ String[] mapValue1 =
+ { "MapValue0" };
+ String[] mapValue2 =
+ {};
+ parameterMap.put("Key0", mapValue0);
+ parameterMap.put("Key1", mapValue1);
+ parameterMap.put("Key2", mapValue2);
+
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("DELETE");
+ Mockito.when(httpServletRequest.getParameterMap()).thenReturn(parameterMap);
+ XacmlRest.dumpRequest(httpServletRequest);
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("POST");
+ }
+}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/PolicyRestAdapterTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/PolicyRestAdapterTest.java
index 971614359..61a63ce0c 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/PolicyRestAdapterTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/PolicyRestAdapterTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
@@ -19,6 +19,8 @@
*/
package org.onap.policy.rest.adapter;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
@@ -31,14 +33,14 @@ import org.onap.policy.rest.jpa.OnapName;
public class PolicyRestAdapterTest {
@Test
- public void testPolicyExportAdapter(){
+ public void testPolicyExportAdapter() {
PolicyExportAdapter adapter = new PolicyExportAdapter();
adapter.setPolicyDatas(new ArrayList<>());
assertTrue(adapter.getPolicyDatas() != null);
}
@Test
- public void testPolicyRestAdapter(){
+ public void testPolicyRestAdapter() {
PolicyRestAdapter adapter = new PolicyRestAdapter();
adapter.setData(new Object());
assertTrue(adapter.getData() != null);
@@ -115,27 +117,27 @@ public class PolicyRestAdapterTest {
adapter.setExistingCLName("Test");
assertTrue("Test".equals(adapter.getExistingCLName()));
adapter.setOnapNameField(new OnapName());
- assertTrue(adapter.getOnapNameField()!=null);
+ assertTrue(adapter.getOnapNameField() != null);
adapter.setJsonBodyData(new Object());
- assertTrue(adapter.getJsonBodyData()!=null);
+ assertTrue(adapter.getJsonBodyData() != null);
adapter.setDirPath("Test");
assertTrue("Test".equals(adapter.getDirPath()));
adapter.setConfigBodyPath("Test");
assertTrue("Test".equals(adapter.getConfigBodyPath()));
adapter.setAttributes(new ArrayList<>());
- assertTrue(adapter.getAttributes()!=null);
+ assertTrue(adapter.getAttributes() != null);
adapter.setSettings(new ArrayList<>());
- assertTrue(adapter.getSettings()!=null);
+ assertTrue(adapter.getSettings() != null);
adapter.setRuleAlgorithmschoices(new ArrayList<>());
- assertTrue(adapter.getRuleAlgorithmschoices()!=null);
+ assertTrue(adapter.getRuleAlgorithmschoices() != null);
adapter.setServiceTypePolicyName(new HashMap<>());
- assertTrue(adapter.getServiceTypePolicyName()!=null);
+ assertTrue(adapter.getServiceTypePolicyName() != null);
adapter.setVerticaMetrics(new HashMap<>());
- assertTrue(adapter.getVerticaMetrics()!=null);
+ assertTrue(adapter.getVerticaMetrics() != null);
adapter.setDescription(new LinkedHashMap<>());
- assertTrue(adapter.getVerticaMetrics()!=null);
+ assertTrue(adapter.getVerticaMetrics() != null);
adapter.setAttributeFields(new LinkedHashMap<>());
- assertTrue(adapter.getAttributeFields()!=null);
+ assertTrue(adapter.getAttributeFields() != null);
adapter.setClearTimeOut("Test");
assertTrue("Test".equals(adapter.getClearTimeOut()));
adapter.setTrapMaxAge("Test");
@@ -143,15 +145,15 @@ public class PolicyRestAdapterTest {
adapter.setVerificationclearTimeOut("Test");
assertTrue("Test".equals(adapter.getVerificationclearTimeOut()));
adapter.setDynamicLayoutMap(new HashMap<>());
- assertTrue(adapter.getDynamicLayoutMap()!=null);
+ assertTrue(adapter.getDynamicLayoutMap() != null);
adapter.setTrapDatas(new ClosedLoopFaultTrapDatas());
- assertTrue(adapter.getTrapDatas()!=null);
+ assertTrue(adapter.getTrapDatas() != null);
adapter.setFaultDatas(new ClosedLoopFaultTrapDatas());
- assertTrue(adapter.getFaultDatas()!=null);
+ assertTrue(adapter.getFaultDatas() != null);
adapter.setFwPolicyType("Test");
assertTrue("Test".equals(adapter.getFwPolicyType()));
adapter.setFwattributes(new ArrayList<>());
- assertTrue(adapter.getFwattributes()!=null);
+ assertTrue(adapter.getFwattributes() != null);
adapter.setParentForChild("Test");
assertTrue("Test".equals(adapter.getParentForChild()));
adapter.setSecurityZone("Test");
@@ -159,27 +161,27 @@ public class PolicyRestAdapterTest {
adapter.setRuleCombiningAlgId("Test");
assertTrue("Test".equals(adapter.getRuleCombiningAlgId()));
adapter.setDynamicFieldConfigAttributes(new HashMap<>());
- assertTrue(adapter.getDynamicFieldConfigAttributes()!=null);
+ assertTrue(adapter.getDynamicFieldConfigAttributes() != null);
adapter.setDynamicSettingsMap(new HashMap<>());
- assertTrue(adapter.getDynamicSettingsMap()!=null);
+ assertTrue(adapter.getDynamicSettingsMap() != null);
adapter.setDropDownMap(new HashMap<>());
- assertTrue(adapter.getDropDownMap()!=null);
+ assertTrue(adapter.getDropDownMap() != null);
adapter.setActionPerformer("Test");
assertTrue("Test".equals(adapter.getActionPerformer()));
adapter.setActionAttribute("Test");
assertTrue("Test".equals(adapter.getActionAttribute()));
adapter.setDynamicRuleAlgorithmLabels(new ArrayList<>());
- assertTrue(adapter.getDynamicRuleAlgorithmLabels()!=null);
+ assertTrue(adapter.getDynamicRuleAlgorithmLabels() != null);
adapter.setDynamicRuleAlgorithmCombo(new ArrayList<>());
- assertTrue(adapter.getDynamicRuleAlgorithmCombo()!=null);
+ assertTrue(adapter.getDynamicRuleAlgorithmCombo() != null);
adapter.setDynamicRuleAlgorithmField1(new ArrayList<>());
- assertTrue(adapter.getDynamicRuleAlgorithmField1()!=null);
+ assertTrue(adapter.getDynamicRuleAlgorithmField1() != null);
adapter.setDynamicRuleAlgorithmField2(new ArrayList<>());
- assertTrue(adapter.getDynamicRuleAlgorithmField2()!=null);
+ assertTrue(adapter.getDynamicRuleAlgorithmField2() != null);
adapter.setDynamicVariableList(new ArrayList<>());
- assertTrue(adapter.getDynamicVariableList()!=null);
+ assertTrue(adapter.getDynamicVariableList() != null);
adapter.setDataTypeList(new ArrayList<>());
- assertTrue(adapter.getDataTypeList()!=null);
+ assertTrue(adapter.getDataTypeList() != null);
adapter.setActionAttributeValue("Test");
assertTrue("Test".equals(adapter.getActionAttributeValue()));
adapter.setRuleProvider("Test");
@@ -195,15 +197,15 @@ public class PolicyRestAdapterTest {
adapter.setActionDictMethod("Test");
assertTrue("Test".equals(adapter.getActionDictMethod()));
adapter.setYamlparams(new YAMLParams());
- assertTrue(adapter.getYamlparams()!=null);
+ assertTrue(adapter.getYamlparams() != null);
adapter.setRainyday(new RainyDayParams());
- assertTrue(adapter.getRainyday()!=null);
+ assertTrue(adapter.getRainyday() != null);
adapter.setRainydayMap(new HashMap<>());
- assertTrue(adapter.getRainydayMap()!=null);
+ assertTrue(adapter.getRainydayMap() != null);
adapter.setErrorCodeList(new ArrayList<>());
- assertTrue(adapter.getErrorCodeList()!=null);
+ assertTrue(adapter.getErrorCodeList() != null);
adapter.setTreatmentList(new ArrayList<>());
- assertTrue(adapter.getTreatmentList()!=null);
+ assertTrue(adapter.getTreatmentList() != null);
adapter.setServiceType("Test");
assertTrue("Test".equals(adapter.getServiceType()));
adapter.setUuid("Test");
@@ -219,17 +221,17 @@ public class PolicyRestAdapterTest {
adapter.setRuleName("Test");
assertTrue("Test".equals(adapter.getRuleName()));
adapter.setBrmsParamBody(new HashMap<>());
- assertTrue(adapter.getBrmsParamBody()!=null);
+ assertTrue(adapter.getBrmsParamBody() != null);
adapter.setBrmsController("Test");
assertTrue("Test".equals(adapter.getBrmsController()));
adapter.setBrmsDependency(new ArrayList<>());
- assertTrue(adapter.getBrmsDependency()!=null);
+ assertTrue(adapter.getBrmsDependency() != null);
adapter.setRuleData(new LinkedHashMap<>());
- assertTrue(adapter.getRuleData()!=null);
+ assertTrue(adapter.getRuleData() != null);
adapter.setRuleListData(new LinkedHashMap<>());
- assertTrue(adapter.getRuleListData()!=null);
+ assertTrue(adapter.getRuleListData() != null);
adapter.setDrlRuleAndUIParams(new LinkedHashMap<>());
- assertTrue(adapter.getDrlRuleAndUIParams()!=null);
+ assertTrue(adapter.getDrlRuleAndUIParams() != null);
adapter.setPolicyScope("Test");
assertTrue("Test".equals(adapter.getPolicyScope()));
adapter.setProviderComboBox("Test");
@@ -243,11 +245,11 @@ public class PolicyRestAdapterTest {
adapter.setTtlDate("Test");
assertTrue("Test".equals(adapter.getTtlDate()));
adapter.setMatching(new LinkedHashMap<>());
- assertTrue(adapter.getMatching()!=null);
+ assertTrue(adapter.getMatching() != null);
adapter.setTriggerSignatures(new ArrayList<>());
- assertTrue(adapter.getTriggerSignatures()!=null);
+ assertTrue(adapter.getTriggerSignatures() != null);
adapter.setSymptomSignatures(new ArrayList<>());
- assertTrue(adapter.getSymptomSignatures()!=null);
+ assertTrue(adapter.getSymptomSignatures() != null);
adapter.setLogicalConnector("Test");
assertTrue("Test".equals(adapter.getLogicalConnector()));
adapter.setPolicyStatus("Test");
@@ -257,4 +259,26 @@ public class PolicyRestAdapterTest {
adapter.setSupressionType("Test");
assertTrue("Test".equals(adapter.getSupressionType()));
}
+
+ @Test
+ public void testPublic() {
+ PolicyRestAdapter adapter = new PolicyRestAdapter();
+ adapter.setupUsingAttribute("ONAPName", "onapvalue");
+ adapter.setupUsingAttribute("RiskType", "riskvalue");
+ adapter.setupUsingAttribute("RiskLevel", "risklevel");
+ adapter.setupUsingAttribute("guard", "guardvalue");
+ adapter.setupUsingAttribute("ConfigName", "configvalue");
+ adapter.setupUsingAttribute("uuid", "uuidvalue");
+ adapter.setupUsingAttribute("location", "locationvalue");
+ assertEquals("riskvalue", adapter.getRiskType());
+ assertEquals("risklevel", adapter.getRiskLevel());
+ assertEquals("guardvalue", adapter.getGuard());
+ assertEquals("onapvalue", adapter.getOnapName());
+ assertEquals("onapvalue", adapter.getOnapNameField().getName());
+ assertEquals("uuidvalue", adapter.getUuid());
+ assertEquals("locationvalue", adapter.getLocation());
+ assertEquals("configvalue", adapter.getConfigName());
+
+ assertFalse(adapter.setupUsingAttribute("foobar", "foo"));
+ }
}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/dao/PolicyDBExceptionTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/dao/PolicyDbExceptionTest.java
index 0cd89a40e..5293477e8 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/dao/PolicyDBExceptionTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/dao/PolicyDbExceptionTest.java
@@ -3,13 +3,14 @@
* PolicyEngineUtils
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -23,32 +24,32 @@ package org.onap.policy.rest.dao;
import java.io.IOException;
import org.junit.Test;
-public class PolicyDBExceptionTest {
- @Test(expected = PolicyDBException.class)
- public void testException1() throws PolicyDBException {
- throw new PolicyDBException();
- }
+public class PolicyDbExceptionTest {
+ @Test(expected = PolicyDbException.class)
+ public void testException1() throws PolicyDbException {
+ throw new PolicyDbException();
+ }
- @Test(expected = PolicyDBException.class)
- public void testException2() throws PolicyDBException {
- throw new PolicyDBException("test");
- }
+ @Test(expected = PolicyDbException.class)
+ public void testException2() throws PolicyDbException {
+ throw new PolicyDbException("test");
+ }
- @Test(expected = PolicyDBException.class)
- public void testException3() throws PolicyDBException {
- Throwable cause = new IOException();
- throw new PolicyDBException(cause);
- }
+ @Test(expected = PolicyDbException.class)
+ public void testException3() throws PolicyDbException {
+ Throwable cause = new IOException();
+ throw new PolicyDbException(cause);
+ }
- @Test(expected = PolicyDBException.class)
- public void testException4() throws PolicyDBException {
- Throwable cause = new IOException();
- throw new PolicyDBException("test", cause);
- }
+ @Test(expected = PolicyDbException.class)
+ public void testException4() throws PolicyDbException {
+ Throwable cause = new IOException();
+ throw new PolicyDbException("test", cause);
+ }
- @Test(expected = PolicyDBException.class)
- public void testException5() throws PolicyDBException {
- Throwable cause = new IOException();
- throw new PolicyDBException("test", cause, true, true);
- }
+ @Test(expected = PolicyDbException.class)
+ public void testException5() throws PolicyDbException {
+ Throwable cause = new IOException();
+ throw new PolicyDbException("test", cause, true, true);
+ }
}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImplTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImplTest.java
index f5d968b14..3cedd2312 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImplTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImplTest.java
@@ -3,13 +3,15 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications copyright (c) 2019 Nokia
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -17,11 +19,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.rest.daoimpl;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
+import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -31,411 +41,633 @@ import javax.script.SimpleBindings;
import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
import org.h2.tools.Server;
+import org.hibernate.Query;
+import org.hibernate.Session;
import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
import org.junit.After;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
-//import org.onap.policy.conf.HibernateSession;
-//import org.onap.policy.controller.PolicyController;
import org.onap.policy.rest.jpa.OnapName;
import org.onap.policy.rest.jpa.PolicyEntity;
import org.onap.policy.rest.jpa.PolicyRoles;
import org.onap.policy.rest.jpa.PolicyVersion;
-import org.onap.policy.rest.jpa.SystemLogDB;
+import org.onap.policy.rest.jpa.SystemLogDb;
import org.onap.policy.rest.jpa.UserInfo;
import org.onap.policy.rest.jpa.WatchPolicyNotificationTable;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
-import org.springframework.transaction.annotation.Transactional;
import org.springframework.test.annotation.Rollback;
-
+import org.springframework.transaction.annotation.Transactional;
public class PolicyValidationDaoImplTest {
private static Logger logger = FlexLogger.getLogger(PolicyValidationDaoImplTest.class);
- SessionFactory sessionFactory;
- Server server;
- PolicyValidationDaoImpl commonClassDao;
-
- @Before
- public void setUp() throws Exception{
- try{
- BasicDataSource dataSource = new BasicDataSource();
- dataSource.setDriverClassName("org.h2.Driver");
- // In-memory DB for testing
- dataSource.setUrl("jdbc:h2:mem:test");
- dataSource.setUsername("sa");
- dataSource.setPassword("");
- LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
- sessionBuilder.scanPackages("org.onap.*", "com.*");
-
- Properties properties = new Properties();
- properties.put("hibernate.show_sql", "false");
- properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
- properties.put("hibernate.hbm2ddl.auto", "drop");
- properties.put("hibernate.hbm2ddl.auto", "create");
-
- sessionBuilder.addProperties(properties);
- sessionFactory = sessionBuilder.buildSessionFactory();
-
- // Set up dao with SessionFactory
- commonClassDao = new PolicyValidationDaoImpl();
- PolicyValidationDaoImpl.setSessionfactory(sessionFactory);
- //PolicyController.setLogTableLimit("1");
- //HibernateSession.setSession(sessionFactory);
- SystemLogDB data1 = new SystemLogDB();
- data1.setDate(new Date());
- data1.setLogtype("INFO");
- data1.setRemote("Test");
- data1.setSystem("Test");
- data1.setType("Test");
- SystemLogDB data2 = new SystemLogDB();
- data2.setDate(new Date());
- data2.setLogtype("error");
- data2.setRemote("Test");
- data2.setSystem("Test");
- data2.setType("Test");
- //HibernateSession.getSession().save(data1);
- //HibernateSession.getSession().save(data2);
-
- // Create TCP server for troubleshooting
- server = Server.createTcpServer("-tcpAllowOthers").start();
- System.out.println("URL: jdbc:h2:" + server.getURL() + "/mem:test");
-
- }catch(Exception e){
- System.err.println(e);
- fail();
- }
+ static SessionFactory sessionFactory;
+ static Server server;
+ static PolicyValidationDaoImpl commonClassDao;
+
+ /**
+ * Set up all unit tests.
+ *
+ * @throws SQLException on SQL exceptions
+ */
+ @BeforeClass
+ public static void setupAll() throws SQLException {
+ BasicDataSource dataSource = new BasicDataSource();
+ dataSource.setDriverClassName("org.h2.Driver");
+ // In-memory DB for testing
+ dataSource.setUrl("jdbc:h2:mem:test");
+ dataSource.setUsername("sa");
+ dataSource.setPassword("");
+ LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
+ sessionBuilder.scanPackages("org.onap.*", "com.*");
+
+ Properties properties = new Properties();
+ properties.put("hibernate.show_sql", "false");
+ properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
+ properties.put("hibernate.hbm2ddl.auto", "drop");
+ properties.put("hibernate.hbm2ddl.auto", "create");
+
+ sessionBuilder.addProperties(properties);
+ sessionFactory = sessionBuilder.buildSessionFactory();
+
+ // Set up dao with SessionFactory
+ commonClassDao = new PolicyValidationDaoImpl();
+ PolicyValidationDaoImpl.setSessionfactory(sessionFactory);
+ // PolicyController.setLogTableLimit("1");
+ // HibernateSession.setSession(sessionFactory);
+ SystemLogDb data1 = new SystemLogDb();
+ data1.setDate(new Date());
+ data1.setLogtype("INFO");
+ data1.setRemote("Test");
+ data1.setSystem("Test");
+ data1.setType("Test");
+ SystemLogDb data2 = new SystemLogDb();
+ data2.setDate(new Date());
+ data2.setLogtype("error");
+ data2.setRemote("Test");
+ data2.setSystem("Test");
+ data2.setType("Test");
+
+ // Create TCP server for troubleshooting
+ server = Server.createTcpServer("-tcpAllowOthers").start();
+ System.out.println("URL: jdbc:h2:" + server.getURL() + "/mem:test");
+ }
+
+ @AfterClass
+ public static void deleteDB() {
+ sessionFactory.close();
+ server.stop();
+ }
+
+ @After
+ public void tearDown() {
+ truncateAllTables();
}
@Test
@Transactional
@Rollback(true)
- public void testDB(){
- try{
- // Add data
- UserInfo userinfo = new UserInfo();
- userinfo.setUserLoginId("Test");
- userinfo.setUserName("Test");
- commonClassDao.save(userinfo);
- OnapName onapName = new OnapName();
- onapName.setOnapName("Test");
- onapName.setUserCreatedBy(userinfo);
- onapName.setUserModifiedBy(userinfo);
- onapName.setModifiedDate(new Date());
- commonClassDao.save(onapName);
-
-
- List<Object> list = commonClassDao.getData(OnapName.class);
- assertTrue(list.size() == 1);
- logger.debug(list.size());
- logger.debug(list.get(0));
- }catch(Exception e){
- logger.debug("Exception Occured"+e);
- fail();
- }
+ public void testDB() {
+ // Add data
+ UserInfo userinfo = new UserInfo();
+ userinfo.setUserLoginId("Test");
+ userinfo.setUserName("Test");
+ commonClassDao.save(userinfo);
+ OnapName onapName = new OnapName();
+ onapName.setName("Test");
+ onapName.setUserCreatedBy(userinfo);
+ onapName.setUserModifiedBy(userinfo);
+ onapName.setModifiedDate(new Date());
+ commonClassDao.save(onapName);
+
+ List<Object> list = commonClassDao.getData(OnapName.class);
+ assertTrue(list.size() == 1);
+ logger.debug(list.size());
+ logger.debug(list.get(0));
}
@Test
@Transactional
@Rollback(true)
- public void testUser(){
- try{
- // Add data
- UserInfo userinfo = new UserInfo();
- String loginId_userName = "Test";
- userinfo.setUserLoginId(loginId_userName);
- userinfo.setUserName(loginId_userName);
- commonClassDao.save(userinfo);
-
-
- List<Object> dataCur = commonClassDao.getDataByQuery("from UserInfo", new SimpleBindings());
-
- assertEquals(1, dataCur.size());
- UserInfo cur = (UserInfo) dataCur.get(0);
- assertEquals(loginId_userName, cur.getUserLoginId());
- assertEquals(loginId_userName, cur.getUserName());
-
- assertFalse(dataCur.isEmpty());
-
- }catch(Exception e){
- logger.debug("Exception Occured"+e);
- fail();
- }
+ public void testUser() {
+ // Add data
+ UserInfo userinfo = new UserInfo();
+ String loginIdUserName = "Test";
+ userinfo.setUserLoginId(loginIdUserName);
+ userinfo.setUserName(loginIdUserName);
+ commonClassDao.save(userinfo);
+
+ List<Object> dataCur = commonClassDao.getDataByQuery("from UserInfo", new SimpleBindings());
+
+ assertEquals(1, dataCur.size());
+ UserInfo cur = (UserInfo) dataCur.get(0);
+ assertEquals(loginIdUserName, cur.getUserLoginId());
+ assertEquals(loginIdUserName, cur.getUserName());
+
+ assertFalse(dataCur.isEmpty());
}
@Test
@Transactional
@Rollback(true)
- public void getDataByQuery_DashboardController(){
- try{
- // Add data
- PolicyEntity pe = new PolicyEntity();
- String name = "TestPolicy";
- pe.setPolicyName(name);
- pe.setPolicyData("dummyData");
- pe.prePersist();
- pe.setScope("dummyScope");
- pe.setDescription("descr");
- pe.setDeleted(false);
- pe.setCreatedBy("Test");
- commonClassDao.save(pe);
-
- List<Object> dataCur = commonClassDao.getDataByQuery("from PolicyEntity", new SimpleBindings());
-
- assertTrue(1 == dataCur.size());
- assertTrue( dataCur.get(0) instanceof PolicyEntity);
- assertEquals( name, ((PolicyEntity)dataCur.get(0)).getPolicyName());
- assertEquals( pe, ((PolicyEntity)dataCur.get(0)));
-
-
- }catch(Exception e){
- logger.debug("Exception Occured"+e);
- fail();
- }
+ public void getDataByQuery_DashboardController() {
+ // Add data
+ PolicyEntity pe = new PolicyEntity();
+ String name = "TestPolicy";
+ pe.setPolicyName(name);
+ pe.setPolicyData("dummyData");
+ pe.prePersist();
+ pe.setScope("dummyScope");
+ pe.setDescription("descr");
+ pe.setDeleted(false);
+ pe.setCreatedBy("Test");
+ commonClassDao.save(pe);
+
+ List<Object> dataCur = commonClassDao.getDataByQuery("from PolicyEntity", new SimpleBindings());
+
+ assertTrue(1 == dataCur.size());
+ assertTrue(dataCur.get(0) instanceof PolicyEntity);
+ assertEquals(name, ((PolicyEntity) dataCur.get(0)).getPolicyName());
+ assertEquals(pe, (dataCur.get(0)));
}
@Test
@Transactional
@Rollback(true)
- public void getDataByQuery_AutoPushController(){
- try{
- // Add data
- PolicyVersion pv = new PolicyVersion();
- pv.setActiveVersion(2);
- pv.setPolicyName("myPname");
- pv.prePersist();
- pv.setCreatedBy("Test");
- pv.setModifiedBy("Test");
-
- PolicyVersion pv2 = new PolicyVersion();
- pv2.setActiveVersion(1);
- pv2.setPolicyName("test");
- pv2.prePersist();
- pv2.setCreatedBy("Test");
- pv2.setModifiedBy("Test");
-
- commonClassDao.save(pv);
- commonClassDao.save(pv2);
-
- String scope = "my";
- scope += "%";
- String query = "From PolicyVersion where policy_name like :scope and id > 0";
- SimpleBindings params = new SimpleBindings();
- params.put("scope", scope);
- List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
-
-
- assertTrue(1 == dataCur.size());
- assertEquals(pv, (PolicyVersion) dataCur.get(0));
-
- }catch(Exception e){
- logger.debug("Exception Occured"+e);
- fail();
- }
+ public void getDataByQuery_AutoPushController() {
+ // Add data
+ PolicyVersion pv = new PolicyVersion();
+ pv.setActiveVersion(2);
+ pv.setPolicyName("myPname");
+ pv.prePersist();
+ pv.setCreatedBy("Test");
+ pv.setModifiedBy("Test");
+
+ PolicyVersion pv2 = new PolicyVersion();
+ pv2.setActiveVersion(1);
+ pv2.setPolicyName("test");
+ pv2.prePersist();
+ pv2.setCreatedBy("Test");
+ pv2.setModifiedBy("Test");
+
+ commonClassDao.save(pv);
+ commonClassDao.save(pv2);
+
+ String scope = "my";
+ scope += "%";
+ String query = "From PolicyVersion where policy_name like :scope and id > 0";
+ SimpleBindings params = new SimpleBindings();
+ params.put("scope", scope);
+ List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
+
+ assertTrue(1 == dataCur.size());
+ assertEquals(pv, dataCur.get(0));
}
@Test
@Transactional
@Rollback(true)
- public void getDataByQuery_PolicyNotificationMail(){
- try{
- // Add data
- WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
- String policyFileName = "banana";
- watch.setLoginIds("Test");
- watch.setPolicyName("bananaWatch");
- commonClassDao.save(watch);
-
- if(policyFileName.contains("/")){
- policyFileName = policyFileName.substring(0, policyFileName.indexOf("/"));
- policyFileName = policyFileName.replace("/", File.separator);
- }
- if(policyFileName.contains("\\")){
- policyFileName = policyFileName.substring(0, policyFileName.indexOf("\\"));
- policyFileName = policyFileName.replace("\\", "\\\\");
- }
-
-
- // Current Implementation
- policyFileName += "%";
- String query = "from WatchPolicyNotificationTable where policyName like:policyFileName";
- SimpleBindings params = new SimpleBindings();
- params.put("policyFileName", policyFileName);
- List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
-
- // Assertions
- assertTrue(dataCur.size() == 1);
- assertTrue(dataCur.get(0) instanceof WatchPolicyNotificationTable);
- assertEquals(watch, (WatchPolicyNotificationTable) dataCur.get(0));
-
- }catch(Exception e){
- logger.debug("Exception Occured"+e);
- fail();
+ public void getDataByQuery_PolicyNotificationMail() {
+ // Add data
+ WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
+ watch.setLoginIds("Test");
+
+ // Add data
+ UserInfo userinfo = new UserInfo();
+ String loginIdUserName = "Test";
+ userinfo.setUserLoginId(loginIdUserName);
+ userinfo.setUserName(loginIdUserName);
+ commonClassDao.save(userinfo);
+
+ List<Object> dataCur = commonClassDao.getDataByQuery("from UserInfo", new SimpleBindings());
+
+ assertEquals(1, dataCur.size());
+ UserInfo cur = (UserInfo) dataCur.get(0);
+ assertEquals(loginIdUserName, cur.getUserLoginId());
+ assertEquals(loginIdUserName, cur.getUserName());
+
+ assertFalse(dataCur.isEmpty());
+
+ watch.setPolicyName("bananaWatch");
+ commonClassDao.save(watch);
+
+ String policyFileName = "banana";
+ if (policyFileName.contains("/")) {
+ policyFileName = policyFileName.substring(0, policyFileName.indexOf("/"));
+ policyFileName = policyFileName.replace("/", File.separator);
+ }
+ if (policyFileName.contains("\\")) {
+ policyFileName = policyFileName.substring(0, policyFileName.indexOf("\\"));
+ policyFileName = policyFileName.replace("\\", "\\\\");
}
- }
+ // Current Implementation
+ policyFileName += "%";
+ String query = "from WatchPolicyNotificationTable where policyName like:policyFileName";
+ SimpleBindings params = new SimpleBindings();
+ params.put("policyFileName", policyFileName);
+ dataCur = commonClassDao.getDataByQuery(query, params);
+
+ // Assertions
+ assertTrue(dataCur.size() == 1);
+ assertTrue(dataCur.get(0) instanceof WatchPolicyNotificationTable);
+ assertEquals(watch, dataCur.get(0));
+ }
@Test
@Transactional
@Rollback(true)
- public void getDataByQuery_PolicyController(){
- try{
- // Add data
- PolicyEntity pe = new PolicyEntity();
- String name = "actionDummy";
- pe.setPolicyName(name);
- pe.setPolicyData("dummyData");
- pe.prePersist();
- pe.setScope("dummyScope");
- pe.setDescription("descr");
- pe.setDeleted(false);
- pe.setCreatedBy("Test");
- commonClassDao.save(pe);
-
- String dbCheckName = "dummyScope:action";
- String[] splitDBCheckName = dbCheckName.split(":");
-
-
- // Current Implementation
- String query = "FROM PolicyEntity where policyName like :splitDBCheckName1 and scope = :splitDBCheckName0";
- SimpleBindings params = new SimpleBindings();
- params.put("splitDBCheckName1", splitDBCheckName[1] + "%");
- params.put("splitDBCheckName0", splitDBCheckName[0]);
- List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
-
- // Assertions
- assertTrue(dataCur.size() == 1);
- assertTrue(dataCur.get(0) instanceof PolicyEntity);
- assertEquals(pe, (PolicyEntity) dataCur.get(0));
-
- }catch(Exception e){
- logger.debug("Exception Occured"+e);
- fail();
- }
+ public void getDataByQuery_PolicyController() {
+ // Add data
+ PolicyEntity pe = new PolicyEntity();
+ String name = "actionDummy";
+ pe.setPolicyName(name);
+ pe.setPolicyData("dummyData");
+ pe.prePersist();
+ pe.setScope("dummyScope");
+ pe.setDescription("descr");
+ pe.setDeleted(false);
+ pe.setCreatedBy("Test");
+ commonClassDao.save(pe);
+
+ String dbCheckName = "dummyScope:action";
+ String[] splitDbCheckName = dbCheckName.split(":");
+
+ // Current Implementation
+ String query = "FROM PolicyEntity where policyName like :splitDBCheckName1 and scope = :splitDBCheckName0";
+ SimpleBindings params = new SimpleBindings();
+ params.put("splitDBCheckName1", splitDbCheckName[1] + "%");
+ params.put("splitDBCheckName0", splitDbCheckName[0]);
+ List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
+
+ // Assertions
+ assertTrue(dataCur.size() == 1);
+ assertTrue(dataCur.get(0) instanceof PolicyEntity);
+ assertEquals(pe, dataCur.get(0));
}
@Test
@Transactional
@Rollback(true)
- public void getDataByQuery_PolicyNotificationController(){
- try{
- // Add data
- WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
- String finalName = "banana"; // Policy File Name
- String userId = "Test";
- watch.setLoginIds(userId);
- watch.setPolicyName(finalName);
- commonClassDao.save(watch);
-
-
- // Current Implementation
- String query = "from WatchPolicyNotificationTable where POLICYNAME = :finalName and LOGINIDS = :userId";
- SimpleBindings params = new SimpleBindings();
- params.put("finalName", finalName);
- params.put("userId", userId);
- List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
-
- // Assertions
- assertTrue(dataCur.size() == 1);
- assertTrue(dataCur.get(0) instanceof WatchPolicyNotificationTable);
- assertEquals(watch, (WatchPolicyNotificationTable) dataCur.get(0) );
-
- }catch(Exception e){
- logger.debug("Exception Occured"+e);
- fail();
- }
+ public void getDataByQuery_PolicyNotificationController() {
+ // Add data
+ WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
+ String finalName = "banana"; // Policy File Name
+ String userId = "Test";
+ watch.setLoginIds(userId);
+ watch.setPolicyName(finalName);
+ commonClassDao.save(watch);
+
+ // Current Implementation
+ String query = "from WatchPolicyNotificationTable where POLICYNAME = :finalName and LOGINIDS = :userId";
+ SimpleBindings params = new SimpleBindings();
+ params.put("finalName", finalName);
+ params.put("userId", userId);
+ List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
+
+ // Assertions
+ assertTrue(dataCur.size() == 1);
+ assertTrue(dataCur.get(0) instanceof WatchPolicyNotificationTable);
+ assertEquals(watch, dataCur.get(0));
+
+ WatchPolicyNotificationTable table0 = new WatchPolicyNotificationTable();
+ WatchPolicyNotificationTable table1 = new WatchPolicyNotificationTable();
+ assertEquals(table0, table0);
+ assertEquals(table0, table1);
+ assertNotEquals(table0, null);
+ String helloString = "Hello";
+ Object helloObject = helloString;
+ assertNotEquals(table0, helloObject);
+
+ table0.setId(1);
+ assertNotEquals(table0, table1);
+ table1.setId(1);
+ assertEquals(table0, table1);
+
+ table0.setPolicyName("GoToOz");
+ assertNotEquals(table0, table1);
+ table1.setPolicyName("GoToOz");
+ assertEquals(table0, table1);
+ table1.setPolicyName(null);
+ assertNotEquals(table0, table1);
+ table0.setPolicyName(null);
+ assertEquals(table0, table1);
+ table1.setPolicyName("GoToOz");
+ assertNotEquals(table0, table1);
+ table0.setPolicyName("GoToOz");
+ assertEquals(table0, table1);
+ assertEquals(table0, table1);
+ table1.setPolicyName("InOz");
+ assertNotEquals(table0, table1);
+ table0.setPolicyName("InOz");
+ assertEquals(table0, table1);
+
+ table0.setLoginIds("Wizard");
+ assertNotEquals(table0, table1);
+ table1.setLoginIds("Wizard");
+ assertEquals(table0, table1);
+ table1.setLoginIds(null);
+ assertNotEquals(table0, table1);
+ table0.setLoginIds(null);
+ assertEquals(table0, table1);
+ table0.setLoginIds("Wizard");
+ assertNotEquals(table0, table1);
+ table1.setLoginIds("Wizard");
+ assertEquals(table0, table1);
+ table1.setLoginIds(null);
+ table1.setLoginIds("Witch");
+ assertNotEquals(table0, table1);
+ table0.setLoginIds("Witch");
+ assertEquals(table0, table1);
+
+ assertNotNull(table0.hashCode());
+ assertNotNull(table1.hashCode());
+ assertEquals(table0.hashCode(), table0.hashCode());
+
+ table0.setLoginIds("Witci");
+ assertNotEquals(table0, table1);
+ assertNotEquals(table0.hashCode(), table1.hashCode());
}
-
- /* Test for SQL Injection Protection
+ /*
+ * Test for SQL Injection Protection
*/
@Test
@Transactional
@Rollback(true)
- public void getDataByQuery_PolicyNotificationController_Injection(){
- try{
- // Add data
- WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
- String userId = "Test";
- watch.setLoginIds(userId);
- watch.setPolicyName("banana");
- commonClassDao.save(watch);
-
- WatchPolicyNotificationTable watch2 = new WatchPolicyNotificationTable();
- watch2.setLoginIds(userId);
- watch2.setPolicyName("banana2");
- commonClassDao.save(watch2);
-
- // SQL Injection attempt
- String finalName = "banana' OR '1'='1";
-
-
- // Current Implementation
- String query = "from WatchPolicyNotificationTable where POLICYNAME = :finalName and LOGINIDS = :userId";
- SimpleBindings params = new SimpleBindings();
- params.put("finalName", finalName);
- params.put("userId", userId);
- List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
-
- // Assertions
- assertTrue(dataCur.size() <= 1);
-
- if(dataCur.size() >= 1){
- assertTrue(dataCur.get(0) instanceof WatchPolicyNotificationTable);
- assertFalse(watch.equals((WatchPolicyNotificationTable) dataCur.get(0)));
- assertFalse(watch.equals((WatchPolicyNotificationTable) dataCur.get(0)));
- }
- }catch(Exception e){
- logger.debug("Exception Occured"+e);
- fail();
+ public void getDataByQuery_PolicyNotificationController_Injection() {
+ // Add data
+ WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
+ String userId = "Test";
+ watch.setLoginIds(userId);
+ watch.setPolicyName("banana");
+ commonClassDao.save(watch);
+
+ WatchPolicyNotificationTable watch2 = new WatchPolicyNotificationTable();
+ watch2.setLoginIds(userId);
+ watch2.setPolicyName("banana2");
+ commonClassDao.save(watch2);
+
+ // SQL Injection attempt
+ String finalName = "banana' OR '1'='1";
+
+ // Current Implementation
+ String query = "from WatchPolicyNotificationTable where POLICYNAME = :finalName and LOGINIDS = :userId";
+ SimpleBindings params = new SimpleBindings();
+ params.put("finalName", finalName);
+ params.put("userId", userId);
+ List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
+
+ // Assertions
+ assertTrue(dataCur.size() <= 1);
+
+ if (dataCur.size() >= 1) {
+ assertTrue(dataCur.get(0) instanceof WatchPolicyNotificationTable);
+ assertFalse(watch.equals(dataCur.get(0)));
+ assertFalse(watch.equals(dataCur.get(0)));
}
}
@Test
- public void testCommonClassDaoImplMethods(){
- try{
- UserInfo userInfo = new UserInfo();
- userInfo.setUserLoginId("TestID");
- userInfo.setUserName("Test");
- commonClassDao.save(userInfo);
- List<Object> data = commonClassDao.getDataById(UserInfo.class, "userLoginId:userName", "TestID:Test");
- assertTrue(data.size() == 1);
- UserInfo userInfoUpdate = (UserInfo) data.get(0);
- userInfoUpdate.setUserName("Test1");
- commonClassDao.update(userInfoUpdate);
- List<String> data1 = commonClassDao.getDataByColumn(UserInfo.class, "userLoginId");
- assertTrue(data1.size() == 1);
- UserInfo data2 = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName", "TestID:Test1");
- assertTrue("TestID".equals(data2.getUserLoginId()));
- List<Object> data3 = commonClassDao.checkDuplicateEntry("TestID:Test1", "userLoginId:userName", UserInfo.class);
- assertTrue(data3.size() == 1);
- PolicyRoles roles = new PolicyRoles();
- roles.setRole("admin");
- roles.setLoginId(userInfo);
- roles.setScope("test");
- commonClassDao.save(roles);
- List<PolicyRoles> roles1 = commonClassDao.getUserRoles();
- assertTrue(roles1.size() == 1);
- List<String> multipleData = new ArrayList<>();
- multipleData.add("TestID:Test1");
- List<Object> data4 = commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, "userLoginId:userName", multipleData);
- assertTrue(data4.size() == 1);
- commonClassDao.delete(data2);
- }catch(Exception e){
- logger.debug("Exception Occured"+e);
- fail();
- }
+ public void testCommonClassDaoImplMethods() {
+ UserInfo userInfo = new UserInfo();
+ userInfo.setUserLoginId("TestID");
+ userInfo.setUserName("Test");
+ commonClassDao.save(userInfo);
+ List<Object> data = commonClassDao.getDataById(UserInfo.class, "userLoginId:userName", "TestID:Test");
+ assertTrue(data.size() == 1);
+ UserInfo userInfoUpdate = (UserInfo) data.get(0);
+ userInfoUpdate.setUserName("Test1");
+ commonClassDao.update(userInfoUpdate);
+ List<String> data1 = commonClassDao.getDataByColumn(UserInfo.class, "userLoginId");
+ assertTrue(data1.size() == 1);
+ UserInfo data2 = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName",
+ "TestID:Test1");
+ assertTrue("TestID".equals(data2.getUserLoginId()));
+ List<Object> data3 = commonClassDao.checkDuplicateEntry("TestID:Test1", "userLoginId:userName", UserInfo.class);
+ assertTrue(data3.size() == 1);
+ PolicyRoles roles = new PolicyRoles();
+ roles.setRole("admin");
+ roles.setLoginId(userInfo);
+ roles.setScope("test");
+ commonClassDao.save(roles);
+ List<PolicyRoles> roles1 = commonClassDao.getUserRoles();
+ assertTrue(roles1.size() == 1);
+ List<String> multipleData = new ArrayList<>();
+ multipleData.add("TestID:Test1");
+ List<Object> data4 = commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, "userLoginId:userName",
+ multipleData);
+ assertTrue(data4.size() == 1);
+ commonClassDao.delete(data2);
}
- @After
- public void deleteDB(){
- sessionFactory.close();
- server.stop();
+ @Test
+ public void testGetDataByIdparameters() {
+ UserInfo userInfo = new UserInfo();
+ userInfo.setUserLoginId("TestID");
+ userInfo.setUserName("Test");
+ commonClassDao.save(userInfo);
+ List<Object> data = commonClassDao.getDataById(UserInfo.class, "userLoginId:userName", "TestID:Test");
+ assertTrue(data.size() == 1);
+ data = commonClassDao.getDataById(UserInfo.class, null, null);
+ assertNull(data);
+ data = commonClassDao.getDataById(UserInfo.class, "userLoginId:userName", null);
+ assertNull(data);
+ data = commonClassDao.getDataById(UserInfo.class, null, "TestID:Test");
+ assertNull(data);
+ data = commonClassDao.getDataById(UserInfo.class, "userLoginIduserName", "TestID:Test");
+ assertNull(data);
+ data = commonClassDao.getDataById(UserInfo.class, "userLoginIduserName", "TestIDTest");
+ assertNull(data);
+ data = commonClassDao.getDataById(UserInfo.class, "userLoginId data2.getUserLoginId()" + ":userName",
+ "TestIDTest");
+ assertNull(data);
+ commonClassDao.delete(data);
+ }
+
+ @Test
+ public void testGetDataByColumnParameters() {
+ UserInfo userInfo = new UserInfo();
+ userInfo.setUserLoginId("TestID");
+ userInfo.setUserName("Test");
+ commonClassDao.save(userInfo);
+ List<String> data = commonClassDao.getDataByColumn(UserInfo.class, "userLoginId");
+ assertTrue(data.size() == 1);
+ data = commonClassDao.getDataByColumn(null, null);
+ assertNull(data);
+ data = commonClassDao.getDataByColumn(UserInfo.class, null);
+ assertNull(data);
+ data = commonClassDao.getDataByColumn(null, "userLoginId");
+ assertNull(data);
+ commonClassDao.delete(data);
+ }
+
+ @Test
+ public void testGetMultipleDataOnAddingConjunctionParameters() {
+ UserInfo userInfo = new UserInfo();
+ userInfo.setUserLoginId("TestID");
+ userInfo.setUserName("Test");
+ assertEquals("Test", userInfo.getIdentiferByUserId().getUri().getPath());
+ commonClassDao.save(userInfo);
+ List<String> multipleData = new ArrayList<>();
+ multipleData.add("TestID:Test1");
+ List<Object> data = commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, "userLoginId:userName",
+ multipleData);
+ assertTrue(data.size() == 0);
+ data = commonClassDao.getMultipleDataOnAddingConjunction(null, null, null);
+ assertNull(data);
+ data = commonClassDao.getMultipleDataOnAddingConjunction(null, null, multipleData);
+ assertNull(data);
+ data = commonClassDao.getMultipleDataOnAddingConjunction(null, "userLoginId:userName", null);
+ assertNull(data);
+ data = commonClassDao.getMultipleDataOnAddingConjunction(null, "userLoginId:userName", multipleData);
+ assertNull(data);
+ data = commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, null, null);
+ assertNull(data);
+ data = commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, null, multipleData);
+ assertNull(data);
+ data = commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, "userLoginId:userName", null);
+ assertNull(data);
+ commonClassDao.delete(data);
+ }
+ @Test
+ public void testCheckDuplicateEntryParameters() {
+ UserInfo userInfo = new UserInfo();
+ userInfo.setUserLoginId("TestID");
+ userInfo.setUserName("Test");
+ commonClassDao.save(userInfo);
+ List<Object> data = commonClassDao.checkDuplicateEntry("TestID:Test1", "userLoginId:userName", UserInfo.class);
+ assertTrue(data.size() == 0);
+ data = commonClassDao.checkDuplicateEntry(null, null, UserInfo.class);
+ assertNull(data);
+ data = commonClassDao.checkDuplicateEntry("userLoginId:userName", null, UserInfo.class);
+ assertNull(data);
+ data = commonClassDao.checkDuplicateEntry(null, "TestID:Test", UserInfo.class);
+ assertNull(data);
+ data = commonClassDao.checkDuplicateEntry("userLoginIduserName", "TestID:Test", UserInfo.class);
+ assertNull(data);
+ data = commonClassDao.checkDuplicateEntry("userLoginId:userName", "TestID:Test:zooby", UserInfo.class);
+ assertNull(data);
+ data = commonClassDao.checkDuplicateEntry("userLoginId:userName", "TestID", UserInfo.class);
+ assertNull(data);
+ commonClassDao.delete(data);
+ }
+
+ @Test
+ public void testGetEntityItemParameters() {
+ UserInfo userInfo = new UserInfo();
+ userInfo.setUserLoginId("TestID");
+ userInfo.setUserName("Test");
+ commonClassDao.save(userInfo);
+ List<Object> data = commonClassDao.getDataById(UserInfo.class, "userLoginId:userName", "TestID:Test");
+ assertTrue(data.size() == 1);
+ UserInfo userInfoUpdate = (UserInfo) data.get(0);
+ userInfoUpdate.setUserName("Test1");
+ commonClassDao.update(userInfoUpdate);
+ List<String> data1 = commonClassDao.getDataByColumn(UserInfo.class, "userLoginId");
+ assertTrue(data1.size() == 1);
+ UserInfo data2 = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName",
+ "TestID:Test1");
+ assertTrue("TestID".equals(data2.getUserLoginId()));
+ data2 = (UserInfo) commonClassDao.getEntityItem(null, null, null);
+ assertNull(data2);
+ data2 = (UserInfo) commonClassDao.getEntityItem(null, null, "TestID:Test1");
+ assertNull(data2);
+ data2 = (UserInfo) commonClassDao.getEntityItem(null, "userLoginId:userName", null);
+ assertNull(data2);
+ data2 = (UserInfo) commonClassDao.getEntityItem(null, "userLoginId:userName", "TestID:Test1");
+ assertNull(data2);
+ data2 = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, null, null);
+ assertNull(data2);
+ data2 = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, null, "TestID:Test1");
+ assertNull(data2);
+ data2 = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName", null);
+ assertNull(data2);
+ data2 = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginIduserName", "TestID:Test1");
+ assertNull(data2);
+ data2 = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName", "TestIDTest1");
+ assertNull(data2);
+ commonClassDao.delete(data);
+ commonClassDao.delete(data1);
+ commonClassDao.delete(data2);
}
+ @Test
+ public void testOtherMethods() {
+ UserInfo userInfo = new UserInfo();
+ userInfo.setUserLoginId("TestID");
+ userInfo.setUserName("Test");
+ commonClassDao.save(userInfo);
+ commonClassDao.deleteAll();
+ List<Object> data = commonClassDao.getDataById(UserInfo.class, "userLoginId:userName", "TestID:Test");
+ assertTrue(data.size() == 1);
+
+ data = commonClassDao.checkExistingGroupListforUpdate(null, null);
+ assertTrue(data.size() == 0);
+
+ commonClassDao.updateClAlarms(null, null);
+ commonClassDao.updateClYaml(null, null);
+ data = commonClassDao.getDataById(UserInfo.class, "userLoginId:userName", "TestID:Test");
+ assertTrue(data.size() == 1);
+ commonClassDao.update(null);
+ assertTrue(data.size() == 1);
+ commonClassDao.getData(null);
+ assertTrue(data.size() == 1);
+ commonClassDao.delete(data);
+ }
+
+ @Test
+ public void testUpdateQuery() {
+ UserInfo userInfo = new UserInfo();
+ userInfo.setUserLoginId("TestID");
+ userInfo.setUserName("Test");
+ commonClassDao.save(userInfo);
+ commonClassDao.updateQuery("SELECT * FROM userLoginId");
+ List<Object> data = commonClassDao.getDataById(UserInfo.class, "userLoginId:userName", "TestID:Test");
+ assertTrue(data.size() == 1);
+
+ String query = "DELETE FROM org.onap.policy.rest.jpa.FunctionDefinition";
+ commonClassDao.updateQuery(query);
+ data = commonClassDao.getDataById(UserInfo.class, "userLoginId:userName", "TestID:Test");
+ assertTrue(data.size() == 1);
+ commonClassDao.delete(data);
+ }
+
+ @Test
+ public void testGetDataByQueryParameters() {
+ // Add data
+ UserInfo userinfo = new UserInfo();
+ String loginIdUserName = "Test";
+ userinfo.setUserLoginId(loginIdUserName);
+ userinfo.setUserName(loginIdUserName);
+ commonClassDao.save(userinfo);
+
+ SimpleBindings bindings = new SimpleBindings();
+ bindings.put("usercode", 1L);
+
+ try {
+ commonClassDao.getDataByQuery("from UserInfo", bindings);
+ fail("test should throw an exception here");
+ } catch (Exception exc) {
+ assertTrue(exc.getMessage().contains("Parameter usercode does not exist as a named parameter"));
+ }
+ }
+
+ private void truncateAllTables() {
+ Session session = sessionFactory.openSession();
+ Transaction transaction = session.beginTransaction();
+ sessionFactory.getAllClassMetadata().forEach((tableName, x) -> {
+ Query query = session.createQuery("DELETE FROM " + tableName);
+ query.executeUpdate();
+ });
+ transaction.commit();
+ session.close();
+ }
}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionBodyEntityTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionBodyEntityTest.java
index f8777d868..ab74d07f8 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionBodyEntityTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionBodyEntityTest.java
@@ -3,6 +3,7 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,43 +26,46 @@ import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
+
import java.util.Date;
+
import org.junit.Test;
public class ActionBodyEntityTest {
- @Test
- public void testEntity() {
- // Set up test data
- String value = "testVal";
- Date date = new Date();
- ActionBodyEntity entity = new ActionBodyEntity();
- entity.prePersist();
- ActionBodyEntity entity2 = new ActionBodyEntity();
- ActionBodyEntity entity3 = new ActionBodyEntity();
+ @Test
+ public void testEntity() {
+ // Set up test data
+ String value = "testVal";
+ ActionBodyEntity entity = new ActionBodyEntity();
+ entity.prePersist();
+
+ // Test set and get
+ ActionBodyEntity entity0 = new ActionBodyEntity();
+ entity0.preUpdate();
+ entity0.setActionBody(value);
+ assertEquals(value, entity0.getActionBody());
+ entity0.setActionBodyName(value);
+ assertEquals(value, entity0.getActionBodyName());
+ entity0.setCreatedBy(value);
+ assertEquals(value, entity0.getCreatedBy());
+ entity0.setModifiedBy(value);
+ assertEquals(value, entity0.getModifiedBy());
- // Test set and get
- entity3.preUpdate();
- entity3.setActionBody(value);
- assertEquals(value, entity3.getActionBody());
- entity3.setActionBodyName(value);
- assertEquals(value, entity3.getActionBodyName());
- entity3.setCreatedBy(value);
- assertEquals(value, entity3.getCreatedBy());
- entity3.setModifiedBy(value);
- assertEquals(value, entity3.getModifiedBy());
- entity3.setModifiedDate(date);
- assertEquals(date, entity3.getModifiedDate());
- assertEquals(0, entity3.getVersion());
- assertNull(entity3.getCreatedDate());
- entity3.setDeleted(true);
- assertEquals(true, entity3.isDeleted());
- assertEquals(0, entity3.getActionBodyId());
+ Date date = new Date();
+ entity0.setModifiedDate(date);
+ assertEquals(date, entity0.getModifiedDate());
+ assertEquals(0, entity0.getVersion());
+ assertNull(entity0.getCreatedDate());
+ entity0.setDeleted(true);
+ assertEquals(true, entity0.isDeleted());
+ assertEquals(0, entity0.getActionBodyId());
- // Test equals method combinations
- assertEquals(false, entity.equals(null));
- assertEquals(true, entity.equals(entity));
- assertEquals(false, entity.equals(value));
- assertEquals(false, entity.equals(entity2));
- assertThat(entity.hashCode(), is(not(0)));
- }
+ // Test equals method combinations
+ assertEquals(false, entity.equals(null));
+ assertEquals(true, entity.equals(entity));
+ assertEquals(false, entity.equals((Object) value));
+ ActionBodyEntity entity1 = new ActionBodyEntity();
+ assertEquals(false, entity.equals(entity1));
+ assertThat(entity.hashCode(), is(not(0)));
+ }
}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionDictionaryJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionDictionaryJpaTest.java
index 580b3e35d..501c7fd92 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionDictionaryJPATest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionDictionaryJpaTest.java
@@ -3,13 +3,14 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -17,10 +18,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.rest.jpa;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import com.att.research.xacml.api.Identifier;
+
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
@@ -30,11 +38,16 @@ import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
-public class ActionDictionaryJPATest {
+public class ActionDictionaryJpaTest {
- private static Logger logger = FlexLogger.getLogger(ActionDictionaryJPATest.class);
+ private static Logger logger = FlexLogger.getLogger(ActionDictionaryJpaTest.class);
private UserInfo userInfo;
+ /**
+ * Set up the test.
+ *
+ * @throws Exception on test errors
+ */
@Before
public void setUp() throws Exception {
logger.info("setUp: Entering");
@@ -45,7 +58,7 @@ public class ActionDictionaryJPATest {
}
@Test
- public void testActionDictionary(){
+ public void testActionDictionary() {
ActionPolicyDict data = new ActionPolicyDict();
data.setId(1);
assertTrue(1 == data.getId());
@@ -66,48 +79,49 @@ public class ActionDictionaryJPATest {
data.prePersist();
data.preUpdate();
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!=null);
+ assertTrue(data.getUserModifiedBy() != null);
}
@Test
- public void testFunctionArgument(){
+ public void testFunctionArgument() {
FunctionArgument data = new FunctionArgument();
data.setArgIndex(1);
assertTrue(1 == data.getArgIndex());
data.setDatatypeBean(new Datatype());
- assertTrue(data.getDatatypeBean()!=null);
+ assertTrue(data.getDatatypeBean() != null);
data.setFunctionDefinition(new FunctionDefinition());
- assertTrue(data.getFunctionDefinition()!=null);
+ assertTrue(data.getFunctionDefinition() != null);
data.setId(1);
assertTrue(1 == data.getId());
- data.isBag();
- data.toString();
+ assertFalse(data.isBag());
+ assertEquals("FunctionArgument(id=1", data.toString().substring(0, 21));
data.setIsBag(1);
+ assertTrue(data.isBag());
assertTrue(1 == data.getIsBag());
new FunctionArgument(data);
}
@Test
- public void testFunctionDefinition(){
+ public void testFunctionDefinition() {
FunctionDefinition data = new FunctionDefinition();
data.setArgLb(1);
assertTrue(1 == data.getArgLb());
data.setArgUb(1);
assertTrue(1 == data.getArgUb());
data.setDatatypeBean(new Datatype());
- assertTrue(data.getDatatypeBean()!=null);
+ assertTrue(data.getDatatypeBean() != null);
data.setFunctionArguments(new ArrayList<>());
- assertTrue(data.getFunctionArguments()!=null);
- data.setHigherOrderArg_LB(1);
- assertTrue(1 == data.getHigherOrderArg_LB());
- data.setHigherOrderArg_UB(1);
- assertTrue(1 == data.getHigherOrderArg_UB());
+ assertTrue(data.getFunctionArguments() != null);
+ data.setHigherOrderArgLb(1);
+ assertTrue(1 == data.getHigherOrderArgLb());
+ data.setHigherOrderArgUb(1);
+ assertTrue(1 == data.getHigherOrderArgUb());
data.setId(1);
assertTrue(1 == data.getId());
data.setIsBagReturn(1);
@@ -118,15 +132,23 @@ public class ActionDictionaryJPATest {
assertTrue("Test".equals(data.getShortname()));
data.setXacmlid("Test");
assertTrue("Test".equals(data.getXacmlid()));
- data.toString();
- data.isBagReturn();
- data.isHigherOrder();
- data.addFunctionArgument(new FunctionArgument());
- data.removeFunctionArgument(new FunctionArgument());
+ assertTrue(data.toString().startsWith("FunctionDefinition(id=1"));
+ assertTrue(data.isBagReturn());
+ data.setIsBagReturn(0);
+ assertTrue(data.isHigherOrder());
+ assertFalse(data.isBagReturn());
+ data.setIsHigherOrder(0);
+ assertFalse(data.isHigherOrder());
+ FunctionArgument functionArgument = new FunctionArgument();
+ functionArgument.setId(12345);
+ data.addFunctionArgument(functionArgument);
+ assertEquals(12345, data.getFunctionArguments().iterator().next().getId());
+ data.removeFunctionArgument(functionArgument);
+ assertTrue(data.getFunctionArguments().isEmpty());
}
@Test
- public void testCategory(){
+ public void testCategory() {
Category data = new Category();
new Category(null);
data.setAttributes(new HashSet<>());
@@ -134,10 +156,9 @@ public class ActionDictionaryJPATest {
data.removeAttribute(new Attribute());
data.isStandard();
data.isCustom();
- Category.extractGrouping("urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject");
data.getIdentifer();
data.toString();
- assertTrue(data.getAttributes()!=null);
+ assertTrue(data.getAttributes() != null);
data.setGrouping("Test");
assertTrue("Test".equals(data.getGrouping()));
data.setId(1);
@@ -146,15 +167,42 @@ public class ActionDictionaryJPATest {
assertTrue("Test".equals(data.getShortName()));
data.setXacmlId("Test");
assertTrue("Test".equals(data.getXacmlId()));
+
+ data.setIsStandard(Category.STANDARD);
+ assertEquals(Category.STANDARD, data.getIsStandard());
+ assertTrue(data.isStandard());
+ assertFalse(data.isCustom());
+
+ data.setIsStandard(Category.CUSTOM);
+ assertEquals(Category.CUSTOM, data.getIsStandard());
+ assertFalse(data.isStandard());
+ assertTrue(data.isCustom());
+
+ Identifier categoryIdentifier = new DummyIdentifier();
+ Category data2 = new Category(categoryIdentifier,
+ "urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject", Category.STANDARD);
+ assertEquals(DummyIdentifier.class.getName(), data2.getIdentifer().stringValue());
+
+ Category data3 = new Category(categoryIdentifier,
+ "urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject");
+ assertEquals(DummyIdentifier.class.getName(), data3.getIdentifer().stringValue());
+
+ assertEquals("subject",
+ Category.extractGrouping("urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject"));
+ assertNull(Category.extractGrouping(null));
+ assertNull(Category.extractGrouping("some random string"));
+ assertNull(Category.extractGrouping(""));
+ assertEquals("intermediary-attribute", Category
+ .extractGrouping("urn:oasis:names:tc:xacml:1.0:attribute-category:intermediary-attribute"));
}
@Test
- public void testConstraintType(){
+ public void testConstraintType() {
ConstraintType data = new ConstraintType();
new ConstraintType("Test", "Test");
ConstraintType.getRangeTypes();
data.setAttributes(new HashSet<>());
- assertTrue(data.getAttributes()!=null);
+ assertTrue(data.getAttributes() != null);
data.setConstraintType("Test");
assertTrue("Test".equals(data.getConstraintType()));
data.setDescription("Test");
@@ -164,13 +212,13 @@ public class ActionDictionaryJPATest {
}
@Test
- public void testConstraintValue(){
+ public void testConstraintValue() {
ConstraintValue data = new ConstraintValue();
data.clone();
new ConstraintValue(new ConstraintValue());
- new ConstraintValue("Test","Test");
+ new ConstraintValue("Test", "Test");
data.setAttribute(new Attribute());
- assertTrue(data.getAttribute()!=null);
+ assertTrue(data.getAttribute() != null);
data.setId(1);
assertTrue(1 == data.getId());
data.setProperty("Test");
@@ -180,14 +228,20 @@ public class ActionDictionaryJPATest {
}
@Test
- public void testObadvice(){
- Obadvice data = new Obadvice();
+ public void testObadvice() {
new Obadvice();
new Obadvice("Test", "Test");
+ new Obadvice(new DummyIdentifier(), "Test");
+ Obadvice data = new Obadvice();
data.clone();
data.addObadviceExpression(new ObadviceExpression());
+ assertNotNull(data.clone());
data.removeObadviceExpression(new ObadviceExpression());
data.removeAllExpressions();
+ assertEquals(0, data.getObadviceExpressions().size());
+ data.setObadviceExpressions(null);
+ assertNull(data.getObadviceExpressions());
+ data.removeAllExpressions();
data.prePersist();
data.preUpdate();
data.setId(1);
@@ -201,29 +255,30 @@ public class ActionDictionaryJPATest {
data.setModifiedBy("Test");
assertTrue("Test".equals(data.getModifiedBy()));
data.setObadviceExpressions(new HashSet<>());
- assertTrue(data.getObadviceExpressions()!=null);
+ assertTrue(data.getObadviceExpressions() != null);
data.setType("Test");
assertTrue("Test".equals(data.getType()));
data.setXacmlId("Test");
assertTrue("Test".equals(data.getXacmlId()));
+
}
@Test
- public void testObadviceExpression(){
+ public void testObadviceExpression() {
ObadviceExpression data = new ObadviceExpression();
data.clone();
data.setAttribute(new Attribute());
- assertTrue(data.getAttribute()!=null);
+ assertTrue(data.getAttribute() != null);
data.setId(1);
assertTrue(1 == data.getId());
data.setObadvice(new Obadvice());
- assertTrue(data.getObadvice()!=null);
+ assertTrue(data.getObadvice() != null);
data.setType("Test");
assertTrue("Test".equals(data.getType()));
}
@Test
- public void testRuleAlgorithms(){
+ public void testRuleAlgorithms() {
RuleAlgorithms data = new RuleAlgorithms();
data.isCustom();
data.isStandard();
@@ -234,10 +289,17 @@ public class ActionDictionaryJPATest {
data.setXacmlId("Test");
assertTrue("Test".equals(data.getXacmlId()));
data.toString();
+
+ RuleAlgorithms ra0 = new RuleAlgorithms(new DummyIdentifier());
+ assertTrue(ra0.isStandard());
+ assertFalse(ra0.isCustom());
+ RuleAlgorithms ra1 = new RuleAlgorithms(new DummyIdentifier(), 'C');
+ assertFalse(ra1.isStandard());
+ assertTrue(ra1.isCustom());
}
@Test
- public void testAttributeAssignment(){
+ public void testAttributeAssignment() {
AttributeAssignment data = new AttributeAssignment();
data.setId(1);
assertTrue(1 == data.getId());
@@ -248,16 +310,16 @@ public class ActionDictionaryJPATest {
}
@Test
- public void testDatatype(){
+ public void testDatatype() {
Datatype data = new Datatype();
new Datatype(null);
new Datatype(1, new Datatype());
data.setArguments(new HashSet<>());
- assertTrue(data.getArguments()!=null);
+ assertTrue(data.getArguments() != null);
data.setAttributes(new HashSet<>());
- assertTrue(data.getAttributes()!=null);
+ assertTrue(data.getAttributes() != null);
data.setFunctions(new HashSet<>());
- assertTrue(data.getFunctions()!=null);
+ assertTrue(data.getFunctions() != null);
data.setId(1);
assertTrue(1 == data.getId());
data.setShortName("Test");
@@ -270,16 +332,29 @@ public class ActionDictionaryJPATest {
data.removeArgument(new FunctionArgument());
data.removeAttribute(new Attribute());
data.removeAttribute(new FunctionDefinition());
- assertTrue(data.getIdentifer()!=null);
- assertTrue(data.getIdentiferByShortName()!=null);
+ assertTrue(data.getIdentifer() != null);
+ assertTrue(data.getIdentiferByShortName() != null);
data.setIsStandard(Datatype.STANDARD);
assertTrue(data.isStandard());
data.setIsStandard(Datatype.CUSTOM);
assertTrue(data.isCustom());
+
+ data.setIsStandard(Category.STANDARD);
+ assertEquals(Category.STANDARD, data.getIsStandard());
+ assertTrue(data.isStandard());
+ assertFalse(data.isCustom());
+
+ data.setIsStandard(Category.CUSTOM);
+ assertEquals(Category.CUSTOM, data.getIsStandard());
+ assertFalse(data.isStandard());
+ assertTrue(data.isCustom());
+
+ Datatype data2 = new Datatype(new DummyIdentifier(), Datatype.STANDARD);
+ assertEquals(DummyIdentifier.class.getName(), data2.getIdentifer().stringValue());
}
@Test
- public void testPolicyAlgorithms(){
+ public void testPolicyAlgorithms() {
PolicyAlgorithms data = new PolicyAlgorithms();
data.setId(1);
assertTrue(1 == data.getId());
@@ -289,5 +364,13 @@ public class ActionDictionaryJPATest {
assertTrue("Test".equals(data.getXacmlId()));
data.setIsStandard(PolicyAlgorithms.STANDARD);
assertTrue(data.isStandard());
+ assertFalse(data.isCustom());
+ data.setIsStandard(PolicyAlgorithms.CUSTOM);
+ assertFalse(data.isStandard());
+ assertTrue(data.isCustom());
+
+ DummyIdentifier identifier = new DummyIdentifier();
+ assertNotNull(new PolicyAlgorithms(identifier));
+ assertNotNull(new PolicyAlgorithms(identifier, 'C'));
}
}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/BRMSDictionaryJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/BrmsDictionaryJpaTest.java
index 9012cca28..abfef0c35 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/BRMSDictionaryJPATest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/BrmsDictionaryJpaTest.java
@@ -3,13 +3,14 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -17,6 +18,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.rest.jpa;
import static org.junit.Assert.assertTrue;
@@ -28,11 +30,19 @@ import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
-public class BRMSDictionaryJPATest {
+/**
+ * The Class BrmsDictionaryJpaTest.
+ */
+public class BrmsDictionaryJpaTest {
- private static Logger logger = FlexLogger.getLogger(BRMSDictionaryJPATest.class);
+ private static Logger logger = FlexLogger.getLogger(BrmsDictionaryJpaTest.class);
private UserInfo userInfo;
+ /**
+ * Sets the up.
+ *
+ * @throws Exception the exception
+ */
@Before
public void setUp() throws Exception {
logger.info("setUp: Entering");
@@ -42,9 +52,12 @@ public class BRMSDictionaryJPATest {
logger.info("setUp: exit");
}
+ /**
+ * Test BRMS param template.
+ */
@Test
- public void testBRMSParamTemplate(){
- BRMSParamTemplate data = new BRMSParamTemplate();
+ public void testBrmsParamTemplate() {
+ BrmsParamTemplate data = new BrmsParamTemplate();
data.prePersist();
data.setId(1);
assertTrue(1 == data.getId());
@@ -55,14 +68,17 @@ public class BRMSDictionaryJPATest {
data.setDescription("Test");
assertTrue("Test".equals(data.getDescription()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
+ assertTrue(data.getCreatedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
+ assertTrue(data.getUserCreatedBy() != null);
}
+ /**
+ * Test BRMS controller.
+ */
@Test
- public void testBRMSController(){
- BRMSController data = new BRMSController();
+ public void testBrmsController() {
+ BrmsController data = new BrmsController();
data.preUpdate();
data.prePersist();
data.setId(1);
@@ -74,18 +90,21 @@ public class BRMSDictionaryJPATest {
data.setDescription("Test");
assertTrue("Test".equals(data.getDescription()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!=null);
+ assertTrue(data.getUserModifiedBy() != null);
}
+ /**
+ * Test BRMS dependency.
+ */
@Test
- public void testBRMSDependency(){
- BRMSDependency data = new BRMSDependency();
+ public void testrmsDependency() {
+ BrmsDependency data = new BrmsDependency();
data.preUpdate();
data.prePersist();
data.setId(1);
@@ -97,13 +116,13 @@ public class BRMSDictionaryJPATest {
data.setDescription("Test");
assertTrue("Test".equals(data.getDescription()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!=null);
+ assertTrue(data.getUserModifiedBy() != null);
}
}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ClosedLoopPolicyDictionaryJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ClosedLoopPolicyDictionaryJpaTest.java
index 2274855e1..00fba8ca6 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ClosedLoopPolicyDictionaryJPATest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ClosedLoopPolicyDictionaryJpaTest.java
@@ -3,13 +3,14 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -17,6 +18,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.rest.jpa;
import static org.junit.Assert.assertTrue;
@@ -28,11 +30,19 @@ import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
-public class ClosedLoopPolicyDictionaryJPATest {
+/**
+ * The Class ClosedLoopPolicyDictionaryJpaTest.
+ */
+public class ClosedLoopPolicyDictionaryJpaTest {
- private static Logger logger = FlexLogger.getLogger(ClosedLoopPolicyDictionaryJPATest.class);
+ private static Logger logger = FlexLogger.getLogger(ClosedLoopPolicyDictionaryJpaTest.class);
private UserInfo userInfo;
+ /**
+ * Sets the up.
+ *
+ * @throws Exception the exception
+ */
@Before
public void setUp() throws Exception {
logger.info("setUp: Entering");
@@ -42,51 +52,60 @@ public class ClosedLoopPolicyDictionaryJPATest {
logger.info("setUp: exit");
}
+ /**
+ * Test VSCL action.
+ */
@Test
- public void testVSCLAction(){
- VSCLAction data = new VSCLAction();
+ public void testVsclAction() {
+ VsclAction data = new VsclAction();
data.preUpdate();
data.prePersist();
data.setId(1);
assertTrue(1 == data.getId());
- data.setVsclaction("Test");
- assertTrue("Test".equals(data.getVsclaction()));
+ data.setAction("Test");
+ assertTrue("Test".equals(data.getAction()));
data.setDescription("Test");
assertTrue("Test".equals(data.getDescription()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!= null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!= null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!= null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!= null);
+ assertTrue(data.getUserModifiedBy() != null);
}
+ /**
+ * Test VNF type.
+ */
@Test
- public void testVNFType(){
- VNFType data = new VNFType();
+ public void testVnfType() {
+ VnfType data = new VnfType();
data.preUpdate();
data.prePersist();
data.setId(1);
assertTrue(1 == data.getId());
- data.setVnftype("Test");
- assertTrue("Test".equals(data.getVnftype()));
+ data.setType("Test");
+ assertTrue("Test".equals(data.getType()));
data.setDescription("Test");
assertTrue("Test".equals(data.getDescription()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!= null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!= null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!= null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!= null);
+ assertTrue(data.getUserModifiedBy() != null);
}
+ /**
+ * Test PEP options.
+ */
@Test
- public void testPEPOptions(){
- PEPOptions data = new PEPOptions();
+ public void testPepOptions() {
+ PepOptions data = new PepOptions();
data.preUpdate();
data.prePersist();
data.setId(1);
@@ -96,17 +115,20 @@ public class ClosedLoopPolicyDictionaryJPATest {
data.setDescription("Test");
assertTrue("Test".equals(data.getDescription()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!= null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!= null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!= null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!= null);
+ assertTrue(data.getUserModifiedBy() != null);
}
+ /**
+ * Test varbind dictionary.
+ */
@Test
- public void testVarbindDictionary(){
+ public void testVarbindDictionary() {
VarbindDictionary data = new VarbindDictionary();
data.preUpdate();
data.prePersist();
@@ -116,20 +138,23 @@ public class ClosedLoopPolicyDictionaryJPATest {
assertTrue("Test".equals(data.getVarbindName()));
data.setVarbindDescription("Test");
assertTrue("Test".equals(data.getVarbindDescription()));
- data.setVarbindOID("Test");
- assertTrue("Test".equals(data.getVarbindOID()));
+ data.setVarbindOid("Test");
+ assertTrue("Test".equals(data.getVarbindOid()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!= null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!= null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!= null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!= null);
+ assertTrue(data.getUserModifiedBy() != null);
}
+ /**
+ * Test closed loop D 2 services.
+ */
@Test
- public void testClosedLoopD2Services(){
+ public void testClosedLoopD2Services() {
ClosedLoopD2Services data = new ClosedLoopD2Services();
data.preUpdate();
data.prePersist();
@@ -140,17 +165,20 @@ public class ClosedLoopPolicyDictionaryJPATest {
data.setDescription("Test");
assertTrue("Test".equals(data.getDescription()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!= null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!= null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!= null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!= null);
+ assertTrue(data.getUserModifiedBy() != null);
}
+ /**
+ * Test closed loop site.
+ */
@Test
- public void testClosedLoopSite(){
+ public void testClosedLoopSite() {
ClosedLoopSite data = new ClosedLoopSite();
data.preUpdate();
data.prePersist();
@@ -161,12 +189,12 @@ public class ClosedLoopPolicyDictionaryJPATest {
data.setDescription("Test");
assertTrue("Test".equals(data.getDescription()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!= null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!= null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!= null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!= null);
+ assertTrue(data.getUserModifiedBy() != null);
}
}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/CommonDictionaryJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/CommonDictionaryJpaTest.java
index 230844a64..a6505a3f6 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/CommonDictionaryJPATest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/CommonDictionaryJpaTest.java
@@ -3,13 +3,14 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -17,23 +18,34 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.rest.jpa;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Date;
import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
-public class CommonDictionaryJPATest {
+public class CommonDictionaryJpaTest {
- private static Logger logger = FlexLogger.getLogger(CommonDictionaryJPATest.class);
+ private static Logger logger = FlexLogger.getLogger(CommonDictionaryJpaTest.class);
private UserInfo userInfo;
+ /**
+ * Initiations for testing.
+ *
+ * @throws Exception on test initiation errors
+ */
@Before
public void setUp() throws Exception {
logger.info("setUp: Entering");
@@ -44,16 +56,16 @@ public class CommonDictionaryJPATest {
}
@Test
- public void testAttribute(){
+ public void testAttribute() {
Attribute data = new Attribute();
data.setId(1);
assertTrue(1 == data.getId());
data.setCategoryBean(new Category());
- assertTrue(data.getCategoryBean()!=null);
+ assertTrue(data.getCategoryBean() != null);
data.setConstraintType(new ConstraintType());
- assertTrue(data.getConstraintType()!=null);
+ assertTrue(data.getConstraintType() != null);
data.setConstraintValues(new HashSet<>());
- assertTrue(data.getConstraintValues()!=null);
+ assertTrue(data.getConstraintValues() != null);
data.addConstraintValue(new ConstraintValue());
data.removeConstraintValue(new ConstraintValue());
data.removeAllConstraintValues();
@@ -68,7 +80,7 @@ public class CommonDictionaryJPATest {
data.setXacmlId("Test");
assertTrue("Test".equals(data.getXacmlId()));
data.setDatatypeBean(new Datatype());
- assertTrue(data.getDatatypeBean()!=null);
+ assertTrue(data.getDatatypeBean() != null);
data.setIsDesignator(true);
assertTrue(data.isDesignator());
data.setIssuer("Test");
@@ -80,59 +92,108 @@ public class CommonDictionaryJPATest {
data.setSelectorPath("Test");
assertTrue("Test".equals(data.getSelectorPath()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!=null);
+ assertTrue(data.getUserModifiedBy() != null);
+
+ ConstraintValue constraintValue = new ConstraintValue("Greeting", "Hello");
+ data.getConstraintValues().add(constraintValue);
+ assertEquals("Hello", data.getConstraintValues().iterator().next().getValue());
+
+ data.removeConstraintValue(constraintValue);
+ assertTrue(data.getConstraintValues().isEmpty());
+
+ data.addConstraintValue(constraintValue);
+ assertEquals("Hello", data.getConstraintValues().iterator().next().getValue());
+
+ data.setConstraintValues(null);
+ assertNull(data.getConstraintValues());
+
+ data.addConstraintValue(constraintValue);
+ assertEquals("Hello", data.getConstraintValues().iterator().next().getValue());
+
+ data.removeAllConstraintValues();
+ assertTrue(data.getConstraintValues().isEmpty());
+
+ data.setConstraintValues(null);
+ assertNull(data.getConstraintValues());
+
+ data.removeAllConstraintValues();
+ assertNull(data.getConstraintValues());
+
+ data.addConstraintValue(constraintValue);
+ assertEquals("Hello", data.getConstraintValues().iterator().next().getValue());
+
+ data.setConstraintValues(null);
+ assertNull(data.getConstraintValues());
+
+ Set<ConstraintValue> constraintValueSet = new LinkedHashSet<>();
+ constraintValueSet.add(constraintValue);
+
+ data.setConstraintValues(null);
+ assertNull(data.getConstraintValues());
+
+ data.setConstraintValues(constraintValueSet);
+ assertEquals("Hello", data.getConstraintValues().iterator().next().getValue());
+
+ Attribute data2 = new Attribute(data);
+ assertEquals("Hello", data2.getConstraintValues().iterator().next().getValue());
+
+ data.setIsDesignator(true);
+ assertTrue(data.isDesignator());
+
+ data.setIsDesignator(false);
+ assertFalse(data.isDesignator());
}
@Test
- public void testOnapName(){
+ public void testOnapName() {
OnapName data = new OnapName();
data.preUpdate();
data.prePersist();
data.setId(1);
assertTrue(1 == data.getId());
- data.setOnapName("Test");
- assertTrue("Test".equals(data.getOnapName()));
+ data.setName("Test");
+ assertTrue("Test".equals(data.getName()));
data.setDescription("Test");
assertTrue("Test".equals(data.getDescription()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!=null);
+ assertTrue(data.getUserModifiedBy() != null);
}
@Test
- public void testRiskType(){
+ public void testRiskType() {
RiskType data = new RiskType();
data.preUpdate();
data.prePersist();
data.setId(1);
assertTrue(1 == data.getId());
- data.setRiskName("Test");
- assertTrue("Test".equals(data.getRiskName()));
+ data.setName("Test");
+ assertTrue("Test".equals(data.getName()));
data.setDescription("Test");
assertTrue("Test".equals(data.getDescription()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!=null);
+ assertTrue(data.getUserModifiedBy() != null);
}
@Test
- public void testSafePolicyWarning(){
+ public void testSafePolicyWarning() {
SafePolicyWarning data = new SafePolicyWarning();
data.setId(1);
assertTrue(1 == data.getId());
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ConfigurationDataEntityTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ConfigurationDataEntityTest.java
index da5dd5005..a18fcbae3 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ConfigurationDataEntityTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ConfigurationDataEntityTest.java
@@ -3,13 +3,14 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -25,47 +26,51 @@ import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
+
import java.util.Date;
+
import org.junit.Test;
public class ConfigurationDataEntityTest {
- @Test
- public void testEquals() {
- // Set up test data
- String value = "testVal";
- Date date = new Date();
- ConfigurationDataEntity entity = new ConfigurationDataEntity();
- entity.prePersist();
- ConfigurationDataEntity entity2 = new ConfigurationDataEntity();
- ConfigurationDataEntity entity3 = new ConfigurationDataEntity();
+ @Test
+ public void testEquals() {
+ // Set up test data
+ String value = "testVal";
+ ConfigurationDataEntity entity = new ConfigurationDataEntity();
+ entity.prePersist();
+ ConfigurationDataEntity entity3 = new ConfigurationDataEntity();
+
+ // Test set and get
+ entity3.preUpdate();
+ entity3.setConfigBody(value);
+ assertEquals(value, entity3.getConfigBody());
+ entity3.setCreatedBy(value);
+ assertEquals(value, entity3.getCreatedBy());
+ entity3.setModifiedBy(value);
+ assertEquals(value, entity3.getModifiedBy());
+
+ Date date = new Date();
+ entity3.setModifiedDate(date);
+ assertEquals(date, entity3.getModifiedDate());
+ assertEquals(0, entity3.getVersion());
+ assertNull(entity3.getCreatedDate());
+ entity3.setDeleted(true);
+ assertEquals(true, entity3.isDeleted());
+ entity3.setDescription(value);
+ assertEquals(value, entity3.getDescription());
+ entity3.setConfigType(value);
+ assertEquals(value, entity3.getConfigType());
+ entity3.setConfigurationName(value);
+ assertEquals(value, entity3.getConfigurationName());
+ assertEquals(0, entity3.getConfigurationDataId());
- // Test set and get
- entity3.preUpdate();
- entity3.setConfigBody(value);
- assertEquals(value, entity3.getConfigBody());
- entity3.setCreatedBy(value);
- assertEquals(value, entity3.getCreatedBy());
- entity3.setModifiedBy(value);
- assertEquals(value, entity3.getModifiedBy());
- entity3.setModifiedDate(date);
- assertEquals(date, entity3.getModifiedDate());
- assertEquals(0, entity3.getVersion());
- assertNull(entity3.getCreatedDate());
- entity3.setDeleted(true);
- assertEquals(true, entity3.isDeleted());
- entity3.setDescription(value);
- assertEquals(value, entity3.getDescription());
- entity3.setConfigType(value);
- assertEquals(value, entity3.getConfigType());
- entity3.setConfigurationName(value);
- assertEquals(value, entity3.getConfigurationName());
- assertEquals(0, entity3.getConfigurationDataId());
+ // Test method combinations
+ assertEquals(false, entity.equals(null));
+ assertEquals(true, entity.equals(entity));
+ assertEquals(false, entity.equals(value));
- // Test method combinations
- assertEquals(false, entity.equals(null));
- assertEquals(true, entity.equals(entity));
- assertEquals(false, entity.equals(value));
- assertEquals(false, entity.equals(entity2));
- assertThat(entity.hashCode(), is(not(0)));
- }
+ ConfigurationDataEntity entity2 = new ConfigurationDataEntity();
+ assertEquals(false, entity.equals(entity2));
+ assertThat(entity.hashCode(), is(not(0)));
+ }
}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DecisionDictionaryJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DecisionDictionaryJpaTest.java
index b1fc69903..b664cf3ed 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DecisionDictionaryJPATest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DecisionDictionaryJpaTest.java
@@ -3,13 +3,14 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -17,6 +18,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.rest.jpa;
import static org.junit.Assert.assertTrue;
@@ -28,11 +30,19 @@ import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
-public class DecisionDictionaryJPATest {
+/**
+ * The Class DecisionDictionaryJpaTest.
+ */
+public class DecisionDictionaryJpaTest {
- private static Logger logger = FlexLogger.getLogger(DecisionDictionaryJPATest.class);
+ private static Logger logger = FlexLogger.getLogger(DecisionDictionaryJpaTest.class);
private UserInfo userInfo;
+ /**
+ * Sets the up.
+ *
+ * @throws Exception the exception
+ */
@Before
public void setUp() throws Exception {
logger.info("setUp: Entering");
@@ -42,8 +52,11 @@ public class DecisionDictionaryJPATest {
logger.info("setUp: exit");
}
+ /**
+ * Test decision settings.
+ */
@Test
- public void testDecisionSettings(){
+ public void testDecisionSettings() {
DecisionSettings data = new DecisionSettings();
data.setId(1);
assertTrue(1 == data.getId());
@@ -54,7 +67,7 @@ public class DecisionDictionaryJPATest {
data.setXacmlId("Test");
assertTrue("Test".equals(data.getXacmlId()));
data.setDatatypeBean(new Datatype());
- assertTrue(data.getDatatypeBean()!=null);
+ assertTrue(data.getDatatypeBean() != null);
data.setIssuer("Test");
assertTrue("Test".equals(data.getIssuer()));
data.setMustBePresent(true);
@@ -62,17 +75,20 @@ public class DecisionDictionaryJPATest {
data.setPriority("Test");
assertTrue("Test".equals(data.getPriority()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!=null);
+ assertTrue(data.getUserModifiedBy() != null);
}
+ /**
+ * Test rainy day treatments.
+ */
@Test
- public void testRainyDayTreatments(){
+ public void testRainyDayTreatments() {
RainyDayTreatments data = new RainyDayTreatments();
data.setId(1);
assertTrue(1 == data.getId());
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DictionaryDataTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DictionaryDataTest.java
index 486d36442..1b4bb7114 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DictionaryDataTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DictionaryDataTest.java
@@ -5,6 +5,7 @@
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 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,6 +24,7 @@
package org.onap.policy.rest.jpa;
import static org.junit.Assert.assertEquals;
+
import org.junit.Test;
public class DictionaryDataTest {
@@ -34,7 +36,7 @@ public class DictionaryDataTest {
String value = "testData1";
// Set Data
- dictData.setId(1);;
+ dictData.setId(1);
dictData.setDictionaryDataByName(value);
dictData.setDictionaryName(value);
dictData.setDictionaryUrl(value);
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DummyIdentifier.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DummyIdentifier.java
new file mode 100644
index 000000000..bd88db29a
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DummyIdentifier.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.rest.jpa;
+
+import com.att.research.xacml.api.Identifier;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+/**
+ * Dummy category identifier class.
+ */
+public class DummyIdentifier implements Identifier {
+
+ @Override
+ public String stringValue() {
+ return this.getClass().getName();
+ }
+
+ @Override
+ public URI getUri() {
+ try {
+ return new URI(this.getClass().getName());
+ } catch (URISyntaxException e) {
+ return null;
+ }
+ }
+}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/FWDictionaryJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/FwDictionaryJpaTest.java
index b3b23e429..42df1c93d 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/FWDictionaryJPATest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/FwDictionaryJpaTest.java
@@ -3,13 +3,14 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -17,6 +18,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.rest.jpa;
import static org.junit.Assert.assertTrue;
@@ -28,11 +30,19 @@ import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
-public class FWDictionaryJPATest {
+/**
+ * The Class FWDictionaryJPATest.
+ */
+public class FwDictionaryJpaTest {
- private static Logger logger = FlexLogger.getLogger(FWDictionaryJPATest.class);
+ private static Logger logger = FlexLogger.getLogger(FwDictionaryJpaTest.class);
private UserInfo userInfo;
+ /**
+ * Sets the up.
+ *
+ * @throws Exception the exception
+ */
@Before
public void setUp() throws Exception {
logger.info("setUp: Entering");
@@ -42,8 +52,11 @@ public class FWDictionaryJPATest {
logger.info("setUp: exit");
}
+ /**
+ * Test action list.
+ */
@Test
- public void testActionList(){
+ public void testActionList() {
ActionList data = new ActionList();
data.setId(1);
assertTrue(1 == data.getId());
@@ -53,8 +66,11 @@ public class FWDictionaryJPATest {
assertTrue("Test".equals(data.getDescription()));
}
+ /**
+ * Test port list.
+ */
@Test
- public void testPortList(){
+ public void testPortList() {
PortList data = new PortList();
data.setId(1);
assertTrue(1 == data.getId());
@@ -64,8 +80,11 @@ public class FWDictionaryJPATest {
assertTrue("Test".equals(data.getDescription()));
}
+ /**
+ * Test protocol list.
+ */
@Test
- public void testProtocolList(){
+ public void testProtocolList() {
ProtocolList data = new ProtocolList();
data.setId(1);
assertTrue(1 == data.getId());
@@ -75,8 +94,11 @@ public class FWDictionaryJPATest {
assertTrue("Test".equals(data.getDescription()));
}
+ /**
+ * Test security zone.
+ */
@Test
- public void testSecurityZone(){
+ public void testSecurityZone() {
SecurityZone data = new SecurityZone();
data.setId(1);
assertTrue(1 == data.getId());
@@ -86,8 +108,11 @@ public class FWDictionaryJPATest {
assertTrue("Test".equals(data.getZoneValue()));
}
+ /**
+ * Test zone.
+ */
@Test
- public void testZone(){
+ public void testZone() {
Zone data = new Zone();
data.setId(1);
assertTrue(1 == data.getId());
@@ -97,8 +122,11 @@ public class FWDictionaryJPATest {
assertTrue("Test".equals(data.getZoneValue()));
}
+ /**
+ * Test address group.
+ */
@Test
- public void testAddressGroup(){
+ public void testAddressGroup() {
AddressGroup data = new AddressGroup();
data.setId(1);
assertTrue(1 == data.getId());
@@ -110,8 +138,11 @@ public class FWDictionaryJPATest {
assertTrue("Test".equals(data.getDescription()));
}
+ /**
+ * Test prefix list.
+ */
@Test
- public void testPrefixList(){
+ public void testPrefixList() {
PrefixList data = new PrefixList();
data.setId(1);
assertTrue(1 == data.getId());
@@ -123,8 +154,11 @@ public class FWDictionaryJPATest {
assertTrue("Test".equals(data.getDescription()));
}
+ /**
+ * Test FW dictionary list.
+ */
@Test
- public void testFWDictionaryList(){
+ public void testFwDictionaryList() {
FirewallDictionaryList data = new FirewallDictionaryList();
data.setId(1);
assertTrue(1 == data.getId());
@@ -138,9 +172,12 @@ public class FWDictionaryJPATest {
assertTrue("Test".equals(data.getServiceList()));
}
+ /**
+ * Test FW tag.
+ */
@Test
- public void testFWTag(){
- FWTag data = new FWTag();
+ public void testFwTag() {
+ FwTag data = new FwTag();
data.preUpdate();
data.prePersist();
data.setId(1);
@@ -152,18 +189,21 @@ public class FWDictionaryJPATest {
data.setTagValues("Test");
assertTrue("Test".equals(data.getTagValues()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!=null);
+ assertTrue(data.getUserModifiedBy() != null);
}
+ /**
+ * Test FW tag picker.
+ */
@Test
- public void testFWTagPicker(){
- FWTagPicker data = new FWTagPicker();
+ public void testFwTagPicker() {
+ FwTagPicker data = new FwTagPicker();
data.preUpdate();
data.prePersist();
data.setId(1);
@@ -177,17 +217,20 @@ public class FWDictionaryJPATest {
data.setTagValues("Test");
assertTrue("Test".equals(data.getTagValues()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!=null);
+ assertTrue(data.getUserModifiedBy() != null);
}
+ /**
+ * Test service list.
+ */
@Test
- public void testServiceList(){
+ public void testServiceList() {
ServiceList data = new ServiceList();
data.setId(1);
assertTrue(1 == data.getId());
@@ -197,16 +240,19 @@ public class FWDictionaryJPATest {
assertTrue("Test".equals(data.getServiceDescription()));
data.setServiceType("Test");
assertTrue("Test".equals(data.getServiceType()));
- data.setServiceTransProtocol("Test");
- assertTrue("Test".equals(data.getServiceTransProtocol()));
+ data.setServiceTransportProtocol("Test");
+ assertTrue("Test".equals(data.getServiceTransportProtocol()));
data.setServiceAppProtocol("Test");
assertTrue("Test".equals(data.getServiceAppProtocol()));
data.setServicePorts("Test");
assertTrue("Test".equals(data.getServicePorts()));
}
+ /**
+ * Test term list.
+ */
@Test
- public void testTermList(){
+ public void testTermList() {
TermList data = new TermList();
data.preUpdate();
data.prePersist();
@@ -215,15 +261,15 @@ public class FWDictionaryJPATest {
data.setTermName("Test");
assertTrue("Test".equals(data.getTermName()));
data.setDescription("Test");
- assertTrue("Test".equals(data.getTermDescription()));
- data.setFromZones("Test");
+ assertTrue("Test".equals(data.getDescription()));
+ data.setFromZone("Test");
assertTrue("Test".equals(data.getFromZone()));
- data.setToZones("Test");
+ data.setToZone("Test");
assertTrue("Test".equals(data.getToZone()));
- data.setSrcIPList("Test");
- assertTrue("Test".equals(data.getSrcIPList()));
- data.setDestIPList("Test");
- assertTrue("Test".equals(data.getDestIPList()));
+ data.setSrcIpList("Test");
+ assertTrue("Test".equals(data.getSrcIpList()));
+ data.setDestIpList("Test");
+ assertTrue("Test".equals(data.getDestIpList()));
data.setProtocolList("Test");
assertTrue("Test".equals(data.getProtocolList()));
data.setPortList("Test");
@@ -235,17 +281,20 @@ public class FWDictionaryJPATest {
data.setAction("Test");
assertTrue("Test".equals(data.getAction()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
+ assertTrue(data.getModifiedDate() != null);
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!=null);
+ assertTrue(data.getUserModifiedBy() != null);
}
+ /**
+ * Test group service list.
+ */
@Test
- public void testGroupServiceList(){
+ public void testGroupServiceList() {
GroupServiceList data = new GroupServiceList();
data.setId(1);
assertTrue(1 == data.getId());
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/GetterSetterToStringTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/GetterSetterToStringTest.java
new file mode 100644
index 000000000..62d486c63
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/GetterSetterToStringTest.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.rest.jpa;
+
+import com.openpojo.reflection.filters.FilterClassName;
+import com.openpojo.reflection.filters.FilterPackageInfo;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+
+import org.junit.Test;
+import org.onap.policy.common.utils.test.ToStringTester;
+
+/**
+ * Class to perform unit testing of POJOs.
+ */
+public class GetterSetterToStringTest {
+ private static final String POJO_PACKAGE = "org.onap.policy.rest.jpa";
+
+ @Test
+ public void testPdpModels() {
+ // @formatter:off
+ final Validator validator =
+ ValidatorBuilder.create()
+ .with(new ToStringTester())
+ .with(new SetterTester())
+ .with(new GetterTester())
+ .build();
+
+ // exclude Test classes and PdpMessage
+ validator.validate(
+ POJO_PACKAGE,
+ new FilterPackageInfo(),
+ new FilterClassName("^((?!Test$).)*$")
+ );
+ // @formatter:on
+ }
+}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroServiceDictionaryJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroServiceDictionaryJpaTest.java
index 548e3fc84..174d63506 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroServiceDictionaryJPATest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroServiceDictionaryJpaTest.java
@@ -3,13 +3,14 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -17,8 +18,10 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.rest.jpa;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
@@ -26,11 +29,19 @@ import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
-public class MicroServiceDictionaryJPATest {
+/**
+ * The Class MicroServiceDictionaryJpaTest.
+ */
+public class MicroServiceDictionaryJpaTest {
- private static Logger logger = FlexLogger.getLogger(MicroServiceDictionaryJPATest.class);
+ private static Logger logger = FlexLogger.getLogger(MicroServiceDictionaryJpaTest.class);
private UserInfo userInfo;
+ /**
+ * Sets the up.
+ *
+ * @throws Exception the exception
+ */
@Before
public void setUp() throws Exception {
logger.info("setUp: Entering");
@@ -40,9 +51,12 @@ public class MicroServiceDictionaryJPATest {
logger.info("setUp: exit");
}
+ /**
+ * Test DCAE users.
+ */
@Test
- public void testDCAEUsers(){
- DCAEUsers data = new DCAEUsers();
+ public void testDcaeUsers() {
+ DcaeUsers data = new DcaeUsers();
data.setId(1);
assertTrue(1 == data.getId());
data.setName("Test");
@@ -51,9 +65,12 @@ public class MicroServiceDictionaryJPATest {
assertTrue("Test".equals(data.getDescriptionValue()));
}
+ /**
+ * Test DCA euuid.
+ */
@Test
- public void testDCAEuuid(){
- DCAEuuid data = new DCAEuuid();
+ public void testDcaeUuid() {
+ DcaeUuid data = new DcaeUuid();
data.setId(1);
assertTrue(1 == data.getId());
data.setName("Test");
@@ -62,30 +79,39 @@ public class MicroServiceDictionaryJPATest {
assertTrue("Test".equals(data.getDescription()));
}
+ /**
+ * Test MS config name.
+ */
@Test
- public void testMSConfigName(){
+ public void testMsConfigName() {
MicroServiceConfigName data = new MicroServiceConfigName();
data.setId(1);
assertTrue(1 == data.getId());
data.setName("Test");
assertTrue("Test".equals(data.getName()));
- data.setDescriptionValue("Test");
- assertTrue("Test".equals(data.getDescriptionValue()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
}
+ /**
+ * Test MS config location.
+ */
@Test
- public void testMSConfigLocation(){
+ public void testMsConfigLocation() {
MicroServiceLocation data = new MicroServiceLocation();
data.setId(1);
assertTrue(1 == data.getId());
data.setName("Test");
assertTrue("Test".equals(data.getName()));
- data.setDescriptionValue("Test");
- assertTrue("Test".equals(data.getDescriptionValue()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
}
+ /**
+ * Test MS models.
+ */
@Test
- public void testMSModels(){
+ public void testMsModels() {
MicroServiceModels data = new MicroServiceModels();
data.setId(1);
assertTrue(1 == data.getId());
@@ -101,18 +127,22 @@ public class MicroServiceDictionaryJPATest {
assertTrue("Test".equals(data.getAnnotation()));
data.setAttributes("Test");
assertTrue("Test".equals(data.getAttributes()));
- data.setRef_attributes("Test");
- assertTrue("Test".equals(data.getRef_attributes()));
+ data.setRefAttributes("Test");
+ assertTrue("Test".equals(data.getRefAttributes()));
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
- data.setSub_attributes("Test");
- assertTrue("Test".equals(data.getSub_attributes()));
+ assertTrue(data.getUserCreatedBy() != null);
+ data.setSubAttributes("Test");
+ assertTrue("Test".equals(data.getSubAttributes()));
data.setVersion("Test");
assertTrue("Test".equals(data.getVersion()));
+ assertFalse(data.isDecisionModel());
}
+ /**
+ * Test MS attribute dictionary.
+ */
@Test
- public void testMSAttributeDictionary(){
+ public void testMsAttributeDictionary() {
MicroServiceAttribute data = new MicroServiceAttribute();
data.setId(1);
assertTrue(1 == data.getId());
@@ -124,52 +154,67 @@ public class MicroServiceDictionaryJPATest {
assertTrue("Test".equals(data.getModelName()));
}
+ /**
+ * Test policy scope service.
+ */
@Test
- public void testPolicyScopeService(){
+ public void testPolicyScopeService() {
PolicyScopeService data = new PolicyScopeService();
data.setId(1);
assertTrue(1 == data.getId());
data.setName("Test");
assertTrue("Test".equals(data.getName()));
- data.setDescriptionValue("Test");
- assertTrue("Test".equals(data.getDescriptionValue()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
}
+ /**
+ * Test policy scope resource.
+ */
@Test
- public void testPolicyScopeResource(){
+ public void testPolicyScopeResource() {
PolicyScopeResource data = new PolicyScopeResource();
data.setId(1);
assertTrue(1 == data.getId());
data.setName("Test");
assertTrue("Test".equals(data.getName()));
- data.setDescriptionValue("Test");
- assertTrue("Test".equals(data.getDescriptionValue()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
}
+ /**
+ * Test policy scope type.
+ */
@Test
- public void testPolicyScopeType(){
+ public void testPolicyScopeType() {
PolicyScopeType data = new PolicyScopeType();
data.setId(1);
assertTrue(1 == data.getId());
data.setName("Test");
assertTrue("Test".equals(data.getName()));
- data.setDescriptionValue("Test");
- assertTrue("Test".equals(data.getDescriptionValue()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
}
+ /**
+ * Test policy scope closed loop.
+ */
@Test
- public void testPolicyScopeClosedLoop(){
+ public void testPolicyScopeClosedLoop() {
PolicyScopeClosedLoop data = new PolicyScopeClosedLoop();
data.setId(1);
assertTrue(1 == data.getId());
data.setName("Test");
assertTrue("Test".equals(data.getName()));
- data.setDescriptionValue("Test");
- assertTrue("Test".equals(data.getDescriptionValue()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
}
+ /**
+ * Test policy scope group policy scope list.
+ */
@Test
- public void testPolicyScopeGroupPolicyScopeList(){
+ public void testPolicyScopeGroupPolicyScopeList() {
GroupPolicyScopeList data = new GroupPolicyScopeList();
data.setId(1);
assertTrue(1 == data.getId());
@@ -181,8 +226,11 @@ public class MicroServiceDictionaryJPATest {
assertTrue("Test".equals(data.getGroupList()));
}
+ /**
+ * Test closed loops.
+ */
@Test
- public void testClosedLoops(){
+ public void testClosedLoops() {
ClosedLoops data = new ClosedLoops();
data.setId(1);
assertTrue(1 == data.getId());
@@ -194,9 +242,12 @@ public class MicroServiceDictionaryJPATest {
assertTrue("Test".equals(data.getYaml()));
}
+ /**
+ * Test VM type.
+ */
@Test
- public void testVMType(){
- VMType data = new VMType();
+ public void testVmType() {
+ VmType data = new VmType();
data.setId(1);
assertTrue(1 == data.getId());
data.setName("Test");
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroserviceHeaderdeFaultsTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroserviceHeaderdeFaultsTest.java
index 62452dcb0..cbccc3b96 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroserviceHeaderdeFaultsTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroserviceHeaderdeFaultsTest.java
@@ -3,13 +3,14 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -21,33 +22,34 @@
package org.onap.policy.rest.jpa;
import static org.junit.Assert.assertEquals;
+
import org.junit.Test;
public class MicroserviceHeaderdeFaultsTest {
- @Test
- public void testHeader() {
- // Set up test data
- String value = "testVal";
- MicroserviceHeaderdeFaults header = new MicroserviceHeaderdeFaults();
- header.prePersist();
- header.preUpdate();
+ @Test
+ public void testHeader() {
+ // Set up test data
+ String value = "testVal";
+ MicroserviceHeaderdeFaults header = new MicroserviceHeaderdeFaults();
+ header.prePersist();
+ header.preUpdate();
- // Set data
- header.setGuard(value);
- header.setId(1);
- header.setModelName(value);
- header.setOnapName(value);
- header.setPriority(value);
- header.setRiskLevel(value);
- header.setRiskType(value);
+ // Set data
+ header.setGuard(value);
+ header.setId(1);
+ header.setModelName(value);
+ header.setOnapName(value);
+ header.setPriority(value);
+ header.setRiskLevel(value);
+ header.setRiskType(value);
- // Test gets
- assertEquals(value, header.getGuard());
- assertEquals(1, header.getId());
- assertEquals(value, header.getModelName());
- assertEquals(value, header.getOnapName());
- assertEquals(value, header.getPriority());
- assertEquals(value, header.getRiskLevel());
- assertEquals(value, header.getRiskType());
- }
+ // Test gets
+ assertEquals(value, header.getGuard());
+ assertEquals(1, header.getId());
+ assertEquals(value, header.getModelName());
+ assertEquals(value, header.getOnapName());
+ assertEquals(value, header.getPriority());
+ assertEquals(value, header.getRiskLevel());
+ assertEquals(value, header.getRiskType());
+ }
}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/OptimizationModelsJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/OptimizationModelsJpaTest.java
index 243cb5106..81481e191 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/OptimizationModelsJPATest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/OptimizationModelsJpaTest.java
@@ -3,13 +3,14 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -17,6 +18,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.rest.jpa;
import static org.junit.Assert.assertTrue;
@@ -26,11 +28,19 @@ import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
-public class OptimizationModelsJPATest {
+/**
+ * The Class OptimizationModelsJpaTest.
+ */
+public class OptimizationModelsJpaTest {
- private static Logger logger = FlexLogger.getLogger(OptimizationModelsJPATest.class);
+ private static Logger logger = FlexLogger.getLogger(OptimizationModelsJpaTest.class);
private UserInfo userInfo;
+ /**
+ * Sets the up.
+ *
+ * @throws Exception the exception
+ */
@Before
public void setUp() throws Exception {
logger.info("setUp: Entering");
@@ -40,8 +50,11 @@ public class OptimizationModelsJPATest {
logger.info("setUp: exit");
}
+ /**
+ * Test ms models.
+ */
@Test
- public void testMSModels(){
+ public void testMsModels() {
OptimizationModels data = new OptimizationModels();
data.setId(1);
assertTrue(1 == data.getId());
@@ -60,12 +73,11 @@ public class OptimizationModelsJPATest {
data.setRefattributes("Test");
assertTrue("Test".equals(data.getRefattributes()));
data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
+ assertTrue(data.getUserCreatedBy() != null);
data.setSubattributes("Test");
assertTrue("Test".equals(data.getSubattributes()));
data.setVersion("Test");
assertTrue("Test".equals(data.getVersion()));
}
-
}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PIPConfigurationTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PIPConfigurationTest.java
deleted file mode 100644
index 1a4c2756b..000000000
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PIPConfigurationTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP-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.rest.jpa;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Properties;
-import java.util.Set;
-import org.junit.Test;
-import com.att.research.xacml.api.pip.PIPException;
-import com.att.research.xacml.util.XACMLProperties;
-
-public class PIPConfigurationTest {
- @Test
- public void testConfig() throws PIPException {
- String value = "testVal";
- String id = "1";
- PIPConfigParam param = new PIPConfigParam();
- param.setParamName(value);
- param.setParamValue(value);
- Set<PIPConfigParam> params = new HashSet<PIPConfigParam>();
- PIPResolver resolver = new PIPResolver();
- resolver.setClassname(value);
- resolver.setName(value);
- params.add(param);
- Set<PIPResolver> resolvers = new HashSet<PIPResolver>();
- resolvers.add(resolver);
- Properties props = new Properties();
- props.setProperty(id + ".classname", value);
- props.setProperty(XACMLProperties.PROP_PIP_ENGINES, id);
- PIPType type = new PIPType();
- Date date = new Date();
-
- // Test constructors
- PIPConfiguration config = new PIPConfiguration();
- assertNotNull(config);
- config.setPipconfigParams(params);
- config.setPipresolvers(resolvers);
- PIPConfiguration config2 = new PIPConfiguration(config, value);
- assertNotNull(config2);
- config2.prePersist();
- config2.preUpdate();
- PIPConfiguration config3 = new PIPConfiguration(id, props);
- assertNotNull(config3);
- PIPConfiguration config4 = new PIPConfiguration(id, props, value);
- assertNotNull(config4);
-
- // Test set and get
- config.setId(1);
- assertEquals(1, config.getId());
- config.setDescription(value);
- assertEquals(value, config.getDescription());
- config.setName(id);
- assertEquals(id, config.getName());
- config.setClassname(value);
- assertEquals(value, config.getClassname());
- config.setIssuer(value);
- assertEquals(value, config.getIssuer());
- config.setReadOnly(true);
- assertEquals('1', config.getReadOnly());
- config.setReadOnly('0');
- assertEquals('0', config.getReadOnly());
- assertEquals(false, config.isReadOnly());
- config.setRequiresResolvers('t');
- assertEquals('t', config.getRequiresResolvers());
- config.setReadOnly(false);
- assertEquals('0', config.getReadOnly());
- config.setPiptype(type);
- assertEquals(type, config.getPiptype());
- config.setRequiresResolvers(false);
- assertEquals('0', config.getRequiresResolvers());
- config.setCreatedBy(value);
- assertEquals(value, config.getCreatedBy());
- config.setCreatedDate(date);
- assertEquals(date, config.getCreatedDate());
- config.setModifiedBy(value);
- assertEquals(value, config.getModifiedBy());
- config.setModifiedDate(date);
- assertEquals(date, config.getModifiedDate());
- config.setRequiresResolvers(true);
- assertEquals(true, config.requiresResolvers());
- assertEquals(8, config.getConfiguration(id).size());
- assertEquals(9, config.generateProperties(id).size());
-
- // Test remove and clear
- assertEquals(param, config.removePipconfigParam(param));
- config.clearConfigParams();
- assertEquals(0, config.getPipconfigParams().size());
- config.removePipresolver(resolver);
- assertEquals(0, config.getPipresolvers().size());
-
- // Test import
- assertEquals(1, PIPConfiguration.importPIPConfigurations(props).size());
- config.readProperties(id, props);
- assertEquals(id, config.getName());
-
- // Test toString
- String configString = config.toString().replaceAll("@[0-9a-f]*", "");
- assertEquals(323, configString.length());
- }
-}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PipConfigurationTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PipConfigurationTest.java
new file mode 100644
index 000000000..9bc95dc5f
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PipConfigurationTest.java
@@ -0,0 +1,196 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-REST
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.rest.jpa;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import com.att.research.xacml.api.pip.PIPException;
+import com.att.research.xacml.std.pip.engines.StdConfigurableEngine;
+import com.att.research.xacml.util.XACMLProperties;
+
+import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.Test;
+
+public class PipConfigurationTest {
+ @Test
+ public void testConfig() throws PIPException {
+ String value = "testVal";
+ PipConfigParam param = new PipConfigParam();
+ param.setParamName(value);
+ param.setParamValue(value);
+ Set<PipConfigParam> params = new HashSet<PipConfigParam>();
+ PipResolver resolver = new PipResolver();
+ resolver.setClassname(value);
+ resolver.setName(value);
+ params.add(param);
+ Set<PipResolver> resolvers = new HashSet<PipResolver>();
+ resolvers.add(resolver);
+ Properties props = new Properties();
+
+ String id = "1";
+ props.setProperty(id + ".classname", value);
+ props.setProperty(XACMLProperties.PROP_PIP_ENGINES, id);
+
+ // Test constructors
+ PipConfiguration config = new PipConfiguration();
+ assertNotNull(config);
+ config.setPipconfigParams(params);
+ config.setPipresolvers(resolvers);
+ PipConfiguration config2 = new PipConfiguration(config, value);
+ assertNotNull(config2);
+ config2.prePersist();
+ config2.preUpdate();
+ PipConfiguration config3 = new PipConfiguration(id, props);
+ assertNotNull(config3);
+ PipConfiguration config4 = new PipConfiguration(id, props, value);
+ assertNotNull(config4);
+
+ // Test set and get
+ config.setId(1);
+ assertEquals(1, config.getId());
+ config.setDescription(value);
+ assertEquals(value, config.getDescription());
+ config.setName(id);
+ assertEquals(id, config.getName());
+ config.setClassname(value);
+ assertEquals(value, config.getClassname());
+ config.setIssuer(value);
+ assertEquals(value, config.getIssuer());
+ config.setReadOnlyFlag(true);
+ assertEquals('1', config.getReadOnly());
+ config.setReadOnly('0');
+ assertEquals('0', config.getReadOnly());
+ assertEquals(false, config.isReadOnly());
+ config.setRequiresResolvers('t');
+ assertEquals('t', config.getRequiresResolvers());
+ config.setReadOnlyFlag(false);
+ assertEquals('0', config.getReadOnly());
+
+ PipType type = new PipType();
+ config.setPiptype(type);
+ assertEquals(type, config.getPiptype());
+ config.setRequiresResolversFlag(false);
+ assertEquals('0', config.getRequiresResolvers());
+ config.setCreatedBy(value);
+ assertEquals(value, config.getCreatedBy());
+
+ Date date = new Date();
+ config.setCreatedDate(date);
+ assertEquals(date, config.getCreatedDate());
+ config.setModifiedBy(value);
+ assertEquals(value, config.getModifiedBy());
+ config.setModifiedDate(date);
+ assertEquals(date, config.getModifiedDate());
+ config.setRequiresResolversFlag(true);
+ assertTrue(config.requiresResolvers());
+ config.setRequiresResolversFlag(false);
+ assertFalse(config.requiresResolvers());
+ assertEquals(8, config.getConfiguration(id).size());
+ assertEquals(9, config.generateProperties(id).size());
+
+ // Test remove and clear
+ assertEquals(param, config.removePipconfigParam(param));
+ assertNull(config.removePipconfigParam(null));
+ config.clearConfigParams();
+ assertEquals(0, config.getPipconfigParams().size());
+ config.removePipresolver(resolver);
+ assertEquals(0, config.getPipresolvers().size());
+
+ assertEquals(param, config.addPipconfigParam(param));
+ config.clearConfigParams();
+ assertEquals(0, config.getPipconfigParams().size());
+ config.removePipresolver(resolver);
+ assertEquals(0, config.getPipresolvers().size());
+
+ // Test import
+ assertEquals(1, PipConfiguration.importPipConfigurations(props).size());
+ config.readProperties(id, props);
+ assertEquals(id, config.getName());
+
+ // Test toString
+ String configString = config.toString().replaceAll("@[0-9a-f]*", "");
+ assertEquals(322, configString.length());
+
+ assertEquals(0, PipConfiguration.importPipConfigurations(new Properties()).size());
+
+ Properties otherProperties = new Properties();
+ otherProperties.put(XACMLProperties.PROP_PIP_ENGINES, "");
+ assertEquals(0, PipConfiguration.importPipConfigurations(otherProperties).size());
+
+ otherProperties.put(XACMLProperties.PROP_PIP_ENGINES, "badvalue:evenworse");
+ assertEquals(0, PipConfiguration.importPipConfigurations(otherProperties).size());
+
+ // Test readProperties
+ props.setProperty(id + "." + StdConfigurableEngine.PROP_ISSUER, "himself");
+ props.setProperty(id + ".resolvers", "");
+ props.setProperty(id + ".resolver", "");
+ props.setProperty(id + ".anotherproperty", "");
+ config.readProperties(id, props);
+ assertEquals("himself", config.getIssuer());
+ assertEquals(49, config.getRequiresResolvers());
+
+ props.setProperty(id + ".resolvers", "aaa");
+ assertThatThrownBy(() -> config.readProperties(id, props)).hasMessage("PIP Engine defined without a classname");
+
+ props.setProperty(id + ".resolver.aaa.classname", "somewhere.over.the.Rainbow");
+ props.setProperty(id + ".resolver.aaa." + StdConfigurableEngine.PROP_NAME, "Dorothy");
+ props.setProperty(id + ".resolver.aaa." + StdConfigurableEngine.PROP_DESCRIPTION, "Oz");
+ props.setProperty(id + ".resolver.aaa." + StdConfigurableEngine.PROP_ISSUER, "Wizard");
+ props.setProperty(id + ".resolver.aaa.witch", "North");
+ config.readProperties(id, props);
+
+ PipResolver pipResolver = config.getPipresolvers().iterator().next();
+
+ assertEquals("somewhere.over.the.Rainbow", pipResolver.getClassname());
+ assertEquals("Dorothy", pipResolver.getName());
+ assertEquals("Oz", pipResolver.getDescription());
+ assertEquals("Wizard", pipResolver.getIssuer());
+
+ // Test getConfiguration
+ assertEquals(10, config.getConfiguration(null).size());
+ assertEquals(10, config.getConfiguration("kansas").size());
+ assertEquals(10, config.getConfiguration("kansas.").size());
+ config.setDescription(null);
+ assertEquals(9, config.getConfiguration(null).size());
+ config.setIssuer(null);
+ assertEquals(8, config.getConfiguration(null).size());
+ config.setPipresolvers(new LinkedHashSet<PipResolver>());
+ assertEquals(3, config.getConfiguration(null).size());
+
+ // Test generateProperties
+ assertEquals(4, config.generateProperties(null).size());
+ assertEquals(4, config.generateProperties("kansas").size());
+ assertEquals(4, config.generateProperties("kansas.").size());
+ config.setIssuer("");
+ assertEquals(4, config.generateProperties("kansas.").size());
+ }
+}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PIPJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PipJpaTest.java
index 7421d79c9..2a5dff61f 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PIPJPATest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PipJpaTest.java
@@ -3,13 +3,14 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -17,25 +18,33 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.rest.jpa;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import com.att.research.xacml.api.pip.PIPException;
import java.util.Date;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.Properties;
+import java.util.Set;
import org.junit.Test;
-import com.att.research.xacml.api.pip.PIPException;
-
-public class PIPJPATest {
+public class PipJpaTest {
@Test
- public void testPIPConfigParam(){
- PIPConfigParam data = new PIPConfigParam();
- new PIPConfigParam("test");
- new PIPConfigParam(new PIPConfigParam());
+ public void testPipConfigParam() {
+ PipConfigParam data = new PipConfigParam();
+ new PipConfigParam("test");
+ new PipConfigParam(new PipConfigParam());
data.setId(1);
assertTrue(1 == data.getId());
data.setParamName("Test");
@@ -44,18 +53,20 @@ public class PIPJPATest {
assertTrue("Test".equals(data.getParamValue()));
data.setParamDefault("Test");
assertTrue("Test".equals(data.getParamDefault()));
- data.setPipconfiguration(new PIPConfiguration());
- assertTrue(data.getPipconfiguration()!=null);
- data.setRequired(true);
+ data.setPipconfiguration(new PipConfiguration());
+ assertTrue(data.getPipconfiguration() != null);
+ data.setRequiredFlag(true);
assertTrue(data.isRequired());
+ data.setRequiredFlag(false);
+ assertFalse(data.isRequired());
data.toString();
}
@Test
- public void testPIPResolverParam(){
- PIPResolverParam data = new PIPResolverParam();
- new PIPResolverParam("test");
- new PIPResolverParam(new PIPResolverParam());
+ public void testPipResolverParam() {
+ PipResolverParam data = new PipResolverParam();
+ new PipResolverParam("test");
+ new PipResolverParam(new PipResolverParam());
data.setId(1);
assertTrue(1 == data.getId());
data.setParamName("Test");
@@ -64,40 +75,42 @@ public class PIPJPATest {
assertTrue("Test".equals(data.getParamValue()));
data.setParamDefault("Test");
assertTrue("Test".equals(data.getParamDefault()));
- data.setPipresolver(new PIPResolver());
- assertTrue(data.getPipresolver()!=null);
+ data.setPipresolver(new PipResolver());
+ assertTrue(data.getPipresolver() != null);
data.setRequired(true);
assertTrue(data.isRequired());
+ data.setRequired(false);
+ assertFalse(data.isRequired());
data.toString();
}
@Test
- public void testPIPType(){
- PIPType data = new PIPType();
+ public void testPipType() {
+ PipType data = new PipType();
data.setId(1);
assertTrue(1 == data.getId());
data.setType("Test");
assertTrue("Test".equals(data.getType()));
data.setPipconfigurations(new HashSet<>());
- assertTrue(data.getPipconfigurations()!=null);
- data.addPipconfiguration(new PIPConfiguration());
- data.removePipconfiguration(new PIPConfiguration());
+ assertTrue(data.getPipconfigurations() != null);
+ data.addPipconfiguration(new PipConfiguration());
+ data.removePipconfiguration(new PipConfiguration());
data.setType("SQL");
- assertTrue(data.isSQL());
+ assertTrue(data.isSql());
data.setType("LDAP");
- assertTrue(data.isLDAP());
+ assertTrue(data.isLdap());
data.setType("CSV");
- assertTrue(data.isCSV());
+ assertTrue(data.isCsv());
data.setType("Hyper-CSV");
- assertTrue(data.isHyperCSV());
+ assertTrue(data.isHyperCsv());
data.setType("Custom");
assertTrue(data.isCustom());
}
@Test
- public void testPIPResolver(){
- PIPResolver data = new PIPResolver();
- new PIPResolver(new PIPResolver());
+ public void testPipResolver() {
+ PipResolver data = new PipResolver();
+ new PipResolver(new PipResolver());
data.prePersist();
data.preUpdate();
data.setId(1);
@@ -115,32 +128,50 @@ public class PIPJPATest {
data.setModifiedBy("Test");
assertTrue("Test".equals(data.getModifiedBy()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
- data.setPipconfiguration(new PIPConfiguration());
- assertTrue(data.getPipconfiguration()!=null);
+ assertTrue(data.getModifiedDate() != null);
+ data.setPipconfiguration(new PipConfiguration());
+ assertTrue(data.getPipconfiguration() != null);
data.setPipresolverParams(new HashSet<>());
- assertTrue(data.getPipresolverParams()!=null);
- data.addPipresolverParam(new PIPResolverParam());
- data.removePipresolverParam(new PIPResolverParam());
+ assertTrue(data.getPipresolverParams() != null);
+ data.addPipresolverParam(new PipResolverParam());
+ data.removePipresolverParam(new PipResolverParam());
+ assertNull(data.removePipresolverParam(null));
data.clearParams();
data.getConfiguration("test");
+ assertNotNull(data.getConfiguration("test."));
data.setReadOnly(true);
assertTrue(data.isReadOnly());
+ data.setReadOnly(false);
+ assertFalse(data.isReadOnly());
data.toString();
Properties properties = new Properties();
- data.generateProperties(properties,"test");
+ data.generateProperties(properties, "test");
try {
data.readProperties("test", properties);
} catch (PIPException e) {
fail();
}
+ data.setIssuer("");
+ assertEquals(4, data.getConfiguration("test").size());
+ data.generateProperties(properties, "test.");
+ assertEquals(4, data.getConfiguration("test").size());
+
+ Set<PipResolverParam> pipresolverParams = new LinkedHashSet<>();
+ PipResolverParam prp = new PipResolverParam();
+ prp.setParamName("Dorothy");
+ prp.setParamValue("Gale");
+ pipresolverParams.add(prp);
+ data.setPipresolverParams(pipresolverParams);
+ data.generateProperties(properties, "test");
+ assertEquals(5, data.getConfiguration("test").size());
+ assertEquals(5, new PipResolver(data).getConfiguration("test").size());
}
@Test
- public void testPIPConfiguration(){
- PIPConfiguration data = new PIPConfiguration();
+ public void testPipConfiguration() {
+ PipConfiguration data = new PipConfiguration();
data.prePersist();
data.preUpdate();
data.setId(1);
@@ -158,24 +189,24 @@ public class PIPJPATest {
data.setModifiedBy("Test");
assertTrue("Test".equals(data.getModifiedBy()));
data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
+ assertTrue(data.getCreatedDate() != null);
data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
+ assertTrue(data.getModifiedDate() != null);
try {
data.readProperties("test", data.generateProperties("test"));
} catch (PIPException e) {
fail();
}
- data.setPiptype(new PIPType());
- assertTrue(data.getPiptype()!=null);
+ data.setPiptype(new PipType());
+ assertTrue(data.getPiptype() != null);
data.setPipresolvers(new HashSet<>());
- assertTrue(data.getPipresolvers()!=null);
- data.addPipresolver(new PIPResolver());
- data.removePipresolver(new PIPResolver());
+ assertTrue(data.getPipresolvers() != null);
+ data.addPipresolver(new PipResolver());
+ data.removePipresolver(new PipResolver());
data.getConfiguration("test");
- data.setReadOnly(true);
+ data.setReadOnlyFlag(true);
assertTrue(data.isReadOnly());
- data.setRequiresResolvers(true);
+ data.setRequiresResolversFlag(true);
assertTrue(data.requiresResolvers());
data.toString();
}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyAuditlogTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyAuditlogTest.java
index 15e28b142..1ae1cb3e2 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyAuditlogTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyAuditlogTest.java
@@ -3,6 +3,7 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +22,9 @@
package org.onap.policy.rest.jpa;
import static org.junit.Assert.assertEquals;
+
import java.text.ParseException;
+
import org.junit.Test;
public class PolicyAuditlogTest {
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyEntityJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyEntityJPATest.java
deleted file mode 100644
index 706471281..000000000
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyEntityJPATest.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP-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.rest.jpa;
-
-import static org.junit.Assert.assertTrue;
-
-import java.util.Date;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.policy.common.logging.flexlogger.FlexLogger;
-import org.onap.policy.common.logging.flexlogger.Logger;
-
-public class PolicyEntityJPATest {
-
- private static Logger logger = FlexLogger.getLogger(PolicyEntityJPATest.class);
- private UserInfo userInfo;
-
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
- userInfo = new UserInfo();
- userInfo.setUserLoginId("Test");
- userInfo.setUserName("Test");
- logger.info("setUp: exit");
- }
-
- @Test
- public void testPolicyGroupEntity(){
- PolicyGroupEntity data = new PolicyGroupEntity();
- data.setGroupKey(1);
- assertTrue(1 == data.getGroupKey());
- data.setPolicyid(1);
- assertTrue(1 == data.getPolicyid());
- }
-
- @Test
- public void testPolicyDBDaoEntity(){
- PolicyDBDaoEntity data = new PolicyDBDaoEntity();
- data.prePersist();
- data.preUpdate();
- data.setPolicyDBDaoUrl("Test");
- assertTrue("Test".equals(data.getPolicyDBDaoUrl()));
- data.setDescription("Test");
- assertTrue("Test".equals(data.getDescription()));
- assertTrue(data.getCreatedDate()!=null);
- assertTrue(data.getModifiedDate()!=null);
- data.setUsername("Test");
- assertTrue("Test".equals(data.getUsername()));
- data.setPassword("Test");
- assertTrue("Test".equals(data.getPassword()));
- }
-
- @Test
- public void testDatabaseLockEntity(){
- DatabaseLockEntity data = new DatabaseLockEntity();
- data.setKey(1);
- assertTrue(1 == data.getKey());
- }
-
- @Test
- public void testPolicyEntity(){
- PolicyEntity data = new PolicyEntity();
- data.prePersist();
- data.preUpdate();
- data.setPolicyName("Test");
- assertTrue("Test".equals(data.getPolicyName()));
- data.setDescription("Test");
- assertTrue("Test".equals(data.getDescription()));
- assertTrue(data.getCreatedDate()!=null);
- assertTrue(data.getModifiedDate()!=null);
- data.setPolicyData("Test");
- assertTrue("Test".equals(data.getPolicyData()));
- data.setConfigurationData(new ConfigurationDataEntity());
- assertTrue(data.getConfigurationData()!=null);
- data.setActionBodyEntity(new ActionBodyEntity());
- assertTrue(data.getActionBodyEntity()!=null);
- data.setScope("Test");
- assertTrue("Test".equals(data.getScope()));
- data.setCreatedBy("Test");
- assertTrue("Test".equals(data.getCreatedBy()));
- data.setModifiedBy("Test");
- assertTrue("Test".equals(data.getModifiedBy()));
- data.setDeleted(true);
- assertTrue(data.isDeleted());
- data.equals(new PolicyEntity());
- data.hashCode();
- }
-
- @Test
- public void testActionBodyEntity(){
- ActionBodyEntity data = new ActionBodyEntity();
- data.prePersist();
- data.preUpdate();
- data.setActionBodyName("Test");
- assertTrue("Test".equals(data.getActionBodyName()));
- data.setActionBody("Test");
- assertTrue("Test".equals(data.getActionBody()));
- data.setCreatedBy("Test");
- assertTrue("Test".equals(data.getCreatedBy()));
- data.setModifiedBy("Test");
- assertTrue("Test".equals(data.getModifiedBy()));
- data.setModifiedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
- assertTrue(data.getModifiedDate()!=null);
- data.setDeleted(true);
- assertTrue(data.isDeleted());
- assertTrue(data.getCreatedDate()!=null);
- assertTrue(data.getModifiedDate()!=null);
- data.equals(new ConfigurationDataEntity());
- data.hashCode();
- }
-
- @Test
- public void testConfigurationDataEntity(){
- ConfigurationDataEntity data = new ConfigurationDataEntity();
- data.prePersist();
- data.preUpdate();
- data.setConfigurationName("Test");
- assertTrue("Test".equals(data.getConfigurationName()));
- data.setConfigType("Test");
- assertTrue("Test".equals(data.getConfigType()));
- data.setConfigBody("Test");
- assertTrue("Test".equals(data.getConfigBody()));
- data.setCreatedBy("Test");
- assertTrue("Test".equals(data.getCreatedBy()));
- data.setDescription("Test");
- assertTrue("Test".equals(data.getDescription()));
- data.setModifiedBy("Test");
- assertTrue("Test".equals(data.getModifiedBy()));
- data.setModifiedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
- assertTrue(data.getModifiedDate()!=null);
- data.setDeleted(true);
- assertTrue(data.isDeleted());
- assertTrue(data.getCreatedDate()!=null);
- assertTrue(data.getModifiedDate()!=null);
- data.equals(new ConfigurationDataEntity());
- data.hashCode();
- }
-
- @Test
- public void testPdpEntity(){
- PdpEntity data = new PdpEntity();
- data.prePersist();
- data.preUpdate();
- data.setPdpId("Test");
- assertTrue("Test".equals(data.getPdpId()));
- data.setPdpName("Test");
- assertTrue("Test".equals(data.getPdpName()));
- data.setGroup(new GroupEntity());
- assertTrue(data.getGroup()!=null);
- data.setCreatedBy("Test");
- assertTrue("Test".equals(data.getCreatedBy()));
- data.setDescription("Test");
- assertTrue("Test".equals(data.getDescription()));
- data.setModifiedBy("Test");
- assertTrue("Test".equals(data.getModifiedBy()));
- data.setJmxPort(1);
- assertTrue(1 == data.getJmxPort());
- data.setDeleted(true);
- assertTrue(data.isDeleted());
- assertTrue(data.getCreatedDate()!=null);
- assertTrue(data.getModifiedDate()!=null);
- }
-
- @Test
- public void testGroupEntity(){
- GroupEntity data = new GroupEntity();
- data.prePersist();
- data.preUpdate();
- data.setGroupId("Test");
- assertTrue("Test".equals(data.getGroupId()));
- data.setGroupName("Test");
- assertTrue("Test".equals(data.getgroupName()));
- data.setCreatedBy("Test");
- assertTrue("Test".equals(data.getCreatedBy()));
- data.setDescription("Test");
- assertTrue("Test".equals(data.getDescription()));
- data.setModifiedBy("Test");
- assertTrue("Test".equals(data.getModifiedBy()));
- data.setDefaultGroup(true);
- assertTrue(data.isDefaultGroup());
- data.setDeleted(true);
- assertTrue(data.isDeleted());
- assertTrue(data.getCreatedDate()!=null);
- assertTrue(data.getModifiedDate()!=null);
- }
-}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyEntityJpaTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyEntityJpaTest.java
new file mode 100644
index 000000000..a55ff8d6e
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyEntityJpaTest.java
@@ -0,0 +1,528 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-REST
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.rest.jpa;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Date;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+
+/**
+ * The Class PolicyEntityJpaTest.
+ */
+public class PolicyEntityJpaTest {
+
+ private static Logger logger = FlexLogger.getLogger(PolicyEntityJpaTest.class);
+ private UserInfo userInfo;
+
+ /**
+ * Sets the up.
+ *
+ * @throws Exception the exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ userInfo = new UserInfo();
+ userInfo.setUserLoginId("Test");
+ userInfo.setUserName("Test");
+ logger.info("setUp: exit");
+ }
+
+ /**
+ * Test policy group entity.
+ */
+ @Test
+ public void testPolicyGroupEntity() {
+ PolicyGroupEntity data = new PolicyGroupEntity();
+ data.setGroupKey(1);
+ assertTrue(1 == data.getGroupKey());
+ data.setPolicyid(1);
+ assertTrue(1 == data.getPolicyid());
+ }
+
+ /**
+ * Test policy DB dao entity.
+ */
+ @Test
+ public void testPolicyDbDaoEntity() {
+ PolicyDbDaoEntity data = new PolicyDbDaoEntity();
+ data.prePersist();
+ data.preUpdate();
+ data.setPolicyDbDaoUrl("Test");
+ assertTrue("Test".equals(data.getPolicyDbDaoUrl()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
+ assertTrue(data.getCreatedDate() != null);
+ assertTrue(data.getModifiedDate() != null);
+ data.setUsername("Test");
+ assertTrue("Test".equals(data.getUsername()));
+ data.setPassword("Test");
+ assertTrue("Test".equals(data.getPassword()));
+ }
+
+ /**
+ * Test database lock entity.
+ */
+ @Test
+ public void testDatabaseLockEntity() {
+ DatabaseLockEntity data = new DatabaseLockEntity();
+ data.setKey(1);
+ assertTrue(1 == data.getKey());
+ }
+
+ /**
+ * Test policy entity.
+ */
+ @Test
+ public void testPolicyEntity() {
+ PolicyEntity data = new PolicyEntity();
+ data.prePersist();
+ data.preUpdate();
+ data.setPolicyName("Test");
+ assertTrue("Test".equals(data.getPolicyName()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
+ assertTrue(data.getCreatedDate() != null);
+ assertTrue(data.getModifiedDate() != null);
+ data.setPolicyData("Test");
+ assertTrue("Test".equals(data.getPolicyData()));
+ data.setConfigurationData(new ConfigurationDataEntity());
+ assertTrue(data.getConfigurationData() != null);
+ data.setActionBodyEntity(new ActionBodyEntity());
+ assertTrue(data.getActionBodyEntity() != null);
+ data.setScope("Test");
+ assertTrue("Test".equals(data.getScope()));
+ data.setCreatedBy("Test");
+ assertTrue("Test".equals(data.getCreatedBy()));
+ data.setModifiedBy("Test");
+ assertTrue("Test".equals(data.getModifiedBy()));
+ data.setDeleted(true);
+ assertTrue(data.isDeleted());
+ data.equals(new PolicyEntity());
+ data.hashCode();
+
+ PolicyEntity entity0 = new PolicyEntity();
+ PolicyEntity entity1 = new PolicyEntity();
+ assertEquals(entity0, entity0);
+ assertEquals(entity0, entity1);
+ assertNotEquals(entity0, null);
+ String helloString = "Hello";
+ Object helloObject = helloString;
+ assertNotEquals(entity0, helloObject);
+
+ entity0.setPolicyId(1);
+ assertNotEquals(entity0, entity1);
+ entity1.setPolicyId(1);
+ assertEquals(entity0, entity1);
+ entity0.setPolicyId(2);
+ assertNotEquals(entity0, entity1);
+ entity1.setPolicyId(2);
+ assertEquals(entity0, entity1);
+
+ entity0.setPolicyName("GoToOz");
+ assertNotEquals(entity0, entity1);
+ entity1.setPolicyName("GoToOz");
+ assertEquals(entity0, entity1);
+ entity1.setPolicyName(null);
+ assertNotEquals(entity0, entity1);
+ entity0.setPolicyName(null);
+ assertEquals(entity0, entity1);
+ entity1.setPolicyName("GoToOz");
+ assertNotEquals(entity0, entity1);
+ entity0.setPolicyName("GoToOz");
+ assertEquals(entity0, entity1);
+ entity1.setPolicyName("GoToOzNow");
+ assertNotEquals(entity0, entity1);
+ entity0.setPolicyName("GoToOzNow");
+ assertEquals(entity0, entity1);
+
+ entity0.setScope("All");
+ assertNotEquals(entity0, entity1);
+ entity1.setScope("All");
+ assertEquals(entity0, entity1);
+ entity1.setScope(null);
+ assertNotEquals(entity0, entity1);
+ entity0.setScope(null);
+ assertEquals(entity0, entity1);
+ entity1.setScope("All");
+ assertNotEquals(entity0, entity1);
+ entity0.setScope("All");
+ assertEquals(entity0, entity1);
+ entity1.setScope("AllIn");
+ assertNotEquals(entity0, entity1);
+ entity0.setScope("AllIn");
+ assertEquals(entity0, entity1);
+
+ entity0.setVersion(1);
+ assertNotEquals(entity0, entity1);
+ entity1.setVersion(1);
+ assertEquals(entity0, entity1);
+
+ entity0.setPolicyVersion(1);
+ assertNotEquals(entity0, entity1);
+ entity1.setPolicyVersion(1);
+ assertEquals(entity0, entity1);
+ entity0.setPolicyVersion(2);
+ assertNotEquals(entity0, entity1);
+ entity1.setPolicyVersion(2);
+ assertEquals(entity0, entity1);
+
+ entity0.setPolicyData("SomeData");
+ assertNotEquals(entity0, entity1);
+ entity1.setPolicyData("SomeData");
+ assertEquals(entity0, entity1);
+ entity1.setPolicyData(null);
+ assertNotEquals(entity0, entity1);
+ entity0.setPolicyData(null);
+ assertEquals(entity0, entity1);
+ entity1.setPolicyData("SomeData");
+ assertNotEquals(entity0, entity1);
+ entity0.setPolicyData("SomeData");
+ assertEquals(entity0, entity1);
+ entity1.setPolicyData("SomeMoreData");
+ assertNotEquals(entity0, entity1);
+ entity0.setPolicyData("SomeMoreData");
+ assertEquals(entity0, entity1);
+
+ ConfigurationDataEntity cde0 = new ConfigurationDataEntity();
+ entity0.setConfigurationDataEntity(cde0);
+ assertNotEquals(entity0, entity1);
+ entity1.setConfigurationDataEntity(cde0);
+ assertEquals(entity0, entity1);
+ entity1.setConfigurationDataEntity(null);
+ assertNotEquals(entity0, entity1);
+ entity0.setConfigurationDataEntity(null);
+ assertEquals(entity0, entity1);
+ ConfigurationDataEntity cde1 = new ConfigurationDataEntity();
+ entity1.setConfigurationDataEntity(cde1);
+ assertNotEquals(entity0, entity1);
+ entity0.setConfigurationDataEntity(cde1);
+ assertEquals(entity0, entity1);
+
+ ActionBodyEntity abe0 = new ActionBodyEntity();
+ entity0.setActionBodyEntity(abe0);
+ assertNotEquals(entity0, entity1);
+ entity1.setActionBodyEntity(abe0);
+ assertEquals(entity0, entity1);
+ entity1.setActionBodyEntity(null);
+ assertNotEquals(entity0, entity1);
+ entity0.setActionBodyEntity(null);
+ assertEquals(entity0, entity1);
+ entity1.setActionBodyEntity(abe0);
+ assertNotEquals(entity0, entity1);
+ entity0.setActionBodyEntity(abe0);
+ assertEquals(entity0, entity1);
+ ActionBodyEntity abe1 = new ActionBodyEntity();
+ entity1.setActionBodyEntity(abe1);
+ assertNotEquals(entity0, entity1);
+ entity0.setActionBodyEntity(abe1);
+ assertEquals(entity0, entity1);
+
+ entity0.setDescription("Description");
+ assertNotEquals(entity0, entity1);
+ entity1.setDescription("Description");
+ assertEquals(entity0, entity1);
+ entity1.setDescription(null);
+ assertNotEquals(entity0, entity1);
+ entity0.setDescription(null);
+ assertEquals(entity0, entity1);
+ entity1.setDescription("Description");
+ assertNotEquals(entity0, entity1);
+ entity0.setDescription("Description");
+ assertEquals(entity0, entity1);
+ assertEquals(entity0, entity1);
+ entity1.setDescription("Description Extra");
+ assertNotEquals(entity0, entity1);
+ entity0.setDescription("Description Extra");
+ assertEquals(entity0, entity1);
+
+ entity0.setDeleted(true);
+ assertNotEquals(entity0, entity1);
+ entity1.setDeleted(true);
+ assertEquals(entity0, entity1);
+ entity0.setDeleted(false);
+ assertNotEquals(entity0, entity1);
+ entity1.setDeleted(false);
+ assertEquals(entity0, entity1);
+
+ entity0.setDeleteReasonCode("NoReason");
+ assertNotEquals(entity0, entity1);
+ entity1.setDeleteReasonCode("NoReason");
+ assertEquals(entity0, entity1);
+ entity1.setDeleteReasonCode(null);
+ assertNotEquals(entity0, entity1);
+ entity0.setDeleteReasonCode(null);
+ assertEquals(entity0, entity1);
+ entity1.setDeleteReasonCode("NoReason");
+ assertNotEquals(entity0, entity1);
+ entity0.setDeleteReasonCode("NoReason");
+ assertEquals(entity0, entity1);
+ assertEquals(entity0, entity1);
+ entity1.setDeleteReasonCode("NoOtherReason");
+ assertNotEquals(entity0, entity1);
+ entity0.setDeleteReasonCode("NoOtherReason");
+ assertEquals(entity0, entity1);
+
+ entity0.setCreatedBy("Dorothy");
+ assertNotEquals(entity0, entity1);
+ entity1.setCreatedBy("Dorothy");
+ assertEquals(entity0, entity1);
+ entity1.setCreatedBy(null);
+ assertNotEquals(entity0, entity1);
+ entity0.setCreatedBy(null);
+ assertEquals(entity0, entity1);
+ entity1.setCreatedBy("Dorothy");
+ assertNotEquals(entity0, entity1);
+ entity0.setCreatedBy("Dorothy");
+ assertEquals(entity0, entity1);
+ entity1.setCreatedBy("Toto");
+ assertNotEquals(entity0, entity1);
+ entity0.setCreatedBy("Toto");
+ assertEquals(entity0, entity1);
+
+ entity0.setCreatedDate(new Date(12345L));
+ assertNotEquals(entity0, entity1);
+ entity1.setCreatedDate(new Date(12345L));
+ assertEquals(entity0, entity1);
+ entity1.setCreatedDate(null);
+ assertNotEquals(entity0, entity1);
+ entity0.setCreatedDate(null);
+ assertEquals(entity0, entity1);
+ entity1.setCreatedDate(new Date(12345L));
+ assertNotEquals(entity0, entity1);
+ entity0.setCreatedDate(new Date(12345L));
+ assertEquals(entity0, entity1);
+ assertEquals(entity0, entity1);
+ entity1.setCreatedDate(new Date(123456L));
+ assertNotEquals(entity0, entity1);
+ entity0.setCreatedDate(new Date(123456L));
+ assertEquals(entity0, entity1);
+
+ entity0.setModifiedBy("Dorothy");
+ assertNotEquals(entity0, entity1);
+ entity1.setModifiedBy("Dorothy");
+ assertEquals(entity0, entity1);
+ entity1.setModifiedBy(null);
+ assertNotEquals(entity0, entity1);
+ entity0.setModifiedBy(null);
+ assertEquals(entity0, entity1);
+ entity1.setModifiedBy("Dorothy");
+ assertNotEquals(entity0, entity1);
+ entity0.setModifiedBy("Dorothy");
+ assertEquals(entity0, entity1);
+ entity1.setModifiedBy("Toto");
+ assertNotEquals(entity0, entity1);
+ entity0.setModifiedBy("Toto");
+ assertEquals(entity0, entity1);
+
+ entity0.setModifiedDate(new Date(12345L));
+ assertNotEquals(entity0, entity1);
+ entity1.setModifiedDate(new Date(12345L));
+ assertEquals(entity0, entity1);
+ entity1.setModifiedDate(null);
+ assertNotEquals(entity0, entity1);
+ entity0.setModifiedDate(null);
+ assertEquals(entity0, entity1);
+ entity1.setModifiedDate(new Date(12345L));
+ assertNotEquals(entity0, entity1);
+ entity0.setModifiedDate(new Date(12345L));
+ assertEquals(entity0, entity1);
+ assertEquals(entity0, entity1);
+ entity1.setModifiedDate(new Date(123456L));
+ assertNotEquals(entity0, entity1);
+ entity0.setModifiedDate(new Date(123456L));
+ assertEquals(entity0, entity1);
+
+ entity0.setDeletedBy("Dorothy");
+ assertNotEquals(entity0, entity1);
+ entity1.setDeletedBy("Dorothy");
+ assertEquals(entity0, entity1);
+ entity1.setDeletedBy(null);
+ assertNotEquals(entity0, entity1);
+ entity0.setDeletedBy(null);
+ assertEquals(entity0, entity1);
+ entity1.setDeletedBy("Dorothy");
+ assertNotEquals(entity0, entity1);
+ entity0.setDeletedBy("Dorothy");
+ assertEquals(entity0, entity1);
+ assertEquals(entity0, entity1);
+ entity1.setDeletedBy("Toto");
+ assertNotEquals(entity0, entity1);
+ entity0.setDeletedBy("Toto");
+ assertEquals(entity0, entity1);
+
+ assertNotNull(entity0.hashCode());
+ assertNotNull(entity1.hashCode());
+ assertEquals(entity0.hashCode(), entity0.hashCode());
+
+ entity0.setDeletedBy("Totp");
+ assertNotEquals(entity0, entity1);
+ assertNotEquals(entity0.hashCode(), entity1.hashCode());
+ }
+
+ /**
+ * Test action body entity.
+ */
+ @Test
+ public void testActionBodyEntity() {
+ ActionBodyEntity data = new ActionBodyEntity();
+ data.prePersist();
+ data.preUpdate();
+ data.setActionBodyName("Test");
+ assertTrue("Test".equals(data.getActionBodyName()));
+ data.setActionBody("Test");
+ assertTrue("Test".equals(data.getActionBody()));
+ data.setCreatedBy("Test");
+ assertTrue("Test".equals(data.getCreatedBy()));
+ data.setModifiedBy("Test");
+ assertTrue("Test".equals(data.getModifiedBy()));
+ data.setModifiedDate(new Date());
+ assertTrue(data.getCreatedDate() != null);
+ assertTrue(data.getModifiedDate() != null);
+ data.setDeleted(true);
+ assertTrue(data.isDeleted());
+ assertTrue(data.getCreatedDate() != null);
+ assertTrue(data.getModifiedDate() != null);
+ String helloString = "Hello";
+ Object helloObject = helloString;
+ assertNotEquals(data, helloObject);
+ data.hashCode();
+ }
+
+ /**
+ * Test configuration data entity.
+ */
+ @Test
+ public void testConfigurationDataEntity() {
+ ConfigurationDataEntity data = new ConfigurationDataEntity();
+ data.prePersist();
+ data.preUpdate();
+ data.setConfigurationName("Test");
+ assertTrue("Test".equals(data.getConfigurationName()));
+ data.setConfigType("Test");
+ assertTrue("Test".equals(data.getConfigType()));
+ data.setConfigBody("Test");
+ assertTrue("Test".equals(data.getConfigBody()));
+ data.setCreatedBy("Test");
+ assertTrue("Test".equals(data.getCreatedBy()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
+ data.setModifiedBy("Test");
+ assertTrue("Test".equals(data.getModifiedBy()));
+ data.setModifiedDate(new Date());
+ assertTrue(data.getCreatedDate() != null);
+ assertTrue(data.getModifiedDate() != null);
+ data.setDeleted(true);
+ assertTrue(data.isDeleted());
+ assertTrue(data.getCreatedDate() != null);
+ assertTrue(data.getModifiedDate() != null);
+ data.equals(new ConfigurationDataEntity());
+ data.hashCode();
+ }
+
+ /**
+ * Test pdp entity.
+ */
+ @Test
+ public void testPdpEntity() {
+ PdpEntity data = new PdpEntity();
+ data.prePersist();
+ data.preUpdate();
+ data.setPdpId("Test");
+ assertTrue("Test".equals(data.getPdpId()));
+ data.setPdpName("Test");
+ assertTrue("Test".equals(data.getPdpName()));
+ data.setGroup(new GroupEntity());
+ assertTrue(data.getGroup() != null);
+ data.setCreatedBy("Test");
+ assertTrue("Test".equals(data.getCreatedBy()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
+ data.setModifiedBy("Test");
+ assertTrue("Test".equals(data.getModifiedBy()));
+ data.setJmxPort(1);
+ assertTrue(1 == data.getJmxPort());
+ data.setDeleted(true);
+ assertTrue(data.isDeleted());
+ assertTrue(data.getCreatedDate() != null);
+ assertTrue(data.getModifiedDate() != null);
+ }
+
+ /**
+ * Test group entity.
+ */
+ @Test
+ public void testGroupEntity() {
+ GroupEntity data = new GroupEntity();
+ data.prePersist();
+ data.preUpdate();
+ data.setGroupId("Test");
+ assertTrue("Test".equals(data.getGroupId()));
+ data.setGroupName("Test");
+ assertTrue("Test".equals(data.getGroupName()));
+ data.setCreatedBy("Test");
+ assertTrue("Test".equals(data.getCreatedBy()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
+ data.setModifiedBy("Test");
+ assertTrue("Test".equals(data.getModifiedBy()));
+ data.setDefaultGroup(true);
+ assertTrue(data.isDefaultGroup());
+ data.setDeleted(true);
+ assertTrue(data.isDeleted());
+ assertTrue(data.getCreatedDate() != null);
+ assertTrue(data.getModifiedDate() != null);
+
+ assertNull(data.getPolicies());
+ PolicyEntity policy0 = new PolicyEntity();
+ policy0.setPolicyName("PolicyName0");
+ data.addPolicyToGroup(policy0);
+ PolicyEntity policy1 = new PolicyEntity();
+ policy1.setPolicyName("PolicyName1");
+ assertTrue(data.getPolicies().contains(policy0));
+ assertFalse(data.getPolicies().contains(policy1));
+ data.addPolicyToGroup(policy1);
+ assertTrue(data.getPolicies().contains(policy0));
+ assertTrue(data.getPolicies().contains(policy1));
+ data.addPolicyToGroup(policy1);
+ assertTrue(data.getPolicies().contains(policy0));
+ assertTrue(data.getPolicies().contains(policy1));
+ data.removePolicyFromGroup(policy0);
+ assertFalse(data.getPolicies().contains(policy0));
+ assertTrue(data.getPolicies().contains(policy1));
+ data.removePolicyFromGroup(policy0);
+ assertFalse(data.getPolicies().contains(policy0));
+ assertTrue(data.getPolicies().contains(policy1));
+ data.removePolicyFromGroup(policy1);
+ assertNull(data.getPolicies());
+ }
+}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyUtilsJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyUtilsJPATest.java
deleted file mode 100644
index 3ada4dfca..000000000
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyUtilsJPATest.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP-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.rest.jpa;
-
-import static org.junit.Assert.assertTrue;
-
-import java.util.Date;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.policy.common.logging.flexlogger.FlexLogger;
-import org.onap.policy.common.logging.flexlogger.Logger;
-
-public class PolicyUtilsJPATest {
-
- private static Logger logger = FlexLogger.getLogger(PolicyUtilsJPATest.class);
- private UserInfo userInfo;
-
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
- userInfo = new UserInfo();
- userInfo.setUserLoginId("Test");
- userInfo.setUserName("Test");
- logger.info("setUp: exit");
- }
-
- @Test
- public void testWatchPolicyNotificationTable(){
- WatchPolicyNotificationTable data = new WatchPolicyNotificationTable();
- data.setId(1);
- assertTrue(1 == data.getId());
- data.setPolicyName("Test");
- assertTrue("Test".equals(data.getPolicyName()));
- data.setLoginIds("Test");
- assertTrue("Test".equals(data.getLoginIds()));
- data.equals(data);
- data.hashCode();
- }
-
- @Test
- public void testPolicyRoles(){
- PolicyRoles data = new PolicyRoles();
- data.setId(1);
- assertTrue(1 == data.getId());
- data.setScope("Test");
- assertTrue("Test".equals(data.getScope()));
- data.setRole("Test");
- assertTrue("Test".equals(data.getRole()));
- data.setLoginId(userInfo);
- assertTrue("Test".equals(data.getLoginId().getUserLoginId()));
- }
-
- @Test
- public void testPolicyVersion(){
- PolicyVersion data = new PolicyVersion();
- new PolicyVersion("Test", "Test");
- data.prePersist();
- data.preUpdate();
- data.setId(1);
- assertTrue(1 == data.getId());
- data.setActiveVersion(1);
- assertTrue(1 == data.getActiveVersion());
- data.setHigherVersion(1);
- assertTrue(1 == data.getHigherVersion());
- data.setPolicyName("Test");
- assertTrue("Test".equals(data.getPolicyName()));
- data.setCreatedBy("Test");
- assertTrue("Test".equals(data.getCreatedBy()));
- data.setModifiedBy("Test");
- assertTrue("Test".equals(data.getModifiedBy()));
- data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
- data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
- data.equals(data);
- data.hashCode();
- }
-
- @Test
- public void testSystemLogDB(){
- SystemLogDB data = new SystemLogDB();
- new SystemLogDB(1, "","","","","");
- data.setId(1);
- assertTrue(1 == data.getId());
- data.setDescription("Test");
- assertTrue("Test".equals(data.getDescription()));
- data.setType("Test");
- assertTrue("Test".equals(data.getType()));
- data.setSystem("Test");
- assertTrue("Test".equals(data.getSystem()));
- data.setRemote("Test");
- assertTrue("Test".equals(data.getRemote()));
- data.setLogtype("Test");
- assertTrue("Test".equals(data.getLogtype()));
- data.setDate(new Date());
- assertTrue(data.getDate()!=null);
- }
-
- @Test
- public void testRemoteCatalogValues(){
- RemoteCatalogValues data = new RemoteCatalogValues();
- data.setId(1);
- assertTrue(1 == data.getId());
- data.setName("Test");
- assertTrue("Test".equals(data.getName()));
- data.setValue("Test");
- assertTrue("Test".equals(data.getValue()));
- }
-
- @Test
- public void testPolicyScore(){
- PolicyScore data = new PolicyScore();
- data.setId(1);
- assertTrue(1 == data.getId());
- data.setPolicyName("Test");
- assertTrue("Test".equals(data.getPolicyName()));
- data.setVersionExtension("Test");
- assertTrue("Test".equals(data.getVersionExtension()));
- data.setPolicyScore("Test");
- assertTrue("Test".equals(data.getPolicyScore()));
- }
-
- @Test
- public void testPolicyEditorScopes(){
- PolicyEditorScopes data = new PolicyEditorScopes();
- data.prePersist();
- data.preUpdate();
- data.setId(1);
- assertTrue(1 == data.getId());
- data.setScopeName("Test");
- assertTrue("Test".equals(data.getScopeName()));
- data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
- data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
- data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
- data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!=null);
- }
-
- @Test
- public void testDescriptiveScope(){
- DescriptiveScope data = new DescriptiveScope();
- data.prePersist();
- data.preUpdate();
- data.setId(1);
- assertTrue(1 == data.getId());
- data.setScopeName("Test");
- assertTrue("Test".equals(data.getScopeName()));
- data.setSearch("Test");
- assertTrue("Test".equals(data.getSearch()));
- data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!=null);
- data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!=null);
- data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!=null);
- data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!=null);
- }
-
- @Test
- public void testGlobalRoleSettings(){
- GlobalRoleSettings data = new GlobalRoleSettings();
- new GlobalRoleSettings(true);
- data.setRole("Test");
- assertTrue("Test".equals(data.getRole()));
- data.setLockdown(true);
- assertTrue(data.isLockdown());
- }
-}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyUtilsJpaTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyUtilsJpaTest.java
new file mode 100644
index 000000000..f56e55783
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyUtilsJpaTest.java
@@ -0,0 +1,320 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-REST
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.rest.jpa;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Date;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+
+/**
+ * The Class PolicyUtilsJpaTest.
+ */
+public class PolicyUtilsJpaTest {
+
+ private static Logger logger = FlexLogger.getLogger(PolicyUtilsJpaTest.class);
+ private UserInfo userInfo;
+
+ /**
+ * Sets the up.
+ *
+ * @throws Exception the exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ userInfo = new UserInfo();
+ userInfo.setUserLoginId("Test");
+ userInfo.setUserName("Test");
+ logger.info("setUp: exit");
+ }
+
+ /**
+ * Test watch policy notification table.
+ */
+ @Test
+ public void testWatchPolicyNotificationTable() {
+ WatchPolicyNotificationTable data = new WatchPolicyNotificationTable();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setPolicyName("Test");
+ assertTrue("Test".equals(data.getPolicyName()));
+ data.setLoginIds("Test");
+ assertTrue("Test".equals(data.getLoginIds()));
+ data.equals(data);
+ data.hashCode();
+ }
+
+ /**
+ * Test policy roles.
+ */
+ @Test
+ public void testPolicyRoles() {
+ PolicyRoles data = new PolicyRoles();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setScope("Test");
+ assertTrue("Test".equals(data.getScope()));
+ data.setRole("Test");
+ assertTrue("Test".equals(data.getRole()));
+ data.setLoginId(userInfo);
+ assertTrue("Test".equals(data.getLoginId().getUserLoginId()));
+ }
+
+ /**
+ * Test policy version.
+ */
+ @Test
+ public void testPolicyVersion() {
+ PolicyVersion data = new PolicyVersion();
+ new PolicyVersion("Test", "Test");
+ data.prePersist();
+ data.preUpdate();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setActiveVersion(1);
+ assertTrue(1 == data.getActiveVersion());
+ data.setHigherVersion(1);
+ assertTrue(1 == data.getHigherVersion());
+ data.setPolicyName("Test");
+ assertTrue("Test".equals(data.getPolicyName()));
+ data.setCreatedBy("Test");
+ assertTrue("Test".equals(data.getCreatedBy()));
+ data.setModifiedBy("Test");
+ assertTrue("Test".equals(data.getModifiedBy()));
+ data.setCreatedDate(new Date());
+ assertTrue(data.getCreatedDate() != null);
+ data.setModifiedDate(new Date());
+ assertTrue(data.getModifiedDate() != null);
+
+ assertNotNull(data.hashCode());
+
+ PolicyVersion version0 = new PolicyVersion();
+ PolicyVersion version1 = new PolicyVersion();
+ assertEquals(version0, version0);
+ assertEquals(version0, version1);
+ assertNotEquals(version0, null);
+ String helloString = "Hello";
+ Object helloObject = helloString;
+ assertNotEquals(version0, helloObject);
+
+ version0.setId(1);
+ assertNotEquals(version0, version1);
+ version1.setId(1);
+ assertEquals(version0, version1);
+ version0.setActiveVersion(1);
+ assertNotEquals(version0, version1);
+ version1.setActiveVersion(1);
+ assertEquals(version0, version1);
+ version0.setCreatedBy("Dorothy");
+ assertNotEquals(version0, version1);
+ version1.setCreatedBy("Dorothy");
+ assertEquals(version0, version1);
+ version1.setCreatedBy(null);
+ assertNotEquals(version0, version1);
+ version0.setCreatedBy(null);
+ assertEquals(version0, version1);
+ version1.setCreatedBy("Dorothy");
+ assertNotEquals(version0, version1);
+ version0.setCreatedBy("Dorothy");
+ assertEquals(version0, version1);
+ version0.setCreatedDate(new Date(12345L));
+ assertNotEquals(version0, version1);
+ version1.setCreatedDate(new Date(12345L));
+ assertEquals(version0, version1);
+ version1.setCreatedDate(null);
+ assertNotEquals(version0, version1);
+ version0.setCreatedDate(null);
+ assertEquals(version0, version1);
+ version1.setCreatedDate(new Date(12345L));
+ assertNotEquals(version0, version1);
+ version0.setCreatedDate(new Date(12345L));
+ assertEquals(version0, version1);
+ version0.setHigherVersion(1);
+ assertNotEquals(version0, version1);
+ version1.setHigherVersion(1);
+ assertEquals(version0, version1);
+ version0.setModifiedBy("Dorothy");
+ assertNotEquals(version0, version1);
+ version1.setModifiedBy("Dorothy");
+ assertEquals(version0, version1);
+ version1.setModifiedBy(null);
+ assertNotEquals(version0, version1);
+ version0.setModifiedBy(null);
+ assertEquals(version0, version1);
+ version1.setModifiedBy("Dorothy");
+ assertNotEquals(version0, version1);
+ version0.setModifiedBy("Dorothy");
+ assertEquals(version0, version1);
+ version0.setModifiedDate(new Date(12345L));
+ assertNotEquals(version0, version1);
+ version1.setModifiedDate(new Date(12345L));
+ assertEquals(version0, version1);
+ version1.setModifiedDate(null);
+ assertNotEquals(version0, version1);
+ version0.setModifiedDate(null);
+ assertEquals(version0, version1);
+ version1.setModifiedDate(new Date(12345L));
+ assertNotEquals(version0, version1);
+ version0.setModifiedDate(new Date(12345L));
+ assertEquals(version0, version1);
+ version0.setPolicyName("GoToOz");
+ assertNotEquals(version0, version1);
+ version1.setPolicyName("GoToOz");
+ assertEquals(version0, version1);
+ version1.setPolicyName(null);
+ assertNotEquals(version0, version1);
+ version0.setPolicyName(null);
+ assertEquals(version0, version1);
+ version1.setPolicyName("GoToOz");
+ assertNotEquals(version0, version1);
+ version0.setPolicyName("GoToOz");
+ assertEquals(version0, version1);
+
+ assertNotNull(version0.hashCode());
+ assertNotNull(version1.hashCode());
+ assertEquals(version0.hashCode(), version0.hashCode());
+
+ version0.setPolicyName("GoToOy");
+ assertNotEquals(version0, version1);
+ assertNotEquals(version0.hashCode(), version1.hashCode());
+ }
+
+ /**
+ * Test system log DB.
+ */
+ @Test
+ public void testSystemLogDb() {
+ SystemLogDb data = new SystemLogDb();
+ new SystemLogDb(1, "", "", "", "", "");
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
+ data.setType("Test");
+ assertTrue("Test".equals(data.getType()));
+ data.setSystem("Test");
+ assertTrue("Test".equals(data.getSystem()));
+ data.setRemote("Test");
+ assertTrue("Test".equals(data.getRemote()));
+ data.setLogtype("Test");
+ assertTrue("Test".equals(data.getLogtype()));
+ data.setDate(new Date());
+ assertTrue(data.getDate() != null);
+ }
+
+ /**
+ * Test remote catalog values.
+ */
+ @Test
+ public void testRemoteCatalogValues() {
+ RemoteCatalogValues data = new RemoteCatalogValues();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setName("Test");
+ assertTrue("Test".equals(data.getName()));
+ data.setValue("Test");
+ assertTrue("Test".equals(data.getValue()));
+ }
+
+ /**
+ * Test policy score.
+ */
+ @Test
+ public void testPolicyScore() {
+ PolicyScore data = new PolicyScore();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setPolicyName("Test");
+ assertTrue("Test".equals(data.getPolicyName()));
+ data.setVersionExtension("Test");
+ assertTrue("Test".equals(data.getVersionExtension()));
+ data.setScore("Test");
+ assertTrue("Test".equals(data.getScore()));
+ }
+
+ /**
+ * Test policy editor scopes.
+ */
+ @Test
+ public void testPolicyEditorScopes() {
+ PolicyEditorScopes data = new PolicyEditorScopes();
+ data.prePersist();
+ data.preUpdate();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setScopeName("Test");
+ assertTrue("Test".equals(data.getScopeName()));
+ data.setCreatedDate(new Date());
+ assertTrue(data.getCreatedDate() != null);
+ data.setModifiedDate(new Date());
+ assertTrue(data.getModifiedDate() != null);
+ data.setUserCreatedBy(userInfo);
+ assertTrue(data.getUserCreatedBy() != null);
+ data.setUserModifiedBy(userInfo);
+ assertTrue(data.getUserModifiedBy() != null);
+ }
+
+ /**
+ * Test descriptive scope.
+ */
+ @Test
+ public void testDescriptiveScope() {
+ DescriptiveScope data = new DescriptiveScope();
+ data.prePersist();
+ data.preUpdate();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setScopeName("Test");
+ assertTrue("Test".equals(data.getScopeName()));
+ data.setSearch("Test");
+ assertTrue("Test".equals(data.getSearch()));
+ data.setCreatedDate(new Date());
+ assertTrue(data.getCreatedDate() != null);
+ data.setModifiedDate(new Date());
+ assertTrue(data.getModifiedDate() != null);
+ data.setUserCreatedBy(userInfo);
+ assertTrue(data.getUserCreatedBy() != null);
+ data.setUserModifiedBy(userInfo);
+ assertTrue(data.getUserModifiedBy() != null);
+ }
+
+ /**
+ * Test global role settings.
+ */
+ @Test
+ public void testGlobalRoleSettings() {
+ GlobalRoleSettings data = new GlobalRoleSettings();
+ new GlobalRoleSettings(true);
+ data.setRole("Test");
+ assertTrue("Test".equals(data.getRole()));
+ data.setLockdown(true);
+ assertTrue(data.isLockdown());
+ }
+}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/util/DummyPolicyContainer.java b/ONAP-REST/src/test/java/org/onap/policy/rest/util/DummyPolicyContainer.java
new file mode 100644
index 000000000..385576744
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/util/DummyPolicyContainer.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.rest.util;
+
+import java.util.Collection;
+
+public class DummyPolicyContainer implements PolicyContainer {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Collection<?> getContainerPropertyIds() {
+ return null;
+ }
+
+ @Override
+ public Collection<?> getItemIds() {
+ return null;
+ }
+
+ @Override
+ public Class<?> getType(Object propertyId) {
+ return null;
+ }
+
+ @Override
+ public int size() {
+ return 0;
+ }
+
+ @Override
+ public boolean containsId(Object itemId) {
+ return false;
+ }
+
+ @Override
+ public Object addItem() {
+ return null;
+ }
+
+ @Override
+ public boolean removeItem(Object itemId) {
+ return false;
+ }
+
+ @Override
+ public boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue) {
+ return false;
+ }
+
+ @Override
+ public boolean removeContainerProperty(Object propertyId) {
+ return false;
+ }
+
+ @Override
+ public boolean removeAllItems() {
+ return false;
+ }
+}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/util/MSAttributeObjectTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/util/MsAttributeObjectTest.java
index a39eb4996..8ec47fb0b 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/util/MSAttributeObjectTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/util/MsAttributeObjectTest.java
@@ -3,6 +3,7 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,14 +22,16 @@
package org.onap.policy.rest.util;
import static org.junit.Assert.assertTrue;
+
import java.util.HashMap;
+
import org.junit.Test;
-public class MSAttributeObjectTest {
+public class MsAttributeObjectTest {
@Test
- public void testMSAttributeObject() {
- MSAttributeObject data = new MSAttributeObject();
+ public void testMsAttributeObject() {
+ MsAttributeObject data = new MsAttributeObject();
data.setClassName("Test");
assertTrue("Test".equals(data.getClassName()));
data.setRefAttribute(new HashMap<>());
@@ -60,8 +63,8 @@ public class MSAttributeObjectTest {
}
@Test
- public void testMSAttributeValue() {
- MSAttributeValue data = new MSAttributeValue();
+ public void testMsAttributeValue() {
+ MsAttributeValue data = new MsAttributeValue();
data.setName("Test");
assertTrue("Test".equals(data.getName()));
data.setType("Test");
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/util/MSModelUtilsTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/util/MsModelUtilsTest.java
index 34d555062..6d12d57a3 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/util/MSModelUtilsTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/util/MsModelUtilsTest.java
@@ -3,6 +3,7 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +26,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -32,19 +34,25 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.lang.StringUtils;
+
+import org.apache.commons.lang3.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.DictionaryData;
-import org.onap.policy.rest.util.MSModelUtils.MODEL_TYPE;
+import org.onap.policy.rest.util.MsModelUtils.ModelType;
-public class MSModelUtilsTest {
- private static Logger logger = FlexLogger.getLogger(MSModelUtilsTest.class);
+public class MsModelUtilsTest {
+ private static Logger logger = FlexLogger.getLogger(MsModelUtilsTest.class);
private static CommonClassDao commonClassDao;
+ /**
+ * Set tests up.
+ *
+ * @throws Exception on setup failures
+ */
@Before
public void setUp() throws Exception {
List<Object> dictionaryData = new ArrayList<Object>();
@@ -55,28 +63,28 @@ public class MSModelUtilsTest {
logger.info("setUp: Entering");
commonClassDao = mock(CommonClassDao.class);
when(commonClassDao.getDataById(DictionaryData.class, "dictionaryName", "GocVNFType"))
- .thenReturn(dictionaryData);
+ .thenReturn(dictionaryData);
}
@Test
- public void testMSModelUtils() {
- HashMap<String, MSAttributeObject> classMap = new HashMap<>();
+ public void testMsModelUtils() {
+ HashMap<String, MsAttributeObject> classMap = new HashMap<>();
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("DKaTVESPolicy-v1802.xmi").getFile());
- MSModelUtils utils = new MSModelUtils("http://org.onap", "http://org.onap.policy");
- Map<String, MSAttributeObject> tempMap =
- utils.processEpackage(file.getAbsolutePath().toString(), MODEL_TYPE.XMI);
+ MsModelUtils utils = new MsModelUtils("http://org.onap", "http://org.onap.policy");
+ Map<String, MsAttributeObject> tempMap = utils.processEpackage(file.getAbsolutePath().toString(),
+ ModelType.XMI);
classMap.putAll(tempMap);
- MSAttributeObject mainClass = classMap.get("StandardDeviationThreshold");
- String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[] {"[", "]", " "},
- new String[] {"", "", ""});
+ MsAttributeObject mainClass = classMap.get("StandardDeviationThreshold");
+ String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[]
+ { "[", "]", " " }, new String[]
+ { "", "", "" });
List<String> dependency = new ArrayList<String>(Arrays.asList(dependTemp.split(",")));
dependency = utils.getFullDependencyList(dependency, classMap);
String subAttribute = utils.createSubAttributes(dependency, classMap, "StandardDeviationThreshold");
assertTrue(subAttribute != null);
}
-
/**
* Run the void stringBetweenDots(String, String) method test.
*/
@@ -85,25 +93,24 @@ public class MSModelUtilsTest {
public void testStringBetweenDots() {
// expect: uniqueKeys should contain a string value
- MSModelUtils controllerA = new MSModelUtils();
+ MsModelUtils controllerA = new MsModelUtils();
String str = "testing\\.byCorrectWay\\.OfDATA";
assertEquals(1, controllerA.stringBetweenDots(str));
// expect: uniqueKeys should not contain a string value
str = "testing\byWrongtWay.\\OfDATA";
- MSModelUtils controllerB = new MSModelUtils();
+ MsModelUtils controllerB = new MsModelUtils();
assertEquals(0, controllerB.stringBetweenDots(str));
}
/**
- * Run the Map<String,String> load(String) method test.
+ * Run the load method test.
*/
-
@Test
public void testLoad() {
boolean isLocalTesting = true;
- MSModelUtils controller = new MSModelUtils();
+ MsModelUtils controller = new MsModelUtils();
String fileName = null;
Map<String, String> result = null;
try {
@@ -146,7 +153,7 @@ public class MSModelUtilsTest {
logger.error("Exception Occured while loading file" + e1);
}
- MSModelUtils controller = new MSModelUtils(commonClassDao);
+ MsModelUtils controller = new MsModelUtils(commonClassDao);
if (isLocalTesting) {
try {
controller.parseTosca(fileName);
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/util/PDPPolicyContainerTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/util/PDPPolicyContainerTest.java
deleted file mode 100644
index 9302df3b5..000000000
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/util/PDPPolicyContainerTest.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy Engine
- * ================================================================================
- * 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.rest.util;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import java.util.HashSet;
-import java.util.Set;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.policy.rest.util.PDPPolicyContainer.PDPPolicyItem;
-import org.onap.policy.xacml.std.pap.StdPDP;
-import org.onap.policy.xacml.std.pap.StdPDPGroup;
-import org.onap.policy.xacml.std.pap.StdPDPPolicy;
-import com.att.research.xacml.api.pap.PDP;
-import com.att.research.xacml.api.pap.PDPPolicy;
-
-public class PDPPolicyContainerTest {
- StdPDPGroup group;
- PDPPolicyContainer container;
- StdPDPPolicy policy;
-
- @Before
- public void setUp() {
- group = new StdPDPGroup();
- group.setDefault(true);
- group.setDefaultGroup(true);
- group.setDescription("Test");
- group.setId("Test");
- group.setName("Test");
- group.setOnapPdps(new HashSet<>());
- group.setOperation("Test");
- group.setPipConfigs(new HashSet<>());
- HashSet<PDPPolicy> policies = new HashSet<>();
- policy = new StdPDPPolicy();
- policy.setName("Config_test.1.xml");
- policy.setId("Config_test");
- policy.setVersion("1.0");
- policy.setDescription("testDescription");
- policies.add(policy);
- group.setPolicies(policies);
- group.setSelectedPolicies(new HashSet<>());
- container = new PDPPolicyContainer(group);
- }
-
- @Test
- public void testPDPPolicyContainer() {
- container.nextItemId(policy);
- container.prevItemId(policy);
- container.firstItemId();
- container.lastItemId();
- container.isFirstId(policy);
- container.isLastId(policy);
- container.addItemAfter(policy);
- container.getContainerPropertyIds();
- container.getItemIds();
- container.getType("Id");
- assertTrue(String.class.equals(String.class));
- container.getType("Name");
- assertTrue(String.class.equals(String.class));
- container.getType("Version");
- assertTrue(String.class.equals(String.class));
- container.getType("Description");
- assertTrue(String.class.equals(String.class));
- container.getType("Root");
- assertTrue(Boolean.class.equals(Boolean.class));
- assertTrue(container.size() == 1);
- container.containsId(policy);
- container.removeItem(policy);
- container.addContainerProperty(null, null, null);
- container.removeContainerProperty(policy);
- container.removeAllItems();
- container.addItemAt(0);
- }
-
- @Test(expected = NullPointerException.class)
- public void testConstructor() {
- // Test PDP based constructor
- PDP pdp = new StdPDP();
- PDPPolicyContainer container1 = new PDPPolicyContainer(pdp);
- assertNotNull(container1);
-
- // Test set based constructor
- Set<PDPPolicy> set = new HashSet<PDPPolicy>();
- PDPPolicyContainer container2 = new PDPPolicyContainer(set);
- assertNotNull(container2);
-
- // Test object based constructor
- PDPPolicyContainer container3 = new PDPPolicyContainer("testObject");
- assertNotNull(container3);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testAddItem() {
- container.addItem();
- }
-
- @Test
- public void testGetters() {
- assertNull(container.nextItemId("testItem"));
- assertNull(container.prevItemId("testItem"));
- assertNotNull(container.firstItemId());
- assertNotNull(container.lastItemId());
- assertEquals(container.indexOfId("testItem"), -1);
- assertNotNull(container.getIdByIndex(0));
- assertNotNull(container.getItemIds(0, 1));
- }
-
- @Test
- public void testPDPPolicyItem() {
- PDPPolicyItem item = container.new PDPPolicyItem(policy);
- assertEquals("Config_test", item.getId());
- assertEquals("Config_test.1.xml", item.getName());
- assertEquals("1.0", item.getVersion());
- assertEquals("testDescription", item.getDescription());
- item.setRoot(true);
- assertEquals(true, item.getRoot());
- }
-}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/util/ParserExceptionTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/util/ParserExceptionTest.java
new file mode 100644
index 000000000..92b56a146
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/util/ParserExceptionTest.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.rest.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class ParserExceptionTest {
+
+ @Test
+ public void test() {
+ ParserException pe = new ParserException("A Message");
+ assertEquals("A Message", pe.getMessage());
+ }
+}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/util/PdpPolicyContainerTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/util/PdpPolicyContainerTest.java
new file mode 100644
index 000000000..32d9e5255
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/util/PdpPolicyContainerTest.java
@@ -0,0 +1,267 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Engine
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.rest.util;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFLogger.Level;
+import com.att.eelf.configuration.EELFManager;
+import com.att.research.xacml.api.pap.PDP;
+import com.att.research.xacml.api.pap.PDPPolicy;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.logging.eelf.PolicyLogger;
+import org.onap.policy.rest.util.PdpPolicyContainer.PdpPolicyItem;
+import org.onap.policy.xacml.std.pap.StdPDP;
+import org.onap.policy.xacml.std.pap.StdPDPGroup;
+import org.onap.policy.xacml.std.pap.StdPDPPolicy;
+
+public class PdpPolicyContainerTest {
+ StdPDPGroup group;
+ PdpPolicyContainer container;
+ StdPDPPolicy policy;
+
+ /**
+ * Set test up.
+ */
+ @Before
+ public void setUp() {
+ group = new StdPDPGroup();
+ group.setDefault(true);
+ group.setDefaultGroup(true);
+ group.setDescription("Test");
+ group.setId("Test");
+ group.setName("Test");
+ group.setOnapPdps(new HashSet<>());
+ group.setOperation("Test");
+ group.setPipConfigs(new HashSet<>());
+ policy = new StdPDPPolicy();
+ policy.setName("Config_test.1.xml");
+ policy.setId("Config_test");
+ policy.setVersion("1.0");
+ policy.setDescription("testDescription");
+
+ HashSet<PDPPolicy> policies = new HashSet<>();
+ policies.add(policy);
+ group.setPolicies(policies);
+ group.setSelectedPolicies(new HashSet<>());
+ container = new PdpPolicyContainer(group);
+ }
+
+ @Test
+ public void testPdpPolicyContainer() {
+ container.nextItemId(policy);
+ container.prevItemId(policy);
+ container.firstItemId();
+ container.lastItemId();
+ container.isFirstId(policy);
+ container.isLastId(policy);
+ container.addItemAfter(policy);
+ container.getContainerPropertyIds();
+ container.getItemIds();
+ container.getType("Id");
+ assertNull(container.getType("NonExistant"));
+ assertTrue(String.class.equals(String.class));
+ container.getType("Name");
+ assertTrue(String.class.equals(String.class));
+ container.getType("Version");
+ assertTrue(String.class.equals(String.class));
+ container.getType("Description");
+ assertTrue(String.class.equals(String.class));
+ container.getType("Root");
+ assertTrue(Boolean.class.equals(Boolean.class));
+ assertTrue(container.size() == 1);
+ container.containsId(policy);
+ container.removeItem(policy);
+ container.addContainerProperty(null, null, null);
+ container.removeContainerProperty(policy);
+ container.removeAllItems();
+
+ assertFalse(container.isFirstId(policy));
+ assertFalse(container.isLastId(policy));
+ assertNull(container.firstItemId());
+ assertNull(container.lastItemId());
+ assertNull(container.prevItemId(policy));
+
+ assertThatThrownBy(() -> container.getItemIds(0, -1)).isInstanceOf(IllegalArgumentException.class);
+
+ container.addItemAt(0);
+ }
+
+ @Test
+ public void testPdpPolicyContainerWithTrace() {
+ EELFLogger debugLogger = EELFManager.getInstance().getDebugLogger();
+
+ final Level currentLevel = PolicyLogger.getDebugLevel();
+ debugLogger.setLevel(Level.TRACE);
+
+ testPdpPolicyContainer();
+ debugLogger.setLevel(currentLevel);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testConstructor() {
+ // Test PDP based constructor
+ PDP pdp = new StdPDP();
+ PdpPolicyContainer container1 = new PdpPolicyContainer(pdp);
+ assertNotNull(container1);
+
+ // Test set based constructor
+ Set<PDPPolicy> set = new HashSet<PDPPolicy>();
+ PdpPolicyContainer container2 = new PdpPolicyContainer(set);
+ assertNotNull(container2);
+
+ // Test object based constructor
+ PdpPolicyContainer container3 = new PdpPolicyContainer("testObject");
+ assertNotNull(container3);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testAddItem() {
+ container.addItem();
+ }
+
+ @Test
+ public void testGettersWithTrace() {
+ EELFLogger debugLogger = EELFManager.getInstance().getDebugLogger();
+
+ final Level currentLevel = PolicyLogger.getDebugLevel();
+ debugLogger.setLevel(Level.TRACE);
+
+ testGetters();
+ debugLogger.setLevel(currentLevel);
+ }
+
+ @Test
+ public void testGetters() {
+ assertNull(container.nextItemId("testItem"));
+ assertNull(container.prevItemId("testItem"));
+ assertNotNull(container.firstItemId());
+ assertNotNull(container.lastItemId());
+ assertEquals(container.indexOfId("testItem"), -1);
+ assertNotNull(container.getIdByIndex(0));
+ assertNotNull(container.getItemIds(0, 1));
+ }
+
+ @Test
+ public void testPdpPolicyItemWithTrace() {
+ EELFLogger debugLogger = EELFManager.getInstance().getDebugLogger();
+
+ final Level currentLevel = PolicyLogger.getDebugLevel();
+ debugLogger.setLevel(Level.TRACE);
+
+ testPdpPolicyItem();
+ debugLogger.setLevel(currentLevel);
+ }
+
+ @Test
+ public void testPdpPolicyItem() {
+ PdpPolicyItem item = container.new PdpPolicyItem(policy);
+ assertEquals("Config_test", item.getId());
+ assertEquals("Config_test.1.xml", item.getName());
+ assertEquals("1.0", item.getVersion());
+ assertEquals("testDescription", item.getDescription());
+ item.setRoot(true);
+ assertEquals(true, item.getRoot());
+ }
+
+ @Test
+ public void testContainerListOfPolicies() {
+ StdPDPGroup testGroup = new StdPDPGroup();
+ testGroup.setDefault(true);
+ testGroup.setDefaultGroup(true);
+ testGroup.setDescription("Test");
+ testGroup.setId("Test");
+ testGroup.setName("Test");
+ testGroup.setOnapPdps(new HashSet<>());
+ testGroup.setOperation("Test");
+ testGroup.setPipConfigs(new HashSet<>());
+
+ StdPDPPolicy testPolicy0 = new StdPDPPolicy();
+ testPolicy0.setName("Config_test.0.xml");
+ testPolicy0.setId("Config_test0");
+ testPolicy0.setVersion("1.0");
+ testPolicy0.setDescription("testDescription0");
+
+ StdPDPPolicy testPolicy1 = new StdPDPPolicy();
+ testPolicy1.setName("Config_test.1.xml");
+ testPolicy1.setId("Config_test1");
+ testPolicy1.setVersion("1.0");
+ testPolicy1.setDescription("testDescription1");
+
+ HashSet<PDPPolicy> policies = new HashSet<>();
+ policies.add(testPolicy0);
+ policies.add(testPolicy1);
+
+ testGroup.setPolicies(policies);
+ testGroup.setSelectedPolicies(new HashSet<>());
+ PdpPolicyContainer testContainer = new PdpPolicyContainer(testGroup);
+
+ assertEquals("Config_test0", ((PdpPolicyItem) testContainer.nextItemId(testPolicy1)).getId());
+ assertEquals("Config_test1", ((PdpPolicyItem) testContainer.prevItemId(testPolicy0)).getId());
+
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ mapper.writeValue(System.err, testPolicy0);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ // @formatter:off
+ assertTrue(testContainer.removeItem("{"
+ + "\"PDPPolicyType\":\"StdPDPPolicy\","
+ + "\"id\":\"Config_test0\","
+ + "\"name\":\"Config_test.0.xml\","
+ + "\"policyId\":null,"
+ + "\"description\":\"testDescription0\","
+ + "\"version\":\"1.0\","
+ + "\"location\":null,"
+ + "\"valid\":false,"
+ + "\"root\":false"
+ + "}"));
+ assertFalse(testContainer.removeItem("{"
+ + "\"PDPPolicyType\":\"StdPDPPolicy\","
+ + "\"id\":\"Config_test99\","
+ + "\"name\":\"Config_test.0.xml\","
+ + "\"policyId\":null,"
+ + "\"description\":\"testDescription0\","
+ + "\"version\":\"1.0\","
+ + "\"location\":null,"
+ + "\"valid\":false,"
+ + "\"root\":false"
+ + "}"));
+ // @formatter:on
+ }
+}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/util/PolicyItemSetChangeNotifierTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/util/PolicyItemSetChangeNotifierTest.java
index 9e5ff5d9f..5e42ec6f6 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/util/PolicyItemSetChangeNotifierTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/util/PolicyItemSetChangeNotifierTest.java
@@ -3,13 +3,14 @@
* ONAP Policy Engine
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -20,31 +21,57 @@
package org.onap.policy.rest.util;
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+
import org.junit.Test;
import org.mockito.Mockito;
import org.onap.policy.rest.util.PolicyContainer.ItemSetChangeEvent;
import org.onap.policy.rest.util.PolicyContainer.ItemSetChangeListener;
public class PolicyItemSetChangeNotifierTest {
- @Test
- public void testNotifier() {
- // Setup test data
- ItemSetChangeListener listener = Mockito.mock(ItemSetChangeListener.class);
- ItemSetChangeEvent event = Mockito.mock(ItemSetChangeEvent.class);
-
- // Test constructor
- PolicyItemSetChangeNotifier notifier = new PolicyItemSetChangeNotifier();
- assertNotNull(notifier);
-
- // Test listener methods
- try {
- notifier.addItemSetChangeListener(listener);
- notifier.fireItemSetChange(event);
- notifier.removeItemSetChangeListener(listener);
- } catch (Exception ex) {
- fail("Not expecting any exceptions: " + ex);
+ @Test
+ public void testNotifier() {
+
+ // Test constructor
+ PolicyItemSetChangeNotifier notifier = new PolicyItemSetChangeNotifier();
+ assertNotNull(notifier);
+
+ assertEquals(null, notifier.getItemSetChangeListeners());
+
+ ItemSetChangeListener listener1 = Mockito.mock(ItemSetChangeListener.class);
+ notifier.addItemSetChangeListener(listener1);
+ assertEquals(1, notifier.getItemSetChangeListeners().size());
+ ItemSetChangeListener listener2 = Mockito.mock(ItemSetChangeListener.class);
+ notifier.addItemSetChangeListener(listener2);
+ assertEquals(2, notifier.getItemSetChangeListeners().size());
+
+ notifier.removeItemSetChangeListener(listener1);
+ assertEquals(1, notifier.getItemSetChangeListeners().size());
+ notifier.addItemSetChangeListener(listener1);
+ assertEquals(2, notifier.getItemSetChangeListeners().size());
+
+ ItemSetChangeEvent event = Mockito.mock(ItemSetChangeEvent.class);
+ notifier.fireItemSetChange(event);
+
+ notifier.removeItemSetChangeListener(listener1);
+ assertEquals(1, notifier.getItemSetChangeListeners().size());
+ notifier.removeItemSetChangeListener(listener2);
+ assertEquals(0, notifier.getItemSetChangeListeners().size());
+ notifier.removeItemSetChangeListener(listener2);
+ assertEquals(0, notifier.getItemSetChangeListeners().size());
+
+ notifier.setItemSetChangeListeners(null);
+ notifier.removeItemSetChangeListener(listener2);
+ assertEquals(null, notifier.getItemSetChangeListeners());
+
+ assertThatCode(() -> notifier.fireItemSetChange(event)).doesNotThrowAnyException();
+
+ notifier.setContainer(new DummyPolicyContainer());
+ assertThatCode(() -> notifier.fireItemSetChange()).doesNotThrowAnyException();
+
+ PolicyContainer dummySource = new DummyPolicyContainer();
+ assertEquals(dummySource, new PolicyItemSetChangeNotifier.BaseItemSetChangeEvent(dummySource).getContainer());
}
- }
}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/util/PolicyValidationRequestWrapperTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/util/PolicyValidationRequestWrapperTest.java
new file mode 100644
index 000000000..517058309
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/util/PolicyValidationRequestWrapperTest.java
@@ -0,0 +1,422 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.rest.util;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedReader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.policy.api.AttributeType;
+import org.onap.policy.api.PolicyClass;
+import org.onap.policy.api.PolicyConfigType;
+import org.onap.policy.api.PolicyParameters;
+import org.onap.policy.api.PolicyType;
+import org.onap.policy.api.RuleProvider;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.rest.adapter.PolicyRestAdapter;
+
+@RunWith(MockitoJUnitRunner.class)
+public class PolicyValidationRequestWrapperTest {
+
+ @Mock
+ HttpServletRequest request;
+
+ @Test
+ public void testHttpRequest() throws Exception {
+ PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
+
+ assertNull(wrapper.populateRequestParameters((HttpServletRequest) null));
+
+ BufferedReader decisionPolicyReader = new BufferedReader(new StringReader(
+ TextFileUtils.getTextFileAsString("src/test/resources/policies/DecisionPolicy.json")));
+
+ Mockito.when(request.getReader()).thenReturn(decisionPolicyReader);
+
+ wrapper.populateRequestParameters(request);
+
+ BufferedReader policyJsonTrapFaultReader = new BufferedReader(new StringReader(
+ TextFileUtils.getTextFileAsString("src/test/resources/policies/PolicyJsonTrapFault.json")));
+
+ Mockito.when(request.getReader()).thenReturn(policyJsonTrapFaultReader);
+
+ wrapper.populateRequestParameters(request);
+
+ BufferedReader badJsonReader = new BufferedReader(new StringReader("{"));
+
+ Mockito.when(request.getReader()).thenReturn(badJsonReader);
+
+ wrapper.populateRequestParameters(request);
+ }
+
+ @Test
+ public void testDefaultParameterHandling() throws Exception {
+ PolicyParameters parameters = createParametersObject();
+
+ PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
+
+ assertThatThrownBy(() -> wrapper.populateRequestParameters(parameters))
+ .isInstanceOf(NullPointerException.class);
+
+ parameters.setPolicyConfigType(PolicyConfigType.Firewall);
+ PolicyRestAdapter adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("Firewall Config", adapter.getConfigPolicyType());
+
+ parameters.setConfigBody("");
+ assertNull(wrapper.populateRequestParameters((parameters)));
+
+ parameters.setConfigBody("{\"name");
+ assertNull(wrapper.populateRequestParameters((parameters)));
+
+ parameters.setConfigBodyType(PolicyType.OTHER);
+ parameters.setConfigBody(null);
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("Firewall Config", adapter.getConfigPolicyType());
+
+ parameters.setPolicyConfigType(PolicyConfigType.Extended);
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("EXTENDED", adapter.getConfigPolicyType());
+
+ parameters.setTtlDate(null);
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("NA", adapter.getTtlDate());
+ }
+
+ @Test
+ public void testConfigFirewallParameterHandling() throws Exception {
+ PolicyParameters parameters = createParametersObject();
+ parameters.setPolicyConfigType(PolicyConfigType.Firewall);
+
+ PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
+
+ PolicyRestAdapter adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("Firewall Config", adapter.getConfigPolicyType());
+
+ parameters.setConfigBody("{\"someParameter\": \"someValue\"}");
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals(null, adapter.getSecurityZone());
+ assertEquals("ConfigName", adapter.getConfigName());
+
+ parameters.setConfigBody("{\"securityZoneId\": \"SecurityZone\"}");
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("SecurityZone", adapter.getSecurityZone());
+
+ parameters.setConfigBody("{\"configName\": \"AnotherConfigName\"}");
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("AnotherConfigName", adapter.getConfigName());
+ }
+
+ @Test
+ public void testConfigMicroserviceParameterHandling() throws Exception {
+ PolicyParameters parameters = createParametersObject();
+ parameters.setPolicyConfigType(PolicyConfigType.MicroService);
+
+ PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
+
+ assertNull(wrapper.populateRequestParameters((parameters)));
+
+ parameters.setConfigBody("{\"someParameter\": \"someValue\"}");
+
+ PolicyRestAdapter adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("Micro Service", adapter.getConfigPolicyType());
+
+ parameters.setConfigBody("{\"service\": \"MyService\"}");
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("MyService", adapter.getServiceType());
+
+ parameters.setConfigBody("{\"content\": \"{}\"}");
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("\"{}\"", adapter.getPolicyJSON().toString());
+
+ parameters.setConfigBody("{\"content\": {hess:}}");
+ assertNull(wrapper.populateRequestParameters((parameters)));
+ }
+
+ @Test
+ public void testConfigOptimizationParameterHandling() throws Exception {
+ PolicyParameters parameters = createParametersObject();
+ parameters.setPolicyConfigType(PolicyConfigType.Optimization);
+
+ PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
+
+ PolicyRestAdapter adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("Optimization", adapter.getConfigPolicyType());
+
+ parameters.setConfigBody("{\"someParameter\": \"someValue\"}");
+
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("Optimization", adapter.getConfigPolicyType());
+
+ parameters.setConfigBody("{\"service\": \"MyService\"}");
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("MyService", adapter.getServiceType());
+ }
+
+ @Test
+ public void testConfigClosedLoopFaultParameterHandling() throws Exception {
+ PolicyParameters parameters = createParametersObject();
+ parameters.setPolicyConfigType(PolicyConfigType.ClosedLoop_Fault);
+
+ PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
+
+ PolicyRestAdapter adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("ClosedLoop_Fault", adapter.getConfigPolicyType());
+
+ parameters.setConfigBody("{\"someParameter\": \"someValue\"}");
+
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("ClosedLoop_Fault", adapter.getConfigPolicyType());
+
+ parameters.setConfigBody("{\"onapname\": \"MyOnapName\"}");
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("MyOnapName", adapter.getOnapName());
+ }
+
+ @Test
+ public void testConfigClosedLoopPmParameterHandling() throws Exception {
+ PolicyParameters parameters = createParametersObject();
+ parameters.setPolicyConfigType(PolicyConfigType.ClosedLoop_PM);
+
+ PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
+
+ PolicyRestAdapter adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("ClosedLoop_PM", adapter.getConfigPolicyType());
+
+ parameters.setConfigBody("{\"someParameter\": \"someValue\"}");
+
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("ClosedLoop_PM", adapter.getConfigPolicyType());
+
+ parameters.setConfigBody(
+ "{\"onapname\": \"MyOnapName\",\"serviceTypePolicyName\":\"Service Type Policy Name\"}");
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("MyOnapName", adapter.getOnapName());
+ }
+
+ @Test
+ public void testConfigBrmsParameterHandling() throws Exception {
+ PolicyParameters parameters = createParametersObject();
+ parameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
+
+ PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
+ assertThatThrownBy(() -> wrapper.populateRequestParameters(parameters))
+ .isInstanceOf(NullPointerException.class);
+
+ Map<AttributeType, Map<String, String>> attributes = new LinkedHashMap<>();
+ parameters.setAttributes(attributes);
+ assertThatThrownBy(() -> wrapper.populateRequestParameters(parameters))
+ .isInstanceOf(NullPointerException.class);
+
+ Map<String, String> templateMap = new LinkedHashMap<>();
+ templateMap.put("templateName", "Template Name");
+ attributes.put(AttributeType.RULE, templateMap);
+ PolicyRestAdapter adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("BRMS_Param", adapter.getConfigPolicyType());
+ assertEquals("Template Name", adapter.getRuleName());
+
+ parameters.setConfigBody("{\"someParameter\": \"someValue\"}");
+
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("BRMS_Param", adapter.getConfigPolicyType());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testDecisionRainyDayParameterHandling() throws Exception {
+ PolicyParameters parameters = createParametersObject();
+ parameters.setPolicyClass(PolicyClass.Decision);
+
+ PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
+ assertThatThrownBy(() -> wrapper.populateRequestParameters(parameters))
+ .isInstanceOf(NullPointerException.class);
+
+ Map<AttributeType, Map<String, String>> attributes = new LinkedHashMap<>();
+ parameters.setAttributes(attributes);
+ assertThatThrownBy(() -> wrapper.populateRequestParameters(parameters))
+ .isInstanceOf(NullPointerException.class);
+
+ parameters.setRuleProvider(RuleProvider.RAINY_DAY);
+ assertThatThrownBy(() -> wrapper.populateRequestParameters(parameters))
+ .isInstanceOf(NullPointerException.class);
+
+ Map<String, String> treatments = new LinkedHashMap<>();
+ parameters.setTreatments(treatments);
+
+ PolicyRestAdapter adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("Rainy_Day", adapter.getRuleProvider());
+
+ treatments.put("ATreatment", "A Treatment Value");
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("ATreatment", ((Map<String, String>) adapter.getRainyday().getTreatmentTableChoices().get(0))
+ .get("errorcode"));
+ assertEquals("A Treatment Value",
+ ((Map<String, String>) adapter.getRainyday().getTreatmentTableChoices().get(0))
+ .get("treatment"));
+
+ Map<String, String> matchingMap = new LinkedHashMap<>();
+ matchingMap.put("ServiceType", "AServiceType");
+ attributes.put(AttributeType.MATCHING, matchingMap);
+ parameters.setAttributes(attributes);
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("AServiceType", adapter.getRainyday().getServiceType());
+ }
+
+ @Test
+ public void testDecisionGuardParameterHandling() throws Exception {
+ PolicyParameters parameters = createParametersObject();
+ parameters.setPolicyClass(PolicyClass.Decision);
+
+ PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
+ assertThatThrownBy(() -> wrapper.populateRequestParameters(parameters))
+ .isInstanceOf(NullPointerException.class);
+
+ Map<AttributeType, Map<String, String>> attributes = new LinkedHashMap<>();
+ parameters.setAttributes(attributes);
+ assertThatThrownBy(() -> wrapper.populateRequestParameters(parameters))
+ .isInstanceOf(NullPointerException.class);
+
+ parameters.setRuleProvider(RuleProvider.GUARD_BL_YAML);
+
+ PolicyRestAdapter adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("GUARD_BL_YAML", adapter.getRuleProvider());
+
+ parameters.setRuleProvider(RuleProvider.GUARD_MIN_MAX);
+
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("GUARD_MIN_MAX", adapter.getRuleProvider());
+
+ parameters.setRuleProvider(RuleProvider.GUARD_YAML);
+
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("GUARD_YAML", adapter.getRuleProvider());
+
+ Map<String, String> matchingMap = new LinkedHashMap<>();
+ matchingMap.put("actor", "Actor");
+ matchingMap.put("recipe", "Recipe");
+ matchingMap.put("guardActiveStart", "GuardActiveStart");
+ matchingMap.put("guardActiveEnd", "GuardActiveEnd");
+ matchingMap.put("limit", "Limit");
+ matchingMap.put("timeWindow", "Window");
+ matchingMap.put("timeUnits", "Units");
+
+ attributes.put(AttributeType.MATCHING, matchingMap);
+ parameters.setAttributes(attributes);
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("Actor", adapter.getYamlparams().getActor());
+ assertEquals("Recipe", adapter.getYamlparams().getRecipe());
+ assertEquals("GuardActiveStart", adapter.getYamlparams().getGuardActiveStart());
+ assertEquals("GuardActiveEnd", adapter.getYamlparams().getGuardActiveEnd());
+ assertEquals("Limit", adapter.getYamlparams().getLimit());
+ assertEquals("Window", adapter.getYamlparams().getTimeWindow());
+ assertEquals("Units", adapter.getYamlparams().getTimeUnits());
+
+ parameters.setRuleProvider(RuleProvider.GUARD_MIN_MAX);
+ matchingMap.put("min", "TheMin");
+ matchingMap.put("max", "TheMax");
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("TheMin", adapter.getYamlparams().getMin());
+ assertEquals("TheMax", adapter.getYamlparams().getMax());
+
+ parameters.setRuleProvider(RuleProvider.GUARD_BL_YAML);
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertTrue(adapter.getYamlparams().getBlackList().isEmpty());
+
+ matchingMap.put("blackList", "Bad0,Bad1");
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("Bad0", adapter.getYamlparams().getBlackList().get(0));
+ assertEquals("Bad1", adapter.getYamlparams().getBlackList().get(1));
+
+ parameters.setRuleProvider(RuleProvider.AAF);
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertNull(adapter.getYamlparams());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testActionParameterHandling() throws Exception {
+ PolicyParameters parameters = createParametersObject();
+ parameters.setPolicyClass(PolicyClass.Action);
+
+ PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
+
+ PolicyRestAdapter adapter = wrapper.populateRequestParameters((parameters));
+ assertTrue(adapter.getRuleAlgorithmschoices().isEmpty());
+
+ List<String> dynamicRuleAlgorithmLabels = new ArrayList<>();
+ parameters.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertTrue(adapter.getRuleAlgorithmschoices().isEmpty());
+
+ dynamicRuleAlgorithmLabels.add("Label0");
+ List<String> dynamicRuleAlgorithmFunctions = new ArrayList<>();
+ dynamicRuleAlgorithmFunctions.add("FirstAlgorithmFunction");
+ parameters.setDynamicRuleAlgorithmFunctions(dynamicRuleAlgorithmFunctions);
+ List<String> dynamicRuleAlgorithmField1 = new ArrayList<>();
+ dynamicRuleAlgorithmField1.add("FirstAlgorithmFunctionField1");
+ parameters.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
+ List<String> dynamicRuleAlgorithmField2 = new ArrayList<>();
+ dynamicRuleAlgorithmField2.add("FirstAlgorithmFunctionField2");
+ parameters.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
+ parameters.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals(1, adapter.getRuleAlgorithmschoices().size());
+ assertEquals("Label0", ((LinkedHashMap<String, String>) adapter.getRuleAlgorithmschoices().get(0)).get("id"));
+
+ Map<String, String> matchingMap = new LinkedHashMap<>();
+ matchingMap.put("AKey", "AValue");
+
+ Map<AttributeType, Map<String, String>> attributes = new LinkedHashMap<>();
+ attributes.put(AttributeType.MATCHING, matchingMap);
+ parameters.setAttributes(attributes);
+ adapter = wrapper.populateRequestParameters((parameters));
+ assertEquals("AKey", ((LinkedHashMap<String, String>) adapter.getAttributes().get(0)).get("key"));
+ }
+
+ private PolicyParameters createParametersObject() {
+ PolicyParameters parameters = new PolicyParameters();
+
+ parameters.setPolicyName("PolicyName");
+ parameters.setOnapName("ONAPName");
+ parameters.setPriority("SomePriority");
+ parameters.setConfigName("ConfigName");
+ parameters.setRiskType("RiskType");
+ parameters.setRiskLevel("RiskLevel");
+ parameters.setGuard(false);
+ parameters.setTtlDate(new Date());
+
+ return parameters;
+ }
+}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/util/PolicyValidationTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/util/PolicyValidationTest.java
index 6051db4c3..d019c6370 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/util/PolicyValidationTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/util/PolicyValidationTest.java
@@ -3,13 +3,14 @@
* ONAP-REST
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -17,20 +18,44 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.rest.util;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.IOException;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
import java.util.UUID;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
import org.onap.policy.api.PolicyConfigType;
import org.onap.policy.api.PolicyParameters;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.rest.adapter.ClosedLoopFaultTrapDatas;
import org.onap.policy.rest.adapter.PolicyRestAdapter;
+import org.onap.policy.rest.dao.CommonClassDao;
+import org.onap.policy.rest.jpa.MicroServiceModels;
+@RunWith(MockitoJUnitRunner.class)
public class PolicyValidationTest {
+ @Mock
+ private CommonClassDao commonClassDao;
@Before
public void setUp() throws Exception {
@@ -41,9 +66,7 @@ public class PolicyValidationTest {
}
@Test
- public void microServicePolicyTests() throws Exception{
- PolicyValidation validation = new PolicyValidation();
- PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
+ public void microServicePolicyTests() throws Exception {
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
@@ -51,8 +74,8 @@ public class PolicyValidationTest {
policyParameters.setPolicyDescription("This is a sample Micro Service policy Create example");
policyParameters.setOnapName("DCAE");
policyParameters.setPriority("1");
- String MSjsonString = "{\"service\":\"TOSCA_namingJenny\",\"location\":\"Test DictMSLoc\",\"uuid\":\"testDict DCAEUIID\",\"policyName\":\"testModelValidation\",\"description\":\"test\",\"configName\":\"testDict MSConfName\",\"templateVersion\":\"1607\",\"version\":\"gw12181031\",\"priority\":\"5\",\"policyScope\":\"resource=ResourcetypeVenktest1,service=ServiceName1707,type=Name1707,closedLoopControlName=Retest_retest1\",\"riskType\":\"Test\",\"riskLevel\":\"3\",\"guard\":\"True\",\"content\":{\"police-instance-name\":\"testing\",\"naming-models\":[{\"naming-properties\":[{\"property-value\":\"test\",\"source-endpoint\":\"test\",\"property-name\":\"testPropertyname\",\"increment-sequence\":{\"scope\":\"VNF\",\"start-value\":\"1\",\"length\":\"3\",\"increment\":\"2\"},\"source-system\":\"TOSCA\"}],\"naming-type\":\"testNamingType\",\"naming-recipe\":\"testNamingRecipe\"}]}}";;
- policyParameters.setConfigBody(MSjsonString);
+ String msJsonString = TextFileUtils.getTextFileAsString("src/test/resources/policies/MicroServicePolicy.json");
+ policyParameters.setConfigBody(msJsonString);
policyParameters.setRequestID(UUID.randomUUID());
SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
Date date = dateformat3.parse("15/10/2016");
@@ -62,19 +85,1202 @@ public class PolicyValidationTest {
policyParameters.setRiskType("TEST");
policyParameters.setRequestID(UUID.randomUUID());
-
+ PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
PolicyRestAdapter policyData = wrapper.populateRequestParameters(policyParameters);
- StringBuilder responseString = validation.validatePolicy(policyData);
+ PolicyValidation validation = new PolicyValidation();
+ String responseString = validation.validatePolicy(policyData).toString();
+
+ assertNotSame("success", responseString);
+
+ new PolicyValidation(null);
+ assertNull(PolicyValidation.getCommonClassDao());
+
+ policyData.setConfigPolicyType("ClosedLoop_Fault");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).doesNotContain("success");
+
+ policyData.setConfigPolicyType("ClosedLoop_PM");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).doesNotContain("success");
+
+ policyData.setConfigPolicyType("Enforcer Config");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).doesNotContain("success");
+
+ policyData.setConfigPolicyType("Optimization");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).doesNotContain("success");
+
+ policyData.setConfigPolicyType("Strange");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).doesNotContain("success");
+ }
+
+ @Test
+ public void testPolicyHeadingValidation() throws IOException {
+ PolicyValidation validation = new PolicyValidation();
+ PolicyRestAdapter policyData = new PolicyRestAdapter();
+
+ String responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("PolicyName Should not be empty");
+
+ policyData.setPolicyName("%%%~~~%%%");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("The Value in Required Field will allow only '{0-9}, {a-z}, {A-Z}");
+
+ policyData.setPolicyName("ALegalPolicyName");
+ policyData.setPolicyDescription("@CreatedBy:");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString)
+ .contains("The value in the description shouldn't contain @CreatedBy: or @ModifiedBy:");
+ policyData.setPolicyDescription("@CreatedBy:");
+
+ policyData.setPolicyDescription("A Legal Description");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString)
+ .doesNotContain("The value in the description shouldn't contain @CreatedBy: or @ModifiedBy:");
+ }
+
+ @Test
+ public void testPolicyAttributeValidation() throws IOException {
+ PolicyValidation validation = new PolicyValidation();
+ PolicyRestAdapter policyData = new PolicyRestAdapter();
+ policyData.setPolicyName("ALegalPolicyName");
+ policyData.setPolicyDescription("A Valid Description");
+
+ String responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ policyData.setApiflag("API");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ policyData.setApiflag("NOTAPI");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ List<Object> attributes = new ArrayList<>();
+ policyData.setAttributes(attributes);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ attributes.add(new String("hello"));
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+ attributes.clear();
+
+ Map<String, String> mapAttribute = new LinkedHashMap<>();
+ attributes.add(mapAttribute);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Component Attributes</b>:<i> has one missing Component Attribute value");
+
+ mapAttribute.put("key", "value");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("<b>Component Attributes</b>:<i> has one missing Component Attribute value</i><br>",
+ responseString);
+
+ mapAttribute.put("key", "");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("<b>Attributes or Component Attributes</b>:<i>null : value has spaces or invalid characters</i>"
+ + "<br><b>Component Attributes</b>:<i> has one missing Component Attribute value</i><br>",
+ responseString);
+ mapAttribute.clear();
+
+ responseString = validation.validatePolicy(policyData).toString();
+ mapAttribute.put("hello", "aaa");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("<b>Component Attributes</b>:<i> has one missing Component Attribute key</i><br>"
+ + "<b>Component Attributes</b>:<i> has one missing Component Attribute value</i><br>",
+ responseString);
+
+ policyData.setPolicyType("Config");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("<b>RiskType</b>: Risk Type Should not be Empty</i><br>"
+ + "<b>RiskLevel</b>: Risk Level Should not be Empty</i><br>"
+ + "<b>Guard</b>: Guard Value Should not be Empty</i><br>", responseString);
+
+ policyData.setConfigPolicyType("Base");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("has one missing Attribute key");
+
+ policyData.setConfigPolicyType("BRMS_Param");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("has one missing Attribute key");
+
+ policyData.setConfigPolicyType("BRMS_Raw");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("has one missing Attribute key");
+
+ policyData.setConfigPolicyType(null);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Risk Level Should not be Empty");
+
+ mapAttribute.clear();
+ mapAttribute.put("value", "thevalue");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Risk Level Should not be Empty");
+
+ mapAttribute.put("value", "$$$%%%%");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Risk Level Should not be Empty");
+
+ policyData.setConfigPolicyType("Base");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("value has spaces or invalid characters");
+
+ policyData.setConfigPolicyType("BRMS_Param");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("value has spaces or invalid characters");
+
+ policyData.setConfigPolicyType("BRMS_Raw");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("value has spaces or invalid characters");
+
+ policyData.setConfigPolicyType(null);
+ policyData.setPolicyType(null);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("value has spaces or invalid characters");
+ }
+
+ @Test
+ public void testPolicySettingsValidation() throws IOException {
+ PolicyValidation validation = new PolicyValidation();
+ PolicyRestAdapter policyData = new PolicyRestAdapter();
+ policyData.setPolicyName("ALegalPolicyName");
+ policyData.setPolicyDescription("A Valid Description");
+
+ String responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ policyData.setApiflag("API");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ policyData.setApiflag("NOTAPI");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ List<Object> settings = new ArrayList<>();
+ policyData.setSettings(settings);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ settings.add("hello");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+ settings.clear();
+
+ Map<String, String> mapSetting = new LinkedHashMap<>();
+ settings.add(mapSetting);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Settings Attributes</b>:<i> has one missing Attribute key");
+
+ mapSetting.put("key", "value");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("<b>Settings Attributes</b>:<i> has one missing Attribute Value</i><br>", responseString);
+
+ mapSetting.put("key", "");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("<b>Settings Attributes</b>:<i> has one missing Attribute Value</i><br>", responseString);
+ mapSetting.clear();
+
+ mapSetting.put("value", "thevalue");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("has one missing Attribute key");
+
+ mapSetting.put("value", "$$$%%%");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("value has spaces or invalid characters");
+ }
+
+ @Test
+ public void testPolicyRuleAlgorithmsValidation() throws IOException {
+ PolicyValidation validation = new PolicyValidation();
+ PolicyRestAdapter policyData = new PolicyRestAdapter();
+ policyData.setPolicyName("ALegalPolicyName");
+ policyData.setPolicyDescription("A Valid Description");
+
+ String responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ policyData.setApiflag("API");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ policyData.setApiflag("NOTAPI");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ List<Object> ruleAlgorithmschoices = new ArrayList<>();
+ policyData.setRuleAlgorithmschoices(ruleAlgorithmschoices);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ ruleAlgorithmschoices.add("hello");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+ ruleAlgorithmschoices.clear();
+
+ Map<String, String> mapChoice = new LinkedHashMap<>();
+ ruleAlgorithmschoices.add(mapChoice);
+ assertNull(validation.validatePolicy(policyData));
+
+ mapChoice.clear();
+ mapChoice.put("id", "TheID");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Field 1 value is not selected");
+
+ mapChoice.put("dynamicRuleAlgorithmField1", "Field1");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Field 2 value is not selected");
+
+ mapChoice.put("dynamicRuleAlgorithmCombo", "Combo");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Field 3 value is empty");
+
+ mapChoice.put("dynamicRuleAlgorithmField2", "Field2");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ mapChoice.put("dynamicRuleAlgorithmField2", "%%%$$$");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Field 3 value has special characters");
+ }
+
+ @Test
+ public void testPolicyConfigBaseValidation() throws IOException {
+ PolicyValidation validation = new PolicyValidation();
+ PolicyRestAdapter policyData = new PolicyRestAdapter();
+ policyData.setPolicyName("ALegalPolicyName");
+ policyData.setPolicyDescription("A Valid Description");
+
+ String responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ policyData.setApiflag("API");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ policyData.setPolicyType("Config");
+ policyData.setConfigPolicyType("Base");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Onap Name Should not be empty");
+
+ policyData.setOnapName("%%%$$$$");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>OnapName</b>:<i>The Value in Required Field");
+
+ policyData.setOnapName("AValidOnapName");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Risk Level Should not be Empty");
+
+ policyData.setRiskType("%%%$$$$");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>RiskType</b>:<i>The Value in Required Field");
+
+ policyData.setRiskType("AValidRiskType");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Risk Level Should not be Empty");
+
+ policyData.setRiskLevel("%%%$$$$");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>RiskLevel</b>:<i>The Value in Required Field");
+
+ policyData.setRiskLevel("AValidRiskLevel");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Guard Value Should not be Empty");
+
+ policyData.setGuard("%%%$$$$");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Guard</b>:<i>The Value in Required Field");
+
+ policyData.setGuard("AValidGuard");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Config Name Should not be Empty");
+
+ policyData.setConfigName("%%%$$$$");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("ConfigName:The Value in Required Field");
+
+ policyData.setConfigName("AValidConfigName");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Config Type Should not be Empty");
+
+ policyData.setConfigType("%%%$$$$");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("ConfigType:The Value in Required Field");
+
+ policyData.setConfigType("AValidConfigType");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Config Body Should not be Empty");
+
+ policyData.setConfigBodyData("");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Config Body Should not be Empty");
+
+ policyData.setConfigBodyData("%%%$$$$");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setConfigType(null);
+ policyData.setConfigBodyData("ValidConfigBodyData");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Config Type Should not be Empty");
+
+ policyData.setConfigType("JSON");
+ policyData.setConfigBodyData("{");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Config Body: JSON Content is not valid");
+
+ policyData.setConfigBodyData("ValidConfigBodyData");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setConfigType("XML");
+ policyData.setConfigBodyData("{");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Config Body: XML Content data is not valid");
+
+ policyData.setConfigBodyData("<tag>value</tag>");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setConfigType("PROPERTIES");
+ policyData.setConfigBodyData("{");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Config Body: Property data is not valid");
+
+ policyData.setConfigBodyData("propertyName=PropertyValue");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+ }
+
+ @Test
+ public void testPolicyConfigFirewallValidation() throws IOException {
+ PolicyValidation validation = new PolicyValidation();
+ PolicyRestAdapter policyData = new PolicyRestAdapter();
+ policyData.setPolicyName("ALegalPolicyName");
+ policyData.setPolicyDescription("A Valid Description");
+
+ String responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ policyData.setApiflag("API");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ // Invalid values tested in config base test
+ policyData.setOnapName("AValidOnapName");
+ policyData.setRiskType("AValidRiskType");
+ policyData.setRiskLevel("AValidRiskLevel");
+ policyData.setGuard("AValidGuard");
+ assertEquals("success", responseString);
+
+ policyData.setPolicyType("Config");
+ policyData.setConfigPolicyType("Firewall Config");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Config Name is required");
+
+ policyData.setConfigName("");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Config Name is required");
+
+ policyData.setConfigName("%%%$$$$");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>ConfigName</b>:<i>The Value in Required Field");
+
+ policyData.setConfigName("AValidConfigName");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Security Zone is required");
+
+ policyData.setSecurityZone("");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Security Zone is required");
+
+ policyData.setSecurityZone("AValidSeurityZone");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+ }
+
+ @Test
+ public void testPolicyConfigBRMSValidation() throws IOException {
+ PolicyValidation validation = new PolicyValidation();
+ PolicyRestAdapter policyData = new PolicyRestAdapter();
+ policyData.setPolicyName("ALegalPolicyName");
+ policyData.setPolicyDescription("A Valid Description");
+
+ String responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ policyData.setApiflag("API");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ // Invalid values tested in config base test
+ policyData.setOnapName("AValidOnapName");
+ policyData.setRiskType("AValidRiskType");
+ policyData.setRiskLevel("AValidRiskLevel");
+ policyData.setGuard("AValidGuard");
+ assertEquals("success", responseString);
+
+ policyData.setPolicyType("Config");
+ policyData.setConfigPolicyType("BRMS_Param");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("BRMS Template is required");
+
+ policyData.setRuleName("");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("BRMS Template is required");
+
+ policyData.setRuleName("AValidRuleName");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+ policyData.setRuleName(null);
+
+ policyData.setConfigPolicyType("BRMS_Raw");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Raw Rule is required");
+
+ policyData.setConfigBodyData("");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Raw Rule is required");
+
+ policyData.setConfigBodyData("InvalidConfigBodyData");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("expecting one of the following tokens");
+
+ policyData.setConfigBodyData("import org.onap.policy.test.DummyTestSomething;");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+ }
+
+ @Test
+ public void testPolicyConfigCloseLoopPmValidation() throws IOException {
+ PolicyValidation validation = new PolicyValidation();
+ PolicyRestAdapter policyData = new PolicyRestAdapter();
+ policyData.setPolicyName("ALegalPolicyName");
+ policyData.setPolicyDescription("A Valid Description");
+
+ String responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
- assertNotSame("success", responseString.toString());
+ policyData.setApiflag("API");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+ // Invalid values tested in config base test
+ policyData.setOnapName("AValidOnapName");
+ policyData.setRiskType("AValidRiskType");
+ policyData.setRiskLevel("AValidRiskLevel");
+ policyData.setGuard("AValidGuard");
+ assertEquals("success", responseString);
+
+ policyData.setPolicyType("Config");
+ policyData.setConfigPolicyType("ClosedLoop_PM");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("ServiceType PolicyName is required");
+
+ Map<String, String> serviceTypePolicyName = null;
+ policyData.setServiceTypePolicyName(serviceTypePolicyName);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("ServiceType PolicyName is required");
+
+ serviceTypePolicyName = new LinkedHashMap<>();
+ policyData.setServiceTypePolicyName(serviceTypePolicyName);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("ServiceType PolicyName is required");
+
+ serviceTypePolicyName.put("AKey", "AValue");
+ policyData.setServiceTypePolicyName(serviceTypePolicyName);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("ServiceType PolicyName is required");
+ serviceTypePolicyName.clear();
+
+ serviceTypePolicyName.put("serviceTypePolicyName", "");
+ policyData.setServiceTypePolicyName(serviceTypePolicyName);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("ServiceType PolicyName is required");
+
+ serviceTypePolicyName.put("serviceTypePolicyName", "AValidserviceTypePolicyName");
+ policyData.setServiceTypePolicyName(serviceTypePolicyName);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ policyData.setJsonBody("");
+ assertNull(validation.validatePolicy(policyData));
+
+ policyData.setJsonBody("InvalidConfigBodyData");
+ assertNull(validation.validatePolicy(policyData));
+
+ policyData.setJsonBody("{}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ policyData.setJsonBody("{\"gamma\": false}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ policyData.setJsonBody("{\"gamma\": true}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setJsonBody("{\"mcr\": false}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ policyData.setJsonBody("{\"mcr\": true}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setJsonBody("{\"trinity\": false}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ policyData.setJsonBody("{\"trinity\": true}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setJsonBody("{\"vDNS\": false}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ policyData.setJsonBody("{\"vDNS\": true}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setJsonBody("{\"vUSP\": false}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ policyData.setJsonBody("{\"vUSP\": true}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setJsonBody("{\"trinity\": true, \"emailAddress\": null}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setJsonBody("{\"trinity\": true, \"emailAddress\": \"\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Email Address is not Valid");
+
+ policyData.setJsonBody("{\"trinity\": true, \"emailAddress\": \"%%%$$$\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Email Address is not Valid");
+
+ policyData.setJsonBody("{\"trinity\": true, \"emailAddress\": \"dorothy@emealdcity.oz\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setJsonBody("{\"trinity\": true, \"geoLink\": null}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setJsonBody("{\"trinity\": true, \"geoLink\": \"\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setJsonBody("{\"trinity\": true, \"geoLink\": \"$$$%%%\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("The Value in Required Field");
+
+ policyData.setJsonBody("{\"trinity\": true, \"geoLink\": \"AValidGeoLink\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setJsonBody("{\"trinity\": true, \"attributes\": null}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setJsonBody("{\"trinity\": true, \"attributes\": {}}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setJsonBody("{\"trinity\": true, \"attributes\": {\"an0\":\"av0\"}}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setJsonBody("{\"trinity\": true, \"attributes\": {\"an0\":\"$$$%%%\"}}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("value has spaces or invalid characters");
+
+ policyData.setJsonBody("{\"trinity\": true, \"attributes\": {\"Message\":\"$$$%%%\"}}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
}
@Test
- public final void testEmailValidation() {
+ public void testPolicyConfigCloseLoopFaultValidation() throws IOException {
PolicyValidation validation = new PolicyValidation();
- String result = validation.emailValidation("testemail@test.com", "SUCCESS");
- assertEquals("success", result);
+ PolicyRestAdapter policyData = new PolicyRestAdapter();
+ policyData.setPolicyName("ALegalPolicyName");
+ policyData.setPolicyDescription("A Valid Description");
+
+ String responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ policyData.setApiflag("API");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ // Invalid values tested in config base test
+ policyData.setOnapName("AValidOnapName");
+ policyData.setRiskType("AValidRiskType");
+ policyData.setRiskLevel("AValidRiskLevel");
+ policyData.setGuard("AValidGuard");
+ assertEquals("success", responseString);
+
+ policyData.setPolicyType("Config");
+ policyData.setConfigPolicyType("ClosedLoop_Fault");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ policyData.setJsonBody("");
+ assertNull(validation.validatePolicy(policyData));
+
+ policyData.setJsonBody("InvalidConfigBodyData");
+ assertNull(validation.validatePolicy(policyData));
+
+ policyData.setJsonBody("{}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("There were no conditions provided in configBody json");
+
+ policyData.setJsonBody("{\"conditions\": null}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("There were no conditions provided in configBody json");
+
+ policyData.setJsonBody("{\"conditions\": \"\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select At least one Condition");
+
+ policyData.setJsonBody("{\"conditions\": \"AValidCondition\"}");
+ assertNull(validation.validatePolicy(policyData));
+
+ policyData.setApiflag("NOAPI");
+
+ policyData.setJsonBody("");
+ assertNull(validation.validatePolicy(policyData));
+
+ policyData.setJsonBody("InvalidConfigBodyData");
+ assertNull(validation.validatePolicy(policyData));
+
+ ClosedLoopFaultTrapDatas trapDatas = new ClosedLoopFaultTrapDatas();
+ policyData.setTrapDatas(trapDatas);
+
+ ClosedLoopFaultTrapDatas faultDatas = new ClosedLoopFaultTrapDatas();
+ policyData.setFaultDatas(faultDatas);
+
+ policyData.setJsonBody("{}");
+ assertThat(responseString).contains("Select At least one Condition");
+
+ List<Object> trap1 = new ArrayList<>();
+ trapDatas.setTrap1(trap1);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Trigger Clear TimeOut is required");
+
+ policyData.setClearTimeOut("AValidClearTimeout");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Trap Max Age is required");
+
+ policyData.setTrapMaxAge("AValidTrapMaxAge");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ trapDatas.setTrap1(null);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ faultDatas.setTrap1(null);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ faultDatas.setTrap1(trap1);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Fault Clear TimeOut is required when");
+
+ policyData.setVerificationclearTimeOut("AValidVerificationClearTimeout");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ policyData.setJsonBody("{\"gamma\": false}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ policyData.setJsonBody("{\"gamma\": true}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("vPRO Actions is required");
+
+ policyData.setJsonBody("{\"mcr\": false}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ policyData.setJsonBody("{\"mcr\": true}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("vPRO Actions is required");
+
+ policyData.setJsonBody("{\"trinity\": false}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ policyData.setJsonBody("{\"trinity\": true}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("vPRO Actions is required");
+
+ policyData.setJsonBody("{\"vDNS\": false}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ policyData.setJsonBody("{\"vDNS\": true}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("vPRO Actions is required");
+
+ policyData.setJsonBody("{\"vUSP\": false}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select at least one D2");
+
+ policyData.setJsonBody("{\"vUSP\": true}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("vPRO Actions is required");
+
+ policyData.setJsonBody("{\"trinity\": true, \"emailAddress\": null}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("vPRO Actions is required");
+
+ policyData.setJsonBody("{\"trinity\": true, \"emailAddress\": \"\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("vPRO Actions is required");
+
+ policyData.setJsonBody("{\"trinity\": true, \"emailAddress\": \"%%%$$$\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Email Address is not Valid");
+
+ policyData.setJsonBody("{\"trinity\": true, \"emailAddress\": \"dorothy@emealdcity.oz\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("vPRO Actions is required");
+
+ policyData.setJsonBody("{\"trinity\": true, \"actions\": null}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("vPRO Actions is required");
+
+ policyData.setJsonBody("{\"trinity\": true, \"actions\": \"\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("vPRO Actions is required");
+
+ policyData.setJsonBody("{\"trinity\": true, \"actions\": \"$$$%%%\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Policy Status is required");
+ assertThat(responseString).contains("Vnf Type is required");
+
+ policyData.setJsonBody("{\"trinity\": true, \"actions\": \"ValidActions\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Policy Status is required");
+
+ policyData.setJsonBody("{\"trinity\": true, \"actions\": \"ValidActions\", \"closedLoopPolicyStatus\": null}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Policy Status is required");
+
+ policyData.setJsonBody("{\"trinity\": true, \"actions\": \"ValidActions\", \"closedLoopPolicyStatus\": \"\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Policy Status is required");
+
+ policyData.setJsonBody(
+ "{\"trinity\": true, \"actions\": \"ValidActions\", \"closedLoopPolicyStatus\": \"$$$%%%\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select At least one Condition");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\""
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select At least one Condition");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\","
+ + "\"conditions\": null"
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Select At least one Condition");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\","
+ + "\"conditions\": \"SEND\""
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Aging Window is required");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\","
+ + "\"conditions\": \"SEND\","
+ + "\"geoLink\": null"
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Aging Window is required");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\","
+ + "\"conditions\": \"SEND\","
+ + "\"geoLink\": \"\""
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Aging Window is required");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\","
+ + "\"conditions\": \"SEND\","
+ + "\"geoLink\": \"%%%$$$\""
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("GeoLink</b>:<i>The Value in Required Field");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\","
+ + "\"conditions\": \"SEND\","
+ + "\"geoLink\": \"AValidGeoLink\""
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Aging Window is required");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\","
+ + "\"conditions\": \"SEND\","
+ + "\"agingWindow\": -1"
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Time Interval is required");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\","
+ + "\"conditions\": \"SEND\","
+ + "\"agingWindow\": -1,"
+ + "\"timeInterval\": -1"
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Number of Retries is required");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\","
+ + "\"conditions\": \"SEND\","
+ + "\"agingWindow\": -1,"
+ + "\"timeInterval\": -1,"
+ + "\"retrys\": -1"
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("APP-C Timeout is required");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\","
+ + "\"conditions\": \"SEND\","
+ + "\"agingWindow\": -1,"
+ + "\"timeInterval\": -1,"
+ + "\"retrys\": -1,"
+ + "\"timeOutvPRO\": -1"
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("TimeOutRuby is required");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\","
+ + "\"conditions\": \"SEND\","
+ + "\"agingWindow\": -1,"
+ + "\"timeInterval\": -1,"
+ + "\"retrys\": -1,"
+ + "\"timeOutvPRO\": -1,"
+ + "\"timeOutRuby\": -1"
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Vnf Type is required");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\","
+ + "\"conditions\": \"SEND\","
+ + "\"agingWindow\": -1,"
+ + "\"timeInterval\": -1,"
+ + "\"retrys\": -1,"
+ + "\"timeOutvPRO\": -1,"
+ + "\"timeOutRuby\": -1,"
+ + "\"vnfType\": null"
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Vnf Type is required");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\","
+ + "\"conditions\": \"SEND\","
+ + "\"agingWindow\": -1,"
+ + "\"timeInterval\": -1,"
+ + "\"retrys\": -1,"
+ + "\"timeOutvPRO\": -1,"
+ + "\"timeOutRuby\": -1,"
+ + "\"vnfType\": \"\""
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Vnf Type is required");
+
+ // @formatter:off
+ policyData.setJsonBody("{"
+ + "\"trinity\": true,"
+ + "\"actions\": \"ValidActions\","
+ + "\"closedLoopPolicyStatus\": \"AValidStatus\","
+ + "\"conditions\": \"SEND\","
+ + "\"agingWindow\": -1,"
+ + "\"timeInterval\": -1,"
+ + "\"retrys\": -1,"
+ + "\"timeOutvPRO\": -1,"
+ + "\"timeOutRuby\": -1,"
+ + "\"vnfType\": \"AValid VNF Type\""
+ + "}");
+ // @formatter:on
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
}
+ @Test
+ public void testPolicyConfigMicroServiceValidation() throws IOException {
+ PolicyValidation validation = new PolicyValidation(commonClassDao);
+ PolicyRestAdapter policyData = new PolicyRestAdapter();
+ policyData.setPolicyName("ALegalPolicyName");
+ policyData.setPolicyDescription("A Valid Description");
+
+ String responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ policyData.setApiflag("NOAPI");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success", responseString);
+
+ // Invalid values tested in config base test
+ policyData.setOnapName("AValidOnapName");
+ policyData.setRiskType("AValidRiskType");
+ policyData.setRiskLevel("AValidRiskLevel");
+ policyData.setGuard("AValidGuard");
+ assertEquals("success", responseString);
+
+ policyData.setPolicyType("Config");
+ policyData.setConfigPolicyType("Micro Service");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Micro Service Model is required");
+
+ policyData.setServiceType("");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Micro Service Model is required");
+
+ policyData.setServiceType("ServiceType");
+ assertNull(validation.validatePolicy(policyData));
+
+ policyData.setPolicyJSON("");
+ assertNull(validation.validatePolicy(policyData));
+
+ String msJsonContentString0 = TextFileUtils
+ .getTextFileAsString("src/test/resources/policies/MicroServicePolicyContent0.json");
+ policyData.setPolicyJSON(new ObjectMapper().readTree(msJsonContentString0));
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Micro Service Version is required");
+
+ String msJsonContentString1 = TextFileUtils
+ .getTextFileAsString("src/test/resources/policies/MicroServicePolicyContent1.json");
+ policyData.setPolicyJSON(new ObjectMapper().readTree(msJsonContentString1));
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Micro Service Version is required");
+
+ policyData.setServiceType("ServiceType-vServiceVersion");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("The model name, ServiceType of version, ServiceVersion was not found");
+
+ policyData.setServiceType("ServiceType");
+ policyData.setRuleProvider("MicroService_Model");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).doesNotContain("Priority is required");
+
+ policyData.setVersion("ServiceVersion");
+ Mockito.when(commonClassDao.getDataById(MicroServiceModels.class, "modelName:version",
+ "ServiceType:ServiceVersion")).thenReturn(null);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("The model name, ServiceType of version, ServiceVersion was not found");
+
+ List<Object> msModelsList = new ArrayList<>();
+ MicroServiceModels msModels = new MicroServiceModels();
+ msModelsList.add(msModels);
+ Mockito.when(commonClassDao.getDataById(MicroServiceModels.class, "modelName:version",
+ "ServiceType:ServiceVersion")).thenReturn(msModelsList);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ msModels.setAnnotation("SomeAnntation");
+ assertNull(validation.validatePolicy(policyData));
+
+ msModels.setAnnotation("annotation0Key=annotation0Value");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ msModels.setAnnotation("annotation0Key=range::10-100");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("annotation0Key is required for the MicroService model");
+
+ msModels.setAnnotation("police-instance-name=range::10-100");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Model Range:police-instance-name must be between 10 - 100");
+
+ msModels.setAnnotation("police-instance-range=range::12-100");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Model Range:police-instance-range must be between 12 - 100");
+
+ msModels.setAnnotation("police-instance-range=range::0-10");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("Model Range:police-instance-range must be between 0 - 10");
+
+ msModels.setAnnotation("police-instance-range=range::10-100");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ msModels.setAnnotation(null);
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setRuleProvider("Not_MicroService_Model");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Micro Service Model</b>:<i> location is required for this model");
+
+ policyData.setLocation("AValidLocation");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Micro Service Model</b>:<i> configName is required for this model");
+
+ policyData.setConfigName("AValidConfigname");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Micro Service Model</b>:<i> uuid is required for this model");
+
+ policyData.setUuid("AValidUUID");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Micro Service Model</b>:<i> policyScope is required for this model");
+
+ policyData.setPolicyScope("AValidPolicyScope");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Priority</b>:<i> Priority is required");
+
+ policyData.setPriority("AValidPriority");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ policyData.setApiflag("API");
+ assertNull(validation.validatePolicy(policyData));
+
+ msModels.setSubAttributes("{}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ msModels.setSubAttributes("{\"subAttrName0\": \"subAttrValue0\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ msModels.setSubAttributes("{\"subAttrName0\": 10}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ msModels.setSubAttributes("{\"subAttrName0\": {}}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ msModels.setSubAttributes("{\"subAttrName0\": []}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertEquals("success@#", responseString);
+
+ msModels.setSubAttributes("{\"subAttrName0\": \"subAttrValue0-required-true\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Micro Service Model</b>:<i> subAttrName0 is required");
+
+ msModels.setSubAttributes("{\"subAttrName0\": \":subAttrValue0-required-true\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Micro Service Model</b>:<i> subAttrName0 is required");
+
+ msModels.setSubAttributes("{\"subAttrName0\": \"UnknownType:subAttrValue0-required-true\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Micro Service Model</b>:<i> subAttrName0 is required");
+
+ msModels.setSubAttributes("{\"subAttrName0\": \"string:subAttrValue0-required-true\"}");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Micro Service Model</b>:<i> subAttrName0 is required");
+
+ msModels.setRefAttributes("refAttrName0=");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Micro Service Model</b>:<i> subAttrName0 is required");
+
+ msModels.setRefAttributes("refAttrName0=refAttrValue0");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Micro Service Model</b>:<i> subAttrName0 is required");
+
+ msModels.setRefAttributes("refAttrName0=refAttrValue0-required-true");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Micro Service Model</b>:<i> subAttrName0 is required");
+
+ msModels.setAttributes("");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Micro Service Model</b>:<i> subAttrName0 is required");
+
+ msModels.setAttributes("modelAttrName0=modelAttrValue0");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("<b>Micro Service Model</b>:<i> subAttrName0 is required");
+
+ msModels.setRefAttributes("refAttrName0=refAttrValue0-required-true,");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).contains("refAttrName0 is required");
+
+ msModels.setRefAttributes("police-instance-range=refAttrValue0-required-true,");
+ responseString = validation.validatePolicy(policyData).toString();
+ assertThat(responseString).doesNotContain("police-instance-range is required");
+ }
}