diff options
author | Liam Fallon <liam.fallon@ericsson.com> | 2018-09-12 19:39:59 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-09-12 19:39:59 +0000 |
commit | 31def9f82514182e6761fac5ecae70333155aabc (patch) | |
tree | 6810d78353eae9a2c9f7249656c92fb3162249f8 /plugins/reception-plugins/src/test/java/org | |
parent | e52c9ed74a40d86f1494befd89f55f499b28dcfe (diff) | |
parent | 571b40bd86ffeb24f707539f3fe535ff1b2e2ebc (diff) |
Merge "Adding code for dynamically generate Polices"
Diffstat (limited to 'plugins/reception-plugins/src/test/java/org')
7 files changed, 420 insertions, 0 deletions
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestAttribute.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestAttribute.java new file mode 100644 index 00000000..f11a7ecd --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestAttribute.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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; + +/** + * Class to perform unit test for Attribute 0f {@link Attribute}. + * + */ +public class TestAttribute { + + @Test + public void testAttribute() { + final String attributeName = "dummyName"; + final String attributeValue = "dummyValue"; + + final Attribute attribute = new Attribute(); + attribute.setAttributeName(attributeName); + attribute.setAttributeValue(attributeValue); + + validateReport(attributeName,attributeValue,attribute); + } + + private void validateReport(final String name, final String value, final Attribute attribute) { + assertEquals(name, attribute.getAttributeName()); + assertEquals(value, attribute.getAttributeValue()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestContent.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestContent.java new file mode 100644 index 00000000..a329a3ee --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestContent.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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; + +/** + * Class to perform unit test for Content 0f {@link Content}. + * + */ +public class TestContent { + + @Test + public void testContent() { + final String resources = "dummyresource"; + final String identity = "dummyidentity"; + final String policyType = "optimization"; + + final Content content = new Content(); + content.setResources(resources); + content.setIdentity(identity); + content.setPolicyType(policyType); + + validateReport(resources, identity, policyType,content); + } + + private void validateReport(final String resources, final String identity, final String policyType, + final Content content) { + assertEquals(resources, content.getResources()); + assertEquals(identity, content.getIdentity()); + assertEquals(policyType, content.getPolicyType()); + assertEquals(0, content.getPolicyScope().size()); + content.getPolicyScope().add("vFW"); + assertEquals(1, content.getPolicyScope().size()); + content.getPolicyScope().remove("vFW"); + assertEquals(0, content.getPolicyScope().size()); + assertEquals(0, content.getFlavorFeatures().size()); + FlavorFeature flavorFeature = new FlavorFeature(); + content.getFlavorFeatures().add(flavorFeature); + assertEquals(1, content.getFlavorFeatures().size()); + content.getFlavorFeatures().remove(flavorFeature); + assertEquals(0, content.getFlavorFeatures().size()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestDirective.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestDirective.java new file mode 100644 index 00000000..48d11d32 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestDirective.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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; + +/** + * Class to perform unit test for Directive 0f {@link Directive}. + * + */ +public class TestDirective { + + @Test + public void testDirective() { + final String type = "dummytype"; + + final Directive directive = new Directive(); + directive.setType(type); + + validateReport(type,directive); + } + + private void validateReport(final String type, final Directive directive) { + assertEquals(type, directive.getType()); + assertEquals(0, directive.getAttributes().size()); + Attribute attribute = new Attribute(); + directive.getAttributes().add(attribute); + assertEquals(1, directive.getAttributes().size()); + directive.getAttributes().remove(attribute); + assertEquals(0, directive.getAttributes().size()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorFeature.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorFeature.java new file mode 100644 index 00000000..47b4e343 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorFeature.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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; + +/** + * Class to perform unit test for FlavorFeature 0f {@link FlavorFeature}. + * + */ +public class TestFlavorFeature { + + @Test + public void testFlavorFeature() { + final String id = "dummyid"; + final String type = "dummytype"; + + final FlavorFeature flavorFeature = new FlavorFeature(); + flavorFeature.setId(id); + flavorFeature.setType(type); + + validateReport(id,type,flavorFeature); + } + + private void validateReport(final String id, final String type, final FlavorFeature flavorFeature) { + assertEquals(id, flavorFeature.getId()); + assertEquals(type, flavorFeature.getType()); + + assertEquals(0, flavorFeature.getDirectives().size()); + Directive directive = new Directive(); + flavorFeature.getDirectives().add(directive); + assertEquals(1, flavorFeature.getDirectives().size()); + flavorFeature.getDirectives().remove(directive); + assertEquals(0, flavorFeature.getDirectives().size()); + + assertEquals(0, flavorFeature.getFlavorProperties().size()); + FlavorProperty flavorProperty = new FlavorProperty(); + flavorFeature.getFlavorProperties().add(flavorProperty); + assertEquals(1, flavorFeature.getFlavorProperties().size()); + flavorFeature.getFlavorProperties().remove(flavorProperty); + assertEquals(0, flavorFeature.getFlavorProperties().size()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorProperty.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorProperty.java new file mode 100644 index 00000000..b5a535d7 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorProperty.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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; + +/** + * Class to perform unit test for FlavorProperty 0f {@link FlavorProperty}. + * + */ +public class TestFlavorProperty { + + @Test + public void testFlavorProperty() { + final String hpaFeature = "dummyid"; + final String mandatory = "false"; + final String architecture = "generic"; + final String hpaVersion = "v1"; + + final FlavorProperty flavorProperty = new FlavorProperty(); + flavorProperty.setHpaFeature(hpaFeature); + flavorProperty.setMandatory(mandatory); + flavorProperty.setArchitecture(architecture); + flavorProperty.setHpaVersion(hpaVersion); + + validateReport(hpaFeature,mandatory,architecture,hpaVersion,flavorProperty); + } + + private void validateReport(final String hpaFeature, final String mandatory, final String architecture, + final String hpaVersion, final FlavorProperty flavorProperty) { + assertEquals(hpaFeature, flavorProperty.getHpaFeature()); + assertEquals(mandatory, flavorProperty.getMandatory()); + assertEquals(architecture, flavorProperty.getArchitecture()); + assertEquals(hpaVersion, flavorProperty.getHpaVersion()); + + assertEquals(0, flavorProperty.getDirectives().size()); + Directive directive = new Directive(); + flavorProperty.getDirectives().add(directive); + assertEquals(1, flavorProperty.getDirectives().size()); + flavorProperty.getDirectives().remove(directive); + assertEquals(0, flavorProperty.getDirectives().size()); + + assertEquals(0, flavorProperty.getHpaFeatureAttributes().size()); + HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute(); + flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); + assertEquals(1, flavorProperty.getHpaFeatureAttributes().size()); + flavorProperty.getHpaFeatureAttributes().remove(hpaFeatureAttribute); + assertEquals(0, flavorProperty.getHpaFeatureAttributes().size()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestHpaFeatureAttribute.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestHpaFeatureAttribute.java new file mode 100644 index 00000000..40c30eb7 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestHpaFeatureAttribute.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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; + +/** + * Class to perform unit test for HpaFeatureAttribute 0f {@link HpaFeatureAttribute}. + * + */ +public class TestHpaFeatureAttribute { + + @Test + public void testHpaFeatureAttribute() { + final String hpaAttributeKey = "dummykey"; + final String hpaAttributeValue = "4096"; + final String operator = ">="; + final String unit = "MB"; + + final HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute(); + hpaFeatureAttribute.setHpaAttributeKey(hpaAttributeKey); + hpaFeatureAttribute.setHpaAttributeValue(hpaAttributeValue); + hpaFeatureAttribute.setOperator(operator); + hpaFeatureAttribute.setUnit(unit); + + validateReport(hpaAttributeKey,hpaAttributeValue,operator,unit,hpaFeatureAttribute); + } + + private void validateReport(final String hpaAttributeKey, final String hpaAttributeValue, final String operator, + final String unit, final HpaFeatureAttribute hpaFeatureAttribute) { + assertEquals(hpaAttributeKey, hpaFeatureAttribute.getHpaAttributeKey()); + assertEquals(hpaAttributeValue, hpaFeatureAttribute.getHpaAttributeValue()); + assertEquals(operator, hpaFeatureAttribute.getOperator()); + assertEquals(unit, hpaFeatureAttribute.getUnit()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestPolicyDecoderCsarPdpx.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestPolicyDecoderCsarPdpx.java new file mode 100644 index 00000000..1ce5786c --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestPolicyDecoderCsarPdpx.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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 static org.junit.Assert.fail; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import java.io.IOException; +import java.util.Collection; + +import org.junit.Test; +import org.onap.policy.distribution.model.Csar; + +/** + * Class to perform unit test of {@link PolicyDecoderCsarPdpx}. + * + */ +public class TestPolicyDecoderCsarPdpx { + + @Test + public void testHpaPolicy2Vnf() throws IOException { + Csar csar = new Csar("src/test/resources/service-TestNs8-csar.csar"); + + PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); + try { + Collection<PdpxPolicy> ret = policyDecoderCsarPdpx.decode(csar); + assertEquals(2, ret.size()); + } catch (Exception e) { + fail("test should not thrown an exception here: " + e.getMessage()); + } + } + + @Test + public void testHpaPolicyFeature() throws IOException { + Csar csar = new Csar("src/test/resources/hpaPolicySRIOV.csar"); + + PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); + try { + Collection<PdpxPolicy> ret = policyDecoderCsarPdpx.decode(csar); + assertEquals(2, ret.size()); + } catch (Exception e) { + fail("test should not thrown an exception here: " + e.getMessage()); + } + } +} |