@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "d") public void testGetReturnValueDescriptorForMethod() { MethodDescriptor descriptor = Executables.returnValueConstrainedMethod(); assertNotNull( descriptor.getReturnValueDescriptor(), "Return value descriptor should not be null" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "d") public void testGetUnconstrainedReturnValueDescriptorForMethod() { MethodDescriptor descriptor = Executables.cascadedParameterMethod(); assertNotNull( descriptor.getReturnValueDescriptor(), "Return value descriptor should not be null" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "d") public void testReturnValueDescriptorForVoidMethod() { MethodDescriptor descriptor = Executables.parameterConstrainedMethod(); assertNotNull( descriptor.getReturnValueDescriptor(), "Return value descriptor should not be null" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_CASCADABLEDESCRIPTOR, id = "b") public void testGetGroupConversionsReturnsEmptySetForConstructorReturnValue() { ReturnValueDescriptor returnValueDescriptor = Executables.cascadedReturnValueMethod() .getReturnValueDescriptor(); Set<GroupConversionDescriptor> groupConversions = returnValueDescriptor.getGroupConversions(); assertNotNull( groupConversions ); assertTrue( groupConversions.isEmpty() ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_CASCADABLEDESCRIPTOR, id = "a") public void testIsCascadedForMethodReturnValue() { ReturnValueDescriptor descriptor = Executables.returnValueConstrainedMethod() .getReturnValueDescriptor(); assertFalse( descriptor.isCascaded(), "Should not be cascaded" ); descriptor = Executables.cascadedReturnValueMethod().getReturnValueDescriptor(); assertTrue( descriptor.isCascaded(), "Should be cascaded" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_CASCADABLEDESCRIPTOR, id = "a") public void testIsCascadedForVoidMethod() { ReturnValueDescriptor descriptor = Executables.parameterConstrainedMethod().getReturnValueDescriptor(); assertFalse( descriptor.isCascaded() ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_ELEMENTDESCRIPTOR, id = "a") public void testGetElementClassForVoidMethod() { ReturnValueDescriptor descriptor = Executables.parameterConstrainedMethod().getReturnValueDescriptor(); assertEquals( descriptor.getElementClass(), void.class ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_ELEMENTDESCRIPTOR, id = "a") public void testGetElementClassForMethod() { ReturnValueDescriptor descriptor = Executables.returnValueConstrainedMethod().getReturnValueDescriptor(); assertEquals( descriptor.getElementClass(), int.class ); }
@Test @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "o") public void testValidaAnnotationIsApplied() throws Exception { MethodDescriptor descriptor = TestUtil.getMethodDescriptor( Cascaded.class, "cascade", String.class ); assertNotNull( descriptor, "the specified method should be configured in xml" ); ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor(); assertTrue( returnValueDescriptor.isCascaded(), "Cascaded validation should be applied" ); ParameterDescriptor parameterDescriptor = descriptor.getParameterDescriptors().get( 0 ); assertTrue( parameterDescriptor.isCascaded(), "Cascaded validation should be applied" ); } }
@Test @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "i") public void testCascadingOnReturnValueAndParameter() throws Exception { MethodDescriptor descriptor = TestUtil.getMethodDescriptor( CustomerRepository.class, "findByExample", Customer.class ); assertNotNull( descriptor, "the specified method should be configured in xml" ); ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor(); assertTrue( returnValueDescriptor.isCascaded(), "<valid/> is used to configure cascading" ); List<ParameterDescriptor> parameterDescriptors = descriptor.getParameterDescriptors(); assertTrue( parameterDescriptors.size() == 1 ); ParameterDescriptor parameterDescriptor = parameterDescriptors.get( 0 ); assertTrue( parameterDescriptor.isCascaded(), "<valid/> is used to configure cascading" ); }
@Test @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "o") public void testValidAnnotationIsIgnored() throws Exception { MethodDescriptor descriptor = TestUtil.getMethodDescriptor( org.hibernate.beanvalidation.tck.tests.xmlconfiguration.methodvalidation.Cascaded.class, "cascade", String.class ); assertNotNull( descriptor, "the specified method should be configured in xml" ); ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor(); assertFalse( returnValueDescriptor.isCascaded(), "Cascaded validation should be ignored" ); ParameterDescriptor parameterDescriptor = descriptor.getParameterDescriptors().get( 0 ); assertFalse( parameterDescriptor.isCascaded(), "Cascaded validation should be ignored" ); } }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_CASCADABLEDESCRIPTOR, id = "b") @SpecAssertion(section = Sections.CONSTRAINTMETADATA_GROUPCONVERSIONDESCRIPTOR, id = "a") @SpecAssertion(section = Sections.CONSTRAINTMETADATA_GROUPCONVERSIONDESCRIPTOR, id = "b") public void testGetGroupConversionsForVoidMethod() { ReturnValueDescriptor descriptor = Executables.parameterConstrainedMethod().getReturnValueDescriptor(); assertTrue( descriptor.getGroupConversions().isEmpty() ); }
@Test @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_GROUPCONVERSIONS, id = "a") @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_GROUPCONVERSIONS, id = "b") public void testGroupConversionsAppliedOnMethod() throws Exception { MethodDescriptor methodDescriptor = TestUtil.getMethodDescriptor( Groups.class, "convert", String.class ); assertNotNull( methodDescriptor, "the specified method should be configured in xml" ); ReturnValueDescriptor returnValueDescriptor = methodDescriptor.getReturnValueDescriptor(); Set<GroupConversionDescriptor> groupConversionDescriptors = returnValueDescriptor.getGroupConversions(); assertTrue( groupConversionDescriptors.size() == 2 ); List<ParameterDescriptor> parameterDescriptors = methodDescriptor.getParameterDescriptors(); assertTrue( parameterDescriptors.size() == 1 ); ParameterDescriptor parameterDescriptor = parameterDescriptors.get( 0 ); groupConversionDescriptors = parameterDescriptor.getGroupConversions(); assertTrue( groupConversionDescriptors.size() == 1 ); }
@Test @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "j") public void testGroupConversionOnReturnValueAndParameter() throws Exception { MethodDescriptor descriptor = TestUtil.getMethodDescriptor( CustomerRepository.class, "findByExample", Customer.class ); assertNotNull( descriptor, "the specified method should be configured in xml" ); ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor(); Set<GroupConversionDescriptor> groupConversionDescriptors = returnValueDescriptor.getGroupConversions(); assertTrue( groupConversionDescriptors.size() == 1 ); GroupConversionDescriptor groupConversionDescriptor = groupConversionDescriptors.iterator().next(); assertEquals( groupConversionDescriptor.getFrom(), Default.class, "Wrong from class for group conversion" ); List<ParameterDescriptor> parameterDescriptors = descriptor.getParameterDescriptors(); assertTrue( parameterDescriptors.size() == 1 ); ParameterDescriptor parameterDescriptor = parameterDescriptors.get( 0 ); groupConversionDescriptors = parameterDescriptor.getGroupConversions(); assertTrue( groupConversionDescriptors.size() == 1 ); groupConversionDescriptor = groupConversionDescriptors.iterator().next(); assertEquals( groupConversionDescriptor.getFrom(), Default.class, "Wrong from class for group conversion" ); } }
@Test @SpecAssertion(section = Sections.CONSTRAINTDECLARATIONVALIDATIONPROCESS_GROUPSEQUENCE_GROUPCONVERSION, id = "d") public void testConvertGroupDefaultFromForMethodReturnValue() { ReturnValueDescriptor descriptor = getMethodDescriptor( BeanService.class, "getBean" ) .getReturnValueDescriptor(); Set<GroupConversionDescriptor> groupConversionDescriptors = descriptor.getGroupConversions(); GroupConversionDescriptor groupConversionDescriptor = getGroupConversionDescriptorByFrom( groupConversionDescriptors, Default.class ); assertEquals( groupConversionDescriptor.getTo(), ComplexChecks.class ); }
assertNotNull( descriptor, "the specified method should be configured in xml" ); ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor(); Set<ConstraintDescriptor<?>> constraintDescriptors = returnValueDescriptor.getConstraintDescriptors(); assertTrue( constraintDescriptors.size() == 1 );
@Test @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "l") public void testIgnoreAnnotationsOnReturnValueParameterAndCrossParameter() { MethodDescriptor descriptor = TestUtil.getMethodDescriptor( IgnoreAnnotations.class, "foobar", String.class, String.class ); CrossParameterDescriptor crossParameterDescriptor = descriptor.getCrossParameterDescriptor(); assertFalse( crossParameterDescriptor.hasConstraints(), "Cross parameter constraints should be ignored." ); ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor(); assertFalse( returnValueDescriptor.hasConstraints(), "Return value constraints should be ignored." ); ParameterDescriptor parameterDescriptor = descriptor.getParameterDescriptors().get( 0 ); assertFalse( parameterDescriptor.hasConstraints(), "First parameter constraints should be ignored." ); parameterDescriptor = descriptor.getParameterDescriptors().get( 1 ); assertTrue( parameterDescriptor.hasConstraints(), "Second parameter constraints should be applied." ); } }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_CASCADABLEDESCRIPTOR, id = "b") @SpecAssertion(section = Sections.CONSTRAINTMETADATA_GROUPCONVERSIONDESCRIPTOR, id = "a") @SpecAssertion(section = Sections.CONSTRAINTMETADATA_GROUPCONVERSIONDESCRIPTOR, id = "b") public void testGetGroupConversionsForMethodReturnValue() { ReturnValueDescriptor returnValueDescriptor = Executables.methodWithGroupConversionOnReturnValue() .getReturnValueDescriptor(); Set<GroupConversionDescriptor> groupConversions = returnValueDescriptor.getGroupConversions(); assertEquals( groupConversions.size(), 2 ); for ( GroupConversionDescriptor groupConversionDescriptor : groupConversions ) { if ( groupConversionDescriptor.getFrom().equals( Default.class ) ) { assertEquals( groupConversionDescriptor.getTo(), BasicChecks.class ); } else if ( groupConversionDescriptor.getFrom().equals( StrictCustomerServiceChecks.class ) ) { assertEquals( groupConversionDescriptor.getTo(), StrictChecks.class ); } else { fail( String.format( "Encountered unexpected group conversion from %s to %s", groupConversionDescriptor.getFrom().getName(), groupConversionDescriptor.getTo().getName() ) ); } } }
@Test @SpecAssertions({ @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "l"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "m"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "n"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "p") }) public void testIgnoreAnnotationsOnMethodLevel() { MethodDescriptor descriptor = TestUtil.getMethodDescriptor( IgnoreAnnotations.class, "foobar", String.class, String.class ); CrossParameterDescriptor crossParameterDescriptor = descriptor.getCrossParameterDescriptor(); assertFalse( crossParameterDescriptor.hasConstraints(), "Cross parameter constraints should be ignored." ); ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor(); assertFalse( returnValueDescriptor.hasConstraints(), "Return value constraints should be ignored." ); assertTrue( returnValueDescriptor.getGroupConversions().isEmpty(), "Group conversions should be ignored" ); ParameterDescriptor parameterDescriptor = descriptor.getParameterDescriptors().get( 0 ); assertFalse( parameterDescriptor.hasConstraints(), "First parameter constraints should be ignored." ); assertTrue( parameterDescriptor.getGroupConversions().isEmpty(), "Group conversions should be ignored" ); parameterDescriptor = descriptor.getParameterDescriptors().get( 1 ); assertTrue( parameterDescriptor.hasConstraints(), "Second parameter constraints should be applied." ); assertEquals( parameterDescriptor.getGroupConversions().size(), 2, "All group conversions should be combined" ); } }
@SpecAssertion(section = Sections.CONSTRAINTMETADATA_CONTAINERDESCRIPTOR, id = "e") public void testGetContainerElementMetaDataForReturnValue() { ReturnValueDescriptor returnValueDescriptor = Executables.returnValueWithCascadedContainerElements().getReturnValueDescriptor();