diff --git a/arex-web-api/src/main/java/com/arextest/web/api/service/controller/config/expectation/ExpectationScriptController.java b/arex-web-api/src/main/java/com/arextest/web/api/service/controller/config/expectation/ExpectationScriptController.java index 44b5d8168..1afb564f7 100644 --- a/arex-web-api/src/main/java/com/arextest/web/api/service/controller/config/expectation/ExpectationScriptController.java +++ b/arex-web-api/src/main/java/com/arextest/web/api/service/controller/config/expectation/ExpectationScriptController.java @@ -3,46 +3,54 @@ import com.arextest.common.model.response.Response; import com.arextest.common.model.response.ResponseCode; import com.arextest.common.utils.ResponseUtils; -import com.arextest.web.core.repository.expectation.ExpectationScriptRepository; +import com.arextest.web.core.business.config.expectation.ExpectationScriptService; import com.arextest.web.model.contract.contracts.config.expectation.ExpectationScriptDeleteRequest; import com.arextest.web.model.contract.contracts.config.expectation.ExpectationScriptModel; import com.arextest.web.model.contract.contracts.config.expectation.ExpectationScriptQueryRequest; -import java.util.List; import javax.validation.Valid; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/api/config/expectation") public class ExpectationScriptController { - private final ExpectationScriptRepository repository; + private final ExpectationScriptService service; - public ExpectationScriptController(ExpectationScriptRepository repository) { - this.repository = repository; + public ExpectationScriptController(ExpectationScriptService service) { + this.service = service; } - @RequestMapping("/query") + @RequestMapping(path = "/query", method = RequestMethod.POST) + @ResponseBody public Response query(@Valid @RequestBody ExpectationScriptQueryRequest request) { - List list = repository.query(request); - return ResponseUtils.successResponse(list); + return ResponseUtils.successResponse(service.query(request)); } - @RequestMapping("/save") + @RequestMapping(path = "/save", method = RequestMethod.POST) + @ResponseBody public Response save(@Valid @RequestBody ExpectationScriptModel request) { - boolean result = repository.save(request); - if (!result) { - return ResponseUtils.errorResponse("save failed", ResponseCode.REQUESTED_HANDLE_EXCEPTION); + boolean result = service.save(request); + if (result) { + return ResponseUtils.successResponse(true); } - return ResponseUtils.successResponse(true); + if (CollectionUtils.isNotEmpty(request.getInvalidExtractAssertList())) { + String originalText = request.getInvalidExtractAssertList().get(0).getOriginalText(); + return ResponseUtils.parameterInvalidResponse("invalid assert: " + originalText); + } + return ResponseUtils.errorResponse("save failed", ResponseCode.REQUESTED_HANDLE_EXCEPTION); } - @RequestMapping("/delete") + @RequestMapping(path = "/delete", method = RequestMethod.POST) + @ResponseBody public Response delete(@Valid @RequestBody ExpectationScriptDeleteRequest request) { - boolean result = repository.delete(request); - if (!result) { - return ResponseUtils.errorResponse("delete failed", ResponseCode.REQUESTED_HANDLE_EXCEPTION); + boolean result = service.delete(request); + if (result) { + return ResponseUtils.successResponse(true); } - return ResponseUtils.successResponse(true); + return ResponseUtils.errorResponse("delete failed", ResponseCode.REQUESTED_HANDLE_EXCEPTION); } } diff --git a/arex-web-core/src/main/java/com/arextest/web/core/business/config/expectation/ExpectationScriptService.java b/arex-web-core/src/main/java/com/arextest/web/core/business/config/expectation/ExpectationScriptService.java new file mode 100644 index 000000000..7912c5e92 --- /dev/null +++ b/arex-web-core/src/main/java/com/arextest/web/core/business/config/expectation/ExpectationScriptService.java @@ -0,0 +1,39 @@ +package com.arextest.web.core.business.config.expectation; + +import com.arextest.web.core.repository.expectation.ExpectationScriptRepository; +import com.arextest.web.model.contract.contracts.config.expectation.ExpectationScriptDeleteRequest; +import com.arextest.web.model.contract.contracts.config.expectation.ExpectationScriptModel; +import com.arextest.web.model.contract.contracts.config.expectation.ExpectationScriptQueryRequest; +import java.util.List; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Service; + +/** + * @since 2023/12/15 + */ +@Service +public class ExpectationScriptService { + private final ExpectationScriptRepository repository; + private final ScriptNormalizer normalizer; + + public ExpectationScriptService(ExpectationScriptRepository repository, ScriptNormalizer normalizer) { + this.repository = repository; + this.normalizer = normalizer; + } + + public List query(ExpectationScriptQueryRequest request) { + return repository.query(request); + } + + public boolean save(ExpectationScriptModel model) { + normalizer.normalize(model); + if (CollectionUtils.isNotEmpty(model.getInvalidExtractAssertList())) { + return false; + } + return model.getId() != null ? repository.update(model) : repository.insert(model); + } + + public boolean delete(ExpectationScriptDeleteRequest request) { + return repository.delete(request.getId(), request.getAppId()); + } +} diff --git a/arex-web-core/src/main/java/com/arextest/web/core/business/config/expectation/ScriptAssertHandler.java b/arex-web-core/src/main/java/com/arextest/web/core/business/config/expectation/ScriptAssertHandler.java new file mode 100644 index 000000000..c7c13be6b --- /dev/null +++ b/arex-web-core/src/main/java/com/arextest/web/core/business/config/expectation/ScriptAssertHandler.java @@ -0,0 +1,12 @@ +package com.arextest.web.core.business.config.expectation; + +import com.arextest.web.model.contract.contracts.config.expectation.ScriptExtractAssertModel; +import com.arextest.web.model.contract.contracts.config.expectation.ExpectationScriptModel; + +/** + * @since 2023/11/29 + */ +public interface ScriptAssertHandler { + boolean support(ScriptExtractAssertModel model); + void handle(ExpectationScriptModel scriptModel, ScriptExtractAssertModel assertModel); +} diff --git a/arex-web-core/src/main/java/com/arextest/web/core/business/config/expectation/ScriptNormalizer.java b/arex-web-core/src/main/java/com/arextest/web/core/business/config/expectation/ScriptNormalizer.java new file mode 100644 index 000000000..5b1c912ed --- /dev/null +++ b/arex-web-core/src/main/java/com/arextest/web/core/business/config/expectation/ScriptNormalizer.java @@ -0,0 +1,79 @@ +package com.arextest.web.core.business.config.expectation; + +import com.arextest.web.model.contract.contracts.config.expectation.ExpectationScriptModel; +import com.arextest.web.model.contract.contracts.config.expectation.ScriptExtractAssertModel; +import com.arextest.web.model.contract.contracts.config.expectation.ScriptExtractOperationModel; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +/** + * @since 2023/11/29 + */ +@Component +public class ScriptNormalizer { + // (?:let (?\w+) = )?arex\.(?[a-zA-Z]+){1}\[\"(?.+)\"] + private static final String EXTRACT_OPERATION_REGEX = "(?:var (?\\w+) = )?arex\\.(?[a-zA-Z]+){1}\\[\"(?.+)\"]"; + private static final Pattern EXTRACT_OPERATION_PATTERN = Pattern.compile(EXTRACT_OPERATION_REGEX); + // arex\.assert\.[a-zA-Z]+\(.*\); + private static final String EXTRACT_ASSERT_REGEX = "arex\\.assert\\.[a-zA-Z]+\\(.*\\);"; + private static final Pattern EXTRACT_ASSERT_PATTERN = Pattern.compile(EXTRACT_ASSERT_REGEX); + + private final List assertHandlerList; + + public ScriptNormalizer(List assertHandlerList) { + this.assertHandlerList = assertHandlerList; + } + + public void normalize(ExpectationScriptModel model) { + model.setNormalizedContent(model.getContent()); + List extactOpeartionList = extactOpeartionList(model.getNormalizedContent()); + + if (extactOpeartionList.isEmpty()) { + return; + } + + model.setExtractOperationList(extactOpeartionList); + + // match script with EXTRACT_ASSERT_PATTERN + Matcher assertMatcher = EXTRACT_ASSERT_PATTERN.matcher(model.getNormalizedContent()); + while (assertMatcher.find()) { + ScriptExtractAssertModel assertModel = new ScriptExtractAssertModel(assertMatcher.group()); + for (ScriptAssertHandler handler : assertHandlerList) { + if (!handler.support(assertModel)) { + continue; + } + handler.handle(model, assertModel); + if (!assertModel.validate()) { + continue; + } + model.setNormalizedContent(StringUtils.replace(model.getNormalizedContent(), assertModel.getOriginalText(), + assertModel.rebuild())); + } + if (!assertModel.validate()) { + model.setInvalidExtractAssertList(Collections.singletonList(assertModel)); + break; + } + } + } + + private List extactOpeartionList(String script) { + List operationList = new ArrayList<>(); + Matcher matcher = EXTRACT_OPERATION_PATTERN.matcher(script); + while (matcher.find()) { + ScriptExtractOperationModel operationModel = new ScriptExtractOperationModel(); + operationModel.setVariableName(matcher.group("variable")); + operationModel.setCategoryName(matcher.group("category")); + operationModel.setOperationName(matcher.group("operation")); + operationModel.setOriginalText(matcher.group()); + if (operationModel.validate() && !operationList.contains(operationModel)) { + operationList.add(operationModel); + } + } + return operationList; + } +} diff --git a/arex-web-core/src/main/java/com/arextest/web/core/business/config/expectation/assertion/EqualsHandler.java b/arex-web-core/src/main/java/com/arextest/web/core/business/config/expectation/assertion/EqualsHandler.java new file mode 100644 index 000000000..9a6f23cbc --- /dev/null +++ b/arex-web-core/src/main/java/com/arextest/web/core/business/config/expectation/assertion/EqualsHandler.java @@ -0,0 +1,60 @@ +package com.arextest.web.core.business.config.expectation.assertion; + +import com.arextest.web.core.business.config.expectation.ScriptAssertHandler; +import com.arextest.web.model.contract.contracts.config.expectation.ScriptExtractAssertModel; +import com.arextest.web.model.contract.contracts.config.expectation.ExpectationScriptModel; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +/** + * @since 2023/11/29 + */ +@Component +public class EqualsHandler implements ScriptAssertHandler { + // arex\.assert\.equals\((?\"\w+\"), *(?\w+)\.request.(?.*)\); + private static final String EQUALS_REGEX = "arex\\.assert\\.equals\\((?\"\\w+\"), *(?.+)\\.(?:request|response)\\.(?.*)\\);"; + private static final Pattern EQUALS_PATTERN = Pattern.compile(EQUALS_REGEX); + + // arex\.(?[a-zA-Z]+){1}\[\"(?.+)\"] + private static final String OPERATION_REGEX = "arex\\.(?[a-zA-Z]+){1}\\[\"(?.+)\"]"; + private static final Pattern OPERATION_PATTERN = Pattern.compile(OPERATION_REGEX); + + @Override + public boolean support(ScriptExtractAssertModel model) { + return model.getOriginalText().startsWith("arex.assert.equals"); + } + + @Override + public void handle(ExpectationScriptModel scriptModel, ScriptExtractAssertModel assertModel) { + Matcher equalsMatcher = EQUALS_PATTERN.matcher(assertModel.getOriginalText()); + if (!equalsMatcher.find()) { + return; + } + assertModel.setMethodName("equals"); + assertModel.setExpected(equalsMatcher.group("expected")); + assertModel.setShortServiceName(equalsMatcher.group("service")); + assertModel.setPath(equalsMatcher.group("path")); + + if (StringUtils.startsWith(assertModel.getShortServiceName(), "arex")) { + Matcher operationMatcher = OPERATION_PATTERN.matcher(assertModel.getShortServiceName()); + if (operationMatcher.find()) { + assertModel.setCategoryName(operationMatcher.group("category")); + assertModel.setOperationName(operationMatcher.group("operation")); + } + } + + if (StringUtils.isNotEmpty(assertModel.getOperationName())) { + return; + } + + scriptModel.getExtractOperationList().stream() + .filter(importsModel -> StringUtils.equals(importsModel.getVariableName(), assertModel.getShortServiceName())) + .findFirst() + .ifPresent(operation -> { + assertModel.setOperationName(operation.getOperationName()); + assertModel.setCategoryName(operation.getCategoryName()); + }); + } +} diff --git a/arex-web-core/src/main/java/com/arextest/web/core/repository/expectation/ExpectationScriptRepository.java b/arex-web-core/src/main/java/com/arextest/web/core/repository/expectation/ExpectationScriptRepository.java index ca8c382fe..4069c3872 100644 --- a/arex-web-core/src/main/java/com/arextest/web/core/repository/expectation/ExpectationScriptRepository.java +++ b/arex-web-core/src/main/java/com/arextest/web/core/repository/expectation/ExpectationScriptRepository.java @@ -1,7 +1,6 @@ package com.arextest.web.core.repository.expectation; import com.arextest.web.core.repository.RepositoryProvider; -import com.arextest.web.model.contract.contracts.config.expectation.ExpectationScriptDeleteRequest; import com.arextest.web.model.contract.contracts.config.expectation.ExpectationScriptModel; import com.arextest.web.model.contract.contracts.config.expectation.ExpectationScriptQueryRequest; import com.arextest.web.model.dao.mongodb.expectation.ExpectationScriptCollection; @@ -25,11 +24,11 @@ public class ExpectationScriptRepository implements RepositoryProvider { public boolean insert(ExpectationScriptModel model) { ExpectationScriptCollection entity = ExpectationScriptMapper.INSTANCE.toCollection(model); - if (entity.getExpirationTime() < 1L) { + if (entity.getExpirationTime() == null) { // 2099-01-01 12:00:00 entity.setExpirationTime(4070923200000L); } - entity.setValid(BooleanUtils.toBooleanDefaultIfNull(model.valid, true)); + entity.setValid(BooleanUtils.toBooleanDefaultIfNull(model.getValid(), true)); entity.setDataChangeCreateTime(System.currentTimeMillis()); entity.setDataChangeUpdateTime(entity.getDataChangeCreateTime()); mongoTemplate.insert(entity); @@ -43,8 +42,12 @@ public boolean update(ExpectationScriptModel model) { Update update = getConfigUpdate(); update.set(Fields.content, model.getContent()); - update.set(Fields.valid, BooleanUtils.toBooleanDefaultIfNull(model.valid, true)); - update.set(Fields.expirationTime, model.getExpirationTime()); + update.set(Fields.normalizedContent, model.getNormalizedContent()); + update.set(Fields.extractOperationList, model.getExtractOperationList()); + update.set(Fields.valid, BooleanUtils.toBooleanDefaultIfNull(model.getValid(), true)); + if (model.getExpirationTime() != null) { + update.set(Fields.expirationTime, model.getExpirationTime()); + } update.set(Fields.scope, model.getScope()); update.set(Fields.dataChangeUpdateBy, model.getDataChangeUpdateBy()); @@ -52,14 +55,10 @@ public boolean update(ExpectationScriptModel model) { return updateResult.getModifiedCount() > 0; } - public boolean save(ExpectationScriptModel model) { - return model.getId() != null ? update(model) : insert(model); - } - - public boolean delete(ExpectationScriptDeleteRequest request) { + public boolean delete(String id, String appId) { Query query = new Query(); - query.addCriteria(Criteria.where(DASH_ID).is(request.getId())); - query.addCriteria(Criteria.where(Fields.appId).is(request.getAppId())); + query.addCriteria(Criteria.where(DASH_ID).is(id)); + query.addCriteria(Criteria.where(Fields.appId).is(appId)); return mongoTemplate.remove(query, ExpectationScriptCollection.class).getDeletedCount() > 0; } diff --git a/arex-web-core/src/test/java/com/arextest/web/core/business/config/expectation/ScriptNormalizerTest.java b/arex-web-core/src/test/java/com/arextest/web/core/business/config/expectation/ScriptNormalizerTest.java new file mode 100644 index 000000000..109c6773d --- /dev/null +++ b/arex-web-core/src/test/java/com/arextest/web/core/business/config/expectation/ScriptNormalizerTest.java @@ -0,0 +1,52 @@ +package com.arextest.web.core.business.config.expectation; + +import com.arextest.web.core.business.config.expectation.assertion.EqualsHandler; +import com.arextest.web.model.contract.contracts.config.expectation.ExpectationScriptModel; +import com.arextest.web.model.contract.contracts.config.expectation.ScriptExtractOperationModel; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * @since 2023/12/15 + */ +class ScriptNormalizerTest { + static ScriptNormalizer scriptNormalizer; + static List scriptAssertHandlerList; + + @BeforeEach + void setUp() { + scriptAssertHandlerList = new ArrayList<>(1); + scriptAssertHandlerList.add(new EqualsHandler()); + scriptNormalizer = new ScriptNormalizer(scriptAssertHandlerList); + } + + @AfterEach + void tearDown() { + } + + @Test + void normalize() { + String script = " var serviceConsumerA = arex.SoaConsumer[\"HelloService.ConsumerA\"];\n" + + " arex.assert.equals(\"serviceConsumerB\", serviceConsumerA.request.name);\n" + + "\n" + + " var serviceConsumerB = arex.SoaConsumer[\"HelloService.ConsumerB\"];\n" + + " arex.assert.equals(\"serviceConsumerB\", serviceConsumerB.request.name);\n" + + " \n" + + " arex.assert.equals(\"mark4\", arex.SoaProvider[\"HelloService\"].response.order.id);"; + ExpectationScriptModel expectationScript = new ExpectationScriptModel(); + expectationScript.setAppId("test-service"); + expectationScript.setOperationId("test-operation-id"); + expectationScript.setContent(script); + expectationScript.setNormalizedContent(expectationScript.getContent()); + scriptNormalizer.normalize(expectationScript); + + assert expectationScript.getExtractOperationList().size() == 3; + + for (ScriptExtractOperationModel operation : expectationScript.getExtractOperationList()) { + System.out.println(operation); + } + } +} diff --git a/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ExpectationScriptModel.java b/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ExpectationScriptModel.java index 0762ca8e4..73cfba3ae 100644 --- a/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ExpectationScriptModel.java +++ b/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ExpectationScriptModel.java @@ -1,7 +1,6 @@ package com.arextest.web.model.contract.contracts.config.expectation; -import java.util.Map; -import java.util.Set; +import java.util.List; import javax.validation.constraints.NotBlank; import lombok.Data; @@ -33,15 +32,15 @@ public class ExpectationScriptModel { /** * Script normalized content */ - public String normalizedContent; + private String normalizedContent; /** * Script is valid, null for all, 0 true/1 false */ - public Boolean valid; + private Boolean valid; /** * Script expiration time */ - public long expirationTime; + private Long expirationTime; /** * 0 for specified operation * 1 for all operation @@ -52,7 +51,8 @@ public class ExpectationScriptModel { private Long dataChangeCreateTime; private Long dataChangeUpdateTime; /** - * import operation list eg: [{soaConsumer, xxx.service1, xxx.service2}] + * extract operation list */ - private Map> scriptImportOperationMap; + private List extractOperationList; + private transient List invalidExtractAssertList; } diff --git a/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ScriptAssertionModel.java b/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ScriptExtractAssertModel.java similarity index 58% rename from arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ScriptAssertionModel.java rename to arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ScriptExtractAssertModel.java index bf2faa991..a25f68d5b 100644 --- a/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ScriptAssertionModel.java +++ b/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ScriptExtractAssertModel.java @@ -7,30 +7,33 @@ * @since 2023/11/29 */ @Data -public class ScriptAssertionModel { +public class ScriptExtractAssertModel { public String methodName; private String expected; private String shortServiceName; - private String fullServiceName; + private String operationName; private String categoryName; private String path; private String originalText; - public ScriptAssertionModel(String originalText) { + public ScriptExtractAssertModel(String originalText) { this.originalText = originalText; } public boolean validate() { return methodName != null && expected != null - && fullServiceName != null + && operationName != null && path != null; } - public String regenerate() { + public String rebuild() { String[] arrays = StringUtils.splitPreserveAllTokens(originalText, "("); - return String.format("%s(\"%s\", \"%s\", \"%s\", %s", - arrays[0], categoryName, fullServiceName, path, arrays[1]); + if (arrays == null || arrays.length != 2) { + return originalText; + } + return String.format("%s(\"%s\", \"%s\", \"%s\", '%s', %s", + arrays[0], categoryName, operationName, path, originalText, arrays[1]); } } diff --git a/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ScriptExtractOperationModel.java b/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ScriptExtractOperationModel.java new file mode 100644 index 000000000..cc5bc3d64 --- /dev/null +++ b/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ScriptExtractOperationModel.java @@ -0,0 +1,43 @@ +package com.arextest.web.model.contract.contracts.config.expectation; + +import java.util.Objects; +import lombok.Data; + +/** + * @since 2023/11/29 + */ +@Data +public class ScriptExtractOperationModel { + String categoryName; + String variableName; + String operationName; + String originalText; + + public boolean validate() { + return categoryName != null && operationName != null; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + + ScriptExtractOperationModel that = (ScriptExtractOperationModel) object; + + if (!Objects.equals(categoryName, that.categoryName)) { + return false; + } + return Objects.equals(operationName, that.operationName); + } + + @Override + public int hashCode() { + int result = categoryName != null ? categoryName.hashCode() : 0; + result = 31 * result + (operationName != null ? operationName.hashCode() : 0); + return result; + } +} diff --git a/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ScriptImportsOperationModel.java b/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ScriptImportsOperationModel.java deleted file mode 100644 index c8b28959c..000000000 --- a/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/config/expectation/ScriptImportsOperationModel.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.arextest.web.model.contract.contracts.config.expectation; - -import java.util.Objects; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import lombok.Data; - -/** - * @since 2023/11/29 - */ -@Data -public class ScriptImportsOperationModel { - String categoryName; - String variableName; - String operationName; - String originalText; - - // let +(?.*) += +arex.(?.*)?\[\"(?.*)\"] - private static final String REGEX = "let +(?.*) += +arex.(?.*)\n?\\[\"(?.*)\"]"; - private static final Pattern PATTERN = Pattern.compile(REGEX); - - public ScriptImportsOperationModel(String originalText) { - this.originalText = originalText; - if (originalText == null) { - return; - } - Matcher matcher = PATTERN.matcher(originalText); - if (matcher.find()) { - variableName = matcher.group("variableName"); - categoryName = matcher.group("category"); - operationName = matcher.group("operation"); - } - } - - public boolean validate() { - return variableName != null - && categoryName != null - && operationName != null; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object == null || getClass() != object.getClass()) { - return false; - } - - ScriptImportsOperationModel that = (ScriptImportsOperationModel) object; - - if (!Objects.equals(categoryName, that.categoryName)) { - return false; - } - if (!Objects.equals(variableName, that.variableName)) { - return false; - } - return Objects.equals(operationName, that.operationName); - } - - @Override - public int hashCode() { - int result = categoryName != null ? categoryName.hashCode() : 0; - result = 31 * result + (variableName != null ? variableName.hashCode() : 0); - result = 31 * result + (operationName != null ? operationName.hashCode() : 0); - return result; - } -} diff --git a/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/expectation/ExpectationScriptCollection.java b/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/expectation/ExpectationScriptCollection.java index cadc8708a..0085a61c5 100644 --- a/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/expectation/ExpectationScriptCollection.java +++ b/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/expectation/ExpectationScriptCollection.java @@ -1,6 +1,8 @@ package com.arextest.web.model.dao.mongodb.expectation; +import com.arextest.web.model.contract.contracts.config.expectation.ScriptExtractOperationModel; import com.arextest.web.model.dao.mongodb.ModelBase; +import java.util.List; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.FieldNameConstants; @@ -27,6 +29,10 @@ public class ExpectationScriptCollection extends ModelBase { * Script content */ public String content; + /** + * Script normalized content + */ + private String normalizedContent; /** * Script is valid */ @@ -34,7 +40,7 @@ public class ExpectationScriptCollection extends ModelBase { /** * Script expiration time */ - public long expirationTime; + public Long expirationTime; /** /** * 0 specified: for specified operation @@ -43,4 +49,16 @@ public class ExpectationScriptCollection extends ModelBase { private byte scope; private String dataChangeCreateBy; private String dataChangeUpdateBy; + /** + * extract operation list + */ + private List extractOperationList; + + @Data + public static class ScriptExtractOperationCollection { + private String categoryName; + private String variableName; + private String operationName; + private String originalText; + } } diff --git a/arex-web-model/src/main/java/com/arextest/web/model/mapper/expectation/ExpectationScriptMapper.java b/arex-web-model/src/main/java/com/arextest/web/model/mapper/expectation/ExpectationScriptMapper.java index 5d8983c05..82a7e72ad 100644 --- a/arex-web-model/src/main/java/com/arextest/web/model/mapper/expectation/ExpectationScriptMapper.java +++ b/arex-web-model/src/main/java/com/arextest/web/model/mapper/expectation/ExpectationScriptMapper.java @@ -1,6 +1,7 @@ package com.arextest.web.model.mapper.expectation; import com.arextest.web.model.contract.contracts.config.expectation.ExpectationScriptModel; +import com.arextest.web.model.contract.contracts.config.expectation.ScriptExtractOperationModel; import com.arextest.web.model.dao.mongodb.expectation.ExpectationScriptCollection; import java.util.List; import org.mapstruct.Mapper; @@ -12,6 +13,8 @@ public interface ExpectationScriptMapper { ExpectationScriptMapper INSTANCE = Mappers.getMapper(ExpectationScriptMapper.class); ExpectationScriptCollection toCollection(ExpectationScriptModel model); ExpectationScriptModel toModel(ExpectationScriptCollection entity); + ScriptExtractOperationModel toModel(ExpectationScriptCollection.ScriptExtractOperationCollection entity); + ExpectationScriptCollection.ScriptExtractOperationCollection toCollection(ScriptExtractOperationModel model); List toCollectionList(List modelList); List toModelList(List collectionList); } diff --git a/pom.xml b/pom.xml index 495b8d30c..f23bb0a7d 100644 --- a/pom.xml +++ b/pom.xml @@ -389,7 +389,7 @@ - 0.6.0.14-SNAPSHOT + 0.6.0.15-SNAPSHOT 0.1.17 0.0.1 1.0.40