atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From suma...@apache.org
Subject incubator-atlas git commit: ATLAS-858 Unable to delete terms via API which are 3 or more levels deep(jspeidel via sumasai)
Date Sat, 04 Jun 2016 00:37:38 GMT
Repository: incubator-atlas
Updated Branches:
  refs/heads/master 9e23fdc1b -> d661964c2


ATLAS-858 Unable to delete terms via API which are 3 or more levels deep(jspeidel 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/d661964c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/d661964c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/d661964c

Branch: refs/heads/master
Commit: d661964c2c049820958678a17218b33b3128fd6a
Parents: 9e23fdc
Author: Suma Shivaprasad <sumasai.shivaprasad@gmail.com>
Authored: Fri Jun 3 17:37:30 2016 -0700
Committer: Suma Shivaprasad <sumasai.shivaprasad@gmail.com>
Committed: Fri Jun 3 17:37:30 2016 -0700

----------------------------------------------------------------------
 release-log.txt                                 |   1 +
 webapp/pom.xml                                  |   6 +
 .../apache/atlas/web/resources/BaseService.java |  11 +-
 .../atlas/web/resources/EntityService.java      |   9 +-
 .../atlas/web/resources/TaxonomyService.java    |  82 ++-
 .../web/resources/TaxonomyServiceTest.java      | 556 +++++++++++++++++++
 6 files changed, 628 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/d661964c/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index 3db4c3c..eec7d48 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -22,6 +22,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-858 Unable to delete terms via API which are 3 or more levels deep (jspeidel via sumasai)
 ATLAS-848 Atlas UI: Search term box in left navigation is not auto refresh.(Kalyanikashikar
via sumasai)
 ATLAS-793 Business Catalog Delete (jspeidel via yhemanth)
 ATLAS-846 Atlas UI : Add Pagination to Tags and Terms tabs of asset detailes page (kevalbhatt18
via yhemanth)

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/d661964c/webapp/pom.xml
----------------------------------------------------------------------
diff --git a/webapp/pom.xml b/webapp/pom.xml
index 6b0a927..cce6dd6 100755
--- a/webapp/pom.xml
+++ b/webapp/pom.xml
@@ -297,6 +297,12 @@
             <artifactId>atlas-dashboardv2</artifactId>
             <type>war</type>
         </dependency>
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <version>3.4</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/d661964c/webapp/src/main/java/org/apache/atlas/web/resources/BaseService.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/BaseService.java b/webapp/src/main/java/org/apache/atlas/web/resources/BaseService.java
index 83bbd22..2a65538 100644
--- a/webapp/src/main/java/org/apache/atlas/web/resources/BaseService.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/BaseService.java
@@ -40,6 +40,7 @@ import java.util.Map;
 public abstract class BaseService {
     private static final Gson gson = new Gson();
     private final Logger LOG = LoggerFactory.getLogger(getClass());
+    private final static JsonSerializer serializer = new JsonSerializer();
 
     protected Result getResource(ResourceProvider provider, Request request)
             throws ResourceNotFoundException {
@@ -118,16 +119,20 @@ public abstract class BaseService {
         }
     }
 
-    private RuntimeException wrapRuntimeException(RuntimeException e) {
-        return e instanceof CatalogRuntimeException ? e : new CatalogRuntimeException(e);
+    protected JsonSerializer getSerializer() {
+        return serializer;
     }
 
     //todo: abstract via AtlasTypeSystem
     // ensure that the thread wasn't re-pooled with an existing transaction
-    private void initializeGraphTransaction() {
+    protected void initializeGraphTransaction() {
         TitanGraphProvider.getGraphInstance().rollback();
     }
 
+    private RuntimeException wrapRuntimeException(RuntimeException e) {
+        return e instanceof CatalogRuntimeException ? e : new CatalogRuntimeException(e);
+    }
+
     @XmlRootElement
     // the name of this class is used as the collection name in the returned json when returning
a collection
     public static class Results {

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/d661964c/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java b/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java
index 1ea8e14..1f0c944 100644
--- a/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java
@@ -38,7 +38,6 @@ public class EntityService extends BaseService {
 
     private final EntityResourceProvider entityResourceProvider;
     private final EntityTagResourceProvider entityTagResourceProvider;
-    private static JsonSerializer m_serializer = new JsonSerializer();
 
     @Inject
     public EntityService(MetadataService metadataService) {
@@ -55,7 +54,7 @@ public class EntityService extends BaseService {
         BaseRequest request = new CollectionRequest(Collections.<String, Object>emptyMap(),
queryString);
         Result result = getResources(entityResourceProvider, request);
 
-        return Response.status(Response.Status.OK).entity(m_serializer.serialize(result,
ui)).build();
+        return Response.status(Response.Status.OK).entity(getSerializer().serialize(result,
ui)).build();
     }
 
     @GET
@@ -68,7 +67,7 @@ public class EntityService extends BaseService {
         BaseRequest request = new InstanceRequest(Collections.<String, Object>singletonMap("id",
entityId));
         Result result = getResource(entityResourceProvider, request);
 
-        return Response.status(Response.Status.OK).entity(m_serializer.serialize(result,
ui)).build();
+        return Response.status(Response.Status.OK).entity(getSerializer().serialize(result,
ui)).build();
     }
 
     @GET
@@ -84,7 +83,7 @@ public class EntityService extends BaseService {
         properties.put("name", tagName);
         Result result = getResource(entityTagResourceProvider, new InstanceRequest(properties));
 
-        return Response.status(Response.Status.OK).entity(m_serializer.serialize(result,
ui)).build();
+        return Response.status(Response.Status.OK).entity(getSerializer().serialize(result,
ui)).build();
     }
 
     @GET
@@ -98,7 +97,7 @@ public class EntityService extends BaseService {
                 decode(getQueryString(ui)));
         Result result = getResources(entityTagResourceProvider, request);
 
-        return Response.status(Response.Status.OK).entity(m_serializer.serialize(result,
ui)).build();
+        return Response.status(Response.Status.OK).entity(getSerializer().serialize(result,
ui)).build();
     }
 
     @POST

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/d661964c/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java b/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java
index 04cabad..f995198 100644
--- a/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java
@@ -41,15 +41,14 @@ import java.util.Map;
 @Singleton
 public class TaxonomyService extends BaseService {
 
-    private final TaxonomyResourceProvider taxonomyResourceProvider;
-    private static TermResourceProvider termResourceProvider;
-    private static JsonSerializer serializer = new JsonSerializer();
+    private ResourceProvider taxonomyResourceProvider;
+    private ResourceProvider termResourceProvider;
 
     @Inject
-    public TaxonomyService(MetadataService metadataService) {
+    public void setMetadataService(MetadataService metadataService) {
         DefaultTypeSystem typeSystem = new DefaultTypeSystem(metadataService);
-        taxonomyResourceProvider = new TaxonomyResourceProvider(typeSystem);
-        termResourceProvider = new TermResourceProvider(typeSystem);
+        taxonomyResourceProvider = createTaxonomyResourceProvider(typeSystem);
+        termResourceProvider = createTermResourceProvider(typeSystem);
     }
 
     @GET
@@ -62,7 +61,7 @@ public class TaxonomyService extends BaseService {
         Map<String, Object> properties = new HashMap<>();
         properties.put("name", taxonomyName);
         Result result = getResource(taxonomyResourceProvider, new InstanceRequest(properties));
-        return Response.status(Response.Status.OK).entity(serializer.serialize(result, ui)).build();
+        return Response.status(Response.Status.OK).entity(getSerializer().serialize(result,
ui)).build();
     }
 
     @GET
@@ -71,7 +70,7 @@ public class TaxonomyService extends BaseService {
         String queryString = decode(getQueryString(ui));
         Request request = new CollectionRequest(Collections.<String, Object>emptyMap(),
queryString);
         Result result = getResources(taxonomyResourceProvider, request);
-        return Response.status(Response.Status.OK).entity(serializer.serialize(result, ui)).build();
+        return Response.status(Response.Status.OK).entity(getSerializer().serialize(result,
ui)).build();
     }
 
     @POST
@@ -120,7 +119,7 @@ public class TaxonomyService extends BaseService {
         properties.put("termPath", termPath);
         Result result = getResource(termResourceProvider, new InstanceRequest(properties));
 
-        return Response.status(Response.Status.OK).entity(serializer.serialize(result, ui)).build();
+        return Response.status(Response.Status.OK).entity(getSerializer().serialize(result,
ui)).build();
     }
 
     @GET
@@ -136,7 +135,7 @@ public class TaxonomyService extends BaseService {
                 Collections.<String, Object>singletonMap("termPath", termPath), queryString);
         Result result = getResources(termResourceProvider, request);
 
-        return Response.status(Response.Status.OK).entity(serializer.serialize(result, ui)).build();
+        return Response.status(Response.Status.OK).entity(getSerializer().serialize(result,
ui)).build();
     }
 
     @GET
@@ -149,11 +148,6 @@ public class TaxonomyService extends BaseService {
                             @PathParam("remainder") String remainder) throws CatalogException
{
 
         Result result;
-
-        List<PathSegment> pathSegments = ui.getPathSegments();
-
-        int lastIndex = pathSegments.size() - 1;
-        String lastSegment = pathSegments.get(lastIndex).getPath();
         String termName = String.format("%s%s", rootTerm,
                 remainder.replaceAll("/?terms/?([.]*)", "$1."));
         String queryString = decode(getQueryString(ui));
@@ -161,13 +155,17 @@ public class TaxonomyService extends BaseService {
 
         Map<String, Object> properties = new HashMap<>();
         properties.put("termPath", termPath);
+
+        List<PathSegment> pathSegments = ui.getPathSegments();
+        int lastIndex = pathSegments.size() - 1;
+        String lastSegment = pathSegments.get(lastIndex).getPath();
         if (lastSegment.equals("terms") || (lastSegment.isEmpty() && pathSegments.get(lastIndex
- 1).getPath().equals("terms"))) {
             result = getResources(termResourceProvider, new CollectionRequest(properties,
queryString));
         } else {
             result = getResource(termResourceProvider, new InstanceRequest(properties));
         }
 
-        return Response.status(Response.Status.OK).entity(serializer.serialize(result, ui)).build();
+        return Response.status(Response.Status.OK).entity(getSerializer().serialize(result,
ui)).build();
     }
 
     @POST
@@ -188,6 +186,27 @@ public class TaxonomyService extends BaseService {
                 new Results(ui.getRequestUri().toString(), 201)).build();
     }
 
+    @POST
+    @Path("{taxonomyName}/terms/{termName}/{remainder:.*}")
+    @Produces(Servlets.JSON_MEDIA_TYPE)
+    public Response createSubTerm(String body,
+                                  @Context HttpHeaders headers,
+                                  @Context UriInfo ui,
+                                  @PathParam("taxonomyName") String taxonomyName,
+                                  @PathParam("termName") String termName,
+                                  @PathParam("remainder") String remainder) throws CatalogException
{
+
+        Map<String, Object> properties = parsePayload(body);
+        String[] pathTokens = remainder.split("/");
+        validateName(pathTokens[pathTokens.length -1]);
+        properties.put("termPath", new TermPath(taxonomyName, String.format("%s%s", termName,
+                remainder.replaceAll("/?terms/?([.]*)", "$1."))));
+        createResource(termResourceProvider, new InstanceRequest(properties));
+
+        return Response.status(Response.Status.CREATED).entity(
+                new Results(ui.getRequestUri().toString(), 201)).build();
+    }
+
     @DELETE
     @Path("{taxonomyName}/terms/{termName}")
     @Produces(Servlets.JSON_MEDIA_TYPE)
@@ -204,25 +223,30 @@ public class TaxonomyService extends BaseService {
                 new Results(ui.getRequestUri().toString(), 200)).build();
     }
 
-    @POST
+    @DELETE
     @Path("{taxonomyName}/terms/{termName}/{remainder:.*}")
     @Produces(Servlets.JSON_MEDIA_TYPE)
-    public Response createSubTerms(String body,
-                                   @Context HttpHeaders headers,
-                                   @Context UriInfo ui,
-                                   @PathParam("taxonomyName") String taxonomyName,
-                                   @PathParam("termName") String termName,
-                                   @PathParam("remainder") String remainder) throws CatalogException
{
+    public Response deleteSubTerm(@Context HttpHeaders headers,
+                                  @Context UriInfo ui,
+                                  @PathParam("taxonomyName") String taxonomyName,
+                                  @PathParam("termName") String termName,
+                                  @PathParam("remainder") String remainder) throws CatalogException
{
 
-        Map<String, Object> properties = parsePayload(body);
-        String[] pathTokens = remainder.split("/");
-        validateName(pathTokens[pathTokens.length -1]);
+        Map<String, Object> properties = new HashMap<>();
         properties.put("termPath", new TermPath(taxonomyName, String.format("%s%s", termName,
                 remainder.replaceAll("/?terms/?([.]*)", "$1."))));
-        createResource(termResourceProvider, new InstanceRequest(properties));
+        deleteResource(termResourceProvider, new InstanceRequest(properties));
 
-        return Response.status(Response.Status.CREATED).entity(
-                new Results(ui.getRequestUri().toString(), 201)).build();
+        return Response.status(Response.Status.OK).entity(
+                new Results(ui.getRequestUri().toString(), 200)).build();
+    }
+
+    protected ResourceProvider createTaxonomyResourceProvider(AtlasTypeSystem typeSystem)
{
+        return new TaxonomyResourceProvider(typeSystem);
+    }
+
+    protected ResourceProvider createTermResourceProvider(AtlasTypeSystem typeSystem) {
+        return new TermResourceProvider(typeSystem);
     }
 
     private void validateName(String name) throws InvalidPayloadException {

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/d661964c/webapp/src/test/java/org/apache/atlas/web/resources/TaxonomyServiceTest.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/TaxonomyServiceTest.java
b/webapp/src/test/java/org/apache/atlas/web/resources/TaxonomyServiceTest.java
new file mode 100644
index 0000000..a967805
--- /dev/null
+++ b/webapp/src/test/java/org/apache/atlas/web/resources/TaxonomyServiceTest.java
@@ -0,0 +1,556 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 org.apache.atlas.catalog.*;
+import org.apache.atlas.services.MetadataService;
+import org.easymock.Capture;
+import org.testng.annotations.Test;
+
+import static org.easymock.EasyMock.*;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import java.net.URI;
+import java.util.*;
+
+/**
+ * Unit tests for TaxonomyService.
+ */
+public class TaxonomyServiceTest {
+    @Test
+    public void testGetTaxonomy() throws Exception {
+        String taxonomyName = "testTaxonomy";
+        MetadataService metadataService = createStrictMock(MetadataService.class);
+        ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
+        ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
+        UriInfo uriInfo = createNiceMock(UriInfo.class);
+        JsonSerializer serializer = createStrictMock(JsonSerializer.class);
+        Capture<Request> requestCapture = newCapture();
+
+        Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>();
+        Map<String, Object> propertyMap = new HashMap<>();
+        propertyMap.put("name", "testTaxonomy");
+        resultPropertyMaps.add(propertyMap);
+        Result result = new Result(resultPropertyMaps);
+
+        expect(taxonomyResourceProvider.getResourceById(capture(requestCapture))).andReturn(result);
+        expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Get Response");
+        replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider,
serializer);
+
+        TestTaxonomyService service = new TestTaxonomyService(
+                metadataService, taxonomyResourceProvider, termResourceProvider, serializer);
+        Response response = service.getTaxonomy(null, uriInfo, taxonomyName);
+
+        assertTrue(service.wasTransactionInitialized());
+
+        Request request = requestCapture.getValue();
+        Map<String, Object> requestProperties = request.getProperties();
+        assertEquals(requestProperties.size(), 1);
+        assertEquals(requestProperties.get("name"), taxonomyName);
+
+        assertEquals(response.getStatus(), 200);
+        assertEquals(response.getEntity(), "Taxonomy Get Response");
+
+        verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider,
serializer);
+    }
+
+    @Test
+    public void testGetTaxonomies() throws Exception {
+        MetadataService metadataService = createStrictMock(MetadataService.class);
+        ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
+        ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
+        UriInfo uriInfo = createNiceMock(UriInfo.class);
+        URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies?name:testTaxonomy");
+        JsonSerializer serializer = createStrictMock(JsonSerializer.class);
+        Capture<Request> requestCapture = newCapture();
+
+        Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>();
+        Map<String, Object> propertyMap = new HashMap<>();
+        propertyMap.put("name", "testTaxonomy");
+        resultPropertyMaps.add(propertyMap);
+        Result result = new Result(resultPropertyMaps);
+
+        // set mock expectations
+        expect(uriInfo.getRequestUri()).andReturn(uri);
+        expect(taxonomyResourceProvider.getResources(capture(requestCapture))).andReturn(result);
+        expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Get Response");
+        replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider,
serializer);
+
+        // instantiate service and invoke method being tested
+        TestTaxonomyService service = new TestTaxonomyService(
+                metadataService, taxonomyResourceProvider, termResourceProvider, serializer);
+        Response response = service.getTaxonomies(null, uriInfo);
+
+        assertTrue(service.wasTransactionInitialized());
+
+        Request request = requestCapture.getValue();
+        assertTrue(request.getProperties().isEmpty());
+        assertEquals(request.getQueryString(), "name:testTaxonomy");
+
+        assertEquals(response.getStatus(), 200);
+        assertEquals(response.getEntity(), "Taxonomy Get Response");
+
+        verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider,
serializer);
+    }
+
+    @Test
+    public void testCreateTaxonomy() throws Exception {
+        MetadataService metadataService = createStrictMock(MetadataService.class);
+        ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
+        ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
+        UriInfo uriInfo = createNiceMock(UriInfo.class);
+        URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy");
+        Capture<Request> requestCapture = newCapture();
+
+        String body = "{ \"description\" : \"test description\" } ";
+        // set mock expectations
+        expect(uriInfo.getRequestUri()).andReturn(uri);
+        taxonomyResourceProvider.createResource(capture(requestCapture));
+        replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
+
+        // instantiate service and invoke method being tested
+        TestTaxonomyService service = new TestTaxonomyService(
+                metadataService, taxonomyResourceProvider, termResourceProvider, null);
+        Response response = service.createTaxonomy(body, null, uriInfo, "testTaxonomy");
+
+        assertTrue(service.wasTransactionInitialized());
+
+        Request request = requestCapture.getValue();
+        assertEquals(request.getProperties().size(), 2);
+        assertEquals(request.getProperties().get("name"), "testTaxonomy");
+        assertEquals(request.getProperties().get("description"), "test description");
+        assertNull(request.getQueryString());
+
+        assertEquals(response.getStatus(), 201);
+        BaseService.Results createResults = (BaseService.Results) response.getEntity();
+        assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy");
+        assertEquals(createResults.status, 201);
+
+        verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
+    }
+
+    @Test
+    public void testDeleteTaxonomy() throws Exception {
+        MetadataService metadataService = createStrictMock(MetadataService.class);
+        ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
+        ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
+        UriInfo uriInfo = createNiceMock(UriInfo.class);
+        URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy");
+        Capture<Request> requestCapture = newCapture();
+
+        // set mock expectations
+        expect(uriInfo.getRequestUri()).andReturn(uri);
+        taxonomyResourceProvider.deleteResourceById(capture(requestCapture));
+        replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
+
+        // instantiate service and invoke method being tested
+        TestTaxonomyService service = new TestTaxonomyService(
+                metadataService, taxonomyResourceProvider, termResourceProvider, null);
+        Response response = service.deleteTaxonomy(null, uriInfo, "testTaxonomy");
+
+        assertTrue(service.wasTransactionInitialized());
+
+        Request request = requestCapture.getValue();
+        assertEquals(request.getProperties().size(), 1);
+        assertEquals(request.getProperties().get("name"), "testTaxonomy");
+        assertNull(request.getQueryString());
+
+        assertEquals(response.getStatus(), 200);
+        BaseService.Results createResults = (BaseService.Results) response.getEntity();
+        assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy");
+        assertEquals(createResults.status, 200);
+
+        verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
+    }
+
+    @Test
+    public void testGetTaxonomyTerm() throws Exception {
+        String taxonomyName = "testTaxonomy";
+        String termName = "testTaxonomy.termName";
+        MetadataService metadataService = createStrictMock(MetadataService.class);
+        ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
+        ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
+        UriInfo uriInfo = createNiceMock(UriInfo.class);
+        JsonSerializer serializer = createStrictMock(JsonSerializer.class);
+        Capture<Request> requestCapture = newCapture();
+
+        Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>();
+        Map<String, Object> propertyMap = new HashMap<>();
+        propertyMap.put("name", "testTaxonomy.termName");
+        resultPropertyMaps.add(propertyMap);
+        Result result = new Result(resultPropertyMaps);
+
+        expect(termResourceProvider.getResourceById(capture(requestCapture))).andReturn(result);
+        expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Term Get Response");
+        replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider,
serializer);
+
+        TestTaxonomyService service = new TestTaxonomyService(
+                metadataService, taxonomyResourceProvider, termResourceProvider, serializer);
+        Response response = service.getTaxonomyTerm(null, uriInfo, taxonomyName, termName);
+
+        assertTrue(service.wasTransactionInitialized());
+
+        Request request = requestCapture.getValue();
+        Map<String, Object> requestProperties = request.getProperties();
+        assertEquals(requestProperties.size(), 1);
+        TermPath termPath = (TermPath) request.getProperties().get("termPath");
+        assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTaxonomy.termName");
+
+        assertEquals(response.getStatus(), 200);
+        assertEquals(response.getEntity(), "Taxonomy Term Get Response");
+
+        verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider,
serializer);
+    }
+
+    @Test
+    public void testGetTaxonomyTerms() throws Exception {
+        MetadataService metadataService = createStrictMock(MetadataService.class);
+        ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
+        ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
+        UriInfo uriInfo = createNiceMock(UriInfo.class);
+        URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms?name:testTaxonomy.testTerm");
+        JsonSerializer serializer = createStrictMock(JsonSerializer.class);
+        Capture<Request> requestCapture = newCapture();
+
+        Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>();
+        Map<String, Object> propertyMap = new HashMap<>();
+        propertyMap.put("name", "testTaxonomy.testTerm");
+        resultPropertyMaps.add(propertyMap);
+        Result result = new Result(resultPropertyMaps);
+
+        // set mock expectations
+        expect(uriInfo.getRequestUri()).andReturn(uri);
+        expect(termResourceProvider.getResources(capture(requestCapture))).andReturn(result);
+        expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Term Get Response");
+        replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider,
serializer);
+
+        // instantiate service and invoke method being tested
+        TestTaxonomyService service = new TestTaxonomyService(
+                metadataService, taxonomyResourceProvider, termResourceProvider, serializer);
+        Response response = service.getTaxonomyTerms(null, uriInfo, "testTaxonomy");
+
+        assertTrue(service.wasTransactionInitialized());
+
+        Request request = requestCapture.getValue();
+        assertEquals(request.getProperties().size(), 1);
+        TermPath termPath = (TermPath) request.getProperties().get("termPath");
+        assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy");
+        assertEquals(request.getQueryString(), "name:testTaxonomy.testTerm");
+
+        assertEquals(response.getStatus(), 200);
+        assertEquals(response.getEntity(), "Taxonomy Term Get Response");
+
+        verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider,
serializer);
+    }
+
+    @Test
+    public void testGetSubTerms_instance() throws Exception {
+        MetadataService metadataService = createStrictMock(MetadataService.class);
+        ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
+        ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
+        UriInfo uriInfo = createNiceMock(UriInfo.class);
+        URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm/terms/testTerm2");
+        JsonSerializer serializer = createStrictMock(JsonSerializer.class);
+        PathSegment segment1 = createNiceMock(PathSegment.class);
+        PathSegment segment2 = createNiceMock(PathSegment.class);
+        PathSegment segment3 = createNiceMock(PathSegment.class);
+
+        Capture<Request> requestCapture = newCapture();
+
+        Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>();
+        Map<String, Object> propertyMap = new HashMap<>();
+        propertyMap.put("name", "testTaxonomy.testTerm.testTerm2");
+        resultPropertyMaps.add(propertyMap);
+        Result result = new Result(resultPropertyMaps);
+
+        // set mock expectations
+        expect(uriInfo.getRequestUri()).andReturn(uri);
+        expect(uriInfo.getPathSegments()).andReturn(Arrays.asList(segment1, segment2, segment3));
+        expect(segment3.getPath()).andReturn("testTerm2");
+        expect(termResourceProvider.getResourceById(capture(requestCapture))).andReturn(result);
+        expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Term Get Response");
+        replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider,
serializer,
+                segment1, segment2, segment3);
+
+        // instantiate service and invoke method being tested
+        TestTaxonomyService service = new TestTaxonomyService(
+                metadataService, taxonomyResourceProvider, termResourceProvider, serializer);
+        Response response = service.getSubTerms(null, uriInfo, "testTaxonomy", "testTerm",
"/terms/testTerm2");
+
+        assertTrue(service.wasTransactionInitialized());
+
+        Request request = requestCapture.getValue();
+        assertEquals(request.getProperties().size(), 1);
+        TermPath termPath = (TermPath) request.getProperties().get("termPath");
+        assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm.testTerm2");
+        assertNull(request.getQueryString());
+
+        assertEquals(response.getStatus(), 200);
+        assertEquals(response.getEntity(), "Taxonomy Term Get Response");
+
+        verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider,
serializer,
+                segment1, segment2, segment3);
+    }
+
+    @Test
+    public void testGetSubTerms_collection() throws Exception {
+        MetadataService metadataService = createStrictMock(MetadataService.class);
+        ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
+        ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
+        UriInfo uriInfo = createNiceMock(UriInfo.class);
+        URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm/terms/testTerm2/terms?name:testTaxonomy.testTerm.testTerm2.testTerm3");
+        JsonSerializer serializer = createStrictMock(JsonSerializer.class);
+        // would actually be more segments but at this time only the last segment is used
+        PathSegment segment1 = createNiceMock(PathSegment.class);
+        PathSegment segment2 = createNiceMock(PathSegment.class);
+        PathSegment segment3 = createNiceMock(PathSegment.class);
+
+        Capture<Request> requestCapture = newCapture();
+
+        Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>();
+        Map<String, Object> propertyMap = new HashMap<>();
+        propertyMap.put("name", "testTaxonomy.testTerm.testTerm2.testTerm3");
+        resultPropertyMaps.add(propertyMap);
+        Result result = new Result(resultPropertyMaps);
+
+        // set mock expectations
+        expect(uriInfo.getRequestUri()).andReturn(uri);
+        expect(uriInfo.getPathSegments()).andReturn(Arrays.asList(segment1, segment2, segment3));
+        expect(segment3.getPath()).andReturn("terms");
+
+        expect(termResourceProvider.getResources(capture(requestCapture))).andReturn(result);
+        expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Term Get Response");
+        replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider,
serializer,
+                segment1, segment2, segment3);
+
+        // instantiate service and invoke method being tested
+        TestTaxonomyService service = new TestTaxonomyService(
+                metadataService, taxonomyResourceProvider, termResourceProvider, serializer);
+        Response response = service.getSubTerms(null, uriInfo, "testTaxonomy", "testTerm",
"/terms/testTerm2/terms");
+
+        assertTrue(service.wasTransactionInitialized());
+
+        Request request = requestCapture.getValue();
+        assertEquals(request.getProperties().size(), 1);
+        TermPath termPath = (TermPath) request.getProperties().get("termPath");
+        assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm.testTerm2.");
+        assertEquals(request.getQueryString(), "name:testTaxonomy.testTerm.testTerm2.testTerm3");
+
+        assertEquals(response.getStatus(), 200);
+        assertEquals(response.getEntity(), "Taxonomy Term Get Response");
+
+        verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider,
serializer,
+                segment1, segment2, segment3);
+    }
+
+    @Test
+    public void testCreateTerm() throws Exception {
+        String taxonomyName = "testTaxonomy";
+        String termName = "testTerm";
+        MetadataService metadataService = createStrictMock(MetadataService.class);
+        ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
+        ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
+        UriInfo uriInfo = createNiceMock(UriInfo.class);
+        URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm");
+        Capture<Request> requestCapture = newCapture();
+
+        String body = "{ \"description\" : \"test description\" } ";
+        // set mock expectations
+        expect(uriInfo.getRequestUri()).andReturn(uri);
+        termResourceProvider.createResource(capture(requestCapture));
+        replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
+
+        // instantiate service and invoke method being tested
+        TestTaxonomyService service = new TestTaxonomyService(
+                metadataService, taxonomyResourceProvider, termResourceProvider, null);
+        Response response = service.createTerm(body, null, uriInfo, taxonomyName, termName);
+
+        assertTrue(service.wasTransactionInitialized());
+
+        Request request = requestCapture.getValue();
+        assertEquals(request.getProperties().size(), 2);
+        assertEquals(request.getProperties().get("description"), "test description");
+        TermPath termPath = (TermPath) request.getProperties().get("termPath");
+        assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm");
+        assertNull(request.getQueryString());
+
+        assertEquals(response.getStatus(), 201);
+        BaseService.Results createResults = (BaseService.Results) response.getEntity();
+        assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm");
+        assertEquals(createResults.status, 201);
+
+        verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
+    }
+
+    @Test
+    public void testCreateSubTerm() throws Exception {
+        String taxonomyName = "testTaxonomy";
+        String termName = "testTerm";
+        MetadataService metadataService = createStrictMock(MetadataService.class);
+        ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
+        ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
+        UriInfo uriInfo = createNiceMock(UriInfo.class);
+        URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm/terms/testTerm2");
+        Capture<Request> requestCapture = newCapture();
+
+        String body = "{ \"description\" : \"test description\" } ";
+        // set mock expectations
+        expect(uriInfo.getRequestUri()).andReturn(uri);
+        termResourceProvider.createResource(capture(requestCapture));
+        replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
+
+        // instantiate service and invoke method being tested
+        TestTaxonomyService service = new TestTaxonomyService(
+                metadataService, taxonomyResourceProvider, termResourceProvider, null);
+        Response response = service.createSubTerm(body, null, uriInfo, taxonomyName, termName,
"/terms/testTerm2");
+
+        assertTrue(service.wasTransactionInitialized());
+
+        Request request = requestCapture.getValue();
+        assertEquals(request.getProperties().size(), 2);
+        assertEquals(request.getProperties().get("description"), "test description");
+        TermPath termPath = (TermPath) request.getProperties().get("termPath");
+        assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm.testTerm2");
+        assertNull(request.getQueryString());
+
+        assertEquals(response.getStatus(), 201);
+        BaseService.Results createResults = (BaseService.Results) response.getEntity();
+        assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm/terms/testTerm2");
+        assertEquals(createResults.status, 201);
+
+        verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
+    }
+
+    @Test
+    public void testDeleteTerm() throws Exception {
+        MetadataService metadataService = createStrictMock(MetadataService.class);
+        ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
+        ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
+        UriInfo uriInfo = createNiceMock(UriInfo.class);
+        URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm");
+        Capture<Request> requestCapture = newCapture();
+
+        // set mock expectations
+        expect(uriInfo.getRequestUri()).andReturn(uri);
+        termResourceProvider.deleteResourceById(capture(requestCapture));
+        replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
+
+        // instantiate service and invoke method being tested
+        TestTaxonomyService service = new TestTaxonomyService(
+                metadataService, taxonomyResourceProvider, termResourceProvider, null);
+        Response response = service.deleteTerm(null, uriInfo, "testTaxonomy", "testTerm");
+
+        assertTrue(service.wasTransactionInitialized());
+
+        Request request = requestCapture.getValue();
+        assertEquals(request.getProperties().size(), 1);
+        TermPath termPath = (TermPath) request.getProperties().get("termPath");
+        assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm");
+        assertNull(request.getQueryString());
+
+        assertEquals(response.getStatus(), 200);
+        BaseService.Results createResults = (BaseService.Results) response.getEntity();
+        assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm");
+        assertEquals(createResults.status, 200);
+
+        verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
+    }
+
+    @Test
+    public void testDeleteSubTerm() throws Exception {
+        MetadataService metadataService = createStrictMock(MetadataService.class);
+        ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
+        ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
+        UriInfo uriInfo = createNiceMock(UriInfo.class);
+        URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm/terms/testTerm2");
+        Capture<Request> requestCapture = newCapture();
+
+        // set mock expectations
+        expect(uriInfo.getRequestUri()).andReturn(uri);
+        termResourceProvider.deleteResourceById(capture(requestCapture));
+        replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
+
+        // instantiate service and invoke method being tested
+        TestTaxonomyService service = new TestTaxonomyService(
+                metadataService, taxonomyResourceProvider, termResourceProvider, null);
+        Response response = service.deleteSubTerm(null, uriInfo, "testTaxonomy", "testTerm",
"terms/testTerm2");
+
+        assertTrue(service.wasTransactionInitialized());
+
+        Request request = requestCapture.getValue();
+        assertEquals(request.getProperties().size(), 1);
+        TermPath termPath = (TermPath) request.getProperties().get("termPath");
+        assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm.testTerm2");
+        assertNull(request.getQueryString());
+
+        assertEquals(response.getStatus(), 200);
+        BaseService.Results createResults = (BaseService.Results) response.getEntity();
+        assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm/terms/testTerm2");
+        assertEquals(createResults.status, 200);
+
+        verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
+    }
+
+    private static class TestTaxonomyService extends TaxonomyService {
+        private final ResourceProvider testTaxonomyResourceProvider;
+        private final ResourceProvider testTermResourceProvider;
+        private final JsonSerializer testSerializer;
+        private boolean transactionInitialized = false;
+
+        public TestTaxonomyService(MetadataService metadataService,
+                                   ResourceProvider taxonomyProvider,
+                                   ResourceProvider termResourceProvider,
+                                   JsonSerializer serializer) {
+
+            testTaxonomyResourceProvider = taxonomyProvider;
+            testTermResourceProvider = termResourceProvider;
+            testSerializer = serializer;
+            setMetadataService(metadataService);
+        }
+
+        @Override
+        protected ResourceProvider createTaxonomyResourceProvider(AtlasTypeSystem typeSystem)
{
+            return testTaxonomyResourceProvider;
+        }
+
+        @Override
+        protected ResourceProvider createTermResourceProvider(AtlasTypeSystem typeSystem)
{
+            return testTermResourceProvider;
+        }
+
+        @Override
+        protected JsonSerializer getSerializer() {
+            return testSerializer;
+        }
+
+        @Override
+        protected void initializeGraphTransaction() {
+            transactionInitialized = true;
+        }
+
+        public boolean wasTransactionInitialized() {
+            return transactionInitialized;
+        }
+    }
+}



Mime
View raw message