use of com.alibaba.citrus.turbine.impl.DefaultContext in project tis by qlangtech.
the class TestValidator method testValidateIdentityWithDependencyRule.
/**
* 一个校验项,的值需要依赖另外一个校验项运行
*/
public void testValidateIdentityWithDependencyRule() {
IControlMsgHandler msgHandler = EasyMock.createMock("msgHandler", IControlMsgHandler.class);
String field1NameVal = "123";
EasyMock.expect(msgHandler.getString(field1Name)).andReturn(field1NameVal);
EasyMock.expect(msgHandler.getString(field2Name)).andReturn("field2NameValue");
Context context = new DefaultContext();
final String[] field1Val = new String[1];
// field2Name 字段依赖 fieldName 的值
//
Map<String, Validator.FieldValidators> validatorsRules = //
Validator.fieldsValidator(//
field1Name, new Validator.FieldValidators(Validator.require) {
@Override
public void setFieldVal(String val) {
field1Val[0] = val;
}
}, //
field2Name, new Validator.FieldValidators(Validator.require) {
}.addDependency(field1Name), (Validator.IFieldValidator) ((msgHdr, ctx, fieldKey, fieldData) -> {
assertEquals(field1NameVal, field1Val[0]);
return true;
}));
msgHandler.errorsPageShow(context);
EasyMock.expectLastCall().andVoid().times(1);
EasyMock.replay(msgHandler);
assertTrue(Validator.validate(msgHandler, context, validatorsRules));
EasyMock.verify(msgHandler);
}
use of com.alibaba.citrus.turbine.impl.DefaultContext in project tis by qlangtech.
the class TestValidator method testValidateIdentity.
public void testValidateIdentity() {
Validator identityValidator = Validator.identity;
DefaultFieldErrorHandler fEHandler = new DefaultFieldErrorHandler();
DefaultContext context = new DefaultContext();
context.put(DefaultFieldErrorHandler.KEY_VALIDATE_PLUGIN_INDEX, new Integer(2));
assertTrue("error shall none error", identityValidator.validate(fEHandler, context, field1Name, "base123"));
assertFalse(identityValidator.validate(fEHandler, context, field1Name, "_base123"));
List<List<List<DefaultFieldErrorHandler.FieldError>>> pluginErrorList = (List<List<List<DefaultFieldErrorHandler.FieldError>>>) context.get(IFieldErrorHandler.ACTION_ERROR_FIELDS);
assertEquals(3, pluginErrorList.size());
DefaultFieldErrorHandler.FieldError fError = pluginErrorList.get(2).get(0).get(0);
assertEquals(field1Name, fError.getFieldName());
assertEquals(ValidatorCommons.MSG_IDENTITY_ERROR, fError.getMsg());
assertNull(fError.itemsErrorList);
}
use of com.alibaba.citrus.turbine.impl.DefaultContext in project plugins by qlangtech.
the class TestRockMqPluginValidate method testEmptyInputValidate.
public void testEmptyInputValidate() throws Exception {
// final Map<String, String> fieldErrors = Maps.newHashMap();
final DefaultContext context = new DefaultContext();
final Map<String, Object> fieldErrors = context.getContextMap();
validatePluginPostForm("rockmq_plugin_from_empty.json", context);
List<List<DefaultFieldErrorHandler.FieldError>> /**
* item
*/
itemsErrorList = (List<List<DefaultFieldErrorHandler.FieldError>>) fieldErrors.get(IFieldErrorHandler.ACTION_ERROR_FIELDS);
assertEquals(1, itemsErrorList.size());
List<DefaultFieldErrorHandler.FieldError> /**
* item
*/
fErrors = itemsErrorList.get(0);
assertEquals(4, fErrors.size());
Map<String, DefaultFieldErrorHandler.FieldError> filedErrorMap = fErrors.stream().collect(Collectors.toMap((r) -> r.getFieldName(), (r) -> r));
assertNotNull(filedErrorMap.get(mqTopic));
assertNotNull(filedErrorMap.get(deserialize));
assertNotNull(filedErrorMap.get(consumeName));
assertNotNull(filedErrorMap.get(namesrvAddr));
for (DefaultFieldErrorHandler.FieldError errMsg : filedErrorMap.values()) {
assertEquals("ddd", errMsg.getMsg());
}
}
use of com.alibaba.citrus.turbine.impl.DefaultContext in project tis by qlangtech.
the class TestGenerateDAOAndIncrScript method testCompileAndPackageStreamCode.
public void testCompileAndPackageStreamCode() throws Exception {
IControlMsgHandler msgHandler = new DefaultMessageHandler();
IndexStreamCodeGenerator indexStreamCodeGenerator = getIndexStreamCodeGenerator();
GenerateDAOAndIncrScript generateDAOAndIncrScript = new GenerateDAOAndIncrScript(msgHandler, indexStreamCodeGenerator);
DefaultContext context = new DefaultContext();
IndexIncrStatus incrStatus = new IndexIncrStatus();
Map<Integer, Long> /**
* timestamp ver
*/
dependencyDbs = Maps.newHashMap();
// order
dependencyDbs.put(58, 20200227124059l);
// member
dependencyDbs.put(61, 20200227124200l);
// cardcenter
dependencyDbs.put(62, 20200227124220l);
// shop
dependencyDbs.put(63, 20200227124231l);
generateDAOAndIncrScript.generate(context, incrStatus, true, dependencyDbs);
}
Aggregations