From 9fb3368b89745ceb95d7be61f685dbd36dfd9729 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Thu, 24 Oct 2019 12:42:38 -0400 Subject: Fix sonar and coverage Turns out cyclomatic complexity is there in one method. The other JUnits in the applications cover the rest of the class, when time permits I will add that in there for completeness. Issue-ID: POLICY-2066 Change-Id: I31fd43625883bd569d4078bbd684554f6f3fbf53 Signed-off-by: Pamela Dragosh --- .../common/std/StdBaseTranslatorTest.java | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java (limited to 'applications/common/src/test') diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java new file mode 100644 index 00000000..0b3ce6c3 --- /dev/null +++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * 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.pdp.xacml.application.common.std; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.HashMap; +import java.util.Map; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import org.junit.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException; + +public class StdBaseTranslatorTest { + + @Test + public void test() { + StdBaseTranslator translator = new StdBaseTranslator(); + assertNotNull(translator); + assertThatThrownBy(() -> translator.convertPolicy(null)).isInstanceOf(ToscaPolicyConversionException.class); + assertNull(translator.convertRequest(null)); + } + + @Test + public void testBadData() throws ToscaPolicyConversionException { + TestTranslator translator = new TestTranslator(); + + assertThatThrownBy(() -> translator.convertPolicy( + new ToscaPolicy())).isInstanceOf(ToscaPolicyConversionException.class) + .hasMessageContaining("missing metadata"); + + translator.metadata.put(StdBaseTranslator.POLICY_ID, "random.policy.id"); + + assertThatThrownBy(() -> translator.convertPolicy( + new ToscaPolicy())).isInstanceOf(ToscaPolicyConversionException.class) + .hasMessageContaining("missing metadata"); + + translator.metadata.put(StdBaseTranslator.POLICY_VERSION, "1.0.0"); + + ToscaPolicy policy = new ToscaPolicy(); + assertEquals("1.0.0", translator.convertPolicy(policy).getVersion()); + + } + + public class TestTranslator extends StdBaseTranslator { + public Map metadata = new HashMap<>(); + + @Override + public PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException { + PolicyType xacmlPolicy = new PolicyType(); + this.fillMetadataSection(xacmlPolicy, metadata); + return xacmlPolicy; + } + } + +} -- cgit 1.2.3-korg