Fixed the Start-up Failure in the Dualstack Env
[holmes/rule-management.git] / rulemgt / src / test / java / org / onap / holmes / rulemgt / bolt / enginebolt / EngineServiceTest.java
1 /**\r
2  * Copyright 2017 ZTE Corporation.\r
3  * <p>\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  * <p>\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  * <p>\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 \r
18 package org.onap.holmes.rulemgt.bolt.enginebolt;\r
19 \r
20 \r
21 import org.apache.http.HttpResponse;\r
22 import org.apache.http.client.methods.CloseableHttpResponse;\r
23 import org.apache.http.impl.client.CloseableHttpClient;\r
24 import org.apache.http.impl.client.HttpClients;\r
25 import org.junit.Before;\r
26 import org.junit.Rule;\r
27 import org.junit.Test;\r
28 import org.junit.rules.ExpectedException;\r
29 import org.junit.runner.RunWith;\r
30 import org.onap.holmes.common.utils.HttpsUtils;\r
31 import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
32 import org.powermock.api.easymock.PowerMock;\r
33 import org.powermock.core.classloader.annotations.PowerMockIgnore;\r
34 import org.powermock.core.classloader.annotations.PrepareForTest;\r
35 import org.powermock.modules.junit4.PowerMockRunner;\r
36 import org.powermock.reflect.Whitebox;\r
37 \r
38 import java.util.HashMap;\r
39 \r
40 import static org.hamcrest.MatcherAssert.assertThat;\r
41 import static org.hamcrest.Matchers.equalTo;\r
42 \r
43 @PrepareForTest({HttpClients.class, CloseableHttpClient.class, HttpsUtils.class})\r
44 @PowerMockIgnore("javax.net.ssl.*")\r
45 @RunWith(PowerMockRunner.class)\r
46 public class EngineServiceTest {\r
47 \r
48     @Rule\r
49     public ExpectedException thrown = ExpectedException.none();\r
50     private EngineService engineService;\r
51     private HttpResponse httpResponseMock;\r
52     private CloseableHttpClient closeableHttpClient;\r
53     private CorrelationDeployRule4Engine correlationDeployRule4Engine;\r
54     private CloseableHttpResponse closeableHttpResponseMock;\r
55 \r
56     @Before\r
57     public void setUp() {\r
58         engineService = new EngineService();\r
59         closeableHttpClient = PowerMock.createMock(CloseableHttpClient.class);\r
60         httpResponseMock = PowerMock.createMock(HttpResponse.class);\r
61         closeableHttpResponseMock = PowerMock.createMock(CloseableHttpResponse.class);\r
62         correlationDeployRule4Engine = new CorrelationDeployRule4Engine();\r
63         correlationDeployRule4Engine.setContent("{\"package\":\"test\"}");\r
64         correlationDeployRule4Engine.setEngineId("engine_id");\r
65     }\r
66 \r
67     @Test\r
68     public void testEngineService_createHeaders_ok() throws Exception {\r
69         PowerMock.resetAll();\r
70         HashMap<String, String> headers = Whitebox.invokeMethod(engineService, "createHeaders");\r
71         assertThat(headers.get("Content-Type"), equalTo("application/json"));\r
72         assertThat(headers.get("Accept"), equalTo("application/json"));\r
73     }\r
74 \r
75     @Test\r
76     public void testEngineService_closeHttpClient_ok() throws Exception {\r
77         PowerMock.resetAll();\r
78         CloseableHttpClient closeableHttpClient = HttpsUtils\r
79                 .getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);\r
80         Whitebox.invokeMethod(engineService, "closeHttpClient", closeableHttpClient);\r
81     }\r
82 \r
83 }