InheritanceParserValidator implements ParserValidator { @Override public <T> void validateAndSetDefaults(ClassCacheMgr cacheMgr, CFMappingDef<T> cfMapDef) { if (cfMapDef.isBaseEntity()) { validateBaseClassInheritance(cfMapDef); } else if (cfMapDef.isPersistableDerivedEntity()) { validateDerivedClassInheritance(cfMapDef); } else if (!cfMapDef.isNonPersistableDerivedEntity()) { if (null != cacheMgr.findBaseClassViaMappings(cfMapDef)) throw new HectorObjectMapperException("@" + Inheritance.class.getSimpleName() + " found in class hierarchy, but no @" + DiscriminatorValue.class.getSimpleName() + " - quitting"); } }  @Override void parse(ClassCacheMgr cacheMgr, Annotation anno, CFMappingDef<T> cfMapDef); @Override void validateAndSetDefaults(ClassCacheMgr cacheMgr, CFMappingDef<T> cfMapDef);  }
@Test(expected = HectorObjectMapperException.class) public void testValidateInvalidInheritanceType() { CFMappingDef<MyTestBean> cfMapDef = new CFMappingDef<MyTestBean>(MyTestBean.class); cfMapDef.setInheritanceType(InheritanceType.JOINED); InheritanceParserValidator val = new InheritanceParserValidator(); val.validateAndSetDefaults(null, cfMapDef); fail("should have found invalid inheritance type"); }
@Test(expected = HectorObjectMapperException.class) public void testValidateMissingDiscriminatorColumn() { CFMappingDef<MyTestBean> cfMapDef = new CFMappingDef<MyTestBean>(MyTestBean.class); cfMapDef.setInheritanceType(InheritanceType.SINGLE_TABLE); InheritanceParserValidator val = new InheritanceParserValidator(); val.validateAndSetDefaults(null, cfMapDef); fail("should have reported missing discriminator column annotation"); }
@Test(expected = HectorObjectMapperException.class) public void testValidateMissingDiscriminatorValue() { CFMappingDef<MyTestBean> cfMapDef = new CFMappingDef<MyTestBean>(MyTestBean.class); cfMapDef.setInheritanceType(InheritanceType.SINGLE_TABLE); cfMapDef.setDiscColumn("myType"); InheritanceParserValidator val = new InheritanceParserValidator(); val.validateAndSetDefaults(null, cfMapDef); fail("should have reported missing discriminator value annotation"); }
@Test(expected = HectorObjectMapperException.class) public void testValidateDerivedClassMissingDiscriminatorValue() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<MyTestBean> cfBaseMapDef = new CFMappingDef<MyTestBean>( MyTestBean.class); cfBaseMapDef.setInheritanceType(InheritanceType.SINGLE_TABLE); cfBaseMapDef.setDiscColumn("myType"); CFMappingDef<MyBlueTestBean> cfMapDef = new CFMappingDef<MyBlueTestBean>( MyBlueTestBean.class); cfMapDef.setCfSuperMapDef(cfBaseMapDef); cfMapDef.setCfBaseMapDef(cfBaseMapDef); InheritanceParserValidator val = new InheritanceParserValidator(); val.validateAndSetDefaults(cacheMgr, cfMapDef); fail("should have reported missing discriminator value annotation"); }
@Test public void testValidate() { CFMappingDef<MyTestBean> cfMapDef = new CFMappingDef<MyTestBean>(MyTestBean.class); cfMapDef.setInheritanceType(InheritanceType.SINGLE_TABLE); cfMapDef.setDiscColumn("myType"); cfMapDef.setDiscValue("blue"); InheritanceParserValidator val = new InheritanceParserValidator(); try { val.validateAndSetDefaults(null, cfMapDef); } catch (HectorObjectMapperException e) { fail(e.getMessage()); } }