2 * Copyright 2021 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.holmes.engine.dcae;
19 import org.easymock.EasyMock;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.onap.holmes.common.dcae.DcaeConfigurationsCache;
23 import org.onap.holmes.common.utils.SpringContextUtil;
24 import org.onap.holmes.dsa.dmaappolling.DMaaPResponseUtil;
25 import org.onap.holmes.dsa.dmaappolling.Subscriber;
26 import org.onap.holmes.engine.dmaap.SubscriberAction;
27 import org.powermock.api.easymock.PowerMock;
28 import org.powermock.core.classloader.annotations.PrepareForTest;
29 import org.powermock.modules.junit4.PowerMockRunner;
30 import org.powermock.reflect.Whitebox;
32 import static org.hamcrest.core.IsEqual.equalTo;
33 import static org.junit.Assert.assertThat;
35 @RunWith(PowerMockRunner.class)
36 @PrepareForTest({SpringContextUtil.class})
37 public class ConfigFileScanningTaskTest {
41 PowerMock.mockStatic(SpringContextUtil.class);
42 SubscriberAction mockedSa = PowerMock.createMock(SubscriberAction.class);
43 EasyMock.expect(SpringContextUtil.getBean(SubscriberAction.class)).andReturn(mockedSa);
44 // This is invoked while executing new Subscriber().
45 EasyMock.expect(SpringContextUtil.getBean(DMaaPResponseUtil.class)).andReturn(new DMaaPResponseUtil());
46 mockedSa.addSubscriber(EasyMock.anyObject(Subscriber.class));
47 EasyMock.expectLastCall();
49 ConfigFileScanningTask cfst = new ConfigFileScanningTask(null);
50 String configFilePath = ConfigFileScanningTaskTest.class.getResource("/cfy.json").getFile();
51 Whitebox.setInternalState(cfst, "configFile", configFilePath);
53 PowerMock.replayAll();
55 PowerMock.verifyAll();
57 assertThat(DcaeConfigurationsCache.getPubSecInfo("dcae_cl_out").getDmaapInfo().getTopicUrl(),
58 equalTo("http://message-router.onap:3904/events/unauthenticated.DCAE_CL_OUTPUT"));
62 public void run_config_not_changed() {
63 PowerMock.mockStatic(SpringContextUtil.class);
64 SubscriberAction mockedSa = PowerMock.createMock(SubscriberAction.class);
65 // mocked objects will be only used once
66 EasyMock.expect(SpringContextUtil.getBean(SubscriberAction.class)).andReturn(mockedSa);
67 // This is invoked while executing new Subscriber().
68 EasyMock.expect(SpringContextUtil.getBean(DMaaPResponseUtil.class)).andReturn(new DMaaPResponseUtil());
69 mockedSa.addSubscriber(EasyMock.anyObject(Subscriber.class));
70 EasyMock.expectLastCall();
72 ConfigFileScanningTask cfst = new ConfigFileScanningTask(null);
73 String configFilePath = ConfigFileScanningTaskTest.class.getResource("/cfy.json").getFile();
74 Whitebox.setInternalState(cfst, "configFile", configFilePath);
76 PowerMock.replayAll();
79 PowerMock.verifyAll();