* 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.
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;
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);
}
}
}
* 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.
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.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;
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();
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;
--- /dev/null
+/*
+ * ============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"));
+ }
+}
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;
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})
--- /dev/null
+/*
+ * ============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");
+ }
+
+}
* 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.
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;
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 {
.thenReturn(dependencyModel);
VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ Whitebox.setInternalState(vnfExecutionFlow, "logger", logger);
vnfExecutionFlow.getVnfExecutionFlowData(params,context);
}
.thenReturn(dependencyModel);
VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ Whitebox.setInternalState(vnfExecutionFlow, "logger", logger);
vnfExecutionFlow.getVnfExecutionFlowData(params,context);
}
.thenReturn(dependencyModel);
VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ Whitebox.setInternalState(vnfExecutionFlow, "logger", logger);
vnfExecutionFlow.getVnfExecutionFlowData(params,context);
}
*/
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;
package org.onap.appc.dg.common.utils;
import javax.xml.bind.JAXBException;
-
import org.junit.Test;
public class JAXBUtilTest {
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 {