Add msb register code
[holmes/rule-management.git] / rulemgt / src / test / java / org / openo / holmes / rulemgt / bolt / enginebolt / EngineServiceTest.java
1 /**\r
2  * Copyright 2017 ZTE Corporation.\r
3  *\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  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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.openo.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.client.methods.HttpPut;\r
24 import org.apache.http.impl.client.CloseableHttpClient;\r
25 import org.apache.http.impl.client.HttpClients;\r
26 import org.easymock.EasyMock;\r
27 import org.junit.Before;\r
28 import org.junit.Rule;\r
29 import org.junit.Test;\r
30 import org.junit.rules.ExpectedException;\r
31 import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
32 import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
33 import org.powermock.api.easymock.PowerMock;\r
34 import org.powermock.core.classloader.annotations.PrepareForTest;\r
35 import org.powermock.modules.junit4.rule.PowerMockRule;\r
36 \r
37 @PrepareForTest({HttpClients.class, CloseableHttpClient.class})\r
38 public class EngineServiceTest {\r
39 \r
40     @Rule\r
41     public ExpectedException thrown = ExpectedException.none();\r
42     @Rule\r
43     public PowerMockRule powerMockRule = new PowerMockRule();\r
44     private EngineService engineService;\r
45     private HttpResponse httpResponseMock;\r
46     private CloseableHttpClient closeableHttpClient;\r
47     private CorrelationDeployRule4Engine correlationDeployRule4Engine;\r
48     private CloseableHttpResponse closeableHttpResponseMock;\r
49 \r
50     @Before\r
51     public void setUp() {\r
52         engineService = new EngineService();\r
53         closeableHttpClient = PowerMock.createMock(CloseableHttpClient.class);\r
54         httpResponseMock = PowerMock.createMock(HttpResponse.class);\r
55         closeableHttpResponseMock = PowerMock.createMock(CloseableHttpResponse.class);\r
56         correlationDeployRule4Engine = new CorrelationDeployRule4Engine();\r
57         correlationDeployRule4Engine.setContent("{\"package\":\"test\"}");\r
58         correlationDeployRule4Engine.setEngineId("engine_id");\r
59     }\r
60 \r
61     @Test\r
62     public void getResponseContent_http_entity_is_null() throws Exception {\r
63         EasyMock.expect(httpResponseMock.getEntity()).andReturn(null);\r
64         PowerMock.replayAll();\r
65 \r
66         engineService.getResponseContent(httpResponseMock);\r
67 \r
68         PowerMock.verifyAll();\r
69     }\r
70 \r
71     @Test\r
72     public void delete_exception() throws Exception {\r
73         thrown.expect(Exception.class);\r
74 \r
75         engineService.delete("test");\r
76 \r
77     }\r
78 \r
79     @Test\r
80     public void deploy_exception() throws Exception {\r
81 \r
82         thrown.expect(Exception.class);\r
83 \r
84         engineService.deploy(correlationDeployRule4Engine);\r
85 \r
86     }\r
87 \r
88     @Test\r
89     public void check_normal() throws Exception {\r
90         thrown.expect(Exception.class);\r
91 \r
92         engineService.check(new CorrelationCheckRule4Engine());\r
93 \r
94     }\r
95 }