2 * Copyright 2020 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
15 package org.onap.holmes.engine;
17 import org.easymock.EasyMock;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.onap.holmes.common.config.MicroServiceConfig;
21 import org.onap.holmes.common.utils.MsbRegister;
22 import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
23 import org.powermock.api.easymock.PowerMock;
24 import org.powermock.core.classloader.annotations.PrepareForTest;
25 import org.powermock.modules.junit4.PowerMockRunner;
26 import org.powermock.reflect.internal.WhiteboxImpl;
28 import java.util.concurrent.TimeUnit;
30 @RunWith(PowerMockRunner.class)
31 @PrepareForTest(MicroServiceConfig.class)
32 public class InitializerTest {
35 public void process() throws Exception {
36 MsbRegister mockedMsbRegister = PowerMock.createMock(MsbRegister.class);
37 Initializer initializer = new Initializer(mockedMsbRegister);
39 PowerMock.mockStaticPartial(MicroServiceConfig.class, "getMicroServiceIpAndPort", "getEnv");
40 EasyMock.expect(MicroServiceConfig.getMicroServiceIpAndPort()).andReturn(new String[]{"127.0.0.1", "443"});
41 System.setProperty("ENABLE_ENCRYPT", "true");
43 mockedMsbRegister.register2Msb(EasyMock.anyObject(MicroServiceInfo.class));
44 EasyMock.expectLastCall();
46 PowerMock.replayAll();
50 WhiteboxImpl.invokeMethod(initializer, "init");
52 TimeUnit.SECONDS.sleep(6);
54 PowerMock.verifyAll();
57 private void setReadyFlagAfter(final int second) {
60 TimeUnit.SECONDS.sleep(second);
61 } catch (InterruptedException e) {
64 Initializer.setReadyForMsbReg(true);