diff options
Diffstat (limited to 'appc-dg/appc-dg-shared')
11 files changed, 225 insertions, 37 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImpl.java index d5bf8a9c3..4cef62581 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImpl.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImpl.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications (C) 2018 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +38,6 @@ import java.util.Set; import org.apache.commons.lang3.StringUtils; import org.onap.appc.adapter.message.MessageAdapterFactory; import org.onap.appc.adapter.message.Producer; -import org.onap.appc.configuration.Configuration; import org.onap.appc.configuration.ConfigurationFactory; import org.onap.appc.dg.common.IntermediateMessageSender; import org.onap.appc.exceptions.APPCException; @@ -82,8 +83,8 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender if (ctx != null) { ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName()); if (svcRef != null) { - producer = ((MessageAdapterFactory) ctx.getService(svcRef)) - .createProducer(pool, writeTopic, apiKey, apiSecret); + MessageAdapterFactory messageAdapterFactory = ((MessageAdapterFactory) ctx.getService(svcRef)); + producer = messageAdapterFactory.createProducer(pool, writeTopic, apiKey, apiSecret); } } } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java index 71b8062bc..95f7ba755 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications (C) 2018 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +25,8 @@ package org.onap.appc.dg.common.impl; +import java.util.HashMap; +import java.util.Map; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -43,12 +47,10 @@ import org.osgi.framework.ServiceReference; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import java.util.HashMap; -import java.util.Map; @RunWith(PowerMockRunner.class) -@PrepareForTest({DCAEReporterPluginImpl.class, FrameworkUtil.class}) +@PrepareForTest(FrameworkUtil.class) public class DCAEReporterPluginImplTest { private SvcLogicContext ctx; private Map<String, String> params; @@ -99,6 +101,29 @@ public class DCAEReporterPluginImplTest { positiveAssert(); } + @Test + public void testReportErrorDefinition() throws APPCException { + ctx = new SvcLogicContext(); + params = new HashMap<>(); + params.put(Constants.EVENT_MESSAGE, "ERROR DESCRIPTION"); + params.put(Constants.DG_ERROR_CODE, "200"); + ctx.setAttribute("input.common-header.api-ver", apiVer); + ctx.setAttribute("input.common-header.request-id", requestId); + dcaeReporterPlugin.report(params, ctx); + EventMessage msg = eventSender.getMsg(); + Assert.assertEquals("ERROR DESCRIPTION", msg.getEventStatus().getReason()); + } + + @Test + public void testReportSuccess() throws APPCException { + ctx = new SvcLogicContext(); + params = new HashMap<>(); + params.put(Constants.DG_ERROR_CODE, "200"); + dcaeReporterPlugin.reportSuccess(params, ctx); + EventMessage msg = eventSender.getMsg(); + Assert.assertEquals(new Integer(500), msg.getEventStatus().getCode()); + } + private void errorReasonNullAssert() throws APPCException { dcaeReporterPlugin.report(params, ctx); MessageDestination destination = eventSender.getDestination(); diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java index 774739105..54959958d 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java @@ -24,7 +24,6 @@ package org.onap.appc.dg.common.impl; import java.util.Map; - import org.onap.appc.adapter.message.EventSender; import org.onap.appc.adapter.message.MessageDestination; import org.onap.appc.adapter.message.event.EventMessage; diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImplTest.java new file mode 100644 index 000000000..74c1ec7a5 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImplTest.java @@ -0,0 +1,96 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2018 Ericsson + * ============================================================================= + * 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.appc.dg.common.impl; + +import java.util.HashMap; +import java.util.Map; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.onap.appc.adapter.message.MessageAdapterFactory; +import org.onap.appc.adapter.message.Producer; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(FrameworkUtil.class) +public class IntermediateMessageSenderImplTest { + + private SvcLogicContext ctx; + private Map<String, String> params; + + private final BundleContext bundleContext = Mockito.mock(BundleContext.class); + private final Bundle bundleService = Mockito.mock(Bundle.class); + private final ServiceReference sref = Mockito.mock(ServiceReference.class); + private final MessageAdapterFactory mockFactory = Mockito.mock(MessageAdapterFactory.class); + private final Producer mockProducer = Mockito.mock(Producer.class); + + @InjectMocks + private IntermediateMessageSenderImpl intermediateMessageSenderImpl; + + @Spy + private EventSenderMock eventSender = new EventSenderMock(); + + @SuppressWarnings("unchecked") + @Before + public void setUp() throws NoSuchFieldException, IllegalAccessException { + PowerMockito.mockStatic(FrameworkUtil.class); + PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService); + PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext); + PowerMockito.when(bundleContext.getServiceReference(Matchers.any(Class.class))).thenReturn(sref); + PowerMockito.when(bundleContext.<MessageAdapterFactory>getService(sref)).thenReturn(mockFactory); + PowerMockito.when(mockFactory.createProducer(Matchers.anyCollection(), Mockito.anyString(), Mockito.anyString(), + Mockito.anyString())).thenReturn(mockProducer); + } + + @Test + public void testSendEmptyMessage() { + intermediateMessageSenderImpl.init(); + ctx = new SvcLogicContext(); + params = new HashMap<>(); + intermediateMessageSenderImpl.sendMessage(params, ctx); + Assert.assertEquals("FAILURE", ctx.getAttribute("STATUS")); + } + + @Test + public void testSendMessage() { + intermediateMessageSenderImpl.init(); + ctx = new SvcLogicContext(); + ctx.setAttribute("input.common-header.request-id", "REQUEST-ID"); + params = new HashMap<>(); + params.put("message", "TEST MESSAGE"); + params.put("code", "TEST CODE"); + intermediateMessageSenderImpl.sendMessage(params, ctx); + Assert.assertEquals("SUCCESS", ctx.getAttribute("STATUS")); + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/JsonDgUtilImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/JsonDgUtilImplTest.java index 8adaaeead..950cb2f1a 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/JsonDgUtilImplTest.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/JsonDgUtilImplTest.java @@ -27,11 +27,9 @@ package org.onap.appc.dg.common.impl; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; - import java.text.SimpleDateFormat; import java.util.HashMap; import java.util.Map; - import org.junit.Assert; import org.junit.Before; import org.junit.Test; diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVNFConfiguratorImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVNFConfiguratorImpl.java index 21213cab6..8b08fc288 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVNFConfiguratorImpl.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVNFConfiguratorImpl.java @@ -23,26 +23,25 @@ package org.onap.appc.dg.common.impl; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; import org.onap.appc.dg.common.VNFConfigurator; import org.onap.appc.exceptions.APPCException; import org.onap.appc.mdsal.MDSALStore; import org.onap.appc.mdsal.impl.MDSALStoreFactory; import org.onap.appc.mdsal.impl.MDSALStoreImpl; import org.onap.appc.mdsal.objects.BundleInfo; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; - -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; @RunWith(PowerMockRunner.class) @PrepareForTest({MDSALStoreImpl.class,MDSALStoreFactory.class}) diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/VNFCResolverTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/VNFCResolverTest.java new file mode 100644 index 000000000..fce57f3cd --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/VNFCResolverTest.java @@ -0,0 +1,68 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2018 Ericsson + * ============================================================================= + * 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.appc.dg.common.impl; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.onap.appc.dao.util.DBUtils; +import org.onap.appc.rankingframework.AbstractRankedAttributesResolverFactory; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({DBUtils.class, AbstractRankedAttributesResolverFactory.class}) +public class VNFCResolverTest { + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Before + public void setUp() throws NoSuchFieldException, IllegalAccessException, SQLException { + PowerMockito.mockStatic(DBUtils.class); + Connection mockConnection = Mockito.mock(Connection.class); + PreparedStatement mockStatement = Mockito.mock(PreparedStatement.class); + ResultSet mockResultSet = Mockito.mock(ResultSet.class); + PowerMockito.when(DBUtils.getConnection(Mockito.anyString())).thenReturn(mockConnection); + PowerMockito.when(mockConnection.prepareStatement(Mockito.anyString())).thenReturn(mockStatement); + PowerMockito.when(mockStatement.executeQuery()).thenReturn(mockResultSet); + PowerMockito.when(mockResultSet.next()).thenReturn(true); + } + + @Test + public void test() { + VNFCResolver resolver = (VNFCResolver) ResolverFactory.createResolver("VNFC"); + expectedEx.expect(IllegalArgumentException.class); + expectedEx.expectMessage("Duplicated configuration entry:"); + FlowKey flowKey = resolver.resolve("Start", "null", "null", "null"); + } + +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImplTest.java index c03f8a19b..2efda6b53 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImplTest.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImplTest.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications (C) 2018 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +25,10 @@ package org.onap.appc.dg.common.impl; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,14 +46,12 @@ import org.osgi.framework.FrameworkUtil; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import org.powermock.reflect.Whitebox; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; @RunWith(PowerMockRunner.class) -@PrepareForTest({VnfExecutionFlowImplTest.class, FrameworkUtil.class,DependencyManager.class,DependencyModelFactory.class}) +@PrepareForTest({FrameworkUtil.class,DependencyManager.class,DependencyModelFactory.class}) @SuppressWarnings("unchecked") public class VnfExecutionFlowImplTest { @@ -74,6 +76,7 @@ public class VnfExecutionFlowImplTest { .thenReturn(dependencyModel); VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + Whitebox.setInternalState(vnfExecutionFlow, "logger", logger); vnfExecutionFlow.getVnfExecutionFlowData(params,context); } @@ -91,6 +94,7 @@ public class VnfExecutionFlowImplTest { .thenReturn(dependencyModel); VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + Whitebox.setInternalState(vnfExecutionFlow, "logger", logger); vnfExecutionFlow.getVnfExecutionFlowData(params,context); } @@ -107,6 +111,7 @@ public class VnfExecutionFlowImplTest { .thenReturn(dependencyModel); VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + Whitebox.setInternalState(vnfExecutionFlow, "logger", logger); vnfExecutionFlow.getVnfExecutionFlowData(params,context); } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/objects/TestConnectionDetails.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/objects/TestConnectionDetails.java index b84a8948a..c039d54ef 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/objects/TestConnectionDetails.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/objects/TestConnectionDetails.java @@ -19,8 +19,8 @@ */ package org.onap.appc.dg.common.objects; -import static org.junit.Assert.*; - +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import org.junit.Before; import org.junit.Test; diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JAXBUtilTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JAXBUtilTest.java index b5adc5d3f..e5ca2039b 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JAXBUtilTest.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JAXBUtilTest.java @@ -22,7 +22,6 @@ package org.onap.appc.dg.common.utils; import javax.xml.bind.JAXBException; - import org.junit.Test; public class JAXBUtilTest { diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JSONUtilTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JSONUtilTest.java index 37be0e10a..50429f680 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JSONUtilTest.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JSONUtilTest.java @@ -23,16 +23,14 @@ package org.onap.appc.dg.common.utils; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; - -import org.junit.Before; -import org.junit.Test; -import java.util.HashMap; -import java.util.Map; +import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; -import java.io.FileNotFoundException; - import java.io.UncheckedIOException; +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; public class JSONUtilTest { |