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 3.5KB

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