6f193fb3fbe1def1f40f24f4960886ea40194be3
[usecase-ui/server.git] /
1 /**
2  * Copyright 2016-2017 ZTE Corporation.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.usecaseui.server.service.lcm.impl;
17
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.exceptions.AAIException;
24
25 import java.util.Collections;
26 import java.util.List;
27
28 import static org.mockito.Mockito.mock;
29 import static org.mockito.Mockito.when;
30 import static org.onap.usecaseui.server.util.CallStub.failedCall;
31 import static org.onap.usecaseui.server.util.CallStub.successfulCall;
32
33 public class DefaultServiceInstanceServiceTest {
34
35     @Test
36     public void itCanRetrieveServiceInstanceFromAAI() {
37         AAIService aaiService = mock(AAIService.class);
38         String customerId = "1";
39         String serviceType = "service";
40         List<ServiceInstance> instances = Collections.singletonList(new ServiceInstance("1","service","1","VoLTE","e2eservice","abc","vim1"));
41         when(aaiService.listServiceInstances(customerId, serviceType)).thenReturn(successfulCall(instances));
42
43         ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);
44
45         Assert.assertSame(instances, service.listServiceInstances(customerId, serviceType));
46     }
47
48     @Test(expected = AAIException.class)
49     public void retrieveServiceInstancesWillThrowExceptionWhenAAIIsNotAvailable() {
50         AAIService aaiService = mock(AAIService.class);
51         String customerId = "1";
52         String serviceType = "service";
53         when(aaiService.listServiceInstances(customerId, serviceType)).thenReturn(failedCall("AAI is not available!"));
54
55         ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);
56         service.listServiceInstances(customerId, serviceType);
57     }
58 }