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
16 package org.onap.holmes.engine;
\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.PowerMockIgnore;
\r
26 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
27 import org.powermock.modules.junit4.PowerMockRunner;
\r
28 import org.powermock.reflect.Whitebox;
\r
30 import static org.easymock.EasyMock.anyObject;
\r
31 import static org.hamcrest.CoreMatchers.equalTo;
\r
32 import static org.hamcrest.CoreMatchers.is;
\r
33 import static org.junit.Assert.assertThat;
\r
35 @PrepareForTest(MicroServiceConfig.class)
\r
36 @RunWith(PowerMockRunner.class)
\r
37 @PowerMockIgnore("javax.net.ssl.*")
\r
38 public class EngineDActiveAppTest {
\r
40 public static void main(String[] args) throws Exception {
\r
41 String filePath = "C:\\engine-d.yml";
\r
42 new EngineDActiveApp().run(new String[]{"server", filePath});
\r
46 public void testCreateMicroServiceInfo() throws Exception {
\r
47 EngineDActiveApp engineDActiveApp = new EngineDActiveApp();
\r
48 PowerMock.mockStatic(MicroServiceConfig.class);
\r
49 String[] serviceAddrInfo = new String[2];
\r
50 serviceAddrInfo[0] = "10.74.216.82";
\r
51 serviceAddrInfo[1] = "80";
\r
52 EasyMock.expect(MicroServiceConfig.getMicroServiceIpAndPort()).andReturn(serviceAddrInfo);
\r
53 EasyMock.expectLastCall();
\r
54 EasyMock.expect(MicroServiceConfig.getEnv(anyObject(String.class))).andReturn("true").times(2);
\r
55 PowerMock.replayAll();
\r
57 MicroServiceInfo msinfo = Whitebox.invokeMethod(engineDActiveApp,"createMicroServiceInfo");
\r
59 PowerMock.verifyAll();
\r
61 assertThat(msinfo.getServiceName(), equalTo("holmes-engine-mgmt"));
\r
62 assertThat(msinfo.getVersion(), equalTo("v1"));
\r
63 assertThat(msinfo.getUrl(), equalTo("/api/holmes-engine-mgmt/v1"));
\r
64 assertThat(msinfo.getProtocol(), equalTo("REST"));
\r
65 assertThat(msinfo.getVisualRange(), equalTo("0|1"));
\r
66 assertThat(msinfo.isEnable_ssl(), is(true));
\r
67 assertThat(msinfo.getNodes().toArray(new Node[0])[0].getIp(), equalTo(serviceAddrInfo[0]));
\r
68 assertThat(msinfo.getNodes().toArray(new Node[0])[0].getPort(), equalTo("9102"));
\r