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);
}
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();
}
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"));
}
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"));
}
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" + "}");
}
Aggregations