summaryrefslogtreecommitdiffstats
path: root/appc-asdc-listener
diff options
context:
space:
mode:
authorbeili.zhou <beili.zhou@amdocs.com>2017-08-29 18:33:57 -0400
committerMarcus Williams <marcus.williams@intel.com>2017-08-30 16:29:28 +0000
commita1194798f406efe32cb33510f1a9d58b0b5f9bd9 (patch)
tree21931fa9ba7e4023dd4d1998525e5529b944d209 /appc-asdc-listener
parent9a1e7032fae218bd820dc06436a52173fbae7d6e (diff)
Remove catch throwable and error
Fix the following sonar blocker issue: - Catch Exception instead of Throwable - Catch Exception instead of Error Issue-Id: APPC-175 Change-Id: I16a1018001b067216740ec11e5a97e52d714db69 Signed-off-by: beili.zhou <beili.zhou@amdocs.com>
Diffstat (limited to 'appc-asdc-listener')
-rw-r--r--appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcCallback.java7
-rw-r--r--appc-asdc-listener/appc-asdc-listener-bundle/src/test/java/org/openecomp/appc/sdc/listener/AsdcCallbackTest.java58
2 files changed, 38 insertions, 27 deletions
diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcCallback.java b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcCallback.java
index 345149686..b5307d697 100644
--- a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcCallback.java
+++ b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcCallback.java
@@ -83,15 +83,16 @@ public class AsdcCallback implements INotificationCallback {
BundleContext bctx = FrameworkUtil.getBundle(EventSender.class).getBundleContext();
ServiceReference sref = bctx.getServiceReference(EventSender.class);
eventSender = (EventSender) bctx.getService(sref);
- } catch (Throwable t) {
- logger.error("AsdcCallback failed on initializing EventSender", t);
+ } catch (Exception e) {
+ logger.error("AsdcCallback failed on initializing EventSender", e);
}
}
if (isRunning.get()) {
for(IArtifactInfo artifact:data.getServiceArtifacts()){
- ArtifactProcessor artifactProcessor = ArtifactProcessorFactory.getArtifactProcessor(client, eventSender, data, null, artifact, storeUri);
+ ArtifactProcessor artifactProcessor = ArtifactProcessorFactory.getArtifactProcessor(
+ client, eventSender, data, null, artifact, storeUri);
if(artifactProcessor!=null){
executor.submit(artifactProcessor);
}
diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/src/test/java/org/openecomp/appc/sdc/listener/AsdcCallbackTest.java b/appc-asdc-listener/appc-asdc-listener-bundle/src/test/java/org/openecomp/appc/sdc/listener/AsdcCallbackTest.java
index b4ee459f2..3971ec248 100644
--- a/appc-asdc-listener/appc-asdc-listener-bundle/src/test/java/org/openecomp/appc/sdc/listener/AsdcCallbackTest.java
+++ b/appc-asdc-listener/appc-asdc-listener-bundle/src/test/java/org/openecomp/appc/sdc/listener/AsdcCallbackTest.java
@@ -25,6 +25,7 @@
package org.openecomp.appc.sdc.listener;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
@@ -69,42 +70,45 @@ import java.util.List;
ArtifactProcessorFactory.class})
public class AsdcCallbackTest {
- IDistributionClient client;
+ private IDistributionClient client;
private EventSender eventSender;
private INotificationCallback asdcCallback;
private ArtifactStorageService storageService;
private ToscaCsarArtifactProcessor artifactProcessor;
-
@Before
public void setup() throws Exception {
client = PowerMockito.mock(IDistributionClient.class);
eventSender = PowerMockito.mock(EventSender.class);
asdcCallback = new AsdcCallback(null,client);
- artifactProcessor = Mockito.spy(new ToscaCsarArtifactProcessor(client,eventSender,getNotificationData(),getResources().get(0)
- ,getServiceArtifacts().get(0),null));
+ artifactProcessor = Mockito.spy(new ToscaCsarArtifactProcessor(
+ client, eventSender, getNotificationData(), getResources().get(0),
+ getServiceArtifacts().get(0),null));
storageService = PowerMockito.mock(ArtifactStorageService.class);
Whitebox.setInternalState(artifactProcessor,"artifactStorageService", storageService);
- PowerMockito.doCallRealMethod().when(artifactProcessor).processArtifact((IDistributionClientDownloadResult) Matchers.anyObject());
+ PowerMockito.doCallRealMethod().when(artifactProcessor)
+ .processArtifact((IDistributionClientDownloadResult) Matchers.anyObject());
PowerMockito.doCallRealMethod().when(artifactProcessor).run();
-
PowerMockito.mockStatic(ArtifactProcessorFactory.class);
- PowerMockito.when(ArtifactProcessorFactory.getArtifactProcessor((IDistributionClient)Matchers.anyObject(), (EventSender)Matchers.anyObject(),
+ PowerMockito.when(ArtifactProcessorFactory.getArtifactProcessor((IDistributionClient)Matchers.anyObject(),
+ (EventSender)Matchers.anyObject(),
(INotificationData)Matchers.anyObject(), (IResourceInstance)Matchers.anyObject(),
(IArtifactInfo)Matchers.anyObject(), (URI)Matchers.anyObject())).thenReturn(artifactProcessor);
Whitebox.setInternalState(asdcCallback,"eventSender", eventSender);
PowerMockito.doReturn(readDownloadResult()).when(client).download((IArtifactInfo) Matchers.anyObject());
- PowerMockito.doReturn(null).when(client).sendDownloadStatus((IDistributionStatusMessage) Matchers.anyObject());
+ PowerMockito.doReturn(null).when(client).sendDownloadStatus(
+ (IDistributionStatusMessage) Matchers.anyObject());
- PowerMockito.doReturn(null).when(storageService).retrieveSDCArtifact(Matchers.anyString(),Matchers.anyString(),Matchers.anyString());
+ PowerMockito.doReturn(null).when(storageService).retrieveSDCArtifact(Matchers.anyString(),
+ Matchers.anyString(), Matchers.anyString());
PowerMockito.doAnswer(new Answer<Object>() {
@Override
- public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
+ public Object answer(InvocationOnMock invocationOnMock) throws Exception {
System.out.print(invocationOnMock.getArguments()[0].toString());
return null;
}
@@ -112,7 +116,8 @@ public class AsdcCallbackTest {
}
private IDistributionClientDownloadResult readDownloadResult() throws IOException, URISyntaxException {
- DistributionClientDownloadResultImpl downloadResult = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.SUCCESS,"Download success");
+ DistributionClientDownloadResultImpl downloadResult = new DistributionClientDownloadResultImpl(
+ DistributionActionResultEnum.SUCCESS,"Download success");
File file = new File(this.getClass().getResource("/csar/service-ServiceAppc-csar.csar").toURI());
byte[] bFile = new byte[(int) file.length()];
@@ -124,14 +129,12 @@ public class AsdcCallbackTest {
return downloadResult;
}
-
-// @Test
- public void testASDCListener() throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
-
-
+ @Ignore
+ @Test
+ public void testASDCListener()
+ throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
INotificationData notificationData = getNotificationData();
asdcCallback.activateCallback(notificationData);
-
// pause();
}
@@ -143,9 +146,11 @@ public class AsdcCallbackTest {
// }
// }
- private INotificationData getNotificationData() throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException {
+ private INotificationData getNotificationData()
+ throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException {
- INotificationData notificationData = (INotificationData)getObject("org.openecomp.sdc.impl.NotificationDataImpl");
+ INotificationData notificationData = (INotificationData)getObject(
+ "org.openecomp.sdc.impl.NotificationDataImpl");
List<IArtifactInfo> serviceArtifacts = getServiceArtifacts();
@@ -153,9 +158,11 @@ public class AsdcCallbackTest {
return notificationData;
}
- private List<IResourceInstance> getResources() throws ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException {
+ private List<IResourceInstance> getResources()
+ throws ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException {
List<IResourceInstance> resources = new ArrayList<>();
- IResourceInstance resource = (IResourceInstance)getObject("org.openecomp.sdc.impl.JsonContainerResourceInstance");
+ IResourceInstance resource = (IResourceInstance)getObject(
+ "org.openecomp.sdc.impl.JsonContainerResourceInstance");
List<IArtifactInfo> serviceArtifacts = getServiceArtifacts();
invokeMethod(resource,"setArtifacts",serviceArtifacts);
@@ -166,7 +173,8 @@ public class AsdcCallbackTest {
return resources;
}
- private void invokeMethod(Object object, String methodName,Object... arguments) throws IllegalAccessException, InvocationTargetException {
+ private void invokeMethod(Object object, String methodName,Object... arguments)
+ throws IllegalAccessException, InvocationTargetException {
Method[] methods = object.getClass().getDeclaredMethods();
for(Method method:methods){
if(methodName.equalsIgnoreCase(method.getName())){
@@ -176,13 +184,15 @@ public class AsdcCallbackTest {
}
}
- private Object getObject(String fqcn) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
+ private Object getObject(String fqcn)
+ throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
Constructor constructor = Class.forName(fqcn).getDeclaredConstructors()[0];
constructor.setAccessible(true);
return constructor.newInstance();
}
- private List<IArtifactInfo> getServiceArtifacts() throws ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException {
+ private List<IArtifactInfo> getServiceArtifacts()
+ throws ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException {
List<IArtifactInfo> serviceArtifacts = new ArrayList<>();
IArtifactInfo artifactInfo = (IArtifactInfo)getObject("org.openecomp.sdc.impl.ArtifactInfoImpl");
invokeMethod(artifactInfo,"setArtifactType","TOSCA_CSAR");