Search in sources :

Example 21 with ITypedStruct

use of org.apache.atlas.typesystem.ITypedStruct in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryTest method testAddTrait.

@Test(dependsOnMethods = "testGetTraitNames")
public void testAddTrait() throws Exception {
    final String aGUID = getGUID();
    AtlasVertex AtlasVertex = GraphHelper.getInstance().getVertexForGUID(aGUID);
    Long modificationTimestampPreUpdate = GraphHelper.getSingleValuedProperty(AtlasVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
    Assert.assertNotNull(modificationTimestampPreUpdate);
    List<String> traitNames = repositoryService.getTraitNames(aGUID);
    System.out.println("traitNames = " + traitNames);
    Assert.assertEquals(traitNames.size(), 1);
    Assert.assertTrue(traitNames.contains(TestUtils.CLASSIFICATION));
    Assert.assertFalse(traitNames.contains(TestUtils.PII));
    TraitType traitType = typeSystem.getDataType(TraitType.class, TestUtils.PII);
    ITypedStruct traitInstance = traitType.createInstance();
    repositoryService.addTrait(aGUID, traitInstance);
    // refresh trait names
    traitNames = repositoryService.getTraitNames(aGUID);
    Assert.assertEquals(traitNames.size(), 2);
    Assert.assertTrue(traitNames.contains(TestUtils.PII));
    Assert.assertTrue(traitNames.contains(TestUtils.CLASSIFICATION));
    // Verify modification timestamp was updated.
    GraphHelper.getInstance().getVertexForGUID(aGUID);
    Long modificationTimestampPostUpdate = GraphHelper.getSingleValuedProperty(AtlasVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
    Assert.assertNotNull(modificationTimestampPostUpdate);
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) TraitType(org.apache.atlas.typesystem.types.TraitType) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) Test(org.testng.annotations.Test)

Example 22 with ITypedStruct

use of org.apache.atlas.typesystem.ITypedStruct in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryTest method testAddTraitForBadEntity.

@Test(dependsOnMethods = "testAddTrait", expectedExceptions = RepositoryException.class)
public void testAddTraitForBadEntity() throws Exception {
    TraitType traitType = typeSystem.getDataType(TraitType.class, TestUtils.PII);
    ITypedStruct traitInstance = traitType.createInstance();
    repositoryService.addTrait(UUID.randomUUID().toString(), traitInstance);
    Assert.fail();
}
Also used : TraitType(org.apache.atlas.typesystem.types.TraitType) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) Test(org.testng.annotations.Test)

Example 23 with ITypedStruct

use of org.apache.atlas.typesystem.ITypedStruct in project incubator-atlas by apache.

the class GraphBackedRepositoryHardDeleteTest method assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes.

@Override
protected void assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes(String structContainerGuid) throws Exception {
    // Verify that the unidirectional references from the struct and trait instances
    // to the deleted entities were disconnected.
    ITypedReferenceableInstance structContainerConvertedEntity = repositoryService.getEntityDefinition(structContainerGuid);
    ITypedStruct struct = (ITypedStruct) structContainerConvertedEntity.get("struct");
    assertNull(struct.get("target"));
    IStruct trait = structContainerConvertedEntity.getTrait("TestTrait");
    assertNotNull(trait);
    assertNull(trait.get("target"));
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct)

Example 24 with ITypedStruct

use of org.apache.atlas.typesystem.ITypedStruct in project incubator-atlas by apache.

the class GraphBackedRepositorySoftDeleteTest method assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes.

@Override
protected void assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes(String structContainerGuid) throws Exception {
    // Verify that the unidirectional references from the struct and trait instances
    // to the deleted entities were not disconnected.
    ITypedReferenceableInstance structContainerConvertedEntity = repositoryService.getEntityDefinition(structContainerGuid);
    ITypedStruct struct = (ITypedStruct) structContainerConvertedEntity.get("struct");
    assertNotNull(struct.get("target"));
    IStruct trait = structContainerConvertedEntity.getTrait("TestTrait");
    assertNotNull(trait);
    assertNotNull(trait.get("target"));
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct)

Example 25 with ITypedStruct

use of org.apache.atlas.typesystem.ITypedStruct in project incubator-atlas by apache.

the class StructTest method testRecursive.

@Test
public void testRecursive() throws AtlasException {
    Struct s1 = new Struct(recursiveStructType.getName());
    s1.set("a", 1);
    Struct s2 = new Struct(recursiveStructType.getName());
    s2.set("a", 1);
    s2.set("s", s1);
    ITypedStruct ts = recursiveStructType.convert(s2, Multiplicity.REQUIRED);
    Assert.assertEquals(ts.toString(), "{\n" + "\ta : \t1\n" + "\ts : \t{\n" + "\t\ta : \t\t1\n" + "\t\ts : <null>\n" + "\n" + "\t}\n" + "}");
}
Also used : ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Aggregations

ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)29 Test (org.testng.annotations.Test)14 IStruct (org.apache.atlas.typesystem.IStruct)13 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)13 Struct (org.apache.atlas.typesystem.Struct)11 TraitType (org.apache.atlas.typesystem.types.TraitType)6 AtlasException (org.apache.atlas.AtlasException)5 ImmutableList (com.google.common.collect.ImmutableList)4 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)4 List (java.util.List)3 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)3 Id (org.apache.atlas.typesystem.persistence.Id)3 ArrayList (java.util.ArrayList)2 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 EntityChangeListener (org.apache.atlas.listener.EntityChangeListener)2 Referenceable (org.apache.atlas.typesystem.Referenceable)2 TypesDef (org.apache.atlas.typesystem.TypesDef)2 StructType (org.apache.atlas.typesystem.types.StructType)2 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)2 BeforeTest (org.testng.annotations.BeforeTest)2