Commit 2c881a46 by apoorvnaik Committed by Suma Shivaprasad

ATLAS-1307: Integration test calls routing via the Client.

parent de6122fa
...@@ -224,8 +224,8 @@ public abstract class AtlasBaseClient { ...@@ -224,8 +224,8 @@ public abstract class AtlasBaseClient {
String activeServerAddress = null; String activeServerAddress = null;
for (int i = 0; i < getNumberOfRetries(); i++) { for (int i = 0; i < getNumberOfRetries(); i++) {
try { try {
WebResource service = client.resource(UriBuilder.fromUri(serverInstance).build()); service = client.resource(UriBuilder.fromUri(serverInstance).build());
String adminStatus = getAdminStatus(service); String adminStatus = getAdminStatus();
if (StringUtils.equals(adminStatus, "ACTIVE")) { if (StringUtils.equals(adminStatus, "ACTIVE")) {
activeServerAddress = serverInstance; activeServerAddress = serverInstance;
break; break;
...@@ -315,11 +315,7 @@ public abstract class AtlasBaseClient { ...@@ -315,11 +315,7 @@ public abstract class AtlasBaseClient {
private WebResource getResource(WebResource service, String path, String... pathParams) { private WebResource getResource(WebResource service, String path, String... pathParams) {
WebResource resource = service.path(path); WebResource resource = service.path(path);
if (pathParams != null) { resource = appendPathParams(resource, pathParams);
for (String pathParam : pathParams) {
resource = resource.path(pathParam);
}
}
return resource; return resource;
} }
...@@ -347,10 +343,6 @@ public abstract class AtlasBaseClient { ...@@ -347,10 +343,6 @@ public abstract class AtlasBaseClient {
* @throws AtlasServiceException if there is a HTTP error. * @throws AtlasServiceException if there is a HTTP error.
*/ */
public String getAdminStatus() throws AtlasServiceException { public String getAdminStatus() throws AtlasServiceException {
return getAdminStatus(service);
}
private String getAdminStatus(WebResource service) throws AtlasServiceException {
String result = AtlasBaseClient.UNKNOWN_STATUS; String result = AtlasBaseClient.UNKNOWN_STATUS;
WebResource resource = getResource(service, STATUS.getPath()); WebResource resource = getResource(service, STATUS.getPath());
JSONObject response = callAPIWithResource(STATUS, resource, null, JSONObject.class); JSONObject response = callAPIWithResource(STATUS, resource, null, JSONObject.class);
...@@ -380,14 +372,6 @@ public abstract class AtlasBaseClient { ...@@ -380,14 +372,6 @@ public abstract class AtlasBaseClient {
throw che; throw che;
} }
public boolean isRetryEnabled() {
return retryEnabled;
}
public void setRetryEnabled(boolean retryEnabled) {
this.retryEnabled = retryEnabled;
}
@VisibleForTesting @VisibleForTesting
JSONObject callAPIWithRetries(APIInfo api, Object requestObject, ResourceCreator resourceCreator) JSONObject callAPIWithRetries(APIInfo api, Object requestObject, ResourceCreator resourceCreator)
throws AtlasServiceException { throws AtlasServiceException {
...@@ -395,7 +379,7 @@ public abstract class AtlasBaseClient { ...@@ -395,7 +379,7 @@ public abstract class AtlasBaseClient {
WebResource resource = resourceCreator.createResource(); WebResource resource = resourceCreator.createResource();
try { try {
LOG.debug("Using resource {} for {} times", resource.getURI(), i); LOG.debug("Using resource {} for {} times", resource.getURI(), i);
JSONObject result = callAPIWithResource(api, resource, requestObject); JSONObject result = callAPIWithResource(api, resource, requestObject, JSONObject.class);
return result; return result;
} catch (ClientHandlerException che) { } catch (ClientHandlerException che) {
if (i == (getNumberOfRetries() - 1)) { if (i == (getNumberOfRetries() - 1)) {
...@@ -409,24 +393,15 @@ public abstract class AtlasBaseClient { ...@@ -409,24 +393,15 @@ public abstract class AtlasBaseClient {
throw new AtlasServiceException(api, new RuntimeException("Could not get response after retries.")); throw new AtlasServiceException(api, new RuntimeException("Could not get response after retries."));
} }
protected JSONObject callAPIWithResource(APIInfo api, WebResource resource, Object requestObject) public <T> T callAPI(APIInfo api, Object requestObject, Class<T> responseType, String... params)
throws AtlasServiceException {
return callAPIWithResource(api, resource, requestObject, JSONObject.class);
}
protected JSONObject callAPI(final APIInfo api, Object requestObject, final String... pathParams)
throws AtlasServiceException { throws AtlasServiceException {
return callAPIWithRetries(api, requestObject, new ResourceCreator() { return callAPIWithResource(api, getResource(api, params), requestObject, responseType);
@Override
public WebResource createResource() {
return getResource(api, pathParams);
}
});
} }
protected <T> T callAPI(APIInfo api, Object requestObject, Class<T> responseType, String... params) public <T> T callAPI(APIInfo api, Class<T> responseType, Map<String, String> queryParams, String... params)
throws AtlasServiceException { throws AtlasServiceException {
return callAPIWithResource(api, getResource(api, params), requestObject, responseType); WebResource resource = getResource(api, queryParams, params);
return callAPIWithResource(api, resource, null, responseType);
} }
protected WebResource getResource(APIInfo api, String... pathParams) { protected WebResource getResource(APIInfo api, String... pathParams) {
...@@ -436,6 +411,23 @@ public abstract class AtlasBaseClient { ...@@ -436,6 +411,23 @@ public abstract class AtlasBaseClient {
// Modify URL to include the path params // Modify URL to include the path params
private WebResource getResource(WebResource service, APIInfo api, String... pathParams) { private WebResource getResource(WebResource service, APIInfo api, String... pathParams) {
WebResource resource = service.path(api.getPath()); WebResource resource = service.path(api.getPath());
resource = appendPathParams(resource, pathParams);
return resource;
}
public <T> T callAPI(APIInfo api, Class<T> responseType, Map<String, String> queryParams)
throws AtlasServiceException {
return callAPIWithResource(api, getResource(api, queryParams), null, responseType);
}
protected WebResource getResource(APIInfo api, Map<String, String> queryParams, String ... pathParams) {
WebResource resource = service.path(api.getPath());
resource = appendPathParams(resource, pathParams);
resource = appendQueryParams(queryParams, resource);
return resource;
}
private WebResource appendPathParams(WebResource resource, String[] pathParams) {
if (pathParams != null) { if (pathParams != null) {
for (String pathParam : pathParams) { for (String pathParam : pathParams) {
resource = resource.path(pathParam); resource = resource.path(pathParam);
...@@ -444,11 +436,6 @@ public abstract class AtlasBaseClient { ...@@ -444,11 +436,6 @@ public abstract class AtlasBaseClient {
return resource; return resource;
} }
protected <T> T callAPI(APIInfo api, Object requestObject, Class<T> responseType, Map<String, String> queryParams)
throws AtlasServiceException {
return callAPIWithResource(api, getResource(api, queryParams), requestObject, responseType);
}
protected WebResource getResource(APIInfo api, Map<String, String> queryParams) { protected WebResource getResource(APIInfo api, Map<String, String> queryParams) {
return getResource(service, api, queryParams); return getResource(service, api, queryParams);
} }
...@@ -456,6 +443,11 @@ public abstract class AtlasBaseClient { ...@@ -456,6 +443,11 @@ public abstract class AtlasBaseClient {
// Modify URL to include the query params // Modify URL to include the query params
private WebResource getResource(WebResource service, APIInfo api, Map<String, String> queryParams) { private WebResource getResource(WebResource service, APIInfo api, Map<String, String> queryParams) {
WebResource resource = service.path(api.getPath()); WebResource resource = service.path(api.getPath());
resource = appendQueryParams(queryParams, resource);
return resource;
}
private WebResource appendQueryParams(Map<String, String> queryParams, WebResource resource) {
if (null != queryParams && !queryParams.isEmpty()) { if (null != queryParams && !queryParams.isEmpty()) {
for (Map.Entry<String, String> entry : queryParams.entrySet()) { for (Map.Entry<String, String> entry : queryParams.entrySet()) {
resource = resource.queryParam(entry.getKey(), entry.getValue()); resource = resource.queryParam(entry.getKey(), entry.getValue());
...@@ -484,7 +476,7 @@ public abstract class AtlasBaseClient { ...@@ -484,7 +476,7 @@ public abstract class AtlasBaseClient {
private final String path; private final String path;
private final Response.Status status; private final Response.Status status;
APIInfo(String path, String method, Response.Status status) { public APIInfo(String path, String method, Response.Status status) {
this.path = path; this.path = path;
this.method = method; this.method = method;
this.status = status; this.status = status;
......
...@@ -20,9 +20,7 @@ package org.apache.atlas; ...@@ -20,9 +20,7 @@ package org.apache.atlas;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.Struct; import org.apache.atlas.typesystem.Struct;
...@@ -43,6 +41,8 @@ import org.codehaus.jettison.json.JSONObject; ...@@ -43,6 +41,8 @@ import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
...@@ -50,9 +50,6 @@ import java.util.HashMap; ...@@ -50,9 +50,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response;
/** /**
* Client for metadata. * Client for metadata.
*/ */
...@@ -208,6 +205,8 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -208,6 +205,8 @@ public class AtlasClient extends AtlasBaseClient {
SEARCH_DSL(BASE_URI + URI_SEARCH + "/dsl", HttpMethod.GET, Response.Status.OK), SEARCH_DSL(BASE_URI + URI_SEARCH + "/dsl", HttpMethod.GET, Response.Status.OK),
SEARCH_FULL_TEXT(BASE_URI + URI_SEARCH + "/fulltext", HttpMethod.GET, Response.Status.OK), SEARCH_FULL_TEXT(BASE_URI + URI_SEARCH + "/fulltext", HttpMethod.GET, Response.Status.OK),
GREMLIN_SEARCH(BASE_URI + URI_SEARCH + "/gremlin", HttpMethod.GET, Response.Status.OK),
//Lineage operations based on dataset name //Lineage operations based on dataset name
NAME_LINEAGE_INPUTS_GRAPH(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK), NAME_LINEAGE_INPUTS_GRAPH(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK),
NAME_LINEAGE_OUTPUTS_GRAPH(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK), NAME_LINEAGE_OUTPUTS_GRAPH(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK),
...@@ -566,6 +565,16 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -566,6 +565,16 @@ public class AtlasClient extends AtlasBaseClient {
} }
/** /**
* Delete a trait from the given entity
* @param guid guid of the entity
* @param traitName trait to be deleted
* @throws AtlasServiceException
*/
public void deleteTrait(String guid, String traitName) throws AtlasServiceException {
callAPI(API.DELETE_TRAITS, null, guid, TRAITS, traitName);
}
/**
* Supports Partial updates * Supports Partial updates
* Updates properties set in the definition for the entity corresponding to guid * Updates properties set in the definition for the entity corresponding to guid
* @param entityType Type of the entity being updated * @param entityType Type of the entity being updated
...@@ -644,7 +653,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -644,7 +653,7 @@ public class AtlasClient extends AtlasBaseClient {
resource = resource.queryParam(TYPE, entityType); resource = resource.queryParam(TYPE, entityType);
resource = resource.queryParam(ATTRIBUTE_NAME, uniqueAttributeName); resource = resource.queryParam(ATTRIBUTE_NAME, uniqueAttributeName);
resource = resource.queryParam(ATTRIBUTE_VALUE, uniqueAttributeValue); resource = resource.queryParam(ATTRIBUTE_VALUE, uniqueAttributeValue);
JSONObject jsonResponse = callAPIWithResource(API.DELETE_ENTITIES, resource, null); JSONObject jsonResponse = callAPIWithResource(API.DELETE_ENTITIES, resource);
EntityResult results = extractEntityResult(jsonResponse); EntityResult results = extractEntityResult(jsonResponse);
LOG.debug("Delete entities returned results: {}", results); LOG.debug("Delete entities returned results: {}", results);
return results; return results;
...@@ -814,7 +823,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -814,7 +823,7 @@ public class AtlasClient extends AtlasBaseClient {
} }
resource = resource.queryParam(NUM_RESULTS, String.valueOf(numResults)); resource = resource.queryParam(NUM_RESULTS, String.valueOf(numResults));
JSONObject jsonResponse = callAPIWithResource(API.LIST_ENTITY_AUDIT, resource, null); JSONObject jsonResponse = callAPIWithResource(API.LIST_ENTITY_AUDIT, resource);
return extractResults(jsonResponse, AtlasClient.EVENTS, new ExtractOperation<EntityAuditEvent, JSONObject>() { return extractResults(jsonResponse, AtlasClient.EVENTS, new ExtractOperation<EntityAuditEvent, JSONObject>() {
@Override @Override
EntityAuditEvent extractElement(JSONObject element) throws JSONException { EntityAuditEvent extractElement(JSONObject element) throws JSONException {
...@@ -945,19 +954,32 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -945,19 +954,32 @@ public class AtlasClient extends AtlasBaseClient {
} }
// Wrapper methods for compatibility // Wrapper methods for compatibility
@VisibleForTesting
JSONObject callAPIWithResource(API api, WebResource resource, Object requestObject) throws AtlasServiceException { public JSONObject callAPIWithResource(API api, WebResource resource) throws AtlasServiceException {
return callAPIWithResource(toAPIInfo(api), resource, requestObject); return callAPIWithResource(toAPIInfo(api), resource, null, JSONObject.class);
} }
WebResource getResource(API api, String ... params) { @VisibleForTesting
public WebResource getResource(API api, String ... params) {
return getResource(toAPIInfo(api), params); return getResource(toAPIInfo(api), params);
} }
JSONObject callAPI(API api, Object requestObject, String ... params) throws AtlasServiceException { @VisibleForTesting
return callAPI(toAPIInfo(api), requestObject, params); public JSONObject callAPI(API api, Object requestObject) throws AtlasServiceException {
return callAPI(toAPIInfo(api), requestObject, JSONObject.class, (String[]) null);
}
@VisibleForTesting
public JSONObject callAPI(API api, Object requestObject, String ... params) throws AtlasServiceException {
return callAPI(toAPIInfo(api), requestObject, JSONObject.class, params);
}
@VisibleForTesting
public JSONObject callAPI(API api, Map<String, String> queryParams) throws AtlasServiceException {
return callAPI(toAPIInfo(api), JSONObject.class, queryParams);
} }
@VisibleForTesting
JSONObject callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException { JSONObject callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException {
return super.callAPIWithRetries(toAPIInfo(api), requestObject, resourceCreator); return super.callAPIWithRetries(toAPIInfo(api), requestObject, resourceCreator);
} }
......
...@@ -131,6 +131,6 @@ public class AtlasEntitiesClientV2 extends AtlasBaseClient { ...@@ -131,6 +131,6 @@ public class AtlasEntitiesClientV2 extends AtlasBaseClient {
} }
public AtlasEntity.AtlasEntities searchEntities(SearchFilter searchFilter) throws AtlasServiceException { public AtlasEntity.AtlasEntities searchEntities(SearchFilter searchFilter) throws AtlasServiceException {
return callAPI(GET_ENTITIES, null, AtlasEntity.AtlasEntities.class, searchFilter.getParams()); return callAPI(GET_ENTITIES, AtlasEntity.AtlasEntities.class, searchFilter.getParams());
} }
} }
...@@ -73,7 +73,7 @@ public class AtlasTypedefClientV2 extends AtlasBaseClient { ...@@ -73,7 +73,7 @@ public class AtlasTypedefClientV2 extends AtlasBaseClient {
* @return A composite wrapper object with lists of all type definitions * @return A composite wrapper object with lists of all type definitions
*/ */
public AtlasTypesDef getAllTypeDefs(SearchFilter searchFilter) throws AtlasServiceException { public AtlasTypesDef getAllTypeDefs(SearchFilter searchFilter) throws AtlasServiceException {
return callAPI(GET_ALL_TYPE_DEFS, null, AtlasTypesDef.class, searchFilter.getParams()); return callAPI(GET_ALL_TYPE_DEFS, AtlasTypesDef.class, searchFilter.getParams());
} }
public AtlasEnumDef getEnumByName(final String name) throws AtlasServiceException { public AtlasEnumDef getEnumByName(final String name) throws AtlasServiceException {
......
...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai) ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES: ALL CHANGES:
ATLAS-1307: Integration test calls routing via the Client. ((apoorvnaik via sumasai)
ATLAS-1355: Fix for bad error translation from V2 API (apoorvnaik via sumasai) ATLAS-1355: Fix for bad error translation from V2 API (apoorvnaik via sumasai)
ATLAS-1351 HiveHook fails with NPE for hive process registration (vimalsharma via sumasai) ATLAS-1351 HiveHook fails with NPE for hive process registration (vimalsharma via sumasai)
ATLAS-1342 Titan Solrclient - Add timeouts for zookeeper connect and session (sumasai) ATLAS-1342 Titan Solrclient - Add timeouts for zookeeper connect and session (sumasai)
......
...@@ -20,8 +20,6 @@ package org.apache.atlas.notification; ...@@ -20,8 +20,6 @@ package org.apache.atlas.notification;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.notification.entity.EntityNotification; import org.apache.atlas.notification.entity.EntityNotification;
import org.apache.atlas.typesystem.IReferenceableInstance; import org.apache.atlas.typesystem.IReferenceableInstance;
...@@ -35,14 +33,10 @@ import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition; ...@@ -35,14 +33,10 @@ import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
import org.apache.atlas.typesystem.types.TraitType; import org.apache.atlas.typesystem.types.TraitType;
import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.apache.atlas.web.resources.BaseResourceIT; import org.apache.atlas.web.resources.BaseResourceIT;
import org.apache.atlas.web.util.Servlets;
import org.testng.Assert;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
...@@ -144,8 +138,7 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -144,8 +138,7 @@ public class EntityNotificationIT extends BaseResourceIT {
final String guid = tableId._getId(); final String guid = tableId._getId();
ClientResponse clientResponse = addTrait(guid, traitInstanceJSON); serviceClient.addTrait(guid, traitInstance);
assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode());
EntityNotification entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME, EntityNotification entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME,
newNotificationPredicate(EntityNotification.OperationType.TRAIT_ADD, HIVE_TABLE_TYPE, guid)); newNotificationPredicate(EntityNotification.OperationType.TRAIT_ADD, HIVE_TABLE_TYPE, guid));
...@@ -170,8 +163,7 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -170,8 +163,7 @@ public class EntityNotificationIT extends BaseResourceIT {
traitInstanceJSON = InstanceSerialization.toJson(traitInstance, true); traitInstanceJSON = InstanceSerialization.toJson(traitInstance, true);
LOG.debug("Trait instance = " + traitInstanceJSON); LOG.debug("Trait instance = " + traitInstanceJSON);
clientResponse = addTrait(guid, traitInstanceJSON); serviceClient.addTrait(guid, traitInstance);
assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode());
entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME, entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME,
newNotificationPredicate(EntityNotification.OperationType.TRAIT_ADD, HIVE_TABLE_TYPE, guid)); newNotificationPredicate(EntityNotification.OperationType.TRAIT_ADD, HIVE_TABLE_TYPE, guid));
...@@ -192,8 +184,7 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -192,8 +184,7 @@ public class EntityNotificationIT extends BaseResourceIT {
public void testDeleteTrait() throws Exception { public void testDeleteTrait() throws Exception {
final String guid = tableId._getId(); final String guid = tableId._getId();
ClientResponse clientResponse = deleteTrait(guid, traitName); serviceClient.deleteTrait(guid, traitName);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
EntityNotification entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME, EntityNotification entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME,
newNotificationPredicate(EntityNotification.OperationType.TRAIT_DELETE, HIVE_TABLE_TYPE, guid)); newNotificationPredicate(EntityNotification.OperationType.TRAIT_DELETE, HIVE_TABLE_TYPE, guid));
...@@ -213,18 +204,4 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -213,18 +204,4 @@ public class EntityNotificationIT extends BaseResourceIT {
createType(traitDefinitionJSON); createType(traitDefinitionJSON);
} }
private ClientResponse addTrait(String guid, String traitInstance) {
WebResource resource = service.path(ENTITIES).path(guid).path(TRAITS);
return resource.accept(Servlets.JSON_MEDIA_TYPE)
.type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.POST, ClientResponse.class, traitInstance);
}
private ClientResponse deleteTrait(String guid, String traitName) {
WebResource resource = service.path(ENTITIES).path(guid).path(TRAITS).path(traitName);
return resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.DELETE, ClientResponse.class);
}
} }
...@@ -18,18 +18,13 @@ ...@@ -18,18 +18,13 @@
package org.apache.atlas.web.resources; package org.apache.atlas.web.resources;
import com.sun.jersey.api.client.ClientResponse; import org.apache.atlas.AtlasClient;
import com.sun.jersey.api.client.WebResource;
import org.apache.atlas.web.util.Servlets;
import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.configuration.PropertiesConfiguration;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response;
/** /**
* Integration test for Admin jersey resource. * Integration test for Admin jersey resource.
*/ */
...@@ -42,19 +37,11 @@ public class AdminJerseyResourceIT extends BaseResourceIT { ...@@ -42,19 +37,11 @@ public class AdminJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testGetVersion() throws Exception { public void testGetVersion() throws Exception {
WebResource resource = service.path("api/atlas/admin/version"); JSONObject response = serviceClient.callAPI(AtlasClient.API.VERSION, null, (String[]) null);
Assert.assertNotNull(response);
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.GET, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties"); PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties");
JSONObject response = new JSONObject(responseAsString);
Assert.assertEquals(response.get("Version"), buildConfiguration.getString("build.version")); Assert.assertEquals(response.get("Version"), buildConfiguration.getString("build.version"));
Assert.assertEquals(response.get("Name"), buildConfiguration.getString("project.name")); Assert.assertEquals(response.get("Name"), buildConfiguration.getString("project.name"));
Assert.assertEquals(response.get("Description"), buildConfiguration.getString("project.description")); Assert.assertEquals(response.get("Description"), buildConfiguration.getString("project.description"));
......
...@@ -21,7 +21,6 @@ package org.apache.atlas.web.resources; ...@@ -21,7 +21,6 @@ package org.apache.atlas.web.resources;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.sun.jersey.api.client.WebResource;
import kafka.consumer.ConsumerTimeoutException; import kafka.consumer.ConsumerTimeoutException;
import org.apache.atlas.ApplicationProperties; import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
...@@ -34,17 +33,7 @@ import org.apache.atlas.typesystem.TypesDef; ...@@ -34,17 +33,7 @@ import org.apache.atlas.typesystem.TypesDef;
import org.apache.atlas.typesystem.json.InstanceSerialization; import org.apache.atlas.typesystem.json.InstanceSerialization;
import org.apache.atlas.typesystem.json.TypesSerialization; import org.apache.atlas.typesystem.json.TypesSerialization;
import org.apache.atlas.typesystem.persistence.Id; import org.apache.atlas.typesystem.persistence.Id;
import org.apache.atlas.typesystem.types.AttributeDefinition; import org.apache.atlas.typesystem.types.*;
import org.apache.atlas.typesystem.types.ClassType;
import org.apache.atlas.typesystem.types.DataTypes;
import org.apache.atlas.typesystem.types.EnumTypeDefinition;
import org.apache.atlas.typesystem.types.EnumValue;
import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
import org.apache.atlas.typesystem.types.IDataType;
import org.apache.atlas.typesystem.types.Multiplicity;
import org.apache.atlas.typesystem.types.StructTypeDefinition;
import org.apache.atlas.typesystem.types.TraitType;
import org.apache.atlas.typesystem.types.TypeUtils;
import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.apache.atlas.utils.AuthenticationUtil; import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.atlas.utils.ParamChecker; import org.apache.atlas.utils.ParamChecker;
...@@ -68,7 +57,6 @@ import java.util.Map; ...@@ -68,7 +57,6 @@ import java.util.Map;
public abstract class BaseResourceIT { public abstract class BaseResourceIT {
public static final String ATLAS_REST_ADDRESS = "atlas.rest.address"; public static final String ATLAS_REST_ADDRESS = "atlas.rest.address";
protected WebResource service;
protected AtlasClient serviceClient; protected AtlasClient serviceClient;
public static final Logger LOG = LoggerFactory.getLogger(BaseResourceIT.class); public static final Logger LOG = LoggerFactory.getLogger(BaseResourceIT.class);
protected static final int MAX_WAIT_TIME = 60000; protected static final int MAX_WAIT_TIME = 60000;
...@@ -89,7 +77,6 @@ public abstract class BaseResourceIT { ...@@ -89,7 +77,6 @@ public abstract class BaseResourceIT {
} else { } else {
serviceClient = new AtlasClient(atlasUrls); serviceClient = new AtlasClient(atlasUrls);
} }
service = serviceClient.getResource();
} }
protected void createType(TypesDef typesDef) throws Exception { protected void createType(TypesDef typesDef) throws Exception {
......
...@@ -19,14 +19,12 @@ ...@@ -19,14 +19,12 @@
package org.apache.atlas.web.resources; package org.apache.atlas.web.resources;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.Struct; import org.apache.atlas.typesystem.Struct;
import org.apache.atlas.typesystem.json.InstanceSerialization; import org.apache.atlas.typesystem.json.InstanceSerialization;
import org.apache.atlas.typesystem.persistence.Id; import org.apache.atlas.typesystem.persistence.Id;
import org.apache.atlas.web.util.Servlets;
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert; import org.testng.Assert;
...@@ -37,8 +35,6 @@ import org.apache.atlas.typesystem.types.TraitType; ...@@ -37,8 +35,6 @@ import org.apache.atlas.typesystem.types.TraitType;
import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.typesystem.types.utils.TypesUtil;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -49,7 +45,6 @@ import static org.testng.Assert.assertEquals; ...@@ -49,7 +45,6 @@ import static org.testng.Assert.assertEquals;
*/ */
public class DataSetLineageJerseyResourceIT extends BaseResourceIT { public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
private static final String BASE_URI = "api/atlas/lineage/hive/table/";
private String salesFactTable; private String salesFactTable;
private String salesMonthlyTable; private String salesMonthlyTable;
private String salesDBName; private String salesDBName;
...@@ -64,17 +59,10 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -64,17 +59,10 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testInputsGraph() throws Exception { public void testInputsGraph() throws Exception {
WebResource resource = service.path(BASE_URI).path(salesMonthlyTable).path("inputs").path("graph"); JSONObject response = serviceClient.callAPI(AtlasClient.API.NAME_LINEAGE_INPUTS_GRAPH, null, salesMonthlyTable, "inputs", "graph");
Assert.assertNotNull(response);
System.out.println("inputs graph = " + response);
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.GET, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
System.out.println("inputs graph = " + responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
JSONObject results = response.getJSONObject(AtlasClient.RESULTS); JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
...@@ -107,17 +95,10 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -107,17 +95,10 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testOutputsGraph() throws Exception { public void testOutputsGraph() throws Exception {
WebResource resource = service.path(BASE_URI).path(salesFactTable).path("outputs").path("graph"); JSONObject response = serviceClient.callAPI(AtlasClient.API.NAME_LINEAGE_OUTPUTS_GRAPH, null, salesFactTable, "outputs", "graph");
Assert.assertNotNull(response);
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) System.out.println("outputs graph= " + response);
.method(HttpMethod.GET, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
System.out.println("outputs graph= " + responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
JSONObject results = response.getJSONObject(AtlasClient.RESULTS); JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
...@@ -150,17 +131,11 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -150,17 +131,11 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testSchema() throws Exception { public void testSchema() throws Exception {
WebResource resource = service.path(BASE_URI).path(salesFactTable).path("schema"); JSONObject response = serviceClient.callAPI(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, salesFactTable, "schema");
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.GET, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(response);
Assert.assertNotNull(responseAsString); System.out.println("schema = " + response);
System.out.println("schema = " + responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
JSONObject results = response.getJSONObject(AtlasClient.RESULTS); JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
...@@ -198,22 +173,14 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -198,22 +173,14 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
} }
} }
@Test @Test(expectedExceptions = AtlasServiceException.class)
public void testSchemaForInvalidTable() throws Exception { public void testSchemaForInvalidTable() throws Exception {
WebResource resource = service.path(BASE_URI).path("blah").path("schema"); JSONObject response = serviceClient.callAPI(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, "blah", "schema");
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.GET, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
} }
@Test @Test(expectedExceptions = AtlasServiceException.class)
public void testSchemaForDB() throws Exception { public void testSchemaForDB() throws Exception {
WebResource resource = service.path(BASE_URI).path(salesDBName).path("schema"); JSONObject response = serviceClient.callAPI(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, salesDBName, "schema");
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.GET, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
} }
private void setupInstances() throws Exception { private void setupInstances() throws Exception {
......
/** /**
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
...@@ -24,7 +24,6 @@ import com.google.gson.Gson; ...@@ -24,7 +24,6 @@ import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException; import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.EntityAuditEvent; import org.apache.atlas.EntityAuditEvent;
...@@ -49,10 +48,8 @@ import org.apache.atlas.typesystem.types.StructTypeDefinition; ...@@ -49,10 +48,8 @@ import org.apache.atlas.typesystem.types.StructTypeDefinition;
import org.apache.atlas.typesystem.types.TraitType; import org.apache.atlas.typesystem.types.TraitType;
import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.apache.atlas.utils.AuthenticationUtil; import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.atlas.web.util.Servlets;
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.RandomStringUtils;
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -63,7 +60,6 @@ import org.testng.annotations.DataProvider; ...@@ -63,7 +60,6 @@ import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -172,16 +168,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -172,16 +168,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
databaseInstance.set("parameters", Collections.EMPTY_MAP); databaseInstance.set("parameters", Collections.EMPTY_MAP);
databaseInstance.set("location", "/tmp"); databaseInstance.set("location", "/tmp");
ClientResponse clientResponse = JSONObject response = serviceClient
service.path(ENTITIES).accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) .callAPI(AtlasClient.API.CREATE_ENTITY, InstanceSerialization.toJson(databaseInstance, true));
.method(HttpMethod.POST, ClientResponse.class, assertNotNull(response);
InstanceSerialization.toJson(databaseInstance, true));
Assert.assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
AtlasClient.EntityResult entityResult = AtlasClient.EntityResult.fromString(response.toString()); AtlasClient.EntityResult entityResult = AtlasClient.EntityResult.fromString(response.toString());
...@@ -333,8 +322,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -333,8 +322,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
String description = "bar table - new desc"; String description = "bar table - new desc";
addProperty(guid, "description", description); addProperty(guid, "description", description);
String entityRef = getEntityDefinition(getEntityDefinition(guid)); JSONObject response = serviceClient.callAPI(AtlasClient.API.GET_ENTITY, null, guid);
Assert.assertNotNull(entityRef); Assert.assertNotNull(response);
tableInstance.set("description", description); tableInstance.set("description", description);
...@@ -349,8 +338,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -349,8 +338,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
String currentTime = String.valueOf(new DateTime() ); String currentTime = String.valueOf(new DateTime() );
addProperty(guid, "createTime", currentTime); addProperty(guid, "createTime", currentTime);
entityRef = getEntityDefinition(getEntityDefinition(guid)); response = serviceClient.callAPI(AtlasClient.API.GET_ENTITY, null, guid);
Assert.assertNotNull(entityRef); Assert.assertNotNull(response);
tableInstance.set("createTime", currentTime); tableInstance.set("createTime", currentTime);
} }
...@@ -401,13 +390,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -401,13 +390,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test(dependsOnMethods = "testSubmitEntity") @Test(dependsOnMethods = "testSubmitEntity")
public void testGetEntityDefinition() throws Exception { public void testGetEntityDefinition() throws Exception {
final String guid = tableId._getId(); final String guid = tableId._getId();
ClientResponse clientResponse = getEntityDefinition(guid); JSONObject response = serviceClient.callAPI(AtlasClient.API.GET_ENTITY, null, guid);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(response);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
final String definition = response.getString(AtlasClient.DEFINITION); final String definition = response.getString(AtlasClient.DEFINITION);
...@@ -422,38 +407,13 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -422,38 +407,13 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
assertEquals(entityResult.getUpdateEntities().get(0), guid); assertEquals(entityResult.getUpdateEntities().get(0), guid);
} }
private ClientResponse getEntityDefinition(String guid) { @Test(expectedExceptions = AtlasServiceException.class)
WebResource resource = service.path(ENTITIES).path(guid);
return resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.GET, ClientResponse.class);
}
private String getEntityDefinition(ClientResponse clientResponse) throws Exception {
JSONObject response = getEntity(clientResponse);
final String definition = response.getString(AtlasClient.DEFINITION);
Assert.assertNotNull(definition);
return definition;
}
private JSONObject getEntity(ClientResponse clientResponse) throws JSONException {
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
JSONObject response = new JSONObject(clientResponse.getEntity(String.class));
return response;
}
@Test
public void testGetInvalidEntityDefinition() throws Exception { public void testGetInvalidEntityDefinition() throws Exception {
WebResource resource = service.path(ENTITIES).path("blah");
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) JSONObject response = serviceClient.callAPI(AtlasClient.API.GET_ENTITY, null, "blah");
.method(HttpMethod.GET, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(response);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.ERROR)); Assert.assertNotNull(response.get(AtlasClient.ERROR));
Assert.assertNotNull(response.get(AtlasClient.STACKTRACE)); Assert.assertNotNull(response.get(AtlasClient.STACKTRACE));
} }
...@@ -465,17 +425,13 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -465,17 +425,13 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
Assert.assertTrue(entities.contains(tableId._getId())); Assert.assertTrue(entities.contains(tableId._getId()));
} }
@Test @Test(expectedExceptions = AtlasServiceException.class)
public void testGetEntityListForBadEntityType() throws Exception { public void testGetEntityListForBadEntityType() throws Exception {
ClientResponse clientResponse = Map<String, String> queryParams = new HashMap<>();
service.path(ENTITIES).queryParam("type", "blah").accept(Servlets.JSON_MEDIA_TYPE) queryParams.put("type", "blah");
.type(Servlets.JSON_MEDIA_TYPE).method(HttpMethod.GET, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class); JSONObject response = serviceClient.callAPI(AtlasClient.API.GET_ENTITY, queryParams);
Assert.assertNotNull(responseAsString); assertNotNull(response);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.ERROR)); Assert.assertNotNull(response.get(AtlasClient.ERROR));
Assert.assertNotNull(response.get(AtlasClient.STACKTRACE)); Assert.assertNotNull(response.get(AtlasClient.STACKTRACE));
} }
...@@ -485,15 +441,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -485,15 +441,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
public void testGetEntityListForNoInstances() throws Exception { public void testGetEntityListForNoInstances() throws Exception {
String typeName = addNewType(); String typeName = addNewType();
ClientResponse clientResponse = Map<String, String> queryParams = new HashMap<>();
service.path(ENTITIES).queryParam("type", typeName).accept(Servlets.JSON_MEDIA_TYPE) queryParams.put("type", typeName);
.type(Servlets.JSON_MEDIA_TYPE).method(HttpMethod.GET, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = serviceClient.callAPI(AtlasClient.API.GET_ENTITY, queryParams);
assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(AtlasClient.RESULTS); final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
...@@ -515,15 +467,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -515,15 +467,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test(dependsOnMethods = "testSubmitEntity") @Test(dependsOnMethods = "testSubmitEntity")
public void testGetTraitNames() throws Exception { public void testGetTraitNames() throws Exception {
final String guid = tableId._getId(); final String guid = tableId._getId();
ClientResponse clientResponse =
service.path(ENTITIES).path(guid).path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE)
.type(Servlets.JSON_MEDIA_TYPE).method(HttpMethod.GET, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = serviceClient.callAPI(AtlasClient.API.LIST_TRAITS, null, guid, TRAITS);
assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(AtlasClient.RESULTS); final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
...@@ -544,16 +490,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -544,16 +490,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON); LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON);
final String guid = tableId._getId(); final String guid = tableId._getId();
ClientResponse clientResponse = JSONObject response = serviceClient.callAPI(AtlasClient.API.ADD_TRAITS, traitInstanceAsJSON, guid, TRAITS);
service.path(ENTITIES).path(guid).path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE) assertNotNull(response);
.type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_ADD); assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_ADD);
...@@ -573,12 +511,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -573,12 +511,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON); LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON);
final String guid = tableId._getId(); final String guid = tableId._getId();
ClientResponse clientResponse = JSONObject response = serviceClient.callAPI(AtlasClient.API.ADD_TRAITS, traitInstanceAsJSON, guid, TRAITS);
service.path(ENTITIES).path(guid).path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE) assertNotNull(response);
.type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode());
Struct traitDef = serviceClient.getTraitDefinition(guid, traitName); Struct traitDef = serviceClient.getTraitDefinition(guid, traitName);
System.out.println(traitDef.toString()); System.out.println(traitDef.toString());
JSONObject responseAsJSON = new JSONObject(InstanceSerialization.toJson(traitDef, true)); JSONObject responseAsJSON = new JSONObject(InstanceSerialization.toJson(traitDef, true));
...@@ -590,7 +524,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -590,7 +524,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
Assert.assertEquals(allTraitDefs.size(), 9); Assert.assertEquals(allTraitDefs.size(), 9);
} }
@Test(dependsOnMethods = "testAddTrait") @Test(dependsOnMethods = "testAddTrait", expectedExceptions = AtlasServiceException.class)
public void testAddExistingTrait() throws Exception { public void testAddExistingTrait() throws Exception {
final String traitName = "PII_Trait" + randomString(); final String traitName = "PII_Trait" + randomString();
...@@ -599,11 +533,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -599,11 +533,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON); LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON);
final String guid = tableId._getId(); final String guid = tableId._getId();
ClientResponse clientResponse = JSONObject response = serviceClient.callAPI(AtlasClient.API.ADD_TRAITS, traitInstanceAsJSON, guid, TRAITS);
service.path(ENTITIES).path(guid).path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE) assertNotNull(response);
.type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
} }
@Test(dependsOnMethods = "testGetTraitNames") @Test(dependsOnMethods = "testGetTraitNames")
...@@ -622,24 +553,12 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -622,24 +553,12 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON); LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON);
final String guid = tableId._getId(); final String guid = tableId._getId();
ClientResponse clientResponse = JSONObject response = serviceClient.callAPI(AtlasClient.API.ADD_TRAITS, traitInstanceAsJSON, guid, TRAITS);
service.path(ENTITIES).path(guid).path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE) assertNotNull(response);
.type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
// verify the response // verify the response
clientResponse = getEntityDefinition(guid); response = serviceClient.callAPI(AtlasClient.API.GET_ENTITY, null, guid);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
final String definition = response.getString(AtlasClient.DEFINITION); final String definition = response.getString(AtlasClient.DEFINITION);
...@@ -650,7 +569,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -650,7 +569,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
Assert.assertEquals(type, "SSN"); Assert.assertEquals(type, "SSN");
} }
@Test @Test(expectedExceptions = AtlasServiceException.class)
public void testAddTraitWithNoRegistration() throws Exception { public void testAddTraitWithNoRegistration() throws Exception {
final String traitName = "PII_Trait" + randomString(); final String traitName = "PII_Trait" + randomString();
HierarchicalTypeDefinition<TraitType> piiTrait = HierarchicalTypeDefinition<TraitType> piiTrait =
...@@ -662,53 +581,33 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -662,53 +581,33 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
String traitInstanceAsJSON = InstanceSerialization$.MODULE$.toJson(traitInstance, true); String traitInstanceAsJSON = InstanceSerialization$.MODULE$.toJson(traitInstance, true);
LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON); LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON);
ClientResponse clientResponse = JSONObject response = serviceClient.callAPI(AtlasClient.API.CREATE_ENTITY, traitInstanceAsJSON, "random", TRAITS);
service.path(ENTITIES).path("random").path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE)
.type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
} }
@Test(dependsOnMethods = "testAddTrait") @Test(dependsOnMethods = "testAddTrait")
public void testDeleteTrait() throws Exception { public void testDeleteTrait() throws Exception {
final String guid = tableId._getId(); final String guid = tableId._getId();
ClientResponse clientResponse = service.path(ENTITIES).path(guid).path(TRAITS).path(traitName) JSONObject response = serviceClient.callAPI(AtlasClient.API.DELETE_TRAITS, null, guid, TRAITS, traitName);
.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.DELETE, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
Assert.assertNotNull(response.get("traitName")); Assert.assertNotNull(response.get("traitName"));
assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_DELETE); assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_DELETE);
} }
@Test @Test(expectedExceptions = AtlasServiceException.class)
public void testDeleteTraitNonExistent() throws Exception { public void testDeleteTraitNonExistent() throws Exception {
final String traitName = "blah_trait"; final String traitName = "blah_trait";
JSONObject response = serviceClient.callAPI(AtlasClient.API.DELETE_TRAITS, null, "random", TRAITS);
ClientResponse clientResponse = service.path(ENTITIES).path("random").path(TRAITS).path(traitName)
.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.DELETE, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.ERROR)); Assert.assertNotNull(response.get(AtlasClient.ERROR));
Assert.assertEquals(response.getString(AtlasClient.ERROR), Assert.assertEquals(response.getString(AtlasClient.ERROR),
"trait=" + traitName + " should be defined in type system before it can be deleted"); "trait=" + traitName + " should be defined in type system before it can be deleted");
Assert.assertNotNull(response.get(AtlasClient.STACKTRACE)); Assert.assertNotNull(response.get(AtlasClient.STACKTRACE));
} }
@Test(dependsOnMethods = "testSubmitEntity()") @Test(dependsOnMethods = "testSubmitEntity")
public void testDeleteExistentTraitNonExistentForEntity() throws Exception { public void testDeleteExistentTraitNonExistentForEntity() throws Exception {
final String guid = tableId._getId(); final String guid = tableId._getId();
final String traitName = "PII_Trait" + randomString(); final String traitName = "PII_Trait" + randomString();
HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil
...@@ -716,22 +615,12 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -716,22 +615,12 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE)); TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true); String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
createType(traitDefinitionAsJSON); createType(traitDefinitionAsJSON);
ClientResponse clientResponse = service.path(ENTITIES).path(guid).path(TRAITS).path(traitName)
.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.DELETE, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class); JSONObject response = serviceClient.callAPI(AtlasClient.API.DELETE_TRAITS, null, "random", TRAITS);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.ERROR)); Assert.assertNotNull(response.get(AtlasClient.ERROR));
Assert.assertNotNull(response.get(AtlasClient.STACKTRACE)); Assert.assertNotNull(response.get(AtlasClient.STACKTRACE));
} }
private String random() { private String random() {
return RandomStringUtils.random(10); return RandomStringUtils.random(10);
} }
...@@ -754,9 +643,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -754,9 +643,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
instance.set(attrName, attrValue); instance.set(attrName, attrValue);
Id guid = createInstance(instance); Id guid = createInstance(instance);
ClientResponse response = getEntityDefinition(guid._getId()); JSONObject response = serviceClient.callAPI(AtlasClient.API.GET_ENTITY, null, guid._getId());
String definition = getEntityDefinition(response); Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(response.toString(), true);
Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(definition, true);
Assert.assertEquals(getReferenceable.get(attrName), attrValue); Assert.assertEquals(getReferenceable.get(attrName), attrValue);
} }
...@@ -786,9 +674,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -786,9 +674,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
assertEquals(entityResult.getUpdateEntities().size(), 1); assertEquals(entityResult.getUpdateEntities().size(), 1);
assertEquals(entityResult.getUpdateEntities().get(0), tableId._getId()); assertEquals(entityResult.getUpdateEntities().get(0), tableId._getId());
ClientResponse response = getEntityDefinition(tableId._getId()); JSONObject response = serviceClient.callAPI(AtlasClient.API.GET_ENTITY, null, tableId._getId());
String definition = getEntityDefinition(response); Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(response.toString(), true);
Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(definition, true);
List<Referenceable> refs = (List<Referenceable>) getReferenceable.get("columns"); List<Referenceable> refs = (List<Referenceable>) getReferenceable.get("columns");
Assert.assertTrue(refs.get(0).equalsContents(columns.get(0))); Assert.assertTrue(refs.get(0).equalsContents(columns.get(0)));
...@@ -807,9 +694,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -807,9 +694,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
assertEquals(entityResult.getUpdateEntities().size(), 2); assertEquals(entityResult.getUpdateEntities().size(), 2);
assertEquals(entityResult.getUpdateEntities().get(0), tableId._getId()); assertEquals(entityResult.getUpdateEntities().get(0), tableId._getId());
response = getEntityDefinition(tableId._getId()); response = serviceClient.callAPI(AtlasClient.API.GET_ENTITY, null, tableId._getId());
definition = getEntityDefinition(response); getReferenceable = InstanceSerialization.fromJsonReferenceable(response.toString(), true);
getReferenceable = InstanceSerialization.fromJsonReferenceable(definition, true);
refs = (List<Referenceable>) getReferenceable.get("columns"); refs = (List<Referenceable>) getReferenceable.get("columns");
Assert.assertTrue(refs.get(0).getValuesMap().equals(values)); Assert.assertTrue(refs.get(0).getValuesMap().equals(values));
...@@ -849,42 +735,38 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -849,42 +735,38 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
JSONArray entityArray = new JSONArray(1); JSONArray entityArray = new JSONArray(1);
entityArray.put(entityJson); entityArray.put(entityJson);
LOG.debug("Replacing entity= " + tableInstance); LOG.debug("Replacing entity= " + tableInstance);
ClientResponse clientResponse = service.path(ENTITIES).
accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE). JSONObject response = serviceClient.callAPI(AtlasClient.API.UPDATE_ENTITY, entityArray);
method(HttpMethod.PUT, ClientResponse.class, entityArray);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
// ATLAS-586: verify response entity can be parsed by GSON. // ATLAS-586: verify response entity can be parsed by GSON.
String entity = clientResponse.getEntity(String.class);
Gson gson = new Gson(); Gson gson = new Gson();
try { try {
UpdateEntitiesResponse updateEntitiesResponse = gson.fromJson(entity, UpdateEntitiesResponse.class); UpdateEntitiesResponse updateEntitiesResponse = gson.fromJson(response.toString(), UpdateEntitiesResponse.class);
} }
catch (JsonSyntaxException e) { catch (JsonSyntaxException e) {
Assert.fail("Response entity from " + service.path(ENTITIES).getURI() + " not parseable by GSON", e); Assert.fail("Response entity from not parse-able by GSON", e);
} }
clientResponse = getEntityDefinition(tableId._getId()); response = serviceClient.callAPI(AtlasClient.API.GET_ENTITY, null, tableId._getId());
String definition = getEntityDefinition(clientResponse); Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(response.toString(), true);
Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(definition, true);
List<Referenceable> refs = (List<Referenceable>) getReferenceable.get("columns"); List<Referenceable> refs = (List<Referenceable>) getReferenceable.get("columns");
Assert.assertEquals(refs.size(), 2); Assert.assertEquals(refs.size(), 2);
Assert.assertTrue(refs.get(0).getValuesMap().equals(values1)); Assert.assertTrue(refs.get(0).getValuesMap().equals(values1));
Assert.assertTrue(refs.get(1).getValuesMap().equals(values2)); Assert.assertTrue(refs.get(1).getValuesMap().equals(values2));
} }
private static class UpdateEntitiesResponse { private static class UpdateEntitiesResponse {
String requestId; String requestId;
AtlasClient.EntityResult entities; AtlasClient.EntityResult entities;
AtlasEntity definition; AtlasEntity definition;
} }
private static class AtlasEntity { private static class AtlasEntity {
String typeName; String typeName;
final Map<String, Object> values = new HashMap<String, Object>(); final Map<String, Object> values = new HashMap<String, Object>();
} }
@Test @Test
public void testDeleteEntitiesViaRestApi() throws Exception { public void testDeleteEntitiesViaRestApi() throws Exception {
// Create 2 database entities // Create 2 database entities
...@@ -911,14 +793,13 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -911,14 +793,13 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
db2.set("parameters", Collections.EMPTY_MAP); db2.set("parameters", Collections.EMPTY_MAP);
db2.set("location", "/tmp"); db2.set("location", "/tmp");
Id db2Id = createInstance(db2); Id db2Id = createInstance(db2);
// Delete the database entities // Delete the database entities
ClientResponse clientResponse = service.path(ENTITIES). Map<String, String> queryParams = new HashMap<>();
queryParam(AtlasClient.GUID.toLowerCase(), db1Id._getId()). queryParams.put(AtlasClient.GUID.toLowerCase(), db1Id._getId());
queryParam(AtlasClient.GUID.toLowerCase(), db2Id._getId()). queryParams.put(AtlasClient.GUID.toLowerCase(), db2Id._getId());
accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE).method(HttpMethod.DELETE, ClientResponse.class);
JSONObject response = getEntity(clientResponse); JSONObject response = serviceClient.callAPI(AtlasClient.API.DELETE_ENTITIES, queryParams);
List<String> deletedGuidsList = AtlasClient.EntityResult.fromString(response.toString()).getDeletedEntities(); List<String> deletedGuidsList = AtlasClient.EntityResult.fromString(response.toString()).getDeletedEntities();
Assert.assertTrue(deletedGuidsList.contains(db1Id._getId())); Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
Assert.assertTrue(deletedGuidsList.contains(db2Id._getId())); Assert.assertTrue(deletedGuidsList.contains(db2Id._getId()));
...@@ -929,7 +810,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -929,7 +810,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
assertEquals(entity.getId().getState(), Id.EntityState.DELETED); assertEquals(entity.getId().getState(), Id.EntityState.DELETED);
} }
} }
@Test @Test
public void testDeleteEntitiesViaClientApi() throws Exception { public void testDeleteEntitiesViaClientApi() throws Exception {
// Create 2 database entities // Create 2 database entities
...@@ -955,16 +836,16 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -955,16 +836,16 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
db2.set("parameters", Collections.EMPTY_MAP); db2.set("parameters", Collections.EMPTY_MAP);
db2.set("location", "/tmp"); db2.set("location", "/tmp");
Id db2Id = createInstance(db2); Id db2Id = createInstance(db2);
// Delete the database entities // Delete the database entities
List<String> deletedGuidsList = List<String> deletedGuidsList =
serviceClient.deleteEntities(db1Id._getId(), db2Id._getId()).getDeletedEntities(); serviceClient.deleteEntities(db1Id._getId(), db2Id._getId()).getDeletedEntities();
// Verify that deleteEntities() response has database entity guids // Verify that deleteEntities() response has database entity guids
Assert.assertEquals(deletedGuidsList.size(), 2); Assert.assertEquals(deletedGuidsList.size(), 2);
Assert.assertTrue(deletedGuidsList.contains(db1Id._getId())); Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
Assert.assertTrue(deletedGuidsList.contains(db2Id._getId())); Assert.assertTrue(deletedGuidsList.contains(db2Id._getId()));
// Verify entities were deleted from the repository. // Verify entities were deleted from the repository.
for (String guid : deletedGuidsList) { for (String guid : deletedGuidsList) {
Referenceable entity = serviceClient.getEntity(guid); Referenceable entity = serviceClient.getEntity(guid);
......
...@@ -20,29 +20,30 @@ package org.apache.atlas.web.resources; ...@@ -20,29 +20,30 @@ package org.apache.atlas.web.resources;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.lineage.AtlasLineageInfo; import org.apache.atlas.model.lineage.AtlasLineageInfo;
import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.persistence.Id; import org.apache.atlas.typesystem.persistence.Id;
import org.apache.atlas.web.util.Servlets; import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.apache.atlas.AtlasBaseClient.APIInfo;
/** /**
* Entity Lineage v2 Integration Tests. * Entity Lineage v2 Integration Tests.
*/ */
public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceIT { public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceIT {
private static final String BASE_URI = "api/atlas/v2/lineage/"; private static final String BASE_URI = "api/atlas/v2/lineage/";
private static final APIInfo LINEAGE_V2_API = new APIInfo(BASE_URI, "GET", Response.Status.OK);
private static final String INPUT_DIRECTION = "INPUT"; private static final String INPUT_DIRECTION = "INPUT";
private static final String OUTPUT_DIRECTION = "OUTPUT"; private static final String OUTPUT_DIRECTION = "OUTPUT";
private static final String BOTH_DIRECTION = "BOTH"; private static final String BOTH_DIRECTION = "BOTH";
...@@ -66,18 +67,16 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI ...@@ -66,18 +67,16 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
public void testInputLineageInfo() throws Exception { public void testInputLineageInfo() throws Exception {
String tableId = serviceClient.getEntity(HIVE_TABLE_TYPE, String tableId = serviceClient.getEntity(HIVE_TABLE_TYPE,
AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId(); AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
WebResource resource = service.path(BASE_URI).path(tableId).queryParam(DIRECTION_PARAM, INPUT_DIRECTION).
queryParam(DEPTH_PARAM, "5");
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.GET, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class); Map<String, String> queryParams = new HashMap<>();
Assert.assertNotNull(responseAsString); queryParams.put(DIRECTION_PARAM, INPUT_DIRECTION);
System.out.println("input lineage info = " + responseAsString); queryParams.put(DEPTH_PARAM, "5");
JSONObject response = serviceClient.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams);
Assert.assertNotNull(response);
System.out.println("input lineage info = " + response
);
AtlasLineageInfo inputLineageInfo = gson.fromJson(responseAsString, AtlasLineageInfo.class); AtlasLineageInfo inputLineageInfo = gson.fromJson(response.toString(), AtlasLineageInfo.class);
Map<String, AtlasEntityHeader> entities = inputLineageInfo.getGuidEntityMap(); Map<String, AtlasEntityHeader> entities = inputLineageInfo.getGuidEntityMap();
Assert.assertNotNull(entities); Assert.assertNotNull(entities);
...@@ -96,18 +95,16 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI ...@@ -96,18 +95,16 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
public void testOutputLineageInfo() throws Exception { public void testOutputLineageInfo() throws Exception {
String tableId = serviceClient.getEntity(HIVE_TABLE_TYPE, String tableId = serviceClient.getEntity(HIVE_TABLE_TYPE,
AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId(); AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
WebResource resource = service.path(BASE_URI).path(tableId).queryParam(DIRECTION_PARAM, OUTPUT_DIRECTION).
queryParam(DEPTH_PARAM, "5");
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) Map<String, String> queryParams = new HashMap<>();
.method(HttpMethod.GET, ClientResponse.class); queryParams.put(DIRECTION_PARAM, OUTPUT_DIRECTION);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); queryParams.put(DEPTH_PARAM, "5");
JSONObject response = serviceClient.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams);
String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(response);
Assert.assertNotNull(responseAsString); System.out.println("output lineage info = " + response);
System.out.println("output lineage info = " + responseAsString);
AtlasLineageInfo outputLineageInfo = gson.fromJson(responseAsString, AtlasLineageInfo.class); AtlasLineageInfo outputLineageInfo = gson.fromJson(response.toString(), AtlasLineageInfo.class);
Map<String, AtlasEntityHeader> entities = outputLineageInfo.getGuidEntityMap(); Map<String, AtlasEntityHeader> entities = outputLineageInfo.getGuidEntityMap();
Assert.assertNotNull(entities); Assert.assertNotNull(entities);
...@@ -126,18 +123,16 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI ...@@ -126,18 +123,16 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
public void testLineageInfo() throws Exception { public void testLineageInfo() throws Exception {
String tableId = serviceClient.getEntity(HIVE_TABLE_TYPE, String tableId = serviceClient.getEntity(HIVE_TABLE_TYPE,
AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId(); AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
WebResource resource = service.path(BASE_URI).path(tableId).queryParam(DIRECTION_PARAM, BOTH_DIRECTION).
queryParam(DEPTH_PARAM, "5");
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) Map<String, String> queryParams = new HashMap<>();
.method(HttpMethod.GET, ClientResponse.class); queryParams.put(DIRECTION_PARAM, BOTH_DIRECTION);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); queryParams.put(DEPTH_PARAM, "5");
JSONObject response = serviceClient.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams);
String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(response);
Assert.assertNotNull(responseAsString); System.out.println("both lineage info = " + response);
System.out.println("both lineage info = " + responseAsString);
AtlasLineageInfo bothLineageInfo = gson.fromJson(responseAsString, AtlasLineageInfo.class); AtlasLineageInfo bothLineageInfo = gson.fromJson(response.toString(), AtlasLineageInfo.class);
Map<String, AtlasEntityHeader> entities = bothLineageInfo.getGuidEntityMap(); Map<String, AtlasEntityHeader> entities = bothLineageInfo.getGuidEntityMap();
Assert.assertNotNull(entities); Assert.assertNotNull(entities);
......
...@@ -21,8 +21,7 @@ package org.apache.atlas.web.resources; ...@@ -21,8 +21,7 @@ package org.apache.atlas.web.resources;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource; import org.apache.atlas.AtlasBaseClient;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException; import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Referenceable;
...@@ -36,19 +35,19 @@ import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition; ...@@ -36,19 +35,19 @@ import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
import org.apache.atlas.typesystem.types.StructTypeDefinition; import org.apache.atlas.typesystem.types.StructTypeDefinition;
import org.apache.atlas.typesystem.types.TraitType; import org.apache.atlas.typesystem.types.TraitType;
import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.apache.atlas.web.util.Servlets;
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
/** /**
...@@ -56,6 +55,10 @@ import static org.testng.Assert.fail; ...@@ -56,6 +55,10 @@ import static org.testng.Assert.fail;
*/ */
public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
private static final String SEARCH_DSL_PATH = "api/atlas/discovery/search/dsl";
private static final AtlasBaseClient.APIInfo SEARCH_DSL = new AtlasBaseClient.APIInfo(SEARCH_DSL_PATH, "GET", Response.Status.OK);
public static final String GREMLIN_SEARCH = "api/atlas/discovery/search/gremlin";
private String tagName; private String tagName;
private String dbName; private String dbName;
...@@ -70,16 +73,11 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -70,16 +73,11 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testSearchByDSL() throws Exception { public void testSearchByDSL() throws Exception {
String dslQuery = "from "+ DATABASE_TYPE + " qualifiedName=\"" + dbName + "\""; String dslQuery = "from "+ DATABASE_TYPE + " qualifiedName=\"" + dbName + "\"";
WebResource resource = service.path("api/atlas/discovery/search/dsl").queryParam("query", dslQuery); Map<String, String> queryParams = new HashMap<>();
queryParams.put("query", dslQuery);
JSONObject response = serviceClient.callAPI(AtlasClient.API.SEARCH_DSL, queryParams);
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) Assert.assertNotNull(response);
.method(HttpMethod.GET, ClientResponse.class);
assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEquals(response.getString("query"), dslQuery); assertEquals(response.getString("query"), dslQuery);
...@@ -98,11 +96,10 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -98,11 +96,10 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
//search without new parameters of limit and offset should work //search without new parameters of limit and offset should work
String dslQuery = "from "+ DATABASE_TYPE + " qualifiedName=\"" + dbName + "\""; String dslQuery = "from "+ DATABASE_TYPE + " qualifiedName=\"" + dbName + "\"";
WebResource resource = service.path("api/atlas/discovery/search/dsl").queryParam("query", dslQuery); Map<String, String> queryParams = new HashMap<>();
queryParams.put("query", dslQuery);
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) JSONObject response = serviceClient.callAPI(AtlasClient.API.SEARCH_DSL, queryParams);
.method(HttpMethod.GET, ClientResponse.class); assertNotNull(response);
assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
//higher limit, all results returned //higher limit, all results returned
JSONArray results = serviceClient.searchByDSL(dslQuery, 10, 0); JSONArray results = serviceClient.searchByDSL(dslQuery, 10, 0);
...@@ -145,29 +142,24 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -145,29 +142,24 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
} }
} }
@Test @Test(expectedExceptions = AtlasServiceException.class)
public void testSearchByDSLForUnknownType() throws Exception { public void testSearchByDSLForUnknownType() throws Exception {
String dslQuery = "from blah"; String dslQuery = "from blah";
WebResource resource = service.path("api/atlas/discovery/search/dsl").queryParam("query", dslQuery); Map<String, String> queryParams = new HashMap<>();
queryParams.put("query", dslQuery);
JSONObject response = serviceClient.callAPI(AtlasClient.API.SEARCH_DSL, queryParams);
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.GET, ClientResponse.class);
assertEquals(clientResponse.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
} }
@Test @Test
public void testSearchUsingGremlin() throws Exception { public void testSearchUsingGremlin() throws Exception {
String query = "g.V.has('type', 'hive_db').toList()"; String query = "g.V.has('type', 'hive_db').toList()";
WebResource resource = service.path("api/atlas/discovery/search/gremlin").queryParam("query", query); Map<String, String> queryParams = new HashMap<>();
queryParams.put("query", query);
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.GET, ClientResponse.class);
assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class); JSONObject response = serviceClient.callAPI(AtlasClient.API.GREMLIN_SEARCH, queryParams);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEquals(response.getString("query"), query); assertEquals(response.getString("query"), query);
...@@ -178,16 +170,11 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -178,16 +170,11 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
public void testSearchUsingDSL() throws Exception { public void testSearchUsingDSL() throws Exception {
//String query = "from dsl_test_type"; //String query = "from dsl_test_type";
String query = "from "+ DATABASE_TYPE + " qualifiedName=\"" + dbName +"\""; String query = "from "+ DATABASE_TYPE + " qualifiedName=\"" + dbName +"\"";
WebResource resource = service.path("api/atlas/discovery/search").queryParam("query", query); Map<String, String> queryParams = new HashMap<>();
queryParams.put("query", query);
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) JSONObject response = serviceClient.callAPI(AtlasClient.API.SEARCH_DSL, queryParams);
.method(HttpMethod.GET, ClientResponse.class);
assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(response);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEquals(response.getString("query"), query); assertEquals(response.getString("query"), query);
...@@ -197,16 +184,11 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -197,16 +184,11 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testSearchFullTextOnDSLFailure() throws Exception { public void testSearchFullTextOnDSLFailure() throws Exception {
String query = "*"; String query = "*";
WebResource resource = service.path("api/atlas/discovery/search").queryParam("query", query); Map<String, String> queryParams = new HashMap<>();
queryParams.put("query", query);
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) JSONObject response = serviceClient.callAPI(AtlasClient.API.SEARCH_DSL, queryParams);
.method(HttpMethod.GET, ClientResponse.class);
assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEquals(response.getString("query"), query); assertEquals(response.getString("query"), query);
...@@ -234,11 +216,10 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -234,11 +216,10 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
//API works without limit and offset //API works without limit and offset
String query = dbName; String query = dbName;
WebResource resource = service.path("api/atlas/discovery/search/fulltext").queryParam("query", query); Map<String, String> queryParams = new HashMap<>();
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) queryParams.put("query", query);
.method(HttpMethod.GET, ClientResponse.class); response = serviceClient.callAPI(AtlasClient.API.SEARCH_FULL_TEXT, queryParams);
assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); results = response.getJSONArray(AtlasClient.RESULTS);
results = new JSONObject(clientResponse.getEntity(String.class)).getJSONArray(AtlasClient.RESULTS);
assertEquals(results.length(), 1); assertEquals(results.length(), 1);
//verify passed in limits and offsets are used //verify passed in limits and offsets are used
......
...@@ -20,9 +20,6 @@ package org.apache.atlas.web.resources; ...@@ -20,9 +20,6 @@ package org.apache.atlas.web.resources;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException; import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.TypesDef;
...@@ -37,7 +34,6 @@ import org.apache.atlas.typesystem.types.Multiplicity; ...@@ -37,7 +34,6 @@ import org.apache.atlas.typesystem.types.Multiplicity;
import org.apache.atlas.typesystem.types.StructTypeDefinition; import org.apache.atlas.typesystem.types.StructTypeDefinition;
import org.apache.atlas.typesystem.types.TraitType; import org.apache.atlas.typesystem.types.TraitType;
import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.apache.atlas.web.util.Servlets;
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert; import org.testng.Assert;
...@@ -45,11 +41,12 @@ import org.testng.annotations.AfterClass; ...@@ -45,11 +41,12 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createOptionalAttrDef; import static org.apache.atlas.typesystem.types.utils.TypesUtil.createOptionalAttrDef;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
...@@ -84,21 +81,14 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -84,21 +81,14 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
String typesAsJSON = TypesSerialization.toJson(typeDefinition, false); String typesAsJSON = TypesSerialization.toJson(typeDefinition, false);
System.out.println("typesAsJSON = " + typesAsJSON); System.out.println("typesAsJSON = " + typesAsJSON);
WebResource resource = service.path("api/atlas/types"); JSONObject response = serviceClient.callAPI(AtlasClient.API.CREATE_TYPE, typesAsJSON);
Assert.assertNotNull(response);
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.POST, ClientResponse.class, typesAsJSON);
assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONArray typesAdded = response.getJSONArray(AtlasClient.TYPES);
JSONArray typesAdded = response.getJSONArray(AtlasClient.TYPES); assertEquals(typesAdded.length(), 1);
assertEquals(typesAdded.length(), 1); assertEquals(typesAdded.getJSONObject(0).getString("name"), typeDefinition.typeName);
assertEquals(typesAdded.getJSONObject(0).getString("name"), typeDefinition.typeName); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));}
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
}
} }
} }
...@@ -152,15 +142,9 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -152,15 +142,9 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) { for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) {
System.out.println("typeName = " + typeDefinition.typeName); System.out.println("typeName = " + typeDefinition.typeName);
WebResource resource = service.path("api/atlas/types").path(typeDefinition.typeName); JSONObject response = serviceClient.callAPI(AtlasClient.API.LIST_TYPES, null, typeDefinition.typeName);
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) Assert.assertNotNull(response);
.method(HttpMethod.GET, ClientResponse.class);
assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.DEFINITION)); Assert.assertNotNull(response.get(AtlasClient.DEFINITION));
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
...@@ -178,27 +162,16 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -178,27 +162,16 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
} }
} }
@Test @Test(expectedExceptions = AtlasServiceException.class)
public void testGetDefinitionForNonexistentType() throws Exception { public void testGetDefinitionForNonexistentType() throws Exception {
WebResource resource = service.path("api/atlas/types").path("blah"); JSONObject response = serviceClient.callAPI(AtlasClient.API.LIST_TYPES, null, "blah");
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.GET, ClientResponse.class);
assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
} }
@Test(dependsOnMethods = "testSubmit") @Test(dependsOnMethods = "testSubmit")
public void testGetTypeNames() throws Exception { public void testGetTypeNames() throws Exception {
WebResource resource = service.path("api/atlas/types"); JSONObject response = serviceClient.callAPI(AtlasClient.API.LIST_TYPES, null, (String[]) null);
Assert.assertNotNull(response);
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.GET, ClientResponse.class);
assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(AtlasClient.RESULTS); final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
...@@ -214,17 +187,12 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -214,17 +187,12 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
public void testGetTraitNames() throws Exception { public void testGetTraitNames() throws Exception {
String[] traitsAdded = addTraits(); String[] traitsAdded = addTraits();
WebResource resource = service.path("api/atlas/types"); Map<String, String> queryParams = new HashMap<>();
queryParams.put("type", DataTypes.TypeCategory.TRAIT.name());
ClientResponse clientResponse =
resource.queryParam("type", DataTypes.TypeCategory.TRAIT.name()).accept(Servlets.JSON_MEDIA_TYPE)
.type(Servlets.JSON_MEDIA_TYPE).method(HttpMethod.GET, ClientResponse.class);
assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class); JSONObject response = serviceClient.callAPI(AtlasClient.API.LIST_TYPES, queryParams);
Assert.assertNotNull(responseAsString); Assert.assertNotNull(response);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(AtlasClient.RESULTS); final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment