Search in sources :

Example 11 with InvalidRepositoryContentConsumer

use of org.apache.archiva.consumers.InvalidRepositoryContentConsumer in project archiva by apache.

the class RepositoryScannerTest method testTimestampRepositoryScanner.

@Test
public void testTimestampRepositoryScanner() throws Exception {
    ManagedRepository repository = createSimpleRepository();
    List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<>();
    KnownScanConsumer consumer = new KnownScanConsumer();
    consumer.setIncludes(ARTIFACT_PATTERNS);
    knownConsumers.add(consumer);
    List<InvalidRepositoryContentConsumer> invalidConsumers = new ArrayList<>();
    InvalidScanConsumer badconsumer = new InvalidScanConsumer();
    invalidConsumers.add(badconsumer);
    RepositoryScanner scanner = lookupRepositoryScanner();
    RepositoryScanStatistics stats = scanner.scan(repository, knownConsumers, invalidConsumers, getIgnoreList(), getTimestampAsMillis("20061101.000000"));
    assertNotNull("Stats should not be null.", stats);
    assertEquals("Stats.totalFileCount", 4, stats.getTotalFileCount());
    assertEquals("Stats.newFileCount", 3, stats.getNewFileCount());
    assertEquals("Processed Count", 2, consumer.getProcessCount());
    assertEquals("Processed Count (of invalid items)", 1, badconsumer.getProcessCount());
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) ArrayList(java.util.ArrayList) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer) Test(org.junit.Test)

Example 12 with InvalidRepositoryContentConsumer

use of org.apache.archiva.consumers.InvalidRepositoryContentConsumer in project archiva by apache.

the class RepositoryScannerTest method testDefaultRepositoryScanner.

@Test
public void testDefaultRepositoryScanner() throws Exception {
    ManagedRepository repository = createDefaultRepository();
    List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<>();
    KnownScanConsumer consumer = new KnownScanConsumer();
    consumer.setIncludes(new String[] { "**/*.jar", "**/*.war", "**/*.pom", "**/maven-metadata.xml", "**/*-site.xml", "**/*.zip", "**/*.tar.gz", "**/*.sha1", "**/*.md5" });
    knownConsumers.add(consumer);
    List<InvalidRepositoryContentConsumer> invalidConsumers = new ArrayList<>();
    InvalidScanConsumer badconsumer = new InvalidScanConsumer();
    invalidConsumers.add(badconsumer);
    RepositoryScanner scanner = lookupRepositoryScanner();
    RepositoryScanStatistics stats = scanner.scan(repository, knownConsumers, invalidConsumers, getIgnoreList(), RepositoryScanner.FRESH_SCAN);
    assertNotNull("Stats should not be null.", stats);
    assertMinimumHits("Stats.totalFileCount", 17, stats.getTotalFileCount());
    assertMinimumHits("Processed Count", 17, consumer.getProcessCount());
    assertEquals("Processed Count (of invalid items):" + badconsumer.getPaths(), 6, badconsumer.getProcessCount());
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) ArrayList(java.util.ArrayList) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer) Test(org.junit.Test)

Example 13 with InvalidRepositoryContentConsumer

use of org.apache.archiva.consumers.InvalidRepositoryContentConsumer in project archiva by apache.

the class RepositoryScannerTest method testDefaultRepositoryProjectScanner.

@Test
public void testDefaultRepositoryProjectScanner() throws Exception {
    List<String> actualProjectPaths = new ArrayList<>();
    actualProjectPaths.add("org/apache/maven/A/1.0/A-1.0.pom");
    actualProjectPaths.add("org/apache/maven/B/2.0/B-2.0.pom");
    actualProjectPaths.add("org/apache/maven/B/1.0/B-1.0.pom");
    actualProjectPaths.add("org/apache/maven/C/1.0/C-1.0.pom");
    actualProjectPaths.add("org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.pom");
    actualProjectPaths.add("org/apache/maven/update/test-updated/1.0/test-updated-1.0.pom");
    actualProjectPaths.add("org/apache/maven/discovery/1.0/discovery-1.0.pom");
    actualProjectPaths.add("org/apache/maven/samplejar/2.0/samplejar-2.0.pom");
    actualProjectPaths.add("org/apache/maven/samplejar/1.0/samplejar-1.0.pom");
    actualProjectPaths.add("org/apache/testgroup/discovery/1.0/discovery-1.0.pom");
    ManagedRepository repository = createDefaultRepository();
    List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<>();
    KnownScanConsumer consumer = new KnownScanConsumer();
    consumer.setIncludes(new String[] { "**/*.pom" });
    knownConsumers.add(consumer);
    List<InvalidRepositoryContentConsumer> invalidConsumers = new ArrayList<>();
    InvalidScanConsumer badconsumer = new InvalidScanConsumer();
    invalidConsumers.add(badconsumer);
    RepositoryScanner scanner = lookupRepositoryScanner();
    RepositoryScanStatistics stats = scanner.scan(repository, knownConsumers, invalidConsumers, getIgnoreList(), RepositoryScanner.FRESH_SCAN);
    assertNotNull("Stats should not be null.", stats);
    assertMinimumHits("Stats.totalFileCount", actualProjectPaths.size(), stats.getTotalFileCount());
    assertMinimumHits("Processed Count", actualProjectPaths.size(), consumer.getProcessCount());
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) ArrayList(java.util.ArrayList) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer) Test(org.junit.Test)

Example 14 with InvalidRepositoryContentConsumer

use of org.apache.archiva.consumers.InvalidRepositoryContentConsumer in project archiva by apache.

the class RepositoryContentConsumersTest method testGetSelectedInvalidConsumerMap.

@Test
public void testGetSelectedInvalidConsumerMap() throws Exception {
    RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();
    String[] expectedSelectedInvalidIds = new String[] { "update-db-bad-content" };
    Map<String, InvalidRepositoryContentConsumer> invalidConsumerMap = consumerutil.getSelectedInvalidConsumersMap();
    assertNotNull("Invalid Consumer Map should not be null", invalidConsumerMap);
    assertEquals("Invalid Consumer Map.size", expectedSelectedInvalidIds.length, invalidConsumerMap.size());
    for (String expectedId : expectedSelectedInvalidIds) {
        InvalidRepositoryContentConsumer consumer = invalidConsumerMap.get(expectedId);
        assertNotNull("Known[" + expectedId + "] should not be null.", consumer);
        assertEquals("Known[" + expectedId + "].id", expectedId, consumer.getId());
    }
}
Also used : InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer) Test(org.junit.Test)

Example 15 with InvalidRepositoryContentConsumer

use of org.apache.archiva.consumers.InvalidRepositoryContentConsumer in project archiva by apache.

the class RepositoryContentConsumersTest method testExecution.

@Test
public void testExecution() throws Exception {
    IMocksControl knownControl = createNiceControl();
    RepositoryContentConsumers consumers = lookupRepositoryConsumers();
    KnownRepositoryContentConsumer selectedKnownConsumer = knownControl.createMock(KnownRepositoryContentConsumer.class);
    KnownRepositoryContentConsumer unselectedKnownConsumer = createNiceControl().createMock(KnownRepositoryContentConsumer.class);
    consumers.setApplicationContext(new MockApplicationContext(Arrays.asList(selectedKnownConsumer, unselectedKnownConsumer), null));
    consumers.setSelectedKnownConsumers(Collections.singletonList(selectedKnownConsumer));
    IMocksControl invalidControl = createControl();
    InvalidRepositoryContentConsumer selectedInvalidConsumer = invalidControl.createMock(InvalidRepositoryContentConsumer.class);
    InvalidRepositoryContentConsumer unselectedInvalidConsumer = createControl().createMock(InvalidRepositoryContentConsumer.class);
    consumers.setApplicationContext(new MockApplicationContext(null, Arrays.asList(selectedInvalidConsumer, unselectedInvalidConsumer)));
    consumers.setSelectedInvalidConsumers(Collections.singletonList(selectedInvalidConsumer));
    ManagedRepository repo = createRepository("id", "name", Paths.get("target/test-repo"));
    Path testFile = Paths.get("target/test-repo/path/to/test-file.txt");
    Date startTime = new Date(System.currentTimeMillis());
    startTime.setTime(12345678);
    selectedKnownConsumer.beginScan(repo, startTime, false);
    expect(selectedKnownConsumer.getIncludes()).andReturn(Collections.singletonList("**/*.txt"));
    selectedKnownConsumer.processFile(_OS("path/to/test-file.txt"), false);
    knownControl.replay();
    selectedInvalidConsumer.beginScan(repo, startTime, false);
    invalidControl.replay();
    consumers.executeConsumers(repo, testFile, true);
    knownControl.verify();
    invalidControl.verify();
    knownControl.reset();
    invalidControl.reset();
    Path notIncludedTestFile = Paths.get("target/test-repo/path/to/test-file.xml");
    selectedKnownConsumer.beginScan(repo, startTime, false);
    expect(selectedKnownConsumer.getExcludes()).andReturn(Collections.<String>emptyList());
    expect(selectedKnownConsumer.getIncludes()).andReturn(Collections.singletonList("**/*.txt"));
    knownControl.replay();
    selectedInvalidConsumer.beginScan(repo, startTime, false);
    selectedInvalidConsumer.processFile(_OS("path/to/test-file.xml"), false);
    expect(selectedInvalidConsumer.getId()).andReturn("invalid");
    invalidControl.replay();
    consumers.executeConsumers(repo, notIncludedTestFile, true);
    knownControl.verify();
    invalidControl.verify();
    knownControl.reset();
    invalidControl.reset();
    Path excludedTestFile = Paths.get("target/test-repo/path/to/test-file.txt");
    selectedKnownConsumer.beginScan(repo, startTime, false);
    expect(selectedKnownConsumer.getExcludes()).andReturn(Collections.singletonList("**/test-file.txt"));
    knownControl.replay();
    selectedInvalidConsumer.beginScan(repo, startTime, false);
    selectedInvalidConsumer.processFile(_OS("path/to/test-file.txt"), false);
    expect(selectedInvalidConsumer.getId()).andReturn("invalid");
    invalidControl.replay();
    consumers.executeConsumers(repo, excludedTestFile, true);
    knownControl.verify();
    invalidControl.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.repository.ManagedRepository) BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) Date(java.util.Date) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer) Test(org.junit.Test)

Aggregations

InvalidRepositoryContentConsumer (org.apache.archiva.consumers.InvalidRepositoryContentConsumer)15 ArrayList (java.util.ArrayList)12 KnownRepositoryContentConsumer (org.apache.archiva.consumers.KnownRepositoryContentConsumer)12 BasicManagedRepository (org.apache.archiva.repository.BasicManagedRepository)11 Test (org.junit.Test)11 ManagedRepository (org.apache.archiva.repository.ManagedRepository)9 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)8 Path (java.nio.file.Path)2 RepositoryScannerException (org.apache.archiva.repository.scanner.RepositoryScannerException)2 Date (java.util.Date)1 BaseFile (org.apache.archiva.common.utils.BaseFile)1 RepositoryContentConsumer (org.apache.archiva.consumers.RepositoryContentConsumer)1 ConsumerWantsFilePredicate (org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate)1 RepositoryConversionException (org.apache.archiva.converter.RepositoryConversionException)1 RepositoryScanStatistics (org.apache.archiva.repository.scanner.RepositoryScanStatistics)1 RepositoryScanner (org.apache.archiva.repository.scanner.RepositoryScanner)1 ConsumerProcessFileClosure (org.apache.archiva.repository.scanner.functors.ConsumerProcessFileClosure)1 TriggerBeginScanClosure (org.apache.archiva.repository.scanner.functors.TriggerBeginScanClosure)1 TriggerScanCompletedClosure (org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1