Skip to content

Commit 5589e1b

Browse files
committed
Start of integration tests
1 parent bf4c2aa commit 5589e1b

File tree

4 files changed

+237
-5
lines changed

4 files changed

+237
-5
lines changed

pom.xml

Lines changed: 128 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,34 @@
4848
<project.build.source>1.8</project.build.source>
4949
<project.build.target>1.8</project.build.target>
5050

51-
<exist.version>4.4.0</exist.version>
52-
<!-- exist.version>5.0.0-SNAPSHOT</exist.version -->
51+
<!-- default supported exist-db version -->
52+
<exist.version>5.0.0</exist.version>
53+
54+
<!-- used for integration-test -->
55+
<docker.test.image>repo.evolvedbinary.com:9543/evolvedbinary/fusiondb-server:nightly</docker.test.image>
56+
<docker.test.port>4059</docker.test.port>
5357

5458
<!-- used in the EXPath Package Descriptor -->
5559
<package-name>https://fusiondb.com/studio/api</package-name>
5660
</properties>
5761

5862
<dependencies>
5963
<!-- test dependencies -->
64+
6065
<dependency>
61-
<groupId>org.exist-db</groupId>
62-
<artifactId>exist-testkit</artifactId>
63-
<version>${exist.version}</version>
66+
<groupId>org.junit.jupiter</groupId>
67+
<artifactId>junit-jupiter</artifactId>
68+
<version>5.6.2</version>
6469
<scope>test</scope>
6570
</dependency>
71+
72+
<dependency>
73+
<groupId>io.rest-assured</groupId>
74+
<artifactId>rest-assured</artifactId>
75+
<version>4.3.1</version>
76+
<scope>test</scope>
77+
</dependency>
78+
6679
</dependencies>
6780

6881
<build>
@@ -77,7 +90,114 @@
7790
</resource>
7891
</resources>
7992

93+
<testResources>
94+
<testResource>
95+
<directory>src/test/resources-filtered</directory>
96+
<filtering>true</filtering>
97+
</testResource>
98+
</testResources>
99+
80100
<plugins>
101+
102+
<!-- start up Server in Docker for integration-test -->
103+
<plugin>
104+
<groupId>io.fabric8</groupId>
105+
<artifactId>docker-maven-plugin</artifactId>
106+
<version>0.33.0</version>
107+
<configuration>
108+
<verbose>true</verbose>
109+
<images>
110+
<image>
111+
<alias>db-with-api</alias>
112+
<name>${docker.test.image}</name>
113+
<run>
114+
<ports>${docker.test.port}:${docker.test.port}</ports>
115+
<wait>
116+
<log>Server has started, listening on</log>
117+
<time>120000</time>
118+
</wait>
119+
</run>
120+
</image>
121+
</images>
122+
</configuration>
123+
<executions>
124+
<execution>
125+
<id>docker-it-start</id>
126+
<phase>pre-integration-test</phase>
127+
<goals>
128+
<goal>start</goal>
129+
</goals>
130+
</execution>
131+
<execution>
132+
<id>docker-it-stop</id>
133+
<phase>post-integration-test</phase>
134+
<goals>
135+
<goal>stop</goal>
136+
</goals>
137+
</execution>
138+
</executions>
139+
</plugin>
140+
141+
<!-- Upload and deploy latest XAR build of API to Server (inside Docker) for integration-test -->
142+
<plugin>
143+
<groupId>org.codehaus.mojo</groupId>
144+
<artifactId>exec-maven-plugin</artifactId>
145+
<version>3.0.0</version>
146+
<executions>
147+
<execution>
148+
<id>upload-xar</id>
149+
<phase>pre-integration-test</phase>
150+
<goals>
151+
<goal>exec</goal>
152+
</goals>
153+
<configuration>
154+
<executable>curl</executable>
155+
<arguments>
156+
<argument>-v</argument>
157+
<argument>-X</argument>
158+
<argument>PUT</argument>
159+
<argument>--data-binary</argument>
160+
<argument>@${project.build.directory}/${package-final-name}.xar</argument>
161+
<argument>http://admin:@localhost:${docker.test.port}/exist/rest/db/${package-final-name}.xar</argument>
162+
</arguments>
163+
</configuration>
164+
</execution>
165+
<execution>
166+
<id>deploy-xar</id>
167+
<phase>pre-integration-test</phase>
168+
<goals>
169+
<goal>exec</goal>
170+
</goals>
171+
<configuration>
172+
<executable>curl</executable>
173+
<arguments>
174+
<argument>-v</argument>
175+
<argument>-X</argument>
176+
<argument>POST</argument>
177+
<argument>-H</argument>
178+
<argument>application/xml</argument>
179+
<argument>--data-binary</argument>
180+
<argument>@${project.build.testOutputDirectory}/deploy-xar.xq.xml</argument>
181+
<argument>http://admin:@localhost:${docker.test.port}/exist/rest/db/</argument>
182+
</arguments>
183+
</configuration>
184+
</execution>
185+
</executions>
186+
</plugin>
187+
188+
<plugin>
189+
<groupId>org.apache.maven.plugins</groupId>
190+
<artifactId>maven-failsafe-plugin</artifactId>
191+
<version>3.0.0-M5</version>
192+
<executions>
193+
<execution>
194+
<goals>
195+
<goal>integration-test</goal>
196+
</goals>
197+
</execution>
198+
</executions>
199+
</plugin>
200+
81201
<plugin>
82202
<groupId>org.apache.maven.plugins</groupId>
83203
<artifactId>maven-jar-plugin</artifactId>
@@ -101,6 +221,7 @@
101221
</archive>
102222
</configuration>
103223
</plugin>
224+
104225
<plugin>
105226
<groupId>ro.kuberam.maven.plugins</groupId>
106227
<artifactId>kuberam-expath-plugin</artifactId>
@@ -118,13 +239,15 @@
118239
</execution>
119240
</executions>
120241
</plugin>
242+
121243
<plugin>
122244
<groupId>org.apache.maven.plugins</groupId>
123245
<artifactId>maven-gpg-plugin</artifactId>
124246
<configuration>
125247
<useAgent>true</useAgent>
126248
</configuration>
127249
</plugin>
250+
128251
<plugin>
129252
<groupId>org.apache.maven.plugins</groupId>
130253
<artifactId>maven-release-plugin</artifactId>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.fusiondb.studio.api;
2+
3+
import java.util.function.Function;
4+
5+
public class API {
6+
7+
/**
8+
* Default Host for FusionDB Server
9+
*/
10+
public static String DEFAULT_HOST = "localhost";
11+
12+
/**
13+
* Default Port for FusionDB Server
14+
*/
15+
public static int DEFAULT_PORT = 4059;
16+
17+
/**
18+
* Default API Endpoint for Fusion Studio API
19+
*/
20+
public static String DEFAULT_ENDPOINT = "fusiondb";
21+
22+
/**
23+
* Environment variable name for setting the API Host
24+
*/
25+
public static String ENV_VAR_FS_API_HOST = "FS_API_HOST";
26+
27+
/**
28+
* Environment variable name for setting the API Port
29+
*/
30+
public static String ENV_VAR_FS_API_PORT = "FS_API_PORT";
31+
32+
/**
33+
* Get the Base URI for the Fusion Studio API.
34+
*
35+
* The URI can be overriden by environment variables
36+
* see {@link #ENV_VAR_FS_API_HOST} and {@link #ENV_VAR_FS_API_PORT}.
37+
*
38+
* @return the base URI
39+
*/
40+
public static String getApiBaseUri() {
41+
final String host = envVarOrDefault(ENV_VAR_FS_API_HOST, DEFAULT_HOST, envVarValue -> envVarValue);
42+
final int port = envVarOrDefault(ENV_VAR_FS_API_PORT, DEFAULT_PORT, envVarValue -> {
43+
try {
44+
return Integer.parseInt(envVarValue);
45+
} catch (final NumberFormatException e) {
46+
// invalid number
47+
System.err.println("ENV.FS_API_PORT=" + envVarValue + ", is not a valid TCP port number. Using default: " + DEFAULT_PORT);
48+
e.printStackTrace();
49+
return DEFAULT_PORT;
50+
}
51+
});
52+
53+
return "http://" + host + ":" + port + "/exist/restxq/" + DEFAULT_ENDPOINT;
54+
}
55+
56+
/**
57+
* Gets a value from an Environment variable or uses the default
58+
* if there is no such variable.
59+
*
60+
* @param envVarName the name of the environment variable.
61+
* @param defaultValue the default value to use if there is no environment variable
62+
* @param typeConverter a function for converting the value of the environment
63+
* variable (if present) to the desired type
64+
*
65+
* @return the value from the environment variable, or the default value
66+
*/
67+
private static <T> T envVarOrDefault(final String envVarName, final T defaultValue, final Function<String, T> typeConverter) {
68+
final String envVarValue = System.getenv(envVarName);
69+
if (envVarValue != null && !envVarValue.isEmpty()) {
70+
return typeConverter.apply(envVarValue);
71+
} else {
72+
return defaultValue;
73+
}
74+
}
75+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.fusiondb.studio.api;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static com.fusiondb.studio.api.API.getApiBaseUri;
6+
import static io.restassured.RestAssured.when;
7+
8+
public class VersionIT {
9+
10+
@Test
11+
public void getServerVersion() {
12+
when().
13+
get(getApiBaseUri() + "/version").
14+
then()
15+
.statusCode(200);
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<query xmlns="http://exist.sourceforge.net/NS/exist">
2+
<text><![CDATA[
3+
let $pkg-name := "${package-name}"
4+
return
5+
(
6+
if (repo:list() = $pkg-name)
7+
then
8+
if (not(repo:undeploy($pkg-name)))
9+
then
10+
fn:error("Unable to undeploy package: " || $pkg-name)
11+
else()
12+
else(),
13+
14+
repo:install-and-deploy-from-db("/db/${package-final-name}.xar")
15+
)
16+
]]></text>
17+
</query>

0 commit comments

Comments
 (0)