From b6ac738434954b586b751f7a04ff3d1ea94f1460 Mon Sep 17 00:00:00 2001 From: Ofir Sonsino Date: Tue, 15 Oct 2019 20:48:56 +0300 Subject: Aligning elalto branch to 1.4.0 Change-Id: Iaca7575f385ee448b54ccaf1f8c2b9b6668a3739 Issue-ID: SDC-2504 Signed-off-by: Ofir Sonsino --- INFO.yaml | 71 ++-- pom.xml | 16 +- sdc-distribution-ci/pom.xml | 7 + .../src/main/java/org/onap/test/Decoder.java | 16 +- sdc-distribution-client/pom.xml | 27 +- .../java/org/onap/sdc/http/HttpAsdcClient.java | 5 +- .../java/org/onap/sdc/http/SdcConnectorClient.java | 9 +- .../onap/sdc/impl/DistributionClientFactory.java | 38 ++ .../java/org/onap/sdc/impl/StatusDataImpl.java | 7 +- .../DistributionClientDownloadResultStubImpl.java | 81 ++++ .../mock/DistributionClientResultStubImpl.java | 40 ++ .../sdc/impl/mock/DistributionClientStubImpl.java | 129 ++++++ .../main/java/org/onap/sdc/utils/GeneralUtils.java | 22 +- .../onap/sdc/api/asdc/RegistrationRequestTest.java | 45 --- .../onap/sdc/api/asdc/ServerListResponseTest.java | 32 -- .../org/onap/sdc/http/SdcConnectorClientTest.java | 437 ++++----------------- .../onap/sdc/impl/DistributionClientFactory.java | 35 -- .../impl/DistributionStatusMessageImplTest.java | 138 ------- .../java/org/onap/sdc/impl/StatusDataImplTest.java | 42 -- .../DistributionClientDownloadResultStubImpl.java | 81 ---- .../mock/DistributionClientResultStubImpl.java | 40 -- .../sdc/impl/mock/DistributionClientStubImpl.java | 129 ------ .../java/org/onap/sdc/utils/ArtifactsUtils.java | 40 +- .../java/org/onap/sdc/utils/GeneralUtilsTest.java | 66 ---- 24 files changed, 467 insertions(+), 1086 deletions(-) create mode 100644 sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientFactory.java create mode 100644 sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java create mode 100644 sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java create mode 100644 sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java delete mode 100644 sdc-distribution-client/src/test/java/org/onap/sdc/api/asdc/RegistrationRequestTest.java delete mode 100644 sdc-distribution-client/src/test/java/org/onap/sdc/api/asdc/ServerListResponseTest.java delete mode 100644 sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionClientFactory.java delete mode 100644 sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionStatusMessageImplTest.java delete mode 100644 sdc-distribution-client/src/test/java/org/onap/sdc/impl/StatusDataImplTest.java delete mode 100644 sdc-distribution-client/src/test/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java delete mode 100644 sdc-distribution-client/src/test/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java delete mode 100644 sdc-distribution-client/src/test/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java delete mode 100644 sdc-distribution-client/src/test/java/org/onap/sdc/utils/GeneralUtilsTest.java diff --git a/INFO.yaml b/INFO.yaml index 387f7a8..b6b7de6 100644 --- a/INFO.yaml +++ b/INFO.yaml @@ -2,66 +2,55 @@ project: 'sdc/sdc-distribution-client' project_creation_date: '2017-02-14' lifecycle_state: 'Incubation' -project_category: '' project_lead: &onap_releng_ptl name: 'Ofir Sonsino' email: 'ofir.sonsino@intl.att.com' company: 'ATT' id: 'os0695' - timezone: 'Asia/Jerusalem' + timezone: 'Israel/Lod' primary_contact: *onap_releng_ptl -mailing_list: - type: 'groups.io' - url: 'lists.onap.org' - tag: '<[sub-project_name]>' -realtime_discussion: '' issue_tracking: type: 'jira' url: 'https://jira.onap.org/projects/SDC' key: 'SDC' meetings: - type: 'zoom' - agenda: '' - url: 'https://wiki.onap.org/pages/viewpage.action?pageId=6592847' - server: 'n/a' - channel: 'n/a' - repeats: 'weekly' - time: '14:00 UTC' -repositories: - - 'sdc/sdc-distribution-client' + agenda: '' + url: 'https://wiki.onap.org/pages/viewpage.action?pageId=6592847' + server: 'n/a' + channel: 'n/a' + repeats: 'weekly' + time: '14:00 UTC' committers: - <<: *onap_releng_ptl + - name: 'Idan Amit' + email: 'ia096e@intl.att.com' + company: 'ATT' + id: 'idanamit' + timezone: 'Israel/Aviv' - name: 'Tal Gitelman' - email: 'tg851x@intl.att.com' - company: 'ATT' - id: 'tgitelman' - timezone: 'Asia/Jerusalem' + email: 'tg851x@intl.att.com' + company: 'ATT' + id: 'tgitelman' + timezone: 'Israel/Aviv' - name: 'Yuli Shlosberg' - email: 'ys9693@att.com' - company: 'ATT' - id: 'ys9693' - timezone: 'Asia/Jerusalem' + email: 'ys9693@att.com' + company: 'ATT' + id: 'ys9693' + timezone: 'Israel/Aviv' tsc: approval: 'https://lists.onap.org/pipermail/onap-tsc' changes: - type: 'Addition' - name: 'Michael Lando' - link: 'https://wiki.onap.org/pages/viewpage.action?pageId=25435557' + name: 'Michael Lando' + name: 'Idan Amit' + name: 'Tal Gitelman' + name: 'Yuli Shlosberg' + link: 'https://wiki.onap.org/pages/viewpage.action?pageId=25435557' - type: 'Addition' - name: 'Idan Amit' - link: 'https://wiki.onap.org/pages/viewpage.action?pageId=25435557' - - type: 'Addition' - name: 'Tal Gitelman' - link: 'https://wiki.onap.org/pages/viewpage.action?pageId=25435557' - - type: 'Addition' - name: 'Yuli Shlosberg' - link: 'https://wiki.onap.org/pages/viewpage.action?pageId=25435557' - - type: 'Addition' - name: 'Ofir Sonsino' - link: 'https://wiki.onap.org/pages/viewpage.action?pageId=45305945' - - type: 'Removal' - name: 'Michael Lando' - link: 'https://lists.onap.org/g/onap-tsc/message/4239' + name: 'Ofir Sonsino' + link: 'https://wiki.onap.org/pages/viewpage.action?pageId=45305945' - type: 'Removal' - name: 'Idan Amit' - link: 'https://lists.onap.org/g/onap-tsc/message/5218' + name: 'Michael Lando' + link: 'https://lists.onap.org/g/onap-tsc/message/4239' + diff --git a/pom.xml b/pom.xml index dd75433..4786850 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.onap.sdc.sdc-distribution-client sdc-main-distribution-client - 1.4.1-SNAPSHOT + 1.4.0-SNAPSHOT pom sdc-sdc-distribution-client @@ -42,7 +42,6 @@ 1.14 21.0 9.4.18.v20190429 - 0.11 @@ -124,15 +123,6 @@ - - - org.apache.maven.plugins - maven-surefire-plugin - 2.19.1 - - ${argLine} -Xmx2048m - - org.apache.maven.plugins @@ -178,12 +168,12 @@ - ecomp-releases + onap-releases Release Repository ${nexus.proxy}/content/repositories/${releases.path}/ - ecomp-snapshots + onap-snapshots Snapshot Repository ${nexus.proxy}/content/repositories/${snapshots.path}/ diff --git a/sdc-distribution-ci/pom.xml b/sdc-distribution-ci/pom.xml index 7b32b37..1914d07 100644 --- a/sdc-distribution-ci/pom.xml +++ b/sdc-distribution-ci/pom.xml @@ -44,6 +44,13 @@ compile + + commons-codec + commons-codec + 1.9 + compile + + ch.qos.logback logback-classic diff --git a/sdc-distribution-ci/src/main/java/org/onap/test/Decoder.java b/sdc-distribution-ci/src/main/java/org/onap/test/Decoder.java index fc029ff..384d26d 100644 --- a/sdc-distribution-ci/src/main/java/org/onap/test/Decoder.java +++ b/sdc-distribution-ci/src/main/java/org/onap/test/Decoder.java @@ -3,14 +3,13 @@ * sdc-distribution-client * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications copyright (C) 2019 Nokia. 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. @@ -24,21 +23,22 @@ package org.onap.test; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; -import java.util.Base64; +import org.apache.commons.codec.binary.Base64; public class Decoder { public static String encode(byte[] byteArrayToEncode) { - return new String(Base64.getEncoder().encode(byteArrayToEncode)); + return new String(Base64.encodeBase64(byteArrayToEncode)); } public static String decode(String strEncoded) { - return new String(Base64.getDecoder().decode(strEncoded)); + return new String(Base64.decodeBase64(strEncoded)); } public static String readFileToString(String file) throws IOException { - try (FileReader fileReader = new FileReader(file); BufferedReader reader = new BufferedReader(fileReader)) { + try (FileReader fileReader = new FileReader(file); + BufferedReader reader = new BufferedReader(fileReader)) { String line; StringBuilder stringBuilder = new StringBuilder(); String ls = System.getProperty("line.separator"); @@ -47,7 +47,7 @@ public class Decoder { stringBuilder.append(line); stringBuilder.append(ls); } - + reader.close(); fileReader.close(); return stringBuilder.toString(); diff --git a/sdc-distribution-client/pom.xml b/sdc-distribution-client/pom.xml index f774af3..a1999f3 100644 --- a/sdc-distribution-client/pom.xml +++ b/sdc-distribution-client/pom.xml @@ -6,7 +6,7 @@ org.onap.sdc.sdc-distribution-client sdc-main-distribution-client - 1.4.1-SNAPSHOT + 1.4.0-SNAPSHOT sdc-distribution-client @@ -62,17 +62,18 @@ 2.5 + + commons-codec + commons-codec + 1.9 + compile + + org.apache.httpcomponents httpclient ${httpclient.version} - - - commons-codec - commons-codec - - compile @@ -99,12 +100,6 @@ compile - - com.google.guava - guava - ${guava.version} - - org.eclipse.jetty @@ -135,9 +130,9 @@ - com.google.code.bean-matchers - bean-matchers - ${bean-matchers.version} + com.google.guava + guava + ${guava.version} test diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java b/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java index 7871816..a93b4a7 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java @@ -3,7 +3,6 @@ * sdc-distribution-client * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications copyright (C) 2019 Nokia. 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. @@ -30,7 +29,6 @@ import java.security.KeyStore; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.ArrayList; -import java.util.Base64; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -43,6 +41,7 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; +import org.apache.commons.codec.binary.Base64; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; @@ -84,7 +83,7 @@ public class HttpAsdcClient implements IHttpAsdcClient { initSSL(username, password, configuraion.getKeyStorePath(), configuraion.getKeyStorePassword(), configuraion.activateServerTLSAuth()); String userNameAndPassword = username + ":" + password; - this.authHeaderValue = "Basic " + Base64.getEncoder().encodeToString(userNameAndPassword.getBytes()); + this.authHeaderValue = "Basic " + Base64.encodeBase64String(userNameAndPassword.getBytes()); } // @SuppressWarnings("deprecation") diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/http/SdcConnectorClient.java b/sdc-distribution-client/src/main/java/org/onap/sdc/http/SdcConnectorClient.java index 33fedc7..d294fef 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/http/SdcConnectorClient.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/http/SdcConnectorClient.java @@ -3,7 +3,6 @@ * sdc-distribution-client * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications copyright (C) 2019 Nokia. 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. @@ -59,7 +58,7 @@ import com.google.gson.reflect.TypeToken; import fj.data.Either; public class SdcConnectorClient { - String contentDispositionHeader = "Content-Disposition"; + private String contentDispositionHeader = "Content-Disposition"; private static Logger log = LoggerFactory.getLogger(SdcConnectorClient.class.getName()); private IConfiguration configuration; private HttpAsdcClient httpClient = null; @@ -165,7 +164,7 @@ public class SdcConnectorClient { DistributionClientResultImpl response = null; String requestId = UUID.randomUUID().toString(); - HttpAsdcClient httpClient = createNewHttpClient(); + HttpAsdcClient httpClient = new HttpAsdcClient(configuration); Map requestHeaders = addHeadersToHttpRequest(requestId); RegistrationRequest registrationRequest = new RegistrationRequest(credential.getApiKey(), configuration.getEnvironmentName(), configuration.isConsumeProduceStatusTopic(), configuration.getMsgBusAddress()); @@ -192,10 +191,6 @@ public class SdcConnectorClient { } - HttpAsdcClient createNewHttpClient() { - return new HttpAsdcClient(configuration); - } - public DistributionClientDownloadResultImpl dowloadArtifact(IArtifactInfo artifactInfo) { DistributionClientDownloadResultImpl response = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "failed to download artifact from ASDC"); diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientFactory.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientFactory.java new file mode 100644 index 0000000..f7a0041 --- /dev/null +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientFactory.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-distribution-client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.impl; + +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.impl.mock.DistributionClientStubImpl; + +public class DistributionClientFactory { + + private DistributionClientFactory() { + } + + public static IDistributionClient createDistributionClient() { + return new DistributionClientImpl(); + } + + public static IDistributionClient createMockDistributionClient() { + return new DistributionClientStubImpl(); + } +} diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusDataImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusDataImpl.java index de5d1ec..1d46186 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusDataImpl.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusDataImpl.java @@ -3,7 +3,6 @@ * SDC * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications copyright (C) 2019 Nokia. 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. @@ -28,7 +27,7 @@ public class StatusDataImpl implements IStatusData { private String distributionID; private String consumerID; - private Long timestamp; + private long timestamp; private String artifactURL; private DistributionStatusEnum status; private String componentName; @@ -57,7 +56,7 @@ public class StatusDataImpl implements IStatusData { return timestamp; } - public void setTimestamp(Long timestamp) { + public void setTimestamp(long timestamp) { this.timestamp = timestamp; } @@ -82,7 +81,7 @@ public class StatusDataImpl implements IStatusData { @Override public String toString() { - return "StatusDataImpl [distributionID=" + distributionID + ", consumerID=" + consumerID + ", timestamp=" + timestamp + ", artifactURL=" + artifactURL + ", status=" + status + ", errorReason=" + errorReason + "]"; + return "StatusDataImpl [distributionId=" + distributionID + ", consumerId=" + consumerID + ", timestamp=" + timestamp + ", artifactURL=" + artifactURL + ", status=" + status + ", errorReason=" + errorReason + "]"; } @Override diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java new file mode 100644 index 0000000..5ffb655 --- /dev/null +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-distribution-client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.impl.mock; + +import org.onap.sdc.api.results.IDistributionClientDownloadResult; + +/** + * Mock Implementation + */ +public class DistributionClientDownloadResultStubImpl extends DistributionClientResultStubImpl implements IDistributionClientDownloadResult { + + @Override + public byte[] getArtifactPayload() { + String mockPayload = + "heat_template_version: 2013-05-23\r\n" + + "\r\n" + + "description: >\r\n" + + " HOT template that creates one COR network (direct).\r\n" + + "\r\n" + + "parameters:\r\n" + + " cor_direct_net_name:\r\n" + + " type: string\r\n" + + " description: Name of COR direct network\r\n" + + " cor_direct_net_cidr:\r\n" + + " type: string\r\n" + + " description: Direct network address (CIDR notation)\r\n" + + " cor_direct_net_gateway:\r\n" + + " type: string\r\n" + + " description: Direct network gateway address\r\n" + + " cor_direct_net_RT:\r\n" + + " type: string\r\n" + + " description: Direct network route-target (RT)\r\n" + + "\r\n" + + "resources:\r\n" + + " cor_direct_net:\r\n" + + " type: OS::Contrail::VirtualNetwork\r\n" + + " properties:\r\n" + + " name: { get_param: cor_direct_net_name }\r\n" + + " route_targets: [ get_param: cor_direct_net_RT ]\r\n" + + "\r\n" + + " cor_direct_ip_subnet:\r\n" + + " type: OS::Neutron::Subnet\r\n" + + " properties:\r\n" + + " network_id: { get_resource: cor_direct_net }\r\n" + + " cidr: {get_param: cor_direct_net_cidr}\r\n" + + " gateway_ip: { get_param: cor_direct_net_gateway }\r\n"; + + return mockPayload.getBytes(); + } + + @Override + public String getArtifactName() { + // TODO Auto-generated method stub + return "MackArtifactName"; + } + + @Override + public String getArtifactFilename() { + // TODO Auto-generated method stub + return "MackArtifactName"; + } + +} diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java new file mode 100644 index 0000000..d176608 --- /dev/null +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-distribution-client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.impl.mock; + +import org.onap.sdc.api.results.IDistributionClientResult; +import org.onap.sdc.utils.DistributionActionResultEnum; + +/** + * Mock Implementation + */ +public class DistributionClientResultStubImpl implements IDistributionClientResult { + @Override + public DistributionActionResultEnum getDistributionActionResult() { + return DistributionActionResultEnum.SUCCESS; + } + + @Override + public String getDistributionMessageResult() { + return "Stub Result, method not implemented!"; + } + +} diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java new file mode 100644 index 0000000..40e1869 --- /dev/null +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java @@ -0,0 +1,129 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-distribution-client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.impl.mock; + +import java.util.List; + +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.consumer.IComponentDoneStatusMessage; +import org.onap.sdc.api.consumer.IConfiguration; +import org.onap.sdc.api.consumer.IDistributionStatusMessage; +import org.onap.sdc.api.consumer.IFinalDistrStatusMessage; +import org.onap.sdc.api.consumer.INotificationCallback; +import org.onap.sdc.api.consumer.IStatusCallback; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.IVfModuleMetadata; +import org.onap.sdc.api.results.IDistributionClientDownloadResult; +import org.onap.sdc.api.results.IDistributionClientResult; + +/** + * Mock Implementation + */ +public class DistributionClientStubImpl implements IDistributionClient { + + + public IDistributionClientResult updateConfiguration(IConfiguration newConf) { + return new DistributionClientResultStubImpl(); + } + + public IDistributionClientResult start() { + return new DistributionClientResultStubImpl(); + } + + public IDistributionClientResult stop() { + return new DistributionClientResultStubImpl(); + } + + public IDistributionClientResult sendDownloadStatus(IDistributionStatusMessage statusMessage) { + return new DistributionClientResultStubImpl(); + } + + public IDistributionClientResult sendDeploymentStatus(IDistributionStatusMessage statusMessage) { + return new DistributionClientResultStubImpl(); + } + + @Override + public IDistributionClientDownloadResult download(IArtifactInfo artifactInfo) { + return new DistributionClientDownloadResultStubImpl(); + } + + @Override + public IDistributionClientResult init(IConfiguration conf, INotificationCallback callback) { + return new DistributionClientResultStubImpl(); + } + + @Override + public IDistributionClientResult init(IConfiguration conf, INotificationCallback notificationCallback, + IStatusCallback statusCallback) { + return new DistributionClientResultStubImpl(); + } + + @Override + public IConfiguration getConfiguration() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IDistributionClientResult sendDownloadStatus( + IDistributionStatusMessage statusMessage, String errorReason) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IDistributionClientResult sendDeploymentStatus( + IDistributionStatusMessage statusMessage, String errorReason) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IDistributionClientResult sendComponentDoneStatus(IComponentDoneStatusMessage statusMessage) { + return null; + } + + @Override + public IDistributionClientResult sendFinalDistrStatus(IFinalDistrStatusMessage statusMessage) { + return null; + } + + @Override + public List decodeVfModuleArtifact(byte[] artifactPayload) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IDistributionClientResult sendComponentDoneStatus(IComponentDoneStatusMessage statusMessage, + String errorReason) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IDistributionClientResult sendFinalDistrStatus(IFinalDistrStatusMessage statusMessage, String errorReason) { + // TODO Auto-generated method stub + return null; + } + + +} diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/GeneralUtils.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/GeneralUtils.java index d550b74..ac2a904 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/GeneralUtils.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/GeneralUtils.java @@ -3,7 +3,6 @@ * sdc-distribution-client * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications copyright (C) 2019 Nokia. 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. @@ -21,15 +20,13 @@ package org.onap.sdc.utils; -import com.google.common.base.Charsets; -import com.google.common.hash.Hashing; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; -import java.util.Base64; import java.util.List; import java.util.regex.Pattern; +import org.apache.commons.codec.binary.Base64; import org.onap.sdc.api.results.IDistributionClientResult; import org.onap.sdc.impl.DistributionClientResultImpl; import org.slf4j.Logger; @@ -39,21 +36,24 @@ import fj.data.Either; public class GeneralUtils { private static final Logger LOGGER = LoggerFactory.getLogger(GeneralUtils.class.getName()); - private static final int STRING_LENGTH_DIVIDER = 4; + public static final int STRING_LENGTH_DIVIDER = 4; private GeneralUtils() { + } public static String calculateMD5(String data) { - String calculatedMd5 = Hashing.md5().hashString(data, Charsets.UTF_8).toString(); + String calculatedMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(data); // encode base-64 result - byte[] encodeBase64 = Base64.getEncoder().encode(calculatedMd5.getBytes()); - return new String(encodeBase64); + byte[] encodeBase64 = Base64.encodeBase64(calculatedMd5.getBytes()); + String encodeBase64Str = new String(encodeBase64); + return encodeBase64Str; + } public static String calculateMD5(byte[] decodedPayload) { - String decodedMd5 = Hashing.md5().hashBytes(decodedPayload).toString(); - byte[] encodeMd5 = Base64.getEncoder().encode(decodedMd5.getBytes()); + String decodedMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(decodedPayload); + byte[] encodeMd5 = Base64.encodeBase64(decodedMd5.getBytes()); return new String(encodeMd5); } @@ -61,7 +61,7 @@ public class GeneralUtils { boolean isEncoded = false; try { // If no exception is caught, then it is possibly a base64 encoded string - byte[] data = Base64.getDecoder().decode(str); + byte[] data = Base64.decodeBase64(str); // checks if the string was properly padded to the isEncoded = ((str.length() % STRING_LENGTH_DIVIDER == 0) && (Pattern.matches("\\A[a-zA-Z0-9/+]+={1,2}\\z", str))); diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/api/asdc/RegistrationRequestTest.java b/sdc-distribution-client/src/test/java/org/onap/sdc/api/asdc/RegistrationRequestTest.java deleted file mode 100644 index 50ff94c..0000000 --- a/sdc-distribution-client/src/test/java/org/onap/sdc/api/asdc/RegistrationRequestTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 Nokia. 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. - * ============LICENSE_END========================================================= - */ -package org.onap.sdc.api.asdc; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Collections; -import java.util.List; -import org.junit.Test; - -public class RegistrationRequestTest { - - private static final List DIST_ENV_END_POINTS = Collections.emptyList(); - private static final boolean IS_CONSUMER_TO_SDC_DISTR_STATUS_TOPIC = true; - private static final String ENV_NAME = "ENV_NAME"; - private static final String API_KEY = "API_KEY"; - - @Test - public void testConstructorShouldSetProperties() { - RegistrationRequest registrationRequest = - new RegistrationRequest(API_KEY, ENV_NAME, IS_CONSUMER_TO_SDC_DISTR_STATUS_TOPIC, DIST_ENV_END_POINTS); - assertEquals(registrationRequest.getApiPublicKey(), API_KEY); - assertEquals(registrationRequest.getDistEnvEndPoints(), DIST_ENV_END_POINTS); - assertEquals(registrationRequest.getDistrEnvName(), ENV_NAME); - assertTrue(registrationRequest.getIsConsumerToSdcDistrStatusTopic()); - } -} \ No newline at end of file diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/api/asdc/ServerListResponseTest.java b/sdc-distribution-client/src/test/java/org/onap/sdc/api/asdc/ServerListResponseTest.java deleted file mode 100644 index 449eca8..0000000 --- a/sdc-distribution-client/src/test/java/org/onap/sdc/api/asdc/ServerListResponseTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 Nokia. 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. - * ============LICENSE_END========================================================= - */ -package org.onap.sdc.api.asdc; - -import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; -import static org.junit.Assert.assertThat; - -import org.junit.Test; - -public class ServerListResponseTest { - @Test - public void shouldHaveValidGettersAndSetters() { - assertThat(ServerListResponse.class, hasValidGettersAndSetters()); - } -} \ No newline at end of file diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/http/SdcConnectorClientTest.java b/sdc-distribution-client/src/test/java/org/onap/sdc/http/SdcConnectorClientTest.java index 20228e0..ac156b1 100644 --- a/sdc-distribution-client/src/test/java/org/onap/sdc/http/SdcConnectorClientTest.java +++ b/sdc-distribution-client/src/test/java/org/onap/sdc/http/SdcConnectorClientTest.java @@ -3,14 +3,13 @@ * SDC * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications copyright (C) 2019 Nokia. 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. @@ -21,27 +20,17 @@ package org.onap.sdc.http; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.google.common.hash.Hashing; -import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.apache.commons.io.IOUtils; @@ -51,16 +40,12 @@ import org.apache.http.client.methods.CloseableHttpResponse; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.mockito.Matchers; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import org.onap.sdc.api.notification.IArtifactInfo; -import org.onap.sdc.api.results.IDistributionClientResult; import org.onap.sdc.impl.DistributionClientResultImpl; import org.onap.sdc.api.asdc.RegistrationRequest; import org.onap.sdc.api.consumer.IConfiguration; -import org.onap.sdc.utils.DistributionActionResultEnum; import org.onap.sdc.utils.Pair; import com.att.nsa.apiClient.credentials.ApiCredential; @@ -70,341 +55,85 @@ import com.google.gson.GsonBuilder; import fj.data.Either; public class SdcConnectorClientTest { - - private static Gson gson = new GsonBuilder().create(); - private static final String MOCK_ENV = "MockEnv"; - private static final String MOCK_API_KEY = "MockApikey"; - private static HttpAsdcClient httpClient = mock(HttpAsdcClient.class); - private static IConfiguration configuration = mock(IConfiguration.class); - private static ApiCredential apiCredential = mock(ApiCredential.class); - private static HttpAsdcResponse httpAsdcResponse = mock(HttpAsdcResponse.class); - @SuppressWarnings("unchecked") - private static Either mockResponse = - Mockito.mock(Either.class); - private static Map mockHeaders = new HashMap<>(); - Pair mockPair = new Pair<>(httpAsdcResponse, null); - private HttpEntity lastHttpEntity = null; - - private static SdcConnectorClient asdcClient = Mockito.spy(new SdcConnectorClient()); - - private static final String ARTIFACT_URL = "http://127.0.0.1/artifact/url"; - private static final String IT_JUST_DIDN_T_WORK = "It just didn't work"; - private static final List ARTIFACT_TYPES = Arrays.asList("Service", "Resource", "VF", "VFC"); - private static final String VALID_JSON_PAYLOAD = gson.toJson(ARTIFACT_TYPES); - private static final int PORT = 49512; - private static final byte[] BYTES = new byte[] {0xA, 0xB, 0xC, 0xD}; - - - @BeforeClass - public static void beforeClass() { - asdcClient.setConfiguration(configuration); - asdcClient.setHttpClient(httpClient); - when(apiCredential.getApiKey()).thenReturn(MOCK_API_KEY); - when(httpAsdcResponse.getStatus()).thenReturn(HttpStatus.SC_OK); - - doReturn(mockHeaders).when(asdcClient).addHeadersToHttpRequest(Mockito.anyString()); - doReturn(mockResponse).when(asdcClient).parseRegistrationResponse(httpAsdcResponse); - } - - @Before - public void beforeMethod() { - Mockito.reset(configuration, httpClient); - lastHttpEntity = null; - when(configuration.getEnvironmentName()).thenReturn(MOCK_ENV); - - - doAnswer(new Answer>() { - @Override - public Pair answer(InvocationOnMock invocation) throws Throwable { - lastHttpEntity = invocation.getArgumentAt(1, HttpEntity.class); - return mockPair; - } - }).when(httpClient).postRequest(Mockito.eq(AsdcUrls.POST_FOR_TOPIC_REGISTRATION), Mockito.any(HttpEntity.class), - Mockito.eq(mockHeaders), Mockito.eq(false)); - } - - @Test(expected = IllegalStateException.class) - public void initAndCloseTest() { - IConfiguration conf = Mockito.mock(IConfiguration.class); - when(conf.getUser()).thenReturn("user"); - when(conf.getPassword()).thenReturn("password"); - - when(conf.activateServerTLSAuth()).thenReturn(false); - SdcConnectorClient client = new SdcConnectorClient(); - client.init(conf); - assertNotNull(client.getHttpClient()); - client.close(); - - //check if client is really closed - client.getHttpClient().getRequest(AsdcUrls.POST_FOR_TOPIC_REGISTRATION, new HashMap<>()); - } - - - @Test - public void getConfigurationTest() { - IConfiguration conf = asdcClient.getConfiguration(); - assertEquals(configuration, conf); - } - - @Test - public void getHttpClientTest() { - HttpAsdcClient httpAsdcClient = asdcClient.getHttpClient(); - assertEquals(httpClient, httpAsdcClient); - } - - @Test - public void testConsumeProduceStatusTopicFalse() throws UnsupportedOperationException, IOException { - - testConsumeProduceStatusTopic(false); - - } - - @Test - public void testConsumeProduceStatusTopicTrue() throws UnsupportedOperationException, IOException { - - testConsumeProduceStatusTopic(true); - - } - - private void testConsumeProduceStatusTopic(final boolean isConsumeProduceStatusFlag) throws IOException { - when(configuration.isConsumeProduceStatusTopic()).thenReturn(isConsumeProduceStatusFlag); - asdcClient.registerAsdcTopics(apiCredential); - verify(httpClient, times(1)) - .postRequest(Mockito.eq(AsdcUrls.POST_FOR_TOPIC_REGISTRATION), any(HttpEntity.class), - Mockito.eq(mockHeaders), Mockito.eq(false)); - assertNotNull(lastHttpEntity); - RegistrationRequest actualRegRequest = - gson.fromJson(IOUtils.toString(lastHttpEntity.getContent(), StandardCharsets.UTF_8), - RegistrationRequest.class); - RegistrationRequest expectedRegRequest = - gson.fromJson(excpectedStringBody(isConsumeProduceStatusFlag), RegistrationRequest.class); - - assertTrue(actualRegRequest.getApiPublicKey().equals(expectedRegRequest.getApiPublicKey())); - assertTrue(actualRegRequest.getDistrEnvName().equals(expectedRegRequest.getDistrEnvName())); - assertTrue(actualRegRequest.getIsConsumerToSdcDistrStatusTopic() - .equals(expectedRegRequest.getIsConsumerToSdcDistrStatusTopic())); - } - - @Test - public void getValidArtifactTypesListHappyScenarioTest() throws IOException { - HttpAsdcResponse responseMock = mock(HttpAsdcResponse.class); - CloseableHttpResponse closeableHttpResponseMock = mock(CloseableHttpResponse.class); - HttpEntity messageMock = mock(HttpEntity.class); - Pair responsePair = - new Pair<>(responseMock, closeableHttpResponseMock); - - when(responseMock.getStatus()).thenReturn(HttpStatus.SC_OK); - when(responseMock.getMessage()).thenReturn(messageMock); - when(messageMock.getContent()).thenReturn(new ByteArrayInputStream(VALID_JSON_PAYLOAD.getBytes())); - when(httpClient.getRequest(eq(AsdcUrls.GET_VALID_ARTIFACT_TYPES), Matchers.any(), eq(false))) - .thenReturn(responsePair); - - Either, IDistributionClientResult> result = asdcClient.getValidArtifactTypesList(); - assertTrue(result.isLeft()); - List list = result.left().value(); - assertEquals(ARTIFACT_TYPES, list); - } - - @Test - public void getValidArtifactTypesListErrorResponseScenarioTest() throws IOException { - HttpAsdcResponse responseMock = mock(HttpAsdcResponse.class); - HttpEntity messageMock = mock(HttpEntity.class); - Pair responsePair = new Pair<>(responseMock, null); - - when(responseMock.getStatus()).thenReturn(HttpStatus.SC_GATEWAY_TIMEOUT); - when(responseMock.getMessage()).thenReturn(messageMock); - when(messageMock.getContent()).thenReturn(new ByteArrayInputStream(IT_JUST_DIDN_T_WORK.getBytes())); - when(httpClient.getRequest(eq(AsdcUrls.GET_VALID_ARTIFACT_TYPES), Matchers.any(), eq(false))) - .thenReturn(responsePair); - - Either, IDistributionClientResult> result = asdcClient.getValidArtifactTypesList(); - assertTrue(result.isRight()); - IDistributionClientResult distributionClientResult = result.right().value(); - assertEquals(DistributionActionResultEnum.ASDC_SERVER_TIMEOUT, - distributionClientResult.getDistributionActionResult()); - } - - - @Test - public void getValidArtifactTypesListExceptionDuringConnectionClosingTest() throws IOException { - HttpAsdcResponse responseMock = mock(HttpAsdcResponse.class); - CloseableHttpResponse closeableHttpResponseMock = mock(CloseableHttpResponse.class); - HttpEntity messageMock = mock(HttpEntity.class); - Pair responsePair = - new Pair<>(responseMock, closeableHttpResponseMock); - - when(responseMock.getStatus()).thenReturn(HttpStatus.SC_GATEWAY_TIMEOUT); - when(responseMock.getMessage()).thenReturn(messageMock); - when(messageMock.getContent()).thenReturn(new ByteArrayInputStream(VALID_JSON_PAYLOAD.getBytes())); - when(httpClient.getRequest(eq(AsdcUrls.GET_VALID_ARTIFACT_TYPES), Matchers.any(), eq(false))) - .thenReturn(responsePair); - - doThrow(new IOException("Test exception")).when(closeableHttpResponseMock).close(); - - Either, IDistributionClientResult> result = asdcClient.getValidArtifactTypesList(); - assertTrue(result.isRight()); - IDistributionClientResult distributionClientResult = result.right().value(); - assertEquals(DistributionActionResultEnum.ASDC_SERVER_TIMEOUT, - distributionClientResult.getDistributionActionResult()); - } - - @Test - public void getValidArtifactTypesListParsingExceptionHandlingTest() throws IOException { - HttpAsdcResponse responseMock = mock(HttpAsdcResponse.class); - CloseableHttpResponse closeableHttpResponseMock = mock(CloseableHttpResponse.class); - HttpEntity messageMock = mock(HttpEntity.class); - Pair responsePair = - new Pair<>(responseMock, closeableHttpResponseMock); - - when(responseMock.getStatus()).thenReturn(HttpStatus.SC_OK); - when(responseMock.getMessage()).thenReturn(messageMock); - when(messageMock.getContent()).thenReturn(new ThrowingInputStreamForTesting()); - when(httpClient.getRequest(eq(AsdcUrls.GET_VALID_ARTIFACT_TYPES), Matchers.any(), eq(false))) - .thenReturn(responsePair); - - Either, IDistributionClientResult> result = asdcClient.getValidArtifactTypesList(); - assertTrue(result.isRight()); - IDistributionClientResult distributionClientResult = result.right().value(); - assertEquals(DistributionActionResultEnum.GENERAL_ERROR, - distributionClientResult.getDistributionActionResult()); - } - - @Test - public void unregisterTopicsErrorDuringProcessingTest() throws IOException { - when(configuration.getAsdcAddress()).thenReturn("127.0.0.1" + PORT); - when(configuration.isConsumeProduceStatusTopic()).thenReturn(false); - when(configuration.getMsgBusAddress()) - .thenReturn(Arrays.asList("http://127.0.0.1:45321/dmaap", "http://127.0.0.1:45321/dmaap")); - - doReturn(httpClient).when(asdcClient).createNewHttpClient(); - - String failMessage = "It just didn't work"; - HttpAsdcResponse responseMock = mock(HttpAsdcResponse.class); - HttpEntity messageMock = mock(HttpEntity.class); - Pair responsePair = new Pair<>(responseMock, null); - - when(responseMock.getStatus()).thenReturn(HttpStatus.SC_BAD_GATEWAY); - when(responseMock.getMessage()).thenReturn(messageMock); - when(messageMock.getContent()).thenReturn(new ByteArrayInputStream(failMessage.getBytes())); - doReturn(responsePair).when(httpClient) - .postRequest(eq(AsdcUrls.POST_FOR_UNREGISTER), any(HttpEntity.class), any(), eq(false)); - - IDistributionClientResult result = asdcClient.unregisterTopics(apiCredential); - assertEquals(DistributionActionResultEnum.ASDC_CONNECTION_FAILED, result.getDistributionActionResult()); - } - - @Test - public void unregisterTopicsHappyScenarioTest() throws IOException { - when(configuration.getAsdcAddress()).thenReturn("127.0.0.1" + PORT); - when(configuration.isConsumeProduceStatusTopic()).thenReturn(false); - - doReturn(httpClient).when(asdcClient).createNewHttpClient(); - - String failMessage = ""; - HttpAsdcResponse responseMock = mock(HttpAsdcResponse.class); - HttpEntity messageMock = mock(HttpEntity.class); - Pair responsePair = new Pair<>(responseMock, null); - - when(responseMock.getStatus()).thenReturn(HttpStatus.SC_NO_CONTENT); - when(responseMock.getMessage()).thenReturn(messageMock); - when(messageMock.getContent()).thenReturn(new ByteArrayInputStream(failMessage.getBytes())); - doReturn(responsePair).when(httpClient) - .postRequest(eq(AsdcUrls.POST_FOR_UNREGISTER), any(HttpEntity.class), any(), eq(false)); - - IDistributionClientResult result = asdcClient.unregisterTopics(apiCredential); - assertEquals(DistributionActionResultEnum.SUCCESS, result.getDistributionActionResult()); - } - - @Test - public void downloadArtifactHappyScenarioTest() throws IOException { - Map headers = new HashMap<>(); - headers.put(asdcClient.contentDispositionHeader, "SomeHeader"); - - IArtifactInfo artifactInfo = mock(IArtifactInfo.class); - when(artifactInfo.getArtifactURL()).thenReturn(ARTIFACT_URL); - when(artifactInfo.getArtifactChecksum()).thenReturn(Hashing.md5().hashBytes(BYTES).toString()); - - HttpAsdcResponse responseMock = mock(HttpAsdcResponse.class); - HttpEntity messageMock = mock(HttpEntity.class); - Pair responsePair = new Pair<>(responseMock, null); - - when(responseMock.getStatus()).thenReturn(HttpStatus.SC_OK); - when(responseMock.getMessage()).thenReturn(messageMock); - when(responseMock.getHeadersMap()).thenReturn(headers); - when(messageMock.getContent()).thenReturn(new ByteArrayInputStream(BYTES)); - doReturn(responsePair).when(httpClient).getRequest(eq(ARTIFACT_URL), any(), eq(false)); - - IDistributionClientResult result = asdcClient.dowloadArtifact(artifactInfo); - assertEquals(DistributionActionResultEnum.SUCCESS, result.getDistributionActionResult()); - } - - @Test - public void downloadArtifactDataIntegrityProblemTest() throws IOException { - IArtifactInfo artifactInfo = mock(IArtifactInfo.class); - when(artifactInfo.getArtifactURL()).thenReturn(ARTIFACT_URL); - - HttpAsdcResponse responseMock = mock(HttpAsdcResponse.class); - HttpEntity messageMock = mock(HttpEntity.class); - Pair responsePair = new Pair<>(responseMock, null); - - when(responseMock.getStatus()).thenReturn(HttpStatus.SC_OK); - when(responseMock.getMessage()).thenReturn(messageMock); - when(messageMock.getContent()).thenReturn(new ByteArrayInputStream(BYTES)); - doReturn(responsePair).when(httpClient).getRequest(eq(ARTIFACT_URL), any(), eq(false)); - - IDistributionClientResult result = asdcClient.dowloadArtifact(artifactInfo); - assertEquals(DistributionActionResultEnum.DATA_INTEGRITY_PROBLEM, result.getDistributionActionResult()); - } - - @Test - public void downloadArtifactExceptionDuringDownloadHandlingTest() throws IOException { - IArtifactInfo artifactInfo = mock(IArtifactInfo.class); - when(artifactInfo.getArtifactURL()).thenReturn(ARTIFACT_URL); - - HttpAsdcResponse responseMock = mock(HttpAsdcResponse.class); - HttpEntity messageMock = mock(HttpEntity.class); - Pair responsePair = new Pair<>(responseMock, null); - - when(responseMock.getStatus()).thenReturn(HttpStatus.SC_OK); - when(responseMock.getMessage()).thenReturn(messageMock); - when(messageMock.getContent()).thenReturn(new ThrowingInputStreamForTesting()); - doReturn(responsePair).when(httpClient).getRequest(eq(ARTIFACT_URL), any(), eq(false)); - - IDistributionClientResult result = asdcClient.dowloadArtifact(artifactInfo); - assertEquals(DistributionActionResultEnum.GENERAL_ERROR, result.getDistributionActionResult()); - } - - @Test - public void downloadArtifactHandleDownloadErrorTest() throws IOException { - IArtifactInfo artifactInfo = mock(IArtifactInfo.class); - when(artifactInfo.getArtifactURL()).thenReturn(ARTIFACT_URL); - - HttpAsdcResponse responseMock = mock(HttpAsdcResponse.class); - HttpEntity messageMock = mock(HttpEntity.class); - Pair responsePair = new Pair<>(responseMock, null); - - when(responseMock.getStatus()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR); - when(responseMock.getMessage()).thenReturn(messageMock); - when(messageMock.getContent()).thenReturn(new ThrowingInputStreamForTesting()); - doReturn(responsePair).when(httpClient).getRequest(eq(ARTIFACT_URL), any(), eq(false)); - - IDistributionClientResult result = asdcClient.dowloadArtifact(artifactInfo); - assertEquals(DistributionActionResultEnum.ASDC_SERVER_PROBLEM, result.getDistributionActionResult()); - } - - private String excpectedStringBody(boolean isConsumeProduceStatusTopic) { - String stringBodyTemplate = - "{\r\n" + " \"apiPublicKey\": \"MockApikey\",\r\n" + " \"distrEnvName\": \"MockEnv\",\r\n" - + " \"isConsumerToSdcDistrStatusTopic\": %s\r\n" + "}"; - return String.format(stringBodyTemplate, isConsumeProduceStatusTopic); - - } - - static class ThrowingInputStreamForTesting extends InputStream { - - @Override - public int read() throws IOException { - throw new IOException("Not implemented. This is expected as the implementation is for unit tests only."); - } - } + private Gson gson = new GsonBuilder().create(); + private static final String MOCK_ENV = "MockEnv"; + private static final String MOCK_API_KEY = "MockApikey"; + private static HttpAsdcClient httpClient = Mockito.mock(HttpAsdcClient.class); + private static IConfiguration configuration = Mockito.mock(IConfiguration.class); + private static ApiCredential apiCredential = Mockito.mock(ApiCredential.class); + private static HttpAsdcResponse httpAsdcResponse = Mockito.mock(HttpAsdcResponse.class); + @SuppressWarnings("unchecked") + private static Either mockResponse = Mockito + .mock(Either.class); + private static Map mockHeaders = new HashMap<>(); + Pair mockPair = new Pair<>(httpAsdcResponse, null); + private HttpEntity lastHttpEntity = null; + + private static SdcConnectorClient asdcClient = Mockito.spy(new SdcConnectorClient()); + + @BeforeClass + public static void beforeClass() { + asdcClient.setConfiguration(configuration); + asdcClient.setHttpClient(httpClient); + when(apiCredential.getApiKey()).thenReturn(MOCK_API_KEY); + when(httpAsdcResponse.getStatus()).thenReturn(HttpStatus.SC_OK); + + doReturn(mockHeaders).when(asdcClient).addHeadersToHttpRequest(Mockito.anyString()); + doReturn(mockResponse).when(asdcClient).parseRegistrationResponse(httpAsdcResponse); + } + + @Before + public void beforeMethod() { + Mockito.reset(configuration, httpClient); + lastHttpEntity = null; + when(configuration.getEnvironmentName()).thenReturn(MOCK_ENV); + + + doAnswer(new Answer>() { + @Override + public Pair answer(InvocationOnMock invocation) throws Throwable { + lastHttpEntity = invocation.getArgumentAt(1, HttpEntity.class); + return mockPair; + } + }).when(httpClient).postRequest(Mockito.eq(AsdcUrls.POST_FOR_TOPIC_REGISTRATION), Mockito.any(HttpEntity.class), + Mockito.eq(mockHeaders), Mockito.eq(false)); + } + + @Test + public void testConsumeProduceStatusTopicFalse() throws UnsupportedOperationException, IOException { + + testConsumeProduceStatusTopic(false); + + } + + @Test + public void testConsumeProduceStatusTopicTrue() throws UnsupportedOperationException, IOException { + + testConsumeProduceStatusTopic(true); + + } + + private void testConsumeProduceStatusTopic(final boolean isConsumeProduceStatusFlag) throws IOException { + when(configuration.isConsumeProduceStatusTopic()).thenReturn(isConsumeProduceStatusFlag); + asdcClient.registerAsdcTopics(apiCredential); + verify(httpClient, times(1)).postRequest(Mockito.eq(AsdcUrls.POST_FOR_TOPIC_REGISTRATION), + Mockito.any(HttpEntity.class), Mockito.eq(mockHeaders), Mockito.eq(false)); + assertNotNull(lastHttpEntity); + RegistrationRequest actualRegRequest = gson.fromJson(IOUtils.toString(lastHttpEntity.getContent(), StandardCharsets.UTF_8), RegistrationRequest.class); + RegistrationRequest expectedRegRequest = gson.fromJson(excpectedStringBody(isConsumeProduceStatusFlag), RegistrationRequest.class); + + assertTrue(actualRegRequest.getApiPublicKey().equals(expectedRegRequest.getApiPublicKey())); + assertTrue(actualRegRequest.getDistrEnvName().equals(expectedRegRequest.getDistrEnvName())); + assertTrue(actualRegRequest.getIsConsumerToSdcDistrStatusTopic() + .equals(expectedRegRequest.getIsConsumerToSdcDistrStatusTopic())); + } + + + + private String excpectedStringBody(boolean isConsumeProduceStatusTopic) { + String stringBodyTemplate = "{\r\n" + " \"apiPublicKey\": \"MockApikey\",\r\n" + + " \"distrEnvName\": \"MockEnv\",\r\n" + " \"isConsumerToSdcDistrStatusTopic\": %s\r\n" + "}"; + return String.format(stringBodyTemplate, isConsumeProduceStatusTopic); + + } } diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionClientFactory.java b/sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionClientFactory.java deleted file mode 100644 index 6262f06..0000000 --- a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionClientFactory.java +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * sdc-distribution-client - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications copyright (C) 2019 Nokia. 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.sdc.impl; - -import org.onap.sdc.api.IDistributionClient; - -public class DistributionClientFactory { - - private DistributionClientFactory() { - } - - public static IDistributionClient createDistributionClient() { - return new DistributionClientImpl(); - } - -} diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionStatusMessageImplTest.java b/sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionStatusMessageImplTest.java deleted file mode 100644 index bf78a2a..0000000 --- a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionStatusMessageImplTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 Nokia. 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. - * ============LICENSE_END========================================================= - */ -package org.onap.sdc.impl; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.onap.sdc.api.consumer.IComponentDoneStatusMessage; -import org.onap.sdc.api.consumer.IDistributionStatusMessage; -import org.onap.sdc.api.consumer.IFinalDistrStatusMessage; -import org.onap.sdc.utils.DistributionStatusEnum; - -public class DistributionStatusMessageImplTest { - - private static final String ARTIFACT = "ARTIFACT"; - private static final String DISTRIBUTION_ID = "DISTRIBUTION_ID"; - private static final String CONSUMER_ID = "CONSUMER_ID"; - private static final String COMPONENT_NAME = "COMPONENT_NAME"; - - @Test - public void shouldProperlySetPropertiesFromIDistributionStatusMessage() { - IDistributionStatusMessage copyFrom = new IDistributionStatusMessage() { - @Override - public String getArtifactURL() { - return ARTIFACT; - } - - @Override - public String getDistributionID() { - return DISTRIBUTION_ID; - } - - @Override - public String getConsumerID() { - return CONSUMER_ID; - } - - @Override - public long getTimestamp() { - return 0; - } - - @Override - public DistributionStatusEnum getStatus() { - return DistributionStatusEnum.ALREADY_DEPLOYED; - } - }; - - DistributionStatusMessageImpl result = new DistributionStatusMessageImpl(copyFrom); - assertEquals(result.getArtifactURL(), copyFrom.getArtifactURL()); - assertEquals(result.getConsumerID(), copyFrom.getConsumerID()); - assertEquals(result.getDistributionID(), copyFrom.getDistributionID()); - assertEquals(result.getStatus(), copyFrom.getStatus()); - assertEquals(result.getTimestamp(), copyFrom.getTimestamp()); - } - - @Test - public void shouldProperlySetPropertiesFromIComponentDoneStatusMessage() { - IComponentDoneStatusMessage copyFrom = new IComponentDoneStatusMessage() { - @Override - public String getComponentName() { - return COMPONENT_NAME; - } - - @Override - public String getDistributionID() { - return DISTRIBUTION_ID; - } - - @Override - public String getConsumerID() { - return CONSUMER_ID; - } - - @Override - public long getTimestamp() { - return 0; - } - - @Override - public DistributionStatusEnum getStatus() { - return DistributionStatusEnum.ALREADY_DEPLOYED; - } - }; - - DistributionStatusMessageImpl result = new DistributionStatusMessageImpl(copyFrom); - assertEquals(result.getArtifactURL(), copyFrom.getArtifactURL()); - assertEquals(result.getConsumerID(), copyFrom.getConsumerID()); - assertEquals(result.getDistributionID(), copyFrom.getDistributionID()); - assertEquals(result.getStatus(), copyFrom.getStatus()); - assertEquals(result.getTimestamp(), copyFrom.getTimestamp()); - } - - @Test - public void shouldProperlySetPropertiesFromIFinalDistrStatusMessage() { - IFinalDistrStatusMessage copyFrom = new IFinalDistrStatusMessage() { - - @Override - public String getDistributionID() { - return DISTRIBUTION_ID; - } - - @Override - public long getTimestamp() { - return 0; - } - - @Override - public DistributionStatusEnum getStatus() { - return DistributionStatusEnum.ALREADY_DEPLOYED; - } - }; - - DistributionStatusMessageImpl result = new DistributionStatusMessageImpl(copyFrom); - assertEquals(result.getConsumerID(), copyFrom.getConsumerID()); - assertEquals(result.getDistributionID(), copyFrom.getDistributionID()); - assertEquals(result.getStatus(), copyFrom.getStatus()); - assertEquals(result.getTimestamp(), copyFrom.getTimestamp()); - } - -} \ No newline at end of file diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/StatusDataImplTest.java b/sdc-distribution-client/src/test/java/org/onap/sdc/impl/StatusDataImplTest.java deleted file mode 100644 index 82416fa..0000000 --- a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/StatusDataImplTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 Nokia. 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. - * ============LICENSE_END========================================================= - */ -package org.onap.sdc.impl; - -import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanToStringExcluding; -import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding; -import static org.junit.Assert.assertThat; - -import org.junit.Test; - -public class StatusDataImplTest { - - private static final String COMPONENT_NAME = "componentName"; - private static final String ERROR_REASON = "errorReason"; - - @Test - public void shouldHaveValidGettersAndSetters() { - assertThat(StatusDataImpl.class, hasValidGettersAndSettersExcluding(COMPONENT_NAME, ERROR_REASON)); - } - - @Test - public void shouldHaveValidToString() { - assertThat(StatusDataImpl.class, hasValidBeanToStringExcluding(COMPONENT_NAME, ERROR_REASON)); - } -} \ No newline at end of file diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java b/sdc-distribution-client/src/test/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java deleted file mode 100644 index 5ffb655..0000000 --- a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * sdc-distribution-client - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.sdc.impl.mock; - -import org.onap.sdc.api.results.IDistributionClientDownloadResult; - -/** - * Mock Implementation - */ -public class DistributionClientDownloadResultStubImpl extends DistributionClientResultStubImpl implements IDistributionClientDownloadResult { - - @Override - public byte[] getArtifactPayload() { - String mockPayload = - "heat_template_version: 2013-05-23\r\n" - + "\r\n" - + "description: >\r\n" - + " HOT template that creates one COR network (direct).\r\n" - + "\r\n" - + "parameters:\r\n" - + " cor_direct_net_name:\r\n" - + " type: string\r\n" - + " description: Name of COR direct network\r\n" - + " cor_direct_net_cidr:\r\n" - + " type: string\r\n" - + " description: Direct network address (CIDR notation)\r\n" - + " cor_direct_net_gateway:\r\n" - + " type: string\r\n" - + " description: Direct network gateway address\r\n" - + " cor_direct_net_RT:\r\n" - + " type: string\r\n" - + " description: Direct network route-target (RT)\r\n" - + "\r\n" - + "resources:\r\n" - + " cor_direct_net:\r\n" - + " type: OS::Contrail::VirtualNetwork\r\n" - + " properties:\r\n" - + " name: { get_param: cor_direct_net_name }\r\n" - + " route_targets: [ get_param: cor_direct_net_RT ]\r\n" - + "\r\n" - + " cor_direct_ip_subnet:\r\n" - + " type: OS::Neutron::Subnet\r\n" - + " properties:\r\n" - + " network_id: { get_resource: cor_direct_net }\r\n" - + " cidr: {get_param: cor_direct_net_cidr}\r\n" - + " gateway_ip: { get_param: cor_direct_net_gateway }\r\n"; - - return mockPayload.getBytes(); - } - - @Override - public String getArtifactName() { - // TODO Auto-generated method stub - return "MackArtifactName"; - } - - @Override - public String getArtifactFilename() { - // TODO Auto-generated method stub - return "MackArtifactName"; - } - -} diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java b/sdc-distribution-client/src/test/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java deleted file mode 100644 index d176608..0000000 --- a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * sdc-distribution-client - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.sdc.impl.mock; - -import org.onap.sdc.api.results.IDistributionClientResult; -import org.onap.sdc.utils.DistributionActionResultEnum; - -/** - * Mock Implementation - */ -public class DistributionClientResultStubImpl implements IDistributionClientResult { - @Override - public DistributionActionResultEnum getDistributionActionResult() { - return DistributionActionResultEnum.SUCCESS; - } - - @Override - public String getDistributionMessageResult() { - return "Stub Result, method not implemented!"; - } - -} diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java b/sdc-distribution-client/src/test/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java deleted file mode 100644 index 40e1869..0000000 --- a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java +++ /dev/null @@ -1,129 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * sdc-distribution-client - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.sdc.impl.mock; - -import java.util.List; - -import org.onap.sdc.api.IDistributionClient; -import org.onap.sdc.api.consumer.IComponentDoneStatusMessage; -import org.onap.sdc.api.consumer.IConfiguration; -import org.onap.sdc.api.consumer.IDistributionStatusMessage; -import org.onap.sdc.api.consumer.IFinalDistrStatusMessage; -import org.onap.sdc.api.consumer.INotificationCallback; -import org.onap.sdc.api.consumer.IStatusCallback; -import org.onap.sdc.api.notification.IArtifactInfo; -import org.onap.sdc.api.notification.IVfModuleMetadata; -import org.onap.sdc.api.results.IDistributionClientDownloadResult; -import org.onap.sdc.api.results.IDistributionClientResult; - -/** - * Mock Implementation - */ -public class DistributionClientStubImpl implements IDistributionClient { - - - public IDistributionClientResult updateConfiguration(IConfiguration newConf) { - return new DistributionClientResultStubImpl(); - } - - public IDistributionClientResult start() { - return new DistributionClientResultStubImpl(); - } - - public IDistributionClientResult stop() { - return new DistributionClientResultStubImpl(); - } - - public IDistributionClientResult sendDownloadStatus(IDistributionStatusMessage statusMessage) { - return new DistributionClientResultStubImpl(); - } - - public IDistributionClientResult sendDeploymentStatus(IDistributionStatusMessage statusMessage) { - return new DistributionClientResultStubImpl(); - } - - @Override - public IDistributionClientDownloadResult download(IArtifactInfo artifactInfo) { - return new DistributionClientDownloadResultStubImpl(); - } - - @Override - public IDistributionClientResult init(IConfiguration conf, INotificationCallback callback) { - return new DistributionClientResultStubImpl(); - } - - @Override - public IDistributionClientResult init(IConfiguration conf, INotificationCallback notificationCallback, - IStatusCallback statusCallback) { - return new DistributionClientResultStubImpl(); - } - - @Override - public IConfiguration getConfiguration() { - // TODO Auto-generated method stub - return null; - } - - @Override - public IDistributionClientResult sendDownloadStatus( - IDistributionStatusMessage statusMessage, String errorReason) { - // TODO Auto-generated method stub - return null; - } - - @Override - public IDistributionClientResult sendDeploymentStatus( - IDistributionStatusMessage statusMessage, String errorReason) { - // TODO Auto-generated method stub - return null; - } - - @Override - public IDistributionClientResult sendComponentDoneStatus(IComponentDoneStatusMessage statusMessage) { - return null; - } - - @Override - public IDistributionClientResult sendFinalDistrStatus(IFinalDistrStatusMessage statusMessage) { - return null; - } - - @Override - public List decodeVfModuleArtifact(byte[] artifactPayload) { - // TODO Auto-generated method stub - return null; - } - - @Override - public IDistributionClientResult sendComponentDoneStatus(IComponentDoneStatusMessage statusMessage, - String errorReason) { - // TODO Auto-generated method stub - return null; - } - - @Override - public IDistributionClientResult sendFinalDistrStatus(IFinalDistrStatusMessage statusMessage, String errorReason) { - // TODO Auto-generated method stub - return null; - } - - -} diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/utils/ArtifactsUtils.java b/sdc-distribution-client/src/test/java/org/onap/sdc/utils/ArtifactsUtils.java index dad6d4a..b562ab7 100644 --- a/sdc-distribution-client/src/test/java/org/onap/sdc/utils/ArtifactsUtils.java +++ b/sdc-distribution-client/src/test/java/org/onap/sdc/utils/ArtifactsUtils.java @@ -3,14 +3,13 @@ * sdc-distribution-client * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications copyright (C) 2019 Nokia. 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. @@ -22,27 +21,26 @@ package org.onap.sdc.utils; -import java.util.Base64; + +import org.apache.commons.codec.binary.Base64; import org.onap.sdc.impl.mock.DistributionClientDownloadResultStubImpl; public class ArtifactsUtils { - - static DistributionClientDownloadResultStubImpl distributionClientDownloadResultStubImpl = - new DistributionClientDownloadResultStubImpl(); - - public static byte[] getArtifactPayload() { - return distributionClientDownloadResultStubImpl.getArtifactPayload(); - } - - public static String getValidChecksum() { - - String payloadStr = new String(distributionClientDownloadResultStubImpl.getArtifactPayload()); - - byte[] decodedPayload = Base64.getDecoder().decode(payloadStr); - String checkSum = GeneralUtils.calculateMD5(new String(decodedPayload)); - - return checkSum; - } + static DistributionClientDownloadResultStubImpl distributionClientDownloadResultStubImpl = new DistributionClientDownloadResultStubImpl(); + + public static byte [] getArtifactPayload(){ + return distributionClientDownloadResultStubImpl.getArtifactPayload(); + } + + public static String getValidChecksum(){ + + String payloadStr = new String(distributionClientDownloadResultStubImpl.getArtifactPayload()); + + byte[] decodedPayload = Base64.decodeBase64(payloadStr); + String checkSum = GeneralUtils.calculateMD5 (new String(decodedPayload)); + + return checkSum; + } } diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/utils/GeneralUtilsTest.java b/sdc-distribution-client/src/test/java/org/onap/sdc/utils/GeneralUtilsTest.java deleted file mode 100644 index 3ed80c3..0000000 --- a/sdc-distribution-client/src/test/java/org/onap/sdc/utils/GeneralUtilsTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 Nokia. 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.sdc.utils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import com.google.common.base.Charsets; -import com.google.common.hash.HashCode; -import com.google.common.hash.Hashing; -import java.util.Base64; -import org.junit.Test; - -public class GeneralUtilsTest { - - private static final String TEXT_TO_CODE = "This is example text."; - - @Test - public void shouldCalculateMD5ForBytes() { - String hashed = GeneralUtils.calculateMD5(TEXT_TO_CODE.getBytes()); - byte[] decoded = Base64.getDecoder().decode(hashed); - HashCode expected = Hashing.md5().hashString(TEXT_TO_CODE, Charsets.UTF_8); - assertEquals(expected.toString(), new String(decoded)); - } - - @Test - public void shouldCalculateMD5ForString() { - String hashed = GeneralUtils.calculateMD5(TEXT_TO_CODE); - byte[] decoded = Base64.getDecoder().decode(hashed); - HashCode expected = Hashing.md5().hashString(TEXT_TO_CODE, Charsets.UTF_8); - assertEquals(expected.toString(), new String(decoded)); - } - - @Test - public void shouldValidateBase64EncodedString() { - HashCode expected = Hashing.md5().hashString(TEXT_TO_CODE, Charsets.UTF_8); - String base64String = Base64.getEncoder().encodeToString(expected.asBytes()); - assertTrue(GeneralUtils.isBase64Encoded(base64String)); - } - - @Test - public void shouldInvalidateBase64EncodedString() { - String base64String = Base64.getEncoder().encodeToString(TEXT_TO_CODE.getBytes()); - assertFalse(GeneralUtils.isBase64Encoded(base64String)); - } - -} \ No newline at end of file -- cgit 1.2.3-korg