You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2017/11/05 20:31:26 UTC
[04/40] atlas git commit: ATLAS-2251: Remove TypeSystem and related
implementation, to avoid unncessary duplicate of type details in cache
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/typesystem/src/test/java/org/apache/atlas/typesystem/types/cache/DefaultTypeCacheTest.java
----------------------------------------------------------------------
diff --git a/typesystem/src/test/java/org/apache/atlas/typesystem/types/cache/DefaultTypeCacheTest.java b/typesystem/src/test/java/org/apache/atlas/typesystem/types/cache/DefaultTypeCacheTest.java
deleted file mode 100644
index 5c397dd..0000000
--- a/typesystem/src/test/java/org/apache/atlas/typesystem/types/cache/DefaultTypeCacheTest.java
+++ /dev/null
@@ -1,450 +0,0 @@
-/**
- * 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.typesystem.types.cache;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.typesystem.types.ClassType;
-import org.apache.atlas.typesystem.types.DataTypes;
-import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
-import org.apache.atlas.typesystem.types.EnumType;
-import org.apache.atlas.typesystem.types.EnumValue;
-import org.apache.atlas.typesystem.types.IDataType;
-import org.apache.atlas.typesystem.types.StructType;
-import org.apache.atlas.typesystem.types.TraitType;
-import org.apache.atlas.typesystem.types.TypeSystem;
-import org.apache.atlas.typesystem.types.utils.TypesUtil;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
-/**
- * Tests functional behavior of {@link DefaultTypeCache}
- */
-@SuppressWarnings("rawtypes")
-public class DefaultTypeCacheTest {
-
- private String CLASSTYPE_CUSTOMER = "Customer";
- private String STRUCTTYPE_ADDRESS = "Address";
- private String TRAITTYPE_PRIVILEGED = "Privileged";
- private String ENUMTYPE_SHIPPING = "Shipping";
-
- private String UNKNOWN_TYPE = "UndefinedType";
-
- private ClassType customerType;
- private StructType addressType;
- private TraitType privilegedTrait;
- private EnumType shippingEnum;
-
- private DefaultTypeCache cache;
-
- @BeforeClass
- public void onetimeSetup() throws Exception {
-
- // init TypeSystem
- TypeSystem ts = TypeSystem.getInstance().reset();
-
- // Customer ClassType
- customerType = ts.defineClassType(TypesUtil
- .createClassTypeDef(CLASSTYPE_CUSTOMER, ImmutableSet.<String>of(),
- TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE),
- TypesUtil.createRequiredAttrDef("id", DataTypes.LONG_TYPE)));
-
- // Address StructType
- addressType = ts.defineStructType(STRUCTTYPE_ADDRESS, true,
- TypesUtil.createRequiredAttrDef("first line", DataTypes.STRING_TYPE),
- TypesUtil.createOptionalAttrDef("second line", DataTypes.STRING_TYPE),
- TypesUtil.createRequiredAttrDef("city", DataTypes.STRING_TYPE),
- TypesUtil.createRequiredAttrDef("pincode", DataTypes.INT_TYPE));
-
- // Privileged TraitType
- privilegedTrait = ts.defineTraitType(TypesUtil
- .createTraitTypeDef(TRAITTYPE_PRIVILEGED, ImmutableSet.<String>of(),
- TypesUtil.createRequiredAttrDef("category", DataTypes.INT_TYPE)));
-
- // Shipping EnumType
- shippingEnum = ts.defineEnumType(TypesUtil.createEnumTypeDef(ENUMTYPE_SHIPPING,
- new EnumValue("Domestic", 1), new EnumValue("International", 2)));
- }
-
- @BeforeMethod
- public void eachTestSetup() throws Exception {
-
- cache = new DefaultTypeCache();
-
- cache.put(customerType);
- cache.put(addressType);
- cache.put(privilegedTrait);
- cache.put(shippingEnum);
- }
-
- @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));
- }
-
- private void verifyType(IDataType actualType, String expectedName, Class<? extends IDataType> typeClass) {
-
- assertNotNull(actualType, "The " + expectedName + " type not in cache");
- assertTrue(typeClass.isInstance(actualType));
- assertEquals(actualType.getName(), expectedName, "The type name does not match");
- }
-
- @Test
- public void testCacheHasType() throws Exception {
-
- assertTrue(cache.has(CLASSTYPE_CUSTOMER));
- assertTrue(cache.has(STRUCTTYPE_ADDRESS));
- assertTrue(cache.has(TRAITTYPE_PRIVILEGED));
- assertTrue(cache.has(ENUMTYPE_SHIPPING));
-
- assertFalse(cache.has(UNKNOWN_TYPE));
- }
-
- @Test
- public void testCacheHasTypeByCategory() throws Exception {
-
- assertTrue(cache.has(TypeCategory.CLASS, CLASSTYPE_CUSTOMER));
- assertTrue(cache.has(TypeCategory.STRUCT, STRUCTTYPE_ADDRESS));
- assertTrue(cache.has(TypeCategory.TRAIT, TRAITTYPE_PRIVILEGED));
- assertTrue(cache.has(TypeCategory.ENUM, ENUMTYPE_SHIPPING));
-
- assertFalse(cache.has(UNKNOWN_TYPE));
- }
-
- @Test
- public void testCacheGetAllTypeNames() throws Exception {
-
- List<String> allTypeNames = new ArrayList<>(cache.getAllTypeNames());
- Collections.sort(allTypeNames);
-
- final int EXPECTED_TYPE_COUNT = 4;
- assertEquals(allTypeNames.size(), EXPECTED_TYPE_COUNT, "Total number of types does not match.");
-
- assertEquals(STRUCTTYPE_ADDRESS, allTypeNames.get(0));
- assertEquals(CLASSTYPE_CUSTOMER, allTypeNames.get(1));
- assertEquals(TRAITTYPE_PRIVILEGED, allTypeNames.get(2));
- assertEquals(ENUMTYPE_SHIPPING, allTypeNames.get(3));
- }
-
- private Collection<String> getTypeNamesByCategory(final TypeCategory category)
- throws AtlasException {
- return cache.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {{
- put(TypeCache.TYPE_FILTER.CATEGORY, category.name());
- }});
- }
-
- @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
- public void testCacheBulkInsert() throws Exception {
-
- List<IDataType> allTypes = new ArrayList<>();
- allTypes.add(customerType);
- allTypes.add(addressType);
- allTypes.add(privilegedTrait);
- allTypes.add(shippingEnum);
-
- // create a new cache instead of using the one setup for every method call
- cache = new DefaultTypeCache();
- cache.putAll(allTypes);
-
- 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);
- }
-
- @Test
- public void testCacheRemove() throws Exception {
- cache.remove(CLASSTYPE_CUSTOMER);
- assertNull(cache.get(CLASSTYPE_CUSTOMER));
- assertFalse(cache.has(CLASSTYPE_CUSTOMER));
- assertTrue(getTypeNamesByCategory(TypeCategory.CLASS).isEmpty());
-
- final int EXPECTED_TYPE_COUNT = 3;
- assertEquals(cache.getAllTypeNames().size(), EXPECTED_TYPE_COUNT);
- }
-
- @Test
- public void testCacheRemoveByCategory() throws Exception {
-
- cache.remove(TypeCategory.CLASS, CLASSTYPE_CUSTOMER);
- assertNull(cache.get(CLASSTYPE_CUSTOMER));
- assertFalse(cache.has(CLASSTYPE_CUSTOMER));
- assertTrue(getTypeNamesByCategory(TypeCategory.CLASS).isEmpty());
-
- final int EXPECTED_TYPE_COUNT = 3;
- assertEquals(cache.getAllTypeNames().size(), EXPECTED_TYPE_COUNT);
- }
-
- @Test
- public void testCacheClear() throws Exception {
-
- cache.clear();
-
- assertNull(cache.get(CLASSTYPE_CUSTOMER));
- assertFalse(cache.has(CLASSTYPE_CUSTOMER));
-
- assertNull(cache.get(STRUCTTYPE_ADDRESS));
- assertFalse(cache.has(STRUCTTYPE_ADDRESS));
-
- assertNull(cache.get(TRAITTYPE_PRIVILEGED));
- assertFalse(cache.has(TRAITTYPE_PRIVILEGED));
-
- assertNull(cache.get(ENUMTYPE_SHIPPING));
- assertFalse(cache.has(ENUMTYPE_SHIPPING));
-
- assertTrue(getTypeNamesByCategory(TypeCategory.CLASS).isEmpty());
- assertTrue(getTypeNamesByCategory(TypeCategory.STRUCT).isEmpty());
- assertTrue(getTypeNamesByCategory(TypeCategory.TRAIT).isEmpty());
- assertTrue(getTypeNamesByCategory(TypeCategory.ENUM).isEmpty());
-
- assertTrue(cache.getAllTypeNames().isEmpty());
- }
-
- @Test(expectedExceptions = AtlasException.class)
- public void testPutTypeWithNullType() throws Exception {
-
- cache.put(null);
- fail("Null type should be not allowed in 'put'");
- }
-
- @Test(expectedExceptions = AtlasException.class)
- public void testPutTypeWithInvalidType() throws Exception {
-
- cache.put(DataTypes.BOOLEAN_TYPE);
- fail("type should only be an instance of ClassType | EnumType | StructType | TraitType in 'put'");
- }
-
- @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'");
- }
-
- @Test(expectedExceptions = IllegalArgumentException.class)
- public void testCacheHasTypeWithNullCategory() throws Exception {
-
- cache.has(null, CLASSTYPE_CUSTOMER);
- fail("Null TypeCategory should be not allowed in 'has'");
- }
-
- @Test(expectedExceptions = IllegalArgumentException.class)
- public void testCacheHasTypeWithInvalidCategory() throws Exception {
-
- cache.has(TypeCategory.PRIMITIVE, DataTypes.BOOLEAN_TYPE.getName());
- fail("TypeCategory should only be one of TypeCategory.CLASS | ENUM | STRUCT | TRAIT in 'has'");
- }
-
- @Test(expectedExceptions = IllegalArgumentException.class)
- public void testCacheGetTypeNamesByInvalidCategory() throws Exception {
- getTypeNamesByCategory(TypeCategory.PRIMITIVE);
- fail("TypeCategory should only be one of TypeCategory.CLASS | ENUM | STRUCT | TRAIT in 'getNames'");
- }
-
- @Test(expectedExceptions = AtlasException.class)
- public void testCacheBulkInsertWithNullType() throws Exception {
-
- List<IDataType> allTypes = new ArrayList<>();
- allTypes.add(null);
-
- // create a new cache instead of using the one setup for every method call
- cache = new DefaultTypeCache();
- cache.putAll(allTypes);
-
- fail("Null type should be not allowed in 'putAll'");
- }
-
- @Test(expectedExceptions = AtlasException.class)
- public void testCacheBulkInsertWithInvalidType() throws Exception {
-
- List<IDataType> allTypes = new ArrayList<>();
- allTypes.add(DataTypes.BOOLEAN_TYPE);
-
- // create a new cache instead of using the one setup for every method call
- cache = new DefaultTypeCache();
- cache.putAll(allTypes);
-
- fail("type should only one of ClassType | EnumType | StructType | TraitType in 'putAll'");
- }
-
- @Test(expectedExceptions = IllegalArgumentException.class)
- public void testCacheRemoveByNullCategory() throws Exception {
-
- cache.remove(null, CLASSTYPE_CUSTOMER);
- fail("Null type should be not allowed in 'remove'");
- }
-
- @Test(expectedExceptions = IllegalArgumentException.class)
- public void testCacheRemoveByInvalidCategory() throws Exception {
-
- cache.remove(TypeCategory.PRIMITIVE, DataTypes.BOOLEAN_TYPE.getName());
- fail("TypeCategory should only be one of TypeCategory.CLASS | ENUM | STRUCT | TRAIT in 'remove'");
- }
-
- @Test
- public void testGetTypesByFilter() throws Exception {
- // init TypeSystem
- TypeSystem ts = TypeSystem.getInstance().reset();
-
- ts.defineClassType(TypesUtil.createClassTypeDef("A", ImmutableSet.<String>of()));
- ts.defineClassType(TypesUtil.createClassTypeDef("A1", ImmutableSet.of("A")));
-
- ts.defineClassType(TypesUtil.createClassTypeDef("B", ImmutableSet.<String>of()));
-
- ts.defineClassType(TypesUtil.createClassTypeDef("C", ImmutableSet.of("B", "A")));
-
- //supertype ~ A
- ImmutableList<String> results = ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {{
- put(TypeCache.TYPE_FILTER.SUPERTYPE, "A");
- }});
- assertTrue(results.containsAll(Arrays.asList("A1", "C")), "Results: " + results);
-
- //!supertype doesn't return the type itself
- results = ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {{
- put(TypeCache.TYPE_FILTER.NOT_SUPERTYPE, "A");
- }});
- assertTrue(results.containsAll(Arrays.asList("B")), "Results: " + results);
-
- //supertype ~ A && supertype !~ B
- results = ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {{
- put(TypeCache.TYPE_FILTER.SUPERTYPE, "A");
- put(TypeCache.TYPE_FILTER.NOT_SUPERTYPE, "B");
- }});
- assertTrue(results.containsAll(Arrays.asList("A1")), "Results: " + results);
-
- //none of category trait
- results = ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {{
- put(TypeCache.TYPE_FILTER.CATEGORY, TypeCategory.TRAIT.name());
- put(TypeCache.TYPE_FILTER.SUPERTYPE, "A");
- }});
- assertTrue(results.isEmpty(), "Results: " + results);
-
- //no filter returns all types
- results = ts.getTypeNames(null);
- assertTrue(results.containsAll(Arrays.asList("A", "A1", "B", "C")), "Results: " + results);
-
- results = ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>());
- assertTrue(results.containsAll(Arrays.asList("A", "A1", "B", "C")), "Results: " + results);
-
- //invalid category
- try {
- ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {{
- put(TypeCache.TYPE_FILTER.CATEGORY, "A");
- }});
- fail("Expected IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- //invalid supertype
- results = ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {{
- put(TypeCache.TYPE_FILTER.SUPERTYPE, "X");
- }});
- assertTrue(results.isEmpty(), "Expected empty result for non-existent type 'X'. Found: " + results);
-
- //invalid supertype
- results = ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {{
- put(TypeCache.TYPE_FILTER.NOT_SUPERTYPE, "X");
- }});
- assertTrue(results.containsAll(Arrays.asList("A", "A1", "B", "C")), "Results: " + results);
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/BuilderTest.scala
----------------------------------------------------------------------
diff --git a/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/BuilderTest.scala b/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/BuilderTest.scala
deleted file mode 100644
index 9d1d00f..0000000
--- a/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/BuilderTest.scala
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.typesystem.builders
-
-import org.apache.atlas.typesystem.TypesDef
-import org.apache.atlas.typesystem.types.TypeSystem
-import org.testng.annotations.BeforeMethod
-
-abstract class BuilderTest {
-
- var tDef : TypesDef = null
-
- @BeforeMethod
- def before {
- TypeSystem.getInstance().reset()
-
- val b = new TypesBuilder
- import b._
-
- tDef = types {
-
- _trait("Dimension") {}
- _trait("PII") {}
- _trait("Metric") {}
- _trait("ETL") {}
- _trait("JdbcAccess") {}
-
- _class("DB") {
- "name" ~ (string, required, indexed, unique)
- "owner" ~ (string)
- "createTime" ~ (int)
- }
-
- _class("StorageDesc") {
- "inputFormat" ~ (string, required)
- "outputFormat" ~ (string, required)
- }
-
- _class("Column") {
- "name" ~ (string, required)
- "dataType" ~ (string, required)
- "sd" ~ ("StorageDesc", required)
- }
-
- _class("Table", List()) {
- "name" ~ (string, required, indexed)
- "db" ~ ("DB", required)
- "sd" ~ ("StorageDesc", required)
- }
-
- _class("LoadProcess") {
- "name" ~ (string, required)
- "inputTables" ~ (array("Table"), collection)
- "outputTable" ~ ("Table", required)
-
- }
-
- _class("View") {
- "name" ~ (string, required)
- "inputTables" ~ (array("Table"), collection)
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/InstanceBuilderTest.scala
----------------------------------------------------------------------
diff --git a/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/InstanceBuilderTest.scala b/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/InstanceBuilderTest.scala
deleted file mode 100644
index 0331c9c..0000000
--- a/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/InstanceBuilderTest.scala
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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.typesystem.builders
-
-import org.apache.atlas.typesystem.types.{ClassType, Multiplicity, TypeSystem}
-import org.testng.annotations.Test
-
-class InstanceBuilderTest extends BuilderTest {
-
- @Test def test1 {
- TypeSystem.getInstance().defineTypes(tDef)
-
- val b = new InstanceBuilder
- import b._
-
- val instances = b create {
-
- val salesDB = instance("DB") { // use instance to create Referenceables. use closure to
- // set attributes of instance
- 'name ~ "Sales" // use '~' to set attributes. Use a Symbol (names starting with ') for
- // attribute names.
- 'owner ~ "John ETL"
- 'createTime ~ 1000
- }
-
- val salesFact = instance("Table") {
- 'name ~ "sales_fact"
- 'db ~ salesDB
- val sd = instance("StorageDesc") { // any valid scala allowed in closure.
- 'inputFormat ~ "TextIputFormat"
- 'outputFormat ~ "TextOutputFormat"
- }
- 'sd ~ sd // use ~ to set references, collections and maps.
- val columns = Seq(
- instance("Column") {
- 'name ~ "time_id"
- 'dataType ~ "int"
- 'sd ~ sd
- },
- instance("Column") {
- 'name ~ "product_id"
- 'dataType ~ "int"
- 'sd ~ sd
- },
- instance("Column") {
- 'name ~ "customer_id"
- 'dataType ~ "int"
- 'sd ~ sd
- },
- instance("Column", "Metric") {
- 'name ~ "sales"
- 'dataType ~ "int"
- 'sd ~ sd
- 'Metric("x") ~ 1 // use 'TraitName("attrName") to set values on traits.
- }
- )
-
- 'columns ~ columns
-
- }
-
- salesFact.sd.inputFormat ~ "TextInputFormat" // use dot navigation to alter attributes in the object graph.
- // here I am fixing the typo in "TextInputFormat"
- // dot navigation also works for arrays.
- // here I am fixing column(3). Metric trait has no attributes.
- val c = salesFact.columns
- c(3) = instance("Column", "Metric") {
- 'name ~ "sales"
- 'dataType ~ "int"
- 'sd ~ salesFact.sd
- }
-
- }
-
- val ts = TypeSystem.getInstance()
-
- import scala.collection.JavaConversions._
- val typedInstances = instances.map { i =>
- val iTyp = ts.getDataType(classOf[ClassType], i.getTypeName)
- iTyp.convert(i, Multiplicity.REQUIRED)
- }
-
- typedInstances.foreach { i =>
- println(i)
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/MultiplicityTest.scala
----------------------------------------------------------------------
diff --git a/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/MultiplicityTest.scala b/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/MultiplicityTest.scala
deleted file mode 100644
index 91e72c7..0000000
--- a/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/MultiplicityTest.scala
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.typesystem.builders
-
-import org.apache.atlas.AtlasException
-import org.apache.atlas.typesystem.types.{ClassType, Multiplicity, TypeSystem}
-import org.testng.annotations.{BeforeMethod,Test}
-
-class MultiplicityTest {
-
- @BeforeMethod
- def beforeAll {
- TypeSystem.getInstance().reset()
-
- val b = new TypesBuilder
- import b._
-
- val tDef = types {
-
- _trait("Dimension") {}
- _trait("PII") {}
- _trait("Metric") {}
- _trait("ETL") {}
- _trait("JdbcAccess") {}
-
- _class("DB") {
- "name" ~ (string, required, indexed, unique)
- "owner" ~ (string)
- "createTime" ~ (int)
- }
-
- _class("StorageDesc") {
- "inputFormat" ~ (string, required)
- "outputFormat" ~ (string, required)
- }
-
- _class("Column") {
- "name" ~ (string, required)
- "dataType" ~ (string, required)
- "sd" ~ ("StorageDesc", required)
- }
-
- _class("Table", List()) {
- "name" ~ (string, required, indexed)
- "db" ~ ("DB", required)
- "sd" ~ ("StorageDesc", required)
- }
-
- _class("LoadProcess") {
- "name" ~ (string, required)
- "inputTables" ~ (array("Table"), collection)
- "outputTable" ~ ("Table", required)
-
- }
-
- _class("View") {
- "name" ~ (string, required)
- "inputTables" ~ (array("Table"), collection)
- }
-
- _class("AT") {
- "name" ~ (string, required)
- "stringSet" ~ (array("string"), multiplicty(0, Int.MaxValue, true))
- }
- }
-
- TypeSystem.getInstance().defineTypes(tDef)
- }
-
- @Test
- def test1 {
-
- val b = new InstanceBuilder
- import b._
-
- val instances = b create {
- val a = instance("AT") { // use instance to create Referenceables. use closure to
- // set attributes of instance
- 'name ~ "A1" // use '~' to set attributes. Use a Symbol (names starting with ') for
- 'stringSet ~ Seq("a", "a")
- }
- }
-
- val ts = TypeSystem.getInstance()
- import scala.collection.JavaConversions._
- val typedInstances = instances.map { i =>
- val iTyp = ts.getDataType(classOf[ClassType], i.getTypeName)
- iTyp.convert(i, Multiplicity.REQUIRED)
- }
-
- typedInstances.foreach { i =>
- println(i)
- }
- }
-
- @Test(expectedExceptions = Array(classOf[AtlasException]) , expectedExceptionsMessageRegExp = "A multiplicty of more than one requires a collection type for attribute 'stringSet'")
- def WrongMultiplicity {
- val b = new TypesBuilder
- import b._
- val tDef = types {
- _class("Wrong") {
- "name" ~ (string, required)
- "stringSet" ~ (string, multiplicty(0, Int.MaxValue, true))
- }
- }
- TypeSystem.getInstance().defineTypes(tDef)
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/TypesBuilderTest.scala
----------------------------------------------------------------------
diff --git a/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/TypesBuilderTest.scala b/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/TypesBuilderTest.scala
deleted file mode 100644
index d01adb4..0000000
--- a/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/TypesBuilderTest.scala
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.typesystem.builders
-
-import org.apache.atlas.typesystem.json.TypesSerialization
-import org.apache.atlas.typesystem.types.TypeSystem
-import org.testng.annotations.Test
-
-class TypesBuilderTest extends BuilderTest {
-
-
- @Test def test1 {
- TypeSystem.getInstance().defineTypes(tDef)
-
- println(TypesSerialization.toJson(TypeSystem.getInstance(), x => true))
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/typesystem/src/test/scala/org/apache/atlas/typesystem/json/InstanceSerializationTest.scala
----------------------------------------------------------------------
diff --git a/typesystem/src/test/scala/org/apache/atlas/typesystem/json/InstanceSerializationTest.scala b/typesystem/src/test/scala/org/apache/atlas/typesystem/json/InstanceSerializationTest.scala
deleted file mode 100644
index 9e656a5..0000000
--- a/typesystem/src/test/scala/org/apache/atlas/typesystem/json/InstanceSerializationTest.scala
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * 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.typesystem.json
-
-import scala.util.Random
-
-import org.apache.atlas.typesystem.Referenceable
-import org.apache.atlas.typesystem.persistence.Id
-import org.apache.atlas.typesystem.types.DataTypes
-import org.apache.atlas.typesystem.types.TypeSystem
-import org.apache.atlas.typesystem.types.utils.TypesUtil
-import org.testng.Assert.assertEquals
-import org.testng.Assert.assertNotNull
-import org.testng.Assert.assertTrue
-import org.testng.annotations.BeforeClass
-import org.testng.annotations.Test
-
-import com.google.common.collect.ImmutableSet
-
-class InstanceSerializationTest {
- private var typeName: String = null
-
- @BeforeClass def setup {
- typeName = "Random_" + Math.abs(Random.nextInt())
- val clsType = TypesUtil.createClassTypeDef(typeName, "Random-description", ImmutableSet.of[String](),
- TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE))
- TypeSystem.getInstance().defineClassType(clsType)
- }
-
- @Test def testIdentity {
- val entity: Referenceable = new Referenceable(typeName)
- val json: String = InstanceSerialization.toJson(entity, true)
- val entity2: Referenceable = InstanceSerialization.fromJsonReferenceable(json, true)
- assertNotNull(entity2)
- assertEquals(entity2.getId, entity.getId, "Simple conversion failed")
- assertEquals(entity2.getTraits, entity.getTraits, "Traits mismatch")
- }
-
- @Test def testReferenceArrayWithNoState {
- val staticJson = s"""{
- "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Reference",
- "id": {
- "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id",
- "version": 0,
- "typeName": "LoadProcess"
- },
- "typeName": "LoadProcess",
- "values": {
- "inputTables": [{
- "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id",
- "id": "bacfa996-e88e-4d7e-9630-68c9829b10b4",
- "version": 0,
- "typeName": "Table"
- }, {
- "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id",
- "id": "6da06805-3f56-446f-8831-672a65ac2199",
- "version": 0,
- "typeName": "Table"
- }, {
- "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Reference",
- "typeName": "$typeName",
- "values": {}
- "traitNames": []
- "traits": {}
- }
- ],
- "outputTable": {
- "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id",
- "id": "d5c3d6d0-aa10-44c1-b05d-ed9400d2a5ac",
- "version": 0,
- "typeName": "Table"
- },
- "name": "loadSalesDaily"
- },
- "traitNames": [
- "ETL"
- ],
- "traits": {
- "ETL": {
- "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Struct",
- "typeName": "ETL",
- "values": {
- }
- }
- }
- }
- """;
-
- val entity: Referenceable = InstanceSerialization.fromJsonReferenceable(staticJson, true)
- val outputTable = entity.getValuesMap.get("outputTable")
- val inputTables : java.util.List[_] = entity.getValuesMap().get("inputTables").asInstanceOf[java.util.List[_]]
-
- assertTrue(entity.getId.isInstanceOf[Id]);
- assertTrue(outputTable.isInstanceOf[Id]);
- import scala.collection.JavaConversions._
- assertTrue(inputTables(0).isInstanceOf[Id]);
- assertTrue(inputTables(1).isInstanceOf[Id]);
- assertTrue(inputTables(2).isInstanceOf[Referenceable]);
- }
-
- @Test def testMissingStateInId: Unit = {
- val entity: Referenceable = new Referenceable(typeName)
- val staticJson: String = s"""{
- "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Reference",
- "id": {
- "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id",
- "id": "${entity.getId.id}",
- "version":0,
- "typeName": "${entity.getTypeName}",
- },
- "typeName": "${entity.getTypeName}",
- "values": {}
- "traitNames": []
- "traits": {}
- }"""
- val entity2: Referenceable = InstanceSerialization.fromJsonReferenceable(staticJson, true)
- assertNotNull(entity2)
- assertNotNull(entity2.getId)
- assertNotNull(entity2.getId.id) // This creates a new id so the values will not match.
- assertEquals(entity2.getId.typeName, entity.getId.typeName)
- assertEquals(entity2.getId.version, entity.getId.version)
- assertEquals(entity2.getId.state, entity.getId.state)
- assertEquals(entity2.getTypeName, entity.getTypeName, "Type name mismatch")
- assertEquals(entity2.getValuesMap, entity.getValuesMap, "Values mismatch")
- assertEquals(entity2.getTraits, entity.getTraits, "Traits mismatch")
- }
-
- @Test def testMissingId: Unit = {
- val entity: Referenceable = new Referenceable(typeName)
- val staticJson: String = s"""{
- "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Reference",
- "typeName": "${entity.getTypeName}",
- "values": {}
- "traitNames": []
- "traits": {}
- }"""
- val entity2: Referenceable = InstanceSerialization.fromJsonReferenceable(staticJson, true)
- assertNotNull(entity2)
- assertNotNull(entity2.getId)
- assertNotNull(entity2.getId.id) // This creates a new id so the values will not match.
- assertEquals(entity2.getId.typeName, entity.getId.typeName)
- assertEquals(entity2.getId.version, entity.getId.version)
- assertEquals(entity2.getId.state, entity.getId.state)
- assertEquals(entity2.getTypeName, entity.getTypeName, "Type name mismatch")
- assertEquals(entity2.getValuesMap, entity.getValuesMap, "Values mismatch")
- assertEquals(entity2.getTraits, entity.getTraits, "Traits mismatch")
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/typesystem/src/test/scala/org/apache/atlas/typesystem/json/SerializationTest.scala
----------------------------------------------------------------------
diff --git a/typesystem/src/test/scala/org/apache/atlas/typesystem/json/SerializationTest.scala b/typesystem/src/test/scala/org/apache/atlas/typesystem/json/SerializationTest.scala
deleted file mode 100755
index 931773d..0000000
--- a/typesystem/src/test/scala/org/apache/atlas/typesystem/json/SerializationTest.scala
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- * 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.typesystem.json
-
-import com.google.common.collect.ImmutableList
-import org.apache.atlas.typesystem.persistence.Id.EntityState
-import org.apache.atlas.typesystem.persistence.{Id, ReferenceableInstance, StructInstance}
-import org.apache.atlas.typesystem.types._
-import org.apache.atlas.typesystem.types.utils.TypesUtil
-import org.apache.atlas.typesystem.{ITypedReferenceableInstance, ITypedStruct, Referenceable, Struct}
-import org.json4s.native.JsonMethods._
-import org.json4s.native.Serialization.{write => swrite, _}
-import org.json4s.{NoTypeHints, _}
-import org.testng.Assert
-import org.testng.annotations.{BeforeMethod,Test}
-import com.google.common.collect.ImmutableSet
-import org.testng.Assert.assertEquals
-
-class SerializationTest extends BaseTest {
-
- private[atlas] var structType: StructType = null
- private[atlas] var recursiveStructType: StructType = null
-
- @BeforeMethod
- override def setup {
- super.setup
- structType = getTypeSystem.getDataType(classOf[StructType], BaseTest.STRUCT_TYPE_1).asInstanceOf[StructType]
- recursiveStructType = getTypeSystem.getDataType(classOf[StructType], BaseTest.STRUCT_TYPE_2).asInstanceOf[StructType]
- }
-
- @Test def test1 {
- val s: Struct = BaseTest.createStruct()
- val ts: ITypedStruct = structType.convert(s, Multiplicity.REQUIRED)
-
- Assert.assertEquals(ts.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \t" + BaseTest.TEST_DATE + "\n\tm : \t[1, 1]\n\tn : \t[1.1, 1.1]\n\to : \t{a=1.0, b=2.0}\n\tp : \t\n\tq : \t<null>\n\tr : \t{a=}\n}")
-
- implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer +
- new BigDecimalSerializer + new BigIntegerSerializer
-
- //Json representation
- val ser = swrite(ts)
- val ser1 = swrite(ts.toString)
- Assert.assertEquals(ser1, "\"{\\n\\ta : \\t1\\n\\tb : \\ttrue\\n\\tc : \\t1\\n\\td : \\t2\\n\\te : \\t1\\n\\tf : \\t1\\n\\tg : \\t1\\n\\th : \\t1.0\\n\\ti : \\t1.0\\n\\tj : \\t1\\n\\tk : \\t1\\n\\tl : \\t" + BaseTest.TEST_DATE + "\\n\\tm : \\t[1, 1]\\n\\tn : \\t[1.1, 1.1]\\n\\to : \\t{a=1.0, b=2.0}\\n\\tp : \\t\\n\\tq : \\t<null>\\n\\tr : \\t{a=}\\n}\"");
- // Typed Struct read back
- val ts1 = read[StructInstance](ser)
- Assert.assertEquals(ts1.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \t" + BaseTest.TEST_DATE + "\n\tm : \t[1, 1]\n\tn : \t[1.100000000000000088817841970012523233890533447265625, 1.100000000000000088817841970012523233890533447265625]\n\to : \t{a=1.0, b=2.0}\n\tp : \t\n\tq : \t<null>\n\tr : \t{a=}\n}")
- }
-
- @Test def test2 {
- val s: Struct = BaseTest.createStruct()
- val ts: ITypedStruct = structType.convert(s, Multiplicity.REQUIRED)
-
- implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer +
- new BigDecimalSerializer + new BigIntegerSerializer
-
- val ts1 = read[StructInstance](
- """
- {"$typeName$":"t1","e":1,"n":[1.1,1.1],"h":1.0,"b":true,"k":1,"j":1,"d":2,"m":[1,1],"g":1,"a":1,"i":1.0,
- "c":1,"l":"2014-12-03T19:38:55.053Z","f":1,"o":{"a":1.0,"b":2.0}}""")
- // Typed Struct read from string
- Assert.assertEquals(ts1.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \t2014-12-03T19:38:55.053Z\n\tm : \t[1, 1]\n\tn : \t[1.100000000000000088817841970012523233890533447265625, 1.100000000000000088817841970012523233890533447265625]\n\to : \t{a=1.0, b=2.0}\n\tp : \t<null>\n\tq : \t<null>\n\tr : \t<null>\n}")
- }
-
- @Test def testTrait {
- val A: HierarchicalTypeDefinition[TraitType] = TypesUtil.createTraitTypeDef("A", null,
- TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE),
- TypesUtil.createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE),
- TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
- TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE))
- val B: HierarchicalTypeDefinition[TraitType] = TypesUtil.createTraitTypeDef(
- "B", ImmutableSet.of[String]("A"),
- TypesUtil.createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE))
- val C: HierarchicalTypeDefinition[TraitType] = TypesUtil.createTraitTypeDef(
- "C", ImmutableSet.of[String]("A"),
- TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE))
- val D: HierarchicalTypeDefinition[TraitType] = TypesUtil.createTraitTypeDef(
- "D", ImmutableSet.of[String]("B", "C"),
- TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE))
-
- defineTraits(A, B, C, D)
-
- val DType: TraitType = getTypeSystem.getDataType(classOf[TraitType], "D").asInstanceOf[TraitType]
- val s1: Struct = new Struct("D")
- s1.set("d", 1)
- s1.set("c", 1)
- s1.set("b", true)
- s1.set("a", 1)
- s1.set("A.B.D.b", true)
- s1.set("A.B.D.c", 2)
- s1.set("A.B.D.d", 2)
- s1.set("A.C.D.a", 3)
- s1.set("A.C.D.b", false)
- s1.set("A.C.D.c", 3)
- s1.set("A.C.D.d", 3)
-
- val s: Struct = BaseTest.createStruct()
- val ts: ITypedStruct = DType.convert(s1, Multiplicity.REQUIRED)
-
- implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer +
- new BigDecimalSerializer + new BigIntegerSerializer
-
- // Typed Struct :
- Assert.assertEquals(ts.toString, "{\n\td : \t1\n\tb : \ttrue\n\tc : \t1\n\ta : \t1\n\tA.B.D.b : \ttrue\n\tA.B.D.c : \t2\n\tA.B.D.d : \t2\n\tA.C.D.a : \t3\n\tA.C.D.b : \tfalse\n\tA.C.D.c : \t3\n\tA.C.D.d : \t3\n}")
-
- // Json representation :
- val ser = swrite(ts)
- Assert.assertEquals(ser, "{\"$typeName$\":\"D\",\"A.C.D.d\":3,\"A.B.D.c\":2,\"b\":true,\"A.C.D.c\":3,\"d\":1,\"A.B.D.b\":true,\"a\":1,\"A.C.D.b\":false,\"A.B.D.d\":2,\"c\":1,\"A.C.D.a\":3}")
-
- val ts1 = read[StructInstance](
- """
- {"$typeName$":"D","A.C.D.d":3,"A.B.D.c":2,"b":true,"A.C.D.c":3,"d":1,
- "A.B.D.b":true,"a":1,"A.C.D.b":false,"A.B.D.d":2,"c":1,"A.C.D.a":3}""")
- // Typed Struct read from string:
- Assert.assertEquals(ts1.toString, "{\n\td : \t1\n\tb : \ttrue\n\tc : \t1\n\ta : \t1\n\tA.B.D.b : \ttrue\n\tA.B.D.c : \t2\n\tA.B.D.d : \t2\n\tA.C.D.a : \t3\n\tA.C.D.b : \tfalse\n\tA.C.D.c : \t3\n\tA.C.D.d : \t3\n}")
- }
-
- def defineHRTypes(ts: TypeSystem) : Unit = {
- val deptTypeDef: HierarchicalTypeDefinition[ClassType] = TypesUtil.createClassTypeDef(
- "Department",
- ImmutableSet.of[String],
- TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE),
- new AttributeDefinition("employees", String.format("array<%s>", "Person"),
- Multiplicity.COLLECTION, true, "department"))
- val personTypeDef: HierarchicalTypeDefinition[ClassType] = TypesUtil.createClassTypeDef(
- "Person", ImmutableSet.of[String],
- TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE),
- new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"),
- new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates"))
- val managerTypeDef: HierarchicalTypeDefinition[ClassType] = TypesUtil.createClassTypeDef(
- "Manager", ImmutableSet.of[String]("Person"),
- new AttributeDefinition("subordinates", String.format("array<%s>", "Person"),
- Multiplicity.COLLECTION, false, "manager"))
- val securityClearanceTypeDef: HierarchicalTypeDefinition[TraitType] =
- TypesUtil.createTraitTypeDef("SecurityClearance", ImmutableSet.of[String],
- TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE))
-
- ts.defineTypes(ImmutableList.of[EnumTypeDefinition], ImmutableList.of[StructTypeDefinition],
- ImmutableList.of[HierarchicalTypeDefinition[TraitType]](securityClearanceTypeDef),
- ImmutableList.of[HierarchicalTypeDefinition[ClassType]](deptTypeDef, personTypeDef, managerTypeDef)
- )
-
- }
-
- def defineHRDept() : Referenceable = {
- val hrDept: Referenceable = new Referenceable("Department")
- val john: Referenceable = new Referenceable("Person")
- val jane: Referenceable = new Referenceable("Manager", "SecurityClearance")
- hrDept.set("name", "hr")
- john.set("name", "John")
- john.set("department", hrDept.getId)
- jane.set("name", "Jane")
- jane.set("department", hrDept.getId)
- john.set("manager", jane.getId)
- hrDept.set("employees", ImmutableList.of[Referenceable](john, jane))
- jane.set("subordinates", ImmutableList.of[Id](john.getId))
- jane.getTrait("SecurityClearance").set("level", 1)
- hrDept
- }
-
- @Test def testClass {
-
- val ts: TypeSystem = getTypeSystem
- defineHRTypes(ts)
- val hrDept: Referenceable = defineHRDept()
-
- val deptType: ClassType = ts.getDataType(classOf[ClassType], "Department")
- val hrDept2: ITypedReferenceableInstance = deptType.convert(hrDept, Multiplicity.REQUIRED)
-
- println(s"HR Dept Object Graph:\n${hrDept2}\n")
-
- implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer +
- new TypedReferenceableInstanceSerializer + new BigDecimalSerializer + new BigIntegerSerializer
-
- val ser = swrite(hrDept2)
- println(s"HR Dept JSON:\n${pretty(render(parse(ser)))}\n")
-
- println(s"HR Dept Object Graph read from JSON:${read[ReferenceableInstance](ser)}\n")
- }
-
- @Test def testReference {
-
- val ts: TypeSystem = getTypeSystem
- defineHRTypes(ts)
- val hrDept: Referenceable = defineHRDept()
-
-
- val jsonStr = InstanceSerialization.toJson(hrDept)
- val hrDept2 = InstanceSerialization.fromJsonReferenceable(jsonStr)
-
- val deptType: ClassType = ts.getDataType(classOf[ClassType], "Department")
- val hrDept3: ITypedReferenceableInstance = deptType.convert(hrDept2, Multiplicity.REQUIRED)
-
- println(s"HR Dept Object Graph:\n${hrDept3}\n")
-
- implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer +
- new TypedReferenceableInstanceSerializer + new BigDecimalSerializer + new BigIntegerSerializer
-
- val ser = swrite(hrDept3)
- println(s"HR Dept JSON:\n${pretty(render(parse(ser)))}\n")
-
- println(s"HR Dept Object Graph read from JSON:${read[ReferenceableInstance](ser)}\n")
- }
-
- @Test def testReference2 {
-
- val ts: TypeSystem = getTypeSystem
- defineHRTypes(ts)
- val hrDept: Referenceable = defineHRDept()
-
- val deptType: ClassType = ts.getDataType(classOf[ClassType], "Department")
- val hrDept2: ITypedReferenceableInstance = deptType.convert(hrDept, Multiplicity.REQUIRED)
-
- val jsonStr = InstanceSerialization.toJson(hrDept2)
- val hrDept3 = InstanceSerialization.fromJsonReferenceable(jsonStr)
-
- val hrDept4: ITypedReferenceableInstance = deptType.convert(hrDept2, Multiplicity.REQUIRED)
-
- println(s"HR Dept Object Graph:\n${hrDept4}\n")
-
- implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer +
- new TypedReferenceableInstanceSerializer + new BigDecimalSerializer + new BigIntegerSerializer
-
- val ser = swrite(hrDept4)
- println(s"HR Dept JSON:\n${pretty(render(parse(ser)))}\n")
-
- println(s"HR Dept Object Graph read from JSON:${read[ReferenceableInstance](ser)}\n")
-
- }
-
- @Test def testIdSerde: Unit = {
-
- val ts: TypeSystem = getTypeSystem
- defineHRTypes(ts)
- val hrDept: Referenceable = defineHRDept()
- //default state is actiev by default
- assertEquals(hrDept.getId.getState, EntityState.ACTIVE)
-
- val deptType: ClassType = ts.getDataType(classOf[ClassType], "Department")
- val hrDept2: ITypedReferenceableInstance = deptType.convert(hrDept, Multiplicity.REQUIRED)
- hrDept2.getId.state = EntityState.DELETED
-
- //updated state should be maintained correctly after serialisation-deserialisation
- val deptJson: String = InstanceSerialization.toJson(hrDept2, true)
- val deserDept: Referenceable = InstanceSerialization.fromJsonReferenceable(deptJson, true)
- assertEquals(deserDept.getId.getState, EntityState.DELETED)
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/typesystem/src/test/scala/org/apache/atlas/typesystem/json/TypesSerializationTest.scala
----------------------------------------------------------------------
diff --git a/typesystem/src/test/scala/org/apache/atlas/typesystem/json/TypesSerializationTest.scala b/typesystem/src/test/scala/org/apache/atlas/typesystem/json/TypesSerializationTest.scala
deleted file mode 100755
index cfd4bdb..0000000
--- a/typesystem/src/test/scala/org/apache/atlas/typesystem/json/TypesSerializationTest.scala
+++ /dev/null
@@ -1,342 +0,0 @@
-/**
- * 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.typesystem.json
-
-import com.google.common.collect.ImmutableList
-import org.apache.atlas.typesystem.types._
-import org.testng.Assert
-import org.testng.annotations.Test
-
-class TypesSerializationTest extends BaseTest with TypeHelpers {
-
- @Test def test1: Unit = {
-
- val ts = getTypeSystem
-
- val sDef = structDef("ts1", requiredAttr("a", DataTypes.INT_TYPE),
- optionalAttr("b", DataTypes.BOOLEAN_TYPE),
- optionalAttr("c", DataTypes.BYTE_TYPE),
- optionalAttr("d", DataTypes.SHORT_TYPE),
- optionalAttr("e", DataTypes.INT_TYPE),
- optionalAttr("f", DataTypes.INT_TYPE),
- optionalAttr("g", DataTypes.LONG_TYPE),
- optionalAttr("h", DataTypes.FLOAT_TYPE),
- optionalAttr("i", DataTypes.DOUBLE_TYPE),
- optionalAttr("j", DataTypes.BIGINTEGER_TYPE),
- optionalAttr("k", DataTypes.BIGDECIMAL_TYPE),
- optionalAttr("l", DataTypes.DATE_TYPE),
- optionalAttr("m", DataTypes.arrayTypeName(DataTypes.INT_TYPE)),
- optionalAttr("n", DataTypes.arrayTypeName(DataTypes.BIGDECIMAL_TYPE)),
- optionalAttr("o", DataTypes.mapTypeName(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)))
-
-
- ts.defineTypes(ImmutableList.of[EnumTypeDefinition], ImmutableList.of[StructTypeDefinition](sDef),
- ImmutableList.of[HierarchicalTypeDefinition[TraitType]],
- ImmutableList.of[HierarchicalTypeDefinition[ClassType]]
- )
-
- val A: HierarchicalTypeDefinition[TraitType] = createTraitTypeDef("A", List(),
- requiredAttr("a", DataTypes.INT_TYPE),
- optionalAttr("b", DataTypes.BOOLEAN_TYPE),
- optionalAttr("c", DataTypes.BYTE_TYPE),
- optionalAttr("d", DataTypes.SHORT_TYPE))
- val B: HierarchicalTypeDefinition[TraitType] =
- createTraitTypeDef("B", Seq("A"), optionalAttr("b", DataTypes.BOOLEAN_TYPE))
- val C: HierarchicalTypeDefinition[TraitType] =
- createTraitTypeDef("C", Seq("A"), optionalAttr("c", DataTypes.BYTE_TYPE))
- val D: HierarchicalTypeDefinition[TraitType] =
- createTraitTypeDef("D", Seq("B", "C"), optionalAttr("d", DataTypes.SHORT_TYPE))
-
- defineTraits(ts, A, B, C, D)
-
- ts.defineEnumType("HiveObjectType",
- new EnumValue("GLOBAL", 1),
- new EnumValue("DATABASE", 2),
- new EnumValue("TABLE", 3),
- new EnumValue("PARTITION", 4),
- new EnumValue("COLUMN", 5))
-
- ts.defineEnumType("PrincipalType",
- new EnumValue("USER", 1),
- new EnumValue("ROLE", 2),
- new EnumValue("GROUP", 3))
-
- ts.defineEnumType("TxnState",
- new EnumValue("COMMITTED", 1),
- new EnumValue("ABORTED", 2),
- new EnumValue("OPEN", 3))
-
- ts.defineEnumType("LockLevel",
- new EnumValue("DB", 1),
- new EnumValue("TABLE", 2),
- new EnumValue("PARTITION", 3))
-
- ts.defineEnumType("TestType", "TestType-description",
- new EnumValue("A", 1),
- new EnumValue("B", 2),
- new EnumValue("C", 3))
-
- defineClassType(ts, createClassTypeDef("t4", List(),
- requiredAttr("a", DataTypes.INT_TYPE),
- optionalAttr("b", DataTypes.BOOLEAN_TYPE),
- optionalAttr("c", DataTypes.BYTE_TYPE),
- optionalAttr("d", DataTypes.SHORT_TYPE),
- optionalAttr("enum1", ts.getDataType(classOf[EnumType], "HiveObjectType")),
- optionalAttr("e", DataTypes.INT_TYPE),
- optionalAttr("f", DataTypes.INT_TYPE),
- optionalAttr("g", DataTypes.LONG_TYPE),
- optionalAttr("enum2", ts.getDataType(classOf[EnumType], "PrincipalType")),
- optionalAttr("h", DataTypes.FLOAT_TYPE),
- optionalAttr("i", DataTypes.DOUBLE_TYPE),
- optionalAttr("j", DataTypes.BIGINTEGER_TYPE),
- optionalAttr("k", DataTypes.BIGDECIMAL_TYPE),
- optionalAttr("enum3", ts.getDataType(classOf[EnumType], "TxnState")),
- optionalAttr("l", DataTypes.DATE_TYPE),
- optionalAttr("m", ts.defineArrayType(DataTypes.INT_TYPE)),
- optionalAttr("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)),
- optionalAttr("o", ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)),
- optionalAttr("enum4", ts.getDataType(classOf[EnumType], "LockLevel"))))
-
- val deptTypeDef: HierarchicalTypeDefinition[ClassType] = createClassTypeDef("Department", List(),
- requiredAttr("name", DataTypes.STRING_TYPE),
- new AttributeDefinition("employees", String.format("array<%s>", "Person"),
- Multiplicity.COLLECTION, true, "department"))
- val personTypeDef: HierarchicalTypeDefinition[ClassType] = createClassTypeDef("Person", List(),
- requiredAttr("name", DataTypes.STRING_TYPE),
- new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"),
- new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates")
- )
- val managerTypeDef: HierarchicalTypeDefinition[ClassType] = createClassTypeDef("Manager", List("Person"),
- new AttributeDefinition("subordinates", String.format("array<%s>", "Person"),
- Multiplicity.COLLECTION, false, "manager")
- )
- val securityClearanceTypeDef: HierarchicalTypeDefinition[TraitType] = createTraitTypeDef("SecurityClearance", List(),
- requiredAttr("level", DataTypes.INT_TYPE)
- )
-
- val securityClearanceTypeDefWithDesc: HierarchicalTypeDefinition[TraitType] = createTraitTypeDef("SecurityClearance2", Some("SecurityClearance-Description"), List(),
- requiredAttr("level", DataTypes.INT_TYPE)
- )
- ts.defineTypes(ImmutableList.of[EnumTypeDefinition], ImmutableList.of[StructTypeDefinition],
- ImmutableList.of[HierarchicalTypeDefinition[TraitType]](securityClearanceTypeDef, securityClearanceTypeDefWithDesc),
- ImmutableList.of[HierarchicalTypeDefinition[ClassType]](deptTypeDef, personTypeDef, managerTypeDef))
-
- val ser = TypesSerialization.toJson(ts, _ => true)
-
- val typesDef1 = TypesSerialization.fromJson(ser)
-
- val ts1 = TypeSystem.getInstance()
- ts1.reset()
-
- typesDef1.enumTypes.foreach(ts1.defineEnumType(_))
-
- ts1.defineTypes(ImmutableList.of[EnumTypeDefinition], ImmutableList.copyOf(typesDef1.structTypes.toArray),
- ImmutableList.copyOf(typesDef1.traitTypes.toArray),
- ImmutableList.copyOf(typesDef1.classTypes.toArray)
- )
- val ser2 = TypesSerialization.toJson(ts1, _ => true)
- val typesDef2 = TypesSerialization.fromJson(ser2)
-
- Assert.assertEquals(typesDef1, typesDef2)
- }
-
- @Test def test2: Unit = {
-
- val sDef = structDef("ts1", requiredAttr("a", DataTypes.INT_TYPE),
- optionalAttr("b", DataTypes.BOOLEAN_TYPE),
- optionalAttr("c", DataTypes.BYTE_TYPE),
- optionalAttr("d", DataTypes.SHORT_TYPE),
- optionalAttr("e", DataTypes.INT_TYPE),
- optionalAttr("f", DataTypes.INT_TYPE),
- optionalAttr("g", DataTypes.LONG_TYPE),
- optionalAttr("h", DataTypes.FLOAT_TYPE),
- optionalAttr("i", DataTypes.DOUBLE_TYPE),
- optionalAttr("j", DataTypes.BIGINTEGER_TYPE),
- optionalAttr("k", DataTypes.BIGDECIMAL_TYPE),
- optionalAttr("l", DataTypes.DATE_TYPE),
- optionalAttr("m", DataTypes.arrayTypeName(DataTypes.INT_TYPE)),
- optionalAttr("n", DataTypes.arrayTypeName(DataTypes.BIGDECIMAL_TYPE)),
- optionalAttr("o", DataTypes.mapTypeName(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)))
-
-
-
- val ser2 = TypesSerialization.toJson(sDef)
- val typesDef2 = TypesSerialization.fromJson(ser2)
-
- Assert.assertEquals(sDef, typesDef2.structTypes(0))
- }
-
- @Test def test3: Unit = {
-
- val sDef = structDef("ts1", requiredAttr("a", DataTypes.INT_TYPE),
- optionalAttr("b", DataTypes.BOOLEAN_TYPE),
- optionalAttr("c", DataTypes.BYTE_TYPE),
- optionalAttr("d", DataTypes.SHORT_TYPE),
- optionalAttr("e", DataTypes.INT_TYPE),
- optionalAttr("f", DataTypes.INT_TYPE),
- optionalAttr("g", DataTypes.LONG_TYPE),
- optionalAttr("h", DataTypes.FLOAT_TYPE),
- optionalAttr("i", DataTypes.DOUBLE_TYPE),
- optionalAttr("j", DataTypes.BIGINTEGER_TYPE),
- optionalAttr("k", DataTypes.BIGDECIMAL_TYPE),
- optionalAttr("l", DataTypes.DATE_TYPE),
- optionalAttr("m", DataTypes.arrayTypeName(DataTypes.INT_TYPE)),
- optionalAttr("n", DataTypes.arrayTypeName(DataTypes.BIGDECIMAL_TYPE)),
- optionalAttr("o", DataTypes.mapTypeName(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)))
-
- val ser = TypesSerialization.toJson(sDef)
- val typesDef2 = TypesSerialization.fromJson(ser)
-
- Assert.assertEquals(sDef, typesDef2.structTypes(0))
-
- //Now with description
- val sDef2 = structDef("ts1", Some("ts1-description"), requiredAttr("a", DataTypes.INT_TYPE),
- optionalAttr("b", DataTypes.BOOLEAN_TYPE),
- optionalAttr("c", DataTypes.BYTE_TYPE),
- optionalAttr("d", DataTypes.SHORT_TYPE),
- optionalAttr("e", DataTypes.INT_TYPE),
- optionalAttr("f", DataTypes.INT_TYPE),
- optionalAttr("g", DataTypes.LONG_TYPE),
- optionalAttr("h", DataTypes.FLOAT_TYPE),
- optionalAttr("i", DataTypes.DOUBLE_TYPE),
- optionalAttr("j", DataTypes.BIGINTEGER_TYPE),
- optionalAttr("k", DataTypes.BIGDECIMAL_TYPE),
- optionalAttr("l", DataTypes.DATE_TYPE),
- optionalAttr("m", DataTypes.arrayTypeName(DataTypes.INT_TYPE)),
- optionalAttr("n", DataTypes.arrayTypeName(DataTypes.BIGDECIMAL_TYPE)),
- optionalAttr("o", DataTypes.mapTypeName(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)))
-
- val ser2 = TypesSerialization.toJson(sDef)
- val typesDef3 = TypesSerialization.fromJson(ser2)
- Assert.assertEquals(sDef, typesDef3.structTypes(0))
-
- }
-
- @Test def test4 : Unit = {
-
- val A: HierarchicalTypeDefinition[TraitType] = createTraitTypeDef("A", List(),
- requiredAttr("a", DataTypes.INT_TYPE),
- optionalAttr("b", DataTypes.BOOLEAN_TYPE),
- optionalAttr("c", DataTypes.BYTE_TYPE),
- optionalAttr("d", DataTypes.SHORT_TYPE))
- val B: HierarchicalTypeDefinition[TraitType] =
- createTraitTypeDef("B", Seq("A"), optionalAttr("b", DataTypes.BOOLEAN_TYPE))
- val C: HierarchicalTypeDefinition[TraitType] =
- createTraitTypeDef("C", Seq("A"), optionalAttr("c", DataTypes.BYTE_TYPE))
- val D: HierarchicalTypeDefinition[TraitType] =
- createTraitTypeDef("D", Seq("B", "C"), optionalAttr("d", DataTypes.SHORT_TYPE))
- val E: HierarchicalTypeDefinition[TraitType] =
- createTraitTypeDef("E", Some("E-description"), Seq("B", "C"), optionalAttr("d", DataTypes.SHORT_TYPE))
- val typDefs = Seq(A,B,C,D,E)
- typDefs.foreach { tDef =>
- val ser2 = TypesSerialization.toJson(tDef, true)
- val typesDef2 = TypesSerialization.fromJson(ser2)
- Assert.assertEquals(tDef, typesDef2.traitTypes(0))
-
- }
- }
-
- @Test def test5 : Unit = {
- val e1 = new EnumTypeDefinition("HiveObjectType",
- new EnumValue("GLOBAL", 1),
- new EnumValue("DATABASE", 2),
- new EnumValue("TABLE", 3),
- new EnumValue("PARTITION", 4),
- new EnumValue("COLUMN", 5))
-
- val e2 = new EnumTypeDefinition("PrincipalType",
- new EnumValue("USER", 1),
- new EnumValue("ROLE", 2),
- new EnumValue("GROUP", 3))
-
- val e3 = new EnumTypeDefinition("TxnState",
- new EnumValue("COMMITTED", 1),
- new EnumValue("ABORTED", 2),
- new EnumValue("OPEN", 3))
-
- val e4 = new EnumTypeDefinition("LockLevel",
- new EnumValue("DB", 1),
- new EnumValue("TABLE", 2),
- new EnumValue("PARTITION", 3))
-
- val e5 = new EnumTypeDefinition("LockLevel", "LockLevel-description",
- new EnumValue("DB", 1),
- new EnumValue("TABLE", 2),
- new EnumValue("PARTITION", 3))
-
- val typDefs = Seq(e1,e2,e3,e4,e5)
- typDefs.foreach { tDef =>
- val ser2 = TypesSerialization.toJson(tDef)
- val typesDef2 = TypesSerialization.fromJson(ser2)
- Assert.assertEquals(tDef, typesDef2.enumTypes(0))
-
- }
- }
-
- @Test def test6 : Unit = {
- val typDef = createClassTypeDef("t4", List(),
- requiredAttr("a", DataTypes.INT_TYPE),
- optionalAttr("b", DataTypes.BOOLEAN_TYPE),
- optionalAttr("c", DataTypes.BYTE_TYPE),
- optionalAttr("d", DataTypes.SHORT_TYPE),
- optionalAttr("enum1", "HiveObjectType"),
- optionalAttr("e", DataTypes.INT_TYPE),
- optionalAttr("f", DataTypes.INT_TYPE),
- optionalAttr("g", DataTypes.LONG_TYPE),
- optionalAttr("enum2", "PrincipalType"),
- optionalAttr("h", DataTypes.FLOAT_TYPE),
- optionalAttr("i", DataTypes.DOUBLE_TYPE),
- optionalAttr("j", DataTypes.BIGINTEGER_TYPE),
- optionalAttr("k", DataTypes.BIGDECIMAL_TYPE),
- optionalAttr("enum3", "TxnState"),
- optionalAttr("l", DataTypes.DATE_TYPE),
- optionalAttr("m", DataTypes.INT_TYPE),
- optionalAttr("n", DataTypes.BIGDECIMAL_TYPE),
- optionalAttr("o", DataTypes.mapTypeName(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)),
- optionalAttr("enum4", "LockLevel"))
-
- val deptTypeDef: HierarchicalTypeDefinition[ClassType] = createClassTypeDef("Department", List(),
- requiredAttr("name", DataTypes.STRING_TYPE),
- new AttributeDefinition("employees", String.format("array<%s>", "Person"),
- Multiplicity.COLLECTION, true, "department"))
- val personTypeDef: HierarchicalTypeDefinition[ClassType] = createClassTypeDef("Person", List(),
- requiredAttr("name", DataTypes.STRING_TYPE),
- new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"),
- new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates")
- )
- val managerTypeDef: HierarchicalTypeDefinition[ClassType] = createClassTypeDef("Manager", List("Person"),
- new AttributeDefinition("subordinates", String.format("array<%s>", "Person"),
- Multiplicity.COLLECTION, false, "manager")
- )
-
- val managerTypeDefWithDesc: HierarchicalTypeDefinition[ClassType] = createClassTypeDef("Manager", Some("Manager-description"), List("Person"),
- new AttributeDefinition("subordinates", String.format("array<%s>", "Person"),
- Multiplicity.COLLECTION, false, "manager")
- )
-
- val typDefs = Seq(typDef, deptTypeDef, personTypeDef, managerTypeDef, managerTypeDefWithDesc)
- typDefs.foreach { tDef =>
- val ser2 = TypesSerialization.toJson(tDef, false)
- val typesDef2 = TypesSerialization.fromJson(ser2)
- Assert.assertEquals(tDef, typesDef2.classTypes(0))
-
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java b/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java
index 91ba111..cfc2350 100755
--- a/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java
+++ b/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java
@@ -27,24 +27,18 @@ import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.exception.AtlasBaseException;
-import org.apache.atlas.typesystem.Referenceable;
-import org.apache.atlas.typesystem.TypesDef;
-import org.apache.atlas.typesystem.json.InstanceSerialization;
-import org.apache.atlas.typesystem.json.TypesSerialization;
-import org.apache.atlas.typesystem.persistence.Id;
-import org.apache.atlas.typesystem.types.AttributeDefinition;
-import org.apache.atlas.typesystem.types.ClassType;
-import org.apache.atlas.typesystem.types.DataTypes;
-import org.apache.atlas.typesystem.types.EnumTypeDefinition;
-import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
-import org.apache.atlas.typesystem.types.IDataType;
-import org.apache.atlas.typesystem.types.Multiplicity;
-import org.apache.atlas.typesystem.types.StructTypeDefinition;
-import org.apache.atlas.typesystem.types.TraitType;
+import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
+import org.apache.atlas.model.v1.instance.Id;
+import org.apache.atlas.model.v1.instance.Referenceable;
+import org.apache.atlas.model.v1.typedef.*;
+import org.apache.atlas.type.AtlasType;
import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.configuration.Configuration;
import org.codehaus.jettison.json.JSONArray;
+
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
/**
@@ -142,7 +136,7 @@ public class QuickStart {
void createTypes() throws Exception {
TypesDef typesDef = createTypeDefinitions();
- String typesAsJSON = TypesSerialization.toJson(typesDef);
+ String typesAsJSON = AtlasType.toV1Json(typesDef);
System.out.println("typesAsJSON = " + typesAsJSON);
metadataServiceClient.createType(typesAsJSON);
@@ -151,80 +145,80 @@ public class QuickStart {
}
TypesDef createTypeDefinitions() throws Exception {
- HierarchicalTypeDefinition<ClassType> dbClsDef = TypesUtil
+ ClassTypeDefinition dbClsDef = TypesUtil
.createClassTypeDef(DATABASE_TYPE, DATABASE_TYPE, null,
- TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE),
- attrDef("description", DataTypes.STRING_TYPE), attrDef("locationUri", DataTypes.STRING_TYPE),
- attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE));
+ TypesUtil.createUniqueRequiredAttrDef("name", AtlasBaseTypeDef.ATLAS_TYPE_STRING),
+ attrDef("description", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("locationUri", AtlasBaseTypeDef.ATLAS_TYPE_STRING),
+ attrDef("owner", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("createTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG));
- HierarchicalTypeDefinition<ClassType> storageDescClsDef = TypesUtil
- .createClassTypeDef(STORAGE_DESC_TYPE, STORAGE_DESC_TYPE, null, attrDef("location", DataTypes.STRING_TYPE),
- attrDef("inputFormat", DataTypes.STRING_TYPE), attrDef("outputFormat", DataTypes.STRING_TYPE),
- attrDef("compressed", DataTypes.STRING_TYPE, Multiplicity.REQUIRED, false, null));
+ ClassTypeDefinition storageDescClsDef = TypesUtil
+ .createClassTypeDef(STORAGE_DESC_TYPE, STORAGE_DESC_TYPE, null, attrDef("location", AtlasBaseTypeDef.ATLAS_TYPE_STRING),
+ attrDef("inputFormat", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("outputFormat", AtlasBaseTypeDef.ATLAS_TYPE_STRING),
+ attrDef("compressed", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED, false, null));
- HierarchicalTypeDefinition<ClassType> columnClsDef = TypesUtil
- .createClassTypeDef(COLUMN_TYPE, COLUMN_TYPE, null, attrDef("name", DataTypes.STRING_TYPE),
- attrDef("dataType", DataTypes.STRING_TYPE), attrDef("comment", DataTypes.STRING_TYPE));
+ ClassTypeDefinition columnClsDef = TypesUtil
+ .createClassTypeDef(COLUMN_TYPE, COLUMN_TYPE, null, attrDef("name", AtlasBaseTypeDef.ATLAS_TYPE_STRING),
+ attrDef("dataType", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("comment", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
- HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil
+ ClassTypeDefinition tblClsDef = TypesUtil
.createClassTypeDef(TABLE_TYPE, TABLE_TYPE, ImmutableSet.of("DataSet"),
new AttributeDefinition(DB_ATTRIBUTE, DATABASE_TYPE, Multiplicity.REQUIRED, false, null),
new AttributeDefinition("sd", STORAGE_DESC_TYPE, Multiplicity.REQUIRED, true, null),
- attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE),
- attrDef("lastAccessTime", DataTypes.LONG_TYPE), attrDef("retention", DataTypes.LONG_TYPE),
- attrDef("viewOriginalText", DataTypes.STRING_TYPE),
- attrDef("viewExpandedText", DataTypes.STRING_TYPE), attrDef("tableType", DataTypes.STRING_TYPE),
- attrDef("temporary", DataTypes.BOOLEAN_TYPE),
- new AttributeDefinition(COLUMNS_ATTRIBUTE, DataTypes.arrayTypeName(COLUMN_TYPE),
+ attrDef("owner", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("createTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG),
+ attrDef("lastAccessTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG), attrDef("retention", AtlasBaseTypeDef.ATLAS_TYPE_LONG),
+ attrDef("viewOriginalText", AtlasBaseTypeDef.ATLAS_TYPE_STRING),
+ attrDef("viewExpandedText", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("tableType", AtlasBaseTypeDef.ATLAS_TYPE_STRING),
+ attrDef("temporary", AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN),
+ new AttributeDefinition(COLUMNS_ATTRIBUTE, AtlasBaseTypeDef.getArrayTypeName(COLUMN_TYPE),
Multiplicity.COLLECTION, true, null));
- HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil
+ ClassTypeDefinition loadProcessClsDef = TypesUtil
.createClassTypeDef(LOAD_PROCESS_TYPE, LOAD_PROCESS_TYPE, ImmutableSet.of("Process"),
- attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.LONG_TYPE),
- attrDef("endTime", DataTypes.LONG_TYPE),
- attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED),
- attrDef("queryPlan", DataTypes.STRING_TYPE, Multiplicity.REQUIRED),
- attrDef("queryId", DataTypes.STRING_TYPE, Multiplicity.REQUIRED),
- attrDef("queryGraph", DataTypes.STRING_TYPE, Multiplicity.REQUIRED));
-
- HierarchicalTypeDefinition<ClassType> viewClsDef = TypesUtil
+ attrDef("userName", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("startTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG),
+ attrDef("endTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG),
+ attrDef("queryText", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED),
+ attrDef("queryPlan", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED),
+ attrDef("queryId", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED),
+ attrDef("queryGraph", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED));
+
+ ClassTypeDefinition viewClsDef = TypesUtil
.createClassTypeDef(VIEW_TYPE, VIEW_TYPE, ImmutableSet.of("DataSet"),
new AttributeDefinition("db", DATABASE_TYPE, Multiplicity.REQUIRED, false, null),
- new AttributeDefinition("inputTables", DataTypes.arrayTypeName(TABLE_TYPE),
+ new AttributeDefinition("inputTables", AtlasBaseTypeDef.getArrayTypeName(TABLE_TYPE),
Multiplicity.COLLECTION, false, null));
- HierarchicalTypeDefinition<TraitType> dimTraitDef = TypesUtil.createTraitTypeDef("Dimension_v1", "Dimension Trait", null);
+ TraitTypeDefinition dimTraitDef = TypesUtil.createTraitTypeDef("Dimension_v1", "Dimension Trait", null);
- HierarchicalTypeDefinition<TraitType> factTraitDef = TypesUtil.createTraitTypeDef("Fact_v1", "Fact Trait", null);
+ TraitTypeDefinition factTraitDef = TypesUtil.createTraitTypeDef("Fact_v1", "Fact Trait", null);
- HierarchicalTypeDefinition<TraitType> piiTraitDef = TypesUtil.createTraitTypeDef("PII_v1", "PII Trait", null);
+ TraitTypeDefinition piiTraitDef = TypesUtil.createTraitTypeDef("PII_v1", "PII Trait", null);
- HierarchicalTypeDefinition<TraitType> metricTraitDef = TypesUtil.createTraitTypeDef("Metric_v1", "Metric Trait", null);
+ TraitTypeDefinition metricTraitDef = TypesUtil.createTraitTypeDef("Metric_v1", "Metric Trait", null);
- HierarchicalTypeDefinition<TraitType> etlTraitDef = TypesUtil.createTraitTypeDef("ETL_v1", "ETL Trait", null);
+ TraitTypeDefinition etlTraitDef = TypesUtil.createTraitTypeDef("ETL_v1", "ETL Trait", null);
- HierarchicalTypeDefinition<TraitType> jdbcTraitDef = TypesUtil.createTraitTypeDef("JdbcAccess_v1", "JdbcAccess Trait", null);
+ TraitTypeDefinition jdbcTraitDef = TypesUtil.createTraitTypeDef("JdbcAccess_v1", "JdbcAccess Trait", null);
- HierarchicalTypeDefinition<TraitType> logTraitDef = TypesUtil.createTraitTypeDef("Log Data_v1", "LogData Trait", null);
+ TraitTypeDefinition logTraitDef = TypesUtil.createTraitTypeDef("Log Data_v1", "LogData Trait", null);
- return TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
- ImmutableList.of(dimTraitDef, factTraitDef, piiTraitDef, metricTraitDef, etlTraitDef, jdbcTraitDef, logTraitDef),
- ImmutableList.of(dbClsDef, storageDescClsDef, columnClsDef, tblClsDef, loadProcessClsDef, viewClsDef));
+ return new TypesDef(Collections.<EnumTypeDefinition>emptyList(), Collections.<StructTypeDefinition>emptyList(),
+ Arrays.asList(dimTraitDef, factTraitDef, piiTraitDef, metricTraitDef, etlTraitDef, jdbcTraitDef, logTraitDef),
+ Arrays.asList(dbClsDef, storageDescClsDef, columnClsDef, tblClsDef, loadProcessClsDef, viewClsDef));
}
- AttributeDefinition attrDef(String name, IDataType dT) {
+ AttributeDefinition attrDef(String name, String dT) {
return attrDef(name, dT, Multiplicity.OPTIONAL, false, null);
}
- AttributeDefinition attrDef(String name, IDataType dT, Multiplicity m) {
+ AttributeDefinition attrDef(String name, String dT, Multiplicity m) {
return attrDef(name, dT, m, false, null);
}
- AttributeDefinition attrDef(String name, IDataType dT, Multiplicity m, boolean isComposite,
+ AttributeDefinition attrDef(String name, String dT, Multiplicity m, boolean isComposite,
String reverseAttributeName) {
Preconditions.checkNotNull(name);
Preconditions.checkNotNull(dT);
- return new AttributeDefinition(name, dT.getName(), m, isComposite, reverseAttributeName);
+ return new AttributeDefinition(name, dT, m, isComposite, reverseAttributeName);
}
void createEntities() throws Exception {
@@ -311,7 +305,7 @@ public class QuickStart {
private Id createInstance(Referenceable referenceable) throws Exception {
String typeName = referenceable.getTypeName();
- String entityJSON = InstanceSerialization.toJson(referenceable, true);
+ String entityJSON = AtlasType.toV1Json(referenceable);
System.out.println("Submitting new entity= " + entityJSON);
List<String> guids = metadataServiceClient.createEntity(entityJSON);
System.out.println("created instance for type " + typeName + ", guid: " + guids);