atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject [1/4] incubator-atlas git commit: ATLAS-1272: updated types bootstrap to load from new format typedef JSON files
Date Tue, 08 Nov 2016 00:00:12 GMT
Repository: incubator-atlas
Updated Branches:
  refs/heads/master 2ea3a455e -> def9e385c


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/def9e385/repository/src/main/java/org/apache/atlas/services/ReservedTypesRegistrar.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/services/ReservedTypesRegistrar.java
b/repository/src/main/java/org/apache/atlas/services/ReservedTypesRegistrar.java
deleted file mode 100644
index e0cabe9..0000000
--- a/repository/src/main/java/org/apache/atlas/services/ReservedTypesRegistrar.java
+++ /dev/null
@@ -1,135 +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.services;
-
-import com.google.common.collect.ImmutableList;
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.typesystem.TypesDef;
-import org.apache.atlas.typesystem.json.TypesSerialization;
-import org.apache.atlas.typesystem.types.*;
-import org.apache.atlas.typesystem.types.utils.TypesUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-
-public class ReservedTypesRegistrar implements IBootstrapTypesRegistrar {
-
-    private static final Logger LOG = LoggerFactory.getLogger(ReservedTypesRegistrar.class);
-
-    static String getTypesDir() {
-        return System.getProperty("atlas.home")+ File.separator+"models";
-    }
-
-    @Override
-    public void registerTypes(String typesDirName, TypeSystem typeSystem, MetadataService
metadataService)
-            throws AtlasException {
-        File typesDir = new File(typesDirName);
-        if (!typesDir.exists()) {
-            LOG.info("No types directory {} found - not registering any reserved types",
typesDirName);
-            return;
-        }
-
-        File[] typeDefFiles = typesDir.listFiles();
-        //TODO - Enforce a dependency order among models registered by definition and not
by modifiedTime as below
-        // Workaround - Sort by modifiedTime to get the dependency of models in the right
order - first hdfs, followed by hive and hive is needed by storm, falcon models.
-        // Sorting them by time will ensure the right order since the modules are in the
correct order in pom.
-        Arrays.sort(typeDefFiles, new Comparator<File>() {
-            public int compare(File f1, File f2) {
-                return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
-            }
-        });
-
-        for (File typeDefFile : typeDefFiles) {
-            try {
-                if (typeDefFile.isFile()) {
-                    String typeDefJSON = new String(Files.readAllBytes(typeDefFile.toPath()),
StandardCharsets.UTF_8);
-                    registerType(typeSystem, metadataService, typeDefFile.getAbsolutePath(),
typeDefJSON);
-                }
-            } catch (IOException e) {
-                LOG.error("error while registering types in file " + typeDefFile.getAbsolutePath(),
e);
-            } catch (AtlasException e) {
-                LOG.error("error while registering types in file " + typeDefFile.getAbsolutePath(),
e);
-                throw e;
-            }
-        }
-
-    }
-
-    void registerType(TypeSystem typeSystem, MetadataService metadataService, String typeDefName,
String typeDefJSON)
-            throws AtlasException {
-        TypesDef typesDef = null;
-        try {
-            typesDef = TypesSerialization.fromJson(typeDefJSON);
-        } catch (Exception e) {
-            LOG.error("Error while deserializing JSON in {}", typeDefName);
-            throw new ReservedTypesRegistrationException("Error while deserializing JSON
in " + typeDefName, e);
-        }
-        List<HierarchicalTypeDefinition<ClassType>> createClassDefList = new
ArrayList<>();
-        List<HierarchicalTypeDefinition<TraitType>> createTraitDefList = new
ArrayList<>();
-        List<EnumTypeDefinition> createEnumDefList = new ArrayList<>();
-        List<StructTypeDefinition> createStructDefList = new ArrayList<>();
-
-        for(HierarchicalTypeDefinition<ClassType> classTypeDef:typesDef.classTypesAsJavaList()){
-            if(!typeSystem.isRegistered(classTypeDef.typeName)){
-                LOG.debug("ClassType {} is not registered. Adding to create type list", classTypeDef.typeName);
-                createClassDefList.add(classTypeDef);
-            }
-        }
-
-        for(HierarchicalTypeDefinition<TraitType> traitTypeDef:typesDef.traitTypesAsJavaList()){
-            if(!typeSystem.isRegistered(traitTypeDef.typeName)){
-                LOG.debug("TraitType {} is not registered. Adding to create type list", traitTypeDef.typeName);
-                createTraitDefList.add(traitTypeDef);
-            }
-        }
-
-        for(StructTypeDefinition structTypeDef:typesDef.structTypesAsJavaList()){
-            if(!typeSystem.isRegistered(structTypeDef.typeName)){
-                LOG.debug("StructType {} is not registered. Adding to create type list",
structTypeDef.typeName);
-                createStructDefList.add(structTypeDef);
-            }
-        }
-
-        for(EnumTypeDefinition enumTypeDef:typesDef.enumTypesAsJavaList()){
-            if(!typeSystem.isRegistered(enumTypeDef.name)){
-                LOG.debug("EnumType {} is not registered. Adding to create type list", enumTypeDef.name);
-                createEnumDefList.add(enumTypeDef);
-            }
-        }
-
-        TypesDef createTypes = TypesUtil.getTypesDef(ImmutableList.copyOf(createEnumDefList),
ImmutableList.copyOf(createStructDefList),
-                ImmutableList.copyOf(createTraitDefList), ImmutableList.copyOf(createClassDefList));
-
-        if (! createTypes.isEmpty()) {
-            String createTypeJSON = TypesSerialization.toJson(createTypes);
-            if (createTypeJSON != null) {
-                metadataService.createType(createTypeJSON);
-                LOG.info("Created types definition JSON {}", createTypeJSON);
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/def9e385/repository/src/main/java/org/apache/atlas/services/ReservedTypesRegistrationException.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/services/ReservedTypesRegistrationException.java
b/repository/src/main/java/org/apache/atlas/services/ReservedTypesRegistrationException.java
deleted file mode 100644
index 4b3b31d..0000000
--- a/repository/src/main/java/org/apache/atlas/services/ReservedTypesRegistrationException.java
+++ /dev/null
@@ -1,26 +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.services;
-
-public class ReservedTypesRegistrationException extends RuntimeException {
-    public ReservedTypesRegistrationException(String message, Exception e) {
-        super(message, e);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/def9e385/repository/src/test/java/org/apache/atlas/BaseRepositoryTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/BaseRepositoryTest.java b/repository/src/test/java/org/apache/atlas/BaseRepositoryTest.java
index 03d155c..8851b79 100644
--- a/repository/src/test/java/org/apache/atlas/BaseRepositoryTest.java
+++ b/repository/src/test/java/org/apache/atlas/BaseRepositoryTest.java
@@ -44,6 +44,9 @@ import org.apache.atlas.typesystem.types.TypeSystem;
 import org.apache.atlas.typesystem.types.utils.TypesUtil;
 import org.testng.annotations.Guice;
 
+import static org.apache.atlas.AtlasClient.PROCESS_ATTRIBUTE_INPUTS;
+import static org.apache.atlas.AtlasClient.PROCESS_ATTRIBUTE_OUTPUTS;
+
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -67,6 +70,7 @@ public class BaseRepositoryTest {
     protected void setUp() throws Exception {
         //force graph initialization / built in type registration
         TestUtils.getGraph();
+        setUpDefaultTypes();
         setUpTypes();
         new GraphBackedSearchIndexer(new AtlasTypeRegistry());
         TestUtils.resetRequestContext();
@@ -395,4 +399,42 @@ public class BaseRepositoryTest {
         // return the reference to created instance with guid
         return new Id(guids.get(guids.size() - 1), 0, referenceable.getTypeName());
     }
+
+    private void setUpDefaultTypes() throws Exception {
+        TypesDef typesDef = createDefaultTypeDefinitions();
+        String typesAsJSON = TypesSerialization.toJson(typesDef);
+        metadataService.createType(typesAsJSON);
+    }
+
+    TypesDef createDefaultTypeDefinitions() {
+        HierarchicalTypeDefinition<ClassType> referenceableType = TypesUtil
+                .createClassTypeDef(AtlasClient.REFERENCEABLE_SUPER_TYPE, ImmutableSet.<String>of(),
+                        new AttributeDefinition(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, true, true, null));
+
+        HierarchicalTypeDefinition<ClassType> assetType = TypesUtil
+                .createClassTypeDef(AtlasClient.ASSET_TYPE, ImmutableSet.<String>of(),
+                        new AttributeDefinition(AtlasClient.NAME, DataTypes.STRING_TYPE.getName(),
Multiplicity.REQUIRED, false, false, true, null),
+                        TypesUtil.createOptionalAttrDef(AtlasClient.DESCRIPTION, DataTypes.STRING_TYPE),
+                        new AttributeDefinition(AtlasClient.OWNER, DataTypes.STRING_TYPE.getName(),
Multiplicity.OPTIONAL, false, false, true, null));
+
+        HierarchicalTypeDefinition<ClassType> infraType = TypesUtil
+                .createClassTypeDef(AtlasClient.INFRASTRUCTURE_SUPER_TYPE,
+                        ImmutableSet.of(AtlasClient.REFERENCEABLE_SUPER_TYPE, AtlasClient.ASSET_TYPE));
+
+        HierarchicalTypeDefinition<ClassType> datasetType = TypesUtil
+                .createClassTypeDef(AtlasClient.DATA_SET_SUPER_TYPE,
+                        ImmutableSet.of(AtlasClient.REFERENCEABLE_SUPER_TYPE, AtlasClient.ASSET_TYPE));
+
+        HierarchicalTypeDefinition<ClassType> processType = TypesUtil
+                .createClassTypeDef(AtlasClient.PROCESS_SUPER_TYPE,
+                        ImmutableSet.of(AtlasClient.REFERENCEABLE_SUPER_TYPE, AtlasClient.ASSET_TYPE),
+                        new AttributeDefinition(PROCESS_ATTRIBUTE_INPUTS, DataTypes.arrayTypeName(AtlasClient.DATA_SET_SUPER_TYPE),
+                                Multiplicity.OPTIONAL, false, null),
+                        new AttributeDefinition(PROCESS_ATTRIBUTE_OUTPUTS, DataTypes.arrayTypeName(AtlasClient.DATA_SET_SUPER_TYPE),
+                                Multiplicity.OPTIONAL, false, null));
+
+        return TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
+                ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
+                ImmutableList.of(referenceableType, assetType, infraType, datasetType, processType));
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/def9e385/repository/src/test/java/org/apache/atlas/TestUtils.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/TestUtils.java b/repository/src/test/java/org/apache/atlas/TestUtils.java
index abb8e94..88edf8f 100755
--- a/repository/src/test/java/org/apache/atlas/TestUtils.java
+++ b/repository/src/test/java/org/apache/atlas/TestUtils.java
@@ -33,7 +33,6 @@ import org.apache.atlas.repository.typestore.GraphBackedTypeStore;
 import org.apache.atlas.repository.typestore.ITypeStore;
 import org.apache.atlas.services.DefaultMetadataService;
 import org.apache.atlas.services.MetadataService;
-import org.apache.atlas.services.ReservedTypesRegistrar;
 import org.apache.atlas.type.AtlasTypeRegistry;
 import org.apache.atlas.typesystem.ITypedReferenceableInstance;
 import org.apache.atlas.typesystem.Referenceable;
@@ -527,7 +526,6 @@ public final class TestUtils {
         ITypeStore typeStore = new GraphBackedTypeStore();
         DefaultMetadataService defaultMetadataService = new DefaultMetadataService(repo,
                 typeStore,
-                new ReservedTypesRegistrar(),
                 Collections.singletonList(indexerProvider),
                 new ArrayList<Provider<EntityChangeListener>>(), TypeSystem.getInstance(),
config, typeCache);
 

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/def9e385/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java
b/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java
index 3ffed90..cdbde1b 100644
--- a/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java
@@ -190,7 +190,7 @@ public class AtlasTypeDefGraphStoreTest {
         try {
             existingTypesDef = typeDefStore.searchTypesDef(new SearchFilter());
         } catch (AtlasBaseException e) {
-            fail("Shouldn't have failed during Search");
+            // ignore
         }
 
         assertNotEquals(atlasTypesDef, existingTypesDef, "Types to be created already exist
in the system");
@@ -204,7 +204,7 @@ public class AtlasTypeDefGraphStoreTest {
             assertTrue(createdTypesDef.getEntityDefs().containsAll(atlasTypesDef.getEntityDefs()),
"EntityDef creation failed");
 
         } catch (AtlasBaseException e) {
-            fail("Creation of Types should've been a success");
+            fail("Creation of Types should've been a success", e);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/def9e385/repository/src/test/java/org/apache/atlas/services/DefaultMetadataServiceMockTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/services/DefaultMetadataServiceMockTest.java
b/repository/src/test/java/org/apache/atlas/services/DefaultMetadataServiceMockTest.java
deleted file mode 100644
index 9722a72..0000000
--- a/repository/src/test/java/org/apache/atlas/services/DefaultMetadataServiceMockTest.java
+++ /dev/null
@@ -1,151 +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.services;
-
-import com.google.inject.Provider;
-
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.listener.EntityChangeListener;
-import org.apache.atlas.listener.TypesChangeListener;
-import org.apache.atlas.repository.MetadataRepository;
-import org.apache.atlas.repository.typestore.ITypeStore;
-import org.apache.atlas.typesystem.types.TypeSystem;
-import org.apache.atlas.ha.HAConfiguration;
-import org.apache.atlas.typesystem.TypesDef;
-import org.apache.atlas.typesystem.types.IDataType;
-import org.apache.commons.configuration.Configuration;
-import org.mockito.Matchers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-public class DefaultMetadataServiceMockTest {
-
-    @Mock
-    private IBootstrapTypesRegistrar typesRegistrar;
-
-    @Mock
-    private TypeSystem typeSystem;
-
-    @Mock
-    private MetadataRepository metadataRepository;
-
-    @Mock
-    private ITypeStore typeStore;
-
-    @Mock
-    private Configuration configuration;
-
-    @BeforeMethod
-    public void setup() {
-        MockitoAnnotations.initMocks(this);
-    }
-
-    @Test
-    public void testShouldInvokeTypesRegistrarOnCreation() throws AtlasException {
-        when(typeSystem.isRegistered(any(String.class))).thenReturn(true);
-        when(configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
-        when(configuration.getBoolean(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(false);
-        DefaultMetadataService defaultMetadataService = new DefaultMetadataService(mock(MetadataRepository.class),
-                mock(ITypeStore.class),
-                typesRegistrar, new ArrayList<Provider<TypesChangeListener>>(),
-                new ArrayList<Provider<EntityChangeListener>>(), typeSystem,
configuration, null);
-
-        verify(typesRegistrar).registerTypes(ReservedTypesRegistrar.getTypesDir(),
-                typeSystem, defaultMetadataService);
-    }
-
-    @Test
-    public void testShouldNotRestoreTypesIfHAIsEnabled() throws AtlasException {
-        when(configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
-        when(configuration.getBoolean(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
-
-        new DefaultMetadataService(metadataRepository, typeStore,
-                typesRegistrar, new ArrayList<Provider<TypesChangeListener>>(),
-                new ArrayList<Provider<EntityChangeListener>>(), typeSystem,
configuration, null);
-
-        verifyZeroInteractions(typeStore);
-        verify(typeSystem, never()).defineTypes(Matchers.<TypesDef>any());
-        verifyZeroInteractions(typesRegistrar);
-    }
-
-    @Test
-    public void testShouldRestoreTypeSystemOnServerActive() throws AtlasException {
-        when(configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
-        when(configuration.getBoolean(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
-
-        TypesDef typesDef = mock(TypesDef.class);
-        when(typeStore.restore()).thenReturn(typesDef);
-        when(typeSystem.isRegistered(any(String.class))).thenReturn(true);
-
-        DefaultMetadataService defaultMetadataService = new DefaultMetadataService(metadataRepository,
-                typeStore,
-                typesRegistrar, new ArrayList<Provider<TypesChangeListener>>(),
-                new ArrayList<Provider<EntityChangeListener>>(), typeSystem,
configuration, null);
-        defaultMetadataService.instanceIsActive();
-
-        verify(typeStore).restore();
-        verify(typeSystem).defineTypes(typesDef);
-        verify(typesRegistrar).registerTypes(ReservedTypesRegistrar.getTypesDir(),
-                typeSystem, defaultMetadataService);
-    }
-
-    @Test
-    public void testShouldOnlyRestoreCacheOnServerActiveIfAlreadyDoneOnce() throws AtlasException
{
-        when(configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
-        when(configuration.getBoolean(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
-
-        TypesDef typesDef = mock(TypesDef.class);
-        when(typeStore.restore()).thenReturn(typesDef);
-        when(typeSystem.isRegistered(any(String.class))).thenReturn(true);
-
-        TypeSystem.TransientTypeSystem transientTypeSystem = mock(TypeSystem.TransientTypeSystem.class);
-        HashMap<String, IDataType> typesAdded = new HashMap<>();
-        when(transientTypeSystem.getTypesAdded()).thenReturn(typesAdded);
-        when(typeSystem.createTransientTypeSystem(typesDef, true)).
-                thenReturn(transientTypeSystem);
-        DefaultMetadataService defaultMetadataService = new DefaultMetadataService(metadataRepository,
-                typeStore,
-                typesRegistrar, new ArrayList<Provider<TypesChangeListener>>(),
-                new ArrayList<Provider<EntityChangeListener>>(), typeSystem,
configuration, null);
-
-        defaultMetadataService.instanceIsActive();
-        defaultMetadataService.instanceIsPassive();
-        defaultMetadataService.instanceIsActive();
-
-        verify(typeStore, times(2)).restore();
-        verify(typeSystem, times(1)).defineTypes(typesDef);
-        verify(typesRegistrar, times(1)).
-                registerTypes(ReservedTypesRegistrar.getTypesDir(), typeSystem, defaultMetadataService);
-        verify(typeSystem, times(1)).createTransientTypeSystem(typesDef, true);
-        verify(typeSystem, times(1)).commitTypes(typesAdded);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/def9e385/repository/src/test/java/org/apache/atlas/services/ReservedTypesRegistrarTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/services/ReservedTypesRegistrarTest.java
b/repository/src/test/java/org/apache/atlas/services/ReservedTypesRegistrarTest.java
deleted file mode 100644
index effab15..0000000
--- a/repository/src/test/java/org/apache/atlas/services/ReservedTypesRegistrarTest.java
+++ /dev/null
@@ -1,103 +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.services;
-
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.TestUtils;
-import org.apache.atlas.typesystem.TypesDef;
-import org.apache.atlas.typesystem.json.TypesSerialization;
-import org.apache.atlas.typesystem.types.TypeSystem;
-import org.apache.atlas.typesystem.types.TypeUtils;
-import org.apache.atlas.typesystem.types.utils.TypesUtil;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-public class ReservedTypesRegistrarTest {
-
-    @Mock
-    private TypeSystem typeSystem;
-
-    @Mock
-    private MetadataService metadataService;
-
-    @BeforeMethod
-    public void setup() {
-        MockitoAnnotations.initMocks(this);
-    }
-
-    @Test
-    public void testRegistrationWithNoFiles() throws AtlasException {
-        IBootstrapTypesRegistrar bootstrapTypesRegistrar = new ReservedTypesRegistrar();
-        bootstrapTypesRegistrar.registerTypes("/some/dir/", typeSystem, metadataService);
-        verifyZeroInteractions(typeSystem);
-    }
-
-    @Test
-    public void testRegisterCreatesTypesUsingMetadataService() throws AtlasException {
-        ReservedTypesRegistrar reservedTypesRegistrar = new ReservedTypesRegistrar();
-        TypesDef typesDef = TestUtils.defineHiveTypes();
-        String typesJson = TypesSerialization.toJson(typesDef);
-        reservedTypesRegistrar.registerType(typeSystem, metadataService, "/some/file/model.json",
typesJson);
-        verify(metadataService).createType(typesJson);
-    }
-
-    @Test(expectedExceptions = ReservedTypesRegistrationException.class)
-    public void testRegisterFailsIfErrorInJson() throws AtlasException {
-        ReservedTypesRegistrar reservedTypesRegistrar = new ReservedTypesRegistrar();
-        reservedTypesRegistrar.registerType(typeSystem, metadataService, "/some/file/model.json",
"invalid json");
-    }
-
-    @Test(expectedExceptions = AtlasException.class)
-    public void testRegisterFailsOnTypeCreationException() throws AtlasException {
-        ReservedTypesRegistrar reservedTypesRegistrar = new ReservedTypesRegistrar();
-        TypesDef typesDef = TestUtils.defineHiveTypes();
-        String typesJson = TypesSerialization.toJson(typesDef);
-        when(metadataService.createType(typesJson)).thenThrow(new AtlasException("some exception"));
-        reservedTypesRegistrar.registerType(typeSystem, metadataService, "/some/file/model.json",
typesJson);
-    }
-
-    @Test
-    public void testCreateAndUpdateType() throws AtlasException{
-        ReservedTypesRegistrar reservedTypesRegistrar = new ReservedTypesRegistrar();
-        TypesDef typesDef = TestUtils.simpleType();
-        String typesJson = TypesSerialization.toJson(typesDef);
-        reservedTypesRegistrar.registerType(typeSystem, metadataService, "/some/file/model.json",
typesJson);
-        verify(metadataService).createType(typesJson);
-
-        //test update simple type
-        TypesDef updatedTypesDef = TestUtils.simpleTypeUpdated();
-        String updatedTypesJson = TypesSerialization.toJson(updatedTypesDef);
-        TypesDef simpleTypeUpdatedDiff = TestUtils.simpleTypeUpdatedDiff();
-        String simpleTypeUpdatedDiffJson = TypesSerialization.toJson(simpleTypeUpdatedDiff);
-        when(typeSystem.isRegistered("h_type")).thenReturn(true);
-        when(typeSystem.isRegistered("t_type")).thenReturn(true);
-        when(typeSystem.isRegistered("s_type")).thenReturn(true);
-        when(typeSystem.isRegistered("e_type")).thenReturn(true);
-        reservedTypesRegistrar.registerType(typeSystem, metadataService, "/some/file/model.json",
updatedTypesJson);
-        verify(metadataService).createType(simpleTypeUpdatedDiffJson);
-    }
-}


Mime
View raw message