2 * Copyright 2017-2020 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.
16 package org.onap.holmes.common.dmaap;
18 import org.apache.commons.lang3.StringUtils;
19 import org.easymock.EasyMock;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.onap.holmes.common.dmaap.entity.PolicyMsg;
23 import org.onap.holmes.common.utils.JerseyClient;
24 import org.powermock.api.easymock.PowerMock;
25 import org.powermock.core.classloader.annotations.PowerMockIgnore;
26 import org.powermock.modules.junit4.PowerMockRunner;
27 import org.powermock.reflect.internal.WhiteboxImpl;
29 import jakarta.ws.rs.client.Entity;
31 import static org.easymock.EasyMock.anyObject;
33 @RunWith(PowerMockRunner.class)
34 @PowerMockIgnore({"javax.net.ssl.*", "javax.security.*"})
35 public class PublisherTest {
38 public void publish_normal() {
40 Publisher publisher = new Publisher();
41 publisher.setUrl("http://localhost/dmaapTopic");
43 JerseyClient mockedJerseyClient = PowerMock.createMock(JerseyClient.class);
44 WhiteboxImpl.setInternalState(publisher, "client", mockedJerseyClient);
45 EasyMock.expect(mockedJerseyClient.post(anyObject(String.class), anyObject(Entity.class)))
46 .andReturn(StringUtils.EMPTY);
48 PowerMock.replayAll();
50 publisher.publish(new PolicyMsg());
52 PowerMock.verifyAll();