diff options
Diffstat (limited to 'plugins')
10 files changed, 750 insertions, 37 deletions
diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/pom.xml b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/pom.xml index 2dcdcf8de..8424969d7 100644 --- a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/pom.xml +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/pom.xml @@ -1,6 +1,7 @@ <!-- ============LICENSE_START======================================================= Copyright (C) 2018 Ericsson. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -47,11 +48,11 @@ <artifactId>curator-recipes</artifactId> <version>4.0.1</version> </dependency> - <!-- The latest Zookeeper version fixes the vulnerabilities --> + <!-- This Zookeeper version fixes the vulnerabilities --> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> - <version>3.5.4-beta</version> + <version>3.4.13</version> <exclusions> <!-- Zookeeper uses an ancient version of log4j --> <exclusion> diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java index bc8ce9055..ce727b8bf 100644 --- a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -32,6 +33,8 @@ import org.apache.curator.utils.CloseableUtils; import org.apache.zookeeper.CreateMode; import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.context.impl.locking.AbstractLockManager; +import org.onap.policy.apex.context.parameters.ContextParameterConstants; +import org.onap.policy.apex.context.parameters.LockManagerParameters; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.common.parameters.ParameterService; import org.slf4j.ext.XLogger; @@ -75,11 +78,19 @@ public class CuratorLockManager extends AbstractLockManager { super.init(key); // Get the lock manager parameters - final CuratorLockManagerParameters lockParameters = ParameterService - .get(CuratorLockManagerParameters.class.getSimpleName()); + final LockManagerParameters lockParameters = ParameterService.get(ContextParameterConstants.LOCKING_GROUP_NAME); + + if (!(lockParameters instanceof CuratorLockManagerParameters)) { + String message = "could not set up Curator locking, " + + "curator lock manager parameters are not set"; + LOGGER.warn(message); + throw new ContextException(message); + } + + final CuratorLockManagerParameters curatorLockPars = (CuratorLockManagerParameters)lockParameters; // Check if the curator address has been set - curatorZookeeperAddress = lockParameters.getZookeeperAddress(); + curatorZookeeperAddress = curatorLockPars.getZookeeperAddress(); if (curatorZookeeperAddress == null || curatorZookeeperAddress.trim().length() == 0) { String message = "could not set up Curator locking, " + "check if the curator Zookeeper address parameter is set correctly"; @@ -89,8 +100,8 @@ public class CuratorLockManager extends AbstractLockManager { // Set up the curator framework we'll use curatorFramework = CuratorFrameworkFactory.builder().connectString(curatorZookeeperAddress) - .retryPolicy(new ExponentialBackoffRetry(lockParameters.getZookeeperConnectSleepTime(), - lockParameters.getZookeeperContextRetries())) + .retryPolicy(new ExponentialBackoffRetry(curatorLockPars.getZookeeperConnectSleepTime(), + curatorLockPars.getZookeeperContextRetries())) .build(); // Listen for changes on the Curator connection @@ -102,8 +113,8 @@ public class CuratorLockManager extends AbstractLockManager { // Wait for the connection to be made try { curatorFramework.blockUntilConnected( - lockParameters.getZookeeperConnectSleepTime() * lockParameters.getZookeeperContextRetries(), - TimeUnit.MILLISECONDS); + curatorLockPars.getZookeeperConnectSleepTime() * curatorLockPars.getZookeeperContextRetries(), + TimeUnit.MILLISECONDS); } catch (final InterruptedException e) { // restore the interrupt status Thread.currentThread().interrupt(); @@ -123,7 +134,7 @@ public class CuratorLockManager extends AbstractLockManager { // We'll use Ephemeral nodes for locks on the Zookeeper server curatorFramework.create().withMode(CreateMode.EPHEMERAL_SEQUENTIAL); - LOGGER.exit("init(" + key + "," + lockParameters + ")"); + LOGGER.exit("init(" + key + "," + curatorLockPars + ")"); } /* diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java index ac936d436..39972a7f1 100644 --- a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -30,7 +31,7 @@ import org.onap.policy.apex.context.parameters.LockManagerParameters; public class CuratorLockManagerParameters extends LockManagerParameters { // @formatter:off /** The default address used to connect to the Zookeeper server. */ - public static final String DEFAULT_ZOOKEEPER_ADDRESS = "localhost:2181"; + public static final String DEFAULT_ZOOKEEPER_ADDRESS = "localhost:2181"; /** The default sleep time to use when connecting to the Zookeeper server. */ public static final int DEFAULT_ZOOKEEPER_CONNECT_SLEEP_TIME = 1000; diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java new file mode 100644 index 000000000..4c10cefe9 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Samsung. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.policy.apex.plugins.event.carrier.jms; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import javax.jms.Message; +import javax.jms.Session; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventProducer; +import org.onap.policy.apex.service.engine.event.ApexEventReceiver; +import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; + +public class ApexJmsConsumerTest { + + ApexJmsConsumer apexJmsConsumer = null; + EventHandlerParameters consumerParameters = null; + ApexEventReceiver incomingEventReceiver = null; + ApexEventProducer apexJmsProducer = null; + Session jmsSession = null; + JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null; + + /** + * Set up testing. + * + * @throws Exception on test set up errors. + */ + @Before + public void setUp() throws Exception { + apexJmsConsumer = new ApexJmsConsumer(); + consumerParameters = new EventHandlerParameters(); + apexJmsProducer = new ApexJmsProducer(); + } + + @Test(expected = ApexEventException.class) + public void testInitWithNonJmsCarrierTechnologyParameters() throws ApexEventException { + consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {}); + apexJmsConsumer.init("TestApexJmsConsumer", consumerParameters, incomingEventReceiver); + } + + @Test(expected = ApexEventException.class) + public void testInitWithJmsCarrierTechnologyParameters() throws ApexEventException { + jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters(); + consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters); + apexJmsConsumer.init("TestApexJmsConsumer", consumerParameters, incomingEventReceiver); + } + + @Test + public void testStart() { + apexJmsConsumer.start(); + } + + @Test + public void testGetName() { + assertNull(apexJmsConsumer.getName()); + } + + @Test + public void testGetPeeredReference() { + assertNull(apexJmsConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); + } + + @Test + public void testSetPeeredReference() { + PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR, + apexJmsConsumer, apexJmsProducer); + apexJmsConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference); + assertNotNull(apexJmsConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); + } + + @Test(expected = ApexEventRuntimeException.class) + public void testRun() { + apexJmsConsumer.run(); + + } + + @Test(expected = ApexEventRuntimeException.class) + public void testOnMessage() { + Message jmsMessage = null; + apexJmsConsumer.onMessage(jmsMessage); + } + + @Test(expected = NullPointerException.class) + public void testStop() { + apexJmsConsumer.stop(); + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java new file mode 100644 index 000000000..4773296d9 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java @@ -0,0 +1,119 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Samsung. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.policy.apex.plugins.event.carrier.jms; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import javax.jms.Session; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.service.engine.event.ApexEvent; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventProducer; +import org.onap.policy.apex.service.engine.event.ApexEventReceiver; +import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.engine.event.SynchronousEventCache; +import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; + +public class ApexJmsProducerTest { + + ApexJmsConsumer apexJmsConsumer = null; + EventHandlerParameters producerParameters = null; + ApexEventReceiver incomingEventReceiver = null; + ApexEventProducer apexJmsProducer = null; + Session jmsSession = null; + JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null; + SynchronousEventCache synchronousEventCache = null; + private static final long DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT = 1000; + + /** + * Set up testing. + * + * @throws Exception on test set up errors. + */ + @Before + public void setUp() throws Exception { + apexJmsConsumer = new ApexJmsConsumer(); + producerParameters = new EventHandlerParameters(); + apexJmsProducer = new ApexJmsProducer(); + } + + @Test(expected = ApexEventException.class) + public void testInitWithNonJmsCarrierTechnologyParameters() throws ApexEventException { + producerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {}); + apexJmsProducer.init("TestApexJmsProducer", producerParameters); + } + + @Test(expected = ApexEventException.class) + public void testInitWithJmsCarrierTechnologyParameters() throws ApexEventException { + jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters(); + producerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters); + apexJmsProducer.init("TestApexJmsProducer", producerParameters); + } + + @Test + public void testGetName() { + assertNull(apexJmsProducer.getName()); + } + + @Test + public void testGetPeeredReference() { + assertNull(apexJmsProducer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); + } + + @Test + public void testSetPeeredReference() { + PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR, + apexJmsConsumer, apexJmsProducer); + apexJmsProducer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference); + assertNotNull(apexJmsProducer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); + } + + @Test(expected = NullPointerException.class) + public void testSendEvent() throws ApexEventException { + producerParameters.setCarrierTechnologyParameters(new JmsCarrierTechnologyParameters() {}); + synchronousEventCache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, + apexJmsConsumer, apexJmsProducer, DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT); + apexJmsProducer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, + synchronousEventCache); + ApexEvent apexEvent = new ApexEvent("testEvent", "testVersion", "testNameSpace", + "testSource", "testTarget"); + apexJmsProducer.sendEvent(1000L, "TestApexJmsProducer", apexEvent); + } + + @Test(expected = ApexEventRuntimeException.class) + public void testSendEventWithNonSerializableObject() throws ApexEventException { + producerParameters.setCarrierTechnologyParameters(new JmsCarrierTechnologyParameters() {}); + synchronousEventCache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, + apexJmsConsumer, apexJmsProducer, DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT); + apexJmsProducer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, + synchronousEventCache); + apexJmsProducer.sendEvent(-1L, "TestApexJmsProducer", new ApexJmsProducerTest()); + } + + @Test + public void testStop() { + apexJmsProducer.stop(); + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java new file mode 100644 index 000000000..32d712411 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java @@ -0,0 +1,216 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Samsung. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.policy.apex.plugins.event.carrier.jms; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Base64; +import java.util.Properties; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ParameterRuntimeException; + +public class JmsCarrierTechnologyParametersTest { + + JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null; + Properties jmsProducerProperties = null; + Properties jmsConsumerProperties = null; + GroupValidationResult result = null; + + public static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS"; + + public static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS = + ApexJmsProducer.class.getCanonicalName(); + + public static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS = + ApexJmsConsumer.class.getCanonicalName(); + + private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory"; + private static final String DEFAULT_INITIAL_CTXT_FACTORY = + "org.jboss.naming.remote.client.InitialContextFactory"; + private static final String DEFAULT_PROVIDER_URL = "remote://localhost:4447"; + private static final String DEFAULT_SECURITY_PRINCIPAL = "userid"; + private static final String DEFAULT_SECURITY_CREDENTIALS = "cGFzc3dvcmQ="; + private static final String DEFAULT_CONSUMER_TOPIC = "apex-in"; + private static final String DEFAULT_PRODUCER_TOPIC = "apex-out"; + private static final int DEFAULT_CONSUMER_WAIT_TIME = 100; + private static final boolean DEFAULT_TO_OBJECT_MSG_SENDING = true; + + /** + * Set up testing. + * + * @throws Exception on test set up errors. + */ + @Before + public void setUp() throws Exception { + jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters(); + } + + @Test + public void testValidate() { + result = jmsCarrierTechnologyParameters.validate(); + assertNotNull(result); + assertTrue(result.getStatus().isValid()); + } + + @Test + public void testJmsCarrierTechnologyParameters() { + assertNotNull(jmsCarrierTechnologyParameters); + } + + @Test + public void testGetJmsProducerProperties() { + assertNotNull(jmsCarrierTechnologyParameters.getJmsConsumerProperties()); + } + + @Test + public void testGetJmsConsumerProperties() { + assertNotNull(jmsCarrierTechnologyParameters.getJmsProducerProperties()); + } + + @Test + public void testEqualityOfJmsConsumerAndProducerProperties() { + assertEquals(jmsCarrierTechnologyParameters.getJmsProducerProperties(), + jmsCarrierTechnologyParameters.getJmsConsumerProperties()); + } + + @Test + public void testGetConnectionFactory() { + assertEquals(DEFAULT_CONNECTION_FACTORY, + jmsCarrierTechnologyParameters.getConnectionFactory()); + } + + @Test + public void testSetConnectionFactory() { + jmsCarrierTechnologyParameters.setConnectionFactory("QueueConnectionFactory"); + assertNotEquals(DEFAULT_CONNECTION_FACTORY, + jmsCarrierTechnologyParameters.getConnectionFactory()); + } + + @Test + public void testSetConsumerTopic() { + assertEquals(DEFAULT_CONSUMER_TOPIC, jmsCarrierTechnologyParameters.getConsumerTopic()); + jmsCarrierTechnologyParameters.setConsumerTopic(null); + result = jmsCarrierTechnologyParameters.validate(); + assertFalse(result.getStatus().isValid()); + } + + @Test + public void testSetConsumerWaitTime() { + assertEquals(DEFAULT_CONSUMER_WAIT_TIME, + jmsCarrierTechnologyParameters.getConsumerWaitTime()); + jmsCarrierTechnologyParameters.setConsumerWaitTime(-1); + assertNotEquals(DEFAULT_CONSUMER_WAIT_TIME, + jmsCarrierTechnologyParameters.getConsumerWaitTime()); + } + + @Test + public void testSetEventConsumerPluginClass() { + assertEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS, + jmsCarrierTechnologyParameters.getEventConsumerPluginClass()); + jmsCarrierTechnologyParameters.setEventConsumerPluginClass("TestEventConsumerPluginClass"); + assertNotEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS, + jmsCarrierTechnologyParameters.getEventConsumerPluginClass()); + } + + @Test + public void testSetEventProducerPluginClass() { + assertEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS, + jmsCarrierTechnologyParameters.getEventProducerPluginClass()); + jmsCarrierTechnologyParameters.setEventProducerPluginClass("TestEventProducerPluginClass"); + assertNotEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS, + jmsCarrierTechnologyParameters.getEventProducerPluginClass()); + } + + @Test + public void testSetLabel() { + assertEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel()); + jmsCarrierTechnologyParameters.setLabel("TestLable"); + assertNotEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel()); + + } + + @Test + public void testSetObjectMessageSending() { + assertTrue(jmsCarrierTechnologyParameters.isObjectMessageSending()); + jmsCarrierTechnologyParameters.setObjectMessageSending(!DEFAULT_TO_OBJECT_MSG_SENDING); + assertFalse(jmsCarrierTechnologyParameters.isObjectMessageSending()); + } + + @Test + public void testSetProducerTopic() { + assertEquals(DEFAULT_PRODUCER_TOPIC, jmsCarrierTechnologyParameters.getProducerTopic()); + jmsCarrierTechnologyParameters.setProducerTopic(""); + result = jmsCarrierTechnologyParameters.validate(); + assertFalse(result.getStatus().isValid()); + } + + @Test + public void testSetProviderUrl() { + assertEquals(DEFAULT_PROVIDER_URL, jmsCarrierTechnologyParameters.getProviderUrl()); + jmsCarrierTechnologyParameters.setProviderUrl(null); + result = jmsCarrierTechnologyParameters.validate(); + assertFalse(result.getStatus().isValid()); + } + + @Test + public void testSetSecurityCredentials() { + assertEquals( + new String(Base64.getDecoder().decode(DEFAULT_SECURITY_CREDENTIALS.getBytes())), + jmsCarrierTechnologyParameters.getSecurityCredentials()); + jmsCarrierTechnologyParameters.setSecurityCredentials(""); + result = jmsCarrierTechnologyParameters.validate(); + assertFalse(result.getStatus().isValid()); + } + + @Test + public void testSetSecurityPrincipal() { + assertEquals(DEFAULT_SECURITY_PRINCIPAL, + jmsCarrierTechnologyParameters.getSecurityPrincipal()); + jmsCarrierTechnologyParameters.setSecurityPrincipal(null); + result = jmsCarrierTechnologyParameters.validate(); + assertFalse(result.getStatus().isValid()); + } + + @Test + public void testSetInitialContextFactory() { + + assertEquals(DEFAULT_INITIAL_CTXT_FACTORY, + jmsCarrierTechnologyParameters.getInitialContextFactory()); + + jmsCarrierTechnologyParameters.setInitialContextFactory(null); + result = jmsCarrierTechnologyParameters.validate(); + assertFalse(result.getStatus().isValid()); + + jmsCarrierTechnologyParameters.setInitialContextFactory("TestInitialContextFactory"); + assertNotEquals(DEFAULT_INITIAL_CTXT_FACTORY, + jmsCarrierTechnologyParameters.getInitialContextFactory()); + } + + @Test(expected = ParameterRuntimeException.class) + public void testSetName() { + jmsCarrierTechnologyParameters.setName("TestName"); + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java new file mode 100644 index 000000000..bbebbc3b8 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Samsung. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.kafka; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventProducer; +import org.onap.policy.apex.service.engine.event.ApexEventReceiver; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; + +public class ApexKafkaConsumerTest { + ApexKafkaConsumer apexKafkaConsumer = null; + EventHandlerParameters consumerParameters = null; + ApexEventReceiver incomingEventReceiver = null; + ApexEventProducer apexKafkaProducer = null; + + /** + * Set up testing. + * + * @throws ApexEventException on test set up errors. + */ + @Before + public void setUp() throws ApexEventException { + apexKafkaConsumer = new ApexKafkaConsumer(); + consumerParameters = new EventHandlerParameters(); + apexKafkaProducer = new ApexKafkaProducer(); + consumerParameters + .setCarrierTechnologyParameters(new KafkaCarrierTechnologyParameters() {}); + apexKafkaConsumer.init("TestApexKafkaConsumer", consumerParameters, incomingEventReceiver); + } + + @Test + public void testStart() { + apexKafkaConsumer.start(); + } + + @Test + public void testGetName() { + assertEquals("TestApexKafkaConsumer", apexKafkaConsumer.getName()); + } + + @Test + public void testGetPeeredReference() { + assertNull(apexKafkaConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); + } + + @Test + public void testSetPeeredReference() { + PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR, + apexKafkaConsumer, apexKafkaProducer); + apexKafkaConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference); + assertNotNull(apexKafkaConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); + } + + @Test(expected = java.lang.NullPointerException.class) + public void testRun() { + apexKafkaConsumer.run(); + } + + @Test(expected = java.lang.NullPointerException.class) + public void testStop() { + apexKafkaConsumer.stop(); + } + + @Test(expected = ApexEventException.class) + public void testInitWithNonKafkaCarrierTechnologyParameters() throws ApexEventException { + consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {}); + apexKafkaConsumer.init("TestApexKafkaConsumer", consumerParameters, incomingEventReceiver); + } + +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java new file mode 100644 index 000000000..7300474c7 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Samsung. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.kafka; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.engine.event.SynchronousEventCache; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; + +public class ApexKafkaProducerTest { + ApexKafkaProducer apexKafkaProducer = null; + ApexKafkaConsumer apexKafkaConsumer = null; + EventHandlerParameters producerParameters = null; + PeeredReference peeredReference = null; + SynchronousEventCache synchronousEventCache = null; + private static final long DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT = 1000; + + /** + * Set up testing. + */ + @Before + public void setUp() throws Exception { + apexKafkaProducer = new ApexKafkaProducer(); + apexKafkaConsumer = new ApexKafkaConsumer(); + producerParameters = new EventHandlerParameters(); + + } + + @Test(expected = ApexEventException.class) + public void testInit() throws ApexEventException { + apexKafkaProducer.init("TestApexKafkaProducer", producerParameters); + } + + @Test + public void testGetName() { + assertNull(apexKafkaProducer.getName()); + } + + @Test + public void testGetPeeredReference() { + assertNull(apexKafkaProducer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); + } + + @Test + public void testWithProperValues() throws ApexEventException { + producerParameters + .setCarrierTechnologyParameters(new KafkaCarrierTechnologyParameters() {}); + synchronousEventCache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, + apexKafkaConsumer, apexKafkaProducer, DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT); + apexKafkaProducer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, + synchronousEventCache); + apexKafkaProducer.init("TestApexKafkaProducer", producerParameters); + assertEquals("TestApexKafkaProducer", apexKafkaProducer.getName()); + assertNotNull(apexKafkaProducer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); + apexKafkaProducer.stop(); + } + +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java new file mode 100644 index 000000000..6eca1dcf0 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Samsung. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.kafka; + +import static org.junit.Assert.assertNotNull; + +import java.util.Properties; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.parameters.GroupValidationResult; + +public class KafkaCarrierTechnologyParametersTest { + + KafkaCarrierTechnologyParameters kafkaCarrierTechnologyParameters = null; + Properties kafkaProducerProperties = null; + Properties kafkaConsumerProperties = null; + GroupValidationResult result = null; + + /** + * Set up testing. + * + * @throws Exception on setup errors + */ + @Before + public void setUp() throws Exception { + kafkaCarrierTechnologyParameters = new KafkaCarrierTechnologyParameters(); + kafkaProducerProperties = kafkaCarrierTechnologyParameters.getKafkaProducerProperties(); + kafkaConsumerProperties = kafkaCarrierTechnologyParameters.getKafkaConsumerProperties(); + } + + @Test + public void testKafkaCarrierTechnologyParameters() { + assertNotNull(kafkaCarrierTechnologyParameters); + } + + @Test + public void testGetKafkaProducerProperties() { + assertNotNull(kafkaProducerProperties); + } + + @Test + public void testGetKafkaConsumerProperties() { + assertNotNull(kafkaConsumerProperties); + } + + @Test + public void testValidate() { + result = kafkaCarrierTechnologyParameters.validate(); + assertNotNull(result); + } +} diff --git a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/pom.xml b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/pom.xml index 2343a3ab8..ae2def8d2 100644 --- a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/pom.xml +++ b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/pom.xml @@ -1,23 +1,17 @@ -<!-- - ============LICENSE_START======================================================= - 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. - - SPDX-License-Identifier: Apache-2.0 - ============LICENSE_END========================================================= ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<!-- ============LICENSE_START======================================================= + Copyright (C) 2018 Ericsson. All rights reserved. Modifications Copyright + (C) 2019 Nordix Foundation. ================================================================================ + 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. SPDX-License-Identifier: + Apache-2.0 ============LICENSE_END========================================================= --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.policy.apex-pdp.plugins.plugins-persistence.plugins-persistence-jpa</groupId> @@ -72,6 +66,17 @@ <groupId>org.hibernate</groupId> <artifactId>hibernate-c3p0</artifactId> <version>${version.hibernate}</version> + <exclusions> + <exclusion> + <groupId>com.mchange</groupId> + <artifactId>c3p0</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>com.mchange</groupId> + <artifactId>c3p0</artifactId> + <version>0.9.5.3</version> </dependency> </dependencies> |