diff options
Diffstat (limited to 'models-tosca/src/test')
9 files changed, 80 insertions, 573 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java index 858ac09fe..9ee3ec8bb 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java @@ -21,6 +21,7 @@ package org.onap.policy.models.tosca.authorative.concepts; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -62,12 +63,11 @@ public class ToscaPolicyFilterTest { "policies/vCPE.policy.monitoring.input.tosca.json", "policies/vCPE.policy.monitoring.input.tosca.yaml", "policies/vCPE.policy.operational.input.tosca.yaml", - "policies/vDNS.policy.guard.frequency.input.tosca.json", - "policies/vDNS.policy.guard.frequency.input.tosca.yaml", - "policies/vDNS.policy.guard.minmax.input.tosca.yaml", "policies/vDNS.policy.monitoring.input.tosca.json", "policies/vDNS.policy.monitoring.input.tosca.yaml", "policies/vDNS.policy.operational.input.tosca.yaml", + "policies/vDNS.policy.guard.frequencylimiter.input.tosca.yaml", + "policies/vDNS.policy.guard.minmaxvnfs.input.tosca.yaml", "policies/vFirewall.policy.monitoring.input.tosca.json", "policies/vFirewall.policy.monitoring.input.tosca.yaml", "policies/vFirewall.policy.operational.input.tosca.json", @@ -151,22 +151,67 @@ public class ToscaPolicyFilterTest { assertEquals(VERSION_100, filteredList.get(7).getVersion()); assertEquals(VERSION_100, filteredList.get(12).getVersion()); - assertEquals(23, policyList.size()); + assertEquals(22, policyList.size()); assertEquals(22, filteredList.size()); - policyList.get(10).setVersion("2.0.0"); - policyList.get(16).setVersion("3.4.5"); + // + // Change versions to a couple of policies + // + policyList.forEach(policy -> { + if ("onap.vfirewall.tca".equals(policy.getName())) { + policy.setVersion("2.0.0"); + } else if ("operational.modifyconfig".equals(policy.getName())) { + policy.setVersion("3.4.5"); + } + }); + // + // We'll still get back the same number of policies + // filteredList = filter.filter(policyList); assertEquals(22, filteredList.size()); - assertEquals("2.0.0", filteredList.get(12).getVersion()); - assertEquals("3.4.5", filteredList.get(14).getVersion()); - - policyList.get(10).setVersion(VERSION_100); - policyList.get(16).setVersion(VERSION_100); + // + // Assert that the correct versions are returned + // + policyList.forEach(policy -> { + if ("onap.vfirewall.tca".equals(policy.getName())) { + assertThat(policy.getVersion()).isEqualTo("2.0.0"); + } else if ("operational.modifyconfig".equals(policy.getName())) { + assertThat(policy.getVersion()).isEqualTo("3.4.5"); + } else if ("operational.scaleout".equals(policy.getName())) { + assertThat(policy.getVersion()).isEqualTo(VERSION_000); + } else { + assertThat(policy.getVersion()).isEqualTo(VERSION_100); + } + }); + + // + // Change versions back + // + policyList.forEach(policy -> { + if ("onap.vfirewall.tca".equals(policy.getName())) { + policy.setVersion(VERSION_100); + } else if ("operational.modifyconfig".equals(policy.getName())) { + policy.setVersion(VERSION_100); + } + }); + // + // We'll still get back the same number of policies + // filteredList = filter.filter(policyList); assertEquals(22, filteredList.size()); - assertEquals(VERSION_100, filteredList.get(12).getVersion()); - assertEquals(VERSION_100, filteredList.get(14).getVersion()); + // + // Assert that the correct versions are returned + // + policyList.forEach(policy -> { + // + // Should we fix this to be 1.0.0?? + // + if ("operational.scaleout".equals(policy.getName())) { + assertThat(policy.getVersion()).isEqualTo(VERSION_000); + } else { + assertThat(policy.getVersion()).isEqualTo(VERSION_100); + } + }); } @Test @@ -177,7 +222,7 @@ public class ToscaPolicyFilterTest { filter = ToscaPolicyFilter.builder().name("guard.frequency.scaleout").build(); filteredList = filter.filter(policyList); - assertEquals(2, filteredList.size()); + assertEquals(1, filteredList.size()); filter = ToscaPolicyFilter.builder().name("guard.frequency.scalein").build(); filteredList = filter.filter(policyList); @@ -193,7 +238,7 @@ public class ToscaPolicyFilterTest { filter = ToscaPolicyFilter.builder().name("operational.modifyconfig").version(VERSION_100).build(); filteredList = filter.filter(policyList); - assertEquals(0, filteredList.size()); + assertEquals(1, filteredList.size()); } @Test @@ -201,11 +246,11 @@ public class ToscaPolicyFilterTest { // null pattern ToscaPolicyFilter filter = ToscaPolicyFilter.builder().versionPrefix(null).build(); List<ToscaPolicy> filteredList = filter.filter(policyList); - assertEquals(23, filteredList.size()); + assertEquals(22, filteredList.size()); filter = ToscaPolicyFilter.builder().versionPrefix("1.").build(); filteredList = filter.filter(policyList); - assertEquals(21, filteredList.size()); + assertEquals(20, filteredList.size()); filter = ToscaPolicyFilter.builder().versionPrefix("100.").build(); filteredList = filter.filter(policyList); @@ -236,7 +281,7 @@ public class ToscaPolicyFilterTest { filter = ToscaPolicyFilter.builder().typeVersion(VERSION_000).build(); filteredList = filter.filter(policyList); - assertEquals(3, filteredList.size()); + assertEquals(0, filteredList.size()); filter = ToscaPolicyFilter.builder().type("onap.policies.optimization.resource.HpaPolicy") .typeVersion(VERSION_100).build(); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java index 0f038d3cd..6304091af 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java @@ -63,15 +63,15 @@ public class ToscaPolicyTypeFilterTest { "policytypes/onap.policies.optimization.resource.VnfPolicy.yaml", "policytypes/onap.policies.optimization.resource.PciPolicy.yaml", "policytypes/onap.policies.optimization.resource.OptimizationPolicy.yaml", - "policytypes/onap.policies.controlloop.guard.Blacklist.yaml", + "policytypes/onap.policies.controlloop.guard.common.Blacklist.yaml", "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml", "policytypes/onap.policies.optimization.resource.HpaPolicy.yaml", "policytypes/onap.policies.optimization.resource.Vim_fit.yaml", "policytypes/onap.policies.optimization.service.SubscriberPolicy.yaml", "policytypes/onap.policies.optimization.resource.AffinityPolicy.yaml", "policytypes/onap.policies.optimization.service.QueryPolicy.yaml", - "policytypes/onap.policies.controlloop.guard.MinMax.yaml", - "policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml", + "policytypes/onap.policies.controlloop.guard.common.MinMax.yaml", + "policytypes/onap.policies.controlloop.guard.common.FrequencyLimiter.yaml", "policytypes/onap.policies.controlloop.guard.coordination.FirstBlocksSecond.yaml", "policytypes/onap.policies.Optimization.yaml", "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml" @@ -149,8 +149,16 @@ public class ToscaPolicyTypeFilterTest { typeList.get(12).setVersion("2.0.0"); filteredList = filter.filter(typeList); assertEquals(20, filteredList.size()); - assertEquals("2.0.0", filteredList.get(11).getVersion()); - assertEquals(VERSION_100, filteredList.get(18).getVersion()); + // + // This seems to change around as to where this policy type + // got changed - perhaps we change this test to find a specific name + // to test for vs an index which never remains consistent? + // + assertEquals("2.0.0", filteredList.get(18).getVersion()); + // + // And now this index changes again?? + // + assertEquals(VERSION_100, filteredList.get(17).getVersion()); typeList.get(12).setVersion(VERSION_100); filteredList = filter.filter(typeList); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java deleted file mode 100644 index e06692ab0..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.legacy.concepts; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; -import org.onap.policy.models.tosca.legacy.concepts.testconcepts.DummyBadLegacyGuardPolicyContent; - -public class LegacyGuardPolicyTest { - - @Test - public void test() { - LegacyGuardPolicyInput guard = new LegacyGuardPolicyInput(); - assertNotNull(guard); - guard.setPolicyId("guard.frequency"); - assertEquals("guard.frequency", guard.getPolicyId()); - guard.setPolicyVersion("1"); - assertEquals("1", guard.getPolicyVersion()); - Map<String, String> body = new HashMap<>(); - body.put("actor", "SO"); - LegacyGuardPolicyContent content = new LegacyGuardPolicyContent(); - content.setActor("SO"); - guard.setContent(content); - assertEquals("SO", guard.getContent().getActor()); - - DummyBadLegacyGuardPolicyContent dblgpc = new DummyBadLegacyGuardPolicyContent(); - assertThatThrownBy(dblgpc::getAsPropertyMap).hasMessage("could not convert content to a property map"); - } -} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/testconcepts/DummyBadLegacyGuardPolicyContent.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/testconcepts/DummyBadLegacyGuardPolicyContent.java deleted file mode 100644 index 1b149416c..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/testconcepts/DummyBadLegacyGuardPolicyContent.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============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.models.tosca.legacy.concepts.testconcepts; - -import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyContent; - -/** - * Dummy {@link LegacyGuardPolicyContent} class to force exception for testing. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -public class DummyBadLegacyGuardPolicyContent extends LegacyGuardPolicyContent { - public static final String TO_TRIGGER_EXCEPTION = "Dummy"; - @SuppressWarnings("unused") - private final transient String aaa = "aaa"; -} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.java deleted file mode 100644 index 332552a73..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 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.models.tosca.legacy.mapping; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; - -import java.util.LinkedHashMap; -import java.util.Map; - -import org.junit.Test; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; - -/** - * Test the {@link LegacyGuardPolicyMapper} class. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -public class LegacyGuardPolicyMapperTest { - - @Test - public void testLegacyGuardPolicyMapper() { - JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); - serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); - serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); - - JpaToscaPolicy policy = new JpaToscaPolicy(new PfConceptKey("PolicyName", "2.0.0")); - serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policy.getKey(), policy); - - policy.setMetadata(null); - assertThatThrownBy(() -> { - new LegacyGuardPolicyMapper().fromToscaServiceTemplate(serviceTemplate); - }).hasMessageContaining("no metadata defined on TOSCA policy"); - - policy.setMetadata(new LinkedHashMap<>()); - policy.setProperties(null); - assertThatThrownBy(() -> { - new LegacyGuardPolicyMapper().fromToscaServiceTemplate(serviceTemplate); - }).hasMessageContaining("no properties defined on TOSCA policy"); - - policy.setProperties(new LinkedHashMap<>()); - Map<String, LegacyGuardPolicyOutput> guardPolicyMap = - new LegacyGuardPolicyMapper().fromToscaServiceTemplate(serviceTemplate); - LegacyGuardPolicyOutput guardPolicy = guardPolicyMap.values().iterator().next(); - assertEquals("2.0.0", guardPolicy.getVersion()); - } -} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java deleted file mode 100644 index 047ef4891..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java +++ /dev/null @@ -1,388 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 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. - * 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.models.tosca.legacy.provider; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.Map; -import java.util.Properties; - -import org.eclipse.persistence.config.PersistenceUnitProperties; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.base.PfModelException; -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.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider; -import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyContent; -import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; -import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; -import org.yaml.snakeyaml.Yaml; - -/** - * Test the {@link LegacyProvider} class for legacy guard policies. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -public class LegacyProvider4LegacyGuardTest { - private static final String POLICY_ID_IS_NULL = "^policyId is marked .*on.*ull but is null$"; - private static final String VDNS_OUTPUT_JSON = "policies/vDNS.policy.guard.frequency.output.json"; - private static final String VDNS_INPUT_JSON = "policies/vDNS.policy.guard.frequency.input.json"; - private static final String LEGACY_POLICY_IS_NULL = "^legacyGuardPolicy is marked .*on.*ull but is null$"; - private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$"; - private PfDao pfDao; - private StandardCoder standardCoder; - - /** - * Set up the DAO towards the database. - * - * @throws Exception on database errors - */ - @Before - public void setupDao() throws Exception { - final DaoParameters daoParameters = new DaoParameters(); - daoParameters.setPluginClass(DefaultPfDao.class.getName()); - - daoParameters.setPersistenceUnit("ToscaConceptTest"); - - Properties jdbcProperties = new Properties(); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER, "policy"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, "P01icY"); - - // H2, use "org.mariadb.jdbc.Driver" and "jdbc:mariadb://localhost:3306/policy" for locally installed MariaDB - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:testdb"); - - daoParameters.setJdbcProperties(jdbcProperties); - - pfDao = new PfDaoFactory().createPfDao(daoParameters); - pfDao.init(daoParameters); - } - - /** - * Set up standard coder. - */ - @Before - public void setupStandardCoder() { - standardCoder = new StandardCoder(); - } - - @After - public void teardown() { - pfDao.close(); - } - - @Test - public void testPoliciesGet() throws Exception { - assertThatThrownBy(() -> { - new LegacyProvider().getGuardPolicy(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().getGuardPolicy(null, null, ""); - }).hasMessageMatching(DAO_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().getGuardPolicy(pfDao, null, null); - }).hasMessageMatching(POLICY_ID_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().getGuardPolicy(pfDao, "I Dont Exist", null); - }).hasMessage("no policy found for policy: I Dont Exist:null"); - - createPolicyTypes(); - - LegacyGuardPolicyInput originalGip = - standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class); - - assertNotNull(originalGip); - - Map<String, LegacyGuardPolicyOutput> createdGopm = new LegacyProvider().createGuardPolicy(pfDao, originalGip); - - assertEquals(originalGip.getPolicyId(), createdGopm.keySet().iterator().next()); - assertEquals(originalGip.getContent(), - createdGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - - Map<String, LegacyGuardPolicyOutput> gotGopm = - new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), null); - - assertEquals(originalGip.getPolicyId(), gotGopm.keySet().iterator().next()); - assertEquals(originalGip.getContent(), - gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - - String expectedJsonOutput = ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON); - String actualJsonOutput = standardCoder.encode(gotGopm); - - assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", "")); - - gotGopm = new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), "1"); - - assertEquals(originalGip.getPolicyId(), gotGopm.keySet().iterator().next()); - assertEquals(originalGip.getContent(), - gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - - actualJsonOutput = standardCoder.encode(gotGopm); - - assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", "")); - - assertThatThrownBy(() -> { - new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), "2"); - }).hasMessage("no policy found for policy: guard.frequency.scaleout:2"); - } - - @Test - public void testPolicyCreate() throws Exception { - assertThatThrownBy(() -> { - new LegacyProvider().createGuardPolicy(null, null); - }).hasMessageMatching(DAO_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().createGuardPolicy(null, new LegacyGuardPolicyInput()); - }).hasMessageMatching(DAO_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().createGuardPolicy(pfDao, null); - }).hasMessageMatching(LEGACY_POLICY_IS_NULL); - - createPolicyTypes(); - - LegacyGuardPolicyInput originalGip = - standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class); - - assertNotNull(originalGip); - - Map<String, LegacyGuardPolicyOutput> createdGopm = new LegacyProvider().createGuardPolicy(pfDao, originalGip); - - assertEquals(originalGip.getPolicyId(), createdGopm.keySet().iterator().next()); - assertEquals(originalGip.getContent(), - createdGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - - Map<String, LegacyGuardPolicyOutput> gotGopm = - new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), null); - - assertEquals(originalGip.getPolicyId(), gotGopm.keySet().iterator().next()); - assertEquals(originalGip.getContent(), - gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - - String expectedJsonOutput = ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON); - String actualJsonOutput = standardCoder.encode(gotGopm); - - assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", "")); - } - - @Test - public void testPolicyCreateBad() throws Exception { - assertThatThrownBy(() -> { - new LegacyProvider().createGuardPolicy(null, null); - }).hasMessageMatching(DAO_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().createGuardPolicy(null, new LegacyGuardPolicyInput()); - }).hasMessageMatching(DAO_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().createGuardPolicy(pfDao, null); - }).hasMessageMatching(LEGACY_POLICY_IS_NULL); - - createPolicyTypes(); - - LegacyGuardPolicyInput originalGip = - standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class); - - assertNotNull(originalGip); - - originalGip.setPolicyId("i.do.not.exist"); - - assertThatThrownBy(() -> { - new LegacyProvider().createGuardPolicy(pfDao, originalGip); - }).hasMessage("policy type for guard policy \"i.do.not.exist\" unknown"); - } - - @Test - public void testPolicyUpdate() throws Exception { - assertThatThrownBy(() -> { - new LegacyProvider().updateGuardPolicy(null, null); - }).hasMessageMatching(DAO_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().updateGuardPolicy(null, new LegacyGuardPolicyInput()); - }).hasMessageMatching(DAO_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().updateGuardPolicy(pfDao, null); - }).hasMessageMatching(LEGACY_POLICY_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().updateGuardPolicy(pfDao, new LegacyGuardPolicyInput()); - }).hasMessage("policy type for guard policy \"null\" unknown"); - - createPolicyTypes(); - - LegacyGuardPolicyInput originalGip = - standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class); - - assertNotNull(originalGip); - - Map<String, LegacyGuardPolicyOutput> createdGopm = new LegacyProvider().createGuardPolicy(pfDao, originalGip); - assertEquals(originalGip.getPolicyId(), createdGopm.keySet().iterator().next()); - assertEquals(originalGip.getContent(), - createdGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - - Map<String, LegacyGuardPolicyOutput> gotGopm = - new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), null); - - assertEquals(originalGip.getPolicyId(), gotGopm.keySet().iterator().next()); - assertEquals(originalGip.getContent(), - gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - - originalGip.getContent().setRecipe("Roast Turkey"); - Map<String, LegacyGuardPolicyOutput> updatedGp = new LegacyProvider().updateGuardPolicy(pfDao, originalGip); - assertEquals(originalGip.getPolicyId(), updatedGp.keySet().iterator().next()); - assertEquals(originalGip.getContent(), - updatedGp.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - - Map<String, LegacyGuardPolicyOutput> gotUpdatedGopm = - new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), null); - assertEquals(originalGip.getPolicyId(), gotUpdatedGopm.keySet().iterator().next()); - assertEquals(originalGip.getContent(), - gotUpdatedGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - assertEquals("Roast Turkey", - gotUpdatedGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next().getRecipe()); - } - - @Test - public void testPoliciesDelete() throws Exception { - assertThatThrownBy(() -> { - new LegacyProvider().deleteGuardPolicy(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().deleteGuardPolicy(null, null, ""); - }).hasMessageMatching(DAO_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().deleteGuardPolicy(null, "", null); - }).hasMessageMatching(DAO_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().deleteGuardPolicy(null, "", ""); - }).hasMessageMatching(DAO_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().deleteGuardPolicy(pfDao, null, null); - }).hasMessageMatching(POLICY_ID_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().deleteGuardPolicy(pfDao, null, ""); - }).hasMessageMatching(POLICY_ID_IS_NULL); - - assertThatThrownBy(() -> { - new LegacyProvider().deleteGuardPolicy(pfDao, "", null); - }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$"); - - assertThatThrownBy(() -> { - new LegacyProvider().deleteGuardPolicy(pfDao, "IDontExist", "0"); - }).hasMessage("no policy found for policy: IDontExist:0"); - - createPolicyTypes(); - - LegacyGuardPolicyInput originalGip = - standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class); - - assertNotNull(originalGip); - - Map<String, LegacyGuardPolicyOutput> createdGopm = new LegacyProvider().createGuardPolicy(pfDao, originalGip); - assertEquals(originalGip.getPolicyId(), createdGopm.keySet().iterator().next()); - assertEquals(originalGip.getContent(), - createdGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - - Map<String, LegacyGuardPolicyOutput> gotGopm = - new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), null); - - assertEquals(originalGip.getPolicyId(), gotGopm.keySet().iterator().next()); - assertEquals(originalGip.getContent(), - gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - - String expectedJsonOutput = ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON); - String actualJsonOutput = standardCoder.encode(gotGopm); - - assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", "")); - - assertThatThrownBy(() -> { - new LegacyProvider().deleteGuardPolicy(pfDao, originalGip.getPolicyId(), null); - }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$"); - - Map<String, LegacyGuardPolicyOutput> deletedGopm = - new LegacyProvider().deleteGuardPolicy(pfDao, originalGip.getPolicyId(), "1"); - assertEquals(originalGip.getPolicyId(), deletedGopm.keySet().iterator().next()); - assertEquals(originalGip.getContent(), - deletedGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - - assertThatThrownBy(() -> { - new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), null); - }).hasMessage("no policy found for policy: guard.frequency.scaleout:null"); - - LegacyGuardPolicyInput otherGip = new LegacyGuardPolicyInput(); - otherGip.setPolicyId("guard.blacklist.b0"); - otherGip.setPolicyVersion("1"); - otherGip.setContent(new LegacyGuardPolicyContent()); - - Map<String, LegacyGuardPolicyOutput> createdOtherGopm = new LegacyProvider().createGuardPolicy(pfDao, otherGip); - assertEquals(otherGip.getPolicyId(), createdOtherGopm.keySet().iterator().next()); - assertEquals(otherGip.getContent(), - createdOtherGopm.get(otherGip.getPolicyId()).getProperties().values().iterator().next()); - - assertThatThrownBy(() -> { - new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), null); - }).hasMessage("no policy found for policy: guard.frequency.scaleout:null"); - } - - private void createPolicyTypes() throws CoderException, PfModelException { - Object yamlObject = new Yaml().load( - ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml")); - String yamlAsJsonString = new StandardCoder().encode(yamlObject); - - ToscaServiceTemplate toscaServiceTemplatePolicyType = - standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); - - assertNotNull(toscaServiceTemplatePolicyType); - new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType); - - yamlObject = new Yaml() - .load(ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.Blacklist.yaml")); - yamlAsJsonString = new StandardCoder().encode(yamlObject); - - toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); - - assertNotNull(toscaServiceTemplatePolicyType); - new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType); - } -} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java index 500ba9fa2..318eaeede 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java @@ -57,7 +57,7 @@ public class MonitoringPolicySerializationTest { private static final String VERSION = "version"; - private static final String YAML_VERSION = "tosca_simple_yaml_1_0_0"; + private static final String YAML_VERSION = "tosca_simple_yaml_1_1_0"; private static final String DEFINITION_VERSION = "tosca_definitions_version"; diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java index ef4123084..bf2030bd4 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java @@ -145,7 +145,7 @@ public class MonitoringPolicyTypeSerializationTest { assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid()); // Check tosca_definitions_version - assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion()); + assertEquals("tosca_simple_yaml_1_1_0", serviceTemplate.getToscaDefinitionsVersion()); // Check policy_types Map<PfConceptKey, JpaToscaPolicyType> policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap(); @@ -362,7 +362,7 @@ public class MonitoringPolicyTypeSerializationTest { assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid()); // Check tosca_definitions_version - assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion()); + assertEquals("tosca_simple_yaml_1_1_0", serviceTemplate.getToscaDefinitionsVersion()); // Check policy_types Map<PfConceptKey, JpaToscaPolicyType> policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap(); diff --git a/models-tosca/src/test/resources/onap.policies.NoVersion.yaml b/models-tosca/src/test/resources/onap.policies.NoVersion.yaml index 2dda556a6..c8562dad0 100644 --- a/models-tosca/src/test/resources/onap.policies.NoVersion.yaml +++ b/models-tosca/src/test/resources/onap.policies.NoVersion.yaml @@ -1,4 +1,4 @@ -tosca_definitions_version: tosca_simple_yaml_1_0_0 +tosca_definitions_version: tosca_simple_yaml_1_1_0 policy_types: onap.policies.Optimization: derived_from: tosca.policies.Root |