Released Version 1.4.7
[holmes/common.git] / holmes-actions / src / test / java / org / onap / holmes / common / dmaap / PublisherTest.java
1 /*
2  * Copyright 2017-2020 ZTE Corporation.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.holmes.common.dmaap;
17
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;
28
29 import jakarta.ws.rs.client.Entity;
30
31 import static org.easymock.EasyMock.anyObject;
32
33 @RunWith(PowerMockRunner.class)
34 @PowerMockIgnore({"javax.net.ssl.*", "javax.security.*"})
35 public class PublisherTest {
36
37     @Test
38     public void publish_normal() {
39
40         Publisher publisher = new Publisher();
41         publisher.setUrl("http://localhost/dmaapTopic");
42
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);
47
48         PowerMock.replayAll();
49
50         publisher.publish(new PolicyMsg());
51
52         PowerMock.verifyAll();
53     }
54
55 }