use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.
the class EntityJerseyResourceIT method testCompleteUpdate.
@Test
public void testCompleteUpdate() throws Exception {
String dbName = "db" + randomString();
String tableName = "table" + randomString();
Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
Id dbId = createInstance(hiveDBInstance);
Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
Id tableId = createInstance(hiveTableInstance);
final String guid = tableId._getId();
try {
Assert.assertNotNull(UUID.fromString(guid));
} catch (IllegalArgumentException e) {
Assert.fail("Response is not a guid, " + guid);
}
final List<Referenceable> columns = new ArrayList<>();
Map<String, Object> values1 = new HashMap<>();
values1.put(NAME, "col3");
values1.put(QUALIFIED_NAME, "default.table.col3@cl1");
values1.put("comment", "col3 comment");
values1.put("type", "string");
values1.put("owner", "user1");
values1.put("position", 0);
values1.put("description", "col3");
values1.put("table", tableId);
Map<String, Object> values2 = new HashMap<>();
values2.put(NAME, "col4");
values2.put(QUALIFIED_NAME, "default.table.col4@cl1");
values2.put("comment", "col4 comment");
values2.put("type", "string");
values2.put("owner", "user2");
values2.put("position", 1);
values2.put("description", "col4");
values2.put("table", tableId);
Referenceable ref1 = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values1);
Referenceable ref2 = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values2);
columns.add(ref1);
columns.add(ref2);
hiveTableInstance.set("columns", columns);
LOG.debug("Replacing entity= {}", hiveTableInstance);
EntityResult updateEntity = atlasClientV1.updateEntities(hiveTableInstance);
assertNotNull(updateEntity.getUpdateEntities());
hiveTableInstance = atlasClientV1.getEntity(guid);
List<Referenceable> refs = (List<Referenceable>) hiveTableInstance.get("columns");
Assert.assertEquals(refs.size(), 2);
Assert.assertTrue(refs.get(0).getValuesMap().equals(values1));
Assert.assertTrue(refs.get(1).getValuesMap().equals(values2));
}
use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.
the class EntityJerseyResourceIT method testAddExistingTrait.
@Test
public void testAddExistingTrait() throws Exception {
String dbName = "db" + randomString();
String tableName = "table" + randomString();
Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
Id dbId = createInstance(hiveDBInstance);
Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
Id id = createInstance(hiveTableInstance);
final String guid = id._getId();
try {
Assert.assertNotNull(UUID.fromString(guid));
} catch (IllegalArgumentException e) {
Assert.fail("Response is not a guid, " + guid);
}
String traitName = "PII_Trait" + randomString();
HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
createType(traitDefinitionAsJSON);
Struct traitInstance = new Struct(traitName);
atlasClientV1.addTrait(guid, traitInstance);
try {
atlasClientV1.addTrait(guid, traitInstance);
fail("Duplicate trait addition should've failed");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST);
}
}
use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.
the class EntityJerseyResourceIT method testAddNullProperty.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testAddNullProperty() throws Exception {
String dbName = "db" + randomString();
String tableName = "table" + randomString();
Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
Id dbId = createInstance(hiveDBInstance);
Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
Id id = createInstance(hiveTableInstance);
final String guid = id._getId();
try {
Assert.assertNotNull(UUID.fromString(guid));
} catch (IllegalArgumentException e) {
Assert.fail("Response is not a guid, " + guid);
}
//add property
addProperty(guid, null, "foo bar");
Assert.fail();
}
use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.
the class EntityJerseyResourceIT method testGetEntityList.
@Test
public void testGetEntityList() throws Exception {
String dbName = "db" + randomString();
String tableName = "table" + randomString();
Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
Id dbId = createInstance(hiveDBInstance);
Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
Id id = createInstance(hiveTableInstance);
final String guid = id._getId();
try {
Assert.assertNotNull(UUID.fromString(guid));
} catch (IllegalArgumentException e) {
Assert.fail("Response is not a guid, " + guid);
}
List<String> entities = atlasClientV1.listEntities(HIVE_TABLE_TYPE_BUILTIN);
Assert.assertNotNull(entities);
Assert.assertTrue(entities.contains(guid));
}
use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.
the class EntityJerseyResourceIT method testDeleteEntitiesViaClientApi.
@Test
public void testDeleteEntitiesViaClientApi() throws Exception {
// Create 2 database entities
Referenceable db1 = new Referenceable(DATABASE_TYPE_BUILTIN);
String dbName = randomString();
db1.set("name", dbName);
db1.set("description", randomString());
db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
db1.set("owner", "user1");
db1.set(CLUSTER_NAME, "cl1");
db1.set("parameters", Collections.EMPTY_MAP);
db1.set("location", "/tmp");
Id db1Id = createInstance(db1);
Referenceable db2 = new Referenceable(DATABASE_TYPE_BUILTIN);
String dbName2 = randomString();
db2.set("name", dbName2);
db2.set(QUALIFIED_NAME, dbName2);
db2.set(CLUSTER_NAME, 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);
// Delete the database entities
List<String> deletedGuidsList = atlasClientV1.deleteEntities(db1Id._getId(), db2Id._getId()).getDeletedEntities();
// Verify that deleteEntities() response has database entity guids
Assert.assertEquals(deletedGuidsList.size(), 2);
Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
Assert.assertTrue(deletedGuidsList.contains(db2Id._getId()));
// Verify entities were deleted from the repository.
for (String guid : deletedGuidsList) {
Referenceable entity = atlasClientV1.getEntity(guid);
assertEquals(entity.getId().getState(), Id.EntityState.DELETED);
}
}
Aggregations