You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by nb...@apache.org on 2021/08/17 11:44:43 UTC
[atlas] 01/02: ATLAS-3917: While deleting parent tag,
shows incorrect message
This is an automated email from the ASF dual-hosted git repository.
nbonte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git
commit d160138d5e7d23cd8c4345dba55c140dc9bc84b2
Author: Shraddha Chauhan <sh...@freestoneinfotech.com>
AuthorDate: Tue Aug 17 16:05:09 2021 +0530
ATLAS-3917: While deleting parent tag, shows incorrect message
Signed-off-by: Nikhil Bonte <nb...@apache.org>
---
.../store/graph/v2/AtlasTypeDefGraphStoreV2.java | 4 ++--
.../v2/AtlasClassificationDefStoreV2Test.java | 27 ++++++++++++++++++++++
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasTypeDefGraphStoreV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasTypeDefGraphStoreV2.java
index b9d41bb..5da6fde 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasTypeDefGraphStoreV2.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasTypeDefGraphStoreV2.java
@@ -270,9 +270,9 @@ public class AtlasTypeDefGraphStoreV2 extends AtlasTypeDefGraphStore {
void deleteTypeVertex(AtlasVertex vertex) throws AtlasBaseException {
Iterator<AtlasEdge> inEdges = vertex.getEdges(AtlasEdgeDirection.IN).iterator();
-
if (inEdges.hasNext()) {
- throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES);
+ String name = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class);
+ throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, name);
}
Iterable<AtlasEdge> edges = vertex.getEdges(AtlasEdgeDirection.OUT);
diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/v2/AtlasClassificationDefStoreV2Test.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/v2/AtlasClassificationDefStoreV2Test.java
index 3242a33..b8f52f9 100644
--- a/repository/src/test/java/org/apache/atlas/repository/store/graph/v2/AtlasClassificationDefStoreV2Test.java
+++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/v2/AtlasClassificationDefStoreV2Test.java
@@ -17,16 +17,26 @@
*/
package org.apache.atlas.repository.store.graph.v2;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import com.google.inject.Inject;
+import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.TestModules;
+import org.apache.atlas.exception.AtlasBaseException;
+import org.apache.atlas.repository.Constants;
+import org.apache.atlas.repository.graphdb.AtlasEdge;
+import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
+import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
+import java.util.ArrayList;
+
/**
* Tests for AtlasClassificationDefStoreV2
*/
@@ -65,4 +75,21 @@ public class AtlasClassificationDefStoreV2Test {
public void testIsValidName(String data, boolean expected) {
assertEquals(classificationDefStore.isValidName(data), expected);
}
+
+ @Test
+ public void testDeleteReferencedTraitFail() {
+ AtlasVertex typeVertex = mock(AtlasVertex.class);
+ when(typeVertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class)).thenReturn("Tag11");
+ when(typeVertex.getEdges(AtlasEdgeDirection.IN)).thenReturn(() -> {
+ ArrayList<AtlasEdge> list = new ArrayList<>();
+ list.add(mock(AtlasEdge.class));
+ return list.iterator();
+ });
+ try {
+ classificationDefStore.deleteByName("Tag11", typeVertex );
+ } catch (AtlasBaseException abe) {
+ assertEquals(abe.getMessage(), AtlasErrorCode.TYPE_HAS_REFERENCES.getFormattedErrorMessage("Tag11"));
+ assertEquals(abe.getAtlasErrorCode() , AtlasErrorCode.TYPE_HAS_REFERENCES);
+ }
+ }
}
\ No newline at end of file