2 * Copyright 2016-2017 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.usecaseui.server.service.lcm.impl;
18 import org.junit.Assert;
19 import org.junit.Test;
20 import org.onap.usecaseui.server.service.lcm.ServiceInstanceService;
21 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
22 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.ServiceInstance;
23 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.ServiceInstanceRsp;
24 import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException;
26 import java.util.Collections;
27 import java.util.List;
29 import static org.mockito.Mockito.mock;
30 import static org.mockito.Mockito.when;
31 import static org.onap.usecaseui.server.util.CallStub.emptyBodyCall;
32 import static org.onap.usecaseui.server.util.CallStub.failedCall;
33 import static org.onap.usecaseui.server.util.CallStub.successfulCall;
35 public class DefaultServiceInstanceServiceTest {
38 public void itCanRetrieveServiceInstanceFromAAI() {
39 AAIService aaiService = mock(AAIService.class);
40 String customerId = "1";
41 String serviceType = "service";
42 List<ServiceInstance> instances = Collections.singletonList(new ServiceInstance("1","service","1","VoLTE","e2eservice","abc","vim1"));
43 ServiceInstanceRsp rsp = new ServiceInstanceRsp();
44 rsp.setServiceInstances(instances);
45 when(aaiService.listServiceInstances(customerId, serviceType)).thenReturn(successfulCall(rsp));
47 ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);
49 Assert.assertSame(instances, service.listServiceInstances(customerId, serviceType));
52 @Test(expected = AAIException.class)
53 public void retrieveServiceInstancesWillThrowExceptionWhenAAIIsNotAvailable() {
54 AAIService aaiService = mock(AAIService.class);
55 String customerId = "1";
56 String serviceType = "service";
57 when(aaiService.listServiceInstances(customerId, serviceType)).thenReturn(failedCall("AAI is not available!"));
59 ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);
60 service.listServiceInstances(customerId, serviceType);
64 public void retrieveServiceInstancesWillThrowExceptionWhenNoServiceInstancesInAAI() {
65 AAIService aaiService = mock(AAIService.class);
66 String customerId = "1";
67 String serviceType = "service";
68 when(aaiService.listServiceInstances(customerId, serviceType)).thenReturn(emptyBodyCall());
70 ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);
71 List<ServiceInstance> serviceInstances = service.listServiceInstances(customerId, serviceType);
73 Assert.assertTrue("service instances should be empty.", serviceInstances.isEmpty());
76 @Test(expected = AAIException.class)
77 public void getRelationShipDataWillThrowExceptionWhenAAIIsNotAvailable() {
78 AAIService aaiService = mock(AAIService.class);
79 String customerId = "1";
80 String serviceType = "service";
81 String result="result";
82 when(aaiService.getAAIServiceInstance(customerId, serviceType,result)).thenReturn(failedCall("AAI is not available!"));
84 ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);
85 service.getRelationShipData(customerId, serviceType,result);
89 public void getRelationShipDataWillThrowExceptionWhenNoServiceInstancesInAAI() {
90 AAIService aaiService = mock(AAIService.class);
91 String customerId = "1";
92 String serviceType = "service";
93 String result="result";
94 when(aaiService.getAAIServiceInstance(customerId, serviceType,result)).thenReturn(emptyBodyCall());
96 ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);
97 String aa = service.getRelationShipData(customerId, serviceType,result);
99 Assert.assertTrue("service instances should be empty.", aa.isEmpty());