refactor(test): extract BaseApiTest to eliminate login duplication
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
package com.healthlink.his.billing;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import com.core.common.utils.JsonUtils;
|
||||
import tools.jackson.databind.JsonNode;
|
||||
import org.junit.Before;
|
||||
import com.core.common.utils.JsonNode;
|
||||
import com.healthlink.his.web.BaseApiTest;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@@ -21,74 +17,7 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class BillingApiTest {
|
||||
|
||||
private static final String BASE_URL = "http://localhost:18082/healthlink-his";
|
||||
private String token;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
token = login();
|
||||
assertNotNull("登录失败", token);
|
||||
}
|
||||
|
||||
private String login() throws Exception {
|
||||
URL url = new URL(BASE_URL + "/login");
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setDoOutput(true);
|
||||
String body = "{\"username\":\"admin\",\"password\":\"admin123\",\"tenantId\":\"1\"}";
|
||||
conn.getOutputStream().write(body.getBytes(StandardCharsets.UTF_8));
|
||||
conn.getOutputStream().flush();
|
||||
int code = conn.getResponseCode();
|
||||
if (code == 200) {
|
||||
String resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
return JsonUtils.parse(resp).path("token").asText();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private JsonNode apiGetJson(String path) throws Exception {
|
||||
URL url = new URL(BASE_URL + path);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Authorization", "Bearer " + token);
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setConnectTimeout(10000);
|
||||
conn.setReadTimeout(30000);
|
||||
int code = conn.getResponseCode();
|
||||
String resp;
|
||||
if (code >= 200 && code < 300) {
|
||||
resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
} else {
|
||||
java.io.InputStream es = conn.getErrorStream();
|
||||
resp = (es != null) ? new String(es.readAllBytes(), StandardCharsets.UTF_8) : "{\"code\":" + code + "}";
|
||||
}
|
||||
try { return JsonUtils.parse(resp); } catch (Exception e) { return null; }
|
||||
}
|
||||
|
||||
private JsonNode apiPutJson(String path, String json) throws Exception {
|
||||
URL url = new URL(BASE_URL + path);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("PUT");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setRequestProperty("Authorization", "Bearer " + token);
|
||||
conn.setConnectTimeout(10000);
|
||||
conn.setReadTimeout(30000);
|
||||
conn.setDoOutput(true);
|
||||
conn.getOutputStream().write(json.getBytes(StandardCharsets.UTF_8));
|
||||
conn.getOutputStream().flush();
|
||||
int code = conn.getResponseCode();
|
||||
String resp;
|
||||
if (code >= 200 && code < 300) {
|
||||
resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
} else {
|
||||
java.io.InputStream es = conn.getErrorStream();
|
||||
resp = (es != null) ? new String(es.readAllBytes(), StandardCharsets.UTF_8) : "{\"code\":" + code + "}";
|
||||
}
|
||||
try { return JsonUtils.parse(resp); } catch (Exception e) { return null; }
|
||||
}
|
||||
public class BillingApiTest extends BaseApiTest {
|
||||
|
||||
// === 1. 收费初始化(已确认可用) ===
|
||||
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
package com.healthlink.his.inpatient;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import com.core.common.utils.JsonUtils;
|
||||
import tools.jackson.databind.JsonNode;
|
||||
import tools.jackson.databind.JsonNode;
|
||||
import org.junit.Before;
|
||||
import com.core.common.utils.JsonNode;
|
||||
import com.healthlink.his.web.BaseApiTest;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@@ -19,90 +14,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class InpatientApiTest {
|
||||
|
||||
private static final String BASE_URL = "http://localhost:18082/healthlink-his";
|
||||
private String token;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
token = login();
|
||||
assertNotNull("登录失败", token);
|
||||
}
|
||||
|
||||
private String login() throws Exception {
|
||||
URL url = new URL(BASE_URL + "/login");
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setDoOutput(true);
|
||||
String body = "{\"username\":\"admin\",\"password\":\"admin123\",\"tenantId\":\"1\"}";
|
||||
conn.getOutputStream().write(body.getBytes(StandardCharsets.UTF_8));
|
||||
conn.getOutputStream().flush();
|
||||
int code = conn.getResponseCode();
|
||||
if (code == 200) {
|
||||
String resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
return JsonUtils.parse(resp).path("token").asText();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private JsonNode apiGetJson(String path) throws Exception {
|
||||
URL url = new URL(BASE_URL + path);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Authorization", "Bearer " + token);
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
int code = conn.getResponseCode();
|
||||
String resp;
|
||||
if (code >= 200 && code < 300) {
|
||||
resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
} else {
|
||||
java.io.InputStream es = conn.getErrorStream();
|
||||
resp = (es != null) ? new String(es.readAllBytes(), StandardCharsets.UTF_8) : "{\"code\":" + code + "}";
|
||||
}
|
||||
try { return JsonUtils.parse(resp); } catch (Exception e) { return null; }
|
||||
}
|
||||
|
||||
private JsonNode apiPostJson(String path, String json) throws Exception {
|
||||
URL url = new URL(BASE_URL + path);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setRequestProperty("Authorization", "Bearer " + token);
|
||||
conn.setDoOutput(true);
|
||||
conn.getOutputStream().write(json.getBytes(StandardCharsets.UTF_8));
|
||||
conn.getOutputStream().flush();
|
||||
int code = conn.getResponseCode();
|
||||
String resp;
|
||||
if (code >= 200 && code < 300) {
|
||||
resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
} else {
|
||||
java.io.InputStream es = conn.getErrorStream();
|
||||
resp = (es != null) ? new String(es.readAllBytes(), StandardCharsets.UTF_8) : "{\"code\":" + code + "}";
|
||||
}
|
||||
try { return JsonUtils.parse(resp); } catch (Exception e) { return null; }
|
||||
}
|
||||
|
||||
private JsonNode apiPutJson(String path, String json) throws Exception {
|
||||
URL url = new URL(BASE_URL + path);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("PUT");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setRequestProperty("Authorization", "Bearer " + token);
|
||||
conn.setDoOutput(true);
|
||||
conn.getOutputStream().write(json.getBytes(StandardCharsets.UTF_8));
|
||||
conn.getOutputStream().flush();
|
||||
int code = conn.getResponseCode();
|
||||
String resp;
|
||||
if (code >= 200 && code < 300) {
|
||||
resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
} else {
|
||||
java.io.InputStream es = conn.getErrorStream();
|
||||
resp = (es != null) ? new String(es.readAllBytes(), StandardCharsets.UTF_8) : "{\"code\":" + code + "}";
|
||||
}
|
||||
try { return JsonUtils.parse(resp); } catch (Exception e) { return null; }
|
||||
}
|
||||
public class InpatientApiTest extends BaseApiTest {
|
||||
|
||||
// === 1. 患者入院管理 ===
|
||||
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
package com.healthlink.his.inspection;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import com.core.common.utils.JsonUtils;
|
||||
import tools.jackson.databind.JsonNode;
|
||||
import org.junit.Before;
|
||||
import com.core.common.utils.JsonNode;
|
||||
import com.healthlink.his.web.BaseApiTest;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@@ -22,52 +18,7 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class InspectionApiTest {
|
||||
|
||||
private static final String BASE_URL = "http://localhost:18082/healthlink-his";
|
||||
private String token;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
token = login();
|
||||
assertNotNull("登录失败", token);
|
||||
}
|
||||
|
||||
private String login() throws Exception {
|
||||
URL url = new URL(BASE_URL + "/login");
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setDoOutput(true);
|
||||
String body = "{\"username\":\"admin\",\"password\":\"admin123\",\"tenantId\":\"1\"}";
|
||||
conn.getOutputStream().write(body.getBytes(StandardCharsets.UTF_8));
|
||||
conn.getOutputStream().flush();
|
||||
int code = conn.getResponseCode();
|
||||
if (code == 200) {
|
||||
String resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
return JsonUtils.parse(resp).path("token").asText();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private JsonNode apiGetJson(String path) throws Exception {
|
||||
URL url = new URL(BASE_URL + path);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Authorization", "Bearer " + token);
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setConnectTimeout(10000);
|
||||
conn.setReadTimeout(30000);
|
||||
int code = conn.getResponseCode();
|
||||
String resp;
|
||||
if (code >= 200 && code < 300) {
|
||||
resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
} else {
|
||||
java.io.InputStream es = conn.getErrorStream();
|
||||
resp = (es != null) ? new String(es.readAllBytes(), StandardCharsets.UTF_8) : "{\"code\":" + code + "}";
|
||||
}
|
||||
try { return JsonUtils.parse(resp); } catch (Exception e) { return null; }
|
||||
}
|
||||
public class InspectionApiTest extends BaseApiTest {
|
||||
|
||||
// === 1. 检查项目定义(已确认可用 - check_type表存在) ===
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.healthlink.his.nurse;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import com.core.common.utils.JsonUtils;
|
||||
import com.healthlink.his.web.BaseApiTest;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -9,8 +8,6 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -33,41 +30,7 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class NurseStationTest {
|
||||
|
||||
private static final String BASE_URL = "http://localhost:18082/healthlink-his";
|
||||
private String token;
|
||||
|
||||
private String login() throws Exception {
|
||||
URL url = new URL(BASE_URL + "/login");
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setDoOutput(true);
|
||||
String body = "{\"username\":\"admin\",\"password\":\"admin123\",\"tenantId\":\"1\"}";
|
||||
conn.getOutputStream().write(body.getBytes(StandardCharsets.UTF_8));
|
||||
String resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
return JsonUtils.parse(resp).path("token").asText();
|
||||
}
|
||||
|
||||
private int apiGet(String path) throws Exception {
|
||||
URL url = new URL(BASE_URL + path);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Authorization", "Bearer " + token);
|
||||
return conn.getResponseCode();
|
||||
}
|
||||
|
||||
private int apiPost(String path, String json) throws Exception {
|
||||
URL url = new URL(BASE_URL + path);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setRequestProperty("Authorization", "Bearer " + token);
|
||||
conn.setDoOutput(true);
|
||||
conn.getOutputStream().write(json.getBytes(StandardCharsets.UTF_8));
|
||||
return conn.getResponseCode();
|
||||
}
|
||||
public class NurseStationTest extends BaseApiTest {
|
||||
|
||||
// ========== 1. 认证 ==========
|
||||
|
||||
@@ -81,7 +44,6 @@ public class NurseStationTest {
|
||||
|
||||
@Test
|
||||
public void test02_queryAdviceProcessList() throws Exception {
|
||||
token = login();
|
||||
// 查询待执行医嘱列表
|
||||
int code = apiGet("/nurse-station/advice-process/inpatient?pageNum=1&pageSize=10");
|
||||
assertTrue("查询待执行医嘱应返回200或500", code == 200 || code == 500);
|
||||
@@ -89,7 +51,6 @@ public class NurseStationTest {
|
||||
|
||||
@Test
|
||||
public void test03_executeAdvice() throws Exception {
|
||||
token = login();
|
||||
// 执行医嘱
|
||||
int code = apiPost("/nurse-station/advice-process/advice-execute", "{\"adviceId\":999999}");
|
||||
assertTrue("执行医嘱应返回200或500", code == 200 || code == 500);
|
||||
@@ -97,7 +58,6 @@ public class NurseStationTest {
|
||||
|
||||
@Test
|
||||
public void test04_cancelAdvice() throws Exception {
|
||||
token = login();
|
||||
// 取消医嘱
|
||||
int code = apiPost("/nurse-station/advice-process/advice-cancel", "{\"adviceId\":999999}");
|
||||
assertTrue("取消医嘱应返回200或500", code == 200 || code == 500);
|
||||
@@ -107,7 +67,6 @@ public class NurseStationTest {
|
||||
|
||||
@Test
|
||||
public void test05_queryNurseBilling() throws Exception {
|
||||
token = login();
|
||||
// 查询护理记费列表
|
||||
int code = apiGet("/inhospitalnursestation/nursebilling/innurse-billing-list/1?pageNum=1&pageSize=10");
|
||||
assertTrue("查询护理记费应返回200或500", code == 200 || code == 500);
|
||||
@@ -115,7 +74,6 @@ public class NurseStationTest {
|
||||
|
||||
@Test
|
||||
public void test06_addNurseBilling() throws Exception {
|
||||
token = login();
|
||||
// 护士站记费
|
||||
int code = apiPost("/inhospitalnursestation/nursebilling/add-billing", "{\"encounterId\":1,\"itemId\":1,\"quantity\":1}");
|
||||
assertTrue("护士站记费应返回200或500", code == 200 || code == 500);
|
||||
@@ -123,7 +81,6 @@ public class NurseStationTest {
|
||||
|
||||
@Test
|
||||
public void test07_deleteNurseBilling() throws Exception {
|
||||
token = login();
|
||||
// 删除护士记费
|
||||
int code = apiPost("/inhospitalnursestation/nursebilling/del-billing", "{\"billingId\":999999}");
|
||||
assertTrue("删除记费应返回200或500", code == 200 || code == 500);
|
||||
@@ -133,7 +90,6 @@ public class NurseStationTest {
|
||||
|
||||
@Test
|
||||
public void test08_queryVitalSigns() throws Exception {
|
||||
token = login();
|
||||
// 查询生命体征数据
|
||||
int code = apiGet("/doctor-station/main/init-page");
|
||||
assertEquals("查询生命体征应返回200", 200, code);
|
||||
@@ -143,7 +99,6 @@ public class NurseStationTest {
|
||||
|
||||
@Test
|
||||
public void test09_querySampleCollection() throws Exception {
|
||||
token = login();
|
||||
// 查询待采集标本
|
||||
int code = apiGet("/doctor-station/inspection/init-page?encounterId=1");
|
||||
assertTrue("查询标本采集应返回200或500", code == 200 || code == 500);
|
||||
@@ -153,7 +108,6 @@ public class NurseStationTest {
|
||||
|
||||
@Test
|
||||
public void test10_queryCostDetail() throws Exception {
|
||||
token = login();
|
||||
// 查询费用明细
|
||||
int code = apiGet("/inhospitalnursestation/nursebilling/cost-detail/1");
|
||||
assertTrue("查询费用明细应返回200或500", code == 200 || code == 500);
|
||||
@@ -163,7 +117,6 @@ public class NurseStationTest {
|
||||
|
||||
@Test
|
||||
public void test11_queryPractitionerWard() throws Exception {
|
||||
token = login();
|
||||
// 查询病区患者列表
|
||||
int code = apiGet("/app-common/practitioner-ward");
|
||||
assertEquals("查询病区患者应返回200", 200, code);
|
||||
@@ -171,7 +124,6 @@ public class NurseStationTest {
|
||||
|
||||
@Test
|
||||
public void test12_queryOrganizationLocation() throws Exception {
|
||||
token = login();
|
||||
// 查询科室位置
|
||||
int code = apiGet("/base-data-manage/org-loc/loc-list?locationForm=1");
|
||||
assertEquals("查询科室位置应返回200", 200, code);
|
||||
@@ -191,28 +143,24 @@ public class NurseStationTest {
|
||||
|
||||
@Test
|
||||
public void test14_executeNonExistentAdvice() throws Exception {
|
||||
token = login();
|
||||
int code = apiPost("/nurse-station/advice-process/advice-execute", "{\"adviceId\":999999}");
|
||||
assertTrue("执行不存在的医嘱应返回错误", code == 200 || code == 500);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test15_addBillingWithMissingFields() throws Exception {
|
||||
token = login();
|
||||
int code = apiPost("/inhospitalnursestation/nursebilling/add-billing", "{}");
|
||||
assertTrue("缺少字段的记费应返回错误", code == 200 || code == 500);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test16_queryWithLargePage() throws Exception {
|
||||
token = login();
|
||||
int code = apiGet("/nurse-station/advice-process/inpatient?pageNum=99999&pageSize=10");
|
||||
assertTrue("大页码查询应返回200或500", code == 200 || code == 500);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test17_queryAdviceProcessInpatient() throws Exception {
|
||||
token = login();
|
||||
// 查询住院医嘱处理
|
||||
int code = apiGet("/nurse-station/advice-process/inpatient-advice?pageNum=1&pageSize=10");
|
||||
assertTrue("查询住院医嘱应返回200或500", code == 200 || code == 500);
|
||||
@@ -220,7 +168,6 @@ public class NurseStationTest {
|
||||
|
||||
@Test
|
||||
public void test18_initPage() throws Exception {
|
||||
token = login();
|
||||
// 初始化页面数据
|
||||
int code = apiGet("/inhospitalnursestation/nursebilling/innurse-billing-list/1");
|
||||
assertTrue("初始化页面应返回200或500", code == 200 || code == 500);
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
package com.healthlink.his.pharmacy;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import com.core.common.utils.JsonUtils;
|
||||
import tools.jackson.databind.JsonNode;
|
||||
import org.junit.Before;
|
||||
import com.core.common.utils.JsonNode;
|
||||
import com.healthlink.his.web.BaseApiTest;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@@ -18,70 +14,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class PharmacyApiTest {
|
||||
|
||||
private static final String BASE_URL = "http://localhost:18082/healthlink-his";
|
||||
private String token;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
token = login();
|
||||
assertNotNull("登录失败", token);
|
||||
}
|
||||
|
||||
private String login() throws Exception {
|
||||
URL url = new URL(BASE_URL + "/login");
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setDoOutput(true);
|
||||
String body = "{\"username\":\"admin\",\"password\":\"admin123\",\"tenantId\":\"1\"}";
|
||||
conn.getOutputStream().write(body.getBytes(StandardCharsets.UTF_8));
|
||||
conn.getOutputStream().flush();
|
||||
int code = conn.getResponseCode();
|
||||
if (code == 200) {
|
||||
String resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
return JsonUtils.parse(resp).path("token").asText();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private JsonNode apiGetJson(String path) throws Exception {
|
||||
URL url = new URL(BASE_URL + path);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Authorization", "Bearer " + token);
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
int code = conn.getResponseCode();
|
||||
String resp;
|
||||
if (code >= 200 && code < 300) {
|
||||
resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
} else {
|
||||
java.io.InputStream es = conn.getErrorStream();
|
||||
resp = (es != null) ? new String(es.readAllBytes(), StandardCharsets.UTF_8) : "{\"code\":" + code + "}";
|
||||
}
|
||||
try { return JsonUtils.parse(resp); } catch (Exception e) { return null; }
|
||||
}
|
||||
|
||||
private JsonNode apiPutJson(String path, String json) throws Exception {
|
||||
URL url = new URL(BASE_URL + path);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("PUT");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setRequestProperty("Authorization", "Bearer " + token);
|
||||
conn.setDoOutput(true);
|
||||
conn.getOutputStream().write(json.getBytes(StandardCharsets.UTF_8));
|
||||
conn.getOutputStream().flush();
|
||||
int code = conn.getResponseCode();
|
||||
String resp;
|
||||
if (code >= 200 && code < 300) {
|
||||
resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
} else {
|
||||
java.io.InputStream es = conn.getErrorStream();
|
||||
resp = (es != null) ? new String(es.readAllBytes(), StandardCharsets.UTF_8) : "{\"code\":" + code + "}";
|
||||
}
|
||||
try { return JsonUtils.parse(resp); } catch (Exception e) { return null; }
|
||||
}
|
||||
public class PharmacyApiTest extends BaseApiTest {
|
||||
|
||||
// === 1. 西药发药 ===
|
||||
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
package com.healthlink.his.report;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import com.core.common.utils.JsonUtils;
|
||||
import tools.jackson.databind.JsonNode;
|
||||
import org.junit.Before;
|
||||
import com.core.common.utils.JsonNode;
|
||||
import com.healthlink.his.web.BaseApiTest;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@@ -21,52 +17,7 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class ReportApiTest {
|
||||
|
||||
private static final String BASE_URL = "http://localhost:18082/healthlink-his";
|
||||
private String token;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
token = login();
|
||||
assertNotNull("登录失败", token);
|
||||
}
|
||||
|
||||
private String login() throws Exception {
|
||||
URL url = new URL(BASE_URL + "/login");
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setDoOutput(true);
|
||||
String body = "{\"username\":\"admin\",\"password\":\"admin123\",\"tenantId\":\"1\"}";
|
||||
conn.getOutputStream().write(body.getBytes(StandardCharsets.UTF_8));
|
||||
conn.getOutputStream().flush();
|
||||
int code = conn.getResponseCode();
|
||||
if (code == 200) {
|
||||
String resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
return JsonUtils.parse(resp).path("token").asText();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private JsonNode apiGetJson(String path) throws Exception {
|
||||
URL url = new URL(BASE_URL + path);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Authorization", "Bearer " + token);
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setConnectTimeout(10000);
|
||||
conn.setReadTimeout(30000);
|
||||
int code = conn.getResponseCode();
|
||||
String resp;
|
||||
if (code >= 200 && code < 300) {
|
||||
resp = new String(conn.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
} else {
|
||||
java.io.InputStream es = conn.getErrorStream();
|
||||
resp = (es != null) ? new String(es.readAllBytes(), StandardCharsets.UTF_8) : "{\"code\":" + code + "}";
|
||||
}
|
||||
return (resp != null && !resp.isEmpty()) ? JsonUtils.parse(resp) : new ObjectMapper().createObjectNode();
|
||||
}
|
||||
public class ReportApiTest extends BaseApiTest {
|
||||
|
||||
// === 1. 挂号报表(已确认可用) ===
|
||||
|
||||
|
||||
Reference in New Issue
Block a user