summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuji7 <lu.ji3@zte.com.cn>2017-09-29 11:34:10 +0800
committerLuji7 <lu.ji3@zte.com.cn>2017-09-29 11:38:28 +0800
commite7f1d26a8c433597d58d4d85f8895eaad7701f1d (patch)
tree8fca1bdca6685c6dd5271c2b9fc6d89e3e1a6990
parent01846507c0d3d39496f6d1d61b062a4373010433 (diff)
Add UT for query service tempalte.
Change-Id: I1270eaa8fe2442cb2f8584a967a96b4d5bc6c9e3 Issue-Id: USECASEUI-36 Signed-off-by: Luji7 <lu.ji3@zte.com.cn>
-rw-r--r--server/pom.xml6
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/bean/lcm/VfNsPackageInfo.java16
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/bean/VimInfo.java16
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/SDCServiceTemplate.java30
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/Vnf.java48
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionService.java4
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceTest.java55
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionServiceTest.java109
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/util/CallStub.java83
9 files changed, 364 insertions, 3 deletions
diff --git a/server/pom.xml b/server/pom.xml
index 5532eda1..d0f308fb 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -97,6 +97,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/lcm/VfNsPackageInfo.java b/server/src/main/java/org/onap/usecaseui/server/bean/lcm/VfNsPackageInfo.java
index d51ec4b9..0e8ef960 100644
--- a/server/src/main/java/org/onap/usecaseui/server/bean/lcm/VfNsPackageInfo.java
+++ b/server/src/main/java/org/onap/usecaseui/server/bean/lcm/VfNsPackageInfo.java
@@ -20,6 +20,7 @@ import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
import java.util.List;
+import java.util.Objects;
public class VfNsPackageInfo {
@@ -46,4 +47,19 @@ public class VfNsPackageInfo {
public List<VimInfo> getVimInfos() {
return vimInfos;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ VfNsPackageInfo that = (VfNsPackageInfo) o;
+ return Objects.equals(nsPackage, that.nsPackage) &&
+ Objects.equals(vnfPackages, that.vnfPackages) &&
+ Objects.equals(vimInfos, that.vimInfos);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(nsPackage, vnfPackages, vimInfos);
+ }
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/bean/VimInfo.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/bean/VimInfo.java
index 73a98732..336481fe 100644
--- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/bean/VimInfo.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/bean/VimInfo.java
@@ -18,6 +18,8 @@ package org.onap.usecaseui.server.service.lcm.domain.aai.bean;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.Objects;
+
public class VimInfo {
private String cloudOwner;
@@ -41,4 +43,18 @@ public class VimInfo {
public String getCloudRegionId() {
return cloudRegionId;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ VimInfo vimInfo = (VimInfo) o;
+ return Objects.equals(cloudOwner, vimInfo.cloudOwner) &&
+ Objects.equals(cloudRegionId, vimInfo.cloudRegionId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(cloudOwner, cloudRegionId);
+ }
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/SDCServiceTemplate.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/SDCServiceTemplate.java
index 38afd558..9a686bcb 100644
--- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/SDCServiceTemplate.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/SDCServiceTemplate.java
@@ -15,6 +15,11 @@
*/
package org.onap.usecaseui.server.service.lcm.domain.sdc.bean;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Objects;
+
public class SDCServiceTemplate {
private String uuid;
@@ -27,7 +32,13 @@ public class SDCServiceTemplate {
private String category;
- public SDCServiceTemplate(String uuid, String invariantUUID, String name, String toscaModelURL, String category) {
+ @JsonCreator
+ public SDCServiceTemplate(
+ @JsonProperty String uuid,
+ @JsonProperty String invariantUUID,
+ @JsonProperty String name,
+ @JsonProperty String toscaModelURL,
+ @JsonProperty String category) {
this.uuid = uuid;
this.invariantUUID = invariantUUID;
this.name = name;
@@ -54,4 +65,21 @@ public class SDCServiceTemplate {
public String getCategory() {
return category;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ SDCServiceTemplate that = (SDCServiceTemplate) o;
+ return Objects.equals(uuid, that.uuid) &&
+ Objects.equals(invariantUUID, that.invariantUUID) &&
+ Objects.equals(name, that.name) &&
+ Objects.equals(toscaModelURL, that.toscaModelURL) &&
+ Objects.equals(category, that.category);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(uuid, invariantUUID, name, toscaModelURL, category);
+ }
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/Vnf.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/Vnf.java
index 8b98c71c..27949d6a 100644
--- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/Vnf.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/Vnf.java
@@ -15,5 +15,53 @@
*/
package org.onap.usecaseui.server.service.lcm.domain.sdc.bean;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Objects;
+
public class Vnf {
+
+ private String uuid;
+
+ private String invariantUUID;
+
+ private String name;
+
+ @JsonCreator
+ public Vnf(
+ @JsonProperty String uuid,
+ @JsonProperty String invariantUUID,
+ @JsonProperty String name) {
+ this.uuid = uuid;
+ this.invariantUUID = invariantUUID;
+ this.name = name;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public String getInvariantUUID() {
+ return invariantUUID;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ Vnf vnf = (Vnf) o;
+ return Objects.equals(uuid, vnf.uuid) &&
+ Objects.equals(invariantUUID, vnf.invariantUUID) &&
+ Objects.equals(name, vnf.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(uuid, invariantUUID, name);
+ }
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionService.java
index 383ee296..e4a08b8a 100644
--- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionService.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionService.java
@@ -63,9 +63,9 @@ public class DefaultPackageDistributionService implements PackageDistributionSer
public VfNsPackageInfo retrievePackageInfo() {
try {
List<SDCServiceTemplate> nsTemplate = sdcCatalogService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED).execute().body();
- List<Vnf> vnfs = sdcCatalogService.listResources(RESOURCETYPE_VF, DISTRIBUTION_STATUS_DISTRIBUTED).execute().body();
+ List<Vnf> vnf = sdcCatalogService.listResources(RESOURCETYPE_VF, DISTRIBUTION_STATUS_DISTRIBUTED).execute().body();
List<VimInfo> vim = aaiService.listVimInfo().execute().body();
- return new VfNsPackageInfo(nsTemplate, vnfs, vim);
+ return new VfNsPackageInfo(nsTemplate, vnf, vim);
} catch (IOException e) {
throw new SDCCatalogException("SDC Service is not available!", e);
}
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceTest.java
new file mode 100644
index 00000000..af579afa
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceTest.java
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2016-2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.usecaseui.server.service.lcm.impl;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.usecaseui.server.service.lcm.CustomerService;
+import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAICustomer;
+import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException;
+import org.onap.usecaseui.server.util.CallStub;
+import retrofit2.Call;
+
+import java.util.List;
+
+import static java.util.Collections.singletonList;
+
+public class DefaultCustomerServiceTest {
+
+ @Test
+ public void itCanRetrieveCustomersFromAAI() {
+ List<AAICustomer> customers = singletonList(new AAICustomer("1", "name", "type"));
+
+ AAIService aaiService = Mockito.mock(AAIService.class);
+ Call<List<AAICustomer>> call = CallStub.successfulCall(customers);
+ Mockito.when(aaiService.listCustomer()).thenReturn(call);
+
+ CustomerService customerService = new DefaultCustomerService(aaiService);
+ Assert.assertSame(customers, customerService.listCustomer());
+ }
+
+ @Test(expected = AAIException.class)
+ public void itWillThrowExceptionWhenAAIIsNotAvailable() {
+ AAIService aaiService = Mockito.mock(AAIService.class);
+ Call<List<AAICustomer>> call = CallStub.failedCall("AAI is not available!");
+ Mockito.when(aaiService.listCustomer()).thenReturn(call);
+
+ CustomerService customerService = new DefaultCustomerService(aaiService);
+ customerService.listCustomer();
+ }
+} \ No newline at end of file
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionServiceTest.java
new file mode 100644
index 00000000..19430820
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionServiceTest.java
@@ -0,0 +1,109 @@
+/**
+ * Copyright 2016-2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.usecaseui.server.service.lcm.impl;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
+import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
+import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfo;
+import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
+import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
+import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
+import org.onap.usecaseui.server.service.lcm.domain.sdc.exceptions.SDCCatalogException;
+import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
+import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
+import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult;
+import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
+import org.onap.usecaseui.server.util.CallStub;
+import retrofit2.Call;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.*;
+
+public class DefaultPackageDistributionServiceTest {
+
+ @Test
+ public void itCanRetrievePackageFromSDCAndAAI() {
+ List<SDCServiceTemplate> serviceTemplate = Collections.singletonList(new SDCServiceTemplate("1", "1", "service", "", ""));
+ List<Vnf> vnf = Collections.singletonList(new Vnf("2","2","vnf"));
+ SDCCatalogService sdcService = newSDCService(serviceTemplate, vnf);
+
+ List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
+ AAIService aaiService = newAAIService(vim);
+
+ PackageDistributionService service = new DefaultPackageDistributionService(sdcService,aaiService, null);
+
+ Assert.assertThat(service.retrievePackageInfo(), equalTo(new VfNsPackageInfo(serviceTemplate, vnf, vim)));
+ }
+
+ private AAIService newAAIService(List<VimInfo> vim) {
+ AAIService aaiService = Mockito.mock(AAIService.class);
+
+ Call<List<VimInfo>> vimCall = CallStub.successfulCall(vim);
+ Mockito.when(aaiService.listVimInfo()).thenReturn(vimCall);
+ return aaiService;
+ }
+
+ private SDCCatalogService newSDCService(List<SDCServiceTemplate> serviceTemplate, List<Vnf> vnf) {
+ SDCCatalogService sdcService = Mockito.mock(SDCCatalogService.class);
+
+ Call<List<SDCServiceTemplate>> serviceCall = CallStub.successfulCall(serviceTemplate);
+ Mockito.when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
+
+ Call<List<Vnf>> vnfCall = CallStub.successfulCall(vnf);
+ Mockito.when(sdcService.listResources(RESOURCETYPE_VF, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(vnfCall);
+ return sdcService;
+ }
+
+ @Test(expected = SDCCatalogException.class)
+ public void retrievePackageWillThrowExceptionWhenSDCIsNotAvailable() {
+ SDCCatalogService sdcService = Mockito.mock(SDCCatalogService.class);
+ Call<List<SDCServiceTemplate>> serviceCall = CallStub.failedCall("SDC is not available!");
+ Mockito.when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
+
+ List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
+ AAIService aaiService = newAAIService(vim);
+
+ PackageDistributionService service = new DefaultPackageDistributionService(sdcService,aaiService, null);
+ service.retrievePackageInfo();
+ }
+
+ @Test
+ public void itCanPostNsPackageToVFC() {
+ VfcService vfcService = Mockito.mock(VfcService.class);
+ Csar csar = new Csar();
+ DistributionResult result = new DistributionResult("status", "description", "errorcode");
+ Mockito.when(vfcService.distributeNsPackage(csar)).thenReturn(CallStub.successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, null, vfcService);
+
+ Assert.assertSame(result, service.postNsPackage(csar));
+ }
+
+ @Test(expected = VfcException.class)
+ public void postNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
+ VfcService vfcService = Mockito.mock(VfcService.class);
+ Csar csar = new Csar();
+ Mockito.when(vfcService.distributeNsPackage(csar)).thenReturn(CallStub.failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, null, vfcService);
+ service.postNsPackage(csar);
+ }
+} \ No newline at end of file
diff --git a/server/src/test/java/org/onap/usecaseui/server/util/CallStub.java b/server/src/test/java/org/onap/usecaseui/server/util/CallStub.java
new file mode 100644
index 00000000..1fe7638e
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/util/CallStub.java
@@ -0,0 +1,83 @@
+/**
+ * Copyright 2016-2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.usecaseui.server.util;
+
+import okhttp3.Request;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+
+import java.io.IOException;
+
+public class CallStub<T> implements Call<T> {
+
+ private boolean isSuccess;
+ private T result;
+ private String failMessage;
+
+ private CallStub(boolean isSuccess, T result, String message) {
+ this.isSuccess = isSuccess;
+ this.result = result;
+ this.failMessage = message;
+ }
+
+ @Override
+ public Response<T> execute() throws IOException {
+ if (isSuccess) {
+ return Response.success(result);
+ } else {
+ throw new IOException(failMessage);
+ }
+ }
+
+ @Override
+ public void enqueue(Callback<T> callback) {
+
+ }
+
+ @Override
+ public boolean isExecuted() {
+ return false;
+ }
+
+ @Override
+ public void cancel() {
+
+ }
+
+ @Override
+ public boolean isCanceled() {
+ return false;
+ }
+
+ @Override
+ public Call<T> clone() {
+ return null;
+ }
+
+ @Override
+ public Request request() {
+ return null;
+ }
+
+ public static <T> CallStub<T> successfulCall(T result) {
+ return new CallStub<>(true, result, "");
+ }
+
+ public static <T> CallStub<T> failedCall(String message) {
+ return new CallStub<>(false, null, message);
+ }
+}