@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "e") public void testAreParametersConstrainedForConstrainedConstructor() { ConstructorDescriptor descriptor = Executables.parameterConstrainedConstructor(); assertTrue( descriptor.hasConstrainedParameters(), "Should be constrained on parameters" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "e") public void testAreParametersConstrainedForParameterlessConstructor() { ConstructorDescriptor descriptor = Executables.returnValueConstrainedConstructor(); assertFalse( descriptor.hasConstrainedParameters(), "Should not be constrained on parameters" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "e") public void testAreParametersConstrainedForCascadedConstructor() { ConstructorDescriptor descriptor = Executables.cascadedParameterConstructor(); assertTrue( descriptor.hasConstrainedParameters(), "Should be constrained on parameters" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "e") public void testAreParametersConstrainedForCrossParameterConstrainedConstructor() { ConstructorDescriptor descriptor = Executables.crossParameterConstrainedConstructor(); assertTrue( descriptor.hasConstrainedParameters(), "Should be constrained on parameters" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "e") public void testAreParametersConstrainedForNotConstrainedConstructor() { ConstructorDescriptor descriptor = Executables.cascadedReturnValueConstructor(); assertFalse( descriptor.hasConstrainedParameters(), "Should not be constrained on parameters" ); }
@Test @SpecAssertions({ @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "a"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "c"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "e") }) public void testXmlConfiguredConstructors() throws Exception { ConstructorDescriptor descriptor = TestUtil.getConstructorDescriptor( CustomerRepository.class ); assertNotNull( descriptor, "the specified constructor should be configured in xml" ); assertTrue( descriptor.hasConstrainedReturnValue() ); descriptor = TestUtil.getConstructorDescriptor( CustomerRepository.class, String.class ); assertNotNull( descriptor, "the specified constructor should be configured in xml" ); assertTrue( descriptor.hasConstrainedParameters() ); descriptor = TestUtil.getConstructorDescriptor( CustomerRepository.class, CustomerRepository.class ); assertNotNull( descriptor, "the specified constructor should be configured in xml" ); assertTrue( descriptor.hasConstrainedParameters() ); }
@Test @SpecAssertions({ @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "a"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "b"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "c") }) public void testVarargsConstructorParameter() throws Exception { ConstructorDescriptor descriptor = TestUtil.getConstructorDescriptor( CustomerRepository.class, String.class, Customer[].class ); assertNotNull( descriptor, "the specified constructor should be configured in xml" ); assertTrue( descriptor.hasConstrainedParameters() ); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @AroundConstruct // TODO: see previous one public Object construct(InvocationContext context) throws Exception { final Constructor ctor = context.getConstructor(); if (!isConstructorValidated(ctor)) { return context.proceed(); } final ConstructorDescriptor constraints = validator.getConstraintsForClass(ctor.getDeclaringClass()) .getConstraintsForConstructor(ctor.getParameterTypes()); if (!DescriptorManager.isConstrained(constraints)) { return context.proceed(); } initExecutableValidator(); if (constraints.hasConstrainedParameters()) { final Set<ConstraintViolation<?>> violations = executableValidator.validateConstructorParameters(ctor, context.getParameters()); if (!violations.isEmpty()) { throw new ConstraintViolationException(violations); } } final Object result = context.proceed(); if (constraints.hasConstrainedReturnValue()) { final Set<ConstraintViolation<?>> violations = executableValidator.validateConstructorReturnValue(ctor, context.getTarget()); if (!violations.isEmpty()) { throw new ConstraintViolationException(violations); } } return result; }
@SuppressWarnings({ "unchecked", "rawtypes" }) @AroundConstruct // TODO: see previous one public Object construct(InvocationContext context) throws Exception { final Constructor ctor = context.getConstructor(); if (!isConstructorValidated(ctor)) { return context.proceed(); } final ConstructorDescriptor constraints = validator.getConstraintsForClass(ctor.getDeclaringClass()) .getConstraintsForConstructor(ctor.getParameterTypes()); if (!DescriptorManager.isConstrained(constraints)) { return context.proceed(); } initExecutableValidator(); if (constraints.hasConstrainedParameters()) { final Set<ConstraintViolation<?>> violations = executableValidator.validateConstructorParameters(ctor, context.getParameters()); if (!violations.isEmpty()) { throw new ConstraintViolationException(violations); } } final Object result = context.proceed(); if (constraints.hasConstrainedReturnValue()) { final Set<ConstraintViolation<?>> violations = executableValidator.validateConstructorReturnValue(ctor, context.getTarget()); if (!violations.isEmpty()) { throw new ConstraintViolationException(violations); } } return result; }