private <T> void parseInheritanceAnnotation(Inheritance anno, CFMappingDef<T> cfMapDef) { if (InheritanceType.SINGLE_TABLE == anno.strategy()) { cfMapDef.setInheritanceType(InheritanceType.SINGLE_TABLE); } else { throw new RuntimeException("Hector object mapper only supports " + InheritanceType.SINGLE_TABLE + " inheritance at the moment"); } }
@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 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()); } }
public void testValidateDerivedClass() { 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.setCfBaseMapDef(cfBaseMapDef); cfMapDef.setDiscValue("blue"); InheritanceParserValidator val = new InheritanceParserValidator(); try { val.validateAndSetDefaults(null, cfMapDef); } catch (HectorObjectMapperException e) { fail(e.getMessage()); } }
@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"); }