Commit a98af5ec by Arpit Gupta

Merge pull request #85 from hortonworks/QE-4071

QE-4071: Initial setup for atlas regression
parents 75dad300 ae227ea9
...@@ -38,3 +38,7 @@ test-output ...@@ -38,3 +38,7 @@ test-output
#Python #Python
*.pyc *.pyc
# other files
.DS_Store
*.swp
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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>
<hadoop.version>2.7.0</hadoop.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>${hadoop.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>${hadoop.version}</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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</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>
/**
* 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.atlas.regression.security.AtlasAuthenticationToken;
import org.apache.commons.net.util.TrustManagerUtils;
import org.apache.hadoop.security.authentication.client.AuthenticatedURL;
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.HttpStatus;
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);
// add token to the request in case we get a 401 back with negotiate.
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)) {
AuthenticatedURL.Token token = AtlasAuthenticationToken.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;
}
}
/**
* 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 TEXT_CONTENT_TYPE = "text/plain";
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");
}
package org.apache.atlas.regression.security;
import org.apache.atlas.regression.request.BaseRequest;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.authentication.client.AuthenticatedURL;
import org.apache.hadoop.security.authentication.client.KerberosAuthenticator;
import org.apache.hadoop.security.authentication.client.PseudoAuthenticator;
import org.apache.http.auth.AuthenticationException;
import org.apache.log4j.Logger;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
import java.io.IOException;
import java.net.URL;
import java.security.PrivilegedExceptionAction;
import java.util.concurrent.ConcurrentHashMap;
public class AtlasAuthenticationToken {
private static final String AUTH_URL = "api/options";
private static final KerberosAuthenticator AUTHENTICATOR = new KerberosAuthenticator();
private static final AtlasAuthenticationToken INSTANCE = new AtlasAuthenticationToken();
private static final Logger LOGGER = Logger.getLogger(AtlasAuthenticationToken.class);
// Use a hashmap so that we can cache the tokens.
private final ConcurrentHashMap<String, AuthenticatedURL.Token> tokens =
new ConcurrentHashMap<>();
private AtlasAuthenticationToken() {
}
public static final HostnameVerifier ALL_TRUSTING_HOSTNAME_VERIFIER = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession sslSession) {
return true;
}
};
private static void authenticate(String user, String protocol, String host, int port)
throws IOException, AuthenticationException, InterruptedException {
final URL url = new URL(String.format("%s://%s:%d/%s", protocol, host, port,
AUTH_URL + "?" + PseudoAuthenticator.USER_NAME + "=" + user));
LOGGER.info("Authorize using url: " + url.toString());
final AuthenticatedURL.Token currentToken = new AuthenticatedURL.Token();
/*using KerberosAuthenticator which falls back to PsuedoAuthenticator
instead of passing authentication type from the command line - bad factory*/
try {
HttpsURLConnection.setDefaultSSLSocketFactory(BaseRequest.getSslContext()
.getSocketFactory());
} catch (Exception e) {
throw new RuntimeException(e);
}
HttpsURLConnection.setDefaultHostnameVerifier(ALL_TRUSTING_HOSTNAME_VERIFIER);
UserGroupInformation callerUGI = KerberosHelper.getUGI(user);
callerUGI.doAs(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
new AuthenticatedURL(AUTHENTICATOR).openConnection(url, currentToken);
return null;
}
});
String key = getKey(user, protocol, host, port);
// initialize a hash map if its null.
LOGGER.info("Authorization Token: " + currentToken.toString());
INSTANCE.tokens.put(key, currentToken);
}
public static AuthenticatedURL.Token getToken(String user, String protocol, String host,
int port, boolean overWrite)
throws IOException, AuthenticationException, InterruptedException {
String key = getKey(user, protocol, host, port);
/*if the tokens are null or if token is not found then we will go ahead and authenticate
or if we are asked to overwrite*/
if (!INSTANCE.tokens.containsKey(key) || overWrite) {
authenticate(user, protocol, host, port);
}
return INSTANCE.tokens.get(key);
}
public static AuthenticatedURL.Token getToken(String user, String protocol, String host,
int port)
throws IOException, AuthenticationException, InterruptedException {
return getToken(user, protocol, host, port, false);
}
/*spnego token will be unique to the user and uri its being requested for.
Hence the key of the hash map is the combination of user, protocol, host and port.*/
private static String getKey(String user, String protocol, String host, int port) {
return String.format("%s-%s-%s-%d", user, protocol, host, port);
}
}
package org.apache.atlas.regression.security;
import org.apache.hadoop.security.UserGroupInformation;
import org.testng.Assert;
import java.io.IOException;
import java.util.HashMap;
public class KerberosHelper {
private KerberosHelper() {
throw new AssertionError("Instantiating utility class...");
}
// determine if running on a secure cluster if secure=true is sent
public static final boolean IS_SECURE = Boolean.parseBoolean(System.getProperty("secure",
"false"));
/** keytab of current user. */
private static final String CURRENT_USER_KEYTAB = System.getProperty("current.user.keytab",
null);
// determine the user realm to use
private static final String USER_REALM = System.getProperty("user.realm", "");
private static HashMap<String, String> keyTabMap;
/* initialize keyTabMap */
static {
keyTabMap = new HashMap<>();
keyTabMap.put(System.getProperty("user.name"), CURRENT_USER_KEYTAB);
}
public static UserGroupInformation getUGI(String user) throws IOException {
// if unsecure cluster create a remote user object
if (!IS_SECURE) {
return UserGroupInformation.createRemoteUser(user);
}
// if secure create a ugi object from keytab
return UserGroupInformation.loginUserFromKeytabAndReturnUGI(getPrincipal(user),
getKeytabForUser(user));
}
private static String getPrincipal(String user) {
return USER_REALM.isEmpty() ? user : user + '@' + USER_REALM;
}
private static String getKeytabForUser(String user) {
Assert.assertTrue(keyTabMap.containsKey(user), "Unknown user: " + user);
return keyTabMap.get(user);
}
}
\ No newline at end of file
/**
* 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.atlas.regression.request.RequestKeys;
import org.apache.atlas.regression.util.TestUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.testng.annotations.Test;
@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";
@Test
public void testVersion()
throws Exception {
BaseRequest req = new BaseRequest(baseReqUrl + "/version");
HttpResponse response = req.run();
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");
SOFT_ASSERT.assertTrue(null != version && !version.isEmpty(), "Version is empty");
SOFT_ASSERT.assertEquals(name, "metadata-governance", "Name does not match");
SOFT_ASSERT.assertEquals(description,
"Metadata Management and Data Governance Platform over " +
"Hadoop", "Description does not match");
TestUtils.assert200(SOFT_ASSERT, RequestKeys.JSON_CONTENT_TYPE, response);
SOFT_ASSERT.assertAll();
}
@Test
public void testStack()
throws Exception {
BaseRequest req = new BaseRequest(baseReqUrl + "/stack");
HttpResponse response = req.run();
TestUtils.assert200(SOFT_ASSERT, RequestKeys.TEXT_CONTENT_TYPE, response);
SOFT_ASSERT.assertNotNull(EntityUtils.toString(response.getEntity()), "Content is not null");
SOFT_ASSERT.assertAll();
}
}
\ No newline at end of file
/**
* 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 org.testng.annotations.BeforeClass;
import org.testng.asserts.SoftAssert;
public class BaseTest {
public static final String ATLAS_URL = System.getProperty("atlas.url",
"http://localhost:21000") ;
public SoftAssert SOFT_ASSERT;
// without this we get NPE
@BeforeClass(alwaysRun = true)
public void beforeClass() {
SOFT_ASSERT = new SoftAssert();
}
}
\ No newline at end of file
/**
* 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 sep = StringUtils.repeat("-", 5);
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 Status: %s", result
.getTestClass().getName(),
result.getName(), Arrays.toString(result.getParameters()), sep, outcome));
LOGGER.info(footer);
NDC.pop();
}
}
/*
* *
* * 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.atlas.regression.request.RequestKeys;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.testng.asserts.SoftAssert;
public class TestUtils {
public static void assertResponse(SoftAssert softAssert, int expCode, String expMsg, String
contentType, HttpResponse response) {
StatusLine statusLine = response.getStatusLine();
softAssert.assertEquals(statusLine.getStatusCode(), expCode, "Status code mismatch");
softAssert.assertEquals(statusLine.getReasonPhrase(), expMsg, "Status Message mismatch");
softAssert.assertEquals(getContentType(response), contentType, "Content Type Mismatch");
}
public static String getContentType(HttpResponse response) {
for (Header header : response.getHeaders(RequestKeys.CONTENT_TYPE_HEADER)){
return header.getValue();
}
return null;
}
public static void assert200(SoftAssert softAssert, String contentType, HttpResponse response) {
assertResponse(softAssert, 200, "OK", contentType, response);
}
}
#
#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
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