Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / onap / so / client / dmaapproperties / DmaapPropertiesClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
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
21 package org.onap.so.client.dmaapproperties;
22
23 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertThat;
26 import static org.mockito.Matchers.anyString;
27 import static org.mockito.Mockito.doNothing;
28 import static org.mockito.Mockito.doReturn;
29 import static org.mockito.Mockito.times;
30 import static org.mockito.Mockito.verify;
31 import java.io.File;
32 import java.io.IOException;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.mockito.Mockito;
36 import org.mockito.MockitoAnnotations;
37 import org.onap.so.BaseTest;
38 import org.onap.so.client.avpn.dmaap.beans.AVPNDmaapBean;
39 import org.onap.so.client.exception.MapperException;
40 import org.onap.so.client.dmaapproperties.GlobalDmaapPublisher;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import com.fasterxml.jackson.core.JsonProcessingException;
43 import com.fasterxml.jackson.databind.ObjectMapper;
44
45 public class DmaapPropertiesClientTest extends BaseTest {
46
47     @Autowired
48     private DmaapPropertiesClient dmaapPropertiesClient;
49
50
51     private final String file = "src/test/resources/org/onap/so/client/avpn/dmaap/avpnDmaapAsyncRequestStatus.json";
52     private String requestId = "rq1234d1-5a33-55df-13ab-12abad84e331";
53     private String clientSource = "SPP";
54     private String correlator = "myClientId123";
55     private String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
56     private String startTime = "2017-11-17T09:30:47Z";
57     private String finishTime = "2017-11-17T09:30:47Z";
58     private String requestScope = "service";
59     private String requestType = "createInstance";
60     private String timestamp = "2017-11-17T09:30:47Z";
61     private String requestState = "COMPLETE";
62     private String statusMessage = "Success";
63     private String percentProgress = "100";
64
65     @Test
66     public void testBuildRequestJson() throws MapperException, IOException {
67         AVPNDmaapBean actualBean = dmaapPropertiesClient.buildRequestJson(requestId, clientSource, correlator,
68                 serviceInstanceId, startTime, finishTime, requestScope, requestType, timestamp, requestState,
69                 statusMessage, percentProgress, true);
70
71         AVPNDmaapBean expected = new ObjectMapper().readValue(new File(file), AVPNDmaapBean.class);
72
73         assertNotNull(actualBean);
74         assertThat(actualBean, sameBeanAs(expected));
75     }
76
77     @Test
78     public void testDmaapPublishRequest() throws JsonProcessingException, MapperException {
79         DmaapPropertiesClient client = Mockito.spy(DmaapPropertiesClient.class);
80         GlobalDmaapPublisher mockedClientDmaapPublisher = Mockito.mock(GlobalDmaapPublisher.class);
81         AVPNDmaapBean mockedDmaapBean = Mockito.mock(AVPNDmaapBean.class);
82         String request = "test";
83
84         doReturn(mockedDmaapBean).when(client).buildRequestJson(requestId, clientSource, correlator, serviceInstanceId,
85                 startTime, finishTime, requestScope, requestType, timestamp, requestState, statusMessage,
86                 percentProgress, false);
87
88         AVPNDmaapBean actualDmaapBean =
89                 client.buildRequestJson(requestId, clientSource, correlator, serviceInstanceId, startTime, finishTime,
90                         requestScope, requestType, timestamp, requestState, statusMessage, percentProgress, false);
91         mockedClientDmaapPublisher.send(request);
92
93         doNothing().when(mockedClientDmaapPublisher).send(anyString());
94
95         verify(client, times(1)).buildRequestJson(requestId, clientSource, correlator, serviceInstanceId, startTime,
96                 finishTime, requestScope, requestType, timestamp, requestState, statusMessage, percentProgress, false);
97         verify(mockedClientDmaapPublisher, times(1)).send(request);
98
99         assertNotNull(actualDmaapBean);
100     }
101 }