diff options
Diffstat (limited to 'plugins/reception-plugins/src/test/java/org')
2 files changed, 93 insertions, 19 deletions
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java index 0585b23a..21593868 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java @@ -25,6 +25,8 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.Collection; + +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.common.parameters.ParameterGroup; @@ -46,23 +48,31 @@ public class TestPolicyDecoderCsarPdpx { */ @BeforeClass public static void setUp() { - ParameterGroup parameterGroup = new PolicyDecoderCsarPdpxConfigurationParameterBuilder().setOnapName("onapName") - .setPolicyNamePrefix("OOF").setPriority("5").setRiskLevel("2").setRiskType("Test").setVersion("1.0") - .build(); + final ParameterGroup parameterGroup = new PolicyDecoderCsarPdpxConfigurationParameterBuilder() + .setOnapName("onapName").setPolicyNamePrefix("OOF").setPriority("5").setRiskLevel("2") + .setRiskType("Test").setVersion("1.0").build(); parameterGroup.setName(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION); ParameterService.register(parameterGroup); } + /** + * Tear down. + */ + @AfterClass + public static void tearDown() { + ParameterService.deregister(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION); + } + @Test public void testHpaPolicy2Vnf() throws IOException, PolicyDecodingException { - Csar csar = new Csar("src/test/resources/service-TestNs8-csar.csar"); - PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); + final Csar csar = new Csar("src/test/resources/service-TestNs8-csar.csar"); + final PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); policyDecoderCsarPdpx.configure(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION); - Collection<OptimizationPolicy> ret = policyDecoderCsarPdpx.decode(csar); + final Collection<OptimizationPolicy> ret = policyDecoderCsarPdpx.decode(csar); assertEquals(2, ret.size()); - OptimizationPolicy policy = (OptimizationPolicy) ret.toArray()[0]; + final OptimizationPolicy policy = (OptimizationPolicy) ret.toArray()[0]; assertEquals("onapName", policy.getOnapName()); assertTrue(policy.getPolicyName().startsWith("OOF.")); @@ -86,12 +96,12 @@ public class TestPolicyDecoderCsarPdpx { @Test public void testHpaPolicySriov() throws IOException, PolicyDecodingException { - Csar csar = new Csar("src/test/resources/hpaPolicySriov.csar"); - PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); + final Csar csar = new Csar("src/test/resources/hpaPolicySriov.csar"); + final PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); policyDecoderCsarPdpx.configure(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION); - Collection<OptimizationPolicy> policies = policyDecoderCsarPdpx.decode(csar); - OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0]; + final Collection<OptimizationPolicy> policies = policyDecoderCsarPdpx.decode(csar); + final OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0]; assertEquals("onapName", policy.getOnapName()); assertTrue(policy.getPolicyName().startsWith("OOF.")); @@ -126,13 +136,13 @@ public class TestPolicyDecoderCsarPdpx { @Test public void testHpaPolicyPciePassthrough() throws IOException, PolicyDecodingException { - Csar csar = new Csar("src/test/resources/hpaPolicyPciePassthrough.csar"); - PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); + final Csar csar = new Csar("src/test/resources/hpaPolicyPciePassthrough.csar"); + final PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); policyDecoderCsarPdpx.configure(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION); - Collection<OptimizationPolicy> policies = policyDecoderCsarPdpx.decode(csar); + final Collection<OptimizationPolicy> policies = policyDecoderCsarPdpx.decode(csar); assertEquals(2, policies.size()); - OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0]; + final OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0]; assertEquals("onapName", policy.getOnapName()); assertTrue(policy.getPolicyName().startsWith("OOF.")); @@ -169,13 +179,13 @@ public class TestPolicyDecoderCsarPdpx { @Test public void testHpaPolicyHugePage() throws IOException, PolicyDecodingException { - Csar csar = new Csar("src/test/resources/hpaPolicyHugePage.csar"); - PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); + final Csar csar = new Csar("src/test/resources/hpaPolicyHugePage.csar"); + final PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); policyDecoderCsarPdpx.configure(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION); - Collection<OptimizationPolicy> policies = policyDecoderCsarPdpx.decode(csar); + final Collection<OptimizationPolicy> policies = policyDecoderCsarPdpx.decode(csar); assertEquals(2, policies.size()); - OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0]; + final OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0]; assertEquals("onapName", policy.getOnapName()); assertTrue(policy.getPolicyName().startsWith("OOF.")); diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxConfigurationParameterGroup.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxConfigurationParameterGroup.java new file mode 100644 index 00000000..bebb8459 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxConfigurationParameterGroup.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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.distribution.reception.decoding.pdpx; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.common.parameters.ValidationStatus; + +/** + * Class to perform unit test of {@link PolicyDecoderCsarPdpxConfigurationParameterGroup}. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class TestPolicyDecoderCsarPdpxConfigurationParameterGroup { + + private static final String OPTIMIZATION_POLICY_CONFIGURATION = "optimizationPolicyConfiguration"; + + @Test + public void testBuilderAndGetters() { + final PolicyDecoderCsarPdpxConfigurationParameterGroup parameterGroup = + new PolicyDecoderCsarPdpxConfigurationParameterBuilder().setOnapName("onapName") + .setPolicyNamePrefix("OOF").setPriority("5").setRiskLevel("2").setRiskType("Test") + .setVersion("1.0").build(); + parameterGroup.setName(OPTIMIZATION_POLICY_CONFIGURATION); + + assertEquals(OPTIMIZATION_POLICY_CONFIGURATION, parameterGroup.getName()); + assertEquals("onapName", parameterGroup.getOnapName()); + assertEquals("OOF", parameterGroup.getPolicyNamePrefix()); + assertEquals("5", parameterGroup.getPriority()); + assertEquals("2", parameterGroup.getRiskLevel()); + assertEquals("Test", parameterGroup.getRiskType()); + assertEquals("1.0", parameterGroup.getVersion()); + assertEquals(ValidationStatus.CLEAN, parameterGroup.validate().getStatus()); + } + + @Test + public void testInvalidParameters() { + final PolicyDecoderCsarPdpxConfigurationParameterGroup parameterGroup = + new PolicyDecoderCsarPdpxConfigurationParameterBuilder().setOnapName("").setPolicyNamePrefix("") + .setPriority("").setRiskLevel("").setRiskType("").setVersion("").build(); + parameterGroup.setName(OPTIMIZATION_POLICY_CONFIGURATION); + + assertEquals(ValidationStatus.INVALID, parameterGroup.validate().getStatus()); + } +} |