This repository has been archived by the owner on Sep 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added docker based integration testing
Signed-off-by: Andrew DeMaria <lostonamountain@gmail.com>
- Loading branch information
Showing
20 changed files
with
781 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>airsonic-integration-test</artifactId> | ||
<name>Airsonic Integration Test</name> | ||
|
||
<parent> | ||
<groupId>org.airsonic.player</groupId> | ||
<artifactId>airsonic</artifactId> | ||
<version>10.2.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<cucumber.version>2.3.1</cucumber.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.cucumber</groupId> | ||
<artifactId>cucumber-core</artifactId> | ||
<version>${cucumber.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.cucumber</groupId> | ||
<artifactId>cucumber-junit</artifactId> | ||
<version>${cucumber.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.cucumber</groupId> | ||
<artifactId>cucumber-java</artifactId> | ||
<version>${cucumber.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.cucumber</groupId> | ||
<artifactId>cucumber-java8</artifactId> | ||
<version>${cucumber.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.cucumber</groupId> | ||
<artifactId>cucumber-spring</artifactId> | ||
<version>${cucumber.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-codec</groupId> | ||
<artifactId>commons-codec</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpcore</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.spotify</groupId> | ||
<artifactId>docker-client</artifactId> | ||
<version>8.13.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.xmlunit</groupId> | ||
<artifactId>xmlunit-core</artifactId> | ||
<version>2.6.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.xmlunit</groupId> | ||
<artifactId>xmlunit-matchers</artifactId> | ||
<version>2.6.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.airsonic.player</groupId> | ||
<artifactId>subsonic-rest-api</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<testResources> | ||
<testResource> | ||
<directory>src/test/resources</directory> | ||
<filtering>true</filtering> | ||
</testResource> | ||
</testResources> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.github.temyers</groupId> | ||
<artifactId>cucumber-jvm-parallel-plugin</artifactId> | ||
<version>5.0.0</version> | ||
<executions> | ||
<execution> | ||
<id>generateRunners</id> | ||
<phase>generate-test-sources</phase> | ||
<goals> | ||
<goal>generateRunners</goal> | ||
</goals> | ||
<configuration> | ||
<featuresDirectory>src/test/resources/features</featuresDirectory> | ||
<format>pretty</format> | ||
<glue>org.airsonic.test.cucumber.steps</glue> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.5.1</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
<compilerVersion>1.8</compilerVersion> | ||
<showWarnings>true</showWarnings> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.1.0</version> | ||
<executions> | ||
<execution> | ||
<id>default-jar</id> | ||
<phase/> | ||
<configuration> | ||
<finalName>unwanted</finalName> | ||
<classifier>unwanted</classifier> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.21.0</version> | ||
<configuration> | ||
<parallel>all</parallel> | ||
<threadCount>2</threadCount> | ||
<includes> | ||
<include>**/Parallel*IT.class</include> | ||
</includes> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
12 changes: 12 additions & 0 deletions
12
integration-test/src/test/java/org/airsonic/test/SpringContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.airsonic.test; | ||
|
||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.PropertySource; | ||
|
||
@Configuration | ||
@ComponentScan("org.airsonic.test") | ||
@PropertySource("classpath:application.properties") | ||
public class SpringContext { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
integration-test/src/test/java/org/airsonic/test/cucumber/RunCukesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.airsonic.test.cucumber; | ||
|
||
import cucumber.api.CucumberOptions; | ||
import cucumber.api.junit.Cucumber; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(Cucumber.class) | ||
@CucumberOptions(plugin = {"pretty"}, | ||
features = "classpath:features/api/stream-mp3.feature", | ||
glue = "org.airsonic.test.cucumber.steps") | ||
public class RunCukesTest { | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
integration-test/src/test/java/org/airsonic/test/cucumber/server/AirsonicServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.airsonic.test.cucumber.server; | ||
|
||
import org.apache.commons.codec.digest.DigestUtils; | ||
import org.apache.http.client.methods.RequestBuilder; | ||
|
||
import java.nio.file.Path; | ||
|
||
public interface AirsonicServer { | ||
String getBaseUri(); | ||
|
||
void uploadToDefaultMusicFolder(Path directoryPath, String relativePath); | ||
|
||
default void addRestParameters(RequestBuilder builder) { | ||
builder.addParameter("c", "inttest"); | ||
builder.addParameter("v", "1.15.0"); | ||
builder.addParameter("u", "admin"); | ||
builder.addParameter("s", "int"); | ||
builder.addParameter("t", DigestUtils.md5Hex("admin" + "int")); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
integration-test/src/test/java/org/airsonic/test/cucumber/steps/api/PingStepDef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.airsonic.test.cucumber.steps.api; | ||
|
||
import cucumber.api.java8.En; | ||
import org.airsonic.test.cucumber.server.AirsonicServer; | ||
import org.apache.http.HttpEntity; | ||
import org.apache.http.StatusLine; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.util.EntityUtils; | ||
import org.xmlunit.builder.Input; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThat; | ||
import static org.xmlunit.matchers.CompareMatcher.isIdenticalTo; | ||
|
||
public class PingStepDef implements En { | ||
|
||
private CloseableHttpResponse response; | ||
private CloseableHttpClient client; | ||
|
||
public PingStepDef(AirsonicServer server) { | ||
this.client = HttpClientBuilder.create().build(); | ||
When("^A ping request is sent$", () -> { | ||
HttpGet httpGet = new HttpGet(server.getBaseUri() + "/rest/ping"); | ||
this.response = client.execute(httpGet); | ||
}); | ||
Then("^A required parameter response is received$", () -> { | ||
if(response == null) { | ||
throw new IllegalStateException(); | ||
} | ||
try { | ||
StatusLine statusLine = response.getStatusLine(); | ||
assertEquals(statusLine.getStatusCode(), 200); | ||
HttpEntity entity = response.getEntity(); | ||
String actual = EntityUtils.toString(entity); | ||
assertThat( | ||
actual, | ||
isIdenticalTo( | ||
Input.fromStream( | ||
getClass().getResourceAsStream("/blobs/ping/missing-auth.xml"))) | ||
.ignoreWhitespace()); | ||
} finally { | ||
response.close(); | ||
} | ||
}); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
integration-test/src/test/java/org/airsonic/test/cucumber/steps/api/ScanStepDef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.airsonic.test.cucumber.steps.api; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.MapperFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import cucumber.api.java8.En; | ||
import org.airsonic.test.cucumber.server.AirsonicServer; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.client.methods.RequestBuilder; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.util.EntityUtils; | ||
import org.junit.Assert; | ||
import org.subsonic.restapi.Response; | ||
|
||
import java.io.IOException; | ||
|
||
public class ScanStepDef implements En { | ||
|
||
private final AirsonicServer server; | ||
private CloseableHttpResponse response; | ||
private CloseableHttpClient client; | ||
private ObjectMapper mapper = new ObjectMapper(); | ||
|
||
public ScanStepDef(AirsonicServer server) { | ||
mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS); | ||
this.client = HttpClientBuilder.create().build(); | ||
this.server = server; | ||
|
||
Given("a scan is done", () -> { | ||
Assert.assertFalse(isScanning()); | ||
|
||
RequestBuilder builder = RequestBuilder.create("GET").setUri(server.getBaseUri() + "/rest/startScan"); | ||
server.addRestParameters(builder); | ||
response = client.execute(builder.build()); | ||
System.out.println(EntityUtils.toString(response.getEntity())); | ||
Long waitTime = 30000L; | ||
Long sleepTime = 1000L; | ||
while(waitTime > 0 && isScanning()) { | ||
waitTime -= sleepTime; | ||
Thread.sleep(sleepTime); | ||
} | ||
|
||
Assert.assertFalse(isScanning()); | ||
}); | ||
|
||
} | ||
|
||
private boolean isScanning() throws IOException { | ||
RequestBuilder builder = RequestBuilder.create("GET").setUri(server.getBaseUri() + "/rest/getScanStatus"); | ||
builder.addParameter("f", "json"); | ||
server.addRestParameters(builder); | ||
response = client.execute(builder.build()); | ||
|
||
String responseAsString = EntityUtils.toString(response.getEntity()); | ||
JsonNode jsonNode = mapper.readTree(responseAsString).get("subsonic-response"); | ||
Response response = mapper.treeToValue(jsonNode, Response.class); | ||
return response.getScanStatus().isScanning(); | ||
} | ||
|
||
} |
Oops, something went wrong.