Search in sources :

Example 1 with TestDecoratorAdvisor

use of org.commonjava.maven.galley.io.checksum.testutil.TestDecoratorAdvisor in project galley by Commonjava.

the class ChecksummingTransferDecoratorTest method customChecksumReaderFilter.

@Test
public void customChecksumReaderFilter() throws Exception {
    String path = "my-path.txt";
    fixture.setDecorator(new ChecksummingTransferDecorator(new TestDecoratorAdvisor(), new DisabledChecksummingDecoratorAdvisor(), new SpecialPathManagerImpl(), metadataConsumer, new Md5GeneratorFactory()));
    fixture.initMissingComponents();
    fixture.getCache().startReporting();
    final Transfer txfr = fixture.getCache().getTransfer(new ConcreteResource(new SimpleLocation("test:uri"), path));
    File f = new File(temp.getRoot(), "cache/test:uri");
    f = new File(f, path);
    byte[] data = "This is a test with a bunch of data and some other stuff, in a big box sealed with chewing gum".getBytes();
    FileUtils.writeByteArrayToFile(f, data);
    EventMetadata em = new EventMetadata();
    logger.debug("Reading stream with EventMetadata advice: {}", em.get(DO_CHECKSUMS));
    assertRead(txfr, data, em, false, false);
    em = new EventMetadata().set(DO_CHECKSUMS, ChecksummingDecoratorAdvisor.ChecksumAdvice.CALCULATE_NO_WRITE);
    logger.debug("Reading stream with EventMetadata advice: {}", em.get(DO_CHECKSUMS));
    assertRead(txfr, data, em, false, true);
    logger.debug("Removing checksum metadata from consumer");
    metadataConsumer.removeMetadata(txfr);
    em = new EventMetadata().set(DO_CHECKSUMS, ChecksummingDecoratorAdvisor.ChecksumAdvice.CALCULATE_AND_WRITE);
    logger.debug("Reading stream with EventMetadata advice: {}", em.get(DO_CHECKSUMS));
    assertRead(txfr, data, em, true, true);
}
Also used : TestDecoratorAdvisor(org.commonjava.maven.galley.io.checksum.testutil.TestDecoratorAdvisor) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ChecksummingTransferDecorator(org.commonjava.maven.galley.io.ChecksummingTransferDecorator) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) File(java.io.File) SpecialPathManagerImpl(org.commonjava.maven.galley.io.SpecialPathManagerImpl) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Aggregations

File (java.io.File)1 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)1 ChecksummingTransferDecorator (org.commonjava.maven.galley.io.ChecksummingTransferDecorator)1 SpecialPathManagerImpl (org.commonjava.maven.galley.io.SpecialPathManagerImpl)1 TestDecoratorAdvisor (org.commonjava.maven.galley.io.checksum.testutil.TestDecoratorAdvisor)1 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)1 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)1 Transfer (org.commonjava.maven.galley.model.Transfer)1 Test (org.junit.Test)1