summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuangrongFu <fu.guangrong@zte.com.cn>2021-06-29 19:19:30 +0800
committerGuangrongFu <fu.guangrong@zte.com.cn>2021-06-29 19:19:30 +0800
commit9e95ae0e4a525362558e3a00cc9d93245fb74262 (patch)
tree32b5b34d376cf43c5d37e4c42cd3591f53bb7acd
parent732234a32c7413ccf4f49b592ff6ed3e17c7059b (diff)
Fixed the UT problem
Change-Id: I6d3a056ede03e5af5248ee925fc5e1bd13f4d6c4 Issue-ID: HOLMES-453 Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java21
1 files changed, 12 insertions, 9 deletions
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java
index 19b3251..cf40c17 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java
@@ -27,40 +27,39 @@ import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.internal.WhiteboxImpl;
import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.expect;
-import static org.powermock.api.easymock.PowerMock.createPartialMock;
+import static org.powermock.api.easymock.PowerMock.createMock;
+import static org.powermock.api.easymock.PowerMock.expectNew;
@PrepareForTest({MicroServiceConfig.class, JerseyClient.class})
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"javax.net.ssl.*", "javax.security.*"})
public class MsbRegisterTest {
- private MsbRegister msbRegister;
private JerseyClient mockedJerseyClient;
private MicroServiceInfo msi;
@Before
- public void before() {
+ public void before() throws Exception {
msi = new MicroServiceInfo();
String[] msbAddrInfo = {"127.0.0.1", "80"};
PowerMock.mockStatic(MicroServiceConfig.class);
expect(MicroServiceConfig.getMsbIpAndPort()).andReturn(msbAddrInfo);
- mockedJerseyClient = createPartialMock(JerseyClient.class,
- "post", new Class[]{String.class, Entity.class, Class.class});
-
- msbRegister = new MsbRegister();
- WhiteboxImpl.setInternalState(msbRegister, "client", mockedJerseyClient);
+ mockedJerseyClient = createMock(JerseyClient.class);
+ expectNew(JerseyClient.class).andReturn(mockedJerseyClient);
}
@Test
public void test_register2Msb_normal() {
+ expect(mockedJerseyClient.header("Accept", MediaType.APPLICATION_JSON)).andReturn(mockedJerseyClient);
+ expect(mockedJerseyClient.queryParam("createOrUpdate", true)).andReturn(mockedJerseyClient);
expect(mockedJerseyClient.post(anyObject(String.class),
anyObject(Entity.class),
anyObject(Class.class)))
@@ -75,6 +74,7 @@ public class MsbRegisterTest {
PowerMock.replayAll();
+ MsbRegister msbRegister = new MsbRegister();
try {
msbRegister.register2Msb(msi);
} catch (CorrelationException e) {
@@ -86,6 +86,8 @@ public class MsbRegisterTest {
@Test
public void test_register2Msb_fail_once() {
+ expect(mockedJerseyClient.header("Accept", MediaType.APPLICATION_JSON)).andReturn(mockedJerseyClient).times(2);
+ expect(mockedJerseyClient.queryParam("createOrUpdate", true)).andReturn(mockedJerseyClient).times(2);
expect(mockedJerseyClient.post(anyObject(String.class),
anyObject(Entity.class),
anyObject(Class.class)))
@@ -105,6 +107,7 @@ public class MsbRegisterTest {
PowerMock.replayAll();
+ MsbRegister msbRegister = new MsbRegister();
try {
msbRegister.register2Msb(msi);
} catch (CorrelationException e) {