Repository: incubator-atlas Updated Branches: refs/heads/0.7-incubating a015dbb9d -> bfb60aa14
ATLAS-931 Delete entities fails when hard delete is configured (dkantor via sumasai) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/bfb60aa1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/bfb60aa1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/bfb60aa1 Branch: refs/heads/0.7-incubating Commit: bfb60aa1497c2ff20a12bda115beafc7344549aa Parents: a015dbb Author: Suma Shivaprasad <[email protected]> Authored: Tue Jun 21 17:49:40 2016 -0700 Committer: Suma Shivaprasad <[email protected]> Committed: Tue Jun 21 17:50:02 2016 -0700 ---------------------------------------------------------------------- release-log.txt | 1 + .../atlas/web/resources/EntityResource.java | 3 - .../atlas/web/resources/EntityResourceTest.java | 74 ++++++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bfb60aa1/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index f325891..2f10a70 100644 --- a/release-log.txt +++ b/release-log.txt @@ -31,6 +31,7 @@ ATLAS-409 Atlas will not import avro tables with schema read from a file (dosset ATLAS-379 Create sqoop and falcon metadata addons (venkatnrangan,bvellanki,sowmyaramesh via shwethags) ALL CHANGES: +ATLAS-931 Delete entities fails when hard delete is configured (dkantor via sumasai) ATLAS-932 UI: 'create tag' button does not work (mneethiraj via sumasai) ATLAS-928 UI is not showing the name column for hive tables in the schema tab (yhemanth via sumasai) ATLAS-922 remove test atlas-application.properties embedded in atlas-typesystem.jar ( mneethiraj via sumasai) http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bfb60aa1/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java index 76e8276..21ed04f 100755 --- a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java +++ b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java @@ -216,9 +216,6 @@ public class EntityResource { if (sample == null) { sample = getSample(entityResult.getUpdateEntities()); } - if (sample == null) { - sample = getSample(entityResult.getDeletedEntities()); - } return sample; } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bfb60aa1/webapp/src/test/java/org/apache/atlas/web/resources/EntityResourceTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/EntityResourceTest.java b/webapp/src/test/java/org/apache/atlas/web/resources/EntityResourceTest.java new file mode 100644 index 0000000..3fe8e11 --- /dev/null +++ b/webapp/src/test/java/org/apache/atlas/web/resources/EntityResourceTest.java @@ -0,0 +1,74 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.atlas.web.resources; + +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.List; + +import javax.ws.rs.core.Response; + +import org.apache.atlas.AtlasClient.EntityResult; +import org.apache.atlas.services.MetadataService; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * Unit test of {@link EntityResource} + */ +public class EntityResourceTest { + + private static final String DELETED_GUID = "deleted_guid"; + + @Mock + MetadataService mockService; + + @BeforeMethod + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testDeleteEntitiesDoesNotLookupDeletedEntity() throws Exception { + List<String> guids = Collections.singletonList(DELETED_GUID); + + // Create EntityResult with a deleted guid and no other guids. + EntityResult entityResult = new EntityResult(Collections.<String>emptyList(), + Collections.<String>emptyList(), guids); + when(mockService.deleteEntities(guids)).thenReturn(entityResult); + + // Create EntityResource with mock MetadataService. + EntityResource entityResource = new EntityResource(mockService); + + Response response = entityResource.deleteEntities(guids, null, null, null); + + // Verify that if the EntityResult returned by MetadataService includes only deleted guids, + // deleteEntities() does not perform any entity lookup. + verify(mockService, never()).getEntityDefinition(Matchers.anyString()); + + EntityResult resultFromEntityResource = EntityResult.fromString(response.getEntity().toString()); + Assert.assertTrue(resultFromEntityResource.getDeletedEntities().contains(DELETED_GUID)); + } +}
