Update Logging
[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.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.post;
25 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
26 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertThat;
29
30 import java.io.File;
31 import java.io.IOException;
32
33 import org.apache.http.HttpStatus;
34 import org.junit.Test;
35 import org.onap.so.client.avpn.dmaap.beans.AVPNDmaapBean;
36 import org.onap.so.client.exception.MapperException;
37 import org.onap.so.BaseTest;
38 import org.springframework.beans.factory.annotation.Autowired;
39
40 import com.fasterxml.jackson.core.JsonProcessingException;
41 import com.fasterxml.jackson.databind.ObjectMapper;
42 import static com.github.tomakehurst.wiremock.client.WireMock.*;
43
44 public class DmaapPropertiesClientTest extends BaseTest{
45         
46         @Autowired
47         private DmaapPropertiesClient dmaapPropertiesClient;
48
49         private final String file = "src/test/resources/org/onap/so/client/avpn/dmaap/avpnDmaapAsyncRequestStatus.json";
50         private String requestId = "rq1234d1-5a33-55df-13ab-12abad84e331";
51         private String clientSource = "SPP";
52         private String correlator = "myClientId123";
53         private String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
54         private String startTime = "2017-11-17T09:30:47Z";
55         private String finishTime = "2017-11-17T09:30:47Z";
56         private String requestScope = "service";
57         private String requestType = "createInstance";
58         private String timestamp = "2017-11-17T09:30:47Z";
59         private String requestState = "COMPLETE";
60         private String statusMessage = "Success";
61         private String percentProgress = "100";
62         
63         @Test
64         public void testBuildRequestJson() throws MapperException, IOException {
65                 AVPNDmaapBean actualBean = dmaapPropertiesClient.buildRequestJson(requestId, clientSource, correlator, serviceInstanceId, startTime, finishTime, requestScope,
66                                                                                                                                                         requestType, timestamp, requestState, statusMessage, percentProgress, true);
67
68                 AVPNDmaapBean expected = new ObjectMapper().readValue(new File(file), AVPNDmaapBean.class);
69
70                 assertNotNull(actualBean);
71                 assertThat(actualBean, sameBeanAs(expected));
72         }
73
74         @Test
75         public void testDmaapPublishRequest() throws JsonProcessingException, MapperException {
76                 stubFor(post(urlEqualTo("/events/com.att.mso.asyncStatusUpdate?timeout=20000"))
77                                 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_ACCEPTED)));
78
79                 dmaapPropertiesClient.dmaapPublishRequest(requestId, clientSource, correlator, serviceInstanceId, startTime, finishTime, requestScope,
80                                                                                                         requestType, timestamp, requestState, statusMessage, percentProgress, false);
81         }
82 }