Commit fec68ec6 authored by Thomas Mortagne's avatar Thomas Mortagne
Browse files

[misc] Add a bean validation macro properties test

parent dcb19ae0
......@@ -73,6 +73,13 @@
<artifactId>hibernate-validator</artifactId>
<scope>test</scope>
</dependency>
<!-- Hibernate Validator needs a EL implementation,
use the same as Jetty and Tomcat (which are the most used application servers with XWiki) for the tests -->
<dependency>
<groupId>org.mortbay.jasper</groupId>
<artifactId>apache-el</artifactId>
<version>9.0.52</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
......
......@@ -35,6 +35,7 @@
import org.xwiki.properties.internal.converter.EnumConverter;
import org.xwiki.properties.test.GenericTestConverter;
import org.xwiki.properties.test.TestBean;
import org.xwiki.properties.test.TestBeanValidation;
import org.xwiki.test.annotation.ComponentList;
import org.xwiki.test.junit5.mockito.ComponentTest;
import org.xwiki.test.junit5.mockito.InjectComponentManager;
......@@ -108,6 +109,25 @@ void populate() throws PropertyException
assertEquals(Arrays.asList(1, 2), beanTest.getGenericProp());
}
@Test
void populateWithValidation() throws PropertyException
{
TestBeanValidation beanTest = new TestBeanValidation();
Map<String, String> values = new HashMap<>();
values.put("working", "true");
this.defaultBeanManager.populate(beanTest, values);
assertTrue(beanTest.isWorking());
values.put("working", "false");
assertThrows(PropertyException.class, () -> this.defaultBeanManager.populate(beanTest, values),
"No Bean Validation was executed");
}
@Test
void populateWhenMissingMandatoryProperty()
{
......
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.properties.test;
import javax.validation.constraints.AssertTrue;
public class TestBeanValidation
{
@AssertTrue
private boolean working;
/**
* @return the working
*/
public boolean isWorking()
{
return this.working;
}
/**
* @param working the working to set
*/
public void setWorking(boolean working)
{
this.working = working;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment