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();
}
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());
}
}
Aggregations