2f6a00db66fa07cf5781d23b5f5235d65eea746a
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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.openecomp.mso.bpmn.infrastructure.pnf.dmaap;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.verify;
26
27 import java.lang.reflect.Field;
28 import org.apache.http.client.HttpClient;
29 import org.apache.http.client.methods.HttpGet;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.ArgumentCaptor;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.test.context.ContextConfiguration;
36 import org.springframework.test.context.junit4.SpringRunner;
37
38 @RunWith(SpringRunner.class)
39 @ContextConfiguration({"classpath:springConfig_PnfEventReadyConsumer.xml"})
40 public class PnfEventReadyConsumerTest {
41
42     @Autowired
43     private PnfEventReadyConsumer pnfEventReadyConsumer;
44
45     private HttpClient httpClientMock;
46
47     @Before
48     public void init() throws NoSuchFieldException, IllegalAccessException {
49         httpClientMock = mock(HttpClient.class);
50         setPrivateField();
51     }
52
53     @Test
54     public void restClientInvokesWithProperURI() throws Exception {
55         ArgumentCaptor<HttpGet> captor1 = ArgumentCaptor.forClass(HttpGet.class);
56         pnfEventReadyConsumer.notifyWhenPnfReady("correlationId");
57         verify(httpClientMock).execute(captor1.capture());
58         assertThat(captor1.getValue().getURI()).hasHost("hostTest").hasPort(1234).hasScheme("http")
59                 .hasPath("/eventsForTesting/eventTopicTest/consumerGroupTest/consumerTestId");
60     }
61
62     private void setPrivateField() throws NoSuchFieldException, IllegalAccessException {
63         Field field = pnfEventReadyConsumer.getClass().getDeclaredField("httpClient");
64         field.setAccessible(true);
65         field.set(pnfEventReadyConsumer, httpClientMock);
66     }
67
68 }