Repository: atlas
Updated Branches:
  refs/heads/0.8-incubating 1b2471e34 -> 7963525a4


ATLAS-2014: populate createdBy, updatedBy fields on type create and update

(cherry picked from commit 52489d6003ac8c227e048d808175024dc9fe6724)


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/7963525a
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/7963525a
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/7963525a

Branch: refs/heads/0.8-incubating
Commit: 7963525a43372a4fbcc0ac541939e3195192d49c
Parents: 1b2471e
Author: Madhan Neethiraj <mad...@apache.org>
Authored: Tue Aug 1 15:47:34 2017 -0700
Committer: Madhan Neethiraj <mad...@apache.org>
Committed: Wed Aug 2 00:14:30 2017 -0700

----------------------------------------------------------------------
 .../test/java/org/apache/atlas/TestUtilsV2.java | 84 +++++++++++++++++---
 .../store/graph/AtlasTypeDefGraphStore.java     |  6 ++
 .../graph/v1/AtlasTypeDefGraphStoreV1.java      | 22 +++++
 .../repository/impexp/ExportServiceTest.java    |  8 ++
 .../repository/impexp/ImportServiceTest.java    |  9 +++
 .../impexp/ZipFileResourceTestUtils.java        |  5 ++
 .../store/graph/AtlasTypeDefGraphStoreTest.java |  8 ++
 .../graph/v1/AtlasDeleteHandlerV1Test.java      | 14 ++--
 .../store/graph/v1/AtlasEntityStoreV1Test.java  |  4 +
 .../graph/v1/InverseReferenceUpdateV1Test.java  |  4 +
 10 files changed, 149 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/7963525a/intg/src/test/java/org/apache/atlas/TestUtilsV2.java
----------------------------------------------------------------------
diff --git a/intg/src/test/java/org/apache/atlas/TestUtilsV2.java 
b/intg/src/test/java/org/apache/atlas/TestUtilsV2.java
index 2a6ea92..25d502b 100755
--- a/intg/src/test/java/org/apache/atlas/TestUtilsV2.java
+++ b/intg/src/test/java/org/apache/atlas/TestUtilsV2.java
@@ -36,6 +36,7 @@ import 
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinali
 import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
 import org.apache.atlas.model.typedef.AtlasTypesDef;
 import org.apache.atlas.type.AtlasTypeUtil;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.RandomStringUtils;
 
 import java.math.BigDecimal;
@@ -59,6 +60,8 @@ public final class TestUtilsV2 {
 
     public static final long TEST_DATE_IN_LONG = 1418265358440L;
 
+    public static final String TEST_USER = "testUser";
+
     private static AtomicInteger seq = new AtomicInteger();
 
     private TestUtilsV2() {
@@ -147,9 +150,13 @@ public final class TestUtilsV2 {
                 AtlasTypeUtil.createTraitTypeDef("SecurityClearance", 
"SecurityClearance"+_description, ImmutableSet.<String>of(),
                         AtlasTypeUtil.createRequiredAttrDef("level", "int"));
 
-        return new AtlasTypesDef(ImmutableList.of(orgLevelEnum), 
ImmutableList.of(addressDetails),
+        AtlasTypesDef ret = new AtlasTypesDef(ImmutableList.of(orgLevelEnum), 
ImmutableList.of(addressDetails),
                 ImmutableList.of(securityClearanceTypeDef),
                 ImmutableList.of(deptTypeDef, personTypeDef, employeeTypeDef, 
managerTypeDef));
+
+        populateSystemAttributes(ret);
+
+        return ret;
     }
 
     public static AtlasTypesDef defineInverseReferenceTestTypes() {
@@ -175,7 +182,11 @@ public final class TestUtilsV2 {
                     AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, 
Collections.<String, 
Object>singletonMap(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, "manyB")))),
             new AtlasAttributeDef("mappedFromA", "A", true, 
Cardinality.SINGLE, 0, 1, false, false, 
Collections.<AtlasConstraintDef>emptyList()));
 
-        return new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), 
ImmutableList.<AtlasStructDef>of(), ImmutableList.<AtlasClassificationDef>of(), 
ImmutableList.<AtlasEntityDef>of(aDef, bDef));
+        AtlasTypesDef ret = new 
AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), 
ImmutableList.<AtlasStructDef>of(), ImmutableList.<AtlasClassificationDef>of(), 
ImmutableList.<AtlasEntityDef>of(aDef, bDef));
+
+        populateSystemAttributes(ret);
+
+        return ret;
     }
 
     public static AtlasTypesDef defineValidUpdatedDeptEmployeeTypes() {
@@ -255,10 +266,14 @@ public final class TestUtilsV2 {
                 AtlasTypeUtil.createTraitTypeDef("SecurityClearance", 
"SecurityClearance"+_description, ImmutableSet.<String>of(),
                         AtlasTypeUtil.createRequiredAttrDef("level", "int"));
 
-        return new AtlasTypesDef(ImmutableList.of(orgLevelEnum),
+        AtlasTypesDef ret = new AtlasTypesDef(ImmutableList.of(orgLevelEnum),
                 ImmutableList.of(addressDetails),
                 ImmutableList.of(securityClearanceTypeDef),
                 ImmutableList.of(deptTypeDef, personTypeDef, employeeTypeDef, 
managerTypeDef));
+
+        populateSystemAttributes(ret);
+
+        return ret;
     }
 
     public static AtlasTypesDef defineInvalidUpdatedDeptEmployeeTypes() {
@@ -322,10 +337,14 @@ public final class TestUtilsV2 {
                 AtlasTypeUtil.createOptionalAttrDef("approximationOfPi", 
"bigdecimal")
         );
 
-        return new AtlasTypesDef(ImmutableList.of(orgLevelEnum),
+        AtlasTypesDef ret = new AtlasTypesDef(ImmutableList.of(orgLevelEnum),
                 ImmutableList.of(addressDetails),
                 ImmutableList.<AtlasClassificationDef>of(),
                 ImmutableList.of(deptTypeDef, personTypeDef));
+
+        populateSystemAttributes(ret);
+
+        return ret;
     }
 
     public static final String DEPARTMENT_TYPE = "Department";
@@ -541,8 +560,12 @@ public final class TestUtilsV2 {
         AtlasEnumDef enumTypeDefinition = new AtlasEnumDef("e_type", 
"enumType", "1.0",
                 Arrays.asList(new AtlasEnumElementDef("ONE", "Element 
Description", 1)));
 
-        return AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), 
ImmutableList.of(structTypeDefinition),
+        AtlasTypesDef ret = 
AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), 
ImmutableList.of(structTypeDefinition),
                 ImmutableList.of(traitTypeDefinition), 
ImmutableList.of(superTypeDefinition));
+
+        populateSystemAttributes(ret);
+
+        return ret;
     }
 
     public static AtlasTypesDef simpleTypeUpdated(){
@@ -562,8 +585,12 @@ public final class TestUtilsV2 {
 
         AtlasEnumDef enumTypeDefinition = new AtlasEnumDef("e_type", 
"enumType",
                 Arrays.asList(new AtlasEnumElementDef("ONE", "Element 
Description", 1)));
-        return AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), 
ImmutableList.of(structTypeDefinition),
+        AtlasTypesDef ret = 
AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), 
ImmutableList.of(structTypeDefinition),
                 ImmutableList.of(traitTypeDefinition), 
ImmutableList.of(superTypeDefinition, newSuperTypeDefinition));
+
+        populateSystemAttributes(ret);
+
+        return ret;
     }
 
     public static AtlasTypesDef simpleTypeUpdatedDiff() {
@@ -571,10 +598,14 @@ public final class TestUtilsV2 {
                 AtlasTypeUtil.createClassTypeDef("new_h_type", 
ImmutableSet.<String>of(),
                         AtlasTypeUtil.createOptionalAttrDef("attr", "string"));
 
-        return AtlasTypeUtil.getTypesDef(ImmutableList.<AtlasEnumDef>of(),
+        AtlasTypesDef ret = 
AtlasTypeUtil.getTypesDef(ImmutableList.<AtlasEnumDef>of(),
                 ImmutableList.<AtlasStructDef>of(),
                 ImmutableList.<AtlasClassificationDef>of(),
                 ImmutableList.of(newSuperTypeDefinition));
+
+        populateSystemAttributes(ret);
+
+        return ret;
     }
 
 
@@ -793,11 +824,15 @@ public final class TestUtilsV2 {
                                                                                
     AtlasTypeUtil.createRequiredAttrDef("booleanAttr", "boolean"),
                                                                                
     AtlasTypeUtil.createRequiredAttrDef("integerAttr", "int"));
 
-        return AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition),
+        AtlasTypesDef ret = 
AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition),
                 ImmutableList.of(structTypeDefinition, partitionDefinition),
                 ImmutableList.of(classificationTypeDefinition, 
fetlClassificationTypeDefinition, piiTypeDefinition, phiTypeDefinition),
                 ImmutableList.of(superTypeDefinition, databaseTypeDefinition, 
columnsDefinition, tableTypeDefinition,
                         storageDescClsDef, partClsDef, processClsType));
+
+        populateSystemAttributes(ret);
+
+        return ret;
     }
 
     public static final String randomString() {
@@ -907,8 +942,13 @@ public final class TestUtilsV2 {
                 AtlasTypeUtil.createTraitTypeDef("JanitorClearance", 
"JanitorClearance_description", ImmutableSet.of("SecurityClearance1"),
                         AtlasTypeUtil.createRequiredAttrDef("level", "int"));
 
-        return Arrays.asList(securityClearanceTypeDef, 
janitorSecurityClearanceTypeDef);
+        List<AtlasClassificationDef> ret = 
Arrays.asList(securityClearanceTypeDef, janitorSecurityClearanceTypeDef);
+
+        populateSystemAttributes(ret);
+
+        return ret;
     }
+
     public static List<AtlasClassificationDef> 
getClassificationWithValidAttribute(){
         return getClassificationWithValidSuperType();
     }
@@ -919,7 +959,11 @@ public final class TestUtilsV2 {
                         1, 10, false, false,
                         Collections.<AtlasConstraintDef>emptyList()));
 
-        return Arrays.asList(developerTypeDef);
+        List<AtlasEntityDef> ret = Arrays.asList(developerTypeDef);
+
+        populateSystemAttributes(ret);
+
+        return ret;
     }
 
     public static List<AtlasEntityDef> getEntityWithValidAttribute() {
@@ -939,4 +983,24 @@ public final class TestUtilsV2 {
         entityDef.addSuperType("!@#$%");
         return entityDef;
     }
+
+    public static void populateSystemAttributes(AtlasTypesDef typesDef) {
+        populateSystemAttributes(typesDef.getEnumDefs());
+        populateSystemAttributes(typesDef.getStructDefs());
+        populateSystemAttributes(typesDef.getClassificationDefs());
+        populateSystemAttributes(typesDef.getEntityDefs());
+    }
+
+    public static void populateSystemAttributes(List<? extends 
AtlasBaseTypeDef> typeDefs) {
+        if (CollectionUtils.isNotEmpty(typeDefs)) {
+            for (AtlasBaseTypeDef typeDef : typeDefs) {
+                populateSystemAttributes(typeDef);
+            }
+        }
+    }
+
+    public static void populateSystemAttributes(AtlasBaseTypeDef typeDef) {
+        typeDef.setCreatedBy(TestUtilsV2.TEST_USER);
+        typeDef.setUpdatedBy(TestUtilsV2.TEST_USER);
+    }
 }

http://git-wip-us.apache.org/repos/asf/atlas/blob/7963525a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
index fe52f7b..386b493 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
@@ -291,6 +291,12 @@ public abstract class AtlasTypeDefGraphStore implements 
AtlasTypeDefStore, Activ
 
         AtlasTypesDef ret = addToGraphStore(typesDef, ttr);
 
+        try {
+            ttr.updateTypes(ret);
+        } catch (AtlasBaseException e) { // this shouldn't happen, as the 
types were already validated
+            LOG.error("failed to update the registry after updating the 
store", e);
+        }
+
         if (LOG.isDebugEnabled()) {
             LOG.debug("<== AtlasTypeDefGraphStore.createTypesDef(enums={}, 
structs={}, classfications={}, entities={})",
                     CollectionUtils.size(typesDef.getEnumDefs()),

http://git-wip-us.apache.org/repos/asf/atlas/blob/7963525a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
index fbd6314..a30c97a 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
@@ -20,6 +20,7 @@ package org.apache.atlas.repository.store.graph.v1;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import org.apache.atlas.AtlasErrorCode;
+import org.apache.atlas.RequestContextV1;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.listener.TypeDefChangeListener;
 import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
@@ -197,7 +198,9 @@ public class AtlasTypeDefGraphStoreV1 extends 
AtlasTypeDefGraphStore {
                 StringUtils.isNotBlank(typeDef.getDescription()) ? 
typeDef.getDescription() : typeDef.getName());
         ret.setProperty(Constants.TYPEVERSION_PROPERTY_KEY, 
typeDef.getTypeVersion());
         ret.setProperty(Constants.GUID_PROPERTY_KEY, typeDef.getGuid());
+        ret.setProperty(Constants.CREATED_BY_KEY, getCurrentUser());
         ret.setProperty(Constants.TIMESTAMP_PROPERTY_KEY, 
typeDef.getCreateTime().getTime());
+        ret.setProperty(Constants.MODIFIED_BY_KEY, getCurrentUser());
         ret.setProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, 
typeDef.getUpdateTime().getTime());
         ret.setProperty(Constants.VERSION_PROPERTY_KEY, typeDef.getVersion());
         ret.setProperty(Constants.TYPEOPTIONS_PROPERTY_KEY, 
AtlasType.toJson(typeDef.getOptions()));
@@ -255,6 +258,8 @@ public class AtlasTypeDefGraphStoreV1 extends 
AtlasTypeDefGraphStore {
         String description = 
vertex.getProperty(Constants.TYPEDESCRIPTION_PROPERTY_KEY, String.class);
         String typeVersion = 
vertex.getProperty(Constants.TYPEVERSION_PROPERTY_KEY, String.class);
         String guid        = vertex.getProperty(Constants.GUID_PROPERTY_KEY, 
String.class);
+        String createdBy   = vertex.getProperty(Constants.CREATED_BY_KEY, 
String.class);
+        String updatedBy   = vertex.getProperty(Constants.MODIFIED_BY_KEY, 
String.class);
         Long   createTime  = 
vertex.getProperty(Constants.TIMESTAMP_PROPERTY_KEY, Long.class);
         Long   updateTime  = 
vertex.getProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
         Long   version     = 
vertex.getProperty(Constants.VERSION_PROPERTY_KEY, Long.class);
@@ -264,6 +269,8 @@ public class AtlasTypeDefGraphStoreV1 extends 
AtlasTypeDefGraphStore {
         typeDef.setDescription(description);
         typeDef.setTypeVersion(typeVersion);
         typeDef.setGuid(guid);
+        typeDef.setCreatedBy(createdBy);
+        typeDef.setUpdatedBy(updatedBy);
 
         if (createTime != null) {
             typeDef.setCreateTime(new Date(createTime));
@@ -427,7 +434,22 @@ public class AtlasTypeDefGraphStoreV1 extends 
AtlasTypeDefGraphStore {
         Number currVersion = 
vertex.getProperty(Constants.VERSION_PROPERTY_KEY, Number.class);
         long   newVersion  = currVersion == null ? 1 : 
(currVersion.longValue() + 1);
 
+        vertex.setProperty(Constants.MODIFIED_BY_KEY, getCurrentUser());
         vertex.setProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, 
now.getTime());
         vertex.setProperty(Constants.VERSION_PROPERTY_KEY, newVersion);
     }
+
+    private String getCurrentUser() {
+        String ret = RequestContextV1.get().getUser();
+
+        if (StringUtils.isBlank(ret)) {
+            ret = System.getProperty("user.name");
+
+            if (StringUtils.isBlank(ret)) {
+                ret = "atlas";
+            }
+        }
+
+        return ret;
+    }
 }

http://git-wip-us.apache.org/repos/asf/atlas/blob/7963525a/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java
----------------------------------------------------------------------
diff --git 
a/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java
 
b/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java
index b835d22..8eb7a51 100644
--- 
a/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java
+++ 
b/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java
@@ -18,6 +18,7 @@
 package org.apache.atlas.repository.impexp;
 
 
+import org.apache.atlas.RequestContextV1;
 import org.apache.atlas.TestModules;
 import org.apache.atlas.TestUtilsV2;
 import org.apache.atlas.exception.AtlasBaseException;
@@ -42,6 +43,7 @@ import org.slf4j.LoggerFactory;
 import org.testng.Assert;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 import scala.actors.threadpool.Arrays;
@@ -79,6 +81,12 @@ public class ExportServiceTest {
     private AtlasEntityChangeNotifier mockChangeNotifier = 
mock(AtlasEntityChangeNotifier.class);
     private AtlasEntityStoreV1 entityStore;
 
+    @BeforeTest
+    public void setupTest() {
+        RequestContextV1.clear();
+        RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
+    }
+
     @BeforeClass
     public void setupSampleData() throws AtlasBaseException {
         entityStore = new AtlasEntityStoreV1(deleteHandler, typeRegistry, 
mockChangeNotifier, graphMapper);;

http://git-wip-us.apache.org/repos/asf/atlas/blob/7963525a/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
----------------------------------------------------------------------
diff --git 
a/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
 
b/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
index 404225c..b96197b 100644
--- 
a/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
+++ 
b/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
@@ -18,7 +18,9 @@
 package org.apache.atlas.repository.impexp;
 
 import com.google.inject.Inject;
+import org.apache.atlas.RequestContextV1;
 import org.apache.atlas.TestModules;
+import org.apache.atlas.TestUtilsV2;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.impexp.AtlasImportRequest;
 import org.apache.atlas.repository.store.graph.AtlasEntityStore;
@@ -27,6 +29,7 @@ import org.apache.atlas.type.AtlasTypeRegistry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.ITestContext;
+import org.testng.annotations.BeforeTest;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
@@ -52,6 +55,12 @@ public class ImportServiceTest {
     @Inject
     private AtlasEntityStore entityStore;
 
+    @BeforeTest
+    public void setupTest() {
+        RequestContextV1.clear();
+        RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
+    }
+
     @DataProvider(name = "sales")
     public static Object[][] getDataFromQuickStart_v1_Sales(ITestContext 
context) throws IOException {
         return getZipSource("sales-v1-full.zip");

http://git-wip-us.apache.org/repos/asf/atlas/blob/7963525a/repository/src/test/java/org/apache/atlas/repository/impexp/ZipFileResourceTestUtils.java
----------------------------------------------------------------------
diff --git 
a/repository/src/test/java/org/apache/atlas/repository/impexp/ZipFileResourceTestUtils.java
 
b/repository/src/test/java/org/apache/atlas/repository/impexp/ZipFileResourceTestUtils.java
index d901731..3ccbd8e 100644
--- 
a/repository/src/test/java/org/apache/atlas/repository/impexp/ZipFileResourceTestUtils.java
+++ 
b/repository/src/test/java/org/apache/atlas/repository/impexp/ZipFileResourceTestUtils.java
@@ -18,6 +18,8 @@
 package org.apache.atlas.repository.impexp;
 
 import com.google.common.collect.Sets;
+import org.apache.atlas.RequestContextV1;
+import org.apache.atlas.TestUtilsV2;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.impexp.AtlasExportResult;
 import org.apache.atlas.model.impexp.AtlasImportRequest;
@@ -149,6 +151,9 @@ public class ZipFileResourceTestUtils {
         AtlasExportResult exportResult = zipSource.getExportResult();
         List<String> creationOrder = zipSource.getCreationOrder();
 
+        RequestContextV1.clear();
+        RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
+
         AtlasImportRequest request = getDefaultImportRequest();
         AtlasImportResult result = runImportWithParameters(importService, 
request, zipSource);
 

http://git-wip-us.apache.org/repos/asf/atlas/blob/7963525a/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 34829a1..728d418 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
@@ -20,6 +20,7 @@ package org.apache.atlas.repository.store.graph;
 import com.google.inject.Inject;
 import org.apache.atlas.TestModules;
 import org.apache.atlas.TestUtilsV2;
+import org.apache.atlas.RequestContextV1;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.SearchFilter;
 import org.apache.atlas.model.typedef.AtlasClassificationDef;
@@ -33,6 +34,7 @@ import org.apache.atlas.type.AtlasType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
@@ -52,6 +54,12 @@ public class AtlasTypeDefGraphStoreTest {
     private
     AtlasTypeDefStore typeDefStore;
 
+    @BeforeTest
+    public void setupTest() {
+        RequestContextV1.clear();
+        RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
+    }
+
     @Test(priority = 1)
     public void testGet() {
         try {

http://git-wip-us.apache.org/repos/asf/atlas/blob/7963525a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java
----------------------------------------------------------------------
diff --git 
a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java
 
b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java
index 62ef21c..718538a 100644
--- 
a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java
+++ 
b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java
@@ -101,6 +101,9 @@ public abstract class AtlasDeleteHandlerV1Test {
 
     @BeforeClass
     public void setUp() throws Exception {
+        RequestContextV1.clear();
+        RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
+
         metadataService = TestUtils.addSessionCleanupWrapper(metadataService);
         final AtlasTypesDef deptTypesDef = 
TestUtilsV2.defineDeptEmployeeTypes();
         typeDefStore.createTypesDef(deptTypesDef);
@@ -143,7 +146,7 @@ public abstract class AtlasDeleteHandlerV1Test {
     @BeforeTest
     public void init() throws Exception {
         RequestContextV1.clear();
-
+        RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
     }
 
     @AfterClass
@@ -335,7 +338,6 @@ public abstract class AtlasDeleteHandlerV1Test {
         AtlasEntity.AtlasEntitiesWithExtInfo hrDept = 
TestUtilsV2.createDeptEg2();
         init();
 
-        RequestContextV1.clear();
         final EntityMutationResponse hrDeptCreationResponse = 
entityStore.createOrUpdate(new AtlasEntityStream(hrDept), false);
         final AtlasEntityHeader deptCreated = 
hrDeptCreationResponse.getFirstUpdatedEntityByTypeName(DEPARTMENT_TYPE);
         final AtlasEntityHeader maxEmployeeCreated = 
hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.EMPLOYEE_TYPE,
 NAME, "Max");
@@ -893,7 +895,7 @@ public abstract class AtlasDeleteHandlerV1Test {
         object = 
mapOwnerVertex.getProperty(atlasEdgeLabel.getQualifiedMapKey(), Object.class);
         Assert.assertNotNull(object);
 
-        RequestContextV1.clear();
+        init();
         List<AtlasEntityHeader> deletedEntities = 
entityStore.deleteById(mapOwnerGuid).getDeletedEntities();
         Assert.assertEquals(deletedEntities.size(), 2);
         
Assert.assertTrue(extractGuids(deletedEntities).contains(mapOwnerGuid));
@@ -927,6 +929,8 @@ public abstract class AtlasDeleteHandlerV1Test {
             ImmutableList.<AtlasClassificationDef>of(),
             ImmutableList.<AtlasEntityDef>of(mapValueDef, mapOwnerDef));
 
+        TestUtilsV2.populateSystemAttributes(typesDef);
+
         typeDefStore.createTypesDef(typesDef);
 
         AtlasEntityType mapOwnerType = 
typeRegistry.getEntityTypeByName("RequiredMapOwner");
@@ -1033,7 +1037,7 @@ public abstract class AtlasDeleteHandlerV1Test {
         String mapValueGuid = mapValueInstance.getId()._getId();
 
         // Create instance of MapValueReferencerContainer
-        RequestContextV1.clear();
+        init();
         AtlasEntity mapValueReferencer = new 
AtlasEntity(mapValueDef.getName());
         mapValueReferencer.setAttribute("refToMapValue", new 
AtlasObjectId(mapValueInstance.getId()._getId(), 
mapValueInstance.getTypeName()));
         AtlasEntity.AtlasEntitiesWithExtInfo entities = new 
AtlasEntity.AtlasEntitiesWithExtInfo();
@@ -1051,7 +1055,7 @@ public abstract class AtlasDeleteHandlerV1Test {
         mapValueReferenceContainer.setAttribute("requiredMap", 
Collections.singletonMap("value1", 
AtlasTypeUtil.getAtlasObjectId(mapValueReferencer)));
 
 
-        RequestContextV1.clear();
+        init();
         EntityMutationResponse updateEntitiesResult = 
entityStore.createOrUpdate(new AtlasEntityStream(entities), false);
 
         String mapValueReferencerContainerGuid = 
updateEntitiesResult.getCreatedEntitiesByTypeName("MapValueReferencerContainer").get(0).getGuid();

http://git-wip-us.apache.org/repos/asf/atlas/blob/7963525a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java
----------------------------------------------------------------------
diff --git 
a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java
 
b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java
index 44067b9..9b4cbd3 100644
--- 
a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java
+++ 
b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java
@@ -112,6 +112,9 @@ public class AtlasEntityStoreV1Test {
 
     @BeforeClass
     public void setUp() throws Exception {
+        RequestContextV1.clear();
+        RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
+
         metadataService = TestUtils.addSessionCleanupWrapper(metadataService);
         new GraphBackedSearchIndexer(typeRegistry);
 
@@ -141,6 +144,7 @@ public class AtlasEntityStoreV1Test {
     public void init() throws Exception {
         entityStore = new AtlasEntityStoreV1(deleteHandler, typeRegistry, 
mockChangeNotifier, graphMapper);
         RequestContextV1.clear();
+        RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/atlas/blob/7963525a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateV1Test.java
----------------------------------------------------------------------
diff --git 
a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateV1Test.java
 
b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateV1Test.java
index e2a8010..6475639 100644
--- 
a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateV1Test.java
+++ 
b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateV1Test.java
@@ -76,6 +76,9 @@ public abstract class InverseReferenceUpdateV1Test {
 
     @BeforeClass
     public void setUp() throws Exception {
+        RequestContextV1.clear();
+        RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
+
         metadataService = TestUtils.addSessionCleanupWrapper(metadataService);
 
         AtlasTypesDef[] testTypesDefs = new AtlasTypesDef[] { 
TestUtilsV2.defineDeptEmployeeTypes(),
@@ -106,6 +109,7 @@ public abstract class InverseReferenceUpdateV1Test {
     @BeforeMethod
     public void init() throws Exception {
         RequestContextV1.clear();
+        RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
     }
 
     @Test

Reply via email to