use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.
the class EntityJerseyResourceIT method testGetEntityDefinition.
@Test
public void testGetEntityDefinition() 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);
}
Referenceable entity = atlasClientV1.getEntity(guid);
Assert.assertNotNull(entity);
}
use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.
the class EntityJerseyResourceIT method testGetTraitNames.
@Test
public void testGetTraitNames() 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> traits = atlasClientV1.listTraits(guid);
assertNotNull(traits);
Assert.assertEquals(traits.size(), 7);
}
use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.
the class EntityJerseyResourceIT method testAddTraitWithAttribute.
@Test
public void testAddTraitWithAttribute() 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);
}
final String traitName = "PII_Trait" + randomString();
TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet(), TypesUtil.createRequiredAttrDef("type", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
String traitDefinitionAsJSON = AtlasType.toV1Json(piiTrait);
LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
createType(typesDef);
Struct traitInstance = new Struct(traitName);
traitInstance.set("type", "SSN");
atlasClientV1.addTrait(guid, traitInstance);
// verify the response
Referenceable entity = atlasClientV1.getEntity(guid);
Assert.assertNotNull(entity);
Assert.assertEquals(entity.getId()._getId(), guid);
assertNotNull(entity.getTrait(traitName));
assertEquals(entity.getTrait(traitName).get("type"), traitInstance.get("type"));
}
use of org.apache.atlas.v1.model.instance.Id in project 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();
TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet());
String traitDefinitionAsJSON = AtlasType.toV1Json(piiTrait);
LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
createType(typesDef);
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(), BAD_REQUEST);
}
}
use of org.apache.atlas.v1.model.instance.Id in project 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));
}
Aggregations