/** Testing validator with an itemmodel which is ok. Expect: nothing. */ @Test public void testValidatorItemModelOK() throws InterceptorException { final AttributeConstraintModel constraint = new AttributeConstraintModel(); constraint.setAnnotation(NotEmpty.class); constraint.setDescriptor(prodModCodeAD); constraint.setType(prodModCT); constraint.setTarget(ProductModel.class); constraint.setQualifier("code"); expect(modelService.getModelTypeClass(ProductModel.class)).andReturn(Product.class); replay(modelService); typeValidator.onValidate(constraint, null); attrValidator.onValidate(constraint, null); verify(modelService); }
/** * Testing preparer, descriptor is set, other attributes filled with dummy data. Expect: * descriptor overwrites all other fields. */ @Test public void testPreparerWithAttributeDescriptorOnly() throws InterceptorException { final AttributeConstraintModel constraint = new AttributeConstraintModel(); constraint.setDescriptor(prodModCodeAD); constraint.setAnnotation(Min.class); constraint.setType(new ComposedTypeModel()); constraint.setTarget(LanguageModel.class); constraint.setQualifier("xxx"); final ProductModel productModel = new ProductModel(); expect(modelService.create(prodModCT.getCode())).andReturn(productModel); modelService.detach(productModel); expectLastCall(); replay(modelService); preparer.onPrepare(constraint, null); verify(modelService); assertEquals(ProductModel.class, constraint.getTarget()); assertEquals(prodModCT, constraint.getType()); assertEquals(Min.class, constraint.getAnnotation()); assertEquals("code", constraint.getQualifier()); }
/** Testing validator where qualifier is only missing. Expect: exception */ @Test public void testValidatorEmptyQualifier() throws InterceptorException { final AttributeConstraintModel constraint = new AttributeConstraintModel(); constraint.setAnnotation(NotEmpty.class); constraint.setDescriptor(prodModCodeAD); constraint.setType(prodModCT); constraint.setTarget(ProductModel.class); expect(modelService.getModelTypeClass(ProductModel.class)).andReturn(Product.class); replay(modelService); typeValidator.onValidate(constraint, null); verify(modelService); try { attrValidator.onValidate(constraint, null); fail("There was no InterceptorException"); } catch (final InterceptorException e) { assertTrue(e.getMessage().contains("is empty!")); } catch (final Exception e) { fail("unexpected exception: " + e); } }