Commit c9e58e0a by Suma Shivaprasad

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

parent 0b85d5a0
...@@ -67,4 +67,21 @@ ...@@ -67,4 +67,21 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </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> </project>
...@@ -17,11 +17,22 @@ ...@@ -17,11 +17,22 @@
*/ */
package org.apache.atlas.type; package org.apache.atlas.type;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef; 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 org.apache.commons.lang.StringUtils;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -91,5 +102,94 @@ public class AtlasTypeUtil { ...@@ -91,5 +102,94 @@ public class AtlasTypeUtil {
referencedTypeNames.add(typeName); 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);
} }
} }
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.model.instance.AtlasEntity;
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.AtlasTypesDef;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.commons.lang.RandomStringUtils;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.apache.atlas.type.AtlasTypeUtil.createStructTypeDef;
/**
* Test utility class.
*/
public final class TestUtilsV2 {
public static final long TEST_DATE_IN_LONG = 1418265358440L;
private TestUtilsV2() {
}
/**
* Class Hierarchy is:
* Department(name : String, employees : Array[Person])
* Person(name : String, department : Department, manager : Manager)
* Manager(subordinates : Array[Person]) extends Person
* <p/>
* Persons can have SecurityClearance(level : Int) clearance.
*/
public static AtlasTypesDef defineDeptEmployeeTypes() {
String _description = "_description";
AtlasEnumDef orgLevelEnum =
new AtlasEnumDef("OrgLevel", "OrgLevel"+_description, "1.0",
Arrays.asList(
new AtlasEnumElementDef("L1", "Element"+_description, 1),
new AtlasEnumElementDef("L1", "Element"+_description, 2)
));
AtlasStructDef addressDetails =
createStructTypeDef("Address", "Address"+_description,
AtlasTypeUtil.createRequiredAttrDef("street", "string"),
AtlasTypeUtil.createRequiredAttrDef("city", "string"));
AtlasEntityDef deptTypeDef =
AtlasTypeUtil.createClassTypeDef(DEPARTMENT_TYPE, "Department"+_description, ImmutableSet.<String>of(),
AtlasTypeUtil.createRequiredAttrDef("name", "string"),
new AtlasAttributeDef("employees", String.format("array<%s>", "Person"), true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()));
AtlasEntityDef personTypeDef = AtlasTypeUtil.createClassTypeDef("Person", "Person"+_description, ImmutableSet.<String>of(),
AtlasTypeUtil.createRequiredAttrDef("name", "string"),
AtlasTypeUtil.createOptionalAttrDef("orgLevel", "OrgLevel"),
AtlasTypeUtil.createOptionalAttrDef("address", "Address"),
new AtlasAttributeDef("department", "Department", false,
AtlasAttributeDef.Cardinality.SINGLE, 1, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("manager", "Person", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("mentor", "Person", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
AtlasTypeUtil.createOptionalAttrDef("birthday", "date"),
AtlasTypeUtil.createOptionalAttrDef("hasPets", "boolean"),
AtlasTypeUtil.createOptionalAttrDef("numberOfCars", "byte"),
AtlasTypeUtil.createOptionalAttrDef("houseNumber", "short"),
AtlasTypeUtil.createOptionalAttrDef("carMileage", "int"),
AtlasTypeUtil.createOptionalAttrDef("shares", "long"),
AtlasTypeUtil.createOptionalAttrDef("salary", "double"),
AtlasTypeUtil.createOptionalAttrDef("age", "float"),
AtlasTypeUtil.createOptionalAttrDef("numberOfStarsEstimate", "biginteger"),
AtlasTypeUtil.createOptionalAttrDef("approximationOfPi", "bigdecimal")
);
AtlasEntityDef managerTypeDef = AtlasTypeUtil.createClassTypeDef("Manager", "Manager"+_description, ImmutableSet.of("Person"),
new AtlasAttributeDef("subordinates", String.format("array<%s>", "Person"), false, AtlasAttributeDef.Cardinality.SET,
1, 10, false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()));
AtlasClassificationDef securityClearanceTypeDef =
AtlasTypeUtil.createTraitTypeDef("SecurityClearance", "SecurityClearance"+_description, ImmutableSet.<String>of(),
AtlasTypeUtil.createRequiredAttrDef("level", "int"));
return new AtlasTypesDef(ImmutableList.of(orgLevelEnum), ImmutableList.of(addressDetails),
ImmutableList.of(securityClearanceTypeDef),
ImmutableList.of(deptTypeDef, personTypeDef, managerTypeDef));
}
public static AtlasTypesDef defineValidUpdatedDeptEmployeeTypes() {
String _description = "_description_updated";
AtlasEnumDef orgLevelEnum =
new AtlasEnumDef("OrgLevel", "OrgLevel"+_description, "1.0",
Arrays.asList(
new AtlasEnumElementDef("L1", "Element"+ _description, 1),
new AtlasEnumElementDef("L1", "Element"+ _description, 2)
));
AtlasStructDef addressDetails =
createStructTypeDef("Address", "Address"+_description,
AtlasTypeUtil.createRequiredAttrDef("street", "string"),
AtlasTypeUtil.createRequiredAttrDef("city", "string"),
AtlasTypeUtil.createOptionalAttrDef("zip", "int"));
AtlasEntityDef deptTypeDef =
AtlasTypeUtil.createClassTypeDef(DEPARTMENT_TYPE, "Department"+_description, ImmutableSet.<String>of(),
AtlasTypeUtil.createRequiredAttrDef("name", "string"),
AtlasTypeUtil.createOptionalAttrDef("dep-code", "string"),
new AtlasAttributeDef("employees", String.format("array<%s>", "Person"), true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()));
AtlasEntityDef personTypeDef = AtlasTypeUtil.createClassTypeDef("Person", "Person"+_description, ImmutableSet.<String>of(),
AtlasTypeUtil.createRequiredAttrDef("name", "string"),
AtlasTypeUtil.createOptionalAttrDef("emp-code", "string"),
AtlasTypeUtil.createOptionalAttrDef("orgLevel", "OrgLevel"),
AtlasTypeUtil.createOptionalAttrDef("address", "Address"),
new AtlasAttributeDef("department", "Department", false,
AtlasAttributeDef.Cardinality.SINGLE, 1, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("manager", "Person", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("mentor", "Person", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
AtlasTypeUtil.createOptionalAttrDef("birthday", "date"),
AtlasTypeUtil.createOptionalAttrDef("hasPets", "boolean"),
AtlasTypeUtil.createOptionalAttrDef("numberOfCars", "byte"),
AtlasTypeUtil.createOptionalAttrDef("houseNumber", "short"),
AtlasTypeUtil.createOptionalAttrDef("carMileage", "int"),
AtlasTypeUtil.createOptionalAttrDef("shares", "long"),
AtlasTypeUtil.createOptionalAttrDef("salary", "double"),
AtlasTypeUtil.createOptionalAttrDef("age", "float"),
AtlasTypeUtil.createOptionalAttrDef("numberOfStarsEstimate", "biginteger"),
AtlasTypeUtil.createOptionalAttrDef("approximationOfPi", "bigdecimal")
);
AtlasEntityDef managerTypeDef = AtlasTypeUtil.createClassTypeDef("Manager", "Manager"+_description, ImmutableSet.of("Person"),
new AtlasAttributeDef("subordinates", String.format("array<%s>", "Person"), false, AtlasAttributeDef.Cardinality.SET,
1, 10, false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()));
AtlasClassificationDef securityClearanceTypeDef =
AtlasTypeUtil.createTraitTypeDef("SecurityClearance", "SecurityClearance"+_description, ImmutableSet.<String>of(),
AtlasTypeUtil.createRequiredAttrDef("level", "int"));
return new AtlasTypesDef(ImmutableList.of(orgLevelEnum),
ImmutableList.of(addressDetails),
ImmutableList.of(securityClearanceTypeDef),
ImmutableList.of(deptTypeDef, personTypeDef, managerTypeDef));
}
public static AtlasTypesDef defineInvalidUpdatedDeptEmployeeTypes() {
String _description = "_description_updated";
// Test ordinal changes
AtlasEnumDef orgLevelEnum =
new AtlasEnumDef("OrgLevel", "OrgLevel"+_description, "1.0",
Arrays.asList(
new AtlasEnumElementDef("L2", "Element"+ _description, 1),
new AtlasEnumElementDef("L1", "Element"+ _description, 2),
new AtlasEnumElementDef("L3", "Element"+ _description, 3)
));
AtlasStructDef addressDetails =
createStructTypeDef("Address", "Address"+_description,
AtlasTypeUtil.createRequiredAttrDef("street", "string"),
AtlasTypeUtil.createRequiredAttrDef("city", "string"),
AtlasTypeUtil.createRequiredAttrDef("zip", "int"));
AtlasEntityDef deptTypeDef =
AtlasTypeUtil.createClassTypeDef(DEPARTMENT_TYPE, "Department"+_description, ImmutableSet.<String>of(),
AtlasTypeUtil.createRequiredAttrDef("name", "string"),
AtlasTypeUtil.createRequiredAttrDef("dep-code", "string"),
new AtlasAttributeDef("employees", String.format("array<%s>", "Person"), true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()));
AtlasEntityDef personTypeDef = AtlasTypeUtil.createClassTypeDef("Person", "Person"+_description, ImmutableSet.<String>of(),
AtlasTypeUtil.createRequiredAttrDef("name", "string"),
AtlasTypeUtil.createRequiredAttrDef("emp-code", "string"),
AtlasTypeUtil.createOptionalAttrDef("orgLevel", "OrgLevel"),
AtlasTypeUtil.createOptionalAttrDef("address", "Address"),
new AtlasAttributeDef("department", "Department", false,
AtlasAttributeDef.Cardinality.SINGLE, 1, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("manager", "Person", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("mentor", "Person", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
AtlasTypeUtil.createOptionalAttrDef("birthday", "date"),
AtlasTypeUtil.createOptionalAttrDef("hasPets", "boolean"),
AtlasTypeUtil.createOptionalAttrDef("numberOfCars", "byte"),
AtlasTypeUtil.createOptionalAttrDef("houseNumber", "short"),
AtlasTypeUtil.createOptionalAttrDef("carMileage", "int"),
AtlasTypeUtil.createOptionalAttrDef("shares", "long"),
AtlasTypeUtil.createOptionalAttrDef("salary", "double"),
AtlasTypeUtil.createRequiredAttrDef("age", "float"),
AtlasTypeUtil.createOptionalAttrDef("numberOfStarsEstimate", "biginteger"),
AtlasTypeUtil.createOptionalAttrDef("approximationOfPi", "bigdecimal")
);
return new AtlasTypesDef(ImmutableList.of(orgLevelEnum),
ImmutableList.of(addressDetails),
ImmutableList.<AtlasClassificationDef>of(),
ImmutableList.of(deptTypeDef, personTypeDef));
}
public static final String DEPARTMENT_TYPE = "Department";
public static final String PERSON_TYPE = "Person";
public static AtlasEntity createDeptEg1() {
AtlasEntity hrDept = new AtlasEntity(DEPARTMENT_TYPE);
AtlasEntity john = new AtlasEntity(PERSON_TYPE);
// AtlasEntity jane = new AtlasEntity("Manager", "SecurityClearance");
AtlasEntity jane = new AtlasEntity("Manager");
AtlasEntity johnAddr = new AtlasEntity("Address");
AtlasEntity janeAddr = new AtlasEntity("Address");
AtlasEntity julius = new AtlasEntity("Manager");
AtlasEntity juliusAddr = new AtlasEntity("Address");
AtlasEntity max = new AtlasEntity("Person");
AtlasEntity maxAddr = new AtlasEntity("Address");
hrDept.setAttribute("name", "hr");
john.setAttribute("name", "John");
john.setAttribute("department", hrDept);
johnAddr.setAttribute("street", "Stewart Drive");
johnAddr.setAttribute("city", "Sunnyvale");
john.setAttribute("address", johnAddr);
john.setAttribute("birthday",new Date(1950, 5, 15));
john.setAttribute("hasPets", true);
john.setAttribute("numberOfCars", 1);
john.setAttribute("houseNumber", 153);
john.setAttribute("carMileage", 13364);
john.setAttribute("shares", 15000);
john.setAttribute("salary", 123345.678);
john.setAttribute("age", 50);
john.setAttribute("numberOfStarsEstimate", new BigInteger("1000000000000000000000"));
john.setAttribute("approximationOfPi", new BigDecimal("3.141592653589793238462643383279502884197169399375105820974944592307816406286"));
jane.setAttribute("name", "Jane");
jane.setAttribute("department", hrDept);
janeAddr.setAttribute("street", "Great America Parkway");
janeAddr.setAttribute("city", "Santa Clara");
jane.setAttribute("address", janeAddr);
janeAddr.setAttribute("street", "Great America Parkway");
julius.setAttribute("name", "Julius");
julius.setAttribute("department", hrDept);
juliusAddr.setAttribute("street", "Madison Ave");
juliusAddr.setAttribute("city", "Newtonville");
julius.setAttribute("address", juliusAddr);
julius.setAttribute("subordinates", ImmutableList.of());
max.setAttribute("name", "Max");
max.setAttribute("department", hrDept);
maxAddr.setAttribute("street", "Ripley St");
maxAddr.setAttribute("city", "Newton");
max.setAttribute("address", maxAddr);
max.setAttribute("manager", jane);
max.setAttribute("mentor", julius);
max.setAttribute("birthday",new Date(1979, 3, 15));
max.setAttribute("hasPets", true);
max.setAttribute("age", 36);
max.setAttribute("numberOfCars", 2);
max.setAttribute("houseNumber", 17);
max.setAttribute("carMileage", 13);
max.setAttribute("shares", Long.MAX_VALUE);
max.setAttribute("salary", Double.MAX_VALUE);
max.setAttribute("numberOfStarsEstimate", new BigInteger("1000000000000000000000000000000"));
max.setAttribute("approximationOfPi", new BigDecimal("3.1415926535897932"));
john.setAttribute("manager", jane);
john.setAttribute("mentor", max);
hrDept.setAttribute("employees", ImmutableList.of(john, jane, julius, max));
jane.setAttribute("subordinates", ImmutableList.of(john, max));
Map<String, Integer> secClearanceLevelMap = new HashMap<>();
secClearanceLevelMap.put("level", 1);
jane.setAttribute("SecurityClearance", secClearanceLevelMap);
return hrDept;
}
public static final String DATABASE_TYPE = "hive_database";
public static final String DATABASE_NAME = "foo";
public static final String TABLE_TYPE = "hive_table";
public static final String PROCESS_TYPE = "hive_process";
public static final String COLUMN_TYPE = "column_type";
public static final String TABLE_NAME = "bar";
public static final String CLASSIFICATION = "classification";
public static final String PII = "PII";
public static final String SUPER_TYPE_NAME = "Base";
public static final String STORAGE_DESC_TYPE = "hive_storagedesc";
public static final String PARTITION_STRUCT_TYPE = "partition_struct_type";
public static final String PARTITION_CLASS_TYPE = "partition_class_type";
public static final String SERDE_TYPE = "serdeType";
public static final String COLUMNS_MAP = "columnsMap";
public static final String COLUMNS_ATTR_NAME = "columns";
public static final String NAME = "name";
public static AtlasTypesDef simpleType(){
AtlasEntityDef superTypeDefinition =
AtlasTypeUtil.createClassTypeDef("h_type", ImmutableSet.<String>of(),
AtlasTypeUtil.createOptionalAttrDef("attr", "string"));
AtlasStructDef structTypeDefinition = new AtlasStructDef("s_type", "structType", "1.0",
Arrays.asList(AtlasTypeUtil.createRequiredAttrDef("name", "string")));
AtlasClassificationDef traitTypeDefinition =
AtlasTypeUtil.createTraitTypeDef("t_type", "traitType", ImmutableSet.<String>of());
AtlasEnumDef enumTypeDefinition = new AtlasEnumDef("e_type", "enumType", "1.0",
Arrays.asList(new AtlasEnumElementDef("ONE", "Element Description", 1)));
return AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), ImmutableList.of(structTypeDefinition),
ImmutableList.of(traitTypeDefinition), ImmutableList.of(superTypeDefinition));
}
public static AtlasTypesDef simpleTypeUpdated(){
AtlasEntityDef superTypeDefinition =
AtlasTypeUtil.createClassTypeDef("h_type", ImmutableSet.<String>of(),
AtlasTypeUtil.createOptionalAttrDef("attr", "string"));
AtlasEntityDef newSuperTypeDefinition =
AtlasTypeUtil.createClassTypeDef("new_h_type", ImmutableSet.<String>of(),
AtlasTypeUtil.createOptionalAttrDef("attr", "string"));
AtlasStructDef structTypeDefinition = new AtlasStructDef("s_type", "structType", "1.0",
Arrays.asList(AtlasTypeUtil.createRequiredAttrDef("name", "string")));
AtlasClassificationDef traitTypeDefinition =
AtlasTypeUtil.createTraitTypeDef("t_type", "traitType", ImmutableSet.<String>of());
AtlasEnumDef enumTypeDefinition = new AtlasEnumDef("e_type", "enumType",
Arrays.asList(new AtlasEnumElementDef("ONE", "Element Description", 1)));
return AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), ImmutableList.of(structTypeDefinition),
ImmutableList.of(traitTypeDefinition), ImmutableList.of(superTypeDefinition, newSuperTypeDefinition));
}
public static AtlasTypesDef simpleTypeUpdatedDiff() {
AtlasEntityDef newSuperTypeDefinition =
AtlasTypeUtil.createClassTypeDef("new_h_type", ImmutableSet.<String>of(),
AtlasTypeUtil.createOptionalAttrDef("attr", "string"));
return AtlasTypeUtil.getTypesDef(ImmutableList.<AtlasEnumDef>of(),
ImmutableList.<AtlasStructDef>of(),
ImmutableList.<AtlasClassificationDef>of(),
ImmutableList.of(newSuperTypeDefinition));
}
public static AtlasTypesDef defineHiveTypes() {
String _description = "_description";
AtlasEntityDef superTypeDefinition =
AtlasTypeUtil.createClassTypeDef(SUPER_TYPE_NAME, "SuperType_description", ImmutableSet.<String>of(),
AtlasTypeUtil.createOptionalAttrDef("namespace", "string"),
AtlasTypeUtil.createOptionalAttrDef("cluster", "string"),
AtlasTypeUtil.createOptionalAttrDef("colo", "string"));
AtlasEntityDef databaseTypeDefinition =
AtlasTypeUtil.createClassTypeDef(DATABASE_TYPE, DATABASE_TYPE + _description,ImmutableSet.of(SUPER_TYPE_NAME),
AtlasTypeUtil.createUniqueRequiredAttrDef(NAME, "string"),
AtlasTypeUtil.createOptionalAttrDef("created", "string"),
AtlasTypeUtil.createRequiredAttrDef("description", "string"));
AtlasStructDef structTypeDefinition = new AtlasStructDef("serdeType", "serdeType" + _description, "1.0",
Arrays.asList(
AtlasTypeUtil.createRequiredAttrDef("name", "string"),
AtlasTypeUtil.createRequiredAttrDef("serde", "string"),
AtlasTypeUtil.createOptionalAttrDef("description", "string")));
AtlasEnumElementDef values[] = {
new AtlasEnumElementDef("MANAGED", "Element Description", 1),
new AtlasEnumElementDef("EXTERNAL", "Element Description", 2)};
AtlasEnumDef enumTypeDefinition = new AtlasEnumDef("tableType", "tableType" + _description, "1.0", Arrays.asList(values));
AtlasEntityDef columnsDefinition =
AtlasTypeUtil.createClassTypeDef(COLUMN_TYPE, COLUMN_TYPE + "_description",
ImmutableSet.<String>of(),
AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"),
AtlasTypeUtil.createRequiredAttrDef("type", "string"));
AtlasStructDef partitionDefinition = new AtlasStructDef("partition_struct_type", "partition_struct_type" + _description, "1.0",
Arrays.asList(AtlasTypeUtil.createRequiredAttrDef("name", "string")));
AtlasAttributeDef[] attributeDefinitions = new AtlasAttributeDef[]{
new AtlasAttributeDef("location", "string", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("inputFormat", "string", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("outputFormat", "string", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("compressed", "boolean", false,
AtlasAttributeDef.Cardinality.SINGLE, 1, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("numBuckets", "int", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
};
AtlasEntityDef storageDescClsDef =
new AtlasEntityDef(STORAGE_DESC_TYPE, STORAGE_DESC_TYPE + _description, "1.0",
Arrays.asList(attributeDefinitions), ImmutableSet.of(SUPER_TYPE_NAME));
AtlasAttributeDef[] partClsAttributes = new AtlasAttributeDef[]{
new AtlasAttributeDef("values", "array<string>",
true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("table", TABLE_TYPE, false,
AtlasAttributeDef.Cardinality.SINGLE, 1, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("createTime", "long", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("lastAccessTime", "long", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("sd", STORAGE_DESC_TYPE, false,
AtlasAttributeDef.Cardinality.SINGLE, 1, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("columns", String.format("array<%s>", COLUMN_TYPE),
true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("parameters", String.format("map<%s,%s>", "string", "string"), true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList())};
AtlasEntityDef partClsDef =
new AtlasEntityDef("partition_class_type", "partition_class_type" + _description, "1.0",
Arrays.asList(partClsAttributes), ImmutableSet.of(SUPER_TYPE_NAME));
AtlasEntityDef processClsType =
new AtlasEntityDef(PROCESS_TYPE, PROCESS_TYPE + _description, "1.0",
Arrays.asList(new AtlasAttributeDef("outputs", "array<" + TABLE_TYPE + ">", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList())),
ImmutableSet.<String>of());
AtlasEntityDef tableTypeDefinition =
AtlasTypeUtil.createClassTypeDef(TABLE_TYPE, TABLE_TYPE + _description, ImmutableSet.of(SUPER_TYPE_NAME),
AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"),
AtlasTypeUtil.createRequiredAttrDef("description", "string"),
AtlasTypeUtil.createRequiredAttrDef("type", "string"),
AtlasTypeUtil.createOptionalAttrDef("created", "date"),
// enum
new AtlasAttributeDef("tableType", "tableType", false,
AtlasAttributeDef.Cardinality.SINGLE, 1, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
// array of strings
new AtlasAttributeDef("columnNames",
String.format("array<%s>", "string"), true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
// array of classes
new AtlasAttributeDef("columns", String.format("array<%s>", COLUMN_TYPE),
true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
// array of structs
new AtlasAttributeDef("partitions", String.format("array<%s>", "partition_struct_type"),
true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
// map of primitives
new AtlasAttributeDef("parametersMap", String.format("map<%s,%s>", "string", "string"),
true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
//map of classes -
new AtlasAttributeDef(COLUMNS_MAP,
String.format("map<%s,%s>", "string", COLUMN_TYPE),
true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
//map of structs
new AtlasAttributeDef("partitionsMap",
String.format("map<%s,%s>", "string", "partition_struct_type"),
true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
// struct reference
new AtlasAttributeDef("serde1", "serdeType", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("serde2", "serdeType", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
// class reference
new AtlasAttributeDef("database", DATABASE_TYPE, false,
AtlasAttributeDef.Cardinality.SINGLE, 1, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()),
//class reference as composite
new AtlasAttributeDef("databaseComposite", DATABASE_TYPE, true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()));
AtlasClassificationDef piiTypeDefinition =
AtlasTypeUtil.createTraitTypeDef(PII, PII + _description, ImmutableSet.<String>of());
AtlasClassificationDef classificationTypeDefinition =
AtlasTypeUtil.createTraitTypeDef(CLASSIFICATION, CLASSIFICATION + _description, ImmutableSet.<String>of(),
AtlasTypeUtil.createRequiredAttrDef("tag", "string"));
AtlasClassificationDef fetlClassificationTypeDefinition =
AtlasTypeUtil.createTraitTypeDef("fetl" + CLASSIFICATION, "fetl" + CLASSIFICATION + _description, ImmutableSet.of(CLASSIFICATION),
AtlasTypeUtil.createRequiredAttrDef("tag", "string"));
return AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition),
ImmutableList.of(structTypeDefinition, partitionDefinition),
ImmutableList.of(classificationTypeDefinition, fetlClassificationTypeDefinition, piiTypeDefinition),
ImmutableList.of(superTypeDefinition, databaseTypeDefinition, columnsDefinition, tableTypeDefinition,
storageDescClsDef, partClsDef, processClsType));
}
public static final String randomString() {
return RandomStringUtils.randomAlphanumeric(10);
}
public static AtlasEntity createDBEntity() {
AtlasEntity entity = new AtlasEntity(DATABASE_TYPE);
String dbName = RandomStringUtils.randomAlphanumeric(10);
entity.setAttribute(NAME, dbName);
entity.setAttribute("description", "us db");
return entity;
}
public static AtlasEntity createTableEntity(String dbId) {
AtlasEntity entity = new AtlasEntity(TABLE_TYPE);
String tableName = RandomStringUtils.randomAlphanumeric(10);
entity.setAttribute(NAME, tableName);
entity.setAttribute("description", "random table");
entity.setAttribute("type", "type");
entity.setAttribute("tableType", "MANAGED");
// entity.setAttribute("database", new Id(dbId, 0, DATABASE_TYPE));
entity.setAttribute("created", new Date());
return entity;
}
public static AtlasEntity createColumnEntity() {
AtlasEntity entity = new AtlasEntity(COLUMN_TYPE);
entity.setAttribute(NAME, RandomStringUtils.randomAlphanumeric(10));
entity.setAttribute("type", "VARCHAR(32)");
return entity;
}
public static List<AtlasClassificationDef> getClassificationWithValidSuperType() {
AtlasClassificationDef securityClearanceTypeDef =
AtlasTypeUtil.createTraitTypeDef("SecurityClearance1", "SecurityClearance_description", ImmutableSet.<String>of(),
AtlasTypeUtil.createRequiredAttrDef("level", "int"));
AtlasClassificationDef janitorSecurityClearanceTypeDef =
AtlasTypeUtil.createTraitTypeDef("JanitorClearance", "JanitorClearance_description", ImmutableSet.<String>of("SecurityClearance1"),
AtlasTypeUtil.createRequiredAttrDef("level", "int"));
return Arrays.asList(securityClearanceTypeDef, janitorSecurityClearanceTypeDef);
}
public static List<AtlasClassificationDef> getClassificationWithValidAttribute(){
return getClassificationWithValidSuperType();
}
public static List<AtlasEntityDef> getEntityWithValidSuperType() {
AtlasEntityDef employeeTypeDef = AtlasTypeUtil.createClassTypeDef("Employee", "Employee_description", ImmutableSet.<String>of(),
AtlasTypeUtil.createOptionalAttrDef("birthday", "date"),
AtlasTypeUtil.createOptionalAttrDef("hasPets", "boolean"),
AtlasTypeUtil.createOptionalAttrDef("numberOfCars", "byte"),
AtlasTypeUtil.createOptionalAttrDef("houseNumber", "short"),
AtlasTypeUtil.createOptionalAttrDef("carMileage", "int"),
AtlasTypeUtil.createOptionalAttrDef("shares", "long"),
AtlasTypeUtil.createOptionalAttrDef("salary", "double"),
AtlasTypeUtil.createOptionalAttrDef("age", "float"),
AtlasTypeUtil.createOptionalAttrDef("numberOfStarsEstimate", "biginteger"),
AtlasTypeUtil.createOptionalAttrDef("approximationOfPi", "bigdecimal")
);
AtlasEntityDef developerTypeDef = AtlasTypeUtil.createClassTypeDef("Developer", "Developer_description", ImmutableSet.of("Employee"),
new AtlasAttributeDef("subordinates", String.format("array<%s>", "Employee"), false, AtlasAttributeDef.Cardinality.SET,
1, 10, false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()));
return Arrays.asList(employeeTypeDef, developerTypeDef);
}
public static List<AtlasEntityDef> getEntityWithValidAttribute() {
List<AtlasEntityDef> entityDefs = getEntityWithValidSuperType();
entityDefs.get(1).getSuperTypes().clear();
return entityDefs;
}
public static AtlasClassificationDef getClassificationWithInvalidSuperType() {
AtlasClassificationDef classificationDef = simpleType().getClassificationDefs().get(0);
classificationDef.getSuperTypes().add("!@#$%");
return classificationDef;
}
public static AtlasEntityDef getEntityWithInvalidSuperType() {
AtlasEntityDef entityDef = simpleType().getEntityDefs().get(0);
entityDef.addSuperType("!@#$%");
return entityDef;
}
}
...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ...@@ -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) ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES: 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-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-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) ATLAS-1253 Extract error codes into AtlasErrorCode Enum (apoorvnaik via sumasai)
......
...@@ -165,6 +165,13 @@ ...@@ -165,6 +165,13 @@
<classifier>tests</classifier> <classifier>tests</classifier>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.atlas</groupId>
<artifactId>atlas-intg</artifactId>
<type>test-jar</type>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -57,18 +57,23 @@ public class TypeDefSorter { ...@@ -57,18 +57,23 @@ public class TypeDefSorter {
} }
processed.add(type); processed.add(type);
Set<String> superTypeNames = new HashSet<>(); Set<String> superTypeNames = new HashSet<>();
try { if (type.getClass().equals(AtlasClassificationDef.class)) {
AtlasClassificationDef classificationDef = AtlasClassificationDef.class.cast(type); try {
superTypeNames.addAll(classificationDef.getSuperTypes()); AtlasClassificationDef classificationDef = AtlasClassificationDef.class.cast(type);
} catch (ClassCastException ex) { superTypeNames.addAll(classificationDef.getSuperTypes());
LOG.warn("Casting to ClassificationDef failed"); } catch (ClassCastException ex) {
LOG.warn("Casting to ClassificationDef failed");
}
} }
try { if (type.getClass().equals(AtlasEntityDef.class)) {
AtlasEntityDef entityDef = AtlasEntityDef.class.cast(type); try {
superTypeNames.addAll(entityDef.getSuperTypes()); AtlasEntityDef entityDef = AtlasEntityDef.class.cast(type);
} catch (ClassCastException ex) { superTypeNames.addAll(entityDef.getSuperTypes());
LOG.warn("Casting to AtlasEntityDef failed"); } catch (ClassCastException ex) {
LOG.warn("Casting to AtlasEntityDef failed");
}
} }
for (String superTypeName : superTypeNames) { for (String superTypeName : superTypeNames) {
// Recursively add any supertypes first to the result. // Recursively add any supertypes first to the result.
T superType = typesByName.get(superTypeName); T superType = typesByName.get(superTypeName);
......
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.repository.store.graph;
import com.google.inject.Inject;
import org.apache.atlas.RepositoryMetadataModule;
import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
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.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.util.Collections;
import java.util.List;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@Guice(modules = RepositoryMetadataModule.class)
public class AtlasTypeDefGraphStoreTest {
private static final Logger LOG = LoggerFactory.getLogger(AtlasTypeDefGraphStoreTest.class);
@Inject
private
AtlasTypeDefStore typeDefStore;
@AfterClass
public void clear(){
AtlasGraphProvider.cleanup();
}
@Test(priority = 1)
public void testGet() {
try {
List<AtlasEnumDef> allEnumDefs = typeDefStore.getAllEnumDefs();
assertNotNull(allEnumDefs);
assertEquals(allEnumDefs.size(), 0);
} catch (AtlasBaseException e) {
fail("Get should've succeeded", e);
}
try {
List<AtlasClassificationDef> allClassificationDefs = typeDefStore.getAllClassificationDefs();
assertNotNull(allClassificationDefs);
assertEquals(allClassificationDefs.size(), 0);
} catch (AtlasBaseException e) {
fail("Get should've succeeded", e);
}
try {
List<AtlasStructDef> allStructDefs = typeDefStore.getAllStructDefs();
assertNotNull(allStructDefs);
assertEquals(allStructDefs.size(), 0);
} catch (AtlasBaseException e) {
fail("Get should've succeeded", e);
}
try {
List<AtlasEntityDef> allEntityDefs = typeDefStore.getAllEntityDefs();
assertNotNull(allEntityDefs);
// For some reason this keeps on toggling b/w 0 and 5, need to investigate
assertTrue(allEntityDefs.size()>= 0);
} catch (AtlasBaseException e) {
fail("Get should've succeeded", e);
}
}
@Test(dataProvider = "invalidGetProvider", priority = 2)
public void testInvalidGet(String name, String guid){
try {
assertNull(typeDefStore.getEnumDefByName(name));
fail("Exception expected for invalid name");
} catch (AtlasBaseException e) {
}
try {
assertNull(typeDefStore.getEnumDefByGuid(guid));
fail("Exception expected for invalid guid");
} catch (AtlasBaseException e) {
}
try {
assertNull(typeDefStore.getStructDefByName(name));
fail("Exception expected for invalid name");
} catch (AtlasBaseException e) {
}
try {
assertNull(typeDefStore.getStructDefByGuid(guid));
fail("Exception expected for invalid guid");
} catch (AtlasBaseException e) {
}
try {
assertNull(typeDefStore.getClassificationDefByName(name));
fail("Exception expected for invalid name");
} catch (AtlasBaseException e) {
}
try {
assertNull(typeDefStore.getClassificationDefByGuid(guid));
fail("Exception expected for invalid guid");
} catch (AtlasBaseException e) {
}
try {
assertNull(typeDefStore.getEntityDefByName(name));
fail("Exception expected for invalid name");
} catch (AtlasBaseException e) {
}
try {
assertNull(typeDefStore.getEntityDefByGuid(guid));
fail("Exception expected for invalid guid");
} catch (AtlasBaseException e) {
}
}
@DataProvider
public Object[][] invalidGetProvider(){
return new Object[][] {
{"name1", "guid1"},
{"", ""},
{null, null}
};
}
@DataProvider
public Object[][] validCreateDeptTypes(){
return new Object[][] {
{TestUtilsV2.defineDeptEmployeeTypes()}
};
}
@DataProvider
public Object[][] validUpdateDeptTypes(){
return new Object[][] {
{TestUtilsV2.defineValidUpdatedDeptEmployeeTypes()}
};
}
@DataProvider
public Object[][] invalidCreateTypes(){
// TODO: Create invalid type in TestUtilsV2
return new Object[][] {
};
}
@DataProvider
public Object[][] invalidUpdateTypes(){
return new Object[][] {
{TestUtilsV2.defineInvalidUpdatedDeptEmployeeTypes()}
};
}
@Test(dependsOnMethods = {"testGet"}, dataProvider = "validCreateDeptTypes")
public void testCreateDept(AtlasTypesDef atlasTypesDef) {
AtlasTypesDef existingTypesDef = null;
try {
existingTypesDef = typeDefStore.searchTypesDef(new SearchFilter());
} catch (AtlasBaseException e) {
fail("Shouldn't have failed during Search");
}
assertNotEquals(atlasTypesDef, existingTypesDef, "Types to be created already exist in the system");
AtlasTypesDef createdTypesDef = null;
try {
createdTypesDef = typeDefStore.createTypesDef(atlasTypesDef);
assertNotNull(createdTypesDef);
assertTrue(createdTypesDef.getEnumDefs().containsAll(atlasTypesDef.getEnumDefs()), "EnumDefs create failed");
assertTrue(createdTypesDef.getClassificationDefs().containsAll(atlasTypesDef.getClassificationDefs()), "ClassificationDef create failed");
assertTrue(createdTypesDef.getStructDefs().containsAll(atlasTypesDef.getStructDefs()), "StructDef creation failed");
assertTrue(createdTypesDef.getEntityDefs().containsAll(atlasTypesDef.getEntityDefs()), "EntityDef creation failed");
} catch (AtlasBaseException e) {
fail("Creation of Types should've been a success");
}
}
@Test(dependsOnMethods = {"testCreateDept"}, dataProvider = "validUpdateDeptTypes")
public void testUpdate(AtlasTypesDef atlasTypesDef){
try {
AtlasTypesDef updatedTypesDef = typeDefStore.updateTypesDef(atlasTypesDef);
assertNotNull(updatedTypesDef);
assertEquals(updatedTypesDef.getEnumDefs().size(), atlasTypesDef.getEnumDefs().size(), "EnumDefs update failed");
assertEquals(updatedTypesDef.getClassificationDefs().size(), atlasTypesDef.getClassificationDefs().size(), "ClassificationDef update failed");
assertEquals(updatedTypesDef.getStructDefs().size(), atlasTypesDef.getStructDefs().size(), "StructDef update failed");
assertEquals(updatedTypesDef.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size(), "EntityDef update failed");
// Try another update round by name and GUID
for (AtlasEnumDef enumDef : updatedTypesDef.getEnumDefs()) {
AtlasEnumDef updated = typeDefStore.updateEnumDefByGuid(enumDef.getGuid(), enumDef);
assertNotNull(updated);
}
for (AtlasEnumDef enumDef : atlasTypesDef.getEnumDefs()) {
AtlasEnumDef updated = typeDefStore.updateEnumDefByName(enumDef.getName(), enumDef);
assertNotNull(updated);
}
// Try another update round by name and GUID
for (AtlasClassificationDef classificationDef : updatedTypesDef.getClassificationDefs()) {
AtlasClassificationDef updated = typeDefStore.updateClassificationDefByGuid(classificationDef.getGuid(), classificationDef);
assertNotNull(updated);
}
for (AtlasClassificationDef classificationDef : atlasTypesDef.getClassificationDefs()) {
AtlasClassificationDef updated = typeDefStore.updateClassificationDefByName(classificationDef.getName(), classificationDef);
assertNotNull(updated);
}
// Try another update round by name and GUID
for (AtlasStructDef structDef : updatedTypesDef.getStructDefs()) {
AtlasStructDef updated = typeDefStore.updateStructDefByGuid(structDef.getGuid(), structDef);
assertNotNull(updated);
}
for (AtlasStructDef structDef : atlasTypesDef.getStructDefs()) {
AtlasStructDef updated = typeDefStore.updateStructDefByName(structDef.getName(), structDef);
assertNotNull(updated);
}
// Try another update round by name and GUID
for (AtlasEntityDef entityDef : updatedTypesDef.getEntityDefs()) {
AtlasEntityDef updated = typeDefStore.updateEntityDefByGuid(entityDef.getGuid(), entityDef);
assertNotNull(updated);
}
for (AtlasEntityDef entityDef : atlasTypesDef.getEntityDefs()) {
AtlasEntityDef updated = typeDefStore.updateEntityDefByName(entityDef.getName(), entityDef);
assertNotNull(updated);
}
} catch (AtlasBaseException e) {
fail("TypeDef updates should've succeeded");
}
}
@Test(enabled = false, dependsOnMethods = {"testCreateDept"})
public void testUpdateWithMandatoryFields(){
AtlasTypesDef atlasTypesDef = TestUtilsV2.defineInvalidUpdatedDeptEmployeeTypes();
List<AtlasEnumDef> enumDefsToUpdate = atlasTypesDef.getEnumDefs();
List<AtlasClassificationDef> classificationDefsToUpdate = atlasTypesDef.getClassificationDefs();
List<AtlasStructDef> structDefsToUpdate = atlasTypesDef.getStructDefs();
List<AtlasEntityDef> entityDefsToUpdate = atlasTypesDef.getEntityDefs();
AtlasTypesDef onlyEnums = new AtlasTypesDef(enumDefsToUpdate,
Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
AtlasTypesDef onlyStructs = new AtlasTypesDef(Collections.EMPTY_LIST,
structDefsToUpdate, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
AtlasTypesDef onlyClassification = new AtlasTypesDef(Collections.EMPTY_LIST,
Collections.EMPTY_LIST, classificationDefsToUpdate, Collections.EMPTY_LIST);
AtlasTypesDef onlyEntities = new AtlasTypesDef(Collections.EMPTY_LIST,
Collections.EMPTY_LIST, Collections.EMPTY_LIST, entityDefsToUpdate);
try {
AtlasTypesDef updated = typeDefStore.updateTypesDef(onlyEnums);
assertNotNull(updated);
} catch (AtlasBaseException ignored) {}
try {
AtlasTypesDef updated = typeDefStore.updateTypesDef(onlyClassification);
assertNotNull(updated);
assertEquals(updated.getClassificationDefs().size(), 0, "Updates should've failed");
} catch (AtlasBaseException ignored) {}
try {
AtlasTypesDef updated = typeDefStore.updateTypesDef(onlyStructs);
assertNotNull(updated);
assertEquals(updated.getStructDefs().size(), 0, "Updates should've failed");
} catch (AtlasBaseException ignored) {}
try {
AtlasTypesDef updated = typeDefStore.updateTypesDef(onlyEntities);
assertNotNull(updated);
assertEquals(updated.getEntityDefs().size(), 0, "Updates should've failed");
} catch (AtlasBaseException ignored) {}
}
// This should run after all the update calls
@Test(dependsOnMethods = {"testUpdate"}, dataProvider = "validUpdateDeptTypes")
public void testDelete(AtlasTypesDef atlasTypesDef){
try {
typeDefStore.deleteTypesDef(atlasTypesDef);
} catch (AtlasBaseException e) {
fail("Deletion should've succeeded");
}
}
@Test(dependsOnMethods = "testGet")
public void testCreateWithValidAttributes(){
AtlasTypesDef hiveTypes = TestUtilsV2.defineHiveTypes();
try {
AtlasTypesDef createdTypes = typeDefStore.createTypesDef(hiveTypes);
assertEquals(hiveTypes.getEnumDefs(), createdTypes.getEnumDefs(), "Data integrity issue while persisting");
assertEquals(hiveTypes.getStructDefs(), createdTypes.getStructDefs(), "Data integrity issue while persisting");
assertEquals(hiveTypes.getClassificationDefs(), createdTypes.getClassificationDefs(), "Data integrity issue while persisting");
assertEquals(hiveTypes.getEntityDefs(), createdTypes.getEntityDefs(), "Data integrity issue while persisting");
} catch (AtlasBaseException e) {
fail("Hive Type creation should've succeeded");
}
}
@Test(enabled = false)
public void testCreateWithInvalidAttributes(){
}
@Test(dependsOnMethods = "testGet")
public void testCreateWithValidSuperTypes(){
// Test Classification with supertype
List<AtlasClassificationDef> classificationDefs = TestUtilsV2.getClassificationWithValidSuperType();
AtlasTypesDef toCreate = new AtlasTypesDef(null, null, classificationDefs, null);
try {
AtlasTypesDef created = typeDefStore.createTypesDef(toCreate);
assertEquals(created.getClassificationDefs(), toCreate.getClassificationDefs(),
"Classification creation with valid supertype should've succeeded");
} catch (AtlasBaseException e) {
fail("Classification creation with valid supertype should've succeeded");
}
// Test Entity with supertype
List<AtlasEntityDef> entityDefs = TestUtilsV2.getEntityWithValidSuperType();
toCreate = new AtlasTypesDef(null, null, null, entityDefs);
try {
AtlasTypesDef created = typeDefStore.createTypesDef(toCreate);
assertEquals(created.getEntityDefs(), toCreate.getEntityDefs(),
"Entity creation with valid supertype should've succeeded");
} catch (AtlasBaseException e) {
fail("Entity creation with valid supertype should've succeeded");
}
}
@Test(dependsOnMethods = "testGet")
public void testCreateWithInvalidSuperTypes(){
// Test Classification with supertype
AtlasClassificationDef classificationDef = TestUtilsV2.getClassificationWithInvalidSuperType();
try {
AtlasClassificationDef created = typeDefStore.createClassificationDef(classificationDef);
fail("Classification creation with invalid supertype should've failed");
} catch (AtlasBaseException e) {}
// Test Entity with supertype
AtlasEntityDef entityDef = TestUtilsV2.getEntityWithInvalidSuperType();
try {
AtlasEntityDef created = typeDefStore.createEntityDef(entityDef);
fail("Entity creation with invalid supertype should've failed");
} catch (AtlasBaseException e) {}
}
}
\ No newline at end of file
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