Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial setup for Arquillian integration tests. #23

Merged
merged 1 commit into from
Sep 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 34 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ ext.githubProjectName = rootProject.name // Change if github project name is not

buildscript {
repositories {
mavenLocal()
mavenCentral() // maven { url 'http://jcenter.bintray.com' }
}
apply from: file('gradle/buildscript.gradle'), to: buildscript
apply from: file('gradle/buildscript.gradle'), to: buildscript
}

allprojects {
repositories {
repositories {
mavenCentral() // maven { url: 'http://jcenter.bintray.com' }
mavenLocal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to not do this - and simply depend on Karyon from maven central. Do you need 1.0.21? If so, I can wait to merge this until 1.0.21 is released.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmnarloch there is now a karyon version 1.0.22. Could you use that instead, and using just mavenCentral().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will take a look later today.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a bit confused, because the latest github kayron version is 1.0.21: https://github.com/Netflix/karyon/releases , but in the maven central there is 1.0.22: http://repo1.maven.org/maven2/com/netflix/karyon/karyon-core/1.0.22/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow the tags are a bit fu'd.. there is a version bump commit, though

Netflix/karyon@a4558af

On Thu, Sep 12, 2013 at 9:34 AM, Jakub Narloch notifications@github.comwrote:

In build.gradle:

     mavenCentral() // maven { url: 'http://jcenter.bintray.com' }
  •    mavenLocal()
    

I got a bit confused, because the latest github kayron version is 1.0.21:
https://github.com/Netflix/karyon/releases , but in the maven central
there is 1.0.22:
http://repo1.maven.org/maven2/com/netflix/karyon/karyon-core/1.0.22/


Reply to this email directly or view it on GitHubhttps://github.com//pull/23/files#r6315228
.

}
}

Expand Down Expand Up @@ -56,52 +56,71 @@ project(':genie-client') {

project(':genie-server') {
apply plugin: 'java'

// we are doing this rather than a dependency since we
// must perform build-time enhancement for OpenJPA
sourceSets.main.java.srcDirs += '../genie-common/src/main/java'

dependencies {
compile 'com.netflix.archaius:archaius-core:0.5.8'
compile 'commons-collections:commons-collections:3.2.1'
compile 'com.google.inject.extensions:guice-servlet:3.0'
compile 'com.sun.jersey.contribs:jersey-guice:1.9.1'
compile 'com.netflix.servo:servo-core:0.4.34'
compile 'com.netflix.karyon:karyon-extensions:1.0.16'
compile 'com.netflix.karyon:karyon-extensions:1.0.22'

runtime 'org.apache.derby:derby:10.2.2.0'
runtime 'mysql:mysql-connector-java:5.1.16'
runtime 'com.mchange:c3p0:0.9.2'
runtime 'com.mchange:mchange-commons-java:0.2.3.3'

provided 'javax.servlet:servlet-api:2.5'
provided 'javax.servlet:servlet-api:2.5'
}

task enhance << {
ant.taskdef(
name : 'openjpaenhancer',
classpath : project.runtimeClasspath.asPath,
classname : 'org.apache.openjpa.ant.PCEnhancerTask'
)

ant.openjpaenhancer(
classpath : project.runtimeClasspath.asPath)
}

jar {
it.dependsOn enhance
}

test {
it.dependsOn enhance
}
}

project(':genie-web') {
apply plugin: 'war'

dependencies {
compile 'com.netflix.karyon:karyon-admin-web:1.0.16'
compile 'com.netflix.karyon:karyon-admin-web:1.0.22'
compile project(':genie-server')
}
}

project(':genie-web-int-tests') {
apply plugin: 'java'

dependencies {
compile project(':genie-web')

testCompile 'com.netflix.karyon:karyon-extensions-testsuite:1.0.22'
testCompile 'org.jboss.arquillian.junit:arquillian-junit-container:1.1.0.Final'
testCompile 'org.jboss.shrinkwrap:shrinkwrap-impl-base:1.1.2'
testCompile 'org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-impl-maven:2.0.0'
testRuntime 'org.jboss.arquillian.container:arquillian-tomcat-embedded-7:1.0.0.CR5'
testRuntime 'org.apache.tomcat.embed:tomcat-embed-core:7.0.42'
testRuntime 'org.apache.tomcat.embed:tomcat-embed-logging-juli:7.0.42'
testRuntime ('org.apache.tomcat.embed:tomcat-embed-jasper:7.0.42') {
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2013 Netflix, Inc.
*
* 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.
*/

package com.netflix.genie.server.resources;

import com.google.inject.Inject;
import com.netflix.genie.common.messages.HiveConfigResponse;
import com.netflix.genie.server.utils.Deployments;
import com.netflix.kayron.server.test.RunInKaryon;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.ws.rs.core.Response;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
* Tests the {@link HiveConfigResourceV0} class.
*
* @author Jakub Narloch (jmnarloch@gmail.com)
*/
@RunWith(Arquillian.class)
@RunInKaryon(applicationId = "genie")
public class HiveConfigResourceV0TestCase {

/**
* Creates the test deployment.
*
* @return the test deployment
*/
@Deployment
public static Archive createTestArchive() {

return Deployments.createDeployment();
}

/**
* The injected {@link HiveConfigResourceV0} class.
*/
@Inject
private HiveConfigResourceV0 resource;

/**
* Test the {@link HiveConfigResourceV0#getHiveConfig(String, String, String)} method.
*/
@Test
public void shouldRetrieveConfigs() {

// when
Response response = resource.getHiveConfig(null, null, null);

// then
assertNotNull("The response entity was null.", response);
assertNotNull("The response entity was null.", response.getEntity());
assertTrue("The response entity had incorrect type.", response.getEntity() instanceof HiveConfigResponse);
assertNull("The response list was expected to be null.",
((HiveConfigResponse) response.getEntity()).getHiveConfigs());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2013 Netflix, Inc.
*
* 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.
*/

package com.netflix.genie.server.utils;

import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.importer.ZipImporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;

import java.io.File;
import java.io.FileFilter;

/**
* An example test case that demonstrates injection of a simple component into a test case.
*
* @author Jakub Narloch (jmnarloch@gmail.com)
*/
public final class Deployments {

/**
* Creates new instance of {@link Deployments} class.
*/
private Deployments() {
// empty constructor
}

/**
* Creates tbe test deployment.
*
* @return the test deployment
*/
public static Archive createDeployment() {

WebArchive archive = ShrinkWrap.create(ZipImporter.class, "genie-web.war")
.importFrom(resolveTestWar("../genie-web/"))
.as(WebArchive.class);

// overwrites the web.xml file
archive.setWebXML("web.xml");
// adds the archaius configuration
archive.addAsResource("config.properties");

return archive;
}

/**
* Resolves the path to the genie-web war, that need to be build prior executing this test.
*
* @param rootProjectPath the root project path of the genie-web module
*
* @return the path pointing to the build war
*/
private static File resolveTestWar(String rootProjectPath) {

File buildDir = new File(rootProjectPath, "/build/libs/");
File[] war = buildDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isFile()
&& pathname.getName().endsWith(".war");
}
});

return war[0];
}
}
15 changes: 15 additions & 0 deletions genie-web-int-tests/src/test/resources/arquillian.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<engine>
<property name="deploymentExportPath">build/deployments</property>
</engine>

<container qualifier="jetty" default="true">
<configuration>
<property name="bindHttpPort">7001</property>
</configuration>
</container>
</arquillian>
2 changes: 2 additions & 0 deletions genie-web-int-tests/src/test/resources/config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
archaius.deployment.applicationId=genie
archaius.deployment.environment=dev
39 changes: 39 additions & 0 deletions genie-web-int-tests/src/test/resources/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee">

<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.netflix.genie.server, com.netflix.appinfo</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/genie/*</url-pattern>
</servlet-mapping>

<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
<listener-class>com.netflix.kayron.server.test.KayronTestGuiceContextListener</listener-class>
</listener>
</web-app>
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rootProject.name='genie'
include 'genie-common','genie-client','genie-server', 'genie-web'
include 'genie-common','genie-client','genie-server', 'genie-web', 'genie-web-int-tests'