From 9356efc2b14b75f936970938a35f3ecd7c7f0a71 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 16 Feb 2015 21:59:08 +1100 Subject: [PATCH] add unit test for both MRM-935 and MRM-837 --- .../AbstractRepositoryServletTestCase.java | 8 ++-- .../webdav/RepositoryServletDeployTest.java | 42 +++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java index a9beb5273..9b7ae9068 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java @@ -479,7 +479,7 @@ public abstract class AbstractRepositoryServletTestCase request.setMethod( webRequest.getHttpMethod().name() ); - if (webRequest.getHttpMethod() == HttpMethod.PUT ) + if ( webRequest.getHttpMethod() == HttpMethod.PUT ) { PutMethodWebRequest putRequest = PutMethodWebRequest.class.cast( webRequest ); request.setContentType( putRequest.contentType ); @@ -497,7 +497,7 @@ public abstract class AbstractRepositoryServletTestCase || response.getStatus() == HttpServletResponse.SC_MOVED_TEMPORARILY ) { String location = response.getHeader( "Location" ); - log.debug("follow redirect to {}", location); + log.debug( "follow redirect to {}", location ); return getWebResponse( new GetMethodWebRequest( location ) ); } @@ -660,9 +660,9 @@ public abstract class AbstractRepositoryServletTestCase protected void assertResponseOK( WebResponse response ) { - assertNotNull( "Should have recieved a response", response ); - Assert.assertEquals( "Should have been an OK response code", HttpServletResponse.SC_OK, + Assert.assertEquals( "Should have been an OK response code", // + HttpServletResponse.SC_OK, // response.getStatusCode() ); } diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletDeployTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletDeployTest.java index 591a39db5..400090d88 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletDeployTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletDeployTest.java @@ -240,6 +240,48 @@ public class RepositoryServletDeployTest File mkColLocalPath = new File(repoRootInternal, "path/to/"); assertFalse(mkColLocalPath.exists()); } + + @Test + public void testArtifactsDeploymentArtifactIsSnapshot() + throws Exception + { + setupCleanRepo( repoRootInternal ); + + String putUrl = "http://machine.com/repository/internal/path/to/artifact/SNAPSHOT/artifact-SNAPSHOT.jar"; + String metadataUrl = "http://machine.com/repository/internal/path/to/artifact/maven-metadata.xml"; + String checksumUrl = "http://machine.com/repository/internal/path/to/artifact/SNAPSHOT/artifact-SNAPSHOT.jar.sha1"; + + InputStream is = getClass().getResourceAsStream( "/artifact.jar" ); + // verify that the file exists in resources-dir + assertNotNull( "artifact.jar inputstream", is ); + + // send request #1 and verify it's successful + WebRequest request = new PutMethodWebRequest( putUrl, is, "application/octet-stream" ); + WebResponse response = getServletUnitClient().getResponse( request ); + assertResponseCreated( response ); + + is = getClass().getResourceAsStream( "/artifact.jar.sha1" ); + request = new PutMethodWebRequest( checksumUrl, is, "application/octet-stream" ); + response = getServletUnitClient().getResponse( request ); + assertResponseCreated( response ); + + is = getClass().getResourceAsStream( "/maven-metadata.xml" ); + request = new PutMethodWebRequest( metadataUrl, is, "application/octet-stream" ); + response = getServletUnitClient().getResponse( request ); + assertResponseCreated( response ); + + // send request #2 and verify it's re-deployed + is = getClass().getResourceAsStream( "/artifact.jar" ); + request = new PutMethodWebRequest( putUrl, is, "application/octet-stream" ); + response = getServletUnitClient().getResponse( request ); + assertResponseNoContent( response ); + + request = new GetMethodWebRequest( putUrl ); + response = getServletUnitClient().getResponse( request ); + assertResponseOK( response ); + + + } protected void assertResponseNoContent( WebResponse response ) { -- 2.39.5