summaryrefslogtreecommitdiffstats
path: root/ONAP-REST
diff options
context:
space:
mode:
authorbobbymander <bobby.mander@att.com>2018-03-29 10:08:41 -0400
committerbobbymander <bobby.mander@att.com>2018-03-29 10:21:50 -0400
commit9dba1fd8d43c87baf6f43c4d27559c9d4a17d6d5 (patch)
treea729e9c030b64dd1e78a3bea3169c17704039ae0 /ONAP-REST
parentb6abd7445f80d1d165877f394555f8844fe7ac63 (diff)
JUnit additions for ONAP-REST
Issue-ID: POLICY-603 Change-Id: Ic8a20fc758927afb9200547d5919fcf70f15852b Signed-off-by: bobbymander <bobby.mander@att.com>
Diffstat (limited to 'ONAP-REST')
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionBodyEntityTest.java67
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ConfigurationDataEntityTest.java71
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroserviceHeaderdeFaultsTest.java53
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PIPConfigurationTest.java120
4 files changed, 311 insertions, 0 deletions
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
new file mode 100644
index 000000000..f8777d868
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionBodyEntityTest.java
@@ -0,0 +1,67 @@
+/*-
+ * ============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.hamcrest.CoreMatchers.is;
+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 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());
+
+ // 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)));
+ }
+}
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
new file mode 100644
index 000000000..da5dd5005
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ConfigurationDataEntityTest.java
@@ -0,0 +1,71 @@
+/*-
+ * ============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.hamcrest.CoreMatchers.is;
+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 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));
+ assertEquals(false, entity.equals(entity2));
+ assertThat(entity.hashCode(), is(not(0)));
+ }
+}
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
new file mode 100644
index 000000000..62452dcb0
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroserviceHeaderdeFaultsTest.java
@@ -0,0 +1,53 @@
+/*-
+ * ============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 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();
+
+ // 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());
+ }
+}
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..8d87173b0
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PIPConfigurationTest.java
@@ -0,0 +1,120 @@
+/*-
+ * ============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
+ assertEquals(332, config.toString().length());
+ }
+}