您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ArchivaDavResourceLocatorTest.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package org.apache.archiva.webdav;
  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. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import junit.framework.TestCase;
  21. import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
  22. import org.junit.Before;
  23. import org.junit.Test;
  24. import org.junit.runner.RunWith;
  25. /**
  26. */
  27. @RunWith( ArchivaBlockJUnit4ClassRunner.class )
  28. public class ArchivaDavResourceLocatorTest
  29. extends TestCase
  30. {
  31. ArchivaDavLocatorFactory factory;
  32. @Override
  33. @Before
  34. public void setUp()
  35. throws Exception
  36. {
  37. super.setUp();
  38. factory = new ArchivaDavLocatorFactory();
  39. }
  40. @Test
  41. public void testAvoidDoubleSlashInHref()
  42. throws Exception
  43. {
  44. String prefix = "http://myproxy/";
  45. String href = "/repository/internal/";
  46. ArchivaDavResourceLocator locator = getLocator( prefix, href );
  47. assertEquals( "internal", locator.getRepositoryId() );
  48. assertEquals( "", locator.getWorkspaceName() );
  49. assertEquals( "", locator.getWorkspacePath() );
  50. assertEquals( "http://myproxy/", locator.getPrefix() );
  51. assertEquals( "http://myproxy/repository/internal/", locator.getHref( false ) );
  52. assertEquals( "http://myproxy/repository/internal/", locator.getHref( true ) );
  53. assertEquals( "/repository/internal", locator.getResourcePath() );
  54. assertEquals( "/repository/internal", locator.getRepositoryPath() );
  55. }
  56. @Test
  57. public void testLocatorWithPrefixHref()
  58. throws Exception
  59. {
  60. String prefix = "http://myproxy/";
  61. String href = "/repository/internal";
  62. ArchivaDavResourceLocator locator = getLocator( prefix, href );
  63. assertEquals( "internal", locator.getRepositoryId() );
  64. assertEquals( "", locator.getWorkspaceName() );
  65. assertEquals( "", locator.getWorkspacePath() );
  66. assertEquals( "http://myproxy/", locator.getPrefix() );
  67. assertEquals( "http://myproxy/repository/internal", locator.getHref( false ) );
  68. assertEquals( "http://myproxy/repository/internal/", locator.getHref( true ) );
  69. assertEquals( "/repository/internal", locator.getResourcePath() );
  70. assertEquals( "/repository/internal", locator.getRepositoryPath() );
  71. }
  72. @Test
  73. public void testLocatorWithHrefThatContainsPrefix()
  74. throws Exception
  75. {
  76. String prefix = "http://myproxy/";
  77. String href = "http://myproxy/repository/internal";
  78. ArchivaDavResourceLocator locator = getLocator( prefix, href );
  79. assertEquals( "internal", locator.getRepositoryId() );
  80. assertEquals( "", locator.getWorkspaceName() );
  81. assertEquals( "", locator.getWorkspacePath() );
  82. assertEquals( "http://myproxy/", locator.getPrefix() );
  83. assertEquals( "http://myproxy/repository/internal", locator.getHref( false ) );
  84. assertEquals( "http://myproxy/repository/internal/", locator.getHref( true ) );
  85. assertEquals( "/repository/internal", locator.getResourcePath() );
  86. assertEquals( "/repository/internal", locator.getRepositoryPath() );
  87. }
  88. @Test
  89. public void testLocatorWithRootHref()
  90. throws Exception
  91. {
  92. String prefix = "http://myproxy/";
  93. String href = "/";
  94. ArchivaDavResourceLocator locator = getLocator( prefix, href );
  95. assertEquals( "", locator.getRepositoryId() );
  96. assertEquals( "", locator.getWorkspaceName() );
  97. assertEquals( "", locator.getWorkspacePath() );
  98. assertEquals( "http://myproxy/", locator.getPrefix() );
  99. assertEquals( "http://myproxy/", locator.getHref( false ) );
  100. assertEquals( "http://myproxy/", locator.getHref( true ) );
  101. assertEquals( "/", locator.getResourcePath() );
  102. assertEquals( "/", locator.getRepositoryPath() );
  103. }
  104. private ArchivaDavResourceLocator getLocator( String prefix, String href )
  105. {
  106. return (ArchivaDavResourceLocator) factory.createResourceLocator( prefix, href );
  107. }
  108. }