feat(接口): 挤出/失重秤消耗量采集单元测试
This commit is contained in:
parent
01094ce29e
commit
ba876cbebf
@ -0,0 +1,109 @@
|
||||
package com.foreverwin.iep.integration.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.http.HttpHeaders;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class EapExtrudeRecordTest {
|
||||
|
||||
public static final String origin = "http://127.0.0.1:8091";
|
||||
public static final String mesOrigin = "http://localhost:8080";
|
||||
|
||||
@Test
|
||||
public void testCall() throws Exception {
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost postRequest = new HttpPost(mesOrigin + "/iep-int/invoke");
|
||||
|
||||
String token = getToken();
|
||||
postRequest.setHeader(HttpHeaders.AUTHORIZATION, "Bearer "+ token);
|
||||
postRequest.setHeader("TENANT-ID", "2031");
|
||||
postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
|
||||
|
||||
String assembleMsgBody = assembleMsgBody();
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(assembleMsgBody);
|
||||
StringEntity stringEntity = new StringEntity(jsonObject.toJSONString());
|
||||
stringEntity.setContentType("application/json");
|
||||
postRequest.setEntity(stringEntity);
|
||||
// 调用登陆接口获取token
|
||||
HttpResponse response = httpClient.execute(postRequest);
|
||||
String responseString = EntityUtils.toString(response.getEntity());
|
||||
// 解析返回的 JSON 数据
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode responseJson = objectMapper.readTree(responseString);
|
||||
System.out.println(responseJson);
|
||||
}
|
||||
|
||||
private String assembleMsgBody() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("REQ_ID", StrUtil.uuid());
|
||||
jsonObject.put("SEND_TIME","2024-11-29 12:00:00");
|
||||
jsonObject.put("SITE","3041");
|
||||
jsonObject.put("SENDER","EAP");
|
||||
jsonObject.put("MESSAGE_ID","material.data.process");
|
||||
jsonObject.put("FACTORY","009");
|
||||
jsonObject.put("LINE_ID","WC01");
|
||||
jsonObject.put("OPERATION","JMLS");
|
||||
jsonObject.put("RESOURCE","LS001");
|
||||
jsonObject.put("EXTRUDER_RESOURCE","TLK02");
|
||||
jsonObject.put("PROCESS_RESOURCE","TT02");
|
||||
jsonObject.put("MAIN_UOM","KG");
|
||||
jsonObject.put("MAIN_QTY","12");
|
||||
jsonObject.put("SUB_UOM","KG");
|
||||
jsonObject.put("SUB_QTY","3");
|
||||
jsonObject.put("TRANS_TYPE","1");
|
||||
jsonObject.put("TRANS_DATE","2024-11-29 12:00:00");
|
||||
jsonObject.put("START_DATE_TIME","2024-11-29 12:00:00");
|
||||
jsonObject.put("END_DATE_TIME","2024-11-30 12:00:00");
|
||||
JSONArray details = new JSONArray();
|
||||
JSONObject detail = new JSONObject();
|
||||
detail.put("SUB_RESOURCE","TT0201");
|
||||
detail.put("SET_VALUE","22.1");
|
||||
detail.put("ACTUAL_VALUE","33");
|
||||
detail.put("ACTUAL_QTY","66");
|
||||
details.add(detail);
|
||||
jsonObject.put("DETAILS", details);
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
public String getToken() throws Exception {
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost postRequest = new HttpPost(mesOrigin + "/auth/oauth/token?randomStr=blockPuzzle&grant_type=password");
|
||||
// 构建请求参数
|
||||
List<NameValuePair> pair = new ArrayList<>();
|
||||
pair.add(new BasicNameValuePair("username", "agv"));
|
||||
pair.add(new BasicNameValuePair("password", "dAPopZNYLST8ew=="));
|
||||
|
||||
postRequest.setHeader(HttpHeaders.AUTHORIZATION, "Basic bW9tOm1vbQ==");
|
||||
postRequest.setHeader("TENANT-ID", "2031");
|
||||
postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
|
||||
|
||||
postRequest.setEntity(new UrlEncodedFormEntity(pair, "UTF-8"));
|
||||
|
||||
// 调用登陆接口获取token
|
||||
HttpResponse response = httpClient.execute(postRequest);
|
||||
String responseString = EntityUtils.toString(response.getEntity());
|
||||
// 解析返回的 JSON 数据
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode responseJson = objectMapper.readTree(responseString);
|
||||
String accessToken = responseJson.get("access_token").asText();
|
||||
System.out.println(responseJson);
|
||||
return accessToken;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user