use of jakarta.validation.metadata.ReturnValueDescriptor in project beanvalidation-tck by eclipse-ee4j.
the class IgnoreAnnotationsOnMethodTest method testIgnoreAnnotationsOnMethodLevel.
@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");
}
use of jakarta.validation.metadata.ReturnValueDescriptor in project beanvalidation-tck by eclipse-ee4j.
the class MethodValidationTest method testConstraintOnMethodReturnValueAndParameter.
@Test
@SpecAssertions({ @SpecAssertion(section = Sections.CONSTRAINTMETADATA_CONSTRAINTDESCRIPTOR, id = "a"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "h") })
public void testConstraintOnMethodReturnValueAndParameter() throws Exception {
MethodDescriptor descriptor = TestUtil.getMethodDescriptor(CustomerRepository.class, "notifyCustomer", Customer.class, String.class);
assertNotNull(descriptor, "the specified method should be configured in xml");
ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor();
Set<ConstraintDescriptor<?>> constraintDescriptors = returnValueDescriptor.getConstraintDescriptors();
assertTrue(constraintDescriptors.size() == 1);
ConstraintDescriptor<?> constraintDescriptor = constraintDescriptors.iterator().next();
assertEquals(constraintDescriptor.getAnnotation().annotationType(), NotNull.class, "Unexpected constraint type");
List<ParameterDescriptor> parameterDescriptors = descriptor.getParameterDescriptors();
assertTrue(parameterDescriptors.size() == 2);
ParameterDescriptor parameterDescriptor = parameterDescriptors.get(0);
constraintDescriptors = parameterDescriptor.getConstraintDescriptors();
assertTrue(constraintDescriptors.size() == 1);
constraintDescriptor = constraintDescriptors.iterator().next();
assertEquals(constraintDescriptor.getAnnotation().annotationType(), NotNull.class, "Unexpected constraint type");
}
use of jakarta.validation.metadata.ReturnValueDescriptor in project beanvalidation-tck by eclipse-ee4j.
the class MethodValidationTest method testGroupConversionOnReturnValueAndParameter.
@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");
}
use of jakarta.validation.metadata.ReturnValueDescriptor in project beanvalidation-tck by eclipse-ee4j.
the class MethodValidationTest method testCascadingOnReturnValueAndParameter.
@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");
}
use of jakarta.validation.metadata.ReturnValueDescriptor in project beanvalidation-tck by eclipse-ee4j.
the class IgnoreAnnotationsInConstructorConfigurationTest method testIgnoreAnnotationsOnReturnValueParameterAndCrossParameter.
@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.");
}
Aggregations