1a5795ad578ccbcb2a4fbae468dd2fa46ef7ff63
[holmes/engine-management.git] / engine-d / src / test / java / org / onap / holmes / engine / EngineDActiveAppTest.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 package org.onap.holmes.engine;\r
17 \r
18 import org.easymock.EasyMock;\r
19 import org.junit.Test;\r
20 import org.junit.runner.RunWith;\r
21 import org.onap.holmes.common.config.MicroServiceConfig;\r
22 import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;\r
23 import org.onap.msb.sdk.discovery.entity.Node;\r
24 import org.powermock.api.easymock.PowerMock;\r
25 import org.powermock.core.classloader.annotations.PrepareForTest;\r
26 import org.powermock.modules.junit4.PowerMockRunner;\r
27 import org.powermock.reflect.Whitebox;\r
28 \r
29 import static org.hamcrest.CoreMatchers.equalTo;\r
30 import static org.hamcrest.CoreMatchers.is;\r
31 import static org.junit.Assert.assertThat;\r
32 \r
33 @PrepareForTest(MicroServiceConfig.class)\r
34 @RunWith(PowerMockRunner.class)\r
35 public class EngineDActiveAppTest {\r
36 \r
37     public static void main(String[] args) throws Exception {\r
38         String filePath = "C:\\engine-d.yml";\r
39         new EngineDActiveApp().run(new String[]{"server", filePath});\r
40     }\r
41 \r
42     @Test\r
43     public void testCreateMicroServiceInfo() throws Exception {\r
44         EngineDActiveApp engineDActiveApp = new EngineDActiveApp();\r
45         PowerMock.mockStatic(MicroServiceConfig.class);\r
46         String[] serviceAddrInfo = new String[2];\r
47         serviceAddrInfo[0] = "10.74.216.82";\r
48         serviceAddrInfo[1] = "80";\r
49         EasyMock.expect(MicroServiceConfig.getMicroServiceIpAndPort()).andReturn(serviceAddrInfo);\r
50         EasyMock.expectLastCall();\r
51         PowerMock.replayAll();\r
52 \r
53         MicroServiceInfo msinfo = Whitebox.invokeMethod(engineDActiveApp,"createMicroServiceInfo");\r
54 \r
55         PowerMock.verifyAll();\r
56 \r
57         assertThat(msinfo.getServiceName(), equalTo("holmes-engine-mgmt"));\r
58         assertThat(msinfo.getVersion(), equalTo("v1"));\r
59         assertThat(msinfo.getUrl(), equalTo("/api/holmes-engine-mgmt/v1"));\r
60         assertThat(msinfo.getProtocol(), equalTo("REST"));\r
61         assertThat(msinfo.getVisualRange(), equalTo("0|1"));\r
62         assertThat(msinfo.isEnable_ssl(), is(true));\r
63         assertThat(msinfo.getNodes().toArray(new Node[0])[0].getIp(), equalTo(serviceAddrInfo[0]));\r
64         assertThat(msinfo.getNodes().toArray(new Node[0])[0].getPort(), equalTo("9102"));\r
65     }\r
66 }\r