diff options
Diffstat (limited to 'BRMSGateway/src/test/java/org/onap/policy')
6 files changed, 463 insertions, 1 deletions
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<PEDependency> list = new ArrayList<PEDependency>(); + list.add(dependency); + final Map<String, List<PEDependency>> map = new HashMap<String, List<PEDependency>>(); + 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<PropertyChange> 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<PropertyChange> 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<PropertyChange> 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<PropertyChange> 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<PropertyChange> 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<PropertyChange> 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<PropertyChange> 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<PropertyChange> 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<PropertyChange> 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<PropertyChange> 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<PropertyChange> 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<PropertyChange> 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<PropertyChange> 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<String, String> testMap = new HashMap<String, String>(); + 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<ControllerPojo> controllers = new ArrayList<ControllerPojo>(); + 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); |