org.hibernate.beanvalidation.tck.tests.constraints.containerelement.SameElementContainedSeveralTimesInCollectionTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of beanvalidation-tck-tests Show documentation
Show all versions of beanvalidation-tck-tests Show documentation
Jakarta Bean Validation TCK test suite
/**
* Jakarta Bean Validation TCK
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or .
*/
package org.hibernate.beanvalidation.tck.tests.constraints.containerelement;
import static org.hibernate.beanvalidation.tck.util.ConstraintViolationAssert.assertThat;
import static org.hibernate.beanvalidation.tck.util.ConstraintViolationAssert.pathWith;
import static org.hibernate.beanvalidation.tck.util.ConstraintViolationAssert.violationOf;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.constraints.Size;
import org.hibernate.beanvalidation.tck.beanvalidation.Sections;
import org.hibernate.beanvalidation.tck.tests.AbstractTCKTest;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecVersion;
import org.testng.annotations.Test;
/**
* @author Gunnar Morling
* @author Guillaume Smet
*/
@SpecVersion(spec = "beanvalidation", version = "3.0.0")
public class SameElementContainedSeveralTimesInCollectionTest extends AbstractTCKTest {
@Deployment
public static WebArchive createTestArchive() {
return webArchiveBuilder()
.withTestClass( SameElementContainedSeveralTimesInCollectionTest.class )
.build();
}
@Test
@SpecAssertion(section = Sections.CONSTRAINTDECLARATIONVALIDATIONPROCESS_CONTAINERELEMENTCONSTRAINTS, id = "c")
public void sameInvalidInstanceInListShouldBeReportedWithAllPaths() {
ListContainer listContainer = new ListContainer( Arrays.asList( "", "A", "" ) );
Set> constraintViolations = getValidator().validate( listContainer );
assertThat( constraintViolations ).containsOnlyViolations(
violationOf( Size.class )
.withPropertyPath( pathWith()
.property( "values" )
.containerElement( "", true, null, 0, List.class, 0 )
),
violationOf( Size.class )
.withPropertyPath( pathWith()
.property( "values" )
.containerElement( "", true, null, 2, List.class, 0 )
)
);
}
@Test
@SpecAssertion(section = Sections.CONSTRAINTDECLARATIONVALIDATIONPROCESS_CONTAINERELEMENTCONSTRAINTS, id = "c")
public void sameInvalidInstanceInMapShouldBeReportedWithAllPaths() {
List emptyList = Collections.emptyList();
List nonEmptyList = Arrays.asList( "A" );
HashMap> values = new HashMap<>();
values.put( "NON_EMPTY", nonEmptyList );
values.put( "EMPTY_1", emptyList );
values.put( "EMPTY_2", emptyList );
MapContainer withMap = new MapContainer( values );
Set> constraintViolations = getValidator().validate( withMap );
assertThat( constraintViolations ).containsOnlyViolations(
violationOf( Size.class )
.withPropertyPath( pathWith()
.property( "values" )
.containerElement( "