Search in sources :

Example 31 with EntityResult

use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryDeleteTestBase method testLowerBoundsIgnoredOnCompositeDeletedEntities.

@Test
public void testLowerBoundsIgnoredOnCompositeDeletedEntities() throws Exception {
    String hrDeptGuid = createHrDeptGraph();
    ITypedReferenceableInstance hrDept = repositoryService.getEntityDefinition(hrDeptGuid);
    Map<String, String> nameGuidMap = getEmployeeNameGuidMap(hrDept);
    ITypedReferenceableInstance john = repositoryService.getEntityDefinition(nameGuidMap.get("John"));
    String johnGuid = john.getId()._getId();
    ITypedReferenceableInstance max = repositoryService.getEntityDefinition(nameGuidMap.get("Max"));
    String maxGuid = max.getId()._getId();
    // The lower bound constraint on Manager.subordinates should not be enforced on the composite entity
    // for Jane owned by the Department entity, since that entity is being deleted.
    // Prior to the fix for ATLAS-991, this call would fail with a NullRequiredAttributeException.
    EntityResult deleteResult = deleteEntities(johnGuid, maxGuid, hrDeptGuid);
    Assert.assertEquals(deleteResult.getDeletedEntities().size(), 5);
    Assert.assertTrue(deleteResult.getDeletedEntities().containsAll(nameGuidMap.values()));
    Assert.assertTrue(deleteResult.getDeletedEntities().contains(hrDeptGuid));
    assertTestLowerBoundsIgnoredOnCompositeDeletedEntities(hrDeptGuid);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Example 32 with EntityResult

use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryDeleteTestBase method testDeleteCompositeEntityAndContainer.

@Test
public void testDeleteCompositeEntityAndContainer() throws Exception {
    Referenceable db = createDBEntity();
    String dbId = createInstance(db);
    Referenceable column = createColumnEntity();
    String colId = createInstance(column);
    Referenceable table1 = createTableEntity(dbId);
    table1.set(COLUMNS_ATTR_NAME, Arrays.asList(new Id(colId, 0, COLUMN_TYPE)));
    String table1Id = createInstance(table1);
    Referenceable table2 = createTableEntity(dbId);
    String table2Id = createInstance(table2);
    // Delete the tables and column
    EntityResult entityResult = deleteEntities(table1Id, colId, table2Id);
    Assert.assertEquals(entityResult.getDeletedEntities().size(), 3);
    Assert.assertTrue(entityResult.getDeletedEntities().containsAll(Arrays.asList(colId, table1Id, table2Id)));
    assertEntityDeleted(table1Id);
    assertEntityDeleted(colId);
    assertEntityDeleted(table2Id);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) Id(org.apache.atlas.typesystem.persistence.Id) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Example 33 with EntityResult

use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.

the class DefaultMetadataServiceTest method testUpdateEntityArrayOfClass.

@Test
public void testUpdateEntityArrayOfClass() throws Exception {
    //test array of class with id
    final List<Referenceable> columns = new ArrayList<>();
    Map<String, Object> values = new HashMap<>();
    values.put(NAME, "col1");
    values.put("type", "type");
    Referenceable col1 = new Referenceable(TestUtils.COLUMN_TYPE, values);
    columns.add(col1);
    Referenceable tableUpdated = new Referenceable(TestUtils.TABLE_TYPE, new HashMap<String, Object>() {

        {
            put(COLUMNS_ATTR_NAME, columns);
        }
    });
    EntityResult entityResult = updateEntityPartial(tableId._getId(), tableUpdated);
    //col1 created
    assertEquals(entityResult.getCreatedEntities().size(), 1);
    //table updated
    assertEquals(entityResult.getUpdateEntities().size(), 1);
    assertEquals(entityResult.getUpdateEntities().get(0), tableId._getId());
    verifyArrayUpdates(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME), columns, COLUMNS_ATTR_NAME);
    //Partial update. Add col2 But also update col1
    Map<String, Object> valuesCol5 = new HashMap<>();
    valuesCol5.put(NAME, "col2");
    valuesCol5.put("type", "type");
    Referenceable col2 = new Referenceable(TestUtils.COLUMN_TYPE, valuesCol5);
    //update col1
    col1.set("type", "type1");
    columns.add(col2);
    tableUpdated = new Referenceable(TestUtils.TABLE_TYPE, new HashMap<String, Object>() {

        {
            put(COLUMNS_ATTR_NAME, columns);
        }
    });
    entityResult = updateEntityPartial(tableId._getId(), tableUpdated);
    //col2 created
    assertEquals(entityResult.getCreatedEntities().size(), 1);
    //table, col1 updated
    assertEquals(entityResult.getUpdateEntities().size(), 2);
    verifyArrayUpdates(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME), columns, COLUMNS_ATTR_NAME);
    //Complete update. Add  array elements - col3,col4
    Map<String, Object> values1 = new HashMap<>();
    values1.put(NAME, "col3");
    values1.put("type", "type");
    Referenceable col3 = new Referenceable(TestUtils.COLUMN_TYPE, values1);
    columns.add(col3);
    Map<String, Object> values2 = new HashMap<>();
    values2.put(NAME, "col4");
    values2.put("type", "type");
    Referenceable col4 = new Referenceable(TestUtils.COLUMN_TYPE, values2);
    columns.add(col4);
    table.set(COLUMNS_ATTR_NAME, columns);
    entityResult = updateInstance(table);
    //col3, col4 created
    assertEquals(entityResult.getCreatedEntities().size(), 2);
    verifyArrayUpdates(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME), columns, COLUMNS_ATTR_NAME);
    //Swap elements
    columns.clear();
    columns.add(col4);
    columns.add(col3);
    table.set(COLUMNS_ATTR_NAME, columns);
    entityResult = updateInstance(table);
    //col1, col2 are deleted
    assertEquals(entityResult.getDeletedEntities().size(), 2);
    verifyArrayUpdates(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME), columns, COLUMNS_ATTR_NAME);
    //drop a single column
    columns.clear();
    columns.add(col3);
    table.set(COLUMNS_ATTR_NAME, columns);
    entityResult = updateInstance(table);
    //col4 deleted
    assertEquals(entityResult.getDeletedEntities().size(), 1);
    verifyArrayUpdates(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME), columns, COLUMNS_ATTR_NAME);
    //Remove a class reference/Id and insert another reference
    //Also covers isComposite case since columns is a composite
    values.clear();
    columns.clear();
    values.put(NAME, "col5");
    values.put("type", "type");
    Referenceable col5 = new Referenceable(TestUtils.COLUMN_TYPE, values);
    columns.add(col5);
    table.set(COLUMNS_ATTR_NAME, columns);
    entityResult = updateInstance(table);
    //col5 created
    assertEquals(entityResult.getCreatedEntities().size(), 1);
    //col3 deleted
    assertEquals(entityResult.getDeletedEntities().size(), 1);
    verifyArrayUpdates(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME), columns, COLUMNS_ATTR_NAME);
    //Update array column to null
    table.setNull(COLUMNS_ATTR_NAME);
    entityResult = updateInstance(table);
    assertEquals(entityResult.getDeletedEntities().size(), 1);
    verifyArrayUpdates(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME), null, COLUMNS_ATTR_NAME);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONObject(org.codehaus.jettison.json.JSONObject) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

EntityResult (org.apache.atlas.model.legacy.EntityResult)33 Test (org.testng.annotations.Test)21 ArrayList (java.util.ArrayList)12 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)12 JSONObject (org.codehaus.jettison.json.JSONObject)12 List (java.util.List)11 Referenceable (org.apache.atlas.typesystem.Referenceable)11 ImmutableList (com.google.common.collect.ImmutableList)10 Id (org.apache.atlas.typesystem.persistence.Id)6 HashMap (java.util.HashMap)5 WebResource (com.sun.jersey.api.client.WebResource)4 GuidMapping (org.apache.atlas.model.instance.GuidMapping)4 Map (java.util.Map)3 AtlasException (org.apache.atlas.AtlasException)3 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)3 BaseRepositoryTest (org.apache.atlas.BaseRepositoryTest)2 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)2 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)2 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)2 RepositoryException (org.apache.atlas.repository.RepositoryException)2