@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "f") public void testIsReturnValueConstrainedForCascadedConstructor() { ConstructorDescriptor descriptor = Executables.cascadedReturnValueConstructor(); assertTrue( descriptor.hasConstrainedReturnValue(), "Should be constrained on return value" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "f") public void testIsReturnValueConstrainedForNotConstrainedConstructor() { ConstructorDescriptor descriptor = Executables.cascadedParameterConstructor(); assertFalse( descriptor.hasConstrainedReturnValue(), "Should not be constrained on return value" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "f") public void testIsReturnValueConstrainedForConstrainedConstructor() { ConstructorDescriptor descriptor = Executables.returnValueConstrainedConstructor(); assertTrue( descriptor.hasConstrainedReturnValue(), "Should be constrained on return value" ); }
@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() ); }
@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; }