Search in sources :

Example 21 with KnownRepositoryContentConsumer

use of org.apache.archiva.consumers.KnownRepositoryContentConsumer 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)

Example 22 with KnownRepositoryContentConsumer

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

the class RepositoryContentConsumersTest method testGetSelectedKnownConsumerMap.

@Test
public void testGetSelectedKnownConsumerMap() throws Exception {
    RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();
    String[] expectedSelectedKnownIds = new String[] { "create-missing-checksums", "validate-checksum", "index-content", "auto-remove", "auto-rename" };
    Map<String, KnownRepositoryContentConsumer> knownConsumerMap = consumerutil.getSelectedKnownConsumersMap();
    assertNotNull("Known Consumer Map should not be null", knownConsumerMap);
    assertEquals("Known Consumer Map.size but " + knownConsumerMap, expectedSelectedKnownIds.length, knownConsumerMap.size());
    for (String expectedId : expectedSelectedKnownIds) {
        KnownRepositoryContentConsumer consumer = knownConsumerMap.get(expectedId);
        assertNotNull("Known[" + expectedId + "] should not be null.", consumer);
        assertEquals("Known[" + expectedId + "].id", expectedId, consumer.getId());
    }
}
Also used : KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) Test(org.junit.Test)

Aggregations

KnownRepositoryContentConsumer (org.apache.archiva.consumers.KnownRepositoryContentConsumer)22 Test (org.junit.Test)15 InvalidRepositoryContentConsumer (org.apache.archiva.consumers.InvalidRepositoryContentConsumer)13 ArrayList (java.util.ArrayList)12 BasicManagedRepository (org.apache.archiva.repository.BasicManagedRepository)12 ManagedRepository (org.apache.archiva.repository.ManagedRepository)9 Path (java.nio.file.Path)8 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)8 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)4 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)4 HashSet (java.util.HashSet)2 BaseFile (org.apache.archiva.common.utils.BaseFile)2 RepositoryContentConsumer (org.apache.archiva.consumers.RepositoryContentConsumer)2 ConsumerWantsFilePredicate (org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate)2 RepositoryScannerException (org.apache.archiva.repository.scanner.RepositoryScannerException)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)1 FileType (org.apache.archiva.configuration.FileType)1