aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-REST/src/test
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-11-06 12:43:25 +0000
committerliamfallon <liam.fallon@est.tech>2019-11-06 14:08:27 +0000
commitf4ec47c009cdc385a7efed02dda5d26f2ec31b57 (patch)
tree3b6dfa768342ee2b967ea8db724fd47565db9d1e /ONAP-REST/src/test
parent927a79e5b7f9cacd2798504ac158f0a75dc64da8 (diff)
JUnit/SONAR/Checkstyle in ONAP-REST
First batch of JPA pojos Lombok'd and some missing coverage updated I'll be interested to see how Lomboking code shows up in SONAR, I have not added much JUnit here but I have reduced a good bit of source code, let's see what happens. Issue-ID: POLICY-2131 Change-Id: I8f270ef57282f63821c1eb94dd6b50f8ae541028 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'ONAP-REST/src/test')
-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)75
-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)105
3 files changed, 161 insertions, 89 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
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..b2c3a77c1 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,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.
@@ -17,6 +18,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.rest.jpa;
import static org.junit.Assert.assertTrue;
@@ -30,11 +32,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 +52,7 @@ public class ActionDictionaryJPATest {
}
@Test
- public void testActionDictionary(){
+ public void testActionDictionary() {
ActionPolicyDict data = new ActionPolicyDict();
data.setId(1);
assertTrue(1 == data.getId());
@@ -66,24 +73,24 @@ 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();
@@ -94,16 +101,16 @@ public class ActionDictionaryJPATest {
}
@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);
+ assertTrue(data.getFunctionArguments() != null);
data.setHigherOrderArg_LB(1);
assertTrue(1 == data.getHigherOrderArg_LB());
data.setHigherOrderArg_UB(1);
@@ -126,7 +133,7 @@ public class ActionDictionaryJPATest {
}
@Test
- public void testCategory(){
+ public void testCategory() {
Category data = new Category();
new Category(null);
data.setAttributes(new HashSet<>());
@@ -137,7 +144,7 @@ public class ActionDictionaryJPATest {
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);
@@ -149,12 +156,12 @@ public class ActionDictionaryJPATest {
}
@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 +171,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,7 +187,7 @@ public class ActionDictionaryJPATest {
}
@Test
- public void testObadvice(){
+ public void testObadvice() {
Obadvice data = new Obadvice();
new Obadvice();
new Obadvice("Test", "Test");
@@ -201,7 +208,7 @@ 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");
@@ -209,21 +216,21 @@ public class ActionDictionaryJPATest {
}
@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();
@@ -237,7 +244,7 @@ public class ActionDictionaryJPATest {
}
@Test
- public void testAttributeAssignment(){
+ public void testAttributeAssignment() {
AttributeAssignment data = new AttributeAssignment();
data.setId(1);
assertTrue(1 == data.getId());
@@ -248,16 +255,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,8 +277,8 @@ 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);
@@ -279,7 +286,7 @@ public class ActionDictionaryJPATest {
}
@Test
- public void testPolicyAlgorithms(){
+ public void testPolicyAlgorithms() {
PolicyAlgorithms data = new PolicyAlgorithms();
data.setId(1);
assertTrue(1 == data.getId());
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..fa83017f2 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,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.
@@ -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,17 +92,66 @@ 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();
@@ -101,17 +162,17 @@ public class CommonDictionaryJPATest {
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();
@@ -122,17 +183,17 @@ public class CommonDictionaryJPATest {
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());