summaryrefslogtreecommitdiffstats
path: root/models-pdp/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'models-pdp/src/test')
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageUtils.java31
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java2
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java (renamed from models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifier.java)43
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java7
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java2
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java14
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifierOptVersion.java71
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyTypeIdentifier.java63
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ToscaIdentifierTestBase.java81
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/persistence/provider/PdpProviderTest.java14
10 files changed, 62 insertions, 266 deletions
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageUtils.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageUtils.java
new file mode 100644
index 000000000..ee7e15b6a
--- /dev/null
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageUtils.java
@@ -0,0 +1,31 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+/**
+ * Utility class for tests of PdpMessage subclasses.
+ */
+public class PdpMessageUtils {
+
+ public static String removeVariableFields(String text) {
+ return text.replaceAll("requestId=[^,]*", "requestId=xxx").replaceAll("timestampMs=[^,]*", "timestampMs=nnn");
+ }
+}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java
index 39aee6f48..1813dde7d 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java
@@ -38,7 +38,7 @@ import org.onap.policy.common.utils.validation.ToStringTester;
public class TestModels {
@Test
- public void testPapModels() {
+ public void testPdpModels() {
final Validator validator = ValidatorBuilder.create().with(new ToStringTester()).with(new SetterTester())
.with(new GetterTester()).build();
validator.validate(TestModels.class.getPackage().getName(), new FilterPackageInfo());
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifier.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java
index 7a09e9d44..515c48385 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifier.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java
@@ -1,8 +1,9 @@
-/*
+/*-
* ============LICENSE_START=======================================================
* ONAP Policy Models
* ================================================================================
* 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.
@@ -24,39 +25,33 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
+import org.onap.policy.models.pdp.enums.PdpMessageType;
/**
- * Test the other constructors, as {@link TestModels} tests the other methods.
+ * Test the copy constructor, as {@link TestModels} tests the other methods.
*/
-public class TestToscaPolicyIdentifier extends ToscaIdentifierTestBase<ToscaPolicyIdentifier> {
- private static final String NAME = "my-name";
- private static final String VERSION = "1.2.3";
-
- public TestToscaPolicyIdentifier() {
- super(ToscaPolicyIdentifier.class);
- }
-
- @Test
- public void testAllArgsConstructor() {
- assertThatThrownBy(() -> new ToscaPolicyIdentifier(null, VERSION)).isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> new ToscaPolicyIdentifier(NAME, null)).isInstanceOf(NullPointerException.class);
-
- ToscaPolicyIdentifier orig = new ToscaPolicyIdentifier(NAME, VERSION);
- assertEquals(NAME, orig.getName());
- assertEquals(VERSION, orig.getVersion());
- }
+public class TestPdpMessage {
@Test
public void testCopyConstructor() {
- assertThatThrownBy(() -> new ToscaPolicyIdentifier(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new PdpMessage((PdpMessage) null)).isInstanceOf(NullPointerException.class);
- ToscaPolicyIdentifier orig = new ToscaPolicyIdentifier();
+ PdpMessage orig = new PdpMessage(PdpMessageType.PDP_STATE_CHANGE);
// verify with null values
- assertEquals(orig.toString(), new ToscaPolicyIdentifier(orig).toString());
+ PdpMessage newmsg = new PdpMessage(orig);
+ newmsg.setRequestId(orig.getRequestId());
+ newmsg.setTimestampMs(orig.getTimestampMs());
+ assertEquals(orig.toString(), newmsg.toString());
// verify with all values
- orig = new ToscaPolicyIdentifier(NAME, VERSION);
- assertEquals(orig.toString(), new ToscaPolicyIdentifier(orig).toString());
+ orig.setName("my-name");
+ orig.setPdpGroup("my-group");
+ orig.setPdpSubgroup("my-subgroup");
+
+ newmsg = new PdpMessage(orig);
+ newmsg.setRequestId(orig.getRequestId());
+ newmsg.setTimestampMs(orig.getTimestampMs());
+ assertEquals(orig.toString(), newmsg.toString());
}
}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java
index 8c843a1ac..55eaedc26 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java
@@ -23,6 +23,7 @@ package org.onap.policy.models.pdp.concepts;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
+import static org.onap.policy.models.pdp.concepts.PdpMessageUtils.removeVariableFields;
import org.junit.Test;
import org.onap.policy.models.pdp.enums.PdpState;
@@ -39,8 +40,7 @@ public class TestPdpStateChange {
PdpStateChange orig = new PdpStateChange();
// verify with null values
- assertEquals("PdpStateChange(name=null, state=null, pdpGroup=null, pdpSubgroup=null)",
- new PdpStateChange(orig).toString());
+ assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpStateChange(orig).toString()));
// verify with all values
orig.setName("my-name");
@@ -48,7 +48,6 @@ public class TestPdpStateChange {
orig.setPdpSubgroup("my-subgroup");
orig.setState(PdpState.SAFE);
- assertEquals("PdpStateChange(name=my-name, state=SAFE, pdpGroup=my-group, pdpSubgroup=my-subgroup)",
- new PdpStateChange(orig).toString());
+ assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpStateChange(orig).toString()));
}
}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java
index 2580ca829..c80745d76 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java
@@ -29,6 +29,8 @@ import java.util.Map;
import java.util.TreeMap;
import org.junit.Test;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
/**
* Test the copy constructor, as {@link TestModels} tests the other methods.
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java
index d2b571f34..b366088d1 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java
@@ -24,6 +24,7 @@ package org.onap.policy.models.pdp.concepts;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.onap.policy.models.pdp.concepts.PdpMessageUtils.removeVariableFields;
import java.util.Arrays;
import java.util.List;
@@ -42,15 +43,14 @@ public class TestPdpUpdate {
PdpUpdate orig = new PdpUpdate();
// verify with null values
- assertEquals("PdpUpdate(name=null, description=null, pdpGroup=null, pdpSubgroup=null, "
- + "pdpHeartbeatIntervalMs=0, policies=null)", new PdpUpdate(orig).toString());
+ assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpUpdate(orig).toString()));
// verify with all values
orig.setDescription("my-description");
orig.setName("my-name");
orig.setPdpGroup("my-group");
orig.setPdpSubgroup("my-subgroup");
- orig.setPdpHeartbeatIntervalMs(30000);
+ orig.setPdpHeartbeatIntervalMs(30000L);
ToscaPolicy policy1 = new ToscaPolicy();
policy1.setName("policy-a");
@@ -65,13 +65,7 @@ public class TestPdpUpdate {
PdpUpdate other = new PdpUpdate(orig);
- assertEquals("PdpUpdate(name=my-name, description=my-description, "
- + "pdpGroup=my-group, pdpSubgroup=my-subgroup, pdpHeartbeatIntervalMs=30000, policies=["
- + "ToscaPolicy(super=ToscaEntity(name=policy-a, version=1.2.3, derivedFrom=null, "
- + "metadata=null, description=null), type=null, typeVersion=null, properties=null), "
- + "ToscaPolicy(super=ToscaEntity(name=policy-b, version=4.5.6, derivedFrom=null, "
- + "metadata=null, description=null), type=null, typeVersion=null, properties=null)])",
- other.toString());
+ assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
// ensure list and items are not the same object
assertTrue(other.getPolicies() != policies);
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifierOptVersion.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifierOptVersion.java
deleted file mode 100644
index c4e9278eb..000000000
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifierOptVersion.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP Policy Models
- * ================================================================================
- * Copyright (C) 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.pdp.concepts;
-
-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.assertTrue;
-
-import org.junit.Test;
-
-/**
- * Test the other constructors, as {@link TestModels} tests the other methods.
- */
-public class TestToscaPolicyIdentifierOptVersion extends ToscaIdentifierTestBase<ToscaPolicyIdentifierOptVersion> {
- private static final String NAME = "my-name";
- private static final String VERSION = "1.2.3";
-
- public TestToscaPolicyIdentifierOptVersion() {
- super(ToscaPolicyIdentifierOptVersion.class);
- }
-
- @Test
- public void testAllArgsConstructor_testIsNullVersion() {
- assertThatThrownBy(() -> new ToscaPolicyIdentifierOptVersion(null, VERSION))
- .isInstanceOf(NullPointerException.class);
-
- // with null version
- ToscaPolicyIdentifierOptVersion orig = new ToscaPolicyIdentifierOptVersion(NAME, null);
- assertEquals(NAME, orig.getName());
- assertEquals(null, orig.getVersion());
- assertTrue(orig.isNullVersion());
-
- orig = new ToscaPolicyIdentifierOptVersion(NAME, VERSION);
- assertEquals(NAME, orig.getName());
- assertEquals(VERSION, orig.getVersion());
- assertFalse(orig.isNullVersion());
- }
-
- @Test
- public void testCopyConstructor() throws Exception {
- assertThatThrownBy(() -> new ToscaPolicyIdentifierOptVersion(null)).isInstanceOf(NullPointerException.class);
-
- ToscaPolicyIdentifierOptVersion orig = new ToscaPolicyIdentifierOptVersion();
-
- // verify with null values
- assertEquals(orig.toString(), new ToscaPolicyIdentifierOptVersion(orig).toString());
-
- // verify with all values
- orig = makeIdent(NAME, VERSION);
- assertEquals(orig.toString(), new ToscaPolicyIdentifierOptVersion(orig).toString());
- }
-}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyTypeIdentifier.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyTypeIdentifier.java
deleted file mode 100644
index ab314ef12..000000000
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyTypeIdentifier.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP Policy Models
- * ================================================================================
- * Copyright (C) 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.pdp.concepts;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-/**
- * Test the other constructors, as {@link TestModels} tests the other methods.
- */
-public class TestToscaPolicyTypeIdentifier extends ToscaIdentifierTestBase<ToscaPolicyTypeIdentifier> {
- private static final String NAME = "my-name";
- private static final String VERSION = "1.2.3";
-
- public TestToscaPolicyTypeIdentifier() {
- super(ToscaPolicyTypeIdentifier.class);
- }
-
- @Test
- public void testAllArgsConstructor() {
- assertThatThrownBy(() -> new ToscaPolicyTypeIdentifier(null, VERSION)).isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> new ToscaPolicyTypeIdentifier(NAME, null)).isInstanceOf(NullPointerException.class);
-
- ToscaPolicyTypeIdentifier orig = new ToscaPolicyTypeIdentifier(NAME, VERSION);
- assertEquals(NAME, orig.getName());
- assertEquals(VERSION, orig.getVersion());
- }
-
- @Test
- public void testCopyConstructor() {
- assertThatThrownBy(() -> new ToscaPolicyTypeIdentifier(null)).isInstanceOf(NullPointerException.class);
-
- ToscaPolicyTypeIdentifier orig = new ToscaPolicyTypeIdentifier();
-
- // verify with null values
- assertEquals(orig.toString(), new ToscaPolicyTypeIdentifier(orig).toString());
-
- // verify with all values
- orig = new ToscaPolicyTypeIdentifier(NAME, VERSION);
- assertEquals(orig.toString(), new ToscaPolicyTypeIdentifier(orig).toString());
- }
-
-}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ToscaIdentifierTestBase.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ToscaIdentifierTestBase.java
deleted file mode 100644
index 8b6a4f7bb..000000000
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ToscaIdentifierTestBase.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP Policy Models
- * ================================================================================
- * Copyright (C) 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.pdp.concepts;
-
-import org.onap.policy.common.utils.coder.Coder;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
-
-/**
- * Super class to test identity keys.
- *
- * @param <T> type of key being tested
- */
-public class ToscaIdentifierTestBase<T> {
-
- private static final Coder coder = new StandardCoder();
-
- private final Class<T> clazz;
-
-
- /**
- * Constructs the object.
- * @param clazz the type of class being tested
- */
- public ToscaIdentifierTestBase(Class<T> clazz) {
- this.clazz = clazz;
- }
-
- /**
- * Makes an identifier. Uses JSON which does no error checking.
- *
- * @param name name to put into the identifier
- * @param version version to put into the identifier
- * @return a new identifier
- * @throws CoderException if the JSON cannot be decoded
- */
- public T makeIdent(String name, String version) throws CoderException {
- StringBuilder bldr = new StringBuilder();
- bldr.append("{");
-
- if (name != null) {
- bldr.append("'name':'");
- bldr.append(name);
- bldr.append("'");
- }
-
- if (version != null) {
- if (name != null) {
- bldr.append(',');
- }
-
- bldr.append("'version':'");
- bldr.append(version);
- bldr.append("'");
- }
-
- bldr.append("}");
-
- String json = bldr.toString().replace('\'', '"');
-
- return coder.decode(json, clazz);
- }
-}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/persistence/provider/PdpProviderTest.java b/models-pdp/src/test/java/org/onap/policy/models/persistence/provider/PdpProviderTest.java
index fcb9062c6..6f20882f4 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/persistence/provider/PdpProviderTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/persistence/provider/PdpProviderTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@@ -24,10 +25,6 @@ import static org.junit.Assert.assertEquals;
import java.sql.Connection;
import java.sql.DriverManager;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -37,15 +34,9 @@ import org.onap.policy.models.dao.DaoParameters;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.dao.PfDaoFactory;
import org.onap.policy.models.dao.impl.DefaultPfDao;
-import org.onap.policy.models.pdp.concepts.Pdp;
-import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpGroups;
-import org.onap.policy.models.pdp.concepts.PdpSubGroup;
-import org.onap.policy.models.pdp.concepts.ToscaPolicyTypeIdentifier;
-import org.onap.policy.models.pdp.enums.PdpHealthStatus;
-import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.pdp.persistence.provider.PdpProvider;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
/**
* Test the {@link SimpleToscaProvider} class.
@@ -110,7 +101,6 @@ public class PdpProviderTest {
String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
- @SuppressWarnings("unchecked")
PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
PdpGroups createdPdpGroups0 = new PdpGroups();