From dffa54c9a27bcd9524e2aa75684ff02d70507b59 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Thu, 26 Mar 2020 10:03:11 -0400 Subject: Remove unused imports and clean logs Unused imports and marked an unused variable. Added m2e eclipse settings (other repos have this). Added some test logback.xml to clear out jetty debug messages. Replaced deprecated newInstance with getDeclaredConstructor. newInstance Either log or throw Exception - chose throw Added some assertions to JUnit test. Issue-ID: POLICY-2305 Change-Id: Ia4e9ce62dc7fb45aea247d470ca7245e694fc26e Signed-off-by: Pamela Dragosh --- .../forwarding/file/FilePolicyForwarder.java | 2 +- .../lifecycle/api/LifecycleApiPolicyForwarder.java | 5 ++- .../api/LifecycleApiPolicyForwarderTest.java | 24 +++++++------ .../src/test/resources/logback-test.xml | 41 ++++++++++++++++++++++ .../decoding/hpa/PolicyDecoderCsarHpa.java | 5 +++ .../file/PolicyDecoderFileInCsarToPolicy.java | 8 ++--- .../handling/sdc/SdcReceptionHandler.java | 5 ++- .../reception/decoding/hpa/TestAttribute.java | 2 +- .../reception/decoding/hpa/TestContent.java | 3 +- .../reception/decoding/hpa/TestDirective.java | 3 +- .../reception/decoding/hpa/TestFlavorFeature.java | 4 +-- .../reception/decoding/hpa/TestFlavorProperty.java | 4 +-- .../decoding/hpa/TestHpaFeatureAttribute.java | 2 +- 13 files changed, 73 insertions(+), 35 deletions(-) create mode 100644 plugins/forwarding-plugins/src/test/resources/logback-test.xml (limited to 'plugins') diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java index 55735662..e88f7eb9 100644 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java +++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Intel Crop. All rights reserved. + * Modifications Copyright (C) 2020 AT&T Inc. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -97,7 +98,6 @@ public class FilePolicyForwarder implements PolicyForwarder { LOGGER.debug("Sucessfully forwarded the policy to store into file {}.", path); } catch (final InvalidPathException | IOException exp) { final String message = "Error sending policy to file under path:" + fileForwarderParameters.getPath(); - LOGGER.error(message, exp); throw new PolicyForwardingException(message, exp); } } diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java index 5cd9966d..e3c013ad 100644 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java +++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Inc. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -153,10 +154,8 @@ public class LifecycleApiPolicyForwarder implements PolicyForwarder { throw new PolicyForwardingException("Failed creating the entity - " + entity); } } catch (final HttpClientConfigException exception) { - LOGGER.error( - "Invocation of path " + path + " failed for entity " + entity + " due to error opening Http client", + throw new PolicyForwardingException("Invocation of path " + path + " failed for entity " + entity, exception); - throw new PolicyForwardingException("Failed creating the entity - " + entity, exception); } return response; } diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java index 7d84657a..5fce708e 100644 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Inc. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +21,7 @@ package org.onap.policy.distribution.forwarding.lifecycle.api; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.ArrayList; @@ -83,20 +85,22 @@ public class LifecycleApiPolicyForwarderTest { @Test public void testForwardPolicyUsingSimulator() throws Exception { + assertThatCode(() -> { + final ToscaServiceTemplate toscaServiceTemplate1 = + standardCoder.decode(ResourceUtils.getResourceAsString(POLICY_TYPE), ToscaServiceTemplate.class); + final ToscaServiceTemplate toscaServiceTemplate2 = + standardCoder.decode(ResourceUtils.getResourceAsString(POLICY), ToscaServiceTemplate.class); - final ToscaServiceTemplate toscaServiceTemplate1 = - standardCoder.decode(ResourceUtils.getResourceAsString(POLICY_TYPE), ToscaServiceTemplate.class); - final ToscaServiceTemplate toscaServiceTemplate2 = - standardCoder.decode(ResourceUtils.getResourceAsString(POLICY), ToscaServiceTemplate.class); + final LifecycleApiPolicyForwarder forwarder = new LifecycleApiPolicyForwarder(); + forwarder.configure(LifecycleApiForwarderParameters.class.getSimpleName()); - final LifecycleApiPolicyForwarder forwarder = new LifecycleApiPolicyForwarder(); - forwarder.configure(LifecycleApiForwarderParameters.class.getSimpleName()); + final Collection policies = new ArrayList<>(); + policies.add(toscaServiceTemplate1); + policies.add(toscaServiceTemplate2); - final Collection policies = new ArrayList<>(); - policies.add(toscaServiceTemplate1); - policies.add(toscaServiceTemplate2); + forwarder.forward(policies); - forwarder.forward(policies); + }).doesNotThrowAnyException(); } @Test diff --git a/plugins/forwarding-plugins/src/test/resources/logback-test.xml b/plugins/forwarding-plugins/src/test/resources/logback-test.xml new file mode 100644 index 00000000..29d86d48 --- /dev/null +++ b/plugins/forwarding-plugins/src/test/resources/logback-test.xml @@ -0,0 +1,41 @@ + + + + + + policy-api + + + + + + %d %contextName [%t] %level %logger{36} - %msg%n + + + + + + + + + + + diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpa.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpa.java index e1e1a9a9..51aa15f6 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpa.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpa.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Inc. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,6 +47,10 @@ import org.slf4j.LoggerFactory; public class PolicyDecoderCsarHpa implements PolicyDecoder { private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderCsarHpa.class); + // + // This is initialized in configure() but then never used here + // + @SuppressWarnings("unused") private PolicyDecoderCsarHpaParameters decoderParameters; public static final String TOSCA_POLICY_SCOPE = "scope"; diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java index 4b58d2da..643785fa 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Inc. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,8 +38,6 @@ import org.onap.policy.distribution.reception.decoding.PolicyDecoder; import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * This class extracts policy files from a CSAR file. @@ -47,7 +46,6 @@ import org.slf4j.LoggerFactory; */ public class PolicyDecoderFileInCsarToPolicy implements PolicyDecoder { - private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderFileInCsarToPolicy.class); private PolicyDecoderFileInCsarToPolicyParameterGroup decoderParameters; private StandardCoder coder; @@ -87,9 +85,7 @@ public class PolicyDecoderFileInCsarToPolicy implements PolicyDecoder