X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=PolicyEngineAPI%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Ftest%2FSendEventTest.java;fp=PolicyEngineAPI%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Ftest%2FSendEventTest.java;h=46f4dd1e8dfe3d97f78c4707fa88784b6d24a3a2;hp=560ca463fa16c85f3ce0c557cb080ab8b18baee1;hb=2ae7194f9b915e42bba68537eec9426baa5ae456;hpb=939cf950022f89aec547d3a6a9f6b9443b7a8a95 diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/SendEventTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/SendEventTest.java index 560ca463f..46f4dd1e8 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/SendEventTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/SendEventTest.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (C) 2019 Samsung + * ================================================================================ * 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. @@ -24,11 +26,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; - import java.util.Collection; import java.util.HashMap; import java.util.Map; - import org.junit.Before; import org.onap.policy.api.PolicyEngine; import org.onap.policy.api.PolicyEngineException; @@ -36,120 +36,115 @@ import org.onap.policy.api.PolicyEventException; import org.onap.policy.api.PolicyResponse; import org.onap.policy.api.PolicyResponseStatus; import org.onap.policy.common.logging.flexlogger.FlexLogger; -import org.onap.policy.common.logging.flexlogger.Logger; +import org.onap.policy.common.logging.flexlogger.Logger; public class SendEventTest { - - private PolicyEngine policyEngine = null; - private Map eventAttributes = new HashMap(); - private Collection policyResponse = null; - private static final Logger logger = FlexLogger.getLogger(SendEventTest.class); - @Before - public void setUp() { - try { - policyEngine = new PolicyEngine("Test/config_pass.properties"); - } catch (PolicyEngineException e) { - logger.error(e.getMessage()); - fail("PolicyEngine Instantiation Error" + e); - } - logger.info("Loaded.. PolicyEngine"); - } - //@Test - @SuppressWarnings("deprecation") - public void testSendEventFail() { - eventAttributes = null; - try { - policyResponse = policyEngine.sendEvent(eventAttributes); - } catch (PolicyEventException e) { - logger.warn(e.getMessage()); - } - assertNull(policyResponse); - } - - //@Test - @SuppressWarnings("deprecation") - public void testSendEventFailNull() { - eventAttributes.put("", ""); - try { - policyResponse = policyEngine.sendEvent(eventAttributes); - } catch (PolicyEventException e) { - logger.warn(e.getMessage()); - } - assertNull(policyResponse); - } - - // deprecated Test. - /*@Test - public void testSendEventFailAttribute() { - eventAttributes.put("Fail.key", "Value"); - try { - policyResponse = policyEngine.sendEvent(eventAttributes); - } catch (PolicyEventException e) { - logger.warn(e.getMessage()); - } - assertNull(policyResponse.getPolicyResponseMessage()); - }*/ - - //@Test - @SuppressWarnings("deprecation") - public void testSendEventNotValid() { - eventAttributes.put("Action.fail", "Value"); - try { - policyResponse = policyEngine.sendEvent(eventAttributes); - } catch (PolicyEventException e) { - logger.warn(e.getMessage()); - } - for(PolicyResponse policyResponse: this.policyResponse){ - logger.info(policyResponse.getPolicyResponseMessage() + " , " + policyResponse.getPolicyResponseStatus()); - assertNotNull(policyResponse); - assertEquals(PolicyResponseStatus.NO_ACTION_REQUIRED, policyResponse.getPolicyResponseStatus()); - assertNotNull(policyResponse.getPolicyResponseMessage()); - assertNotNull(policyResponse.getRequestAttributes()); - assertNull(policyResponse.getActionTaken()); - assertNull(policyResponse.getActionAdvised()); - } - } - - //@Test - @SuppressWarnings("deprecation") - public void testSendEventActionAdvised() { - eventAttributes.put("Key", "Value"); - eventAttributes.put("cpu", "80"); - try { - policyResponse = policyEngine.sendEvent(eventAttributes); - } catch (PolicyEventException e) { - logger.warn(e.getMessage()); - } - for(PolicyResponse policyResponse: this.policyResponse){ - logger.info(policyResponse.getPolicyResponseMessage() + " , " + policyResponse.getPolicyResponseStatus()); - assertNotNull(policyResponse); - assertEquals(PolicyResponseStatus.ACTION_ADVISED, policyResponse.getPolicyResponseStatus()); - assertNotNull(policyResponse.getPolicyResponseMessage()); - assertNotNull(policyResponse.getRequestAttributes()); - assertNull(policyResponse.getActionTaken()); - assertNotNull(policyResponse.getActionAdvised()); - } - } - - //@Test - @SuppressWarnings("deprecation") - public void testSendEventActionTaken() { - eventAttributes.put("Key", "Value"); - eventAttributes.put("cpu", "91"); - try { - policyResponse = policyEngine.sendEvent(eventAttributes); - } catch (PolicyEventException e) { - logger.warn(e.getMessage()); - } - for(PolicyResponse policyResponse: this.policyResponse){ - logger.info(policyResponse.getPolicyResponseMessage() + " , " + policyResponse.getPolicyResponseStatus()); - assertNotNull(policyResponse); - assertEquals(PolicyResponseStatus.ACTION_TAKEN, policyResponse.getPolicyResponseStatus()); - assertNotNull(policyResponse.getPolicyResponseMessage()); - assertNotNull(policyResponse.getRequestAttributes()); - assertNotNull(policyResponse.getActionTaken()); - assertNull(policyResponse.getActionAdvised()); - } - } + private PolicyEngine policyEngine = null; + private Map eventAttributes = new HashMap(); + private Collection policyResponse = null; + private static final Logger logger = FlexLogger.getLogger(SendEventTest.class); + + @Before + public void setUp() { + try { + policyEngine = new PolicyEngine("Test/config_pass.properties"); + } catch (PolicyEngineException e) { + logger.error(e.getMessage()); + fail("PolicyEngine Instantiation Error" + e); + } + logger.info("Loaded.. PolicyEngine"); + } + + // @Test + @SuppressWarnings("deprecation") + public void testSendEventFail() { + eventAttributes = null; + try { + policyResponse = policyEngine.sendEvent(eventAttributes); + } catch (PolicyEventException e) { + logger.warn(e.getMessage()); + } + assertNull(policyResponse); + } + + // @Test + @SuppressWarnings("deprecation") + public void testSendEventFailNull() { + eventAttributes.put("", ""); + try { + policyResponse = policyEngine.sendEvent(eventAttributes); + } catch (PolicyEventException e) { + logger.warn(e.getMessage()); + } + assertNull(policyResponse); + } + + // @Test + @SuppressWarnings("deprecation") + public void testSendEventNotValid() { + eventAttributes.put("Action.fail", "Value"); + try { + policyResponse = policyEngine.sendEvent(eventAttributes); + } catch (PolicyEventException e) { + logger.warn(e.getMessage()); + } + for (PolicyResponse policyResponse : this.policyResponse) { + logger.info(policyResponse.getPolicyResponseMessage() + " , " + + policyResponse.getPolicyResponseStatus()); + assertNotNull(policyResponse); + assertEquals(PolicyResponseStatus.NO_ACTION_REQUIRED, + policyResponse.getPolicyResponseStatus()); + assertNotNull(policyResponse.getPolicyResponseMessage()); + assertNotNull(policyResponse.getRequestAttributes()); + assertNull(policyResponse.getActionTaken()); + assertNull(policyResponse.getActionAdvised()); + } + } + + // @Test + @SuppressWarnings("deprecation") + public void testSendEventActionAdvised() { + eventAttributes.put("Key", "Value"); + eventAttributes.put("cpu", "80"); + try { + policyResponse = policyEngine.sendEvent(eventAttributes); + } catch (PolicyEventException e) { + logger.warn(e.getMessage()); + } + for (PolicyResponse policyResponse : this.policyResponse) { + logger.info(policyResponse.getPolicyResponseMessage() + " , " + + policyResponse.getPolicyResponseStatus()); + assertNotNull(policyResponse); + assertEquals(PolicyResponseStatus.ACTION_ADVISED, + policyResponse.getPolicyResponseStatus()); + assertNotNull(policyResponse.getPolicyResponseMessage()); + assertNotNull(policyResponse.getRequestAttributes()); + assertNull(policyResponse.getActionTaken()); + assertNotNull(policyResponse.getActionAdvised()); + } + } + + // @Test + @SuppressWarnings("deprecation") + public void testSendEventActionTaken() { + eventAttributes.put("Key", "Value"); + eventAttributes.put("cpu", "91"); + try { + policyResponse = policyEngine.sendEvent(eventAttributes); + } catch (PolicyEventException e) { + logger.warn(e.getMessage()); + } + for (PolicyResponse policyResponse : this.policyResponse) { + logger.info(policyResponse.getPolicyResponseMessage() + " , " + + policyResponse.getPolicyResponseStatus()); + assertNotNull(policyResponse); + assertEquals(PolicyResponseStatus.ACTION_TAKEN, + policyResponse.getPolicyResponseStatus()); + assertNotNull(policyResponse.getPolicyResponseMessage()); + assertNotNull(policyResponse.getRequestAttributes()); + assertNotNull(policyResponse.getActionTaken()); + assertNull(policyResponse.getActionAdvised()); + } + } }