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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.annotation.DirtiesContext;
  35. import org.springframework.test.context.ContextConfiguration;
  36. import javax.inject.Inject;
  37. import java.nio.file.Path;
  38. import java.nio.file.Paths;
  39. import static org.junit.Assert.*;
  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. @Before
  51. public void setUp()
  52. throws Exception
  53. {
  54. FileType fileType =
  55. 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. }
  63. @SuppressWarnings( "deprecation" )
  64. @Test
  65. public void testConsumption()
  66. {
  67. Path localFile =
  68. repoLocation.resolve( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" );
  69. ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
  70. BaseFile baseFile = new BaseFile( repoLocation.toFile(), localFile.toFile() );
  71. predicate.setBasefile( baseFile );
  72. assertFalse( predicate.evaluate( consumer ) );
  73. }
  74. @SuppressWarnings( "deprecation" )
  75. @Test
  76. public void testConsumptionOfOtherMetadata()
  77. {
  78. Path localFile =
  79. repoLocation.resolve( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" );
  80. ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
  81. BaseFile baseFile = new BaseFile( repoLocation.toFile(), localFile.toFile() );
  82. predicate.setBasefile( baseFile );
  83. assertFalse( predicate.evaluate( consumer ) );
  84. }
  85. public String getName()
  86. {
  87. return StringUtils.substringAfterLast( getClass().getName(), "." );
  88. }
  89. }