Commit c9e58e0a by Suma Shivaprasad

ATLAS-1233 UnitTests for the TypeDefStores (apoorvnaik via sumasai)

parent 0b85d5a0
......@@ -67,4 +67,21 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
......@@ -17,11 +17,22 @@
*/
package org.apache.atlas.type;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.commons.lang.StringUtils;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -91,5 +102,94 @@ public class AtlasTypeUtil {
referencedTypeNames.add(typeName);
}
}
}
public static AtlasAttributeDef createOptionalAttrDef(String name, AtlasType dataType) {
return new AtlasAttributeDef(name, dataType.getTypeName(), true,
Cardinality.SINGLE, 0, 1,
true, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
}
public static AtlasAttributeDef createOptionalAttrDef(String name, String dataType) {
return new AtlasAttributeDef(name, dataType, true,
Cardinality.SINGLE, 0, 1,
true, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
}
public static AtlasAttributeDef createRequiredAttrDef(String name, String dataType) {
return new AtlasAttributeDef(name, dataType, false,
Cardinality.SINGLE, 1, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
}
public static AtlasAttributeDef createUniqueRequiredAttrDef(String name, AtlasType dataType) {
return new AtlasAttributeDef(name, dataType.getTypeName(), false,
Cardinality.SINGLE, 1, 1,
true, true,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
}
public static AtlasAttributeDef createUniqueRequiredAttrDef(String name, String typeName) {
return new AtlasAttributeDef(name, typeName, false,
Cardinality.SINGLE, 1, 1,
true, true,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
}
public static AtlasAttributeDef createRequiredAttrDef(String name, AtlasType dataType) {
return new AtlasAttributeDef(name, dataType.getTypeName(), false,
Cardinality.SINGLE, 1, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
}
public static AtlasEnumDef createEnumTypeDef(String name, String description, AtlasEnumElementDef... enumValues) {
return new AtlasEnumDef(name, description, "1.0", Arrays.asList(enumValues));
}
public static AtlasClassificationDef createTraitTypeDef(String name, ImmutableSet<String> superTypes, AtlasAttributeDef... attrDefs) {
return createTraitTypeDef(name, null, superTypes, attrDefs);
}
public static AtlasClassificationDef createTraitTypeDef(String name, String description, ImmutableSet<String> superTypes, AtlasAttributeDef... attrDefs) {
return createTraitTypeDef(name, description, "1.0", superTypes, attrDefs);
}
public static AtlasClassificationDef createTraitTypeDef(String name, String description, String version, ImmutableSet<String> superTypes, AtlasAttributeDef... attrDefs) {
return new AtlasClassificationDef(name, description, "1.0", Arrays.asList(attrDefs), superTypes);
}
public static AtlasStructDef createStructTypeDef(String name, AtlasAttributeDef... attrDefs) {
return createStructTypeDef(name, null, attrDefs);
}
public static AtlasStructDef createStructTypeDef(String name, String description, AtlasAttributeDef... attrDefs) {
return new AtlasStructDef(name, description, "1.0", Arrays.asList(attrDefs));
}
public static AtlasEntityDef createClassTypeDef(String name,
ImmutableSet<String> superTypes, AtlasAttributeDef... attrDefs) {
return createClassTypeDef(name, null, "1.0", superTypes, attrDefs);
}
public static AtlasEntityDef createClassTypeDef(String name, String description,
ImmutableSet<String> superTypes, AtlasAttributeDef... attrDefs) {
return createClassTypeDef(name, description, "1.0", superTypes, attrDefs);
}
public static AtlasEntityDef createClassTypeDef(String name, String description, String version,
ImmutableSet<String> superTypes, AtlasAttributeDef... attrDefs) {
return new AtlasEntityDef(name, description, "1.0", Arrays.asList(attrDefs), superTypes);
}
public static AtlasTypesDef getTypesDef(List<AtlasEnumDef> enums,
List<AtlasStructDef> structs,
List<AtlasClassificationDef> traits,
List<AtlasEntityDef> classes) {
return new AtlasTypesDef(enums, structs, traits, classes);
}
}
......@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES:
ATLAS-1233 UnitTests for the TypeDefStores (apoorvnaik via sumasai)
ATLAS-1240 Adding Change listeners to react on changes in TypesDef (apoorvnaik via sumasai)
ATLAS-1239 when stopping Atlas on the command line it should explicitly say when it has stopped (ayubkhan via sumasai)
ATLAS-1253 Extract error codes into AtlasErrorCode Enum (apoorvnaik via sumasai)
......
......@@ -165,6 +165,13 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.atlas</groupId>
<artifactId>atlas-intg</artifactId>
<type>test-jar</type>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
......@@ -57,18 +57,23 @@ public class TypeDefSorter {
}
processed.add(type);
Set<String> superTypeNames = new HashSet<>();
try {
AtlasClassificationDef classificationDef = AtlasClassificationDef.class.cast(type);
superTypeNames.addAll(classificationDef.getSuperTypes());
} catch (ClassCastException ex) {
LOG.warn("Casting to ClassificationDef failed");
if (type.getClass().equals(AtlasClassificationDef.class)) {
try {
AtlasClassificationDef classificationDef = AtlasClassificationDef.class.cast(type);
superTypeNames.addAll(classificationDef.getSuperTypes());
} catch (ClassCastException ex) {
LOG.warn("Casting to ClassificationDef failed");
}
}
try {
AtlasEntityDef entityDef = AtlasEntityDef.class.cast(type);
superTypeNames.addAll(entityDef.getSuperTypes());
} catch (ClassCastException ex) {
LOG.warn("Casting to AtlasEntityDef failed");
if (type.getClass().equals(AtlasEntityDef.class)) {
try {
AtlasEntityDef entityDef = AtlasEntityDef.class.cast(type);
superTypeNames.addAll(entityDef.getSuperTypes());
} catch (ClassCastException ex) {
LOG.warn("Casting to AtlasEntityDef failed");
}
}
for (String superTypeName : superTypeNames) {
// Recursively add any supertypes first to the result.
T superType = typesByName.get(superTypeName);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment