PombaReqest and ServiceInstance improvements
[vid.git] / vid-app-common / src / test / java / org / onap / vid / aai / PombaClientImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2019 Nokia
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.vid.aai;
21
22 import static org.mockito.BDDMockito.given;
23 import static org.mockito.BDDMockito.then;
24
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import com.google.common.collect.Lists;
27 import java.io.IOException;
28 import java.net.URL;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.junit.MockitoJUnitRunner;
34 import org.onap.vid.model.PombaInstance.PombaRequest;
35 import org.onap.vid.model.PombaInstance.ServiceInstance;
36 import org.onap.vid.utils.SystemPropertiesWrapper;
37
38 @RunWith(MockitoJUnitRunner.class)
39 public class PombaClientImplTest {
40
41     @Mock
42     private SystemPropertiesWrapper systemPropertiesWrapper;
43     @Mock
44     private PombaRestInterface pombaRestInterface;
45     @InjectMocks
46     private PombaClientImpl pombaClient;
47
48     @Test
49     public void should_doHttpPost_withGivenPombaRequest() throws IOException {
50         //Given
51         String expectedUrl = "http://localhost/dummyUrl";
52         given(systemPropertiesWrapper.getProperty("pomba.server.url")).willReturn(expectedUrl);
53         String expectedPayload = readExpectedPombaJsonRequest();
54         PombaRequest pombaRequest = createPombaRequest();
55
56         //When
57         pombaClient.verify(pombaRequest);
58
59         //Then
60         then(pombaRestInterface).should().RestPost("VidAaiController", expectedUrl, expectedPayload);
61     }
62
63     private String readExpectedPombaJsonRequest() throws IOException {
64         URL url = PombaClientImplTest.class.getClassLoader().getResource("pomba_request.json");
65         PombaRequest expectedPombaRequest = new ObjectMapper().readValue(url, PombaRequest.class);
66         return new ObjectMapper().writeValueAsString(expectedPombaRequest);
67     }
68
69     private PombaRequest createPombaRequest() {
70         ServiceInstance serviceInstance1 = createServiceInstance("serviceType1", "serviceInstanceId1", "customerId1",
71             "modelVersion1", "modelInvariantId1");
72         ServiceInstance serviceInstance2 = createServiceInstance("serviceType2", "serviceInstanceId2", "customerId2",
73             "modelVersion2", "modelInvariantId2");
74
75         PombaRequest pombaRequest = new PombaRequest(Lists.newArrayList(serviceInstance1, serviceInstance2));
76         return pombaRequest;
77     }
78
79     private ServiceInstance createServiceInstance(String serviceType, String serviceInstanceId, String customerId,
80         String modelVersionId, String modelInvariantId) {
81         ServiceInstance serviceInstance = new ServiceInstance(
82             serviceInstanceId,
83             modelVersionId,
84             modelInvariantId,
85             customerId,
86             serviceType);
87         return serviceInstance;
88     }
89
90 }