GraphBackedMetadataRepository implements MetadataRepository { @Override @GraphTransaction public void addTrait(List<String> entityGuids, ITypedStruct traitInstance) throws RepositoryException { Preconditions.checkNotNull(entityGuids, "entityGuids list cannot be null"); Preconditions.checkNotNull(traitInstance, "Trait instance cannot be null"); if (LOG.isDebugEnabled()) { LOG.debug("Adding a new trait={} for entities={}", traitInstance.getTypeName(), entityGuids); } GraphTransactionInterceptor.lockObjectAndReleasePostCommit(entityGuids); for (String entityGuid : entityGuids) { addTraitImpl(entityGuid, traitInstance); } } @Inject  GraphBackedMetadataRepository(DeleteHandler deleteHandler, AtlasGraph atlasGraph); GraphToTypedInstanceMapper getGraphToInstanceMapper(); @Override String getTypeAttributeName(); @Override String getStateAttributeName(); @Override String getSuperTypeAttributeName(); String getIdAttributeName(); @Override String getVersionAttributeName(); @Override String getTraitLabel(IDataType<?> dataType, String traitName); @Override String getFieldNameInVertex(IDataType<?> dataType, AttributeInfo aInfo); String getFieldNameInVertex(IDataType<?> dataType, String attrName); @Override String getEdgeLabel(IDataType<?> dataType, AttributeInfo aInfo); @Override @GraphTransaction CreateUpdateEntitiesResult createEntities(ITypedReferenceableInstance... entities); @Override @GraphTransaction ITypedReferenceableInstance getEntityDefinition(String guid); @Override @GraphTransaction List<ITypedReferenceableInstance> getEntityDefinitions(String... guids); @Override @GraphTransaction ITypedReferenceableInstance getEntityDefinition(String entityType, String attribute, Object value); @Override @GraphTransaction List<String> getEntityList(String entityType); @Override @GraphTransaction List<String> getTraitNames(String guid); @Override @GraphTransaction void addTrait(List<String> entityGuids, ITypedStruct traitInstance); @Override @GraphTransaction void addTrait(String guid, ITypedStruct traitInstance); @Override @GraphTransaction void deleteTrait(String guid, String traitNameToBeDeleted); @Override @GraphTransaction CreateUpdateEntitiesResult updateEntities(ITypedReferenceableInstance... entitiesUpdated); @Override @GraphTransaction CreateUpdateEntitiesResult updatePartial(ITypedReferenceableInstance entity); @Override @GraphTransaction EntityResult deleteEntities(List<String> guids); AtlasGraph getGraph();  }
@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); traitNames = repositoryService.getTraitNames(aGUID); Assert.assertEquals(traitNames.size(), 2); Assert.assertTrue(traitNames.contains(TestUtils.PII)); Assert.assertTrue(traitNames.contains(TestUtils.CLASSIFICATION)); GraphHelper.getInstance().getVertexForGUID(aGUID); Long modificationTimestampPostUpdate = GraphHelper.getSingleValuedProperty(AtlasVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class); Assert.assertNotNull(modificationTimestampPostUpdate); }
@Test(expectedExceptions = NullPointerException.class) public void testAddTraitWithNullInstance() throws Exception { repositoryService.addTrait(getGUID(), null); Assert.fail(); }
@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(); }