From 44d88722bf59f9d39b54a1aac3f59def61133b29 Mon Sep 17 00:00:00 2001 From: ramverma Date: Wed, 3 Apr 2019 14:58:57 +0000 Subject: Changing PAP model as per discussion 1) Changing PAP models to use ToscaPolicyIdentifier instead of actual ToscaPolicy itself. 2) Deleting unused PdpHealthCheck message. As we decided to return heath check based on DB state. 3) Updating PdpStatus message to use ToscaPolicyIdentifier instead of actual ToscaPolicy itself. Pdp don't need to send the whole ToscaPolicy everytime in heartbeat to PAP. Instead the identifier is sufficient. Change-Id: I50ead8d8b6af118fd1da08071a2b0fc50584d4aa Issue-ID: POLICY-1443 Signed-off-by: ramverma --- .../policy/models/pdp/concepts/IdentTestBase.java | 81 ---------------------- .../models/pdp/concepts/TestPdpSubGroup.java | 24 ++++--- .../models/pdp/concepts/TestPolicyIdent.java | 62 ----------------- .../pdp/concepts/TestPolicyIdentOptVersion.java | 70 ------------------- .../models/pdp/concepts/TestPolicyTypeIdent.java | 63 ----------------- .../pdp/concepts/TestToscaPolicyIdentifier.java | 62 +++++++++++++++++ .../TestToscaPolicyIdentifierOptVersion.java | 71 +++++++++++++++++++ .../concepts/TestToscaPolicyTypeIdentifier.java | 63 +++++++++++++++++ .../pdp/concepts/ToscaIdentifierTestBase.java | 81 ++++++++++++++++++++++ .../persistence/provider/PdpProviderTest.java | 2 +- 10 files changed, 291 insertions(+), 288 deletions(-) delete mode 100644 models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/IdentTestBase.java delete mode 100644 models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdent.java delete mode 100644 models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdentOptVersion.java delete mode 100644 models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyTypeIdent.java create mode 100644 models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifier.java create mode 100644 models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifierOptVersion.java create mode 100644 models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyTypeIdentifier.java create mode 100644 models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ToscaIdentifierTestBase.java (limited to 'models-pdp/src/test') diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/IdentTestBase.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/IdentTestBase.java deleted file mode 100644 index 10bc9a997..000000000 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/IdentTestBase.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 type of key being tested - */ -public class IdentTestBase { - - private static final Coder coder = new StandardCoder(); - - private final Class clazz; - - - /** - * Constructs the object. - * @param clazz the type of class being tested - */ - public IdentTestBase(Class 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/pdp/concepts/TestPdpSubGroup.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java index eac2fb5d6..2580ca829 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 @@ -27,8 +27,8 @@ import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.Map; import java.util.TreeMap; + import org.junit.Test; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; /** * Test the copy constructor, as {@link TestModels} tests the other methods. @@ -39,7 +39,7 @@ public class TestPdpSubGroup { public void testCopyConstructor() { assertThatThrownBy(() -> new PdpSubGroup(null)).isInstanceOf(NullPointerException.class); - PdpSubGroup orig = new PdpSubGroup(); + final PdpSubGroup orig = new PdpSubGroup(); // verify with null values assertEquals( @@ -51,27 +51,29 @@ public class TestPdpSubGroup { orig.setCurrentInstanceCount(10); orig.setDesiredInstanceCount(11); - Pdp inst1 = new Pdp(); + final Pdp inst1 = new Pdp(); inst1.setInstanceId("my-id-A"); - Pdp inst2 = new Pdp(); + final Pdp inst2 = new Pdp(); inst2.setInstanceId("my-id-B"); orig.setPdpInstances(Arrays.asList(inst1, inst2)); orig.setPdpType("my-type"); - ToscaPolicy pol1 = new ToscaPolicy(); - pol1.setDescription("policy-A"); - ToscaPolicy pol2 = new ToscaPolicy(); - pol2.setDescription("policy-B"); + final ToscaPolicyIdentifier pol1 = new ToscaPolicyIdentifier(); + pol1.setName("policy-A"); + pol1.setVersion("1.0.0"); + final ToscaPolicyIdentifier pol2 = new ToscaPolicyIdentifier(); + pol2.setName("policy-B"); + pol1.setVersion("2.0.0"); orig.setPolicies(Arrays.asList(pol1, pol2)); - Map props = new TreeMap<>(); + final Map props = new TreeMap<>(); props.put("key-A", "value-A"); props.put("key-B", "value-B"); orig.setProperties(props); - PolicyTypeIdent supp1 = new PolicyTypeIdent("supp-A", "1.2"); - PolicyTypeIdent supp2 = new PolicyTypeIdent("supp-B", "3.4"); + final ToscaPolicyTypeIdentifier supp1 = new ToscaPolicyTypeIdentifier("supp-A", "1.2"); + final ToscaPolicyTypeIdentifier supp2 = new ToscaPolicyTypeIdentifier("supp-B", "3.4"); orig.setSupportedPolicyTypes(Arrays.asList(supp1, supp2)); assertEquals(orig.toString(), new PdpSubGroup(orig).toString()); diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdent.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdent.java deleted file mode 100644 index da942468a..000000000 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdent.java +++ /dev/null @@ -1,62 +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 TestPolicyIdent extends IdentTestBase { - private static final String NAME = "my-name"; - private static final String VERSION = "1.2.3"; - - public TestPolicyIdent() { - super(PolicyIdent.class); - } - - @Test - public void testAllArgsConstructor() { - assertThatThrownBy(() -> new PolicyIdent(null, VERSION)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> new PolicyIdent(NAME, null)).isInstanceOf(NullPointerException.class); - - PolicyIdent orig = new PolicyIdent(NAME, VERSION); - assertEquals(NAME, orig.getName()); - assertEquals(VERSION, orig.getVersion()); - } - - @Test - public void testCopyConstructor() { - assertThatThrownBy(() -> new PolicyIdent(null)).isInstanceOf(NullPointerException.class); - - PolicyIdent orig = new PolicyIdent(); - - // verify with null values - assertEquals(orig.toString(), new PolicyIdent(orig).toString()); - - // verify with all values - orig = new PolicyIdent(NAME, VERSION); - assertEquals(orig.toString(), new PolicyIdent(orig).toString()); - } -} diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdentOptVersion.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdentOptVersion.java deleted file mode 100644 index 6ae7ad32b..000000000 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdentOptVersion.java +++ /dev/null @@ -1,70 +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 TestPolicyIdentOptVersion extends IdentTestBase { - private static final String NAME = "my-name"; - private static final String VERSION = "1.2.3"; - - public TestPolicyIdentOptVersion() { - super(PolicyIdentOptVersion.class); - } - - @Test - public void testAllArgsConstructor_testIsNullVersion() { - assertThatThrownBy(() -> new PolicyIdentOptVersion(null, VERSION)).isInstanceOf(NullPointerException.class); - - // with null version - PolicyIdentOptVersion orig = new PolicyIdentOptVersion(NAME, null); - assertEquals(NAME, orig.getName()); - assertEquals(null, orig.getVersion()); - assertTrue(orig.isNullVersion()); - - orig = new PolicyIdentOptVersion(NAME, VERSION); - assertEquals(NAME, orig.getName()); - assertEquals(VERSION, orig.getVersion()); - assertFalse(orig.isNullVersion()); - } - - @Test - public void testCopyConstructor() throws Exception { - assertThatThrownBy(() -> new PolicyIdentOptVersion(null)).isInstanceOf(NullPointerException.class); - - PolicyIdentOptVersion orig = new PolicyIdentOptVersion(); - - // verify with null values - assertEquals(orig.toString(), new PolicyIdentOptVersion(orig).toString()); - - // verify with all values - orig = makeIdent(NAME, VERSION); - assertEquals(orig.toString(), new PolicyIdentOptVersion(orig).toString()); - } -} diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyTypeIdent.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyTypeIdent.java deleted file mode 100644 index 9247544fd..000000000 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyTypeIdent.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 TestPolicyTypeIdent extends IdentTestBase { - private static final String NAME = "my-name"; - private static final String VERSION = "1.2.3"; - - public TestPolicyTypeIdent() { - super(PolicyTypeIdent.class); - } - - @Test - public void testAllArgsConstructor() { - assertThatThrownBy(() -> new PolicyTypeIdent(null, VERSION)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> new PolicyTypeIdent(NAME, null)).isInstanceOf(NullPointerException.class); - - PolicyTypeIdent orig = new PolicyTypeIdent(NAME, VERSION); - assertEquals(NAME, orig.getName()); - assertEquals(VERSION, orig.getVersion()); - } - - @Test - public void testCopyConstructor() { - assertThatThrownBy(() -> new PolicyTypeIdent(null)).isInstanceOf(NullPointerException.class); - - PolicyTypeIdent orig = new PolicyTypeIdent(); - - // verify with null values - assertEquals(orig.toString(), new PolicyTypeIdent(orig).toString()); - - // verify with all values - orig = new PolicyTypeIdent(NAME, VERSION); - assertEquals(orig.toString(), new PolicyTypeIdent(orig).toString()); - } - -} 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/TestToscaPolicyIdentifier.java new file mode 100644 index 000000000..7a09e9d44 --- /dev/null +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifier.java @@ -0,0 +1,62 @@ +/* + * ============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 TestToscaPolicyIdentifier extends ToscaIdentifierTestBase { + 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()); + } + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new ToscaPolicyIdentifier(null)).isInstanceOf(NullPointerException.class); + + ToscaPolicyIdentifier orig = new ToscaPolicyIdentifier(); + + // verify with null values + assertEquals(orig.toString(), new ToscaPolicyIdentifier(orig).toString()); + + // verify with all values + orig = new ToscaPolicyIdentifier(NAME, VERSION); + assertEquals(orig.toString(), new ToscaPolicyIdentifier(orig).toString()); + } +} 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 new file mode 100644 index 000000000..c4e9278eb --- /dev/null +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifierOptVersion.java @@ -0,0 +1,71 @@ +/* + * ============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 { + 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 new file mode 100644 index 000000000..ab314ef12 --- /dev/null +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyTypeIdentifier.java @@ -0,0 +1,63 @@ +/* + * ============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 { + 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 new file mode 100644 index 000000000..8b6a4f7bb --- /dev/null +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ToscaIdentifierTestBase.java @@ -0,0 +1,81 @@ +/* + * ============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 type of key being tested + */ +public class ToscaIdentifierTestBase { + + private static final Coder coder = new StandardCoder(); + + private final Class clazz; + + + /** + * Constructs the object. + * @param clazz the type of class being tested + */ + public ToscaIdentifierTestBase(Class 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 14990f911..fcb9062c6 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 @@ -41,7 +41,7 @@ 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.PolicyTypeIdent; +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; -- cgit