use of com.alibaba.citrus.turbine.impl.DefaultContext in project plugins by qlangtech.
the class DataXOssReader method getSelectedTabs.
@Override
public List<ParseColsResult.DataXReaderTabMeta> getSelectedTabs() {
DefaultContext context = new DefaultContext();
ParseColsResult parseOSSColsResult = ParseColsResult.parseColsCfg(new MockFieldErrorHandler(), context, StringUtils.EMPTY, this.column);
if (!parseOSSColsResult.success) {
throw new IllegalStateException("parseOSSColsResult must be success");
}
return Collections.singletonList(parseOSSColsResult.tabMeta);
}
use of com.alibaba.citrus.turbine.impl.DefaultContext in project plugins by qlangtech.
the class DataXHdfsReader method getSelectedTabs.
@Override
public List<ParseColsResult.DataXReaderTabMeta> getSelectedTabs() {
DefaultContext context = new DefaultContext();
ParseColsResult parseOSSColsResult = ParseColsResult.parseColsCfg(new MockFieldErrorHandler(), context, StringUtils.EMPTY, this.column);
if (!parseOSSColsResult.success) {
throw new IllegalStateException("parseOSSColsResult must be success");
}
return Collections.singletonList(parseOSSColsResult.tabMeta);
}
use of com.alibaba.citrus.turbine.impl.DefaultContext in project plugins by qlangtech.
the class DataXFtpReader method getSelectedTabs.
@Override
public List<ParseColsResult.DataXReaderTabMeta> getSelectedTabs() {
DefaultContext context = new DefaultContext();
ParseColsResult parseColsResult = ParseColsResult.parseColsCfg(new DefaultFieldErrorHandler(), context, StringUtils.EMPTY, this.column);
if (!parseColsResult.success) {
throw new IllegalStateException("parseColsResult must be success");
}
return Collections.singletonList(parseColsResult.tabMeta);
}
use of com.alibaba.citrus.turbine.impl.DefaultContext in project plugins by qlangtech.
the class TestRockMqPluginValidate method testDigital_Alpha_CharacterValidate.
public void testDigital_Alpha_CharacterValidate() throws Exception {
final DefaultContext context = new DefaultContext();
final Map<String, Object> fieldErrors = context.getContextMap();
validatePluginPostForm("rockmq_plugin_from_invalid.json", context);
List<List<DefaultFieldErrorHandler.FieldError>> /**
* item
*/
itemsErrorList = (List<List<DefaultFieldErrorHandler.FieldError>>) fieldErrors.get(IFieldErrorHandler.ACTION_ERROR_FIELDS);
assertNotNull(itemsErrorList);
assertEquals(1, itemsErrorList.size());
List<DefaultFieldErrorHandler.FieldError> fieldErrors1 = itemsErrorList.get(0);
assertEquals(2, fieldErrors1.size());
Optional<DefaultFieldErrorHandler.FieldError> mqTopicErr = fieldErrors1.stream().filter((r) -> mqTopic.equals(r.getFieldName())).findFirst();
assertTrue(mqTopicErr.isPresent());
assertEquals(ValidatorCommons.MSG_IDENTITY_ERROR, mqTopicErr.get().getMsg());
assertNull(mqTopicErr.get().itemsErrorList);
assertEquals(mqTopic, mqTopicErr.get().getFieldName());
Optional<DefaultFieldErrorHandler.FieldError> deserializeErr = fieldErrors1.stream().filter((r) -> deserialize.equals(r.getFieldName())).findFirst();
assertTrue(deserializeErr.isPresent());
DefaultFieldErrorHandler.FieldError dErr = deserializeErr.get();
assertEquals(deserialize, dErr.getFieldName());
assertNull(dErr.getMsg());
assertNotNull(dErr.itemsErrorList);
assertEquals(1, dErr.itemsErrorList.size());
List<DefaultFieldErrorHandler.FieldError> /**
* item
*/
dValsItem = dErr.itemsErrorList.get(0);
assertEquals(1, dValsItem.size());
DefaultFieldErrorHandler.FieldError testName = dValsItem.get(0);
assertEquals(testProp, testName.getFieldName());
assertEquals("ddd", testName.getMsg());
assertNull(testName.itemsErrorList);
}
use of com.alibaba.citrus.turbine.impl.DefaultContext in project tis by qlangtech.
the class TestValidator method testValidateFieldByMultiRules.
public void testValidateFieldByMultiRules() {
final String numbericValidateFaild = "必须是数字";
//
//
Map<String, Validator.FieldValidators> validatorsRules = //
Validator.fieldsValidator(//
field1Name, new Validator.FieldValidators(Validator.require) {
}, (Validator.IFieldValidator) ((msgHandler, context, fieldKey, fieldData) -> {
if (!StringUtils.isNumeric(fieldData)) {
msgHandler.addFieldError(context, field1Name, numbericValidateFaild);
// 校验是否是数字
return false;
}
return true;
}));
assertEquals("validatorsRules size", 1, validatorsRules.size());
Validator.FieldValidators fieldValidators = validatorsRules.get(field1Name);
assertNotNull(fieldValidators);
assertEquals(2, fieldValidators.validators.size());
Context context = new DefaultContext();
IControlMsgHandler msgHandler = EasyMock.createMock("msgHandler", IControlMsgHandler.class);
EasyMock.expect(msgHandler.getString(field1Name)).andReturn("123");
msgHandler.errorsPageShow(context);
EasyMock.expectLastCall().andVoid().times(2);
EasyMock.expect(msgHandler.getString(field1Name)).andReturn("123aaa");
msgHandler.addFieldError(context, field1Name, numbericValidateFaild);
msgHandler.addErrorMessage(context, Validator.FORM_ERROR_SUMMARY);
// EasyMock.expect().andReturn("123aaa");
EasyMock.replay(msgHandler);
assertTrue(Validator.validate(msgHandler, context, validatorsRules));
// 第二次应该校验失败了
assertFalse(Validator.validate(msgHandler, context, validatorsRules));
EasyMock.verify(msgHandler);
}
Aggregations