From 0dea75c506058a9e999d30ec1916c7530504a8d6 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 8 May 2018 11:28:40 +0100 Subject: Configuration as argument to BRMS Gateway Added the ability specify the parameter file for the BRMS Gateway as a argument to allow different configurations to be used during unit test. This will allow more thorought unit tests to be written. Replaced System.exit() calls with exeception throws becasue System.exit() call bring down the entire JVM during testing, terminating the test at that point. Changed the package path on four unit test files to the correct path for unit tests for the BRMS gateway. Added a unit test for sanity test of the configuraiton file argument. Issue-ID: POLICY-773 Change-Id: Ic095a5131ddb846eaf3b11157853fab71908c629 Signed-off-by: liamfallon --- .../java/org/onap/policy/brms/api/BrmsGateway.java | 29 ++- .../java/org/onap/brmsgw/test/BrmsJpaTest.java | 73 ------- .../java/org/onap/brmsgw/test/BrmsPushTest.java | 235 --------------------- .../org/onap/brmsgw/test/ControllerPojoTest.java | 47 ----- .../org/onap/brmsgw/test/NotificationPojoTest.java | 48 ----- .../java/org/onap/policy/brms/BrmsJpaTest.java | 73 +++++++ .../java/org/onap/policy/brms/BrmsPushTest.java | 235 +++++++++++++++++++++ .../org/onap/policy/brms/ControllerPojoTest.java | 47 +++++ .../org/onap/policy/brms/NotificationPojoTest.java | 48 +++++ .../onap/policy/brms/api/BrmsGatewayMainTest.java | 59 ++++++ .../org/onap/policy/brms/api/BrmsGatewayTest.java | 2 +- 11 files changed, 487 insertions(+), 409 deletions(-) delete mode 100644 BRMSGateway/src/test/java/org/onap/brmsgw/test/BrmsJpaTest.java delete mode 100644 BRMSGateway/src/test/java/org/onap/brmsgw/test/BrmsPushTest.java delete mode 100644 BRMSGateway/src/test/java/org/onap/brmsgw/test/ControllerPojoTest.java delete mode 100644 BRMSGateway/src/test/java/org/onap/brmsgw/test/NotificationPojoTest.java create mode 100644 BRMSGateway/src/test/java/org/onap/policy/brms/BrmsJpaTest.java create mode 100644 BRMSGateway/src/test/java/org/onap/policy/brms/BrmsPushTest.java create mode 100644 BRMSGateway/src/test/java/org/onap/policy/brms/ControllerPojoTest.java create mode 100644 BRMSGateway/src/test/java/org/onap/policy/brms/NotificationPojoTest.java create mode 100644 BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayMainTest.java (limited to 'BRMSGateway') diff --git a/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsGateway.java b/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsGateway.java index d12178319..e743794ec 100644 --- a/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsGateway.java +++ b/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsGateway.java @@ -34,7 +34,7 @@ import org.onap.policy.xacml.api.XACMLErrorConstants; * * @version 0.1 */ -class BrmsGateway { +public class BrmsGateway { private static final Logger logger = FlexLogger.getLogger(BrmsGateway.class); private static final String CONFIGFILE = "config.properties"; @@ -45,15 +45,34 @@ class BrmsGateway { // Default private constructor } + /** + * Main method. + * @param args The path to the configuration file is the only allowed optional argument + * @throws Exception on BRMS Gateway errors + */ public static void main(final String[] args) throws Exception { + // The configuration file containing the configuration for the BRMS Gateway + String configFile = CONFIGFILE; + + // Check if a configuration file has been specified as a parameter + if (args.length == 1) { + configFile = args[0]; + } + else if (args.length > 1) { + String errorString = "usage: " + BrmsGateway.class.getCanonicalName() + " [configFile]"; + logger.error(errorString); + throw new PolicyException(errorString); + } + // Initialize Handler. logger.info("Initializing BRMS Handler"); BrmsHandler brmsHandler = null; try { - brmsHandler = new BrmsHandler(CONFIGFILE); + brmsHandler = new BrmsHandler(configFile); } catch (final PolicyException e) { - logger.error("Check your property file: " + e.getMessage(), e); - System.exit(1); + String errorString = "Check your property file: " + e.getMessage(); + logger.error(errorString); + throw new PolicyException(errorString); } // Set Handler with Auto Notification and initialize policyEngine @@ -62,7 +81,7 @@ class BrmsGateway { policyEngine = new PolicyEngine(CONFIGFILE, NotificationScheme.AUTO_ALL_NOTIFICATIONS, brmsHandler); } catch (final Exception e) { logger.error(XACMLErrorConstants.ERROR_UNKNOWN + "Error while Initializing Policy Engine " + e.getMessage(), - e); + e); } // Keep Running.... diff --git a/BRMSGateway/src/test/java/org/onap/brmsgw/test/BrmsJpaTest.java b/BRMSGateway/src/test/java/org/onap/brmsgw/test/BrmsJpaTest.java deleted file mode 100644 index 32ed314d5..000000000 --- a/BRMSGateway/src/test/java/org/onap/brmsgw/test/BrmsJpaTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP Policy Engine - * ================================================================================ - * Copyright (C) 2018 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.brmsgw.test; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Test; -import org.onap.policy.api.PEDependency; -import org.onap.policy.brms.entity.BrmsGroupInfo; -import org.onap.policy.brms.entity.BrmsPolicyInfo; -import org.onap.policy.brms.entity.DependencyInfo; - -public class BrmsJpaTest { - @Test - public void testJpa() { - final String testVal = "testVal"; - final BrmsGroupInfo groupInfo = new BrmsGroupInfo(); - - // Test group info - groupInfo.setControllerName(testVal); - assertEquals(groupInfo.getControllerName(), testVal); - groupInfo.setGroupId(testVal); - assertEquals(groupInfo.getGroupId(), testVal); - groupInfo.setArtifactId(testVal); - assertEquals(groupInfo.getArtifactId(), testVal); - groupInfo.setVersion(testVal); - assertEquals(groupInfo.getVersion(), testVal); - - // Test policy info - final BrmsPolicyInfo policyInfo = new BrmsPolicyInfo(); - policyInfo.setPolicyName(testVal); - assertEquals(policyInfo.getPolicyName(), testVal); - policyInfo.setControllerName(groupInfo); - assertEquals(policyInfo.getControllerName(), groupInfo); - } - - @Test - public void testDependencyInfo() { - final String testKey = "testKey"; - final PEDependency dependency = new PEDependency(); - final List list = new ArrayList(); - list.add(dependency); - final Map> map = new HashMap>(); - map.put(testKey, list); - final DependencyInfo info = new DependencyInfo(); - - info.setDependencies(map); - assertEquals(info.getDependencies(), map); - } -} diff --git a/BRMSGateway/src/test/java/org/onap/brmsgw/test/BrmsPushTest.java b/BRMSGateway/src/test/java/org/onap/brmsgw/test/BrmsPushTest.java deleted file mode 100644 index 36e633638..000000000 --- a/BRMSGateway/src/test/java/org/onap/brmsgw/test/BrmsPushTest.java +++ /dev/null @@ -1,235 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP Policy Engine - * ================================================================================ - * Copyright (C) 2017 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.brmsgw.test; - -import static org.junit.Assert.assertNotNull; - -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; -import java.util.Properties; - -import org.junit.Test; -import org.onap.policy.api.PolicyException; -import org.onap.policy.brms.api.BrmsHandler; - -public class BrmsPushTest { - - private static final String VALID_FILE = "src/test/resources/config.properties"; - private static final String INVALID_FILE = "src/test/resources/failure.properties"; - - @Test(expected = PolicyException.class) - public void brmsHandlerFailTest() throws PolicyException { - new BrmsHandler(null); - } - - @Test(expected = PolicyException.class) - public void brmsHandlerFailTest1() throws PolicyException { - new BrmsHandler("src/test/resources/filenotexists.txt"); - } - - @Test(expected = PolicyException.class) - public void brmsHandlerFailTest2() throws PolicyException { - final PropertyChange prop = new PropertyChange(); - prop.key = "defaultName"; - prop.remove = true; - final List props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BrmsHandler(INVALID_FILE); - } - - @Test(expected = PolicyException.class) - public void brmsHandlerFailTest3() throws PolicyException { - PropertyChange prop = new PropertyChange(); - prop.key = "repositoryID"; - prop.remove = true; - final List props = new LinkedList<>(); - props.add(prop); - prop = new PropertyChange(); - prop.key = "RESOURCE_NAME"; - prop.remove = true; - props.add(prop); - setFailureProperties(props); - new BrmsHandler(INVALID_FILE); - } - - @Test(expected = PolicyException.class) - public void brmsHandlerFailTest4() throws PolicyException { - final PropertyChange prop = new PropertyChange(); - prop.key = "repositoryURL"; - prop.remove = true; - final List props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BrmsHandler(INVALID_FILE); - } - - @Test(expected = PolicyException.class) - public void brmsHandlerFailTest5() throws PolicyException { - final PropertyChange prop = new PropertyChange(); - prop.key = "repositoryName"; - prop.remove = true; - final List props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BrmsHandler(INVALID_FILE); - } - - @Test(expected = PolicyException.class) - public void brmsHandlerFailTest6() throws PolicyException { - PropertyChange prop = new PropertyChange(); - prop.key = "repositoryURL"; - prop.value = - "http://nexus:8081/nexus/content/repositories/releases, http://nexus:8081/nexus/content/repositories/releases"; - prop.remove = false; - final List props = new LinkedList<>(); - props.add(prop); - prop = new PropertyChange(); - prop.key = "repositoryUsername"; - prop.remove = true; - props.add(prop); - setFailureProperties(props); - new BrmsHandler(INVALID_FILE); - } - - @Test(expected = PolicyException.class) - public void brmsHandlerFailTest7() throws PolicyException { - final PropertyChange prop = new PropertyChange(); - prop.key = "repositoryPassword"; - prop.remove = true; - final List props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BrmsHandler(INVALID_FILE); - } - - @Test(expected = PolicyException.class) - public void brmsHandlerFailTest8() throws PolicyException { - final PropertyChange prop = new PropertyChange(); - prop.key = "policyKeyID"; - prop.remove = true; - final List props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BrmsHandler(INVALID_FILE); - } - - @Test(expected = PolicyException.class) - public void brmsHandlerFailTest9() throws PolicyException { - PropertyChange prop = new PropertyChange(); - prop.key = "sync"; - prop.value = "true"; - prop.remove = false; - final List props = new LinkedList<>(); - props.add(prop); - prop = new PropertyChange(); - prop.key = "brms.dependency.version"; - prop.remove = true; - props.add(prop); - prop = new PropertyChange(); - prop.key = "groupNames"; - prop.remove = true; - props.add(prop); - setFailureProperties(props); - new BrmsHandler(INVALID_FILE); - } - - @Test(expected = PolicyException.class) - public void brmsHandlerFailTest10() throws PolicyException { - final PropertyChange prop = new PropertyChange(); - prop.key = "groupNames"; - prop.value = ""; - prop.remove = false; - final List props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BrmsHandler(INVALID_FILE); - } - - @Test(expected = PolicyException.class) - public void brmsHandlerFailTest11() throws PolicyException { - final PropertyChange prop = new PropertyChange(); - prop.key = "default.groupID"; - prop.remove = true; - final List props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BrmsHandler(INVALID_FILE); - } - - @Test(expected = PolicyException.class) - public void brmsHandlerFailTest12() throws PolicyException { - final PropertyChange prop = new PropertyChange(); - prop.key = "default.artifactID"; - prop.remove = true; - final List props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BrmsHandler(INVALID_FILE); - } - - @Test(expected = PolicyException.class) - public void brmsHandlerFailTest13() throws PolicyException { - PropertyChange prop = new PropertyChange(); - prop.key = "NOTIFICATION_TYPE"; - prop.value = "dmaap"; - prop.remove = false; - final List props = new LinkedList<>(); - props.add(prop); - prop = new PropertyChange(); - prop.key = "NOTIFICATION_SERVERS"; - prop.remove = true; - props.add(prop); - setFailureProperties(props); - new BrmsHandler(INVALID_FILE); - } - - @Test - public void brmsHandlerTest() throws PolicyException { - assertNotNull(new BrmsHandler(VALID_FILE)); - } - - private void setFailureProperties(final List properties) throws PolicyException { - final Properties validProp = new Properties(); - try { - validProp.load(new FileInputStream(VALID_FILE)); - for (final PropertyChange prop : properties) { - if (prop.remove) { - validProp.remove(prop.key); - } else { - validProp.setProperty(prop.key, prop.value); - } - } - validProp.store(new FileOutputStream(INVALID_FILE), null); - } catch (final IOException e) { - throw new PolicyException(e); - } - } - - class PropertyChange { - public String key = null; - public String value = null; - public Boolean remove = false; - } -} diff --git a/BRMSGateway/src/test/java/org/onap/brmsgw/test/ControllerPojoTest.java b/BRMSGateway/src/test/java/org/onap/brmsgw/test/ControllerPojoTest.java deleted file mode 100644 index 21534ddcd..000000000 --- a/BRMSGateway/src/test/java/org/onap/brmsgw/test/ControllerPojoTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP Policy Engine - * ================================================================================ - * Copyright (C) 2018 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.brmsgw.test; - -import static org.junit.Assert.assertEquals; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -import org.onap.policy.brms.api.ControllerPojo; - -public class ControllerPojoTest { - @Test - public void testPojo() { - final String testKey = "testKey"; - final String testVal = "testVal"; - final Map testMap = new HashMap(); - testMap.put(testKey, testVal); - final ControllerPojo pojo = new ControllerPojo(); - - pojo.setName(testVal); - assertEquals(pojo.getName(), testVal); - pojo.setDrools(testMap); - assertEquals(pojo.getDrools(), testMap); - pojo.setOperation(testVal); - assertEquals(pojo.getOperation(), testVal); - } -} diff --git a/BRMSGateway/src/test/java/org/onap/brmsgw/test/NotificationPojoTest.java b/BRMSGateway/src/test/java/org/onap/brmsgw/test/NotificationPojoTest.java deleted file mode 100644 index f83b749f7..000000000 --- a/BRMSGateway/src/test/java/org/onap/brmsgw/test/NotificationPojoTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP Policy Engine - * ================================================================================ - * Copyright (C) 2018 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.brmsgw.test; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; -import org.onap.policy.brms.api.ControllerPojo; -import org.onap.policy.brms.api.NotificationPojo; - -public class NotificationPojoTest { - @Test - public void testPojo() { - final String testVal = "testVal"; - final ControllerPojo ctrlPojo = new ControllerPojo(); - final List controllers = new ArrayList(); - controllers.add(ctrlPojo); - final NotificationPojo pojo = new NotificationPojo(); - - pojo.setRequestId(testVal); - assertEquals(pojo.getRequestId(), testVal); - pojo.setEntity(testVal); - assertEquals(pojo.getEntity(), testVal); - pojo.setControllers(controllers); - assertEquals(pojo.getControllers(), controllers); - } -} diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/BrmsJpaTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/BrmsJpaTest.java new file mode 100644 index 000000000..2d5aaa496 --- /dev/null +++ b/BRMSGateway/src/test/java/org/onap/policy/brms/BrmsJpaTest.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2018 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.brms; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.onap.policy.api.PEDependency; +import org.onap.policy.brms.entity.BrmsGroupInfo; +import org.onap.policy.brms.entity.BrmsPolicyInfo; +import org.onap.policy.brms.entity.DependencyInfo; + +public class BrmsJpaTest { + @Test + public void testJpa() { + final String testVal = "testVal"; + final BrmsGroupInfo groupInfo = new BrmsGroupInfo(); + + // Test group info + groupInfo.setControllerName(testVal); + assertEquals(groupInfo.getControllerName(), testVal); + groupInfo.setGroupId(testVal); + assertEquals(groupInfo.getGroupId(), testVal); + groupInfo.setArtifactId(testVal); + assertEquals(groupInfo.getArtifactId(), testVal); + groupInfo.setVersion(testVal); + assertEquals(groupInfo.getVersion(), testVal); + + // Test policy info + final BrmsPolicyInfo policyInfo = new BrmsPolicyInfo(); + policyInfo.setPolicyName(testVal); + assertEquals(policyInfo.getPolicyName(), testVal); + policyInfo.setControllerName(groupInfo); + assertEquals(policyInfo.getControllerName(), groupInfo); + } + + @Test + public void testDependencyInfo() { + final String testKey = "testKey"; + final PEDependency dependency = new PEDependency(); + final List list = new ArrayList(); + list.add(dependency); + final Map> map = new HashMap>(); + map.put(testKey, list); + final DependencyInfo info = new DependencyInfo(); + + info.setDependencies(map); + assertEquals(info.getDependencies(), map); + } +} diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/BrmsPushTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/BrmsPushTest.java new file mode 100644 index 000000000..4a1b4f8d4 --- /dev/null +++ b/BRMSGateway/src/test/java/org/onap/policy/brms/BrmsPushTest.java @@ -0,0 +1,235 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2017 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.brms; + +import static org.junit.Assert.assertNotNull; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; + +import org.junit.Test; +import org.onap.policy.api.PolicyException; +import org.onap.policy.brms.api.BrmsHandler; + +public class BrmsPushTest { + + private static final String VALID_FILE = "src/test/resources/config.properties"; + private static final String INVALID_FILE = "src/test/resources/failure.properties"; + + @Test(expected = PolicyException.class) + public void brmsHandlerFailTest() throws PolicyException { + new BrmsHandler(null); + } + + @Test(expected = PolicyException.class) + public void brmsHandlerFailTest1() throws PolicyException { + new BrmsHandler("src/test/resources/filenotexists.txt"); + } + + @Test(expected = PolicyException.class) + public void brmsHandlerFailTest2() throws PolicyException { + final PropertyChange prop = new PropertyChange(); + prop.key = "defaultName"; + prop.remove = true; + final List props = new LinkedList<>(); + props.add(prop); + setFailureProperties(props); + new BrmsHandler(INVALID_FILE); + } + + @Test(expected = PolicyException.class) + public void brmsHandlerFailTest3() throws PolicyException { + PropertyChange prop = new PropertyChange(); + prop.key = "repositoryID"; + prop.remove = true; + final List props = new LinkedList<>(); + props.add(prop); + prop = new PropertyChange(); + prop.key = "RESOURCE_NAME"; + prop.remove = true; + props.add(prop); + setFailureProperties(props); + new BrmsHandler(INVALID_FILE); + } + + @Test(expected = PolicyException.class) + public void brmsHandlerFailTest4() throws PolicyException { + final PropertyChange prop = new PropertyChange(); + prop.key = "repositoryURL"; + prop.remove = true; + final List props = new LinkedList<>(); + props.add(prop); + setFailureProperties(props); + new BrmsHandler(INVALID_FILE); + } + + @Test(expected = PolicyException.class) + public void brmsHandlerFailTest5() throws PolicyException { + final PropertyChange prop = new PropertyChange(); + prop.key = "repositoryName"; + prop.remove = true; + final List props = new LinkedList<>(); + props.add(prop); + setFailureProperties(props); + new BrmsHandler(INVALID_FILE); + } + + @Test(expected = PolicyException.class) + public void brmsHandlerFailTest6() throws PolicyException { + PropertyChange prop = new PropertyChange(); + prop.key = "repositoryURL"; + prop.value = "http://nexus:8081/nexus/content/repositories/releases," + + "http://nexus:8081/nexus/content/repositories/releases"; + prop.remove = false; + final List props = new LinkedList<>(); + props.add(prop); + prop = new PropertyChange(); + prop.key = "repositoryUsername"; + prop.remove = true; + props.add(prop); + setFailureProperties(props); + new BrmsHandler(INVALID_FILE); + } + + @Test(expected = PolicyException.class) + public void brmsHandlerFailTest7() throws PolicyException { + final PropertyChange prop = new PropertyChange(); + prop.key = "repositoryPassword"; + prop.remove = true; + final List props = new LinkedList<>(); + props.add(prop); + setFailureProperties(props); + new BrmsHandler(INVALID_FILE); + } + + @Test(expected = PolicyException.class) + public void brmsHandlerFailTest8() throws PolicyException { + final PropertyChange prop = new PropertyChange(); + prop.key = "policyKeyID"; + prop.remove = true; + final List props = new LinkedList<>(); + props.add(prop); + setFailureProperties(props); + new BrmsHandler(INVALID_FILE); + } + + @Test(expected = PolicyException.class) + public void brmsHandlerFailTest9() throws PolicyException { + PropertyChange prop = new PropertyChange(); + prop.key = "sync"; + prop.value = "true"; + prop.remove = false; + final List props = new LinkedList<>(); + props.add(prop); + prop = new PropertyChange(); + prop.key = "brms.dependency.version"; + prop.remove = true; + props.add(prop); + prop = new PropertyChange(); + prop.key = "groupNames"; + prop.remove = true; + props.add(prop); + setFailureProperties(props); + new BrmsHandler(INVALID_FILE); + } + + @Test(expected = PolicyException.class) + public void brmsHandlerFailTest10() throws PolicyException { + final PropertyChange prop = new PropertyChange(); + prop.key = "groupNames"; + prop.value = ""; + prop.remove = false; + final List props = new LinkedList<>(); + props.add(prop); + setFailureProperties(props); + new BrmsHandler(INVALID_FILE); + } + + @Test(expected = PolicyException.class) + public void brmsHandlerFailTest11() throws PolicyException { + final PropertyChange prop = new PropertyChange(); + prop.key = "default.groupID"; + prop.remove = true; + final List props = new LinkedList<>(); + props.add(prop); + setFailureProperties(props); + new BrmsHandler(INVALID_FILE); + } + + @Test(expected = PolicyException.class) + public void brmsHandlerFailTest12() throws PolicyException { + final PropertyChange prop = new PropertyChange(); + prop.key = "default.artifactID"; + prop.remove = true; + final List props = new LinkedList<>(); + props.add(prop); + setFailureProperties(props); + new BrmsHandler(INVALID_FILE); + } + + @Test(expected = PolicyException.class) + public void brmsHandlerFailTest13() throws PolicyException { + PropertyChange prop = new PropertyChange(); + prop.key = "NOTIFICATION_TYPE"; + prop.value = "dmaap"; + prop.remove = false; + final List props = new LinkedList<>(); + props.add(prop); + prop = new PropertyChange(); + prop.key = "NOTIFICATION_SERVERS"; + prop.remove = true; + props.add(prop); + setFailureProperties(props); + new BrmsHandler(INVALID_FILE); + } + + @Test + public void brmsHandlerTest() throws PolicyException { + assertNotNull(new BrmsHandler(VALID_FILE)); + } + + private void setFailureProperties(final List properties) throws PolicyException { + final Properties validProp = new Properties(); + try { + validProp.load(new FileInputStream(VALID_FILE)); + for (final PropertyChange prop : properties) { + if (prop.remove) { + validProp.remove(prop.key); + } else { + validProp.setProperty(prop.key, prop.value); + } + } + validProp.store(new FileOutputStream(INVALID_FILE), null); + } catch (final IOException e) { + throw new PolicyException(e); + } + } + + class PropertyChange { + public String key = null; + public String value = null; + public Boolean remove = false; + } +} diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/ControllerPojoTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/ControllerPojoTest.java new file mode 100644 index 000000000..e00689dc8 --- /dev/null +++ b/BRMSGateway/src/test/java/org/onap/policy/brms/ControllerPojoTest.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2018 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.brms; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.onap.policy.brms.api.ControllerPojo; + +public class ControllerPojoTest { + @Test + public void testPojo() { + final String testKey = "testKey"; + final String testVal = "testVal"; + final Map testMap = new HashMap(); + testMap.put(testKey, testVal); + final ControllerPojo pojo = new ControllerPojo(); + + pojo.setName(testVal); + assertEquals(pojo.getName(), testVal); + pojo.setDrools(testMap); + assertEquals(pojo.getDrools(), testMap); + pojo.setOperation(testVal); + assertEquals(pojo.getOperation(), testVal); + } +} diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/NotificationPojoTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/NotificationPojoTest.java new file mode 100644 index 000000000..ef6fff087 --- /dev/null +++ b/BRMSGateway/src/test/java/org/onap/policy/brms/NotificationPojoTest.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2018 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.brms; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.onap.policy.brms.api.ControllerPojo; +import org.onap.policy.brms.api.NotificationPojo; + +public class NotificationPojoTest { + @Test + public void testPojo() { + final String testVal = "testVal"; + final ControllerPojo ctrlPojo = new ControllerPojo(); + final List controllers = new ArrayList(); + controllers.add(ctrlPojo); + final NotificationPojo pojo = new NotificationPojo(); + + pojo.setRequestId(testVal); + assertEquals(pojo.getRequestId(), testVal); + pojo.setEntity(testVal); + assertEquals(pojo.getEntity(), testVal); + pojo.setControllers(controllers); + assertEquals(pojo.getControllers(), controllers); + } +} diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayMainTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayMainTest.java new file mode 100644 index 000000000..e20986fa6 --- /dev/null +++ b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayMainTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.brms.api; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Test; +import org.onap.policy.api.PolicyException; + +public class BrmsGatewayMainTest { + + @Test + public void testTooManyArguments() { + try { + String[] args = {"aaa", "bbb"}; + BrmsGateway.main(args); + fail("test should throw an exception"); + } + catch (PolicyException e) { + assertEquals("usage: org.onap.policy.brms.api.BrmsGateway [configFile]", e.getMessage()); + } + catch (Exception e) { + fail("test should throw a PolicyException"); + } + + try { + String[] args = {"aaa"}; + BrmsGateway.main(args); + fail("test should throw an exception"); + } + catch (PolicyException e) { + assertEquals("Check your property file: PE300 - Data Issue: " + + "Config File doesn't Exist in the specified Path aaa", e.getMessage()); + } + catch (Exception e) { + fail("test should throw a PolicyException"); + } + } + +} diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayTest.java index b3f836fc5..fd8a7ed3b 100644 --- a/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayTest.java +++ b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayTest.java @@ -52,7 +52,7 @@ public class BrmsGatewayTest { // Run app try { - final String[] args = null; + final String[] args = new String[0]; BrmsGateway.main(args); } catch (final Exception ex) { fail("Not expected an exception: " + ex); -- cgit 1.2.3-korg