Search in sources :

Example 36 with AtlasRelationshipEndDef

use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef in project incubator-atlas by apache.

the class TestAtlasRelationshipType method testRelationshipAttributesOnExistingAttributes.

@Test(dependsOnMethods = "testRelationshipAttributes")
public void testRelationshipAttributesOnExistingAttributes() throws Exception {
    AtlasRelationshipDef employeePhoneRelationDef = new AtlasRelationshipDef(EMPLOYEE_PHONE_RELATION_TYPE, getDescription(EMPLOYEE_PHONE_RELATION_TYPE), "1.0", RelationshipCategory.ASSOCIATION, PropagateTags.ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "phone_no", Cardinality.SINGLE), new AtlasRelationshipEndDef(PHONE_TYPE, "owner", Cardinality.SINGLE));
    createType(employeePhoneRelationDef);
    Map<String, AtlasAttribute> employeeRelationshipAttrs = getRelationAttrsForType(EMPLOYEE_TYPE);
    Map<String, AtlasAttribute> employeeAttrs = getAttrsForType(EMPLOYEE_TYPE);
    // validate if phone_no exists in both relationAttributes and attributes
    Assert.assertTrue(employeeRelationshipAttrs.containsKey("phone_no"));
    Assert.assertTrue(employeeAttrs.containsKey("phone_no"));
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) Test(org.testng.annotations.Test)

Example 37 with AtlasRelationshipEndDef

use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef in project incubator-atlas by apache.

the class TestAtlasRelationshipType method testvalidateAtlasRelationshipDef.

@Test
public void testvalidateAtlasRelationshipDef() throws AtlasBaseException {
    AtlasRelationshipEndDef ep_single = new AtlasRelationshipEndDef("typeA", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
    AtlasRelationshipEndDef ep_single_container = new AtlasRelationshipEndDef("typeB", "attr2", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
    AtlasRelationshipEndDef ep_single_container_2 = new AtlasRelationshipEndDef("typeC", "attr3", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE, true);
    AtlasRelationshipEndDef ep_single_container_3 = new AtlasRelationshipEndDef("typeD", "attr4", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE, true);
    AtlasRelationshipEndDef ep_SET = new AtlasRelationshipEndDef("typeD", "attr4", AtlasStructDef.AtlasAttributeDef.Cardinality.SET, false);
    AtlasRelationshipEndDef ep_LIST = new AtlasRelationshipEndDef("typeE", "attr5", AtlasStructDef.AtlasAttributeDef.Cardinality.LIST, true);
    AtlasRelationshipEndDef ep_SET_container = new AtlasRelationshipEndDef("typeF", "attr6", AtlasStructDef.AtlasAttributeDef.Cardinality.SET, true);
    AtlasRelationshipDef relationshipDef1 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single, ep_SET);
    AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef1);
    AtlasRelationshipDef relationshipDef2 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_SET_container, ep_single);
    AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef2);
    AtlasRelationshipDef relationshipDef3 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_SET_container, ep_single);
    AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef3);
    try {
        AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single_container_2, ep_single_container);
        AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
        fail("This call is expected to fail");
    } catch (AtlasBaseException abe) {
        if (!abe.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIPDEF_ASSOCIATION_AND_CONTAINER)) {
            fail("This call expected a different error");
        }
    }
    try {
        AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single, ep_single_container);
        AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
        fail("This call is expected to fail");
    } catch (AtlasBaseException abe) {
        if (!abe.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_NO_CONTAINER)) {
            fail("This call expected a different error");
        }
    }
    try {
        AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single, ep_single_container);
        AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
        fail("This call is expected to fail");
    } catch (AtlasBaseException abe) {
        if (!abe.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIPDEF_AGGREGATION_NO_CONTAINER)) {
            fail("This call expected a different error");
        }
    }
    try {
        AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_SET_container, ep_SET);
        AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
        fail("This call is expected to fail");
    } catch (AtlasBaseException abe) {
        if (!abe.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_MULTIPLE_PARENTS)) {
            fail("This call expected a different error");
        }
    }
    try {
        AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single, ep_LIST);
        AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
        fail("This call is expected to fail");
    } catch (AtlasBaseException abe) {
        if (!abe.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIPDEF_LIST_ON_END)) {
            fail("This call expected a different error");
        }
    }
    try {
        AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_LIST, ep_single);
        AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
        fail("This call is expected to fail");
    } catch (AtlasBaseException abe) {
        if (!abe.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIPDEF_LIST_ON_END)) {
            fail("This call expected a different error");
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) Test(org.testng.annotations.Test)

Example 38 with AtlasRelationshipEndDef

use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef in project incubator-atlas by apache.

the class AtlasRelationshipDefStoreV1Test method updateRelCat.

@DataProvider
public Object[][] updateRelCat() {
    AtlasRelationshipDef existingType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    AtlasRelationshipDef newType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    return new Object[][] { { existingType, newType } };
}
Also used : AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) DataProvider(org.testng.annotations.DataProvider)

Example 39 with AtlasRelationshipEndDef

use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef in project incubator-atlas by apache.

the class AtlasRelationshipDefStoreV1Test method updateValidProperties.

@DataProvider
public Object[][] updateValidProperties() {
    AtlasRelationshipDef existingType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "0", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    AtlasRelationshipDef newType = AtlasTypeUtil.createRelationshipTypeDef("basicType", // updated
    "description1", // updated
    "1", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, // updated
    AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    return new Object[][] { { existingType, newType } };
}
Also used : AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) DataProvider(org.testng.annotations.DataProvider)

Example 40 with AtlasRelationshipEndDef

use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef in project incubator-atlas by apache.

the class AtlasRelationshipDefStoreV1Test method updateEnd1.

@DataProvider
public Object[][] updateEnd1() {
    AtlasRelationshipDef existingType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    AtlasRelationshipDef changeType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeE", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    AtlasRelationshipDef changeAttr = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr2", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    AtlasRelationshipDef changeCardinality = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.LIST), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    return new Object[][] { { existingType, changeType }, { existingType, changeAttr }, { existingType, changeCardinality } };
}
Also used : AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) DataProvider(org.testng.annotations.DataProvider)

Aggregations

AtlasRelationshipEndDef (org.apache.atlas.model.typedef.AtlasRelationshipEndDef)40 AtlasRelationshipDef (org.apache.atlas.model.typedef.AtlasRelationshipDef)25 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)13 DataProvider (org.testng.annotations.DataProvider)10 RelationshipCategory (org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory)6 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)4 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)4 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)4 Test (org.testng.annotations.Test)4 PropagateTags (org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags)3 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)3 AtlasRelationshipType (org.apache.atlas.type.AtlasRelationshipType)3 AtlasException (org.apache.atlas.AtlasException)2 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)2 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)2 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)2 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)2 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)2 AtlasRelationshipEdgeDirection (org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection)2 AtlasType (org.apache.atlas.type.AtlasType)2