View Javadoc
1   package org.apache.archiva.webdav;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import com.gargoylesoftware.htmlunit.WebRequest;
23  import com.gargoylesoftware.htmlunit.WebResponse;
24  import org.apache.commons.io.FileUtils;
25  import org.junit.Before;
26  import org.junit.Test;
27  
28  import java.io.File;
29  import java.nio.charset.Charset;
30  
31  /**
32   * RepositoryServletTest
33   */
34  public class RepositoryServletNoProxyMetadataTest
35      extends AbstractRepositoryServletTestCase
36  {
37  
38      @Before
39      @Override
40      public void setUp() throws Exception
41      {
42          super.setUp();
43          startRepository();
44      }
45  
46      @Test
47      public void testGetVersionMetadataDefaultLayout()
48          throws Exception
49      {
50          String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
51          String expectedMetadataContents = "metadata-for-commons-lang-version-2.1";
52  
53          File checksumFile = new File( repoRootInternal, commonsLangMetadata );
54          checksumFile.getParentFile().mkdirs();
55  
56          FileUtils.writeStringToFile( checksumFile, expectedMetadataContents, Charset.defaultCharset() );
57  
58          WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
59          WebResponse response = getServletUnitClient().getResponse( request );
60          assertResponseOK( response );
61  
62          assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
63      }
64  
65      @Test
66      public void testGetProjectMetadataDefaultLayout()
67          throws Exception
68      {
69          String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
70          String expectedMetadataContents = "metadata-for-commons-lang-version-for-project";
71  
72          File checksumFile = new File( repoRootInternal, commonsLangMetadata );
73          checksumFile.getParentFile().mkdirs();
74  
75          FileUtils.writeStringToFile( checksumFile, expectedMetadataContents, Charset.defaultCharset() );
76  
77          WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
78          WebResponse response = getServletUnitClient().getResponse( request );
79          assertResponseOK( response );
80  
81          assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
82      }
83  
84      @Test
85      public void testGetGroupMetadataDefaultLayout()
86          throws Exception
87      {
88          String commonsLangMetadata = "commons-lang/maven-metadata.xml";
89          String expectedMetadataContents = "metadata-for-commons-lang-group";
90  
91          File checksumFile = new File( repoRootInternal, commonsLangMetadata );
92          checksumFile.getParentFile().mkdirs();
93  
94          FileUtils.writeStringToFile( checksumFile, expectedMetadataContents, Charset.defaultCharset() );
95  
96          WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
97          WebResponse response = getServletUnitClient().getResponse( request );
98          assertResponseOK( response );
99  
100         assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
101     }
102 
103     @Test
104     public void testGetSnapshotVersionMetadataDefaultLayout()
105         throws Exception
106     {
107         String assemblyPluginMetadata =
108             "org/apache/maven/plugins/maven-assembly-plugin/2.2-beta-2-SNAPSHOT/maven-metadata.xml";
109         String expectedMetadataContents = "metadata-for-assembly-plugin-version-2.2-beta-2-SNAPSHOT";
110 
111         File checksumFile = new File( repoRootInternal, assemblyPluginMetadata );
112         checksumFile.getParentFile().mkdirs();
113 
114         FileUtils.writeStringToFile( checksumFile, expectedMetadataContents, Charset.defaultCharset() );
115 
116         WebRequest request =
117             new GetMethodWebRequest( "http://machine.com/repository/internal/" + assemblyPluginMetadata );
118         WebResponse response = getServletUnitClient().getResponse( request );
119         assertResponseOK( response );
120 
121         assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
122     }
123 
124 }