Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
2c881a46
Commit
2c881a46
authored
Nov 20, 2016
by
apoorvnaik
Committed by
Suma Shivaprasad
Dec 07, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1307: Integration test calls routing via the Client.
parent
de6122fa
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
169 additions
and
292 deletions
+169
-292
AtlasBaseClient.java
client/src/main/java/org/apache/atlas/AtlasBaseClient.java
+32
-40
AtlasClient.java
client/src/main/java/org/apache/atlas/AtlasClient.java
+35
-13
AtlasEntitiesClientV2.java
...src/main/java/org/apache/atlas/AtlasEntitiesClientV2.java
+1
-1
AtlasTypedefClientV2.java
.../src/main/java/org/apache/atlas/AtlasTypedefClientV2.java
+1
-1
release-log.txt
release-log.txt
+1
-0
EntityNotificationIT.java
...a/org/apache/atlas/notification/EntityNotificationIT.java
+3
-26
AdminJerseyResourceIT.java
...org/apache/atlas/web/resources/AdminJerseyResourceIT.java
+3
-16
BaseResourceIT.java
...t/java/org/apache/atlas/web/resources/BaseResourceIT.java
+1
-14
DataSetLineageJerseyResourceIT.java
...e/atlas/web/resources/DataSetLineageJerseyResourceIT.java
+14
-47
EntityJerseyResourceIT.java
...rg/apache/atlas/web/resources/EntityJerseyResourceIT.java
+0
-0
EntityLineageJerseyResourceIT.java
...he/atlas/web/resources/EntityLineageJerseyResourceIT.java
+27
-32
MetadataDiscoveryJerseyResourceIT.java
...tlas/web/resources/MetadataDiscoveryJerseyResourceIT.java
+36
-55
TypesJerseyResourceIT.java
...org/apache/atlas/web/resources/TypesJerseyResourceIT.java
+15
-47
No files found.
client/src/main/java/org/apache/atlas/AtlasBaseClient.java
View file @
2c881a46
...
...
@@ -224,8 +224,8 @@ public abstract class AtlasBaseClient {
String
activeServerAddress
=
null
;
for
(
int
i
=
0
;
i
<
getNumberOfRetries
();
i
++)
{
try
{
WebResource
service
=
client
.
resource
(
UriBuilder
.
fromUri
(
serverInstance
).
build
());
String
adminStatus
=
getAdminStatus
(
service
);
service
=
client
.
resource
(
UriBuilder
.
fromUri
(
serverInstance
).
build
());
String
adminStatus
=
getAdminStatus
();
if
(
StringUtils
.
equals
(
adminStatus
,
"ACTIVE"
))
{
activeServerAddress
=
serverInstance
;
break
;
...
...
@@ -315,11 +315,7 @@ public abstract class AtlasBaseClient {
private
WebResource
getResource
(
WebResource
service
,
String
path
,
String
...
pathParams
)
{
WebResource
resource
=
service
.
path
(
path
);
if
(
pathParams
!=
null
)
{
for
(
String
pathParam
:
pathParams
)
{
resource
=
resource
.
path
(
pathParam
);
}
}
resource
=
appendPathParams
(
resource
,
pathParams
);
return
resource
;
}
...
...
@@ -347,10 +343,6 @@ public abstract class AtlasBaseClient {
* @throws AtlasServiceException if there is a HTTP error.
*/
public
String
getAdminStatus
()
throws
AtlasServiceException
{
return
getAdminStatus
(
service
);
}
private
String
getAdminStatus
(
WebResource
service
)
throws
AtlasServiceException
{
String
result
=
AtlasBaseClient
.
UNKNOWN_STATUS
;
WebResource
resource
=
getResource
(
service
,
STATUS
.
getPath
());
JSONObject
response
=
callAPIWithResource
(
STATUS
,
resource
,
null
,
JSONObject
.
class
);
...
...
@@ -380,14 +372,6 @@ public abstract class AtlasBaseClient {
throw
che
;
}
public
boolean
isRetryEnabled
()
{
return
retryEnabled
;
}
public
void
setRetryEnabled
(
boolean
retryEnabled
)
{
this
.
retryEnabled
=
retryEnabled
;
}
@VisibleForTesting
JSONObject
callAPIWithRetries
(
APIInfo
api
,
Object
requestObject
,
ResourceCreator
resourceCreator
)
throws
AtlasServiceException
{
...
...
@@ -395,7 +379,7 @@ public abstract class AtlasBaseClient {
WebResource
resource
=
resourceCreator
.
createResource
();
try
{
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
;
}
catch
(
ClientHandlerException
che
)
{
if
(
i
==
(
getNumberOfRetries
()
-
1
))
{
...
...
@@ -409,24 +393,15 @@ public abstract class AtlasBaseClient {
throw
new
AtlasServiceException
(
api
,
new
RuntimeException
(
"Could not get response after retries."
));
}
protected
JSONObject
callAPIWithResource
(
APIInfo
api
,
WebResource
resource
,
Object
requestObject
)
throws
AtlasServiceException
{
return
callAPIWithResource
(
api
,
resource
,
requestObject
,
JSONObject
.
class
);
}
protected
JSONObject
callAPI
(
final
APIInfo
api
,
Object
requestObject
,
final
String
...
pathParams
)
public
<
T
>
T
callAPI
(
APIInfo
api
,
Object
requestObject
,
Class
<
T
>
responseType
,
String
...
params
)
throws
AtlasServiceException
{
return
callAPIWithRetries
(
api
,
requestObject
,
new
ResourceCreator
()
{
@Override
public
WebResource
createResource
()
{
return
getResource
(
api
,
pathParams
);
}
});
return
callAPIWithResource
(
api
,
getResource
(
api
,
params
),
requestObject
,
responseType
);
}
p
rotected
<
T
>
T
callAPI
(
APIInfo
api
,
Object
requestObject
,
Class
<
T
>
responseType
,
String
...
params
)
p
ublic
<
T
>
T
callAPI
(
APIInfo
api
,
Class
<
T
>
responseType
,
Map
<
String
,
String
>
queryParams
,
String
...
params
)
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
)
{
...
...
@@ -436,6 +411,23 @@ public abstract class AtlasBaseClient {
// Modify URL to include the path params
private
WebResource
getResource
(
WebResource
service
,
APIInfo
api
,
String
...
pathParams
)
{
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
)
{
for
(
String
pathParam
:
pathParams
)
{
resource
=
resource
.
path
(
pathParam
);
...
...
@@ -444,11 +436,6 @@ public abstract class AtlasBaseClient {
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
)
{
return
getResource
(
service
,
api
,
queryParams
);
}
...
...
@@ -456,6 +443,11 @@ public abstract class AtlasBaseClient {
// Modify URL to include the query params
private
WebResource
getResource
(
WebResource
service
,
APIInfo
api
,
Map
<
String
,
String
>
queryParams
)
{
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
())
{
for
(
Map
.
Entry
<
String
,
String
>
entry
:
queryParams
.
entrySet
())
{
resource
=
resource
.
queryParam
(
entry
.
getKey
(),
entry
.
getValue
());
...
...
@@ -484,7 +476,7 @@ public abstract class AtlasBaseClient {
private
final
String
path
;
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
.
method
=
method
;
this
.
status
=
status
;
...
...
client/src/main/java/org/apache/atlas/AtlasClient.java
View file @
2c881a46
...
...
@@ -20,9 +20,7 @@ package org.apache.atlas;
import
com.google.common.annotations.VisibleForTesting
;
import
com.google.common.collect.ImmutableSet
;
import
com.sun.jersey.api.client.WebResource
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.typesystem.Referenceable
;
import
org.apache.atlas.typesystem.Struct
;
...
...
@@ -43,6 +41,8 @@ import org.codehaus.jettison.json.JSONObject;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.ws.rs.HttpMethod
;
import
javax.ws.rs.core.Response
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
...
...
@@ -50,9 +50,6 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
javax.ws.rs.HttpMethod
;
import
javax.ws.rs.core.Response
;
/**
* Client for metadata.
*/
...
...
@@ -208,6 +205,8 @@ public class AtlasClient extends AtlasBaseClient {
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
),
GREMLIN_SEARCH
(
BASE_URI
+
URI_SEARCH
+
"/gremlin"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
),
//Lineage operations based on dataset name
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
),
...
...
@@ -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
* Updates properties set in the definition for the entity corresponding to guid
* @param entityType Type of the entity being updated
...
...
@@ -644,7 +653,7 @@ public class AtlasClient extends AtlasBaseClient {
resource
=
resource
.
queryParam
(
TYPE
,
entityType
);
resource
=
resource
.
queryParam
(
ATTRIBUTE_NAME
,
uniqueAttributeName
);
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
);
LOG
.
debug
(
"Delete entities returned results: {}"
,
results
);
return
results
;
...
...
@@ -814,7 +823,7 @@ public class AtlasClient extends AtlasBaseClient {
}
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
>()
{
@Override
EntityAuditEvent
extractElement
(
JSONObject
element
)
throws
JSONException
{
...
...
@@ -945,19 +954,32 @@ public class AtlasClient extends AtlasBaseClient {
}
// Wrapper methods for compatibility
JSONObject
callAPIWithResource
(
API
api
,
WebResource
resource
,
Object
requestObject
)
throws
AtlasServiceException
{
return
callAPIWithResource
(
toAPIInfo
(
api
),
resource
,
requestObject
);
@VisibleForTesting
public
JSONObject
callAPIWithResource
(
API
api
,
WebResource
resource
)
throws
AtlasServiceException
{
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
);
}
JSONObject
callAPI
(
API
api
,
Object
requestObject
,
String
...
params
)
throws
AtlasServiceException
{
return
callAPI
(
toAPIInfo
(
api
),
requestObject
,
params
);
@VisibleForTesting
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
{
return
super
.
callAPIWithRetries
(
toAPIInfo
(
api
),
requestObject
,
resourceCreator
);
}
...
...
client/src/main/java/org/apache/atlas/AtlasEntitiesClientV2.java
View file @
2c881a46
...
...
@@ -131,6 +131,6 @@ public class AtlasEntitiesClientV2 extends AtlasBaseClient {
}
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
());
}
}
client/src/main/java/org/apache/atlas/AtlasTypedefClientV2.java
View file @
2c881a46
...
...
@@ -73,7 +73,7 @@ public class AtlasTypedefClientV2 extends AtlasBaseClient {
* @return A composite wrapper object with lists of all type definitions
*/
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
{
...
...
release-log.txt
View file @
2c881a46
...
...
@@ -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)
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-1351 HiveHook fails with NPE for hive process registration (vimalsharma via sumasai)
ATLAS-1342 Titan Solrclient - Add timeouts for zookeeper connect and session (sumasai)
...
...
webapp/src/test/java/org/apache/atlas/notification/EntityNotificationIT.java
View file @
2c881a46
...
...
@@ -20,8 +20,6 @@ package org.apache.atlas.notification;
import
com.google.common.collect.ImmutableSet
;
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.notification.entity.EntityNotification
;
import
org.apache.atlas.typesystem.IReferenceableInstance
;
...
...
@@ -35,14 +33,10 @@ import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
import
org.apache.atlas.typesystem.types.TraitType
;
import
org.apache.atlas.typesystem.types.utils.TypesUtil
;
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.Guice
;
import
org.testng.annotations.Test
;
import
javax.ws.rs.HttpMethod
;
import
javax.ws.rs.core.Response
;
import
java.util.Collections
;
import
java.util.LinkedList
;
import
java.util.List
;
...
...
@@ -144,8 +138,7 @@ public class EntityNotificationIT extends BaseResourceIT {
final
String
guid
=
tableId
.
_getId
();
ClientResponse
clientResponse
=
addTrait
(
guid
,
traitInstanceJSON
);
assertEquals
(
clientResponse
.
getStatus
(),
Response
.
Status
.
CREATED
.
getStatusCode
());
serviceClient
.
addTrait
(
guid
,
traitInstance
);
EntityNotification
entityNotification
=
waitForNotification
(
notificationConsumer
,
MAX_WAIT_TIME
,
newNotificationPredicate
(
EntityNotification
.
OperationType
.
TRAIT_ADD
,
HIVE_TABLE_TYPE
,
guid
));
...
...
@@ -170,8 +163,7 @@ public class EntityNotificationIT extends BaseResourceIT {
traitInstanceJSON
=
InstanceSerialization
.
toJson
(
traitInstance
,
true
);
LOG
.
debug
(
"Trait instance = "
+
traitInstanceJSON
);
clientResponse
=
addTrait
(
guid
,
traitInstanceJSON
);
assertEquals
(
clientResponse
.
getStatus
(),
Response
.
Status
.
CREATED
.
getStatusCode
());
serviceClient
.
addTrait
(
guid
,
traitInstance
);
entityNotification
=
waitForNotification
(
notificationConsumer
,
MAX_WAIT_TIME
,
newNotificationPredicate
(
EntityNotification
.
OperationType
.
TRAIT_ADD
,
HIVE_TABLE_TYPE
,
guid
));
...
...
@@ -192,8 +184,7 @@ public class EntityNotificationIT extends BaseResourceIT {
public
void
testDeleteTrait
()
throws
Exception
{
final
String
guid
=
tableId
.
_getId
();
ClientResponse
clientResponse
=
deleteTrait
(
guid
,
traitName
);
Assert
.
assertEquals
(
clientResponse
.
getStatus
(),
Response
.
Status
.
OK
.
getStatusCode
());
serviceClient
.
deleteTrait
(
guid
,
traitName
);
EntityNotification
entityNotification
=
waitForNotification
(
notificationConsumer
,
MAX_WAIT_TIME
,
newNotificationPredicate
(
EntityNotification
.
OperationType
.
TRAIT_DELETE
,
HIVE_TABLE_TYPE
,
guid
));
...
...
@@ -213,18 +204,4 @@ public class EntityNotificationIT extends BaseResourceIT {
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
);
}
}
webapp/src/test/java/org/apache/atlas/web/resources/AdminJerseyResourceIT.java
View file @
2c881a46
...
...
@@ -18,18 +18,13 @@
package
org
.
apache
.
atlas
.
web
.
resources
;
import
com.sun.jersey.api.client.ClientResponse
;
import
com.sun.jersey.api.client.WebResource
;
import
org.apache.atlas.web.util.Servlets
;
import
org.apache.atlas.AtlasClient
;
import
org.apache.commons.configuration.PropertiesConfiguration
;
import
org.codehaus.jettison.json.JSONObject
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.Test
;
import
javax.ws.rs.HttpMethod
;
import
javax.ws.rs.core.Response
;
/**
* Integration test for Admin jersey resource.
*/
...
...
@@ -42,19 +37,11 @@ public class AdminJerseyResourceIT extends BaseResourceIT {
@Test
public
void
testGetVersion
()
throws
Exception
{
WebResource
resource
=
service
.
path
(
"api/atlas/admin/version"
);
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
);
JSONObject
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
VERSION
,
null
,
(
String
[])
null
);
Assert
.
assertNotNull
(
response
);
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
(
"Name"
),
buildConfiguration
.
getString
(
"project.name"
));
Assert
.
assertEquals
(
response
.
get
(
"Description"
),
buildConfiguration
.
getString
(
"project.description"
));
...
...
webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java
View file @
2c881a46
...
...
@@ -21,7 +21,6 @@ package org.apache.atlas.web.resources;
import
com.google.common.base.Preconditions
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableSet
;
import
com.sun.jersey.api.client.WebResource
;
import
kafka.consumer.ConsumerTimeoutException
;
import
org.apache.atlas.ApplicationProperties
;
import
org.apache.atlas.AtlasClient
;
...
...
@@ -34,17 +33,7 @@ import org.apache.atlas.typesystem.TypesDef;
import
org.apache.atlas.typesystem.json.InstanceSerialization
;
import
org.apache.atlas.typesystem.json.TypesSerialization
;
import
org.apache.atlas.typesystem.persistence.Id
;
import
org.apache.atlas.typesystem.types.AttributeDefinition
;
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.*
;
import
org.apache.atlas.typesystem.types.utils.TypesUtil
;
import
org.apache.atlas.utils.AuthenticationUtil
;
import
org.apache.atlas.utils.ParamChecker
;
...
...
@@ -68,7 +57,6 @@ import java.util.Map;
public
abstract
class
BaseResourceIT
{
public
static
final
String
ATLAS_REST_ADDRESS
=
"atlas.rest.address"
;
protected
WebResource
service
;
protected
AtlasClient
serviceClient
;
public
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
BaseResourceIT
.
class
);
protected
static
final
int
MAX_WAIT_TIME
=
60000
;
...
...
@@ -89,7 +77,6 @@ public abstract class BaseResourceIT {
}
else
{
serviceClient
=
new
AtlasClient
(
atlasUrls
);
}
service
=
serviceClient
.
getResource
();
}
protected
void
createType
(
TypesDef
typesDef
)
throws
Exception
{
...
...
webapp/src/test/java/org/apache/atlas/web/resources/DataSetLineageJerseyResourceIT.java
View file @
2c881a46
...
...
@@ -19,14 +19,12 @@
package
org
.
apache
.
atlas
.
web
.
resources
;
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.AtlasServiceException
;
import
org.apache.atlas.typesystem.Referenceable
;
import
org.apache.atlas.typesystem.Struct
;
import
org.apache.atlas.typesystem.json.InstanceSerialization
;
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.JSONObject
;
import
org.testng.Assert
;
...
...
@@ -37,8 +35,6 @@ import org.apache.atlas.typesystem.types.TraitType;
import
org.apache.atlas.typesystem.types.utils.TypesUtil
;
import
com.google.common.collect.ImmutableSet
;
import
javax.ws.rs.HttpMethod
;
import
javax.ws.rs.core.Response
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -49,7 +45,6 @@ import static org.testng.Assert.assertEquals;
*/
public
class
DataSetLineageJerseyResourceIT
extends
BaseResourceIT
{
private
static
final
String
BASE_URI
=
"api/atlas/lineage/hive/table/"
;
private
String
salesFactTable
;
private
String
salesMonthlyTable
;
private
String
salesDBName
;
...
...
@@ -64,17 +59,10 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test
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
));
JSONObject
results
=
response
.
getJSONObject
(
AtlasClient
.
RESULTS
);
...
...
@@ -107,17 +95,10 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test
public
void
testOutputsGraph
()
throws
Exception
{
WebResource
resource
=
service
.
path
(
BASE_URI
).
path
(
salesFactTable
).
path
(
"outputs"
).
path
(
"graph"
);
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
());
JSONObject
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
NAME_LINEAGE_OUTPUTS_GRAPH
,
null
,
salesFactTable
,
"outputs"
,
"graph"
);
Assert
.
assertNotNull
(
response
);
System
.
out
.
println
(
"outputs graph= "
+
response
);
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
));
JSONObject
results
=
response
.
getJSONObject
(
AtlasClient
.
RESULTS
);
...
...
@@ -150,17 +131,11 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test
public
void
testSchema
()
throws
Exception
{
WebResource
resource
=
service
.
path
(
BASE_URI
).
path
(
salesFactTable
).
path
(
"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
());
JSONObject
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
NAME_LINEAGE_SCHEMA
,
null
,
salesFactTable
,
"schema"
);
String
responseAsString
=
clientResponse
.
getEntity
(
String
.
class
);
Assert
.
assertNotNull
(
responseAsString
);
System
.
out
.
println
(
"schema = "
+
responseAsString
);
Assert
.
assertNotNull
(
response
);
System
.
out
.
println
(
"schema = "
+
response
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertNotNull
(
response
.
get
(
AtlasClient
.
REQUEST_ID
));
JSONObject
results
=
response
.
getJSONObject
(
AtlasClient
.
RESULTS
);
...
...
@@ -198,22 +173,14 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
}
}
@Test
@Test
(
expectedExceptions
=
AtlasServiceException
.
class
)
public
void
testSchemaForInvalidTable
()
throws
Exception
{
WebResource
resource
=
service
.
path
(
BASE_URI
).
path
(
"blah"
).
path
(
"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
());
JSONObject
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
NAME_LINEAGE_SCHEMA
,
null
,
"blah"
,
"schema"
);
}
@Test
@Test
(
expectedExceptions
=
AtlasServiceException
.
class
)
public
void
testSchemaForDB
()
throws
Exception
{
WebResource
resource
=
service
.
path
(
BASE_URI
).
path
(
salesDBName
).
path
(
"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
());
JSONObject
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
NAME_LINEAGE_SCHEMA
,
null
,
salesDBName
,
"schema"
);
}
private
void
setupInstances
()
throws
Exception
{
...
...
webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java
View file @
2c881a46
This diff is collapsed.
Click to expand it.
webapp/src/test/java/org/apache/atlas/web/resources/EntityLineageJerseyResourceIT.java
View file @
2c881a46
...
...
@@ -20,29 +20,30 @@ package org.apache.atlas.web.resources;
import
com.google.common.collect.ImmutableList
;
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.model.instance.AtlasEntityHeader
;
import
org.apache.atlas.model.lineage.AtlasLineageInfo
;
import
org.apache.atlas.typesystem.Referenceable
;
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.annotations.BeforeClass
;
import
org.testng.annotations.Test
;
import
javax.ws.rs.HttpMethod
;
import
javax.ws.rs.core.Response
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
static
org
.
apache
.
atlas
.
AtlasBaseClient
.
APIInfo
;
/**
* Entity Lineage v2 Integration Tests.
*/
public
class
EntityLineageJerseyResourceIT
extends
DataSetLineageJerseyResourceIT
{
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
OUTPUT_DIRECTION
=
"OUTPUT"
;
private
static
final
String
BOTH_DIRECTION
=
"BOTH"
;
...
...
@@ -66,18 +67,16 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
public
void
testInputLineageInfo
()
throws
Exception
{
String
tableId
=
serviceClient
.
getEntity
(
HIVE_TABLE_TYPE
,
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
);
Assert
.
assertNotNull
(
responseAsString
);
System
.
out
.
println
(
"input lineage info = "
+
responseAsString
);
Map
<
String
,
String
>
queryParams
=
new
HashMap
<>();
queryParams
.
put
(
DIRECTION_PARAM
,
INPUT_DIRECTION
);
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
(
response
AsString
,
AtlasLineageInfo
.
class
);
AtlasLineageInfo
inputLineageInfo
=
gson
.
fromJson
(
response
.
toString
()
,
AtlasLineageInfo
.
class
);
Map
<
String
,
AtlasEntityHeader
>
entities
=
inputLineageInfo
.
getGuidEntityMap
();
Assert
.
assertNotNull
(
entities
);
...
...
@@ -96,18 +95,16 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
public
void
testOutputLineageInfo
()
throws
Exception
{
String
tableId
=
serviceClient
.
getEntity
(
HIVE_TABLE_TYPE
,
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
)
.
method
(
HttpMethod
.
GET
,
ClientResponse
.
class
);
Assert
.
assertEquals
(
clientResponse
.
getStatus
(),
Response
.
Status
.
OK
.
getStatusCode
());
Map
<
String
,
String
>
queryParams
=
new
HashMap
<>();
queryParams
.
put
(
DIRECTION_PARAM
,
OUTPUT_DIRECTION
);
queryParams
.
put
(
DEPTH_PARAM
,
"5"
);
JSONObject
response
=
serviceClient
.
callAPI
(
LINEAGE_V2_API
,
JSONObject
.
class
,
queryParams
);
String
responseAsString
=
clientResponse
.
getEntity
(
String
.
class
);
Assert
.
assertNotNull
(
responseAsString
);
System
.
out
.
println
(
"output lineage info = "
+
responseAsString
);
Assert
.
assertNotNull
(
response
);
System
.
out
.
println
(
"output lineage info = "
+
response
);
AtlasLineageInfo
outputLineageInfo
=
gson
.
fromJson
(
response
AsString
,
AtlasLineageInfo
.
class
);
AtlasLineageInfo
outputLineageInfo
=
gson
.
fromJson
(
response
.
toString
()
,
AtlasLineageInfo
.
class
);
Map
<
String
,
AtlasEntityHeader
>
entities
=
outputLineageInfo
.
getGuidEntityMap
();
Assert
.
assertNotNull
(
entities
);
...
...
@@ -126,18 +123,16 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
public
void
testLineageInfo
()
throws
Exception
{
String
tableId
=
serviceClient
.
getEntity
(
HIVE_TABLE_TYPE
,
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
)
.
method
(
HttpMethod
.
GET
,
ClientResponse
.
class
);
Assert
.
assertEquals
(
clientResponse
.
getStatus
(),
Response
.
Status
.
OK
.
getStatusCode
());
Map
<
String
,
String
>
queryParams
=
new
HashMap
<>();
queryParams
.
put
(
DIRECTION_PARAM
,
BOTH_DIRECTION
);
queryParams
.
put
(
DEPTH_PARAM
,
"5"
);
JSONObject
response
=
serviceClient
.
callAPI
(
LINEAGE_V2_API
,
JSONObject
.
class
,
queryParams
);
String
responseAsString
=
clientResponse
.
getEntity
(
String
.
class
);
Assert
.
assertNotNull
(
responseAsString
);
System
.
out
.
println
(
"both lineage info = "
+
responseAsString
);
Assert
.
assertNotNull
(
response
);
System
.
out
.
println
(
"both lineage info = "
+
response
);
AtlasLineageInfo
bothLineageInfo
=
gson
.
fromJson
(
response
AsString
,
AtlasLineageInfo
.
class
);
AtlasLineageInfo
bothLineageInfo
=
gson
.
fromJson
(
response
.
toString
()
,
AtlasLineageInfo
.
class
);
Map
<
String
,
AtlasEntityHeader
>
entities
=
bothLineageInfo
.
getGuidEntityMap
();
Assert
.
assertNotNull
(
entities
);
...
...
webapp/src/test/java/org/apache/atlas/web/resources/MetadataDiscoveryJerseyResourceIT.java
View file @
2c881a46
...
...
@@ -21,8 +21,7 @@ package org.apache.atlas.web.resources;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableSet
;
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.AtlasServiceException
;
import
org.apache.atlas.typesystem.Referenceable
;
...
...
@@ -36,19 +35,19 @@ import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
import
org.apache.atlas.typesystem.types.StructTypeDefinition
;
import
org.apache.atlas.typesystem.types.TraitType
;
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.JSONObject
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.Test
;
import
javax.ws.rs.HttpMethod
;
import
javax.ws.rs.core.Response
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertNotNull
;
import
static
org
.
testng
.
Assert
.
fail
;
/**
...
...
@@ -56,6 +55,10 @@ import static org.testng.Assert.fail;
*/
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
dbName
;
...
...
@@ -70,16 +73,11 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
@Test
public
void
testSearchByDSL
()
throws
Exception
{
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
)
.
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
));
assertEquals
(
response
.
getString
(
"query"
),
dslQuery
);
...
...
@@ -98,11 +96,10 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
//search without new parameters of limit and offset should work
String
dslQuery
=
"from "
+
DATABASE_TYPE
+
" qualifiedName=\""
+
dbName
+
"\""
;
WebResource
resource
=
service
.
path
(
"api/atlas/discovery/search/dsl"
).
queryParam
(
"query"
,
dslQuery
);
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
());
Map
<
String
,
String
>
queryParams
=
new
HashMap
<>();
queryParams
.
put
(
"query"
,
dslQuery
);
JSONObject
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
SEARCH_DSL
,
queryParams
);
assertNotNull
(
response
);
//higher limit, all results returned
JSONArray
results
=
serviceClient
.
searchByDSL
(
dslQuery
,
10
,
0
);
...
...
@@ -145,29 +142,24 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
}
}
@Test
@Test
(
expectedExceptions
=
AtlasServiceException
.
class
)
public
void
testSearchByDSLForUnknownType
()
throws
Exception
{
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
public
void
testSearchUsingGremlin
()
throws
Exception
{
String
query
=
"g.V.has('type', 'hive_db').toList()"
;
WebResource
resource
=
service
.
path
(
"api/atlas/discovery/search/gremlin"
).
queryParam
(
"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
());
Map
<
String
,
String
>
queryParams
=
new
HashMap
<>();
queryParams
.
put
(
"query"
,
query
);
String
responseAsString
=
clientResponse
.
getEntity
(
String
.
class
);
Assert
.
assertNotNull
(
responseAsString
);
JSONObject
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
GREMLIN_SEARCH
,
queryParams
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
assertNotNull
(
response
);
Assert
.
assertNotNull
(
response
.
get
(
AtlasClient
.
REQUEST_ID
));
assertEquals
(
response
.
getString
(
"query"
),
query
);
...
...
@@ -178,16 +170,11 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
public
void
testSearchUsingDSL
()
throws
Exception
{
//String query = "from dsl_test_type";
String
query
=
"from "
+
DATABASE_TYPE
+
" qualifiedName=\""
+
dbName
+
"\""
;
WebResource
resource
=
service
.
path
(
"api/atlas/discovery/search"
).
queryParam
(
"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
());
Map
<
String
,
String
>
queryParams
=
new
HashMap
<>();
queryParams
.
put
(
"query"
,
query
);
JSONObject
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
SEARCH_DSL
,
queryParams
);
String
responseAsString
=
clientResponse
.
getEntity
(
String
.
class
);
Assert
.
assertNotNull
(
responseAsString
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertNotNull
(
response
);
Assert
.
assertNotNull
(
response
.
get
(
AtlasClient
.
REQUEST_ID
));
assertEquals
(
response
.
getString
(
"query"
),
query
);
...
...
@@ -197,16 +184,11 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
@Test
public
void
testSearchFullTextOnDSLFailure
()
throws
Exception
{
String
query
=
"*"
;
WebResource
resource
=
service
.
path
(
"api/atlas/discovery/search"
).
queryParam
(
"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
);
Assert
.
assertNotNull
(
responseAsString
);
Map
<
String
,
String
>
queryParams
=
new
HashMap
<>();
queryParams
.
put
(
"query"
,
query
);
JSONObject
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
SEARCH_DSL
,
queryParams
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertNotNull
(
response
);
Assert
.
assertNotNull
(
response
.
get
(
AtlasClient
.
REQUEST_ID
));
assertEquals
(
response
.
getString
(
"query"
),
query
);
...
...
@@ -234,11 +216,10 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
//API works without limit and offset
String
query
=
dbName
;
WebResource
resource
=
service
.
path
(
"api/atlas/discovery/search/fulltext"
).
queryParam
(
"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
());
results
=
new
JSONObject
(
clientResponse
.
getEntity
(
String
.
class
)).
getJSONArray
(
AtlasClient
.
RESULTS
);
Map
<
String
,
String
>
queryParams
=
new
HashMap
<>();
queryParams
.
put
(
"query"
,
query
);
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
SEARCH_FULL_TEXT
,
queryParams
);
results
=
response
.
getJSONArray
(
AtlasClient
.
RESULTS
);
assertEquals
(
results
.
length
(),
1
);
//verify passed in limits and offsets are used
...
...
webapp/src/test/java/org/apache/atlas/web/resources/TypesJerseyResourceIT.java
View file @
2c881a46
...
...
@@ -20,9 +20,6 @@ package org.apache.atlas.web.resources;
import
com.google.common.collect.ImmutableList
;
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.AtlasServiceException
;
import
org.apache.atlas.typesystem.TypesDef
;
...
...
@@ -37,7 +34,6 @@ 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.utils.TypesUtil
;
import
org.apache.atlas.web.util.Servlets
;
import
org.codehaus.jettison.json.JSONArray
;
import
org.codehaus.jettison.json.JSONObject
;
import
org.testng.Assert
;
...
...
@@ -45,11 +41,12 @@ import org.testng.annotations.AfterClass;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.Test
;
import
javax.ws.rs.HttpMethod
;
import
javax.ws.rs.core.Response
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
static
org
.
apache
.
atlas
.
typesystem
.
types
.
utils
.
TypesUtil
.
createOptionalAttrDef
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
...
...
@@ -84,21 +81,14 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
String
typesAsJSON
=
TypesSerialization
.
toJson
(
typeDefinition
,
false
);
System
.
out
.
println
(
"typesAsJSON = "
+
typesAsJSON
);
WebResource
resource
=
service
.
path
(
"api/atlas/types"
);
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
());
JSONObject
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
CREATE_TYPE
,
typesAsJSON
);
Assert
.
assertNotNull
(
response
);
String
responseAsString
=
clientResponse
.
getEntity
(
String
.
class
);
Assert
.
assertNotNull
(
responseAsString
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
JSONArray
typesAdded
=
response
.
getJSONArray
(
AtlasClient
.
TYPES
);
assertEquals
(
typesAdded
.
length
(),
1
);
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 {
for
(
HierarchicalTypeDefinition
typeDefinition
:
typeDefinitions
)
{
System
.
out
.
println
(
"typeName = "
+
typeDefinition
.
typeName
);
WebResource
resource
=
service
.
path
(
"api/atlas/types"
).
path
(
typeDefinition
.
typeName
);
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
());
JSONObject
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
LIST_TYPES
,
null
,
typeDefinition
.
typeName
);
String
responseAsString
=
clientResponse
.
getEntity
(
String
.
class
);
Assert
.
assertNotNull
(
responseAsString
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertNotNull
(
response
);
Assert
.
assertNotNull
(
response
.
get
(
AtlasClient
.
DEFINITION
));
Assert
.
assertNotNull
(
response
.
get
(
AtlasClient
.
REQUEST_ID
));
...
...
@@ -178,27 +162,16 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
}
}
@Test
@Test
(
expectedExceptions
=
AtlasServiceException
.
class
)
public
void
testGetDefinitionForNonexistentType
()
throws
Exception
{
WebResource
resource
=
service
.
path
(
"api/atlas/types"
).
path
(
"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
());
JSONObject
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
LIST_TYPES
,
null
,
"blah"
);
}
@Test
(
dependsOnMethods
=
"testSubmit"
)
public
void
testGetTypeNames
()
throws
Exception
{
WebResource
resource
=
service
.
path
(
"api/atlas/types"
);
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
());
JSONObject
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
LIST_TYPES
,
null
,
(
String
[])
null
);
Assert
.
assertNotNull
(
response
);
String
responseAsString
=
clientResponse
.
getEntity
(
String
.
class
);
Assert
.
assertNotNull
(
responseAsString
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertNotNull
(
response
.
get
(
AtlasClient
.
REQUEST_ID
));
final
JSONArray
list
=
response
.
getJSONArray
(
AtlasClient
.
RESULTS
);
...
...
@@ -214,17 +187,12 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
public
void
testGetTraitNames
()
throws
Exception
{
String
[]
traitsAdded
=
addTraits
();
WebResource
resource
=
service
.
path
(
"api/atlas/types"
);
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
());
Map
<
String
,
String
>
queryParams
=
new
HashMap
<>();
queryParams
.
put
(
"type"
,
DataTypes
.
TypeCategory
.
TRAIT
.
name
());
String
responseAsString
=
clientResponse
.
getEntity
(
String
.
clas
s
);
Assert
.
assertNotNull
(
response
AsString
);
JSONObject
response
=
serviceClient
.
callAPI
(
AtlasClient
.
API
.
LIST_TYPES
,
queryParam
s
);
Assert
.
assertNotNull
(
response
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertNotNull
(
response
.
get
(
AtlasClient
.
REQUEST_ID
));
final
JSONArray
list
=
response
.
getJSONArray
(
AtlasClient
.
RESULTS
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment