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.

AbstractArtifactConsumerTest.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package org.apache.archiva.consumers.core;
  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.utils.BaseFile;
  21. import org.apache.archiva.configuration.provider.ArchivaConfiguration;
  22. import org.apache.archiva.configuration.model.FileType;
  23. import org.apache.archiva.configuration.provider.FileTypes;
  24. import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
  25. import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate;
  26. import org.apache.archiva.repository.RepositoryRegistry;
  27. import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
  28. import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
  29. import org.apache.commons.lang3.StringUtils;
  30. import org.junit.Before;
  31. import org.junit.Test;
  32. import org.junit.runner.RunWith;
  33. import org.springframework.context.ApplicationContext;
  34. import org.springframework.test.context.ContextConfiguration;
  35. import javax.inject.Inject;
  36. import java.nio.file.Path;
  37. import java.nio.file.Paths;
  38. import static org.junit.Assert.assertEquals;
  39. import static org.junit.Assert.assertFalse;
  40. @RunWith( ArchivaSpringJUnit4ClassRunner.class )
  41. @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
  42. public abstract class AbstractArtifactConsumerTest
  43. {
  44. private Path repoLocation;
  45. protected KnownRepositoryContentConsumer consumer;
  46. @Inject
  47. protected ApplicationContext applicationContext;
  48. @Inject
  49. ArchivaConfiguration archivaConfiguration;
  50. @SuppressWarnings( "unused" )
  51. @Inject
  52. RepositoryRegistry repositoryRegistry;
  53. @SuppressWarnings( "unused" )
  54. @Inject
  55. RepositoryHandlerDependencies repositoryHandlerDependencies;
  56. @Before
  57. public void setUp()
  58. throws Exception
  59. {
  60. FileType fileType =
  61. archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
  62. assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
  63. fileType.addPattern( "**/*.xml" );
  64. archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("MD5");
  65. archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("SHA1");
  66. archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("SHA256");
  67. repoLocation = Paths.get( "target/test-" + getName() + "/test-repo" );
  68. }
  69. @SuppressWarnings( "deprecation" )
  70. @Test
  71. public void testConsumption()
  72. {
  73. Path localFile =
  74. repoLocation.resolve( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" );
  75. ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
  76. BaseFile baseFile = new BaseFile( repoLocation.toFile(), localFile.toFile() );
  77. predicate.setBasefile( baseFile );
  78. assertFalse( predicate.evaluate( consumer ) );
  79. }
  80. @SuppressWarnings( "deprecation" )
  81. @Test
  82. public void testConsumptionOfOtherMetadata()
  83. {
  84. Path localFile =
  85. repoLocation.resolve( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" );
  86. ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
  87. BaseFile baseFile = new BaseFile( repoLocation.toFile(), localFile.toFile() );
  88. predicate.setBasefile( baseFile );
  89. assertFalse( predicate.evaluate( consumer ) );
  90. }
  91. public String getName()
  92. {
  93. return StringUtils.substringAfterLast( getClass().getName(), "." );
  94. }
  95. }