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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.repository.base.ArchivaRepositoryRegistry;
  27. import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
  28. import org.apache.commons.lang3.StringUtils;
  29. import org.junit.After;
  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.*;
  39. @RunWith( ArchivaSpringJUnit4ClassRunner.class )
  40. @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
  41. public abstract class AbstractArtifactConsumerTest
  42. {
  43. private Path repoLocation;
  44. protected KnownRepositoryContentConsumer consumer;
  45. @Inject
  46. protected ApplicationContext applicationContext;
  47. @Inject
  48. ArchivaConfiguration archivaConfiguration;
  49. ArchivaRepositoryRegistry repositoryRegistry;
  50. @Before
  51. public void setUp()
  52. throws Exception
  53. {
  54. FileType fileType =
  55. (FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
  56. assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
  57. fileType.addPattern( "**/*.xml" );
  58. archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("MD5");
  59. archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("SHA1");
  60. archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("SHA256");
  61. repoLocation = Paths.get( "target/test-" + getName() + "/test-repo" );
  62. repositoryRegistry = applicationContext.getBean( "repositoryRegistry", ArchivaRepositoryRegistry.class );
  63. assertNotNull( repositoryRegistry );
  64. }
  65. @After
  66. public void destroy() {
  67. repositoryRegistry.destroy();
  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. }