You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RepositoryURLTest.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package org.apache.archiva.maven.repository;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import junit.framework.TestCase;
  20. import org.apache.archiva.model.RepositoryURL;
  21. import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
  22. import org.junit.Test;
  23. import org.junit.runner.RunWith;
  24. import java.net.MalformedURLException;
  25. /**
  26. * RepositoryURLTest
  27. *
  28. *
  29. */
  30. @RunWith( ArchivaBlockJUnit4ClassRunner.class )
  31. public class RepositoryURLTest
  32. extends TestCase
  33. {
  34. private void assertURL( String actualURL, String protocol, String username, String password, String hostname,
  35. String port, String path )
  36. {
  37. RepositoryURL url = new RepositoryURL( actualURL );
  38. assertEquals( protocol, url.getProtocol() );
  39. assertEquals( username, url.getUsername() );
  40. assertEquals( password, url.getPassword() );
  41. assertEquals( hostname, url.getHost() );
  42. assertEquals( port, url.getPort() );
  43. assertEquals( path, url.getPath() );
  44. }
  45. @Test
  46. public void testProtocolHttp()
  47. throws MalformedURLException
  48. {
  49. assertURL( "http://localhost/path/to/resource.txt", "http", null, null, "localhost", null,
  50. "/path/to/resource.txt" );
  51. }
  52. @Test
  53. public void testProtocolWagonWebdav()
  54. throws MalformedURLException
  55. {
  56. assertURL( "dav:http://localhost/path/to/resource.txt", "dav:http", null, null, "localhost", null,
  57. "/path/to/resource.txt" );
  58. }
  59. @Test
  60. public void testProtocolHttpWithPort()
  61. throws MalformedURLException
  62. {
  63. assertURL( "http://localhost:9090/path/to/resource.txt", "http", null, null, "localhost", "9090",
  64. "/path/to/resource.txt" );
  65. }
  66. @Test
  67. public void testProtocolHttpWithUsername()
  68. throws MalformedURLException
  69. {
  70. assertURL( "http://user@localhost/path/to/resource.txt", "http", "user", null, "localhost", null,
  71. "/path/to/resource.txt" );
  72. }
  73. @Test
  74. public void testProtocolHttpWithUsernamePassword()
  75. throws MalformedURLException
  76. {
  77. assertURL( "http://user:pass@localhost/path/to/resource.txt", "http", "user", "pass", "localhost", null,
  78. "/path/to/resource.txt" );
  79. }
  80. @Test
  81. public void testProtocolHttpWithUsernamePasswordPort()
  82. throws MalformedURLException
  83. {
  84. assertURL( "http://user:pass@localhost:9090/path/to/resource.txt", "http", "user", "pass", "localhost", "9090",
  85. "/path/to/resource.txt" );
  86. }
  87. }