diff options
Diffstat (limited to 'BRMSGateway/src/test/java')
11 files changed, 591 insertions, 583 deletions
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 ffcc2e379..000000000 --- a/BRMSGateway/src/test/java/org/onap/brmsgw/test/BRMSJpaTest.java +++ /dev/null @@ -1,71 +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.brmsInterface.jpa.BRMSGroupInfo; -import org.onap.policy.brmsInterface.jpa.BRMSPolicyInfo; -import org.onap.policy.brmsInterface.jpa.DependencyInfo; - -public class BRMSJpaTest { - @Test - public void testJpa() { - String testVal = "testVal"; - 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 - BRMSPolicyInfo policyInfo = new BRMSPolicyInfo(); - policyInfo.setPolicyName(testVal); - assertEquals(policyInfo.getPolicyName(), testVal); - policyInfo.setControllerName(groupInfo); - assertEquals(policyInfo.getControllerName(), groupInfo); - } - - @Test - public void testDependencyInfo() { - String testKey = "testKey"; - PEDependency dependency = new PEDependency(); - List<PEDependency> list = new ArrayList<PEDependency>(); - list.add(dependency); - Map<String, List<PEDependency>> map = new HashMap<String, List<PEDependency>>(); - map.put(testKey, list); - 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 aa2574401..000000000 --- a/BRMSGateway/src/test/java/org/onap/brmsgw/test/BRMSPushTest.java +++ /dev/null @@ -1,234 +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.brmsInterface.BRMSHandler; - -public class BRMSPushTest { - - private final String VALIDFILE = "src/test/resources/config.properties"; - private final String INVALIDFILE = "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 { - PropertyChange prop = new PropertyChange(); - prop.key = "defaultName"; - prop.remove = true; - List<PropertyChange> props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BRMSHandler(INVALIDFILE); - } - - @Test (expected = PolicyException.class) - public void bRMSHandlerFailTest3() throws PolicyException { - PropertyChange prop = new PropertyChange(); - prop.key = "repositoryID"; - prop.remove = true; - 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(INVALIDFILE); - } - - @Test (expected = PolicyException.class) - public void bRMSHandlerFailTest4() throws PolicyException { - PropertyChange prop = new PropertyChange(); - prop.key = "repositoryURL"; - prop.remove = true; - List<PropertyChange> props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BRMSHandler(INVALIDFILE); - } - - @Test (expected = PolicyException.class) - public void bRMSHandlerFailTest5() throws PolicyException { - PropertyChange prop = new PropertyChange(); - prop.key = "repositoryName"; - prop.remove = true; - List<PropertyChange> props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BRMSHandler(INVALIDFILE); - } - - @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; - List<PropertyChange> props = new LinkedList<>(); - props.add(prop); - prop = new PropertyChange(); - prop.key = "repositoryUsername"; - prop.remove = true; - props.add(prop); - setFailureProperties(props); - new BRMSHandler(INVALIDFILE); - } - - @Test (expected = PolicyException.class) - public void bRMSHandlerFailTest7() throws PolicyException { - PropertyChange prop = new PropertyChange(); - prop.key = "repositoryPassword"; - prop.remove = true; - List<PropertyChange> props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BRMSHandler(INVALIDFILE); - } - - @Test (expected = PolicyException.class) - public void bRMSHandlerFailTest8() throws PolicyException { - PropertyChange prop = new PropertyChange(); - prop.key = "policyKeyID"; - prop.remove = true; - List<PropertyChange> props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BRMSHandler(INVALIDFILE); - } - - @Test (expected = PolicyException.class) - public void bRMSHandlerFailTest9() throws PolicyException { - PropertyChange prop = new PropertyChange(); - prop.key = "sync"; - prop.value = "true"; - prop.remove = false; - 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(INVALIDFILE); - } - - @Test (expected = PolicyException.class) - public void bRMSHandlerFailTest10() throws PolicyException { - PropertyChange prop = new PropertyChange(); - prop.key = "groupNames"; - prop.value = ""; - prop.remove = false; - List<PropertyChange> props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BRMSHandler(INVALIDFILE); - } - - @Test (expected = PolicyException.class) - public void bRMSHandlerFailTest11() throws PolicyException { - PropertyChange prop = new PropertyChange(); - prop.key = "default.groupID"; - prop.remove = true; - List<PropertyChange> props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BRMSHandler(INVALIDFILE); - } - - @Test (expected = PolicyException.class) - public void bRMSHandlerFailTest12() throws PolicyException { - PropertyChange prop = new PropertyChange(); - prop.key = "default.artifactID"; - prop.remove = true; - List<PropertyChange> props = new LinkedList<>(); - props.add(prop); - setFailureProperties(props); - new BRMSHandler(INVALIDFILE); - } - - @Test (expected = PolicyException.class) - public void bRMSHandlerFailTest13() throws PolicyException { - PropertyChange prop = new PropertyChange(); - prop.key = "NOTIFICATION_TYPE"; - prop.value = "dmaap"; - prop.remove = false; - 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(INVALIDFILE); - } - - @Test - public void BRMSHandlerTest() throws PolicyException { - assertNotNull(new BRMSHandler(VALIDFILE)); - } - - private void setFailureProperties(List<PropertyChange> properties) throws PolicyException { - Properties validProp = new Properties(); - try { - validProp.load(new FileInputStream(VALIDFILE)); - for (PropertyChange prop: properties) { - if(prop.remove) { - validProp.remove(prop.key); - }else { - validProp.setProperty(prop.key, prop.value); - } - } - validProp.store(new FileOutputStream(INVALIDFILE), null); - } catch (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/BrmsJpaTest.java b/BRMSGateway/src/test/java/org/onap/brmsgw/test/BrmsJpaTest.java new file mode 100644 index 000000000..32ed314d5 --- /dev/null +++ b/BRMSGateway/src/test/java/org/onap/brmsgw/test/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.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<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/brmsgw/test/BrmsPushTest.java b/BRMSGateway/src/test/java/org/onap/brmsgw/test/BrmsPushTest.java new file mode 100644 index 000000000..36e633638 --- /dev/null +++ b/BRMSGateway/src/test/java/org/onap/brmsgw/test/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.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<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/brmsgw/test/ControllerPOJOTest.java b/BRMSGateway/src/test/java/org/onap/brmsgw/test/ControllerPojoTest.java index 5d736f61d..21534ddcd 100644 --- a/BRMSGateway/src/test/java/org/onap/brmsgw/test/ControllerPOJOTest.java +++ b/BRMSGateway/src/test/java/org/onap/brmsgw/test/ControllerPojoTest.java @@ -21,25 +21,27 @@ 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.brmsInterface.ControllerPOJO; +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(); -public class ControllerPOJOTest { - @Test - public void testPojo() { - String testKey = "testKey"; - String testVal = "testVal"; - Map<String, String> testMap = new HashMap<String, String>(); - testMap.put(testKey, testVal); - 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); - } + 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 index ef6585f5d..f83b749f7 100644 --- a/BRMSGateway/src/test/java/org/onap/brmsgw/test/NotificationPOJOTest.java +++ b/BRMSGateway/src/test/java/org/onap/brmsgw/test/NotificationPojoTest.java @@ -21,26 +21,28 @@ 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.brmsInterface.ControllerPOJO; -import org.onap.policy.brmsInterface.NotificationPOJO; +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(); -public class NotificationPOJOTest { - @Test - public void testPojo() { - String testVal = "testVal"; - ControllerPOJO ctrlPojo = new ControllerPOJO(); - List<ControllerPOJO> controllers = new ArrayList<ControllerPOJO>(); - controllers.add(ctrlPojo); - 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); - } + 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/brmsInterface/BRMSGatewayTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayTest.java index e0b38b666..b3f836fc5 100644 --- a/BRMSGateway/src/test/java/org/onap/policy/brmsInterface/BRMSGatewayTest.java +++ b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayTest.java @@ -18,11 +18,12 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.brmsInterface; +package org.onap.policy.brms.api; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; + import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; @@ -31,31 +32,30 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) -public class BRMSGatewayTest { - @Test - public void testGet() { - assertNull(BRMSGateway.getPolicyEngine()); - } +public class BrmsGatewayTest { + @Test + public void testGet() { + assertNull(BrmsGateway.getPolicyEngine()); + } - @PrepareForTest({Thread.class, BRMSGateway.class}) - @Test - public void testMain() throws Exception { - // Mock Thread - PowerMockito.spy(Thread.class); - PowerMockito.doNothing().when(Thread.class); - Thread.sleep(1000); + @PrepareForTest({Thread.class, BrmsGateway.class}) + @Test + public void testMain() throws Exception { + // Mock Thread + PowerMockito.spy(Thread.class); + PowerMockito.doNothing().when(Thread.class); + Thread.sleep(1000); - // Mock handler - BRMSHandler handler = Mockito.mock(BRMSHandler.class); - PowerMockito.whenNew(BRMSHandler.class).withArguments(any()).thenReturn(handler); + // Mock handler + final BrmsHandler handler = Mockito.mock(BrmsHandler.class); + PowerMockito.whenNew(BrmsHandler.class).withArguments(any()).thenReturn(handler); - // Run app - try { - String[] args = null; - BRMSGateway.main(args); - } - catch (Exception ex) { - fail("Not expected an exception: " + ex); - } - } + // Run app + try { + final String[] args = null; + BrmsGateway.main(args); + } catch (final Exception ex) { + fail("Not expected an exception: " + ex); + } + } } diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsHandlerTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsHandlerTest.java new file mode 100644 index 000000000..58bacef13 --- /dev/null +++ b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsHandlerTest.java @@ -0,0 +1,94 @@ +/*- + * ============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.api; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.Persistence; +import javax.persistence.Query; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.policy.api.NotificationType; +import org.onap.policy.std.StdPDPNotification; +import org.onap.policy.utils.BackUpMonitor; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class BrmsHandlerTest { + @PrepareForTest({Persistence.class, BackUpMonitor.class}) + @Test + public void negativeTestNotifications() throws Exception { + // Mock emf, persistence, and query + final EntityManagerFactory emf = Mockito.mock(EntityManagerFactory.class); + final EntityManager em = Mockito.mock(EntityManager.class); + Mockito.when(emf.createEntityManager()).thenReturn(em); + PowerMockito.mockStatic(Persistence.class); + PowerMockito.when(Persistence.createEntityManagerFactory(any(), any())).thenReturn(emf); + final EntityTransaction et = Mockito.mock(EntityTransaction.class); + Mockito.when(em.getTransaction()).thenReturn(et); + final Query query = Mockito.mock(Query.class); + Mockito.when(em.createQuery(Mockito.anyString())).thenReturn(query); + + // Mock backup monitor + PowerMockito.mockStatic(BackUpMonitor.class); + final BackUpMonitor monitor = Mockito.mock(BackUpMonitor.class); + PowerMockito.when(BackUpMonitor.getInstance(any(), any(), any(), any())).thenReturn(monitor); + + // Test constructor + final StdPDPNotification notification = new StdPDPNotification(); + final String propFile = "config.properties"; + final BrmsHandler handler = new BrmsHandler(propFile); + final BrmsPush brmsPush = new BrmsPush(propFile, handler); + handler.setBrmsPush(brmsPush); + assertNotNull(handler); + assertNotNull(brmsPush); + assertNull(handler.getPolicyEngine()); + + try { + // Test update + notification.setNotificationType(NotificationType.UPDATE); + handler.runOnNotification(notification); + handler.notificationReceived(notification); + + // Test remove + notification.setNotificationType(NotificationType.REMOVE); + handler.runOnNotification(notification); + handler.notificationReceived(notification); + + // Test both + notification.setNotificationType(NotificationType.BOTH); + handler.runOnNotification(notification); + handler.notificationReceived(notification); + } catch (final Exception ex) { + fail("Not expecting an exception: " + ex); + } + } +} diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsPushTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsPushTest.java new file mode 100644 index 000000000..2b13640d2 --- /dev/null +++ b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsPushTest.java @@ -0,0 +1,125 @@ +/*- + * ============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.api; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.Persistence; +import javax.persistence.Query; + +import org.apache.maven.model.Dependency; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.policy.api.PolicyException; +import org.onap.policy.utils.BackUpHandler; +import org.onap.policy.utils.BackUpMonitor; +import org.onap.policy.utils.BackUpMonitorException; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class BrmsPushTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @PrepareForTest({Persistence.class, BackUpMonitor.class}) + @Test + public void testPush() throws BackUpMonitorException, PolicyException { + // Mock emf, persistence, and query + final EntityManagerFactory emf = Mockito.mock(EntityManagerFactory.class); + final EntityManager em = Mockito.mock(EntityManager.class); + Mockito.when(emf.createEntityManager()).thenReturn(em); + PowerMockito.mockStatic(Persistence.class); + PowerMockito.when(Persistence.createEntityManagerFactory(Mockito.any(), Mockito.any())).thenReturn(emf); + final EntityTransaction et = Mockito.mock(EntityTransaction.class); + Mockito.when(em.getTransaction()).thenReturn(et); + final Query query = Mockito.mock(Query.class); + Mockito.when(em.createQuery(Mockito.anyString())).thenReturn(query); + + // Mock backup monitor + PowerMockito.mockStatic(BackUpMonitor.class); + final BackUpMonitor monitor = Mockito.mock(BackUpMonitor.class); + PowerMockito.when(BackUpMonitor.getInstance(any(), any(), any(), any())).thenReturn(monitor); + + // Test constructor + final String propFile = "config.properties"; + final BackUpHandler handler = Mockito.mock(BackUpHandler.class); + final BrmsPush push = new BrmsPush(propFile, handler); + assertNotNull(push); + + final String name = "testName"; + try { + // Test initiate + push.initiate(true); + + // Test reset + push.resetDs(); + + // Test add + final String rule = "testRule"; + final Map<String, String> responseAttributes = new HashMap<String, String>(); + responseAttributes.put("$controller:", "{\n\"testKey\": \"testVal\"\n}\n"); + responseAttributes.put("$dependency$", "[a,b]"); + push.addRule(name, rule, responseAttributes); + } catch (final Exception ex) { + fail("Not expecting an exception: " + ex); + } + + try { + // Test remove + push.removeRule(name); + } catch (final Exception ex) { + fail("Not expecting an exception: " + ex); + + } + + // Test misc methods + final String controllerName = "testController"; + final List<Dependency> deps = push.defaultDependencies(controllerName); + assertEquals(deps.size(), 7); + assertNotNull(BrmsPush.getBackUpMonitor()); + assertEquals(push.urlListSize(), 1); + + try { + push.rotateUrls(); + } catch (final Exception ex) { + fail("Not expecting an exception: " + ex); + } + + // Test push + thrown.expect(PolicyException.class); + push.pushRules(); + } +} diff --git a/BRMSGateway/src/test/java/org/onap/policy/brmsInterface/BRMSHandlerTest.java b/BRMSGateway/src/test/java/org/onap/policy/brmsInterface/BRMSHandlerTest.java deleted file mode 100644 index 8e15cdf28..000000000 --- a/BRMSGateway/src/test/java/org/onap/policy/brmsInterface/BRMSHandlerTest.java +++ /dev/null @@ -1,93 +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.policy.brmsInterface; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.EntityTransaction; -import javax.persistence.Persistence; -import javax.persistence.Query; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.onap.policy.api.NotificationType; -import org.onap.policy.std.StdPDPNotification; -import org.onap.policy.utils.BackUpMonitor; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -public class BRMSHandlerTest { - @PrepareForTest({Persistence.class, BackUpMonitor.class}) - @Test - public void negativeTestNotifications() throws Exception { - // Mock emf, persistence, and query - EntityManagerFactory emf = Mockito.mock(EntityManagerFactory.class); - EntityManager em = Mockito.mock(EntityManager.class); - Mockito.when(emf.createEntityManager()).thenReturn(em); - PowerMockito.mockStatic(Persistence.class); - PowerMockito.when(Persistence.createEntityManagerFactory(any(), any())).thenReturn(emf); - EntityTransaction et = Mockito.mock(EntityTransaction.class); - Mockito.when(em.getTransaction()).thenReturn(et); - Query query = Mockito.mock(Query.class); - Mockito.when(em.createQuery(Mockito.anyString())).thenReturn(query); - - // Mock backup monitor - PowerMockito.mockStatic(BackUpMonitor.class); - BackUpMonitor monitor = Mockito.mock(BackUpMonitor.class); - PowerMockito.when(BackUpMonitor.getInstance(any(), any(), any(), any())).thenReturn(monitor); - - // Test constructor - StdPDPNotification notification = new StdPDPNotification(); - String propFile = "config.properties"; - BRMSHandler handler = new BRMSHandler(propFile); - BRMSPush brmsPush = new BRMSPush(propFile, handler); - handler.setBRMSPush(brmsPush); - assertNotNull(handler); - assertNotNull(brmsPush); - assertNull(handler.getPolicyEngine()); - - try { - // Test update - notification.setNotificationType(NotificationType.UPDATE); - handler.runOnNotification(notification); - handler.notificationReceived(notification); - - // Test remove - notification.setNotificationType(NotificationType.REMOVE); - handler.runOnNotification(notification); - handler.notificationReceived(notification); - - // Test both - notification.setNotificationType(NotificationType.BOTH); - handler.runOnNotification(notification); - handler.notificationReceived(notification); - } - catch (Exception ex) { - fail("Not expecting an exception: " + ex); - } - } -} diff --git a/BRMSGateway/src/test/java/org/onap/policy/brmsInterface/BRMSPushTest.java b/BRMSGateway/src/test/java/org/onap/policy/brmsInterface/BRMSPushTest.java deleted file mode 100644 index 5ca2b309c..000000000 --- a/BRMSGateway/src/test/java/org/onap/policy/brmsInterface/BRMSPushTest.java +++ /dev/null @@ -1,125 +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.policy.brmsInterface; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.EntityTransaction; -import javax.persistence.Persistence; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.onap.policy.api.PolicyException; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.onap.policy.utils.BackUpHandler; -import org.onap.policy.utils.BackUpMonitor; -import org.onap.policy.utils.BackUpMonitorException; -import org.apache.maven.model.Dependency; -import javax.persistence.Query; - -@RunWith(PowerMockRunner.class) -public class BRMSPushTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @PrepareForTest({Persistence.class, BackUpMonitor.class}) - @Test - public void testPush() throws BackUpMonitorException, PolicyException { - // Mock emf, persistence, and query - EntityManagerFactory emf = Mockito.mock(EntityManagerFactory.class); - EntityManager em = Mockito.mock(EntityManager.class); - Mockito.when(emf.createEntityManager()).thenReturn(em); - PowerMockito.mockStatic(Persistence.class); - PowerMockito.when(Persistence.createEntityManagerFactory(Mockito.any(), Mockito.any())).thenReturn(emf); - EntityTransaction et = Mockito.mock(EntityTransaction.class); - Mockito.when(em.getTransaction()).thenReturn(et); - Query query = Mockito.mock(Query.class); - Mockito.when(em.createQuery(Mockito.anyString())).thenReturn(query); - - // Mock backup monitor - PowerMockito.mockStatic(BackUpMonitor.class); - BackUpMonitor monitor = Mockito.mock(BackUpMonitor.class); - PowerMockito.when(BackUpMonitor.getInstance(any(), any(), any(), any())).thenReturn(monitor); - - // Test constructor - String propFile = "config.properties"; - BackUpHandler handler = Mockito.mock(BackUpHandler.class); - BRMSPush push = new BRMSPush(propFile, handler); - assertNotNull(push); - - String name = "testName"; - try { - // Test initiate - push.initiate(true); - - // Test reset - push.resetDS(); - - // Test add - String rule = "testRule"; - Map<String, String> responseAttributes = new HashMap<String, String>(); - responseAttributes.put("$controller:", "{\n\"testKey\": \"testVal\"\n}\n"); - responseAttributes.put("$dependency$", "[a,b]"); - push.addRule(name, rule, responseAttributes); - } - catch (Exception ex) { - fail("Not expecting an exception: " + ex); - } - - try { - // Test remove - push.removeRule(name); - } - catch (Exception ex) { - fail("Not expecting an exception: " + ex); - - } - - // Test misc methods - String controllerName = "testController"; - List<Dependency> deps = push.defaultDependencies(controllerName); - assertEquals(deps.size(), 7); - assertNotNull(BRMSPush.getBackUpMonitor()); - assertEquals(push.urlListSize(), 1); - - try { - push.rotateURLs(); - } - catch (Exception ex) { - fail("Not expecting an exception: " + ex); - } - - // Test push - thrown.expect(PolicyException.class); - push.pushRules(); - } -} |