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.

ArtifactBuilderTest.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package org.apache.archiva.rest.services.utils;
  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 org.apache.archiva.common.filelock.DefaultFileLockManager;
  21. import org.apache.archiva.repository.storage.fs.FilesystemAsset;
  22. import org.apache.archiva.repository.storage.fs.FilesystemStorage;
  23. import org.apache.archiva.repository.storage.StorageAsset;
  24. import org.junit.Test;
  25. import org.mockito.InjectMocks;
  26. import java.io.IOException;
  27. import java.nio.file.Path;
  28. import java.nio.file.Paths;
  29. import static org.assertj.core.api.Assertions.assertThat;
  30. public class ArtifactBuilderTest
  31. {
  32. @InjectMocks
  33. private ArtifactBuilder builder = new ArtifactBuilder();
  34. StorageAsset getFile(String path) throws IOException {
  35. Path filePath = Paths.get(path);
  36. FilesystemStorage filesystemStorage = new FilesystemStorage(filePath.getParent(), new DefaultFileLockManager());
  37. return new FilesystemAsset(filesystemStorage, filePath.getFileName().toString(), filePath);
  38. }
  39. @Test
  40. public void testBuildSnapshot() throws IOException {
  41. assertThat( builder.getExtensionFromFile( getFile( "/tmp/foo-2.3-20141119.064321-40.jar" ) ) ).isEqualTo( "jar" );
  42. }
  43. @Test
  44. public void testBuildPom() throws IOException {
  45. assertThat( builder.getExtensionFromFile( getFile( "/tmp/foo-1.0.pom" ) ) ).isEqualTo( "pom" );
  46. }
  47. @Test
  48. public void testBuildJar() throws IOException {
  49. assertThat( builder.getExtensionFromFile( getFile( "/tmp/foo-1.0-sources.jar" ) ) ).isEqualTo( "jar" );
  50. }
  51. @Test
  52. public void testBuildTarGz() throws IOException {
  53. assertThat( builder.getExtensionFromFile( getFile( "/tmp/foo-1.0.tar.gz" ) ) ).isEqualTo( "tar.gz" );
  54. }
  55. @Test
  56. public void testBuildPomZip() throws IOException {
  57. assertThat( builder.getExtensionFromFile( getFile( "/tmp/foo-1.0.pom.zip" ) ) ).isEqualTo( "pom.zip" );
  58. }
  59. @Test
  60. public void testBuildR00() throws IOException {
  61. assertThat( builder.getExtensionFromFile( getFile( "/tmp/foo-1.0.r00" ) ) ).isEqualTo( "r00" );
  62. }
  63. }