Skip to content
Permalink
Browse files

Usage test from maven

  • Loading branch information...
Alex Stockinger
Alex Stockinger committed Jul 24, 2017
1 parent c957350 commit 26b21df3c36d376df59a0532c4f971e13d93c918
@@ -3,4 +3,5 @@ classes/
build/
.gradle/
.idea/
out/
out/
target/
@@ -25,27 +25,50 @@ node() {
}
}

try {
stage("Publish to Nexus") {
if (currentBuild.result == 'UNSTABLE') {
throw new RuntimeException("SKIP: Won't deploy because build is unstable");
stage("Publish to Nexus") {
if (currentBuild.result == 'UNSTABLE') {
throw new RuntimeException("SKIP: Won't deploy because build is unstable");
}
withCredentials([
usernamePassword(
credentialsId: 'maven',
usernameVariable: 'MAVEN_USER',
passwordVariable: 'MAVEN_PASSWORD'
)
]) {
sh "./gradlew uploadArchives"
}
}

stage("Usage testing") {
@NonCPS def imageDirs = findFiles(glob:"usageTests/images/**/Dockerfile").collect { f ->
def split = f.path.split("/")
"${split[2]}:${split[3]}"
}
imageDirs.each { imageVersion ->
def dockerImage = dir("usageTests/images/${imageVersion.replace(":", "/")}") {
docker.build("testee-usage-$imageVersion")
}
withCredentials([
usernamePassword(
credentialsId: 'maven',
usernameVariable: 'MAVEN_USER',
passwordVariable: 'MAVEN_PASSWORD'
)
]) {
sh "./gradlew uploadArchives"

dir("usageTests/maven/") {
dockerImage.inside {
try {
withCredentials([
usernamePassword(
credentialsId: 'maven',
usernameVariable: 'MAVEN_USER',
passwordVariable: 'MAVEN_PASSWORD'
)
]) {
sh "chmod 755 build.sh && ./build.sh"
}
} catch(Throwable t) {
currentBuild.result == 'UNSTABLE'
println t.message
}
}
}
}
} catch(Throwable t) {
if(!t.message.startsWith("SKIP:")) {
throw t;
} else {
println t.message;
}
}
}

@@ -62,13 +85,15 @@ def withBuildEnv(closure) {

def psqlContainer = "testee-psql-${System.currentTimeMillis()}"
psqlImage.withRun("--name $psqlContainer -e POSTGRES_DB=testee -e POSTGRES_PASSWORD=testee -e POSTGRES_USER=testee") {
withEnv([
"TESTEE_PSQL_HOSTNAME=psql",
"TESTEE_PSQL_DB=testee",
"TESTEE_PSQL_USER=testee",
"TESTEE_PSQL_PASSWORD=testee"
]) {
jdkImage.inside("--link ${psqlContainer}:psql -e TESTEE_PSQL_HOSTNAME=psql -e TESTEE_PSQL_DB=testee -e TESTEE_PSQL_USER=testee -e TESTEE_PSQL_PASSWORD=testee", closure)
}
jdkImage.inside(
[
"--link ${psqlContainer}:psql",
"-e TESTEE_PSQL_HOSTNAME=psql",
"-e TESTEE_PSQL_DB=testee",
"-e TESTEE_PSQL_USER=testee",
"-e TESTEE_PSQL_PASSWORD=testee"
].join(" "),
closure
)
}
}
@@ -36,49 +36,9 @@ subprojects {

apply plugin: 'maven'

uploadArchives {
repositories {
mavenDeployer {
repository(url: "https://maven.it-stockinger.de/nexus/content/repositories/releases/") {
authentication(userName: System.getenv("MAVEN_USER"), password: System.getenv("MAVEN_PASSWORD"))
}

snapshotRepository(url: "https://maven.it-stockinger.de/nexus/content/repositories/snapshots/") {
authentication(userName: System.getenv("MAVEN_USER"), password: System.getenv("MAVEN_PASSWORD"))
}
pom.project {
name "TestEE.fi - ${project.name} module"
packaging 'jar'
description 'Functional testing for Java-EE.'
url 'https://github.com/dajudge/testee'

scm {
connection 'scm:git:https://github.com/dajudge/testee.git'
developerConnection 'scm:git:https://github.com/dajudge/testee.git'
url 'https://github.com/dajudge/testee.git'
}

licenses {
license {
name 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}

developers {
developer {
id 'alexs'
name 'Alex Stockinger'
email 'alex@it-stockinger.de'
}
}
}
}
}
}

afterEvaluate { Project project ->
if (project.pluginManager.hasPlugin("java")) {

jacocoTestReport.reports.xml.enabled = true

project.tasks.withType(Test) {
@@ -95,6 +55,47 @@ subprojects {
ignoreFailures = ignoreTestFailures
}

uploadArchives {
repositories {
mavenDeployer {
repository(url: "https://maven.it-stockinger.de/nexus/content/repositories/releases/") {
authentication(userName: System.getenv("MAVEN_USER"), password: System.getenv("MAVEN_PASSWORD"))
}

snapshotRepository(url: "https://maven.it-stockinger.de/nexus/content/repositories/snapshots/") {
authentication(userName: System.getenv("MAVEN_USER"), password: System.getenv("MAVEN_PASSWORD"))
}
pom.project {
name "TestEE.fi - ${project.name} module"
artifactId "testee-${project.name}"
packaging 'jar'
description 'Functional testing for Java-EE.'
url 'https://github.com/dajudge/testee'

scm {
connection 'scm:git:https://github.com/dajudge/testee.git'
developerConnection 'scm:git:https://github.com/dajudge/testee.git'
url 'https://github.com/dajudge/testee.git'
}

licenses {
license {
name 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}

developers {
developer {
id 'alexs'
name 'Alex Stockinger'
email 'alex@it-stockinger.de'
}
}
}
}
}
}
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
@@ -0,0 +1,5 @@
FROM openjdk:8u131-jdk-alpine

RUN apk update && \
apk add ca-certificates wget && \
update-ca-certificates
@@ -0,0 +1,18 @@
FROM debian:jessie

ENV JAVA_VERSION=8 \
JAVA_UPDATE=141 \
JAVA_BUILD=15 \
JAVA_PATH=336fa29ff2bb4ef291e347e091f7f4a7 \
JAVA_HOME="/usr/lib/jvm/default-jvm"

RUN apt-get update -q && \
apt-get install -q -y --no-install-recommends wget ca-certificates unzip && \
cd "/tmp" && \
wget -q --header "Cookie: oraclelicense=accept-securebackup-cookie;" \
"http://download.oracle.com/otn-pub/java/jdk/${JAVA_VERSION}u${JAVA_UPDATE}-b${JAVA_BUILD}/${JAVA_PATH}/jdk-${JAVA_VERSION}u${JAVA_UPDATE}-linux-x64.tar.gz" && \
tar -xzf "jdk-${JAVA_VERSION}u${JAVA_UPDATE}-linux-x64.tar.gz" && \
mkdir -p "/usr/lib/jvm" && \
mv "/tmp/jdk1.${JAVA_VERSION}.0_${JAVA_UPDATE}" "/usr/lib/jvm/java-${JAVA_VERSION}-oracle" && \
ln -s "/usr/lib/jvm/java-${JAVA_VERSION}-oracle" "$JAVA_HOME" && \
rm "/tmp/"*
@@ -0,0 +1,16 @@
#! /bin/sh

USER_HOME_DIR="/root"
MAVEN_VERSION=3.5.0
BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
BASE_DIR=/tmp/maven

mkdir -p $BASE_DIR $BASE_DIR/ref
wget -q -O /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz
tar -xzf /tmp/apache-maven.tar.gz -C $BASE_DIR --strip-components=1
rm -f /tmp/apache-maven.tar.gz

MAVEN_HOME=$BASE_DIR
MAVEN_CONFIG="$USER_HOME_DIR/.m2"

$BASE_DIR/bin/mvn clean verify -gs settings.xml -Dnexus.username=$MAVEN_USER -Dnexus.password=$MAVEN_PASSWORD clean install
@@ -0,0 +1,44 @@
<?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>

<groupId>com.dajudge.testee</groupId>
<artifactId>maven-usage-test</artifactId>
<version>${testee.version}</version>
<name>Maven usage test</name>

<properties>
<testee.version>0.0.1-SNAPSHOT</testee.version>
</properties>

<repositories>
<repository>
<id>nexus</id>
<url>https://maven.it-stockinger.de/nexus/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.dajudge.testee</groupId>
<artifactId>testee-junit4-all</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,12 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>nexus</id>
<username>${nexus.username}</username>
<password>${nexus.password}</password>
</server>
</servers>
</settings>
@@ -0,0 +1,37 @@
package com.dajudge.testee.maven;

import com.dajudge.testee.flyway.annotation.Flyway;
import com.dajudge.testee.h2.H2PostgresConnectionFactory;
import com.dajudge.testee.jdbc.TestData;
import com.dajudge.testee.jdbc.TestDataSource;
import com.dajudge.testee.jpa.TestPersistenceUnits;
import com.dajudge.testee.junit4.TestEE;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

@TestDataSource(name = "testds", factory = H2PostgresConnectionFactory.class)
@Flyway(dataSource = "testds")
@RunWith(TestEE.class)
public class MavenTest {

@PersistenceContext(unitName = "test")
private EntityManager entityManager;

@TestData
public static void setupTestData(final TestPersistenceUnits persistenceUnits) {
persistenceUnits.get("test").persist(new TestEntity(1, "lolcats"));
}

@Test
public void runs() {
final TestEntity entity = entityManager.find(TestEntity.class, 1L);
assertNotNull(entity);
assertEquals("lolcats", entity.getStringValue());
}
}
@@ -0,0 +1,38 @@
package com.dajudge.testee.maven;

import javax.persistence.Entity;
import javax.persistence.Id;

/**
* Created by dajudge on 24.07.2017.
*/
@Entity
public class TestEntity {
@Id
private long id;
private String stringValue;

public TestEntity() {
}

public TestEntity(long id, String stringValue) {
this.id = id;
this.stringValue = stringValue;
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getStringValue() {
return stringValue;
}

public void setStringValue(String stringValue) {
this.stringValue = stringValue;
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="test" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>testds</jta-data-source>
</persistence-unit>
</persistence>
@@ -0,0 +1,5 @@
CREATE TABLE testentity(
id BIGINT NOT NULL,
stringValue VARCHAR(1024) NOT NULL,
PRIMARY KEY(id)
);
Oops, something went wrong.

0 comments on commit 26b21df

Please sign in to comment.
You can’t perform that action at this time.