Commit f694a910 by Vimal Sharma

ATLAS-1315 Fix webapp Integration tests (ayubkhan,apoorvnaik via svimal2106)

parent cea70bc6
...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai) ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES: ALL CHANGES:
ATLAS-1315 Fix webapp Integration tests (ayubkhan,apoorvnaik via svimal2106)
ATLAS-1313 Tests SSLAndKerberosTest.testService and SSLTest.testService are failing (ayubkhan via svimal2106) ATLAS-1313 Tests SSLAndKerberosTest.testService and SSLTest.testService are failing (ayubkhan via svimal2106)
ATLAS-1116 Performance monitoring of backend methods in API requests (shwethags) ATLAS-1116 Performance monitoring of backend methods in API requests (shwethags)
ATLAS-1310 attempt LDAP authentication only when enabled (mneethiraj) ATLAS-1310 attempt LDAP authentication only when enabled (mneethiraj)
......
...@@ -64,6 +64,7 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -64,6 +64,7 @@ public class EntityNotificationIT extends BaseResourceIT {
@Inject @Inject
private NotificationInterface notificationInterface; private NotificationInterface notificationInterface;
private Id tableId; private Id tableId;
private Id dbId;
private String traitName; private String traitName;
private NotificationConsumer<EntityNotification> notificationConsumer; private NotificationConsumer<EntityNotification> notificationConsumer;
...@@ -71,6 +72,8 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -71,6 +72,8 @@ public class EntityNotificationIT extends BaseResourceIT {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
createTypeDefinitions(); createTypeDefinitions();
Referenceable HiveDBInstance = createHiveDBInstance(DATABASE_NAME);
dbId = createInstance(HiveDBInstance);
List<NotificationConsumer<EntityNotification>> consumers = List<NotificationConsumer<EntityNotification>> consumers =
notificationInterface.createConsumers(NotificationInterface.NotificationType.ENTITIES, 1); notificationInterface.createConsumers(NotificationInterface.NotificationType.ENTITIES, 1);
...@@ -80,11 +83,7 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -80,11 +83,7 @@ public class EntityNotificationIT extends BaseResourceIT {
@Test @Test
public void testCreateEntity() throws Exception { public void testCreateEntity() throws Exception {
Referenceable hiveDBInstance = createHiveDBInstance(DATABASE_NAME); Referenceable tableInstance = createHiveTableInstance(DATABASE_NAME, TABLE_NAME, dbId);
Id dbID = createInstance(hiveDBInstance);
hiveDBInstance.replaceWithNewId(dbID);
Referenceable tableInstance = createHiveTableInstance(hiveDBInstance, TABLE_NAME);
tableId = createInstance(tableInstance); tableId = createInstance(tableInstance);
final String guid = tableId._getId(); final String guid = tableId._getId();
...@@ -110,11 +109,10 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -110,11 +109,10 @@ public class EntityNotificationIT extends BaseResourceIT {
public void testDeleteEntity() throws Exception { public void testDeleteEntity() throws Exception {
final String tableName = "table-" + randomString(); final String tableName = "table-" + randomString();
final String dbName = "db-" + randomString(); final String dbName = "db-" + randomString();
Referenceable hiveDBInstance = createHiveDBInstance(dbName); Referenceable HiveDBInstance = createHiveDBInstance(dbName);
Id dbID = createInstance(hiveDBInstance); Id dbId = createInstance(HiveDBInstance);
hiveDBInstance.replaceWithNewId(dbID);
Referenceable tableInstance = createHiveTableInstance(hiveDBInstance, tableName); Referenceable tableInstance = createHiveTableInstance(dbName, tableName, dbId);
final Id tableId = createInstance(tableInstance); final Id tableId = createInstance(tableInstance);
final String guid = tableId._getId(); final String guid = tableId._getId();
......
...@@ -56,7 +56,10 @@ import org.slf4j.LoggerFactory; ...@@ -56,7 +56,10 @@ import org.slf4j.LoggerFactory;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Collections;
import java.util.Map;
/** /**
* Base class for integration tests. * Base class for integration tests.
...@@ -90,11 +93,32 @@ public abstract class BaseResourceIT { ...@@ -90,11 +93,32 @@ public abstract class BaseResourceIT {
} }
protected void createType(TypesDef typesDef) throws Exception { protected void createType(TypesDef typesDef) throws Exception {
try { try{
if ( !typesDef.enumTypes().isEmpty() ){
String sampleType = typesDef.enumTypesAsJavaList().get(0).name;
serviceClient.getType(sampleType);
LOG.info("Checking enum type existence");
}
else if( !typesDef.structTypes().isEmpty()){
StructTypeDefinition sampleType = typesDef.structTypesAsJavaList().get(0);
serviceClient.getType(sampleType.typeName);
LOG.info("Checking struct type existence");
}
else if( !typesDef.traitTypes().isEmpty()){
HierarchicalTypeDefinition<TraitType> sampleType = typesDef.traitTypesAsJavaList().get(0);
serviceClient.getType(sampleType.typeName);
LOG.info("Checking trait type existence");
}
else{
HierarchicalTypeDefinition<ClassType> sampleType = typesDef.classTypesAsJavaList().get(0);
serviceClient.getType(sampleType.typeName);
LOG.info("Checking class type existence");
}
LOG.info("Types already exist. Skipping type creation");
} catch(AtlasServiceException ase) {
//Expected if type doesnt exist
String typesAsJSON = TypesSerialization.toJson(typesDef); String typesAsJSON = TypesSerialization.toJson(typesDef);
createType(typesAsJSON); createType(typesAsJSON);
} catch(AtlasServiceException ase) {
LOG.info("Types failed. Tests might malfunction");
} }
} }
...@@ -118,6 +142,24 @@ public abstract class BaseResourceIT { ...@@ -118,6 +142,24 @@ public abstract class BaseResourceIT {
return null; return null;
} }
protected TypesDef getTypesDef(ImmutableList<EnumTypeDefinition> enums,
ImmutableList<StructTypeDefinition> structs,
ImmutableList<HierarchicalTypeDefinition<TraitType>> traits,
ImmutableList<HierarchicalTypeDefinition<ClassType>> classes){
enums = (enums != null) ? enums : ImmutableList
.<EnumTypeDefinition>of();
structs =
(structs != null) ? structs : ImmutableList.<StructTypeDefinition>of();
traits = (traits != null) ? traits : ImmutableList
.<HierarchicalTypeDefinition<TraitType>>of();
classes = (classes != null) ? classes : ImmutableList
.<HierarchicalTypeDefinition<ClassType>>of();
return TypesUtil.getTypesDef(enums, structs, traits, classes);
}
protected static final String DATABASE_TYPE = "hive_db"; protected static final String DATABASE_TYPE = "hive_db";
protected static final String HIVE_TABLE_TYPE = "hive_table"; protected static final String HIVE_TABLE_TYPE = "hive_table";
protected static final String COLUMN_TYPE = "hive_column"; protected static final String COLUMN_TYPE = "hive_column";
...@@ -179,14 +221,22 @@ public abstract class BaseResourceIT { ...@@ -179,14 +221,22 @@ public abstract class BaseResourceIT {
TypesUtil.createTraitTypeDef("sec", ImmutableSet.<String>of()); TypesUtil.createTraitTypeDef("sec", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> financeTrait = HierarchicalTypeDefinition<TraitType> financeTrait =
TypesUtil.createTraitTypeDef("finance", ImmutableSet.<String>of()); TypesUtil.createTraitTypeDef("finance", ImmutableSet.<String>of());
/*HierarchicalTypeDefinition<TraitType> factTrait =
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), TypesUtil.createTraitTypeDef("Fact", ImmutableSet.<String>of());
ImmutableList.of(structTypeDefinition), HierarchicalTypeDefinition<TraitType> etlTrait =
ImmutableList.of(classificationTrait, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, financeTrait), TypesUtil.createTraitTypeDef("ETL", ImmutableSet.<String>of());
// ImmutableList.<HierarchicalTypeDefinition<ClassType>>of()); HierarchicalTypeDefinition<TraitType> dimensionTrait =
ImmutableList.of(dbClsDef, columnClsDef, tblClsDef, loadProcessClsDef)); TypesUtil.createTraitTypeDef("Dimension", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> metricTrait =
createType(typesDef); TypesUtil.createTraitTypeDef("Metric", ImmutableSet.<String>of());*/
createType(getTypesDef(ImmutableList.of(enumTypeDefinition), null, null, null));
createType(getTypesDef(null, ImmutableList.of(structTypeDefinition), null, null));
createType(getTypesDef(null, null,
ImmutableList.of(classificationTrait, piiTrait, phiTrait, pciTrait,
soxTrait, secTrait, financeTrait), null));
createType(getTypesDef(null, null, null,
ImmutableList.of(dbClsDef, columnClsDef, tblClsDef, loadProcessClsDef)));
} }
AttributeDefinition attrDef(String name, IDataType dT) { AttributeDefinition attrDef(String name, IDataType dT) {
...@@ -208,7 +258,17 @@ public abstract class BaseResourceIT { ...@@ -208,7 +258,17 @@ public abstract class BaseResourceIT {
return RandomStringUtils.randomAlphanumeric(10); return RandomStringUtils.randomAlphanumeric(10);
} }
protected Referenceable createHiveTableInstance(Referenceable databaseInstance, String tableName) throws Exception { protected Referenceable createHiveTableInstance(String dbName, String tableName, Id dbId) throws Exception {
Map<String, Object> values = new HashMap<>();
values.put("name", dbName);
values.put("description", "foo database");
values.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
values.put("owner", "user1");
values.put("clusterName", "cl1");
values.put("parameters", Collections.EMPTY_MAP);
values.put("location", "/tmp");
Referenceable databaseInstance = new Referenceable(dbId._getId(), dbId.getTypeName(), values);
Referenceable tableInstance = Referenceable tableInstance =
new Referenceable(HIVE_TABLE_TYPE, "classification", "pii", "phi", "pci", "sox", "sec", "finance"); new Referenceable(HIVE_TABLE_TYPE, "classification", "pii", "phi", "pci", "sox", "sec", "finance");
tableInstance.set("name", tableName); tableInstance.set("name", tableName);
...@@ -246,6 +306,11 @@ public abstract class BaseResourceIT { ...@@ -246,6 +306,11 @@ public abstract class BaseResourceIT {
databaseInstance.set("qualifiedName", dbName); databaseInstance.set("qualifiedName", dbName);
databaseInstance.set("clusterName", randomString()); databaseInstance.set("clusterName", randomString());
databaseInstance.set("description", "foo database"); databaseInstance.set("description", "foo database");
databaseInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
databaseInstance.set("owner", "user1");
databaseInstance.set("clusterName", "cl1");
databaseInstance.set("parameters", Collections.EMPTY_MAP);
databaseInstance.set("location", "/tmp");
return databaseInstance; return databaseInstance;
} }
......
...@@ -71,6 +71,8 @@ import java.util.List; ...@@ -71,6 +71,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.Collections;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
...@@ -92,6 +94,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -92,6 +94,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
private Referenceable tableInstance; private Referenceable tableInstance;
private Id tableId; private Id tableId;
private Id dbId;
private String traitName; private String traitName;
@Inject @Inject
...@@ -103,6 +106,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -103,6 +106,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
super.setUp(); super.setUp();
createTypeDefinitions(); createTypeDefinitions();
Referenceable HiveDBInstance = createHiveDBInstance(DATABASE_NAME);
dbId = createInstance(HiveDBInstance);
List<NotificationConsumer<EntityNotification>> consumers = List<NotificationConsumer<EntityNotification>> consumers =
notificationInterface.createConsumers(NotificationInterface.NotificationType.ENTITIES, 1); notificationInterface.createConsumers(NotificationInterface.NotificationType.ENTITIES, 1);
...@@ -112,17 +117,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -112,17 +117,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testSubmitEntity() throws Exception { public void testSubmitEntity() throws Exception {
Referenceable dbInstance = createHiveDBInstance(DATABASE_NAME); tableInstance = createHiveTableInstance(DATABASE_NAME, TABLE_NAME, dbId);
Id dbID = createInstance(dbInstance);
try {
Assert.assertNotNull(UUID.fromString(dbID._getId()));
dbInstance.replaceWithNewId(dbID);
} catch (IllegalArgumentException e) {
Assert.fail("Response is not a guid, " + dbID._getId());
}
tableInstance = createHiveTableInstance(dbInstance, TABLE_NAME);
tableId = createInstance(tableInstance); tableId = createInstance(tableInstance);
final String guid = tableId._getId(); final String guid = tableId._getId();
...@@ -141,6 +136,12 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -141,6 +136,12 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
entity.set("qualifiedName", dbName); entity.set("qualifiedName", dbName);
entity.set("clusterName", randomString()); entity.set("clusterName", randomString());
entity.set("description", randomString()); entity.set("description", randomString());
entity.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
entity.set("owner", "user1");
entity.set("clusterName", "cl1");
entity.set("parameters", Collections.EMPTY_MAP);
entity.set("location", "/tmp");
String user = "admin"; String user = "admin";
AtlasClient localClient = null; AtlasClient localClient = null;
...@@ -165,6 +166,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -165,6 +166,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
databaseInstance.set("qualifiedName", dbName); databaseInstance.set("qualifiedName", dbName);
databaseInstance.set("clusterName", randomString()); databaseInstance.set("clusterName", randomString());
databaseInstance.set("description", randomString()); databaseInstance.set("description", randomString());
databaseInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
databaseInstance.set("owner", "user1");
databaseInstance.set("clusterName", "cl1");
databaseInstance.set("parameters", Collections.EMPTY_MAP);
databaseInstance.set("location", "/tmp");
ClientResponse clientResponse = ClientResponse clientResponse =
service.path(ENTITIES).accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) service.path(ENTITIES).accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
...@@ -187,32 +193,30 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -187,32 +193,30 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
public void testEntityDeduping() throws Exception { public void testEntityDeduping() throws Exception {
final Referenceable db = new Referenceable(DATABASE_TYPE); final Referenceable db = new Referenceable(DATABASE_TYPE);
final String dbName = "db" + randomString(); final String dbName = "db" + randomString();
db.set("name", dbName); Referenceable HiveDBInstance = createHiveDBInstance(dbName);
db.set("qualifiedName", dbName); Id dbIdReference = createInstance(HiveDBInstance);
db.set("clusterName", randomString()); final String dbId = dbIdReference._getId();
db.set("description", randomString());
final String dbid = serviceClient.createEntity(db).get(0); assertEntityAudit(dbId, EntityAuditEvent.EntityAuditAction.ENTITY_CREATE);
assertEntityAudit(dbid, EntityAuditEvent.EntityAuditAction.ENTITY_CREATE);
waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() { waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() {
@Override @Override
public boolean evaluate(EntityNotification notification) throws Exception { public boolean evaluate(EntityNotification notification) throws Exception {
return notification != null && notification.getEntity().getId()._getId().equals(dbid); return notification != null && notification.getEntity().getId()._getId().equals(dbId);
} }
}); });
JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE, dbName)); JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE, dbName));
assertEquals(results.length(), 1); assertEquals(results.length(), 1);
//create entity again shouldn't create another instance with same unique attribute value //create entity again shouldn't create another instance with same unique attribute value
List<String> entityResults = serviceClient.createEntity(db); List<String> entityResults = serviceClient.createEntity(HiveDBInstance);
assertEquals(entityResults.size(), 0); assertEquals(entityResults.size(), 0);
try { try {
waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() { waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() {
@Override @Override
public boolean evaluate(EntityNotification notification) throws Exception { public boolean evaluate(EntityNotification notification) throws Exception {
return notification != null && notification.getEntity().getId()._getId().equals(dbid); return notification != null && notification.getEntity().getId()._getId().equals(dbId);
} }
}); });
fail("Expected time out exception"); fail("Expected time out exception");
...@@ -220,18 +224,15 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -220,18 +224,15 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
//expected timeout //expected timeout
} }
results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE, dbName)); results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE, dbName));
assertEquals(results.length(), 1); assertEquals(results.length(), 1);
//Test the same across references //Test the same across references
Referenceable table = new Referenceable(HIVE_TABLE_TYPE); Referenceable table = new Referenceable(HIVE_TABLE_TYPE);
final String tableName = randomString(); final String tableName = randomString();
table.set("name", tableName); Referenceable tableInstance = createHiveTableInstance(DATABASE_NAME, tableName, dbIdReference);
table.set("db", db); serviceClient.createEntity(tableInstance);
table.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName); results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE, dbName));
serviceClient.createEntity(table);
results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE, dbName));
assertEquals(results.length(), 1); assertEquals(results.length(), 1);
} }
...@@ -282,8 +283,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -282,8 +283,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test(dataProvider = "invalidAttrValues") @Test(dataProvider = "invalidAttrValues")
public void testEntityInvalidValue(String value) throws Exception { public void testEntityInvalidValue(String value) throws Exception {
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE); Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
String dbName = randomString(); databaseInstance.set("name", randomString());
databaseInstance.set("name", dbName);
databaseInstance.set("description", value); databaseInstance.set("description", value);
try { try {
...@@ -296,13 +296,16 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -296,13 +296,16 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testGetEntityByAttribute() throws Exception { public void testGetEntityByAttribute() throws Exception {
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE); Referenceable db1 = new Referenceable(DATABASE_TYPE);
String dbName = randomString(); String dbName = randomString();
databaseInstance.set("name", dbName); db1.set("name", dbName);
databaseInstance.set("qualifiedName", dbName); db1.set("description", randomString());
databaseInstance.set("clusterName", randomString()); db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
databaseInstance.set("description", "foo database"); db1.set("owner", "user1");
createInstance(databaseInstance); db1.set("clusterName", "cl1");
db1.set("parameters", Collections.EMPTY_MAP);
db1.set("location", "/tmp");
createInstance(db1);
//get entity by attribute //get entity by attribute
Referenceable referenceable = serviceClient.getEntity(DATABASE_TYPE, "qualifiedName", dbName); Referenceable referenceable = serviceClient.getEntity(DATABASE_TYPE, "qualifiedName", dbName);
...@@ -313,11 +316,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -313,11 +316,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testSubmitEntityWithBadDateFormat() throws Exception { public void testSubmitEntityWithBadDateFormat() throws Exception {
try { try {
Referenceable hiveDBInstance = createHiveDBInstance("db" + randomString()); Referenceable tableInstance = createHiveTableInstance("db" + randomString(), "table" + randomString(), dbId);
Id dbID = createInstance(hiveDBInstance);
hiveDBInstance.replaceWithNewId(dbID);
Referenceable tableInstance = createHiveTableInstance(hiveDBInstance, "table" + randomString());
tableInstance.set("lastAccessTime", "2014-07-11"); tableInstance.set("lastAccessTime", "2014-07-11");
tableId = createInstance(tableInstance); tableId = createInstance(tableInstance);
Assert.fail("Was expecting an exception here "); Assert.fail("Was expecting an exception here ");
...@@ -347,8 +346,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -347,8 +346,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
Assert.assertEquals(e.getStatus().getStatusCode(), Response.Status.BAD_REQUEST.getStatusCode()); Assert.assertEquals(e.getStatus().getStatusCode(), Response.Status.BAD_REQUEST.getStatusCode());
} }
//non-string property, update String currentTime = String.valueOf(new DateTime() );
String currentTime = String.valueOf(new DateTime());
addProperty(guid, "createTime", currentTime); addProperty(guid, "createTime", currentTime);
entityRef = getEntityDefinition(getEntityDefinition(guid)); entityRef = getEntityDefinition(getEntityDefinition(guid));
...@@ -386,6 +384,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -386,6 +384,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
databaseInstance.set("qualifiedName", dbName); databaseInstance.set("qualifiedName", dbName);
databaseInstance.set("clusterName", randomString()); databaseInstance.set("clusterName", randomString());
databaseInstance.set("description", "new database"); databaseInstance.set("description", "new database");
databaseInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
databaseInstance.set("owner", "user1");
databaseInstance.set("clusterName", "cl1");
databaseInstance.set("parameters", Collections.EMPTY_MAP);
databaseInstance.set("location", "/tmp");
Id dbInstance = createInstance(databaseInstance); Id dbInstance = createInstance(databaseInstance);
String dbId = dbInstance._getId(); String dbId = dbInstance._getId();
...@@ -759,12 +762,18 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -759,12 +762,18 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test(dependsOnMethods = "testSubmitEntity") @Test(dependsOnMethods = "testSubmitEntity")
public void testPartialUpdate() throws Exception { public void testPartialUpdate() throws Exception {
String colName = "col1"+randomString();
final List<Referenceable> columns = new ArrayList<>(); final List<Referenceable> columns = new ArrayList<>();
Map<String, Object> values = new HashMap<>(); Map<String, Object> values = new HashMap<>();
values.put("name", "col1"); values.put("name", colName);
values.put("qualifiedName", "qualifiedName.col1"); values.put("comment", "col1 comment");
values.put("type", "string"); values.put("qualifiedName", "default.table.col1@"+colName);
values.put("comment", "col1 comment"); values.put("comment", "col1 comment");
values.put("type", "string");
values.put("owner", "user1");
values.put("position", 0);
values.put("description", "col1");
values.put("table", null);
Referenceable ref = new Referenceable(BaseResourceIT.COLUMN_TYPE, values); Referenceable ref = new Referenceable(BaseResourceIT.COLUMN_TYPE, values);
columns.add(ref); columns.add(ref);
...@@ -794,8 +803,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -794,8 +803,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
LOG.debug("Updating entity= " + tableUpdated); LOG.debug("Updating entity= " + tableUpdated);
entityResult = serviceClient.updateEntity(BaseResourceIT.HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, entityResult = serviceClient.updateEntity(BaseResourceIT.HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
(String) tableInstance.get("name"), tableUpdated); (String) tableInstance.get("qualifiedName"), tableUpdated);
assertEquals(entityResult.getUpdateEntities().size(), 1); assertEquals(entityResult.getUpdateEntities().size(), 2);
assertEquals(entityResult.getUpdateEntities().get(0), tableId._getId()); assertEquals(entityResult.getUpdateEntities().get(0), tableId._getId());
response = getEntityDefinition(tableId._getId()); response = getEntityDefinition(tableId._getId());
...@@ -803,8 +812,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -803,8 +812,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
getReferenceable = InstanceSerialization.fromJsonReferenceable(definition, true); getReferenceable = InstanceSerialization.fromJsonReferenceable(definition, true);
refs = (List<Referenceable>) getReferenceable.get("columns"); refs = (List<Referenceable>) getReferenceable.get("columns");
Assert.assertTrue(refs.get(0).equalsContents(columns.get(0))); Assert.assertTrue(refs.get(0).getValuesMap().equals(values));
Assert.assertEquals(refs.get(0).get("dataType"), "int"); Assert.assertEquals(refs.get(0).get("type"), "int");
} }
@Test(dependsOnMethods = "testSubmitEntity") @Test(dependsOnMethods = "testSubmitEntity")
...@@ -812,15 +821,24 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -812,15 +821,24 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
final List<Referenceable> columns = new ArrayList<>(); final List<Referenceable> columns = new ArrayList<>();
Map<String, Object> values1 = new HashMap<>(); Map<String, Object> values1 = new HashMap<>();
values1.put("name", "col3"); values1.put("name", "col3");
values1.put("qualifiedName", "qualifiedName.col3"); values1.put("qualifiedName", "default.table.col3@cl1");
values1.put("type", "string");
values1.put("comment", "col3 comment"); values1.put("comment", "col3 comment");
values1.put("type", "string");
values1.put("owner", "user1");
values1.put("position", 0);
values1.put("description", "col3");
values1.put("table", null);
Map<String, Object> values2 = new HashMap<>(); Map<String, Object> values2 = new HashMap<>();
values2.put("name", "col4"); values2.put("name", "col4");
values2.put("qualifiedName", "qualifiedName.col4"); values2.put("qualifiedName", "default.table.col4@cl1");
values2.put("type", "string");
values2.put("comment", "col4 comment"); values2.put("comment", "col4 comment");
values2.put("type", "string");
values2.put("owner", "user2");
values2.put("position", 1);
values2.put("description", "col4");
values2.put("table", null);
Referenceable ref1 = new Referenceable(BaseResourceIT.COLUMN_TYPE, values1); Referenceable ref1 = new Referenceable(BaseResourceIT.COLUMN_TYPE, values1);
Referenceable ref2 = new Referenceable(BaseResourceIT.COLUMN_TYPE, values2); Referenceable ref2 = new Referenceable(BaseResourceIT.COLUMN_TYPE, values2);
...@@ -852,8 +870,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -852,8 +870,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
List<Referenceable> refs = (List<Referenceable>) getReferenceable.get("columns"); List<Referenceable> refs = (List<Referenceable>) getReferenceable.get("columns");
Assert.assertEquals(refs.size(), 2); Assert.assertEquals(refs.size(), 2);
Assert.assertTrue(refs.get(0).equalsContents(columns.get(0))); Assert.assertTrue(refs.get(0).getValuesMap().equals(values1));
Assert.assertTrue(refs.get(1).equalsContents(columns.get(1))); Assert.assertTrue(refs.get(1).getValuesMap().equals(values2));
} }
private static class UpdateEntitiesResponse { private static class UpdateEntitiesResponse {
...@@ -871,11 +889,14 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -871,11 +889,14 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
public void testDeleteEntitiesViaRestApi() throws Exception { public void testDeleteEntitiesViaRestApi() throws Exception {
// Create 2 database entities // Create 2 database entities
Referenceable db1 = new Referenceable(DATABASE_TYPE); Referenceable db1 = new Referenceable(DATABASE_TYPE);
String dbName1 = randomString(); String dbName = randomString();
db1.set("name", dbName1); db1.set("name", dbName);
db1.set("qualifiedName", dbName1);
db1.set("clusterName", randomString());
db1.set("description", randomString()); db1.set("description", randomString());
db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
db1.set("owner", "user1");
db1.set("clusterName", "cl1");
db1.set("parameters", Collections.EMPTY_MAP);
db1.set("location", "/tmp");
Id db1Id = createInstance(db1); Id db1Id = createInstance(db1);
Referenceable db2 = new Referenceable(DATABASE_TYPE); Referenceable db2 = new Referenceable(DATABASE_TYPE);
...@@ -884,6 +905,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -884,6 +905,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
db2.set("qualifiedName", dbName2); db2.set("qualifiedName", dbName2);
db2.set("clusterName", randomString()); db2.set("clusterName", randomString());
db2.set("description", randomString()); db2.set("description", randomString());
db2.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName2);
db2.set("owner", "user2");
db2.set("clusterName", "cl1");
db2.set("parameters", Collections.EMPTY_MAP);
db2.set("location", "/tmp");
Id db2Id = createInstance(db2); Id db2Id = createInstance(db2);
// Delete the database entities // Delete the database entities
...@@ -908,11 +934,14 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -908,11 +934,14 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
public void testDeleteEntitiesViaClientApi() throws Exception { public void testDeleteEntitiesViaClientApi() throws Exception {
// Create 2 database entities // Create 2 database entities
Referenceable db1 = new Referenceable(DATABASE_TYPE); Referenceable db1 = new Referenceable(DATABASE_TYPE);
String dbName1 = randomString(); String dbName = randomString();
db1.set("name", dbName1); db1.set("name", dbName);
db1.set("qualifiedName", dbName1);
db1.set("clusterName", randomString());
db1.set("description", randomString()); db1.set("description", randomString());
db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
db1.set("owner", "user1");
db1.set("clusterName", "cl1");
db1.set("parameters", Collections.EMPTY_MAP);
db1.set("location", "/tmp");
Id db1Id = createInstance(db1); Id db1Id = createInstance(db1);
Referenceable db2 = new Referenceable(DATABASE_TYPE); Referenceable db2 = new Referenceable(DATABASE_TYPE);
String dbName2 = randomString(); String dbName2 = randomString();
...@@ -920,6 +949,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -920,6 +949,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
db2.set("qualifiedName", dbName2); db2.set("qualifiedName", dbName2);
db2.set("clusterName", randomString()); db2.set("clusterName", randomString());
db2.set("description", randomString()); db2.set("description", randomString());
db2.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName2);
db2.set("owner", "user2");
db2.set("clusterName", "cl1");
db2.set("parameters", Collections.EMPTY_MAP);
db2.set("location", "/tmp");
Id db2Id = createInstance(db2); Id db2Id = createInstance(db2);
// Delete the database entities // Delete the database entities
...@@ -947,6 +981,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -947,6 +981,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
db1.set("qualifiedName", dbName); db1.set("qualifiedName", dbName);
db1.set("clusterName", randomString()); db1.set("clusterName", randomString());
db1.set("description", randomString()); db1.set("description", randomString());
db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
db1.set("owner", "user1");
db1.set("clusterName", "cl1");
db1.set("parameters", Collections.EMPTY_MAP);
db1.set("location", "/tmp");
Id db1Id = createInstance(db1); Id db1Id = createInstance(db1);
// Delete the database entity // Delete the database entity
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment