123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- package org.apache.archiva.webdav;
-
- /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
- import com.gargoylesoftware.htmlunit.WebRequest;
- import com.gargoylesoftware.htmlunit.WebResponse;
- import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
- import org.apache.archiva.webdav.mock.httpunit.MkColMethodWebRequest;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
-
- import javax.servlet.http.HttpServletResponse;
- import java.io.InputStream;
- import java.nio.file.Files;
- import java.nio.file.Path;
-
-
- /**
- * Deploy / Put Test cases for RepositoryServlet.
- *
- *
- */
- public class RepositoryServletDeployTest
- extends AbstractRepositoryServletTestCase
- {
- private static final String ARTIFACT_DEFAULT_LAYOUT = "/path/to/artifact/1.0.0/artifact-1.0.0.jar";
-
- @Before
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- startRepository();
- }
-
- @Override
- @After
- public void tearDown( ) throws Exception
- {
- super.tearDown( );
- }
-
- @Test
- public void testPutWithMissingParentCollection()
- throws Exception
- {
- setupCleanRepo( repoRootInternal );
-
- String putUrl = "http://machine.com/repository/internal" + ARTIFACT_DEFAULT_LAYOUT;
- InputStream is = getClass().getResourceAsStream( "/artifact.jar" );
- // verify that the file exists in resources-dir
- assertNotNull( "artifact.jar inputstream", is );
-
- WebRequest request = new PutMethodWebRequest( putUrl, is, "application/octet-stream" );
-
- WebResponse response = getServletUnitClient().getResponse( request );
- assertResponseCreated( response );
- assertFileContents( "artifact.jar\n", repoRootInternal, ARTIFACT_DEFAULT_LAYOUT );
- }
-
- /**
- * MRM-747
- * test whether trying to overwrite existing relase-artifact is blocked by returning HTTP-code 409
- *
- * @throws Exception
- */
- @Test
- public void testReleaseArtifactsRedeploymentValidPath()
- throws Exception
- {
- setupCleanRepo( repoRootInternal );
-
- String putUrl = "http://machine.com/repository/internal" + ARTIFACT_DEFAULT_LAYOUT;
- String metadataUrl = "http://machine.com/repository/internal/path/to/artifact/maven-metadata.xml";
- String checksumUrl = "http://machine.com/repository/internal" + ARTIFACT_DEFAULT_LAYOUT + ".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 blocked
- is = getClass().getResourceAsStream( "/artifact.jar" );
- request = new PutMethodWebRequest( putUrl, is, "application/octet-stream" );
- response = getServletUnitClient().getResponse( request );
- assertResponseConflictError( response );
- }
-
- @Test
- public void testReleaseArtifactsRedeploymentIsAllowed()
- throws Exception
- {
- setupCleanRepo( repoRootInternal );
-
- ManagedRepositoryConfiguration managedRepo = archivaConfiguration.getConfiguration().findManagedRepositoryById( REPOID_INTERNAL );
- managedRepo.setBlockRedeployments( false );
-
- saveConfiguration( archivaConfiguration );
-
- String putUrl = "http://machine.com/repository/internal" + ARTIFACT_DEFAULT_LAYOUT;
- String metadataUrl = "http://machine.com/repository/internal/path/to/artifact/maven-metadata.xml";
- String checksumUrl = "http://machine.com/repository/internal" + ARTIFACT_DEFAULT_LAYOUT + ".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 if it's still successful
- is = getClass().getResourceAsStream( "/artifact.jar" );
- request = new PutMethodWebRequest( putUrl, is, "application/octet-stream" );
- response = getServletUnitClient().getResponse( request );
- assertResponseNoContent( response );
- }
-
- @Test
- public void testReleaseArtifactsRedeploymentInvalidPath()
- throws Exception
- {
- setupCleanRepo( repoRootInternal );
-
- String putUrl = "http://machine.com/repository/internal/artifact.jar";
- String metadataUrl = "http://machine.com/repository/internal/maven-metadata.xml";
- String checksumUrl = "http://machine.com/repository/internal/artifact.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 );
- }
-
- @Test
- public void testReleaseArtifactsRedeploymentArtifactIsSnapshot()
- throws Exception
- {
- setupCleanRepo( repoRootInternal );
-
- String putUrl = "http://machine.com/repository/internal/path/to/artifact/1.0-SNAPSHOT/artifact-1.0-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/1.0-SNAPSHOT/artifact-1.0-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 );
- }
-
- @Test
- public void testMkColWithMissingParentCollectionFails()
- throws Exception
- {
- setupCleanRepo( repoRootInternal );
-
- String putUrl = "http://machine.com/repository/internal/path/to/";
-
- WebRequest request = new MkColMethodWebRequest( putUrl );
-
- WebResponse response = getServletUnitClient().getResponse( request );
-
- assertEquals(HttpServletResponse.SC_CONFLICT, response.getStatusCode());
-
- Path mkColLocalPath = repoRootInternal.resolve( "path/to/");
- assertFalse( Files.exists(mkColLocalPath));
- }
-
- @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 )
- {
- assertNotNull( "Should have recieved a response", response );
- assertEquals( "Should have been a 204/NO CONTENT response code.", HttpServletResponse.SC_NO_CONTENT, response
- .getStatusCode() );
- }
-
- protected void assertResponseCreated( WebResponse response )
- {
- assertNotNull( "Should have recieved a response", response );
- assertEquals( "Should have been a 201/CREATED response code.", HttpServletResponse.SC_CREATED, response
- .getStatusCode() );
- }
- }
|