ClassCacheMgr { public <T> CFMappingDef<T> initializeCacheForClass(Class<T> clazz) { CFMappingDef<T> cfMapDef = initializeColumnFamilyMapDef(clazz); try { initializePropertiesMapDef(cfMapDef); } catch (IntrospectionException e) { throw new HectorObjectMapperException(e); } catch (InstantiationException e) { throw new HectorObjectMapperException(e); } catch (IllegalAccessException e) { throw new HectorObjectMapperException(e); } checkMappingAndSetDefaults(cfMapDef); if (!cfMapDef.isDerivedEntity()) { cfMapByColFamName.put(cfMapDef.getEffectiveColFamName(), cfMapDef); } cfMapByClazz.put(cfMapDef.getRealClass(), cfMapDef); return cfMapDef; }  CFMappingDef<? super T> findBaseClassViaMappings(CFMappingDef<T> cfMapDef); CFMappingDef<T> getCfMapDef(Class<T> clazz, boolean throwException); CFMappingDef<T> getCfMapDef(String colFamName, boolean throwException); CFMappingDef<T> initializeCacheForClass(Class<T> clazz); Map<String, PropertyDescriptor> getFieldPropertyDescriptorMap(Class<?> clazz); Method findAnnotatedMethod(Class<?> clazz, Class<? extends Annotation> anno);  }
@Test public void testInheritanceOfEntity() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<MyRedTestBean> cfMapDef = cacheMgr.initializeCacheForClass(MyRedTestBean.class); assertEquals(14, cfMapDef.getAllProperties().size()); assertNotNull(cfMapDef.getCfBaseMapDef()); assertEquals(MyRedTestBean.class, cfMapDef.getEffectiveClass()); assertEquals("TestBeanColumnFamily", cfMapDef.getEffectiveColFamName()); assertEquals("myType", cfMapDef.getDiscColumn()); assertEquals(DiscriminatorType.STRING, cfMapDef.getDiscType()); assertEquals("baseId", cfMapDef.getKeyDef().getIdPropertyMap().values().iterator().next() .getPropDesc().getName()); assertEquals( MyRedTestBean.class.getSuperclass(), cfMapDef.getCfSuperMapDef().getRealClass()); assertFalse( cfMapDef.getCfSuperMapDef().isColumnSliceRequired()); }
@Test public void testInheritanceOfNonEntity() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<MyPurpleTestBean> cfMapDef = cacheMgr.initializeCacheForClass(MyPurpleTestBean.class); assertEquals(2, cfMapDef.getAllProperties().size()); assertNull(cfMapDef.getCfBaseMapDef()); assertEquals(MyPurpleTestBean.class, cfMapDef.getEffectiveClass()); }
@Test @Ignore("looks as if this isn't finished - investigate") public void testInheritanceOfEntityWithNoProperties() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); cacheMgr.initializeCacheForClass(MyBlueTestBean.class); }
@Test(expected = HectorObjectMapperException.class) public void testBadPojo() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); cacheMgr.initializeCacheForClass(MyBadTestBean.class); }
@Test(expected = HectorObjectMapperException.class) public void testBadIdGetterSetter() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); cacheMgr.initializeCacheForClass(MyMissingIdSetterBean.class); }
@Test(expected = HectorObjectMapperException.class) public void testDupeEntityColumnFamilyMapping() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); cacheMgr.initializeCacheForClass(MyDupeCF1.class); cacheMgr.initializeCacheForClass(MyDupeCF2.class); }
@Test public void testParsingEntityWithoutAnonymousAddHandler() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<MyTestBeanNoAnonymous> cfMapDef = cacheMgr.initializeCacheForClass(MyTestBeanNoAnonymous.class); assertFalse("mapping should not indicate there is an anonymous handler", cfMapDef.isAnonymousHandlerAvailable()); assertNotNull("should have set the slice column array", cfMapDef.getSliceColumnNameArr()); assertEquals(1, cfMapDef.getSliceColumnNameArr().length); assertEquals("lp1", cfMapDef.getSliceColumnNameArr()[0]); }
@Test public void testParsingInheritedEntityWithoutAnonymousAddHandler() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<Chair> cfMapDef = cacheMgr.initializeCacheForClass(Chair.class); assertFalse("mapping should not indicate there is an anonymous handler", cfMapDef.isAnonymousHandlerAvailable()); assertFalse( "should not be using column slice because of inheritance", cfMapDef.isColumnSliceRequired()); assertNull("should not have set the slice column array because of inheritance", cfMapDef.getSliceColumnNameArr()); }
@Test public void testParsingComplexEntity() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<MyComplexEntity> cfMapDef = cacheMgr.initializeCacheForClass(MyComplexEntity.class); KeyDefinition keyDef = cfMapDef.getKeyDef(); assertEquals(MyCompositePK.class, keyDef.getPkClazz()); assertEquals(2, keyDef.getIdPropertyMap().size()); assertEquals(keyDef.getIdPropertyMap().size(), keyDef.getPropertyDescriptorMap().size()); }
@Ignore("Cannot enable until method annotations are supported by ClassCacheMgr") @Test(expected = HectorObjectMapperException.class) public void testMissingIdAnno() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); cacheMgr.initializeCacheForClass(MyMissingIdAnno.class); }
@Test(expected = HectorObjectMapperException.class) public void testParsingComplexIdFieldMissing() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); cacheMgr.initializeCacheForClass(MyComplexEntityMissingIdField.class); }
@Test(expected = HectorObjectMapperException.class) public void testParsingComplexIdFieldWrong() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); cacheMgr.initializeCacheForClass(MyComplexEntityWrongIdField.class); }
@Test public void testCollectionPropertyHandling() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<CollectionBean> cfMapDef = cacheMgr.initializeCacheForClass(CollectionBean.class); PropertyMappingDefinition md = cfMapDef.getPropMapByPropName("mySet"); assertEquals( Set.class, md.getCollectionType() ); assertEquals( "mySet", md.getColName()); assertNull( "should not be using slice query with List collection", cfMapDef.getSliceColumnNameArr()); }
@Test public void testCollectionWithCustomConverterPropertyHandling() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<CustomConvertedCollectionBean> cfMapDef = cacheMgr.initializeCacheForClass(CustomConvertedCollectionBean.class); PropertyMappingDefinition md = cfMapDef.getPropMapByPropName("mySet"); assertEquals( null, md.getCollectionType() ); assertEquals( "mySet", md.getColName()); assertNotNull( "should be using slice query with custom converted collection", cfMapDef.getSliceColumnNameArr()); }