Search in sources :

Example 46 with AtlasTypesDef

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

the class AtlasEntityStoreV1Test method testTagAssociationAfterRedefinition.

@Test
public void testTagAssociationAfterRedefinition() {
    AtlasClassificationDef aTag = new AtlasClassificationDef("testTag");
    AtlasAttributeDef attributeDef = new AtlasAttributeDef("testAttribute", "int", true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, true, Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
    aTag.addAttribute(attributeDef);
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.setClassificationDefs(Arrays.asList(aTag));
    try {
        typeDefStore.createTypesDef(typesDef);
    } catch (AtlasBaseException e) {
        fail("Tag creation should've succeeded");
    }
    try {
        typeDefStore.deleteTypesDef(typesDef);
    } catch (AtlasBaseException e) {
        fail("Tag deletion should've succeeded");
    }
    aTag = new AtlasClassificationDef("testTag");
    attributeDef = new AtlasAttributeDef("testAttribute", "string", true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, true, Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
    aTag.addAttribute(attributeDef);
    typesDef.setClassificationDefs(Arrays.asList(aTag));
    try {
        typeDefStore.createTypesDef(typesDef);
    } catch (AtlasBaseException e) {
        fail("Tag re-creation should've succeeded");
    }
    final AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
    try {
        EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);
        List<AtlasEntityHeader> createdEntity = response.getCreatedEntities();
        assertTrue(CollectionUtils.isNotEmpty(createdEntity));
        String guid = createdEntity.get(0).getGuid();
        entityStore.addClassification(Arrays.asList(guid), new AtlasClassification(aTag.getName(), "testAttribute", "test-string"));
    } catch (AtlasBaseException e) {
        fail("DB entity creation should've succeeded");
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) TestUtils.randomString(org.apache.atlas.TestUtils.randomString) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 47 with AtlasTypesDef

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

the class AtlasEntityStoreV1Test method setUp.

@BeforeClass
public void setUp() throws Exception {
    metadataService = TestUtils.addSessionCleanupWrapper(metadataService);
    new GraphBackedSearchIndexer(typeRegistry);
    AtlasTypesDef[] testTypesDefs = new AtlasTypesDef[] { TestUtilsV2.defineDeptEmployeeTypes(), TestUtilsV2.defineHiveTypes() };
    for (AtlasTypesDef typesDef : testTypesDefs) {
        AtlasTypesDef typesToCreate = AtlasTypeDefStoreInitializer.getTypesToCreate(typesDef, typeRegistry);
        if (!typesToCreate.isEmpty()) {
            typeDefStore.createTypesDef(typesToCreate);
        }
    }
    deptEntity = TestUtilsV2.createDeptEg2();
    dbEntity = TestUtilsV2.createDBEntityV2();
    tblEntity = TestUtilsV2.createTableEntityV2(dbEntity.getEntity());
}
Also used : GraphBackedSearchIndexer(org.apache.atlas.repository.graph.GraphBackedSearchIndexer) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) BeforeClass(org.testng.annotations.BeforeClass)

Example 48 with AtlasTypesDef

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

the class AtlasEntityStoreV1Test method testSpecialCharacters.

@Test(enabled = false)
public //TODO : Failing in typedef creation
void testSpecialCharacters() throws Exception {
    //Verify that type can be created with reserved characters in typename, attribute name
    final String typeName = "test_type_" + RandomStringUtils.randomAlphanumeric(10);
    String strAttrName = randomStrWithReservedChars();
    String arrayAttrName = randomStrWithReservedChars();
    String mapAttrName = randomStrWithReservedChars();
    AtlasEntityDef typeDefinition = AtlasTypeUtil.createClassTypeDef(typeName, "Special chars test type", ImmutableSet.<String>of(), AtlasTypeUtil.createOptionalAttrDef(strAttrName, "string"), AtlasTypeUtil.createOptionalAttrDef(arrayAttrName, "array<string>"), AtlasTypeUtil.createOptionalAttrDef(mapAttrName, "map<string,string>"));
    AtlasTypesDef atlasTypesDef = new AtlasTypesDef(null, null, null, Arrays.asList(typeDefinition));
    typeDefStore.createTypesDef(atlasTypesDef);
    //verify that entity can be created with reserved characters in string value, array value and map key and value
    AtlasEntity entity = new AtlasEntity();
    entity.setAttribute(strAttrName, randomStrWithReservedChars());
    entity.setAttribute(arrayAttrName, new String[] { randomStrWithReservedChars() });
    entity.setAttribute(mapAttrName, new HashMap<String, String>() {

        {
            put(randomStrWithReservedChars(), randomStrWithReservedChars());
        }
    });
    AtlasEntityWithExtInfo entityWithExtInfo = new AtlasEntityWithExtInfo(entity);
    final EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entityWithExtInfo), false);
    final AtlasEntityHeader firstEntityCreated = response.getFirstEntityCreated();
    validateEntity(entityWithExtInfo, getEntityFromStore(firstEntityCreated));
//Verify that search with reserved characters works - for string attribute
//        String query =
//            String.format("`%s` where `%s` = '%s'", typeName, strAttrName, entity.getAttribute(strAttrName));
//        String responseJson = discoveryService.searchByDSL(query, new QueryParams(1, 0));
//        JSONObject response = new JSONObject(responseJson);
//        assertEquals(response.getJSONArray("rows").length(), 1);
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) TestUtils.randomString(org.apache.atlas.TestUtils.randomString) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 49 with AtlasTypesDef

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

the class AtlasTypeDefGraphStoreTest method allCreatedTypes.

@DataProvider
public Object[][] allCreatedTypes() {
    // Capture all the types that are getting created or updated here.
    AtlasTypesDef updatedTypeDefs = TestUtilsV2.defineValidUpdatedDeptEmployeeTypes();
    AtlasTypesDef allTypeDefs = new AtlasTypesDef();
    allTypeDefs.getEnumDefs().addAll(updatedTypeDefs.getEnumDefs());
    allTypeDefs.getStructDefs().addAll(updatedTypeDefs.getStructDefs());
    allTypeDefs.getClassificationDefs().addAll(updatedTypeDefs.getClassificationDefs());
    allTypeDefs.getEntityDefs().addAll(updatedTypeDefs.getEntityDefs());
    allTypeDefs.getEntityDefs().addAll(TestUtilsV2.getEntityWithValidSuperType());
    return new Object[][] { { allTypeDefs } };
}
Also used : AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) DataProvider(org.testng.annotations.DataProvider)

Example 50 with AtlasTypesDef

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

the class AtlasTypeDefGraphStoreTest method testCreateWithValidSuperTypes.

@Test(dependsOnMethods = "testGet")
public void testCreateWithValidSuperTypes() {
    // Test Classification with supertype
    List<AtlasClassificationDef> classificationDefs = TestUtilsV2.getClassificationWithValidSuperType();
    AtlasTypesDef toCreate = new AtlasTypesDef(Collections.<AtlasEnumDef>emptyList(), Collections.<AtlasStructDef>emptyList(), classificationDefs, Collections.<AtlasEntityDef>emptyList());
    try {
        AtlasTypesDef created = typeDefStore.createTypesDef(toCreate);
        assertEquals(created.getClassificationDefs(), toCreate.getClassificationDefs(), "Classification creation with valid supertype should've succeeded");
    } catch (AtlasBaseException e) {
        fail("Classification creation with valid supertype should've succeeded");
    }
    // Test Entity with supertype
    List<AtlasEntityDef> entityDefs = TestUtilsV2.getEntityWithValidSuperType();
    toCreate = new AtlasTypesDef(Collections.<AtlasEnumDef>emptyList(), Collections.<AtlasStructDef>emptyList(), Collections.<AtlasClassificationDef>emptyList(), entityDefs);
    try {
        AtlasTypesDef created = typeDefStore.createTypesDef(toCreate);
        assertEquals(created.getEntityDefs(), toCreate.getEntityDefs(), "Entity creation with valid supertype should've succeeded");
    } catch (AtlasBaseException e) {
        fail("Entity creation with valid supertype should've succeeded");
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Aggregations

AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)64 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)30 Test (org.testng.annotations.Test)25 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)22 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)20 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)16 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)13 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)12 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)9 SearchFilter (org.apache.atlas.model.SearchFilter)8 ArrayList (java.util.ArrayList)7 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)7 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)7 HashMap (java.util.HashMap)6 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)6 BeforeClass (org.testng.annotations.BeforeClass)6 BeforeTest (org.testng.annotations.BeforeTest)5 Produces (javax.ws.rs.Produces)4 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)4 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)4