@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "d") public void testGetReturnValueDescriptorForConstructor() { ConstructorDescriptor descriptor = Executables.returnValueConstrainedConstructor(); assertNotNull( descriptor.getReturnValueDescriptor(), "Return value descriptor should not be null" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_CASCADABLEDESCRIPTOR, id = "b") public void testGetGroupConversionsReturnsEmptySetForMethodReturnValue() { ReturnValueDescriptor returnValueDescriptor = Executables.cascadedReturnValueConstructor() .getReturnValueDescriptor(); Set<GroupConversionDescriptor> groupConversions = returnValueDescriptor.getGroupConversions(); assertNotNull( groupConversions ); assertTrue( groupConversions.isEmpty() ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "d") public void testGetUnconstrainedReturnValueDescriptorForConstructor() { ConstructorDescriptor descriptor = Executables.cascadedParameterConstructor(); assertNotNull( descriptor.getReturnValueDescriptor(), "Return value descriptor should not be null" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_CASCADABLEDESCRIPTOR, id = "a") public void testIsCascadedForConstructorReturnValue() { ReturnValueDescriptor descriptor = Executables.returnValueConstrainedConstructor() .getReturnValueDescriptor(); assertFalse( descriptor.isCascaded(), "Should not be cascaded" ); descriptor = Executables.cascadedReturnValueConstructor().getReturnValueDescriptor(); assertTrue( descriptor.isCascaded(), "Should be cascaded" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_ELEMENTDESCRIPTOR, id = "a") public void testGetElementClassForConstructor() { ReturnValueDescriptor descriptor = Executables.returnValueConstrainedConstructor().getReturnValueDescriptor(); assertEquals( descriptor.getElementClass(), CustomerService.class ); }
@Test @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_GROUPCONVERSIONS, id = "a") @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_GROUPCONVERSIONS, id = "b") public void testGroupConversionsAppliedOnConstructor() throws Exception { ConstructorDescriptor constructorDescriptor = TestUtil.getConstructorDescriptor( Groups.class ); assertNotNull( constructorDescriptor, "the specified constructor should be configured in xml" ); ReturnValueDescriptor returnValueDescriptor = constructorDescriptor.getReturnValueDescriptor(); Set<GroupConversionDescriptor> groupConversionDescriptors = returnValueDescriptor.getGroupConversions(); assertTrue( groupConversionDescriptors.size() == 1 ); }
@Test @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "n") public void testValidAnnotationIsIgnored() throws Exception { ConstructorDescriptor descriptor = TestUtil.getConstructorDescriptor( Cascaded.class, String.class ); assertNotNull( descriptor, "the specified constructor should be configured in xml" ); ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor(); assertFalse( returnValueDescriptor.isCascaded(), "Cascaded validation should disabled" ); ParameterDescriptor parameterDescriptor = descriptor.getParameterDescriptors().get( 0 ); assertFalse( parameterDescriptor.isCascaded(), "Cascaded validation should disabled" ); } }
@Test @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "n") public void testValidaAnnotationIsApplied() throws Exception { ConstructorDescriptor descriptor = TestUtil.getConstructorDescriptor( Cascaded.class, String.class ); assertNotNull( descriptor, "the specified constructor 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_CONSTRUCTORLEVELOVERRIDING, id = "h") public void testCascadingOnReturnValueAndParameter() throws Exception { ConstructorDescriptor descriptor = TestUtil.getConstructorDescriptor( CustomerRepository.class, CustomerRepository.class ); assertNotNull( descriptor, "the specified constructor 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_CONSTRUCTORLEVELOVERRIDING, id = "i") public void testGroupConversionOnReturnValueAndParameter() throws Exception { ConstructorDescriptor descriptor = TestUtil.getConstructorDescriptor( CustomerRepository.class, CustomerRepository.class ); assertNotNull( descriptor, "the specified constructor 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" ); } }
assertNotNull( descriptor, "the specified constructor 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_CONSTRUCTORLEVELOVERRIDING, id = "k") public void testIgnoreAnnotationsOnReturnValueParameterAndCrossParameter() { ConstructorDescriptor descriptor = TestUtil.getConstructorDescriptor( IgnoreAnnotations.class, 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 testGetGroupConversionsForConstructorReturnValue() { ReturnValueDescriptor returnValueDescriptor = Executables.constructorWithGroupConversionOnReturnValue() .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_CONSTRUCTORLEVELOVERRIDING, id = "k"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "l"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "m"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "o") }) public void testIgnoreAnnotationsOnConstructorLevel() { ConstructorDescriptor descriptor = TestUtil.getConstructorDescriptor( IgnoreAnnotations.class, 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" ); } }