/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2018 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.onap.msb.sdk.discovery.MSBService;
import org.onap.msb.sdk.discovery.common.RouteException;
import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
@RunWith(PowerMockRunner.class)
@PrepareForTest({HttpClientUtil.class})
+@PowerMockIgnore("jdk.internal.reflect.*")
public class MSBServiceClientTest {
private static final String MOCK_MSB_URL_REG_UPDATE_TRUE =
"http://127.0.0.1:10081/api/microservices/v1/services?createOrUpdate=true";
"http://127.0.0.1:10081/api/microservices/v1/services/aai/version/v8";
private static final String MOCK_REG_SERVICE_JSON =
- "{\"serviceName\":\"aai\",\"version\":\"v8\",\"url\":\"/aai/v8\",\"protocol\":\"REST\",\"visualRange\":\"1\",\"lb_policy\":\"\",\"path\":\"/aai/v8\",\"nodes\":[{\"ip\":\"10.74.44.1\",\"port\":\"8443\",\"ttl\":\"\"}],\"metadata\":null}";
+ "{\"serviceName\":\"aai\",\"version\":\"v8\",\"url\":\"/aai/v8\",\"protocol\":\"REST\",\"visualRange\":\"1\",\"lb_policy\":\"\",\"path\":\"/aai/v8\",\"nodes\":[{\"ip\":\"10.74.44.1\",\"port\":\"8443\",\"ttl\":\"\",\"checkType\":\"HTTP\",\"checkUrl\":\"\",\"checkInterval\":\"10s\",\"checkTimeOut\":\"10s\"}],\"metadata\":null,\"enable_ssl\":false}";
@Test
public void test_registration_update_true() throws RouteException {
Assert.assertTrue(microServiceFullInfo.getVisualRange().equals("1"));
}
+ @Test
+ public void test_unregistration() throws Exception {
+ mockHttpDel();
+ MSBServiceClient msbClient = new MSBServiceClient("127.0.0.1", 10081);
+ msbClient.cancelMicroServiceInfo("aai", "v8");
+ }
+
+ @Test
+ public void test_unregistration_a_instance() throws Exception {
+ mockHttpDel();
+ MSBServiceClient msbClient = new MSBServiceClient("127.0.0.1", 10081);
+ msbClient.cancelMicroServiceInfo("aai", "v8", "10.74.44.1", "8443");
+ }
+
private MicroServiceFullInfo mockMicroServiceFullInfo(MicroServiceInfo info) {
MicroServiceFullInfo serviceInfo = new MicroServiceFullInfo();
serviceInfo.setServiceName(info.getServiceName());
PowerMockito.when(HttpClientUtil.httpGet(mockMSBUrl)).thenReturn(mockServiceInfoJson);
}
+ private void mockHttpDel() throws Exception {
+ PowerMockito.mockStatic(HttpClientUtil.class);
+
+ }
}