Modify Unit Tests
[usecase-ui/server.git] / server / src / test / java / org / onap / usecaseui / server / service / lcm / impl / SotnServiceQryServiceImplTest.java
1 /**
2  * Copyright (C) 2020 Huawei, Inc. and others. All rights reserved.
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 okhttp3.MediaType;
19 import okhttp3.ResponseBody;
20 import okio.Buffer;
21 import okio.BufferedSource;
22 import org.jetbrains.annotations.NotNull;
23 import org.jetbrains.annotations.Nullable;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
27
28 import static org.mockito.ArgumentMatchers.eq;
29 import static org.mockito.Mockito.mock;
30 import static org.mockito.Mockito.when;
31 import static org.onap.usecaseui.server.util.CallStub.failedCall;
32 import static org.onap.usecaseui.server.util.CallStub.successfulCall;
33
34 public class SotnServiceQryServiceImplTest {
35
36     AAIService aaiService = mock(AAIService.class);
37
38     SotnServiceQryServiceImpl sotnServiceQryService = new SotnServiceQryServiceImpl(aaiService);
39     ResponseBody result;
40
41     @Before
42     public void before() throws Exception {
43         result= new ResponseBody() {
44             @Nullable
45             @Override
46             public MediaType contentType() {
47                 return MediaType.parse("application/json; charset=utf-8");
48             }
49
50             @Override
51             public long contentLength() {
52                 return 0;
53             }
54
55             @NotNull
56             @Override
57             public BufferedSource source() {
58
59                 return new Buffer();
60             }
61         };
62     }
63     @Test
64     public void getServiceInstancesTest() {
65         when(aaiService.listServiceInstances(eq("SOTN-CUST"),eq("SOTN"))).thenReturn(successfulCall(result));
66         sotnServiceQryService.getServiceInstances("SOTN");
67     }
68
69     @Test
70     public void getServiceInstancesWithThrowException() {
71         when(aaiService.listServiceInstances(eq("SOTN-CUST"),eq("SOTN"))).thenReturn(failedCall("aai is not exist!"));
72         sotnServiceQryService.getServiceInstances("SOTN");
73     }
74
75 }