use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.
the class AtlasDeleteHandlerV1Test method testDeleteTargetOfRequiredMapReference.
@Test
public void testDeleteTargetOfRequiredMapReference() throws Exception {
// Define type for map value.
AtlasEntityDef mapValueDef = new AtlasEntityDef("RequiredMapValue", "RequiredMapValue_description", "1.0", Collections.<AtlasStructDef.AtlasAttributeDef>emptyList(), Collections.<String>emptySet());
AtlasStructDef.AtlasAttributeDef[] mapOwnerAttributes = new AtlasStructDef.AtlasAttributeDef[] { new AtlasStructDef.AtlasAttributeDef("map", "map<string,RequiredMapValue>", false, AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE, 1, 1, false, false, Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()) };
AtlasEntityDef mapOwnerDef = new AtlasEntityDef("RequiredMapOwner", "RequiredMapOwner_description", "1.0", Arrays.asList(mapOwnerAttributes), Collections.<String>emptySet());
AtlasTypesDef typesDef = AtlasTypeUtil.getTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.<AtlasClassificationDef>of(), ImmutableList.<AtlasEntityDef>of(mapValueDef, mapOwnerDef));
typeDefStore.createTypesDef(typesDef);
AtlasEntityType mapOwnerType = typeRegistry.getEntityTypeByName("RequiredMapOwner");
AtlasEntityType mapValueType = typeRegistry.getEntityTypeByName("RequiredMapValue");
// Create instances of RequiredMapOwner and RequiredMapValue.
// Set RequiredMapOwner.map with one entry that references RequiredMapValue instance.
AtlasEntity mapOwnerInstance = new AtlasEntity(mapOwnerType.getTypeName());
AtlasEntity mapValueInstance = new AtlasEntity(mapValueType.getTypeName());
mapOwnerInstance.setAttribute("map", Collections.singletonMap("value1", AtlasTypeUtil.getAtlasObjectId(mapValueInstance)));
AtlasEntity.AtlasEntitiesWithExtInfo entities = new AtlasEntity.AtlasEntitiesWithExtInfo();
entities.addReferredEntity(mapValueInstance);
entities.addEntity(mapOwnerInstance);
List<AtlasEntityHeader> createEntitiesResult = entityStore.createOrUpdate(new AtlasEntityStream(entities), false).getCreatedEntities();
Assert.assertEquals(createEntitiesResult.size(), 2);
List<String> guids = metadataService.getEntityList("RequiredMapOwner");
Assert.assertEquals(guids.size(), 1);
String mapOwnerGuid = guids.get(0);
guids = metadataService.getEntityList("RequiredMapValue");
Assert.assertEquals(guids.size(), 1);
String mapValueGuid = guids.get(0);
// Verify MapOwner.map attribute has expected value.
final AtlasEntity.AtlasEntityWithExtInfo mapOwnerInstance1 = entityStore.getById(mapOwnerGuid);
Object object = mapOwnerInstance1.getEntity().getAttribute("map");
Assert.assertNotNull(object);
Assert.assertTrue(object instanceof Map);
Map<String, AtlasObjectId> map = (Map<String, AtlasObjectId>) object;
Assert.assertEquals(map.size(), 1);
AtlasObjectId mapValueInstance1 = map.get("value1");
Assert.assertNotNull(mapValueInstance1);
Assert.assertEquals(mapValueInstance1.getGuid(), mapValueGuid);
String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(mapOwnerType, "map");
String mapEntryLabel = edgeLabel + "." + "value1";
AtlasEdgeLabel atlasEdgeLabel = new AtlasEdgeLabel(mapEntryLabel);
AtlasVertex mapOwnerVertex = GraphHelper.getInstance().getVertexForGUID(mapOwnerGuid);
object = mapOwnerVertex.getProperty(atlasEdgeLabel.getQualifiedMapKey(), Object.class);
Assert.assertNotNull(object);
// Verify deleting the target of required map attribute throws a AtlasBaseException.
try {
entityStore.deleteById(mapValueGuid);
Assert.fail(AtlasBaseException.class.getSimpleName() + " was expected but none thrown.");
} catch (Exception e) {
verifyExceptionThrown(e, AtlasBaseException.class);
}
}
use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.
the class ImportTransformsTest method getHiveColumnAtlasEntity.
private AtlasEntity getHiveColumnAtlasEntity(int index) {
AtlasEntity entity = new AtlasEntity("hive_column");
Map<String, Object> attributes = new HashMap<>();
attributes.put(qualifiedName, String.format("col%s.TABLE1.default@cl1", index));
attributes.put("name", "col" + index);
entity.setAttributes(attributes);
return entity;
}
use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.
the class ImportTransformsTest method getHiveTableAtlasEntity.
private AtlasEntity getHiveTableAtlasEntity() {
AtlasEntity entity = new AtlasEntity("hive_table");
Map<String, Object> attributes = new HashMap<>();
attributes.put(qualifiedName, "TABLE1.default" + lowerCaseCL1);
attributes.put("dbname", "someDB");
attributes.put("name", "somename");
entity.setAttributes(attributes);
return entity;
}
use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.
the class ImportTransformsTest method transformEntityWith2Transforms.
@Test
public void transformEntityWith2Transforms() throws AtlasBaseException {
AtlasEntity entity = getHiveTableAtlasEntity();
String attrValue = (String) entity.getAttribute(qualifiedName);
transform.apply(entity);
assertEquals(entity.getAttribute(qualifiedName), applyDefaultTransform(attrValue));
}
use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.
the class AtlasEntityStoreV1Test method testMapOfPrimitivesUpdate.
@Test(dependsOnMethods = "testCreate")
public void testMapOfPrimitivesUpdate() throws Exception {
AtlasEntity tableEntity = new AtlasEntity(tblEntity.getEntity());
AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity);
entitiesInfo.addReferredEntity(tableEntity);
//Add a new entry
Map<String, String> paramsMap = (Map<String, String>) tableEntity.getAttribute("parametersMap");
paramsMap.put("newParam", "value");
init();
EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
validateMutationResponse(response, EntityMutations.EntityOperation.UPDATE, 1);
AtlasEntityHeader updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
validateEntity(entitiesInfo, getEntityFromStore(updatedTable));
//Remove an entry
paramsMap.remove("key1");
init();
response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
validateMutationResponse(response, EntityMutations.EntityOperation.UPDATE, 1);
updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
validateEntity(entitiesInfo, getEntityFromStore(updatedTable));
}
Aggregations