Skip to content

Commit

Permalink
deegree#963 - fixed deegree-workspace-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoltz committed Aug 10, 2021
1 parent e8c7c7b commit 672c8b0
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 39 deletions.
63 changes: 62 additions & 1 deletion deegree-tests/deegree-workspace-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,61 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>compliance-tests</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.deegree</groupId>
<artifactId>deegree-workspace-wps</artifactId>
<version>${project.version}</version>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/workspaces/deegree-workspace-wps</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.deegree</groupId>
<artifactId>deegree-workspace-utah</artifactId>
<version>${project.version}</version>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/workspaces/deegree-workspace-utah</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.deegree</groupId>
<artifactId>deegree-workspace-aixm</artifactId>
<version>${project.version}</version>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/workspaces/deegree-workspace-aixm</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.deegree</groupId>
<artifactId>deegree-workspace-geosciml</artifactId>
<version>${project.version}</version>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/workspaces/deegree-workspace-geosciml</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.deegree</groupId>
<artifactId>deegree-workspace-wcts</artifactId>
<version>${project.version}</version>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/workspaces/deegree-workspace-wcts</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.deegree</groupId>
<artifactId>deegree-workspace-xplan40</artifactId>
<version>${project.version}</version>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/workspaces/deegree-workspace-xplan40</outputDirectory>
</artifactItem>
</artifactItems>
<excludes>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand All @@ -34,7 +89,7 @@
<includes>
<include>**/*IT.java</include>
</includes>
<argLine>-Xmx1024m -Xss2048k -Djava.awt.headless=true</argLine>
<argLine>-Xmx1024m -Xss2048k -Djava.awt.headless=true -Dportnumber=${jetty.http.port} -Dcontext=deegree-workspace-tests -DworkspaceDir=${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/workspaces</argLine>
</configuration>
<executions>
<execution>
Expand All @@ -56,6 +111,12 @@
<webApp>
<contextPath>/deegree-workspace-tests</contextPath>
</webApp>
<systemProperties>
<systemProperty>
<name>DEEGREE_WORKSPACE_ROOT</name>
<value>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/workspaces</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,76 +40,124 @@ Occam Labs UG (haftungsbeschränkt)

package org.deegree.maven;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.util.EntityUtils;
import org.deegree.maven.ithelper.ServiceIntegrationTestHelper;
import org.deegree.maven.ithelper.TestEnvironment;
import org.deegree.maven.utils.HttpUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.slf4j.Logger;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;

import static org.slf4j.LoggerFactory.getLogger;

/**
*
* @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
* @author last edited by: $Author$
*
* @version $Revision$, $Date$
*/
@RunWith(Parameterized.class)
public class ServiceIT {

private static final Logger LOG = getLogger(ServiceIT.class);
private static final Logger LOG = getLogger( ServiceIT.class );

private final Path workspaceUnderTest;

private boolean testCapabilities = true;

private boolean testLayers = true;

private boolean testRequests = true;

private File workspace = new File("./src/main/webapp/WEB-INF/workspace");
private static final TestEnvironment env = new TestEnvironment( System.getProperties() );

public ServiceIT( Path workspaceUnderTest ) {
this.workspaceUnderTest = workspaceUnderTest;
}

@Parameters
public static List<Path> getParameters()
throws IOException {
String workspaceDir = env.getWorkspaceDir();
Path workspaces = Paths.get( workspaceDir );
return Files.list( workspaces ).filter( p -> Files.isDirectory( p ) && Files.exists( p ) ).collect(
Collectors.toList() );
}

private TestEnvironment env = new TestEnvironment(System.getProperties());
@Before
public void restartWorkspace()
throws Exception {
ServiceIntegrationTestHelper helper = new ServiceIntegrationTestHelper( env );
String workspaceName = workspaceUnderTest.getFileName().toString();
LOG.info( "Restart Workspace {}", workspaceName );
try {
HttpClient client = HttpUtils.getAuthenticatedHttpClient( env );
String restartUrl = helper.createBaseURL() + "config/restart/" + workspaceName;
LOG.info( "Sending against: " + restartUrl );
HttpGet get = new HttpGet( restartUrl );
HttpResponse resp = client.execute( get );
String response = EntityUtils.toString( resp.getEntity(), "UTF-8" ).trim();
LOG.info( "Response after initial restart was: " + response );
} catch ( IOException e ) {
throw new Exception( "Could not test workspace " + workspaceName + ": "
+ e.getLocalizedMessage(), e );
}
}

@Test
public void execute() throws Exception {
public void execute()
throws Exception {
try {
if (!workspace.exists()) {
workspace = new File(env.getBasedir(), "src/main/webapp/WEB-INF/conf");
if (!workspace.exists()) {
LOG.error("Could not find a workspace to operate on.");
throw new RuntimeException("Could not find a workspace to operate on.");
String workspaceName = workspaceUnderTest.getFileName().toString();
LOG.info( "Workspace under test {}", workspaceName );
ServiceIntegrationTestHelper helper = new ServiceIntegrationTestHelper( env );
Path services = workspaceUnderTest.resolve( "services" );
if ( Files.exists( services ) ) {
List<Path> serviceList = Files.list( services ).filter(
f -> isService( f ) ).collect( Collectors.toList() );
for ( Path service : serviceList ) {
testService( helper, service );
}
LOG.warn("Default/configured workspace did not exist, using existing " + workspace
+ " instead.");
}

ServiceIntegrationTestHelper helper = new ServiceIntegrationTestHelper(env);

File[] listed = new File(workspace, "services").listFiles();
if (listed != null) {
for (File f : listed) {
String nm = f.getName().toLowerCase();
if (nm.length() != 7) {
continue;
}
String service = nm.substring(0, 3).toUpperCase();
if (testCapabilities) {
helper.testCapabilities(service);
}
if (testLayers) {
helper.testLayers(service);
LOG.info("All maps can be requested.");
}
if ( testRequests ) {
helper.testRequests();
}
}
} catch ( NoClassDefFoundError e ) {
LOG.warn( "Class not found, not performing any tests." );
}
}

if (testRequests) {
helper.testRequests();
}
} catch (NoClassDefFoundError e) {
LOG.warn("Class not found, not performing any tests.");
private void testService( ServiceIntegrationTestHelper helper, Path service )
throws Exception {
String serviceName = service.getFileName().toString().toLowerCase();
String serviceType = serviceName.substring( 0, 3 ).toUpperCase();
LOG.info( "Service name: {}, service type: {}", serviceName, serviceType );
if ( testCapabilities ) {
helper.testCapabilities( serviceType );
}
if ( testLayers ) {
helper.testLayers( serviceType );
LOG.info( "All maps can be requested." );
}
}

private boolean isService( Path f ) {
String fileName = f.getFileName().toString();
return fileName.endsWith( ".xml" ) && !"wmts.xml".equals( fileName ) && !"main.xml".equals( fileName )
&& !fileName.endsWith( "metadata.xml" );
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ public String getBasedir() {
String basedir = properties.getProperty( "basedir" );
return basedir;
}

public String getWorkspaceDir() {
return properties.getProperty( "workspaceDir" );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
log4j.rootLogger=INFO, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %5p: [%c{1}] %m%n

log4j.logger.org.deegree=INFO
log4j.logger.org.deegree.services.wms=INFO

0 comments on commit 672c8b0

Please sign in to comment.