DefaultTypeCache implements TypeCache { @Override public IDataType get(String typeName) throws AtlasException { return types_.get(typeName); }  @Override boolean has(String typeName); @Override boolean has(TypeCategory typeCategory, String typeName); @Override IDataType get(String typeName); @Override IDataType get(TypeCategory typeCategory, String typeName); @Override Collection<String> getTypeNames(Map<TYPE_FILTER, String> filterMap); @Override Collection<String> getAllTypeNames(); @Override void put(IDataType type); @Override void putAll(Collection<IDataType> types); @Override void remove(String typeName); @Override void remove(TypeCategory typeCategory, String typeName); @Override void clear(); @Override IDataType onTypeFault(String typeName);  }
@Test public void testCacheGetType() throws Exception { IDataType custType = cache.get(CLASSTYPE_CUSTOMER); verifyType(custType, CLASSTYPE_CUSTOMER, ClassType.class); IDataType addrType = cache.get(STRUCTTYPE_ADDRESS); verifyType(addrType, STRUCTTYPE_ADDRESS, StructType.class); IDataType privTrait = cache.get(TRAITTYPE_PRIVILEGED); verifyType(privTrait, TRAITTYPE_PRIVILEGED, TraitType.class); IDataType shippingEnum = cache.get(ENUMTYPE_SHIPPING); verifyType(shippingEnum, ENUMTYPE_SHIPPING, EnumType.class); assertNull(cache.get(UNKNOWN_TYPE)); }
@Test public void testCacheGetTypeByCategory() throws Exception { IDataType custType = cache.get(TypeCategory.CLASS, CLASSTYPE_CUSTOMER); verifyType(custType, CLASSTYPE_CUSTOMER, ClassType.class); IDataType addrType = cache.get(TypeCategory.STRUCT, STRUCTTYPE_ADDRESS); verifyType(addrType, STRUCTTYPE_ADDRESS, StructType.class); IDataType privTrait = cache.get(TypeCategory.TRAIT, TRAITTYPE_PRIVILEGED); verifyType(privTrait, TRAITTYPE_PRIVILEGED, TraitType.class); IDataType shippingEnum = cache.get(TypeCategory.ENUM, ENUMTYPE_SHIPPING); verifyType(shippingEnum, ENUMTYPE_SHIPPING, EnumType.class); assertNull(cache.get(UNKNOWN_TYPE)); }
@Test public void testCacheGetTypeNamesByCategory() throws Exception { List<String> classTypes = new ArrayList(getTypeNamesByCategory(TypeCategory.CLASS)); final int EXPECTED_CLASSTYPE_COUNT = 1; assertEquals(classTypes.size(), EXPECTED_CLASSTYPE_COUNT); assertEquals(CLASSTYPE_CUSTOMER, classTypes.get(0)); List<String> structTypes = new ArrayList(getTypeNamesByCategory(TypeCategory.STRUCT)); final int EXPECTED_STRUCTTYPE_COUNT = 1; assertEquals(structTypes.size(), EXPECTED_STRUCTTYPE_COUNT); assertEquals(STRUCTTYPE_ADDRESS, structTypes.get(0)); List<String> traitTypes = new ArrayList(getTypeNamesByCategory(TypeCategory.TRAIT)); final int EXPECTED_TRAITTYPE_COUNT = 1; assertEquals(traitTypes.size(), EXPECTED_TRAITTYPE_COUNT); assertEquals(TRAITTYPE_PRIVILEGED, traitTypes.get(0)); List<String> enumTypes = new ArrayList(getTypeNamesByCategory(TypeCategory.ENUM)); final int EXPECTED_ENUMTYPE_COUNT = 1; assertEquals(enumTypes.size(), EXPECTED_ENUMTYPE_COUNT); assertEquals(ENUMTYPE_SHIPPING, enumTypes.get(0)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testGetTypeWithNullCategory() throws Exception { cache.get(null, CLASSTYPE_CUSTOMER); fail("Null TypeCategory should be not allowed in 'get'"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testGetTypeWithInvalidCategory() throws Exception { cache.get(TypeCategory.PRIMITIVE, DataTypes.BOOLEAN_TYPE.getName()); fail("TypeCategory should only be one of TypeCategory.CLASS | ENUM | STRUCT | TRAIT in 'get'"); }