Commit 9dc96c46 by Apoorv Naik Committed by Madhan Neethiraj

ATLAS-1292: Integration test fixes caused by recent bootstrap changes

parent 774975c9
...@@ -80,8 +80,11 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -80,8 +80,11 @@ public class EntityNotificationIT extends BaseResourceIT {
@Test @Test
public void testCreateEntity() throws Exception { public void testCreateEntity() throws Exception {
Referenceable tableInstance = createHiveTableInstance(DATABASE_NAME, TABLE_NAME); Referenceable hiveDBInstance = createHiveDBInstance(DATABASE_NAME);
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();
...@@ -107,7 +110,11 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -107,7 +110,11 @@ 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 tableInstance = createHiveTableInstance(dbName, tableName); Referenceable hiveDBInstance = createHiveDBInstance(dbName);
Id dbID = createInstance(hiveDBInstance);
hiveDBInstance.replaceWithNewId(dbID);
Referenceable tableInstance = createHiveTableInstance(hiveDBInstance, tableName);
final Id tableId = createInstance(tableInstance); final Id tableId = createInstance(tableInstance);
final String guid = tableId._getId(); final String guid = tableId._getId();
......
...@@ -65,8 +65,11 @@ public class NotificationHookConsumerIT extends BaseResourceIT { ...@@ -65,8 +65,11 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
//send valid message //send valid message
final Referenceable entity = new Referenceable(DATABASE_TYPE); final Referenceable entity = new Referenceable(DATABASE_TYPE);
entity.set("name", "db" + randomString()); String dbName = "db" + randomString();
entity.set("name", dbName);
entity.set("description", randomString()); entity.set("description", randomString());
entity.set("qualifiedName", dbName);
entity.set("clusterName", randomString());
sendHookMessage(new HookNotification.EntityCreateRequest(TEST_USER, entity)); sendHookMessage(new HookNotification.EntityCreateRequest(TEST_USER, entity));
waitFor(MAX_WAIT_TIME, new Predicate() { waitFor(MAX_WAIT_TIME, new Predicate() {
...@@ -81,21 +84,24 @@ public class NotificationHookConsumerIT extends BaseResourceIT { ...@@ -81,21 +84,24 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
@Test @Test
public void testCreateEntity() throws Exception { public void testCreateEntity() throws Exception {
final Referenceable entity = new Referenceable(DATABASE_TYPE); final Referenceable entity = new Referenceable(DATABASE_TYPE);
entity.set("name", "db" + randomString()); String dbName = "db" + randomString();
entity.set("name", dbName);
entity.set("description", randomString()); entity.set("description", randomString());
entity.set("qualifiedName", dbName);
entity.set("clusterName", randomString());
sendHookMessage(new HookNotification.EntityCreateRequest(TEST_USER, entity)); sendHookMessage(new HookNotification.EntityCreateRequest(TEST_USER, entity));
waitFor(MAX_WAIT_TIME, new Predicate() { waitFor(MAX_WAIT_TIME, new Predicate() {
@Override @Override
public boolean evaluate() throws Exception { public boolean evaluate() throws Exception {
JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE, entity.get("name"))); JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE, entity.get("qualifiedName")));
return results.length() == 1; return results.length() == 1;
} }
}); });
//Assert that user passed in hook message is used in audit //Assert that user passed in hook message is used in audit
Referenceable instance = serviceClient.getEntity(DATABASE_TYPE, "name", (String) entity.get("name")); Referenceable instance = serviceClient.getEntity(DATABASE_TYPE, "qualifiedName", (String) entity.get("qualifiedName"));
List<EntityAuditEvent> events = List<EntityAuditEvent> events =
serviceClient.getEntityAuditEvents(instance.getId()._getId(), (short) 1); serviceClient.getEntityAuditEvents(instance.getId()._getId(), (short) 1);
assertEquals(events.size(), 1); assertEquals(events.size(), 1);
...@@ -108,22 +114,25 @@ public class NotificationHookConsumerIT extends BaseResourceIT { ...@@ -108,22 +114,25 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
final String dbName = "db" + randomString(); final String dbName = "db" + randomString();
entity.set("name", dbName); entity.set("name", dbName);
entity.set("description", randomString()); entity.set("description", randomString());
entity.set("qualifiedName", dbName);
entity.set("clusterName", randomString());
serviceClient.createEntity(entity); serviceClient.createEntity(entity);
final Referenceable newEntity = new Referenceable(DATABASE_TYPE); final Referenceable newEntity = new Referenceable(DATABASE_TYPE);
newEntity.set("owner", randomString()); newEntity.set("owner", randomString());
sendHookMessage( sendHookMessage(
new HookNotification.EntityPartialUpdateRequest(TEST_USER, DATABASE_TYPE, "name", dbName, newEntity)); new HookNotification.EntityPartialUpdateRequest(TEST_USER, DATABASE_TYPE, "qualifiedName", dbName, newEntity));
waitFor(MAX_WAIT_TIME, new Predicate() { waitFor(MAX_WAIT_TIME, new Predicate() {
@Override @Override
public boolean evaluate() throws Exception { public boolean evaluate() throws Exception {
Referenceable localEntity = serviceClient.getEntity(DATABASE_TYPE, "name", dbName); Referenceable localEntity = serviceClient.getEntity(DATABASE_TYPE, "qualifiedName", dbName);
return (localEntity.get("owner") != null && localEntity.get("owner").equals(newEntity.get("owner"))); return (localEntity.get("owner") != null && localEntity.get("owner").equals(newEntity.get("owner")));
} }
}); });
//Its partial update and un-set fields are not updated //Its partial update and un-set fields are not updated
Referenceable actualEntity = serviceClient.getEntity(DATABASE_TYPE, "name", dbName); Referenceable actualEntity = serviceClient.getEntity(DATABASE_TYPE, "qualifiedName", dbName);
assertEquals(actualEntity.get("description"), entity.get("description")); assertEquals(actualEntity.get("description"), entity.get("description"));
} }
...@@ -133,24 +142,27 @@ public class NotificationHookConsumerIT extends BaseResourceIT { ...@@ -133,24 +142,27 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
final String dbName = "db" + randomString(); final String dbName = "db" + randomString();
entity.set("name", dbName); entity.set("name", dbName);
entity.set("description", randomString()); entity.set("description", randomString());
entity.set("qualifiedName", dbName);
entity.set("clusterName", randomString());
serviceClient.createEntity(entity); serviceClient.createEntity(entity);
final Referenceable newEntity = new Referenceable(DATABASE_TYPE); final Referenceable newEntity = new Referenceable(DATABASE_TYPE);
final String newName = "db" + randomString(); final String newName = "db" + randomString();
newEntity.set("name", newName); newEntity.set("qualifiedName", newName);
sendHookMessage( sendHookMessage(
new HookNotification.EntityPartialUpdateRequest(TEST_USER, DATABASE_TYPE, "name", dbName, newEntity)); new HookNotification.EntityPartialUpdateRequest(TEST_USER, DATABASE_TYPE, "qualifiedName", dbName, newEntity));
waitFor(MAX_WAIT_TIME, new Predicate() { waitFor(MAX_WAIT_TIME, new Predicate() {
@Override @Override
public boolean evaluate() throws Exception { public boolean evaluate() throws Exception {
JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE, newName)); JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE, newName));
return results.length() == 1; return results.length() == 1;
} }
}); });
//no entity with the old qualified name //no entity with the old qualified name
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(), 0); assertEquals(results.length(), 0);
} }
...@@ -161,10 +173,13 @@ public class NotificationHookConsumerIT extends BaseResourceIT { ...@@ -161,10 +173,13 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
final String dbName = "db" + randomString(); final String dbName = "db" + randomString();
entity.set("name", dbName); entity.set("name", dbName);
entity.set("description", randomString()); entity.set("description", randomString());
entity.set("qualifiedName", dbName);
entity.set("clusterName", randomString());
final String dbId = serviceClient.createEntity(entity).get(0); final String dbId = serviceClient.createEntity(entity).get(0);
sendHookMessage( sendHookMessage(
new HookNotification.EntityDeleteRequest(TEST_USER, DATABASE_TYPE, "name", dbName)); new HookNotification.EntityDeleteRequest(TEST_USER, DATABASE_TYPE, "qualifiedName", dbName));
waitFor(MAX_WAIT_TIME, new Predicate() { waitFor(MAX_WAIT_TIME, new Predicate() {
@Override @Override
public boolean evaluate() throws Exception { public boolean evaluate() throws Exception {
...@@ -180,24 +195,29 @@ public class NotificationHookConsumerIT extends BaseResourceIT { ...@@ -180,24 +195,29 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
final String dbName = "db" + randomString(); final String dbName = "db" + randomString();
entity.set("name", dbName); entity.set("name", dbName);
entity.set("description", randomString()); entity.set("description", randomString());
entity.set("qualifiedName", dbName);
entity.set("clusterName", randomString());
serviceClient.createEntity(entity); serviceClient.createEntity(entity);
final Referenceable newEntity = new Referenceable(DATABASE_TYPE); final Referenceable newEntity = new Referenceable(DATABASE_TYPE);
newEntity.set("name", dbName); newEntity.set("name", randomString());
newEntity.set("description", randomString()); newEntity.set("description", randomString());
newEntity.set("owner", randomString()); newEntity.set("owner", randomString());
newEntity.set("qualifiedName", dbName);
newEntity.set("clusterName", randomString());
//updating unique attribute //updating unique attribute
sendHookMessage(new HookNotification.EntityUpdateRequest(TEST_USER, newEntity)); sendHookMessage(new HookNotification.EntityUpdateRequest(TEST_USER, newEntity));
waitFor(MAX_WAIT_TIME, new Predicate() { waitFor(MAX_WAIT_TIME, new Predicate() {
@Override @Override
public boolean evaluate() throws Exception { public boolean evaluate() throws Exception {
JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE, dbName)); JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE, newEntity.get("qualifiedName")));
return results.length() == 1; return results.length() == 1;
} }
}); });
Referenceable actualEntity = serviceClient.getEntity(DATABASE_TYPE, "name", dbName); Referenceable actualEntity = serviceClient.getEntity(DATABASE_TYPE, "qualifiedName", dbName);
assertEquals(actualEntity.get("description"), newEntity.get("description")); assertEquals(actualEntity.get("description"), newEntity.get("description"));
assertEquals(actualEntity.get("owner"), newEntity.get("owner")); assertEquals(actualEntity.get("owner"), newEntity.get("owner"));
} }
......
...@@ -90,14 +90,11 @@ public abstract class BaseResourceIT { ...@@ -90,14 +90,11 @@ public abstract class BaseResourceIT {
} }
protected void createType(TypesDef typesDef) throws Exception { protected void createType(TypesDef typesDef) throws Exception {
HierarchicalTypeDefinition<ClassType> sampleType = typesDef.classTypesAsJavaList().get(0);
try { try {
serviceClient.getType(sampleType.typeName);
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");
} }
} }
...@@ -186,6 +183,7 @@ public abstract class BaseResourceIT { ...@@ -186,6 +183,7 @@ public abstract class BaseResourceIT {
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.of(enumTypeDefinition),
ImmutableList.of(structTypeDefinition), ImmutableList.of(structTypeDefinition),
ImmutableList.of(classificationTrait, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, financeTrait), ImmutableList.of(classificationTrait, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, financeTrait),
// ImmutableList.<HierarchicalTypeDefinition<ClassType>>of());
ImmutableList.of(dbClsDef, columnClsDef, tblClsDef, loadProcessClsDef)); ImmutableList.of(dbClsDef, columnClsDef, tblClsDef, loadProcessClsDef));
createType(typesDef); createType(typesDef);
...@@ -210,11 +208,7 @@ public abstract class BaseResourceIT { ...@@ -210,11 +208,7 @@ public abstract class BaseResourceIT {
return RandomStringUtils.randomAlphanumeric(10); return RandomStringUtils.randomAlphanumeric(10);
} }
protected Referenceable createHiveTableInstance(String dbName, String tableName) throws Exception { protected Referenceable createHiveTableInstance(Referenceable databaseInstance, String tableName) throws Exception {
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
databaseInstance.set("name", dbName);
databaseInstance.set("description", "foo database");
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 +240,15 @@ public abstract class BaseResourceIT { ...@@ -246,6 +240,15 @@ public abstract class BaseResourceIT {
return tableInstance; return tableInstance;
} }
protected Referenceable createHiveDBInstance(String dbName) {
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
databaseInstance.set("name", dbName);
databaseInstance.set("qualifiedName", dbName);
databaseInstance.set("clusterName", randomString());
databaseInstance.set("description", "foo database");
return databaseInstance;
}
public interface Predicate { public interface Predicate {
/** /**
......
...@@ -167,9 +167,10 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -167,9 +167,10 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
for (int index = 0; index < rows.length(); index++) { for (int index = 0; index < rows.length(); index++) {
final JSONObject row = rows.getJSONObject(index); final JSONObject row = rows.getJSONObject(index);
LOG.info("JsonRow - {}", row);
Assert.assertNotNull(row.getString("name")); Assert.assertNotNull(row.getString("name"));
Assert.assertNotNull(row.getString("comment")); Assert.assertNotNull(row.getString("comment"));
Assert.assertNotNull(row.getString("dataType")); Assert.assertNotNull(row.getString("type"));
Assert.assertEquals(row.getString("$typeName$"), "hive_column"); Assert.assertEquals(row.getString("$typeName$"), "hive_column");
} }
} }
...@@ -185,23 +186,15 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -185,23 +186,15 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
for (int index = 0; index < rows.length(); index++) { for (int index = 0; index < rows.length(); index++) {
final JSONObject row = rows.getJSONObject(index); final JSONObject row = rows.getJSONObject(index);
LOG.info("JsonRow - {}", row);
Assert.assertNotNull(row.getString("name")); Assert.assertNotNull(row.getString("name"));
Assert.assertNotNull(row.getString("comment")); Assert.assertNotNull(row.getString("comment"));
Assert.assertNotNull(row.getString("dataType")); Assert.assertNotNull(row.getString("type"));
Assert.assertEquals(row.getString("$typeName$"), "hive_column"); Assert.assertEquals(row.getString("$typeName$"), "hive_column");
} }
} }
@Test @Test
public void testSchemaForEmptyTable() throws Exception {
WebResource resource = service.path(BASE_URI).path("").path("schema");
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.GET, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}
@Test
public void testSchemaForInvalidTable() throws Exception { public void testSchemaForInvalidTable() throws Exception {
WebResource resource = service.path(BASE_URI).path("blah").path("schema"); WebResource resource = service.path(BASE_URI).path("blah").path("schema");
...@@ -264,6 +257,8 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -264,6 +257,8 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
throws Exception { throws Exception {
Referenceable referenceable = new Referenceable(DATABASE_TYPE, traitNames); Referenceable referenceable = new Referenceable(DATABASE_TYPE, traitNames);
referenceable.set("name", name); referenceable.set("name", name);
referenceable.set("qualifiedName", name);
referenceable.set("clusterName", locationUri + name);
referenceable.set("description", description); referenceable.set("description", description);
referenceable.set("owner", owner); referenceable.set("owner", owner);
referenceable.set("locationUri", locationUri); referenceable.set("locationUri", locationUri);
...@@ -272,10 +267,11 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -272,10 +267,11 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
return createInstance(referenceable); return createInstance(referenceable);
} }
Referenceable column(String name, String dataType, String comment, String... traitNames) throws Exception { Referenceable column(String name, String type, String comment, String... traitNames) throws Exception {
Referenceable referenceable = new Referenceable(COLUMN_TYPE, traitNames); Referenceable referenceable = new Referenceable(COLUMN_TYPE, traitNames);
referenceable.set("name", name); referenceable.set("name", name);
referenceable.set("dataType", dataType); referenceable.set("qualifiedName", name);
referenceable.set("type", type);
referenceable.set("comment", comment); referenceable.set("comment", comment);
return referenceable; return referenceable;
...@@ -304,13 +300,14 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -304,13 +300,14 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
Referenceable referenceable = new Referenceable(HIVE_PROCESS_TYPE, traitNames); Referenceable referenceable = new Referenceable(HIVE_PROCESS_TYPE, traitNames);
referenceable.set("name", name); referenceable.set("name", name);
referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name); referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
referenceable.set("user", user); referenceable.set("userName", user);
referenceable.set("startTime", System.currentTimeMillis()); referenceable.set("startTime", System.currentTimeMillis());
referenceable.set("endTime", System.currentTimeMillis() + 10000); referenceable.set("endTime", System.currentTimeMillis() + 10000);
referenceable.set("inputs", inputTables); referenceable.set("inputs", inputTables);
referenceable.set("outputs", outputTables); referenceable.set("outputs", outputTables);
referenceable.set("operationType", "testOperation");
referenceable.set("queryText", queryText); referenceable.set("queryText", queryText);
referenceable.set("queryPlan", queryPlan); referenceable.set("queryPlan", queryPlan);
referenceable.set("queryId", queryId); referenceable.set("queryId", queryId);
......
...@@ -48,11 +48,13 @@ import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition; ...@@ -48,11 +48,13 @@ import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
import org.apache.atlas.typesystem.types.StructTypeDefinition; import org.apache.atlas.typesystem.types.StructTypeDefinition;
import org.apache.atlas.typesystem.types.TraitType; import org.apache.atlas.typesystem.types.TraitType;
import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.RandomStringUtils;
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.joda.time.DateTime;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testng.Assert; import org.testng.Assert;
...@@ -72,7 +74,6 @@ import java.util.UUID; ...@@ -72,7 +74,6 @@ import java.util.UUID;
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;
import org.apache.atlas.utils.AuthenticationUtil;
/** /**
...@@ -111,7 +112,17 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -111,7 +112,17 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testSubmitEntity() throws Exception { public void testSubmitEntity() throws Exception {
tableInstance = createHiveTableInstance(DATABASE_NAME, TABLE_NAME); Referenceable dbInstance = createHiveDBInstance(DATABASE_NAME);
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();
...@@ -125,7 +136,10 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -125,7 +136,10 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testRequestUser() throws Exception { public void testRequestUser() throws Exception {
Referenceable entity = new Referenceable(DATABASE_TYPE); Referenceable entity = new Referenceable(DATABASE_TYPE);
entity.set("name", randomString()); String dbName = randomString();
entity.set("name", dbName);
entity.set("qualifiedName", dbName);
entity.set("clusterName", randomString());
entity.set("description", randomString()); entity.set("description", randomString());
String user = "admin"; String user = "admin";
...@@ -146,7 +160,10 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -146,7 +160,10 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
//API should accept single entity (or jsonarray of entities) //API should accept single entity (or jsonarray of entities)
public void testSubmitSingleEntity() throws Exception { public void testSubmitSingleEntity() throws Exception {
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE); Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
databaseInstance.set("name", randomString()); String dbName = randomString();
databaseInstance.set("name", dbName);
databaseInstance.set("qualifiedName", dbName);
databaseInstance.set("clusterName", randomString());
databaseInstance.set("description", randomString()); databaseInstance.set("description", randomString());
ClientResponse clientResponse = ClientResponse clientResponse =
...@@ -171,6 +188,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -171,6 +188,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
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); db.set("name", dbName);
db.set("qualifiedName", dbName);
db.set("clusterName", randomString());
db.set("description", randomString()); db.set("description", randomString());
final String dbid = serviceClient.createEntity(db).get(0); final String dbid = serviceClient.createEntity(db).get(0);
...@@ -263,7 +282,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -263,7 +282,8 @@ 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);
databaseInstance.set("name", randomString()); String dbName = randomString();
databaseInstance.set("name", dbName);
databaseInstance.set("description", value); databaseInstance.set("description", value);
try { try {
...@@ -279,19 +299,25 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -279,19 +299,25 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE); Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
String dbName = randomString(); String dbName = randomString();
databaseInstance.set("name", dbName); databaseInstance.set("name", dbName);
databaseInstance.set("qualifiedName", dbName);
databaseInstance.set("clusterName", randomString());
databaseInstance.set("description", "foo database"); databaseInstance.set("description", "foo database");
createInstance(databaseInstance); createInstance(databaseInstance);
//get entity by attribute //get entity by attribute
Referenceable referenceable = serviceClient.getEntity(DATABASE_TYPE, "name", dbName); Referenceable referenceable = serviceClient.getEntity(DATABASE_TYPE, "qualifiedName", dbName);
Assert.assertEquals(referenceable.getTypeName(), DATABASE_TYPE); Assert.assertEquals(referenceable.getTypeName(), DATABASE_TYPE);
Assert.assertEquals(referenceable.get("name"), dbName); Assert.assertEquals(referenceable.get("qualifiedName"), dbName);
} }
@Test @Test
public void testSubmitEntityWithBadDateFormat() throws Exception { public void testSubmitEntityWithBadDateFormat() throws Exception {
try { try {
Referenceable tableInstance = createHiveTableInstance("db" + randomString(), "table" + randomString()); Referenceable hiveDBInstance = createHiveDBInstance("db" + randomString());
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 ");
...@@ -322,7 +348,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -322,7 +348,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
} }
//non-string property, update //non-string property, update
String currentTime = String.valueOf(System.currentTimeMillis()); String currentTime = String.valueOf(new DateTime());
addProperty(guid, "createTime", currentTime); addProperty(guid, "createTime", currentTime);
entityRef = getEntityDefinition(getEntityDefinition(guid)); entityRef = getEntityDefinition(getEntityDefinition(guid));
...@@ -355,7 +381,10 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -355,7 +381,10 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
public void testAddReferenceProperty() throws Exception { public void testAddReferenceProperty() throws Exception {
//Create new db instance //Create new db instance
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE); Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
databaseInstance.set("name", randomString()); String dbName = randomString();
databaseInstance.set("name", dbName);
databaseInstance.set("qualifiedName", dbName);
databaseInstance.set("clusterName", randomString());
databaseInstance.set("description", "new database"); databaseInstance.set("description", "new database");
Id dbInstance = createInstance(databaseInstance); Id dbInstance = createInstance(databaseInstance);
...@@ -733,7 +762,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -733,7 +762,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
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", "col1");
values.put("dataType", "string"); values.put("qualifiedName", "qualifiedName.col1");
values.put("type", "string");
values.put("comment", "col1 comment"); values.put("comment", "col1 comment");
Referenceable ref = new Referenceable(BaseResourceIT.COLUMN_TYPE, values); Referenceable ref = new Referenceable(BaseResourceIT.COLUMN_TYPE, values);
...@@ -755,7 +785,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -755,7 +785,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
Assert.assertTrue(refs.get(0).equalsContents(columns.get(0))); Assert.assertTrue(refs.get(0).equalsContents(columns.get(0)));
//Update by unique attribute //Update by unique attribute
values.put("dataType", "int"); values.put("type", "int");
ref = new Referenceable(BaseResourceIT.COLUMN_TYPE, values); ref = new Referenceable(BaseResourceIT.COLUMN_TYPE, values);
columns.set(0, ref); columns.set(0, ref);
tableUpdated = new Referenceable(BaseResourceIT.HIVE_TABLE_TYPE, new HashMap<String, Object>() {{ tableUpdated = new Referenceable(BaseResourceIT.HIVE_TABLE_TYPE, new HashMap<String, Object>() {{
...@@ -782,12 +812,14 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -782,12 +812,14 @@ 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("dataType", "string"); values1.put("qualifiedName", "qualifiedName.col3");
values1.put("type", "string");
values1.put("comment", "col3 comment"); values1.put("comment", "col3 comment");
Map<String, Object> values2 = new HashMap<>(); Map<String, Object> values2 = new HashMap<>();
values2.put("name", "col4"); values2.put("name", "col4");
values2.put("dataType", "string"); values2.put("qualifiedName", "qualifiedName.col4");
values2.put("type", "string");
values2.put("comment", "col4 comment"); values2.put("comment", "col4 comment");
Referenceable ref1 = new Referenceable(BaseResourceIT.COLUMN_TYPE, values1); Referenceable ref1 = new Referenceable(BaseResourceIT.COLUMN_TYPE, values1);
...@@ -839,11 +871,18 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -839,11 +871,18 @@ 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);
db1.set("name", randomString()); String dbName1 = randomString();
db1.set("name", dbName1);
db1.set("qualifiedName", dbName1);
db1.set("clusterName", randomString());
db1.set("description", randomString()); db1.set("description", randomString());
Id db1Id = createInstance(db1); Id db1Id = createInstance(db1);
Referenceable db2 = new Referenceable(DATABASE_TYPE); Referenceable db2 = new Referenceable(DATABASE_TYPE);
db2.set("name", randomString()); String dbName2 = randomString();
db2.set("name", dbName2);
db2.set("qualifiedName", dbName2);
db2.set("clusterName", randomString());
db2.set("description", randomString()); db2.set("description", randomString());
Id db2Id = createInstance(db2); Id db2Id = createInstance(db2);
...@@ -869,11 +908,17 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -869,11 +908,17 @@ 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);
db1.set("name", randomString()); String dbName1 = randomString();
db1.set("name", dbName1);
db1.set("qualifiedName", dbName1);
db1.set("clusterName", randomString());
db1.set("description", randomString()); db1.set("description", randomString());
Id db1Id = createInstance(db1); Id db1Id = createInstance(db1);
Referenceable db2 = new Referenceable(DATABASE_TYPE); Referenceable db2 = new Referenceable(DATABASE_TYPE);
db2.set("name", randomString()); String dbName2 = randomString();
db2.set("name", dbName2);
db2.set("qualifiedName", dbName2);
db2.set("clusterName", randomString());
db2.set("description", randomString()); db2.set("description", randomString());
Id db2Id = createInstance(db2); Id db2Id = createInstance(db2);
...@@ -899,11 +944,13 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -899,11 +944,13 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
Referenceable db1 = new Referenceable(DATABASE_TYPE); Referenceable db1 = new Referenceable(DATABASE_TYPE);
String dbName = randomString(); String dbName = randomString();
db1.set("name", dbName); db1.set("name", dbName);
db1.set("qualifiedName", dbName);
db1.set("clusterName", randomString());
db1.set("description", randomString()); db1.set("description", randomString());
Id db1Id = createInstance(db1); Id db1Id = createInstance(db1);
// Delete the database entity // Delete the database entity
List<String> deletedGuidsList = serviceClient.deleteEntity(DATABASE_TYPE, "name", dbName).getDeletedEntities(); List<String> deletedGuidsList = serviceClient.deleteEntity(DATABASE_TYPE, "qualifiedName", dbName).getDeletedEntities();
// Verify that deleteEntities() response has database entity guids // Verify that deleteEntities() response has database entity guids
Assert.assertEquals(deletedGuidsList.size(), 1); Assert.assertEquals(deletedGuidsList.size(), 1);
......
...@@ -41,13 +41,13 @@ import java.util.Set; ...@@ -41,13 +41,13 @@ import java.util.Set;
/** /**
* Entity Lineage v2 Integration Tests. * Entity Lineage v2 Integration Tests.
*/ */
public class EntityLineageJerseyResourceIT extends BaseResourceIT { public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceIT {
private static final String BASE_URI = "api/atlas/v2/lineage/"; private static final String BASE_URI = "api/atlas/v2/lineage/";
private static final String INPUT_DIRECTION = "INPUT"; private static final String INPUT_DIRECTION = "INPUT";
private static final String OUTPUT_DIRECTION = "OUTPUT"; private static final String OUTPUT_DIRECTION = "OUTPUT";
private static final String BOTH_DIRECTION = "BOTH"; private static final String BOTH_DIRECTION = "BOTH";
private static final String DIRECTION_PARAM = "direction"; private static final String DIRECTION_PARAM = "direction";
private static final String DEPTH_PARAM = "depth"; private static final String DEPTH_PARAM = "depth";
private String salesFactTable; private String salesFactTable;
private String salesMonthlyTable; private String salesMonthlyTable;
...@@ -191,63 +191,4 @@ public class EntityLineageJerseyResourceIT extends BaseResourceIT { ...@@ -191,63 +191,4 @@ public class EntityLineageJerseyResourceIT extends BaseResourceIT {
loadProcess("loadSalesMonthly" + randomString(), "John ETL", ImmutableList.of(salesFactDaily), loadProcess("loadSalesMonthly" + randomString(), "John ETL", ImmutableList.of(salesFactDaily),
ImmutableList.of(salesFactMonthly), "create table as select ", "plan", "id", "graph"); ImmutableList.of(salesFactMonthly), "create table as select ", "plan", "id", "graph");
} }
Id database(String name, String description, String owner, String locationUri, String... traitNames)
throws Exception {
Referenceable referenceable = new Referenceable(DATABASE_TYPE, traitNames);
referenceable.set("name", name);
referenceable.set("description", description);
referenceable.set("owner", owner);
referenceable.set("locationUri", locationUri);
referenceable.set("createTime", System.currentTimeMillis());
return createInstance(referenceable);
}
Referenceable column(String name, String dataType, String comment, String... traitNames) throws Exception {
Referenceable referenceable = new Referenceable(COLUMN_TYPE, traitNames);
referenceable.set("name", name);
referenceable.set("dataType", dataType);
referenceable.set("comment", comment);
return referenceable;
}
Id table(String name, String description, Id dbId, String owner, String tableType, List<Referenceable> columns,
String... traitNames) throws Exception {
Referenceable referenceable = new Referenceable(HIVE_TABLE_TYPE, traitNames);
referenceable.set("name", name);
referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
referenceable.set("description", description);
referenceable.set("owner", owner);
referenceable.set("tableType", tableType);
referenceable.set("createTime", System.currentTimeMillis());
referenceable.set("lastAccessTime", System.currentTimeMillis());
referenceable.set("retention", System.currentTimeMillis());
referenceable.set("db", dbId);
referenceable.set("columns", columns);
return createInstance(referenceable);
}
Id loadProcess(String name, String user, List<Id> inputTables, List<Id> outputTables, String queryText,
String queryPlan, String queryId, String queryGraph, String... traitNames) throws Exception {
Referenceable referenceable = new Referenceable(HIVE_PROCESS_TYPE, traitNames);
referenceable.set("name", name);
referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
referenceable.set("user", user);
referenceable.set("startTime", System.currentTimeMillis());
referenceable.set("endTime", System.currentTimeMillis() + 10000);
referenceable.set("inputs", inputTables);
referenceable.set("outputs", outputTables);
referenceable.set("queryText", queryText);
referenceable.set("queryPlan", queryPlan);
referenceable.set("queryId", queryId);
referenceable.set("queryGraph", queryGraph);
return createInstance(referenceable);
}
} }
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