From f394a5ea593e62ee564d94b2f5b6b62aede1ac74 Mon Sep 17 00:00:00 2001 From: Lyn Elisa Goltz Date: Thu, 12 Aug 2021 07:29:50 +0200 Subject: [PATCH] #963 - cleaned up deegree-workspace-tests --- .../{ServiceIT.java => WorkpacesIT.java} | 25 +-- .../java/org/deegree/maven/WorkspaceIT.java | 145 ------------------ .../ServiceIntegrationTestHelper.java | 107 +------------ .../maven/ithelper/TestEnvironment.java | 11 +- 4 files changed, 10 insertions(+), 278 deletions(-) rename deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/{ServiceIT.java => WorkpacesIT.java} (90%) delete mode 100644 deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/WorkspaceIT.java diff --git a/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/ServiceIT.java b/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/WorkpacesIT.java similarity index 90% rename from deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/ServiceIT.java rename to deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/WorkpacesIT.java index 28b006a8ff..988085d6b6 100644 --- a/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/ServiceIT.java +++ b/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/WorkpacesIT.java @@ -69,21 +69,15 @@ Occam Labs UG (haftungsbeschränkt) * @version $Revision$, $Date$ */ @RunWith(Parameterized.class) -public class ServiceIT { +public class WorkpacesIT { - private static final Logger LOG = getLogger( ServiceIT.class ); + private static final Logger LOG = getLogger( WorkpacesIT.class ); private final Path workspaceUnderTest; - private boolean testCapabilities = true; - - private boolean testLayers = true; - - private boolean testRequests = true; - private static final TestEnvironment env = new TestEnvironment( System.getProperties() ); - public ServiceIT( Path workspaceUnderTest ) { + public WorkpacesIT( Path workspaceUnderTest ) { this.workspaceUnderTest = workspaceUnderTest; } @@ -130,9 +124,6 @@ public void execute() for ( Path service : serviceList ) { testService( helper, service ); } - if ( testRequests ) { - helper.testRequests(); - } } } catch ( NoClassDefFoundError e ) { LOG.warn( "Class not found, not performing any tests." ); @@ -144,13 +135,9 @@ private void testService( ServiceIntegrationTestHelper helper, Path service ) 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." ); - } + helper.testCapabilities( serviceType ); + helper.testLayers( serviceType ); + LOG.info( "All maps can be requested." ); } private boolean isService( Path f ) { diff --git a/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/WorkspaceIT.java b/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/WorkspaceIT.java deleted file mode 100644 index bc4b0c22d1..0000000000 --- a/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/WorkspaceIT.java +++ /dev/null @@ -1,145 +0,0 @@ -/*---------------------------------------------------------------------------- - This file is part of deegree, http://deegree.org/ - Copyright (C) 2001-2010 by: - - Department of Geography, University of Bonn - - and - - lat/lon GmbH - - - This library is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free - Software Foundation; either version 2.1 of the License, or (at your option) - any later version. - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. - You should have received a copy of the GNU Lesser General Public License - along with this library; if not, write to the Free Software Foundation, Inc., - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Contact information: - - lat/lon GmbH - Aennchenstr. 19, 53177 Bonn - Germany - http://lat-lon.de/ - - Department of Geography, University of Bonn - Prof. Dr. Klaus Greve - Postfach 1147, 53001 Bonn - Germany - http://www.geographie.uni-bonn.de/deegree/ - - Occam Labs UG (haftungsbeschränkt) - Godesberger Allee 139, 53175 Bonn - Germany - http://www.occamlabs.de/ - - e-mail: info@deegree.org - ----------------------------------------------------------------------------*/ -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.client.methods.HttpPost; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.FileEntity; -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.slf4j.Logger; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import static org.deegree.commons.utils.net.HttpUtils.UTF8STRING; -import static org.deegree.commons.utils.net.HttpUtils.get; -import static org.slf4j.LoggerFactory.getLogger; - -/** - * - * @author Andreas Schmitz - * @author last edited by: $Author$ - * - * @version $Revision$, $Date$ - */ -public class WorkspaceIT { - - private static final Logger LOG = getLogger( WorkspaceIT.class ); - - private TestEnvironment env = new TestEnvironment( System.getProperties() ); - - public void execute() throws Exception { - List workspaces = new ArrayList(); - - ServiceIntegrationTestHelper helper = new ServiceIntegrationTestHelper( env ); - - for ( File workspace : workspaces ) { - LOG.info( "Testing workspace " + workspace.getAbsolutePath() ); - - String url = helper.createBaseURL() + "config/upload/iut.zip"; - File file = workspace; // TODO x-x---x-xx - try { - HttpClient client = HttpUtils.getAuthenticatedHttpClient( env ); - - LOG.info( "Sending against: " + helper.createBaseURL() + "config/delete/iut" ); - HttpGet get = new HttpGet( helper.createBaseURL() + "config/delete/iut" ); - HttpResponse resp = client.execute( get ); - String response = EntityUtils.toString( resp.getEntity(), "UTF-8" ).trim(); - LOG.info( "Response after initially deleting iut was: " + response ); - - LOG.info( "Sending against: " + helper.createBaseURL() + "config/restart" ); - get = new HttpGet( helper.createBaseURL() + "config/restart" ); - resp = client.execute( get ); - response = EntityUtils.toString( resp.getEntity(), "UTF-8" ).trim(); - LOG.info( "Response after initial restart was: " + response ); - - LOG.info( "Sending against: " + url ); - HttpPost post = new HttpPost( url ); - post.setEntity( new FileEntity( file, ContentType.APPLICATION_OCTET_STREAM ) ); - resp = client.execute( post ); - response = EntityUtils.toString( resp.getEntity() ).trim(); - LOG.info( "Response after uploading was: " + response ); - - LOG.info( "Sending against: " + helper.createBaseURL() + "config/restart/iut" ); - get = new HttpGet( helper.createBaseURL() + "config/restart/iut" ); - resp = client.execute( get ); - response = EntityUtils.toString( resp.getEntity(), "UTF-8" ).trim(); - LOG.info( "Response after starting workspace was: " + response ); - } catch ( IOException e ) { - throw new Exception( "Could not test workspace " + workspace.getName() + ": " - + e.getLocalizedMessage(), e ); - } - - try { - String s = get( UTF8STRING, helper.createBaseURL() + "config/list/iut/services/", null, "deegree", - "deegree" ); - String[] services = s.split( "\\s" ); - - for ( String srv : services ) { - String nm = new File( srv ).getName().toLowerCase(); - if ( nm.length() != 7 ) { - continue; - } - String service = nm.substring( 0, 3 ).toUpperCase(); - helper.testCapabilities( service ); - helper.testLayers( service ); - LOG.info( "All maps can be requested." ); - } - String response = get( UTF8STRING, helper.createBaseURL() + "config/delete/iut", null, "deegree", - "deegree" ).trim(); - LOG.info( "Response after finally deleting iut was: " + response ); - } catch ( Exception e ) { - LOG.error( e.getLocalizedMessage(), e ); - throw new Exception( "Could not test workspace " + workspace.getName() + ": " - + e.getLocalizedMessage(), e ); - } - } - } - -} - diff --git a/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/ithelper/ServiceIntegrationTestHelper.java b/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/ithelper/ServiceIntegrationTestHelper.java index 7c5f8b6bba..b261d99023 100644 --- a/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/ithelper/ServiceIntegrationTestHelper.java +++ b/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/ithelper/ServiceIntegrationTestHelper.java @@ -35,7 +35,6 @@ package org.deegree.maven.ithelper; import org.apache.commons.io.IOUtils; -import org.apache.commons.io.filefilter.SuffixFileFilter; import org.deegree.cs.CRSUtils; import org.deegree.cs.persistence.CRSManager; import org.deegree.geometry.Envelope; @@ -48,30 +47,21 @@ import javax.imageio.ImageIO; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; -import java.io.File; -import java.io.FileFilter; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.io.StringReader; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import static java.util.Collections.singletonList; -import static org.apache.commons.io.FileUtils.readFileToString; -import static org.apache.commons.io.IOUtils.closeQuietly; -import static org.apache.commons.io.IOUtils.toByteArray; -import static org.deegree.commons.utils.net.HttpUtils.STREAM; -import static org.deegree.commons.utils.net.HttpUtils.post; import static org.deegree.protocol.wms.WMSConstants.WMSRequestType.GetMap; import static org.slf4j.LoggerFactory.getLogger; /** - * + * * @author Andreas Schmitz * @author last edited by: $Author$ - * + * * @version $Revision$, $Date$ */ public class ServiceIntegrationTestHelper { @@ -156,97 +146,4 @@ public void testLayers( String service ) } } - public static double determineSimilarity( String name, InputStream in1, InputStream in2 ) - throws IOException, Exception { - try { - byte[] buf1 = toByteArray( in1 ); - byte[] buf2 = toByteArray( in2 ); - long equal = 0; - for ( int i = 0; i < buf1.length; ++i ) { - if ( i < buf2.length && buf1[i] == buf2[i] ) { - ++equal; - } - } - double sim = (double) equal / (double) buf1.length; - if ( sim < 0.99 ) { - throw new Exception( "Request test " + name + " resulted in a similarity of only " + sim - + "!" ); - } - return sim; - } finally { - closeQuietly( in1 ); - closeQuietly( in2 ); - } - } - - public void testRequests() - throws Exception { - String address = createBaseURL() + "services"; - - File reqDir = new File( environment.getBasedir(), "src/test/requests" ); - LOG.info( "---- Searching main requests directory for requests." ); - testRequestDirectories( address, reqDir ); - } - - public void testRequestDirectories( String address, File dir ) - throws Exception { - testRequestDirectory( address, dir ); - File[] listed = dir.listFiles(); - if ( listed != null ) { - for ( File f : listed ) { - if ( f.isDirectory() && !f.getName().equalsIgnoreCase( ".svn" ) ) { - LOG.info( "---- Searching request class " + f.getName() + " for requests." ); - testRequestDirectories( address, f ); - } - } - } - } - - public void testRequestDirectory( String address, File dir ) - throws Exception { - File[] listed = dir.listFiles( (FileFilter) new SuffixFileFilter( "kvp" ) ); - if ( listed != null ) { - for ( File f : listed ) { - String name = f.getName(); - name = name.substring( 0, name.length() - 4 ); - LOG.info( "KVP request testing " + name ); - try { - String req = readFileToString( f ).trim(); - InputStream in1 = new URL( address + ( req.startsWith( "?" ) ? "" : "?" ) + req ).openStream(); - File response = new File( f.getParentFile(), name + ".response" ); - InputStream in2 = new FileInputStream( response ); - double sim = determineSimilarity( name, in1, in2 ); - if ( sim != 1 ) { - LOG.info( "Request test " + name + " resulted in similarity of " + sim ); - } - } catch ( IOException e ) { - throw new Exception( "KVP request checking of " + name + " failed: " - + e.getLocalizedMessage(), e ); - } - } - } - listed = dir.listFiles( (FileFilter) new SuffixFileFilter( "xml" ) ); - if ( listed != null ) { - for ( File f : listed ) { - String name = f.getName(); - name = name.substring( 0, name.length() - 4 ); - LOG.info( "XML request testing " + name ); - FileInputStream reqIn = null; - try { - reqIn = new FileInputStream( f ); - InputStream in1 = post( STREAM, address, reqIn, null ); - File response = new File( f.getParentFile(), name + ".response" ); - InputStream in2 = new FileInputStream( response ); - double sim = determineSimilarity( name, in1, in2 ); - LOG.info( "Request test " + name + " resulted in similarity of " + sim ); - } catch ( IOException e ) { - throw new Exception( "KVP request checking of " + name + " failed: " - + e.getLocalizedMessage(), e ); - } finally { - closeQuietly( reqIn ); - } - } - } - } - } diff --git a/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/ithelper/TestEnvironment.java b/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/ithelper/TestEnvironment.java index af7ff5b005..9fc869f68e 100644 --- a/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/ithelper/TestEnvironment.java +++ b/deegree-tests/deegree-workspace-tests/src/test/java/org/deegree/maven/ithelper/TestEnvironment.java @@ -40,20 +40,18 @@ Occam Labs UG (haftungsbeschränkt) package org.deegree.maven.ithelper; -import org.deegree.cs.persistence.CRSManager; - import java.util.Properties; public class TestEnvironment { private Properties properties; - public TestEnvironment(Properties properties) { + public TestEnvironment( Properties properties ) { this.properties = properties; } public String getPort() { - String port = properties.getProperty( "portnumber" , "8080"); + String port = properties.getProperty( "portnumber", "8080" ); return port; } @@ -62,11 +60,6 @@ public String getContext() { return context; } - public String getBasedir() { - String basedir = properties.getProperty( "basedir" ); - return basedir; - } - public String getWorkspaceDir() { return properties.getProperty( "workspaceDir" ); }