Search in sources :

Example 6 with DefaultContext

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);
}
Also used : DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext) Context(com.alibaba.citrus.turbine.Context) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler) DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext)

Example 7 with DefaultContext

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);
}
Also used : List(java.util.List) DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext) DefaultFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.impl.DefaultFieldErrorHandler)

Example 8 with DefaultContext

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());
    }
}
Also used : DelegateControl4JsonPostMsgHandler(com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler) Descriptor(com.qlangtech.tis.extension.Descriptor) AttrValMap(com.qlangtech.tis.util.AttrValMap) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Context(com.alibaba.citrus.turbine.Context) IFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler) JSONArray(com.alibaba.fastjson.JSONArray) IOUtils(org.apache.commons.io.IOUtils) ValidatorCommons(com.qlangtech.tis.plugin.ValidatorCommons) List(java.util.List) DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext) Map(java.util.Map) TisUTF8(com.qlangtech.tis.manage.common.TisUTF8) Optional(java.util.Optional) DefaultFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.impl.DefaultFieldErrorHandler) InputStream(java.io.InputStream) List(java.util.List) DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext) DefaultFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.impl.DefaultFieldErrorHandler)

Example 9 with DefaultContext

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);
}
Also used : IndexIncrStatus(com.qlangtech.tis.coredefine.module.action.IndexIncrStatus) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler) DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext)

Aggregations

DefaultContext (com.alibaba.citrus.turbine.impl.DefaultContext)9 Context (com.alibaba.citrus.turbine.Context)4 DefaultFieldErrorHandler (com.qlangtech.tis.runtime.module.misc.impl.DefaultFieldErrorHandler)4 IControlMsgHandler (com.qlangtech.tis.runtime.module.misc.IControlMsgHandler)3 List (java.util.List)3 JSONArray (com.alibaba.fastjson.JSONArray)2 Descriptor (com.qlangtech.tis.extension.Descriptor)2 TisUTF8 (com.qlangtech.tis.manage.common.TisUTF8)2 ValidatorCommons (com.qlangtech.tis.plugin.ValidatorCommons)2 IFieldErrorHandler (com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler)2 DelegateControl4JsonPostMsgHandler (com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler)2 AttrValMap (com.qlangtech.tis.util.AttrValMap)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 IOUtils (org.apache.commons.io.IOUtils)2 IndexIncrStatus (com.qlangtech.tis.coredefine.module.action.IndexIncrStatus)1