|
|
@@ -8,6 +8,7 @@ import org.junit.Test;
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.Collections;
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
@@ -99,4 +100,56 @@ public class EiamClient_UserImplTest {
|
|
|
server.stop(0);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void deleteUser_plainTextResponse_returnsSuccessPayload() throws Exception {
|
|
|
+ HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
|
|
|
+ server.createContext("/v2/instance/application/users/user_test", exchange -> {
|
|
|
+ byte[] responseBody = "deleted".getBytes(StandardCharsets.UTF_8);
|
|
|
+ exchange.sendResponseHeaders(200, responseBody.length);
|
|
|
+ exchange.getResponseBody().write(responseBody);
|
|
|
+ exchange.close();
|
|
|
+ });
|
|
|
+ server.start();
|
|
|
+ try {
|
|
|
+ EiamConf conf = new EiamConf();
|
|
|
+ conf.setBaseUrl("http://127.0.0.1:" + server.getAddress().getPort());
|
|
|
+ EiamClient_UserImpl client = new EiamClient_UserImpl();
|
|
|
+ ReflectionTestUtils.setField(client, "eiamConf", conf);
|
|
|
+
|
|
|
+ EiamApiResponse response = client.deleteUser("token", "instance", "application",
|
|
|
+ "user_test");
|
|
|
+
|
|
|
+ assertNull(response.getCode());
|
|
|
+ } finally {
|
|
|
+ server.stop(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void deleteUser_errorStatus_throwsBusinessException() throws Exception {
|
|
|
+ HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
|
|
|
+ server.createContext("/v2/instance/application/users/user_test", exchange -> {
|
|
|
+ byte[] responseBody = "error".getBytes(StandardCharsets.UTF_8);
|
|
|
+ exchange.sendResponseHeaders(500, responseBody.length);
|
|
|
+ exchange.getResponseBody().write(responseBody);
|
|
|
+ exchange.close();
|
|
|
+ });
|
|
|
+ server.start();
|
|
|
+ try {
|
|
|
+ EiamConf conf = new EiamConf();
|
|
|
+ conf.setBaseUrl("http://127.0.0.1:" + server.getAddress().getPort());
|
|
|
+ EiamClient_UserImpl client = new EiamClient_UserImpl();
|
|
|
+ ReflectionTestUtils.setField(client, "eiamConf", conf);
|
|
|
+
|
|
|
+ try {
|
|
|
+ client.deleteUser("token", "instance", "application", "user_test");
|
|
|
+ fail("应拒绝非 2xx 删除响应");
|
|
|
+ } catch (McException ex) {
|
|
|
+ assertEquals("500", ex.getCode());
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ server.stop(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|