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
52336574
Commit
52336574
authored
9 years ago
by
arpitgupta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial code to start writing tests
parent
0438f50d
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
503 additions
and
0 deletions
+503
-0
pom.xml
regression/pom.xml
+96
-0
BaseRequest.java
...java/org/apache/atlas/regression/request/BaseRequest.java
+192
-0
RequestKeys.java
...java/org/apache/atlas/regression/request/RequestKeys.java
+35
-0
AdminResourceTest.java
.../org/apache/atlas/regression/tests/AdminResourceTest.java
+56
-0
BaseTest.java
...test/java/org/apache/atlas/regression/tests/BaseTest.java
+24
-0
TestNGListener.java
...java/org/apache/atlas/regression/util/TestNGListener.java
+77
-0
log4j.properties
regression/src/test/resources/log4j.properties
+23
-0
No files found.
regression/pom.xml
0 → 100644
View file @
52336574
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
atlas-regression
</artifactId>
<groupId>
org.apache.hadoop.metadata
</groupId>
<version>
0.1-incubating-SNAPSHOT
</version>
<description>
Regression Framework for Atlas
</description>
<name>
atlas-regression
</name>
<properties>
<atlas.url>
http://localhost:21000
</atlas.url>
<surefire.version>
2.18.1
</surefire.version>
<testng.groups>
admin
</testng.groups>
<testng.exclude.groups></testng.exclude.groups>
</properties>
<dependencies>
<dependency>
<groupId>
org.testng
</groupId>
<artifactId>
testng
</artifactId>
<version>
6.9.4
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-exec
</artifactId>
<version>
1.3
</version>
</dependency>
<dependency>
<groupId>
com.jayway.jsonpath
</groupId>
<artifactId>
json-path
</artifactId>
<version>
2.0.0
</version>
</dependency>
<dependency>
<groupId>
log4j
</groupId>
<artifactId>
log4j
</artifactId>
<version>
1.2.17
</version>
</dependency>
<dependency>
<groupId>
commons-lang
</groupId>
<artifactId>
commons-lang
</artifactId>
<version>
2.6
</version>
</dependency>
<dependency>
<groupId>
commons-net
</groupId>
<artifactId>
commons-net
</artifactId>
<version>
3.2
</version>
</dependency>
<dependency>
<groupId>
org.apache.hadoop
</groupId>
<artifactId>
hadoop-auth
</artifactId>
<version>
2.6.0
</version>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpcore
</artifactId>
<version>
4.2.5
</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<version>
${surefire.version}
</version>
<configuration>
<failIfNoTests>
true
</failIfNoTests>
<redirectTestOutputToFile>
true
</redirectTestOutputToFile>
<groups>
${testng.groups}
</groups>
<excludedGroups>
${testng.exclude.groups}
</excludedGroups>
<properties>
<property>
<name>
listener
</name>
<value>
org.apache.atlas.regression.util.TestNGListener
</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-report-plugin
</artifactId>
<version>
${surefire.version}
</version>
</plugin>
</plugins>
</reporting>
</project>
This diff is collapsed.
Click to expand it.
regression/src/test/java/org/apache/atlas/regression/request/BaseRequest.java
0 → 100644
View file @
52336574
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
regression
.
request
;
import
org.apache.commons.net.util.TrustManagerUtils
;
import
org.apache.hadoop.security.authentication.client.PseudoAuthenticator
;
import
org.apache.http.Header
;
import
org.apache.http.HttpEntityEnclosingRequest
;
import
org.apache.http.HttpHost
;
import
org.apache.http.HttpRequest
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.auth.AuthenticationException
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.methods.HttpDelete
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.client.methods.HttpPut
;
import
org.apache.http.client.utils.URIBuilder
;
import
org.apache.http.conn.scheme.Scheme
;
import
org.apache.http.conn.scheme.SchemeRegistry
;
import
org.apache.http.conn.ssl.AllowAllHostnameVerifier
;
import
org.apache.http.conn.ssl.SSLSocketFactory
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.DefaultHttpClient
;
import
org.apache.http.impl.conn.BasicClientConnectionManager
;
import
org.apache.http.message.BasicHeader
;
import
org.apache.log4j.Logger
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.TrustManager
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.security.SecureRandom
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
BaseRequest
{
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
BaseRequest
.
class
);
private
String
method
;
private
String
url
;
private
List
<
Header
>
headers
;
private
String
requestData
;
private
String
user
;
private
URI
uri
;
private
HttpHost
target
;
private
static
final
SSLSocketFactory
SSL_SOCKET_FACTORY
;
static
{
try
{
SSLContext
ssl
=
getSslContext
();
SSL_SOCKET_FACTORY
=
new
SSLSocketFactory
(
ssl
,
new
AllowAllHostnameVerifier
());
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
static
SSLContext
getSslContext
()
throws
Exception
{
SSLContext
sslContext
=
SSLContext
.
getInstance
(
"SSL"
);
sslContext
.
init
(
null
,
new
TrustManager
[]{
TrustManagerUtils
.
getValidateServerCertificateTrustManager
()},
new
SecureRandom
());
return
sslContext
;
}
public
BaseRequest
(
String
url
)
throws
URISyntaxException
{
this
(
url
,
"get"
,
null
,
null
);
}
public
BaseRequest
(
String
url
,
String
method
,
String
user
)
throws
URISyntaxException
{
this
(
url
,
method
,
user
,
null
);
}
public
BaseRequest
(
String
url
,
String
method
,
String
user
,
String
data
)
throws
URISyntaxException
{
this
.
method
=
method
;
this
.
url
=
url
;
this
.
requestData
=
null
;
this
.
user
=
(
null
==
user
)
?
RequestKeys
.
CURRENT_USER
:
user
;
this
.
uri
=
new
URI
(
url
);
target
=
new
HttpHost
(
uri
.
getHost
(),
uri
.
getPort
(),
uri
.
getScheme
());
this
.
headers
=
new
ArrayList
<
Header
>();
this
.
requestData
=
data
;
}
public
void
addHeader
(
String
name
,
String
value
)
{
headers
.
add
(
new
BasicHeader
(
name
,
value
));
}
public
HttpResponse
run
()
throws
URISyntaxException
,
IOException
,
AuthenticationException
,
InterruptedException
{
URIBuilder
uriBuilder
=
new
URIBuilder
(
this
.
url
);
/*falcon now reads a user.name parameter in the request.
by default we will add it to every request.*/
uriBuilder
.
addParameter
(
PseudoAuthenticator
.
USER_NAME
,
this
.
user
);
uri
=
uriBuilder
.
build
();
this
.
url
=
uri
.
toString
();
// process the get
if
(
this
.
method
.
equalsIgnoreCase
(
"get"
))
{
return
execute
(
new
HttpGet
(
this
.
url
));
}
else
if
(
this
.
method
.
equalsIgnoreCase
(
"delete"
))
{
return
execute
(
new
HttpDelete
(
this
.
url
));
}
HttpEntityEnclosingRequest
request
=
null
;
if
(
this
.
method
.
equalsIgnoreCase
(
"post"
))
{
request
=
new
HttpPost
(
new
URI
(
this
.
url
));
}
else
if
(
this
.
method
.
equalsIgnoreCase
(
"put"
))
{
request
=
new
HttpPut
(
new
URI
(
this
.
url
));
}
else
{
throw
new
IOException
(
"Unknown method: "
+
method
);
}
if
(
this
.
requestData
!=
null
)
{
request
.
setEntity
(
new
StringEntity
(
requestData
));
}
return
execute
(
request
);
}
private
HttpResponse
execute
(
HttpRequest
request
)
throws
IOException
,
AuthenticationException
,
InterruptedException
{
// add headers to the request
if
(
null
!=
headers
&&
headers
.
size
()
>
0
)
{
for
(
Header
header
:
headers
)
{
request
.
addHeader
(
header
);
}
}
HttpClient
client
;
if
(
uri
.
toString
().
startsWith
(
"https"
))
{
SchemeRegistry
schemeRegistry
=
new
SchemeRegistry
();
schemeRegistry
.
register
(
new
Scheme
(
"https"
,
uri
.
getPort
(),
SSL_SOCKET_FACTORY
));
BasicClientConnectionManager
cm
=
new
BasicClientConnectionManager
(
schemeRegistry
);
client
=
new
DefaultHttpClient
(
cm
);
}
else
{
client
=
new
DefaultHttpClient
();
}
LOGGER
.
info
(
"Request Url: "
+
request
.
getRequestLine
().
getUri
());
LOGGER
.
info
(
"Request Method: "
+
request
.
getRequestLine
().
getMethod
());
for
(
Header
header
:
request
.
getAllHeaders
())
{
LOGGER
.
info
(
String
.
format
(
"Request Header: Name=%s Value=%s"
,
header
.
getName
(),
header
.
getValue
()));
}
HttpResponse
response
=
client
.
execute
(
target
,
request
);
// TODO: Determine appropriate call for when running secure atlas.
// /*incase the cookie is expired and we get a negotiate error back, generate the token again
// and send the request*/
// if ((response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED)) {
// Header[] wwwAuthHeaders = response.getHeaders(RequestKeys.WWW_AUTHENTICATE);
// if (wwwAuthHeaders != null && wwwAuthHeaders.length != 0
// && wwwAuthHeaders[0].getValue().trim().startsWith(RequestKeys.NEGOTIATE)) {
// if (AbstractEntityHelper.AUTHENTICATE) {
// token = FalconAuthorizationToken.getToken(user, uri.getScheme(),
// uri.getHost(), uri.getPort(), true);
// request.removeHeaders(RequestKeys.COOKIE);
// request.addHeader(RequestKeys.COOKIE, RequestKeys.AUTH_COOKIE_EQ + token);
// }
// LOGGER.info("Request Url: " + request.getRequestLine().getUri());
// LOGGER.info("Request Method: " + request.getRequestLine().getMethod());
// for (Header header : request.getAllHeaders()) {
// LOGGER.info(String.format("Request Header: Name=%s Value=%s", header.getName(),
// header.getValue()));
// }
// response = client.execute(target, request);
// }
// }
LOGGER
.
info
(
"Response Status: "
+
response
.
getStatusLine
());
for
(
Header
header
:
response
.
getAllHeaders
())
{
LOGGER
.
info
(
String
.
format
(
"Response Header: Name=%s Value=%s"
,
header
.
getName
(),
header
.
getValue
()));
}
return
response
;
}
}
This diff is collapsed.
Click to expand it.
regression/src/test/java/org/apache/atlas/regression/request/RequestKeys.java
0 → 100644
View file @
52336574
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
regression
.
request
;
public
class
RequestKeys
{
private
RequestKeys
()
{
throw
new
AssertionError
(
"Instantiating utility class..."
);
}
public
static
final
String
CONTENT_TYPE_HEADER
=
"Content-Type"
;
public
static
final
String
JSON_CONTENT_TYPE
=
"application/json"
;
public
static
final
String
AUTH_COOKIE
=
"hadoop.auth"
;
public
static
final
String
AUTH_COOKIE_EQ
=
AUTH_COOKIE
+
"="
;
public
static
final
String
COOKIE
=
"Cookie"
;
public
static
final
String
WWW_AUTHENTICATE
=
"WWW-Authenticate"
;
public
static
final
String
NEGOTIATE
=
"Negotiate"
;
public
static
final
String
CURRENT_USER
=
System
.
getProperty
(
"user.name"
);
}
This diff is collapsed.
Click to expand it.
regression/src/test/java/org/apache/atlas/regression/tests/AdminResourceTest.java
0 → 100644
View file @
52336574
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
regression
.
tests
;
import
com.jayway.jsonpath.Configuration
;
import
com.jayway.jsonpath.JsonPath
;
import
org.apache.atlas.regression.request.BaseRequest
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.util.EntityUtils
;
import
org.apache.log4j.Logger
;
import
org.testng.annotations.Test
;
import
org.testng.asserts.SoftAssert
;
@Test
(
groups
=
"admin"
)
public
class
AdminResourceTest
extends
BaseTest
{
private
static
final
Logger
logger
=
Logger
.
getLogger
(
AdminResourceTest
.
class
);
private
static
String
baseReqUrl
=
ATLAS_URL
+
"/api/metadata/admin"
;
public
SoftAssert
softassert
=
new
SoftAssert
();
@Test
public
void
testVersion
()
throws
Exception
{
BaseRequest
req
=
new
BaseRequest
(
baseReqUrl
+
"/version"
);
HttpResponse
response
=
req
.
run
();
softassert
.
assertEquals
(
200
,
response
.
getStatusLine
().
getStatusCode
(),
"Status code "
+
"mismatch"
);
String
json
=
EntityUtils
.
toString
(
response
.
getEntity
());
Object
document
=
Configuration
.
defaultConfiguration
().
jsonProvider
().
parse
(
json
);
String
version
=
JsonPath
.
read
(
document
,
"$.Version"
);
String
name
=
JsonPath
.
read
(
document
,
"$.Name"
);
String
description
=
JsonPath
.
read
(
document
,
"$.Description"
);
softassert
.
assertTrue
(
null
!=
version
&&
!
version
.
isEmpty
(),
"Version is empty"
);
softassert
.
assertEquals
(
name
,
"metadata-governance"
,
"Name does not match"
);
softassert
.
assertEquals
(
name
,
"metadata-governance"
,
"Name does not match"
);
softassert
.
assertEquals
(
description
,
"Metadata Management and Data Governance Platform over "
+
"Hadoop"
,
"Description does not match"
);
softassert
.
assertAll
();
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
regression/src/test/java/org/apache/atlas/regression/tests/BaseTest.java
0 → 100644
View file @
52336574
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
regression
.
tests
;
public
class
BaseTest
{
public
static
final
String
ATLAS_URL
=
System
.
getProperty
(
"atlas.url"
,
"http://localhost:21000"
)
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
regression/src/test/java/org/apache/atlas/regression/util/TestNGListener.java
0 → 100644
View file @
52336574
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
regression
.
util
;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.NDC
;
import
org.testng.ITestContext
;
import
org.testng.ITestListener
;
import
org.testng.ITestResult
;
import
org.apache.commons.lang.StringUtils
;
import
java.util.Arrays
;
public
class
TestNGListener
implements
ITestListener
{
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
TestNGListener
.
class
);
private
final
String
header
=
StringUtils
.
repeat
(
"-"
,
80
);
private
final
String
footer
=
StringUtils
.
repeat
(
"#"
,
80
);
private
enum
resultStatus
{
SUCCESS
,
FAILED
,
SKIPPED
,
TestFailedButWithinSuccessPercentage
}
public
void
onTestStart
(
ITestResult
iTestResult
)
{
LOGGER
.
info
(
header
);
LOGGER
.
info
(
String
.
format
(
"Testing going to start for: %s.%s(%s)"
,
iTestResult
.
getTestClass
().
getName
(),
iTestResult
.
getName
(),
Arrays
.
toString
(
iTestResult
.
getParameters
())));
NDC
.
push
(
iTestResult
.
getName
());
}
public
void
onTestSuccess
(
ITestResult
iTestResult
)
{
endOfTestHook
(
iTestResult
,
resultStatus
.
SUCCESS
);
}
public
void
onTestFailure
(
ITestResult
iTestResult
)
{
endOfTestHook
(
iTestResult
,
resultStatus
.
FAILED
);
}
public
void
onTestSkipped
(
ITestResult
iTestResult
)
{
endOfTestHook
(
iTestResult
,
resultStatus
.
SKIPPED
);
}
public
void
onTestFailedButWithinSuccessPercentage
(
ITestResult
iTestResult
)
{
endOfTestHook
(
iTestResult
,
resultStatus
.
TestFailedButWithinSuccessPercentage
);
}
public
void
onStart
(
ITestContext
iTestContext
)
{
}
public
void
onFinish
(
ITestContext
iTestContext
)
{
}
private
void
endOfTestHook
(
ITestResult
result
,
resultStatus
outcome
)
{
LOGGER
.
info
(
String
.
format
(
"Testing going to end for: %s.%s(%s) %s"
,
result
.
getTestClass
().
getName
(),
result
.
getName
(),
Arrays
.
toString
(
result
.
getParameters
()),
outcome
));
LOGGER
.
info
(
footer
);
NDC
.
pop
();
}
}
This diff is collapsed.
Click to expand it.
regression/src/test/resources/log4j.properties
0 → 100644
View file @
52336574
#Copyright [yyyy] [name of copyright owner]
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
#root logger
log4j.rootLogger
=
INFO, stderr
# configure stderr
log4j.appender.stderr
=
org.apache.log4j.ConsoleAppender
log4j.appender.stderr.Threshold
=
DEBUG
log4j.appender.stderr.Target
=
System.err
log4j.appender.stderr.layout
=
org.apache.log4j.PatternLayout
log4j.appender.stderr.layout.ConversionPattern
=
%d %-5p - [%t:%x] ~ %m (%c{1}:%L)%n
This diff is collapsed.
Click to expand it.
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