2 * Copyright 2017 ZTE Corporation.
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
18 package org.onap.holmes.rulemgt.bolt.enginebolt;
\r
21 import static org.hamcrest.MatcherAssert.assertThat;
\r
22 import static org.hamcrest.Matchers.equalTo;
\r
24 import java.util.HashMap;
\r
25 import org.apache.http.HttpResponse;
\r
26 import org.apache.http.client.methods.CloseableHttpResponse;
\r
27 import org.apache.http.impl.client.CloseableHttpClient;
\r
28 import org.apache.http.impl.client.HttpClients;
\r
29 import org.junit.Before;
\r
30 import org.junit.Rule;
\r
31 import org.junit.Test;
\r
32 import org.junit.rules.ExpectedException;
\r
33 import org.onap.holmes.common.utils.HttpsUtils;
\r
34 import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
\r
35 import org.powermock.api.easymock.PowerMock;
\r
36 import org.powermock.core.classloader.annotations.PowerMockIgnore;
\r
37 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
38 import org.powermock.modules.junit4.rule.PowerMockRule;
\r
39 import org.powermock.reflect.Whitebox;
\r
41 @PrepareForTest({HttpClients.class, CloseableHttpClient.class, HttpsUtils.class})
\r
42 @PowerMockIgnore("javax.net.ssl.*")
\r
43 public class EngineServiceTest {
\r
46 public ExpectedException thrown = ExpectedException.none();
\r
48 public PowerMockRule powerMockRule = new PowerMockRule();
\r
49 private EngineService engineService;
\r
50 private HttpResponse httpResponseMock;
\r
51 private CloseableHttpClient closeableHttpClient;
\r
52 private CorrelationDeployRule4Engine correlationDeployRule4Engine;
\r
53 private CloseableHttpResponse closeableHttpResponseMock;
\r
56 public void setUp() {
\r
57 engineService = new EngineService();
\r
58 closeableHttpClient = PowerMock.createMock(CloseableHttpClient.class);
\r
59 httpResponseMock = PowerMock.createMock(HttpResponse.class);
\r
60 closeableHttpResponseMock = PowerMock.createMock(CloseableHttpResponse.class);
\r
61 correlationDeployRule4Engine = new CorrelationDeployRule4Engine();
\r
62 correlationDeployRule4Engine.setContent("{\"package\":\"test\"}");
\r
63 correlationDeployRule4Engine.setEngineId("engine_id");
\r
67 public void testEngineService_createHeaders_ok() throws Exception {
\r
68 PowerMock.resetAll();
\r
69 HashMap<String, String> headers = Whitebox.invokeMethod(engineService, "createHeaders");
\r
70 assertThat(headers.get("Content-Type"), equalTo("application/json"));
\r
71 assertThat(headers.get("Accept"), equalTo("application/json"));
\r
75 public void testEngineService_closeHttpClient_ok() throws Exception {
\r
76 PowerMock.resetAll();
\r
77 CloseableHttpClient closeableHttpClient = HttpsUtils
\r
78 .getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);
\r
79 Whitebox.invokeMethod(engineService, "closeHttpClient", closeableHttpClient);
\r