From c7075000de5b9ec3fe3674a0c454402bfd2b0efa Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Fri, 2 Dec 2016 15:16:27 +0400 Subject: [PATCH] PL-7699 Bean validation support for UI - fix components test --- .../testsupport/CubaClientTestCase.java | 8 ++ .../testsupport/TestBeanValidation.java | 135 ++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 modules/client/test/com/haulmont/cuba/client/testsupport/TestBeanValidation.java diff --git a/modules/client/test/com/haulmont/cuba/client/testsupport/CubaClientTestCase.java b/modules/client/test/com/haulmont/cuba/client/testsupport/CubaClientTestCase.java index f2204e041e..c88f483946 100644 --- a/modules/client/test/com/haulmont/cuba/client/testsupport/CubaClientTestCase.java +++ b/modules/client/test/com/haulmont/cuba/client/testsupport/CubaClientTestCase.java @@ -72,6 +72,8 @@ public class CubaClientTestCase { protected TestMessageTools messageTools; + protected TestBeanValidation beanValidation; + public CubaClientTestCase() { String property = System.getProperty("logback.configurationFile"); if (StringUtils.isBlank(property)) { @@ -126,6 +128,8 @@ public class CubaClientTestCase { messages = new TestMessages(userSessionSource, configuration, metadata, extendedEntities); messageTools = (TestMessageTools) messages.getTools(); + beanValidation = new TestBeanValidation(); + ((TestMetadataTools) metadata.getTools()).setMessages(messages); ((TestMetadataTools) metadata.getTools()).setUserSessionSource(userSessionSource); @@ -176,6 +180,10 @@ public class CubaClientTestCase { AppBeans.get(MessageTools.NAME); result = messageTools; AppBeans.get(MessageTools.class); result = messageTools; AppBeans.get(MessageTools.NAME, MessageTools.class); result = messageTools; + + AppBeans.get(BeanValidation.NAME); result = beanValidation; + AppBeans.get(BeanValidation.class); result = beanValidation; + AppBeans.get(BeanValidation.NAME, BeanValidation.class); result = beanValidation; } }; } diff --git a/modules/client/test/com/haulmont/cuba/client/testsupport/TestBeanValidation.java b/modules/client/test/com/haulmont/cuba/client/testsupport/TestBeanValidation.java new file mode 100644 index 0000000000..953a458760 --- /dev/null +++ b/modules/client/test/com/haulmont/cuba/client/testsupport/TestBeanValidation.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2008-2016 Haulmont. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.haulmont.cuba.client.testsupport; + +import com.haulmont.cuba.core.global.BeanValidation; +import org.hibernate.validator.cfg.ConstraintMapping; + +import javax.annotation.Nullable; +import javax.validation.ConstraintViolation; +import javax.validation.Validator; +import javax.validation.executable.ExecutableValidator; +import javax.validation.metadata.*; +import java.util.Collections; +import java.util.Set; + +public class TestBeanValidation implements BeanValidation { + @Override + public Validator getValidator() { + return new ValidatorStub(); + } + + @Override + public Validator getValidator(ConstraintMapping constraintMapping) { + return new ValidatorStub(); + } + + @Override + public Validator getValidator(@Nullable ConstraintMapping constraintMapping, ValidationOptions options) { + return new ValidatorStub(); + } + + public static class ValidatorStub implements Validator { + @Override + public Set> validate(T object, Class[] groups) { + return Collections.emptySet(); + } + + @Override + public Set> validateProperty(T object, String propertyName, Class[] groups) { + return Collections.emptySet(); + } + + @Override + public Set> validateValue(Class beanType, String propertyName, Object value, Class[] groups) { + return Collections.emptySet(); + } + + @Override + public BeanDescriptor getConstraintsForClass(Class clazz) { + return new BeanDescriptorStub(); + } + + @Override + public T unwrap(Class type) { + return null; + } + + @Override + public ExecutableValidator forExecutables() { + return null; + } + } + + public static class BeanDescriptorStub implements BeanDescriptor { + + @Override + public boolean isBeanConstrained() { + return false; + } + + @Override + public PropertyDescriptor getConstraintsForProperty(String propertyName) { + return null; + } + + @Override + public Set getConstrainedProperties() { + return null; + } + + @Override + public MethodDescriptor getConstraintsForMethod(String methodName, Class[] parameterTypes) { + return null; + } + + @Override + public Set getConstrainedMethods(MethodType methodType, MethodType... methodTypes) { + return null; + } + + @Override + public ConstructorDescriptor getConstraintsForConstructor(Class[] parameterTypes) { + return null; + } + + @Override + public Set getConstrainedConstructors() { + return null; + } + + @Override + public boolean hasConstraints() { + return false; + } + + @Override + public Class getElementClass() { + return null; + } + + @Override + public Set> getConstraintDescriptors() { + return null; + } + + @Override + public ConstraintFinder findConstraints() { + return null; + } + } +} \ No newline at end of file