91be5d382678a3601da833d36e737b31c9d2cd83
[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.modules.junit4.rule.PowerMockRule;\r
37 import org.powermock.reflect.Whitebox;\r
38 \r
39 import java.util.HashMap;\r
40 \r
41 import static org.hamcrest.MatcherAssert.assertThat;\r
42 import static org.hamcrest.Matchers.equalTo;\r
43 \r
44 @PrepareForTest({HttpClients.class, CloseableHttpClient.class, HttpsUtils.class})\r
45 @PowerMockIgnore("javax.net.ssl.*")\r
46 @RunWith(PowerMockRunner.class)\r
47 public class EngineServiceTest {\r
48 \r
49     @Rule\r
50     public ExpectedException thrown = ExpectedException.none();\r
51     private EngineService engineService;\r
52     private HttpResponse httpResponseMock;\r
53     private CloseableHttpClient closeableHttpClient;\r
54     private CorrelationDeployRule4Engine correlationDeployRule4Engine;\r
55     private CloseableHttpResponse closeableHttpResponseMock;\r
56 \r
57     @Before\r
58     public void setUp() {\r
59         engineService = new EngineService();\r
60         closeableHttpClient = PowerMock.createMock(CloseableHttpClient.class);\r
61         httpResponseMock = PowerMock.createMock(HttpResponse.class);\r
62         closeableHttpResponseMock = PowerMock.createMock(CloseableHttpResponse.class);\r
63         correlationDeployRule4Engine = new CorrelationDeployRule4Engine();\r
64         correlationDeployRule4Engine.setContent("{\"package\":\"test\"}");\r
65         correlationDeployRule4Engine.setEngineId("engine_id");\r
66     }\r
67 \r
68     @Test\r
69     public void testEngineService_createHeaders_ok() throws Exception {\r
70         PowerMock.resetAll();\r
71         HashMap<String, String> headers = Whitebox.invokeMethod(engineService, "createHeaders");\r
72         assertThat(headers.get("Content-Type"), equalTo("application/json"));\r
73         assertThat(headers.get("Accept"), equalTo("application/json"));\r
74     }\r
75 \r
76     @Test\r
77     public void testEngineService_closeHttpClient_ok() throws Exception {\r
78         PowerMock.resetAll();\r
79         CloseableHttpClient closeableHttpClient = HttpsUtils\r
80                 .getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);\r
81         Whitebox.invokeMethod(engineService, "closeHttpClient", closeableHttpClient);\r
82     }\r
83 \r
84 }