summaryrefslogtreecommitdiffstats
path: root/appc-sdc-listener/appc-sdc-listener-bundle
diff options
context:
space:
mode:
authorDunietz, Irwin <id1681@att.com>2020-01-16 15:13:14 -0500
committerTakamune Cho <takamune.cho@att.com>2020-01-29 19:44:48 +0000
commitb5fe8a69e90b950c07dc11af481eab7e9bab52c6 (patch)
tree3da81ce60554e65b93776b9aea647f3c6d8679ab /appc-sdc-listener/appc-sdc-listener-bundle
parent9b32cb60360a2a2973c621053510718de0072111 (diff)
Change code in appc dispatcher for new LCMs in R6
Also introduce some minor improvements to robustness, efficiency, & formatting. Issue-ID: APPC-1789 Signed-off-by: Dunietz, Irwin <id1681@att.com> Change-Id: I82d970c2f7cde6c8dab1222af86ea70ce93b7e50
Diffstat (limited to 'appc-sdc-listener/appc-sdc-listener-bundle')
-rw-r--r--appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/ProviderOperations.java59
-rw-r--r--appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcListener.java15
-rw-r--r--appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/listener/SdcCallbackTest.java124
3 files changed, 104 insertions, 94 deletions
diff --git a/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/ProviderOperations.java b/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/ProviderOperations.java
index 42006018e..50cfb8f59 100644
--- a/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/ProviderOperations.java
+++ b/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/ProviderOperations.java
@@ -17,17 +17,17 @@
* 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.sdc.listener;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.net.URL;
-import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
@@ -37,11 +37,9 @@ import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Map;
import java.util.Map.Entry;
-
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
-
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
@@ -61,13 +59,9 @@ import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HTTP;
import org.onap.appc.exceptions.APPCException;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
public class ProviderOperations {
-
private static final EELFLogger LOG = EELFManager.getInstance().getLogger(ProviderOperations.class);
-
private static String basic_auth;
private static URL defaultUrl;
@@ -82,9 +76,12 @@ public class ProviderOperations {
post.setHeader("Content-Type", "application/json");
post.setHeader("Accept", "application/json");
- // Set Auth
- if (basic_auth != null) {
+ // Set Auth if Provider URL is specified and basic auth has been configured
+ if (basic_auth != null && defaultUrl != null && url.equals(defaultUrl)) {
post.setHeader("Authorization", "Basic " + basic_auth);
+ LOG.debug("ASDCListener ProviderOperations: Using basic authentication for request to url " + url);
+ } else {
+ LOG.debug("ASDCListener ProviderOperations: Not Using basic authentication for request to url " + url);
}
if (adtl_headers != null) {
@@ -115,17 +112,17 @@ public class ProviderOperations {
}
/**
- * Sets the basic authentication header for the given user and password. If either entry is null then set basic auth
- * to null
+ * Sets the basic authentication header for the given user and password. If either entry is null
+ * then set basic auth to null
*
- * @param user
- * The user with optional domain name (for AAF)
- * @param password
- * The password for the user
+ * @param user The user with optional domain name (for AAF)
+ * @param password The password for the user
* @return The new value of the basic auth string that will be used in the request headers
*/
public static String setAuthentication(String user, String password) {
if (user != null && password != null) {
+ LOG.debug("SDCListener ProviderOperations:setAuthentication user is: " + user
+ + " Encrypted password: XXXX");
String authStr = user + ":" + password;
basic_auth = new String(Base64.encodeBase64(authStr.getBytes()));
} else {
@@ -137,15 +134,12 @@ public class ProviderOperations {
/**
* Sets the default Provider URL to the provided URL. If the entry is null then sets to null.
*
- * @param URL The URL
+ * @param URL url The URL
*/
- public static void setDefaultUrl(URL URL) {
- if (URL != null) {
- defaultUrl = URL;
- } else {
- defaultUrl = null;
- }
+ public static void setDefaultUrl(URL url) {
+ defaultUrl = url;
}
+
@SuppressWarnings("deprecation")
private static HttpClient getHttpClient(URL url) throws APPCException {
HttpClient client;
@@ -175,7 +169,7 @@ public class ProviderOperations {
client = new DefaultHttpClient();
} else {
throw new APPCException(
- "The provider.topology.url property is invalid. The url did not start with http[s]");
+ "The provider.topology.url property is invalid. The url did not start with http[s]");
}
return client;
}
@@ -184,18 +178,16 @@ public class ProviderOperations {
public static class MySSLSocketFactory extends SSLSocketFactory {
private SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
- public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException,
- KeyStoreException, UnrecoverableKeyException {
+ public MySSLSocketFactory(KeyStore truststore)
+ throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
super(truststore);
TrustManager tm = new X509TrustManager() {
@Override
- public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- }
+ public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
@Override
- public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- }
+ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
@Override
public X509Certificate[] getAcceptedIssuers() {
@@ -203,14 +195,11 @@ public class ProviderOperations {
}
};
- sslContext.init(null, new TrustManager[] {
- tm
- }, null);
+ sslContext.init(null, new TrustManager[] {tm}, null);
}
@Override
- public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
- throws IOException, UnknownHostException {
+ public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException {
return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
}
diff --git a/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcListener.java b/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcListener.java
index c67535e11..fffc106ea 100644
--- a/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcListener.java
+++ b/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcListener.java
@@ -69,8 +69,8 @@ public class SdcListener {
config = new SdcConfig(props);
ukey = props.getProperty("appc.sdc.provider.user");
uval = props.getProperty("appc.sdc.provider.pass");
- logger.debug(String.format("[%d] created SDC config provider URL [%s]", timeStamp, config.getStoreOpURI().toString()));
-
+ logger.debug(String.format("[%d] created SDC config provider URL [%s]",
+ timeStamp, config.getStoreOpURI().toString()));
client = DistributionClientFactory.createDistributionClient();
logger.debug(String.format("[%d] created SDC client", timeStamp));
@@ -197,14 +197,21 @@ public class SdcListener {
URL url = new URL(String.format("http%s://%s/sdc2/rest/v1/consumers",
host.contains("443") ? "s" : "", host));
- logger.info(String.format("Attempting to register user %s on %s with salted pass of %s",
- config.getUser(), url, saltedPass[1]));
+ /*logger.info(String.format("Attempting to register user %s on %s with salted pass of %s",
+ config.getUser(), url, saltedPass[1]));*/
+ logger.info(String.format("Attempting to register user %s on %s with salted pass",
+ config.getUser(), url));
ProviderOperations providerOperations = new ProviderOperations();
ProviderOperations.setDefaultUrl(config.getStoreOpURI().toURL());
ProviderOperations.setAuthentication(ukey, uval);
ProviderResponse result = providerOperations.post(url, json, headers);
+/*
+ result = ProviderOperations.post(config.getStoreOpURI().toURL(), "{\"input\": {\"document-parameters\":{\"service-uuid\":\"c2d96f2c-58b2-45c1-b952-56d4982b48f4\",\"artifact-name\":\"reference_AllAction_vDBE_Svc_VoLTE_DBE_vDBE_U_vDBE_VF_VoLTE_DBE0_0.0.1V.json\",\"artifact-version\":\"1\",\"resource-name\":\"vDBE_VF_VoLTE_DBE\",\"artifact-description\":\"Reference file of VoLTE\",\"distribution-id\":\"6bdabf7d-2270-4da7-ba50-9b57e4a5e95b\",\"service-name\":\"vDBE_Svc_VoLTE_DBE_vDBE_U\",\"resource-instance-name\":\"vDBE_VF_VoLTE_DBE 0\",\"artifact-uuid\":\"93e9a91f-4b7f-4234-ae43-d7b3ba7bfb84\",\"resource-version\":\"7.0\",\"artifact-type\":\"APPC_CONFIG\",\"service-artifacts\":\"[]\",\"service-description\":\"ASDC vDBE Service for the VoLTE-vDBE project\",\"resource-uuid\":\"93bf7180-eba8-4b49-b81d-78fcd515ec89\",\"resource-type\":\"VF\",\"artifact-contents\":\"{\n\t\\\"reference_data\\\": [\n\t\t{\n\t\t\t\\\"action\\\": \\\"Configure\\\",\n\t\t\t\\\"action-level\\\": \\\"vnf\\\",\n\t\t\t\\\"scope\\\": {\n\t\t\t\t\\\"vnf-type\\\": \\\"vDBE_Svc_VoLTE_DBE_vDBE_U/vDBE_VF_VoLTE_DBE 0\\\",\n\t\t\t\t\\\"vnfc-type\\\": \\\"\\\"\n\t\t\t},\n\t\t\t\\\"template\\\": \\\"Y\\\",\n\t\t\t\\\"vm\\\": [\n\t\t\t\t{\n\t\t\t\t\t\\\"vm-instance\\\": 1,\n\t\t\t\t\t\\\"vnfc\\\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\\\"vnfc-instance\\\": \\\"1\\\",\n\t\t\t\t\t\t\t\\\"vnfc-function-code\\\": \\\"dbu\\\",\n\t\t\t\t\t\t\t\\\"ipaddress-v4-oam-vip\\\": \\\"Y\\\",\n\t\t\t\t\t\t\t\\\"group-notation-type\\\": \\\"first-vnfc-name\\\",\n\t\t\t\t\t\t\t\\\"group-notation-value\\\": \\\"pair\\\",\n\t\t\t\t\t\t\t\\\"vnfc-type\\\": \\\"vDBE-V - DBUX\\\"\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\\\"vm-instance\\\": 2,\n\t\t\t\t\t\\\"vnfc\\\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\\\"vnfc-instance\\\": \\\"1\\\",\n\t\t\t\t\t\t\t\\\"vnfc-function-code\\\": \\\"dbu\\\",\n\t\t\t\t\t\t\t\\\"ipaddress-v4-oam-vip\\\": \\\"Y\\\",\n\t\t\t\t\t\t\t\\\"group-notation-type\\\": \\\"first-vnfc-name\\\",\n\t\t\t\t\t\t\t\\\"group-notation-value\\\": \\\"pair\\\",\n\t\t\t\t\t\t\t\\\"vnfc-type\\\": \\\"vDBE-V - DBUX\\\"\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t],\n\t\t\t\\\"device-protocol\\\": \\\"NETCONF-XML\\\",\n\t\t\t\\\"user-name\\\": \\\"root\\\",\n\t\t\t\\\"port-number\\\": \\\"830\\\",\n\t\t\t\\\"artifact-list\\\": [\n\t\t\t\t{\n\t\t\t\t\t\\\"artifact-name\\\": \\\"template_Configure_vDBE_Svc_VoLTE_DBE_vDBE_U_vDBE_VF_VoLTE_DBE0_0.0.1V.xml\\\",\n\t\t\t\t\t\\\"artifact-type\\\": \\\"config_template\\\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\\\"artifact-name\\\": \\\"pd_Configure_vDBE_Svc_VoLTE_DBE_vDBE_U_vDBE_VF_VoLTE_DBE0_0.0.1V.yaml\\\",\n\t\t\t\t\t\\\"artifact-type\\\": \\\"parameter_definitions\\\"\n\t\t\t\t}\n\t\t\t],\n\t\t\t\\\"scopeType\\\": \\\"vnf-type\\\"\n\t\t},\n\t\t{\n\t\t\t\\\"action\\\": \\\"AllAction\\\",\n\t\t\t\\\"action-level\\\": \\\"vnf\\\",\n\t\t\t\\\"scope\\\": {\n\t\t\t\t\\\"vnf-type\\\": \\\"vDBE_Svc_VoLTE_DBE_vDBE_U/vDBE_VF_VoLTE_DBE 0\\\",\n\t\t\t\t\\\"vnfc-type\\\": \\\"\\\"\n\t\t\t},\n\t\t\t\\\"artifact-list\\\": [\n\t\t\t\t{\n\t\t\t\t\t\\\"artifact-name\\\": \\\"reference_AllAction_vDBE_Svc_VoLTE_DBE_vDBE_U_vDBE_VF_VoLTE_DBE0_0.0.1V.json\\\",\n\t\t\t\t\t\\\"artifact-type\\\": \\\"reference_template\\\"\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t]\n}\"}, \"request-information\":{\"request-action\":\"StoreSdcDocumentRequest\",\"source\":\"SDC\",\"request-id\":\"c2d96f2c-58b2-45c1-b952-56d4982b48f4\"}}}", null);
+ logger.info(String.format("Result Status 3 = %d", result.getStatus()));
+*/
return result.getStatus() == 200;
+
} catch (Exception e) {
logger.error(
"Error performing initial registration with SDC server. User may not be able to connect",
diff --git a/appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/listener/SdcCallbackTest.java b/appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/listener/SdcCallbackTest.java
index 1567b7859..b4fe41312 100644
--- a/appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/listener/SdcCallbackTest.java
+++ b/appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/listener/SdcCallbackTest.java
@@ -2,16 +2,16 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
* 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.
@@ -62,6 +62,7 @@ import java.util.List;
import java.util.stream.Collectors;
import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
@RunWith(PowerMockRunner.class)
@PrepareForTest({IDistributionClient.class,
@@ -83,47 +84,51 @@ public class SdcCallbackTest {
IDistributionClient client = PowerMockito.mock(IDistributionClient.class);
EventSender eventSender = PowerMockito.mock(EventSender.class);
sdcCallback = new SdcCallback(null, client);
- resourceContent=readInput("/output/resource-ResourceAppc-template.yml").replaceAll(System.lineSeparator(),"");
- artifactProcessor = Mockito.spy(new ToscaCsarArtifactProcessor(client, eventSender, getNotificationData(), getResources().get(0)
- , getServiceArtifacts().get(0), null));
+ resourceContent =
+ readInput("/output/resource-ResourceAppc-template.yml").replaceAll(System.lineSeparator(), "");
+ 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);
- DependencyModelGenerator dependencyModelGeneratorMock=PowerMockito.mock(DependencyModelGenerator.class);
- PowerMockito.when(dependencyModelGeneratorMock.getDependencyModel(Matchers.anyString(),Matchers.anyString()))
+ Whitebox.setInternalState(artifactProcessor, "artifactStorageService", storageService);
+ DependencyModelGenerator dependencyModelGeneratorMock = PowerMockito.mock(DependencyModelGenerator.class);
+ PowerMockito.when(dependencyModelGeneratorMock.getDependencyModel(anyString(), anyString()))
.thenReturn("Dependency_model");
- Whitebox.setInternalState(artifactProcessor,"dependencyModelGenerator",dependencyModelGeneratorMock);
+ Whitebox.setInternalState(artifactProcessor, "dependencyModelGenerator", dependencyModelGeneratorMock);
PowerMockito.doCallRealMethod().when(artifactProcessor).processArtifact(anyObject());
PowerMockito.doCallRealMethod().when(artifactProcessor).run();
//PowerMockito.mockStatic(ArtifactProcessorFactory.class);
- ArtifactProcessorFactory artifactProcessorFactory=PowerMockito.mock(ArtifactProcessorFactory.class);
- PowerMockito.when(artifactProcessorFactory.getArtifactProcessor(anyObject(), anyObject(),
- anyObject(), anyObject(),
- anyObject(), anyObject())).thenReturn(artifactProcessor);
+ ArtifactProcessorFactory artifactProcessorFactory = PowerMockito.mock(ArtifactProcessorFactory.class);
+ PowerMockito.when(artifactProcessorFactory.getArtifactProcessor(
+ /* (IDistributionClient) */ anyObject(), /* (EventSender) */ anyObject(),
+ /* (INotificationData) */ anyObject(), /* (IResourceInstance) */ anyObject(),
+ /* (IArtifactInfo) */ anyObject(), /* (URI) */ anyObject()))
+ .thenReturn(artifactProcessor);
- Whitebox.setInternalState(sdcCallback,"eventSender", eventSender);
- PowerMockito.doReturn(readDownloadResult()).when(client).download(anyObject());
- PowerMockito.doReturn(null).when(client).sendDownloadStatus(anyObject());
+ Whitebox.setInternalState(sdcCallback, "eventSender", eventSender);
+ PowerMockito.doReturn(readDownloadResult()).when(client).download(/* (IArtifactInfo) */ anyObject());
+ PowerMockito.doReturn(null).when(client).sendDownloadStatus(/* (IDistributionStatusMessage) */ anyObject());
- PowerMockito.doReturn(null).when(storageService).retrieveSDCArtifact(Matchers.anyString(),
- Matchers.anyString(),Matchers.anyString());
+ PowerMockito.doReturn(null).when(storageService).retrieveSDCArtifact(anyString(), anyString(), anyString());
PowerMockito.doAnswer(invocationOnMock -> {
System.out.print(invocationOnMock.getArguments()[0].toString());
return null;
- }).when(storageService).storeSDCArtifact(anyObject());
+ }).when(storageService).storeSDCArtifact(/* (SDCArtifact) */ anyObject());
}
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()];
- FileInputStream fileInputStream = new FileInputStream(file);
- fileInputStream.read(bFile);
- fileInputStream.close();
+ try (FileInputStream fileInputStream = new FileInputStream(file)) {
+ fileInputStream.read(bFile);
+ } catch (Exception e){
+ e.printStackTrace();
+ }
downloadResult.setArtifactPayload(bFile);
return downloadResult;
@@ -131,7 +136,8 @@ public class SdcCallbackTest {
@Test
- public void testSDCListener() throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
+ public void testSDCListener()
+ throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
INotificationData notificationData = getNotificationData();
sdcCallback.activateCallback(notificationData);
pause();
@@ -140,21 +146,22 @@ public class SdcCallbackTest {
@Test
public void testArtifacts() throws Exception {
PowerMockito.doAnswer(invocationOnMock -> {
- SDCArtifact artifact =(SDCArtifact)invocationOnMock.getArguments()[0];
- SDCReference reference=(SDCReference)invocationOnMock.getArguments()[1];
- Assert.assertEquals("abcd-efgh-ijkl",artifact.getArtifactUUID());
- Assert.assertEquals("Resource-APPC",reference.getVnfType());
- Assert.assertEquals(resourceContent.trim(),artifact.getArtifactContent().replaceAll(System.lineSeparator(),""));
+ SDCArtifact artifact = (SDCArtifact) invocationOnMock.getArguments()[0];
+ SDCReference reference = (SDCReference) invocationOnMock.getArguments()[1];
+ Assert.assertEquals("abcd-efgh-ijkl", artifact.getArtifactUUID());
+ Assert.assertEquals("Resource-APPC", reference.getVnfType());
+ Assert.assertEquals(resourceContent.trim(),
+ artifact.getArtifactContent().replaceAll(System.lineSeparator(), ""));
return null;
}).doAnswer(invocation -> {
- SDCArtifact artifact =(SDCArtifact)invocation.getArguments()[0];
- SDCReference reference=(SDCReference)invocation.getArguments()[1];
- Assert.assertEquals("Resource-APPC",reference.getVnfType());
- Assert.assertEquals("tosca_dependency_model",reference.getFileCategory());
- Assert.assertEquals("Dependency_model",artifact.getArtifactContent());
- Assert.assertEquals("Resource-APPC",artifact.getResourceName());
+ SDCArtifact artifact = (SDCArtifact) invocation.getArguments()[0];
+ SDCReference reference = (SDCReference) invocation.getArguments()[1];
+ Assert.assertEquals("Resource-APPC", reference.getVnfType());
+ Assert.assertEquals("tosca_dependency_model", reference.getFileCategory());
+ Assert.assertEquals("Dependency_model", artifact.getArtifactContent());
+ Assert.assertEquals("Resource-APPC", artifact.getResourceName());
return null;
- }).when(storageService).storeSDCArtifactWithReference(anyObject(),anyObject());
+ }).when(storageService).storeSDCArtifactWithReference(anyObject(), anyObject());
artifactProcessor.processArtifact(readDownloadResult());
}
@@ -169,7 +176,7 @@ public class SdcCallbackTest {
private String readInput(String inputFile) throws URISyntaxException {
File file = new File(this.getClass().getResource(inputFile).toURI());
byte[] bFile = new byte[(int) file.length()];
- try(FileInputStream fileInputStream = new FileInputStream(file)){
+ try (FileInputStream fileInputStream = new FileInputStream(file)) {
fileInputStream.read(bFile);
} catch (Exception e){
e.printStackTrace();
@@ -177,9 +184,11 @@ public class SdcCallbackTest {
return new String(bFile);
}
- private INotificationData getNotificationData() throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException {
+ private INotificationData getNotificationData()
+ throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException {
- INotificationData notificationData = (INotificationData)getObject("org.onap.sdc.impl.NotificationDataImpl");
+ INotificationData notificationData =
+ (INotificationData) getObject("org.onap.sdc.impl.NotificationDataImpl");
List<IArtifactInfo> serviceArtifacts = getServiceArtifacts();
@@ -187,44 +196,49 @@ public class SdcCallbackTest {
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.onap.sdc.impl.JsonContainerResourceInstance");
+ IResourceInstance resource =
+ (IResourceInstance) getObject("org.onap.sdc.impl.JsonContainerResourceInstance");
List<IArtifactInfo> serviceArtifacts = getServiceArtifacts();
- invokeMethod(resource,"setArtifacts",serviceArtifacts);
- invokeMethod(resource,"setResourceName","Vnf");
- invokeMethod(resource,"setResourceVersion","1.0");
+ invokeMethod(resource, "setArtifacts", serviceArtifacts);
+ invokeMethod(resource, "setResourceName", "Vnf");
+ invokeMethod(resource, "setResourceVersion", "1.0");
resources.add(resource);
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){
+ for(Method method : methods) {
if(methodName.equalsIgnoreCase(method.getName())){
method.setAccessible(true);
- method.invoke(object,arguments);
+ method.invoke(object, arguments);
}
}
}
- private Object getObject(String fqcn) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
+ private Object getObject(String fqcn)
+ throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
Constructor constructor = Arrays.asList(Class.forName(fqcn).getDeclaredConstructors())
.stream()
- .filter(constructor1 -> constructor1.getParameterCount()==0)
+ .filter(constructor1 -> constructor1.getParameterCount() == 0)
.collect(Collectors.toList())
.get(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.onap.sdc.impl.ArtifactInfoImpl");
- invokeMethod(artifactInfo,"setArtifactType","TOSCA_CSAR");
- invokeMethod(artifactInfo,"setArtifactUUID","abcd-efgh-ijkl");
+ IArtifactInfo artifactInfo = (IArtifactInfo) getObject("org.onap.sdc.impl.ArtifactInfoImpl");
+ invokeMethod(artifactInfo, "setArtifactType", "TOSCA_CSAR");
+ invokeMethod(artifactInfo, "setArtifactUUID", "abcd-efgh-ijkl");
serviceArtifacts.add(artifactInfo);
return serviceArtifacts;
}