AI不追问,组件新增旋转轴字段
This commit is contained in:
@@ -21,6 +21,8 @@ import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -67,7 +69,7 @@ class AdminApiTest {
|
||||
@Test
|
||||
void oneSignatureEndpointGeneratesCodeWithoutDatabaseRecordAndRenewsSameBatch() throws Exception {
|
||||
JsonNode first = sign(Map.of());
|
||||
assertThat(first.path("componentCode").asText()).matches("CW-[A-F0-9]{32}");
|
||||
assertThat(first.path("componentCode").asText()).matches("CW-[0-9A-HJKMNP-TV-Z]{16}");
|
||||
String step = first.path("step").path("keyPrefix").asText();
|
||||
String urdf = first.path("urdf").path("keyPrefix").asText();
|
||||
assertThat(step).startsWith("cadworld_dev/components/" + first.path("componentCode").asText() + "/step/");
|
||||
@@ -89,6 +91,31 @@ class AdminApiTest {
|
||||
.content("{\"componentId\":999}")).andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyUploadSessionCanRenewCreateAndEditWithoutChangingCode() throws Exception {
|
||||
String code = "CW-0123456789ABCDEF0123456789ABCDEF";
|
||||
String batch = "abcdef0123456789abcdef0123456789";
|
||||
String prefix = "cadworld_dev/components/" + code;
|
||||
UploadSessionClaims session = new UploadSessionClaims(0L, null, code, batch,
|
||||
prefix + "/step/" + batch + "/", prefix + "/urdf/" + batch + "/",
|
||||
Instant.now().plusSeconds(300));
|
||||
String token = tokens.generateToken(session);
|
||||
JsonNode renewed = sign(Map.of("uploadSessionToken", token));
|
||||
assertThat(renewed.path("componentCode").asText()).isEqualTo(code);
|
||||
assertThat(renewed.path("uploadSessionToken").asText()).isEqualTo(token);
|
||||
assertThat(renewed.path("step").path("keyPrefix").asText()).isEqualTo(session.stepPrefix());
|
||||
|
||||
String step = session.stepPrefix() + "model.STEP";
|
||||
storage.simulateDirectUpload(step, "application/octet-stream", new byte[]{1, 2});
|
||||
JsonNode created = create(Map.of("uploadSessionToken", token, "stepObjectKey", step));
|
||||
assertThat(created.path("componentCode").asText()).isEqualTo(code);
|
||||
JsonNode editing = sign(Map.of("componentId", created.path("id").asLong()));
|
||||
assertThat(editing.path("componentCode").asText()).isEqualTo(code);
|
||||
assertThat(editing.path("step").path("keyPrefix").asText()).isNotEqualTo(session.stepPrefix());
|
||||
JsonNode editingRenewed = sign(Map.of("uploadSessionToken", editing.path("uploadSessionToken").asText()));
|
||||
assertThat(editingRenewed.path("componentCode").asText()).isEqualTo(code);
|
||||
}
|
||||
|
||||
@Test
|
||||
void componentDefaultsSearchUrlsAndDuplicateNamesMatchNewSchema() throws Exception {
|
||||
Map<String,Object> body = uploaded();
|
||||
@@ -191,10 +218,53 @@ class AdminApiTest {
|
||||
.isEqualTo(changed);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"X", "Y", "Z"})
|
||||
void rotationAxisRoundTripsThroughCreateUpdateDetailAndList(String axis) throws Exception {
|
||||
Map<String, Object> body = uploaded();
|
||||
body.put("rotationAxis", axis);
|
||||
JsonNode created = create(body);
|
||||
long id = created.path("id").asLong();
|
||||
assertThat(created.path("rotationAxis").asText()).isEqualTo(axis);
|
||||
assertThat(jdbc.queryForObject("SELECT rotation_axis FROM component WHERE id=?", String.class, id)).isEqualTo(axis);
|
||||
mvc.perform(get("/admin-api/components/{id}", id)).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.rotationAxis").value(axis));
|
||||
mvc.perform(get("/admin-api/components").param("keyword", created.path("componentCode").asText()))
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$.data.items[0].rotationAxis").value(axis));
|
||||
String nextAxis = "X".equals(axis) ? "Y" : "X";
|
||||
Map<String, Object> form = update(1);
|
||||
form.put("rotationAxis", nextAxis);
|
||||
JsonNode changed = data(mvc.perform(put("/admin-api/components/{id}", id).contentType(MediaType.APPLICATION_JSON)
|
||||
.content(json.writeValueAsString(form))).andExpect(status().isOk()).andReturn());
|
||||
assertThat(changed.path("rotationAxis").asText()).isEqualTo(nextAxis);
|
||||
assertThat(componentMapper.selectById(id).getRotationAxis().name()).isEqualTo(nextAxis);
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidRotationAxisValuesNeverCreateOrUpdateComponents() throws Exception {
|
||||
Map<String, Object> original = uploaded();
|
||||
original.put("rotationAxis", "Z");
|
||||
long id = create(original).path("id").asLong();
|
||||
Map<String, Object> body = uploaded();
|
||||
Map<String, Object> form = update(1);
|
||||
for (Object invalid : List.of("", "x", " X ", "XY", "A", 0, 1, 2, true, List.of("X"), Map.of("axis", "X"))) {
|
||||
body.put("rotationAxis", invalid);
|
||||
form.put("rotationAxis", invalid);
|
||||
expectCreateError(body, 422, "INVALID_REQUEST");
|
||||
mvc.perform(put("/admin-api/components/{id}", id).contentType(MediaType.APPLICATION_JSON)
|
||||
.content(json.writeValueAsString(form))).andExpect(status().isUnprocessableEntity())
|
||||
.andExpect(jsonPath("$.code").value("INVALID_REQUEST"));
|
||||
}
|
||||
assertThat(count("component")).isEqualTo(1);
|
||||
assertThat(componentMapper.selectById(id).getRotationAxis().name()).isEqualTo("Z");
|
||||
assertThat(componentMapper.selectById(id).getVersion()).isEqualTo(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void fullUpdateRestoresDefaultsForOmittedAndExplicitNullFields() throws Exception {
|
||||
Map<String,Object> body = uploaded();
|
||||
body.put("degreesOfFreedom", 3);
|
||||
body.put("rotationAxis", "Z");
|
||||
body.put("functionDescription", "固定");
|
||||
body.put("shape", "圆形");
|
||||
body.put("size", "大型");
|
||||
@@ -203,7 +273,7 @@ class AdminApiTest {
|
||||
JsonNode created = create(body);
|
||||
long id = created.path("id").asLong();
|
||||
Map<String,Object> form = update(1);
|
||||
for (String field : List.of("degreesOfFreedom", "functionDescription", "shape", "size", "torqueNm", "bomList")) {
|
||||
for (String field : List.of("degreesOfFreedom", "rotationAxis", "functionDescription", "shape", "size", "torqueNm", "bomList")) {
|
||||
form.put(field, json.nullNode());
|
||||
}
|
||||
JsonNode cleared = data(mvc.perform(put("/admin-api/components/{id}", id).contentType(MediaType.APPLICATION_JSON)
|
||||
@@ -211,6 +281,7 @@ class AdminApiTest {
|
||||
assertComponentDefaults(cleared);
|
||||
Component stored = componentMapper.selectById(id);
|
||||
assertThat(stored.getDegreesOfFreedom()).isZero();
|
||||
assertThat(stored.getRotationAxis()).isNull();
|
||||
assertThat(stored.getFunctionDescription()).isEmpty();
|
||||
assertThat(stored.getShape()).isEmpty();
|
||||
assertThat(stored.getSize()).isEmpty();
|
||||
@@ -219,6 +290,7 @@ class AdminApiTest {
|
||||
|
||||
body = uploaded();
|
||||
body.put("degreesOfFreedom", 3);
|
||||
body.put("rotationAxis", "Y");
|
||||
body.put("functionDescription", "固定");
|
||||
body.put("shape", "圆形");
|
||||
body.put("size", "大型");
|
||||
@@ -228,6 +300,7 @@ class AdminApiTest {
|
||||
JsonNode omitted = data(mvc.perform(put("/admin-api/components/{id}", otherId).contentType(MediaType.APPLICATION_JSON)
|
||||
.content(json.writeValueAsString(update(1)))).andExpect(status().isOk()).andReturn());
|
||||
assertComponentDefaults(omitted);
|
||||
assertThat(componentMapper.selectById(otherId).getRotationAxis()).isNull();
|
||||
assertThat(componentMapper.selectById(otherId).getBomList()).isEqualTo(json.createArrayNode());
|
||||
}
|
||||
|
||||
@@ -820,6 +893,8 @@ class AdminApiTest {
|
||||
return body;
|
||||
}
|
||||
void assertComponentDefaults(JsonNode response) {
|
||||
assertThat(response.has("rotationAxis")).isTrue();
|
||||
assertThat(response.get("rotationAxis").isNull()).isTrue();
|
||||
assertThat(response.get("degreesOfFreedom")).isEqualTo(json.valueToTree(0));
|
||||
for (String field : List.of("functionDescription", "shape", "size")) {
|
||||
assertThat(response.get(field)).isEqualTo(json.valueToTree(""));
|
||||
|
||||
@@ -19,6 +19,7 @@ final class TestSchemaSupport {
|
||||
material VARCHAR(128) NOT NULL DEFAULT '',
|
||||
mass_kg DECIMAL(18,6) NOT NULL DEFAULT 0,
|
||||
degrees_of_freedom INT NOT NULL DEFAULT 0 COMMENT '自由度,非负整数',
|
||||
rotation_axis CHAR(1) DEFAULT NULL CHECK (rotation_axis IN ('X','Y','Z')) COMMENT '旋转轴:X、Y、Z;NULL表示未设置',
|
||||
function_description VARCHAR(512) NOT NULL DEFAULT '' COMMENT '组件功能描述',
|
||||
shape VARCHAR(128) NOT NULL DEFAULT '' COMMENT '组件形状描述',
|
||||
size VARCHAR(128) NOT NULL DEFAULT '' COMMENT '组件大小描述',
|
||||
|
||||
Reference in New Issue
Block a user