Skip to content
Snippets Groups Projects
Commit c986f892 authored by Thorsten Vitt's avatar Thorsten Vitt
Browse files

Allow integration-testing access to protected resources

parent 6245caa1
No related branches found
No related tags found
No related merge requests found
% Testing the Aggregator
% Thorsten Vitt
%
Automatic Tests
===============
Unit Tests
----------
Unit tests are run against individual classes in the source directory.
The complete service will *not* be set up.
Test classes are placed under `src/test` and named `*Test.java`. Tests will be
run using the surefire plugin when you run maven to any of the interesting
phases and can be skipped by passing the `-DskipTests` parameter.
Integration Tests
-----------------
Integration tests are tests against a fully setup service. A local
tomcat running the service will be set up, and the tests will be run in
a separate application. The system property `service.url` will contain
the root URL of the aggregator service to run.
Integration tests are executed using the failsafe plugin by running `mvn
verify`. The tests live in files called `*IT.java` under `src/test`.
Integration Tests with Authentication
-------------------------------------
These tests work like normal integration tests, but additionally they are
passed a session ID that is required to access non-public TextGrid resources in
the `sid` system property.
Implementors call the files containing the tests `*AT.java` (for
*a*uthenticated *t*ests) and place them under `src/test`. To test,
1. [Get a session ID](https://textgridlab.org/1.0/WebAuthN/WebAuthN2.php?authZinstance=textgrid-ws3.sub.uni-goettingen.de) for the user *tgtest*
2. run maven using `mvn -Dsid=<session ID> verify`
Interactive Testing
===================
You can run a local copy of the service using `mvn tomcat:run-war`. The
service will then be available at <http://localhost:13000/aggregator>
for you to test interactively.
......@@ -436,6 +436,48 @@
<aggregator.endpoint.published>https://textgridlab.org/1.0/aggregator</aggregator.endpoint.published>
</properties>
</profile>
<profile>
<id>authtests</id>
<activation>
<property>
<name>sid</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<includes>**/*IT.java</includes>
<includes>**/*AT.java</includes>
</includes>
<systemPropertyVariables>
<service.url>http://localhost:${test.server.port}/aggregator</service.url>
<sid>${sid}</sid>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<organization>
<name>TextGrid</name>
......
package info.textgrid.services.aggregator.html;
import info.textgrid.services.aggregator.AbstractIntegrationTest;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import org.junit.Assert;
import org.junit.Test;
public class HtmlAT extends AbstractIntegrationTest {
@Test
public void testSimpleGet() throws MalformedURLException, IOException {
final HttpURLConnection connection = createRequest("/html/textgrid:1zzbt.0?sid="
+ System.getProperty("sid"));
connection.connect();
Assert.assertEquals(200, connection.getResponseCode());
Assert.assertEquals("text/xml", connection.getContentType());
Assert.assertTrue("Content length > 0", readContents(connection) > 0);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment