Search in sources :

Example 6 with IO.getFile

use of aQute.lib.io.IO.getFile in project bnd by bndtools.

the class FileRepoTest method testDownloadListenerCallback.

public void testDownloadListenerCallback() throws Exception {
    try {
        FileRepo repo = new FileRepo("tmp", tmp, true);
        File srcBundle = IO.getFile("testresources/test.jar");
        PutResult r = repo.put(IO.stream(IO.getFile("testresources/test.jar")), null);
        assertNotNull(r);
        assertNotNull(r.artifact);
        // file repo, so should match
        File f = new File(r.artifact);
        SHA1 sha1 = SHA1.digest(srcBundle);
        sha1.equals(SHA1.digest(f));
        DownloadListener mock = Mockito.mock(DownloadListener.class);
        f = repo.get("test", new Version("0"), null, mock);
        Mockito.verify(mock).success(f);
        Mockito.verifyNoMoreInteractions(mock);
        Mockito.reset(mock);
        f = repo.get("XXXXXXXXXXXXXXXXX", new Version("0"), null, mock);
        assertNull(f);
        Mockito.verifyZeroInteractions(mock);
    } finally {
        IO.delete(tmp);
    }
}
Also used : SHA1(aQute.libg.cryptography.SHA1) DownloadListener(aQute.bnd.service.RepositoryPlugin.DownloadListener) Version(aQute.bnd.version.Version) FileRepo(aQute.lib.deployer.FileRepo) IO.getFile(aQute.lib.io.IO.getFile) File(java.io.File) PutResult(aQute.bnd.service.RepositoryPlugin.PutResult)

Example 7 with IO.getFile

use of aQute.lib.io.IO.getFile in project bnd by bndtools.

the class FileRepoTest method setUp.

@Override
protected void setUp() throws Exception {
    File testRepoDir = IO.getFile("src/test/repo");
    assertTrue(testRepoDir.isDirectory());
    testRepo = createRepo(testRepoDir);
    File nonExistentDir = IO.getFile("invalidrepo");
    nonExistentDir.mkdir();
    nonExistentDir.setReadOnly();
    nonExistentRepo = createRepo(nonExistentDir);
    tmp = IO.getFile("tmp" + getName());
    tmp.mkdir();
    indexedRepo = createRepo(tmp, MAP.$("index", "true"));
}
Also used : IO.getFile(aQute.lib.io.IO.getFile) File(java.io.File)

Example 8 with IO.getFile

use of aQute.lib.io.IO.getFile in project bnd by bndtools.

the class FileRepoTest method testBundleNotModifiedOnPut.

public void testBundleNotModifiedOnPut() throws Exception {
    MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
    File dstBundle = null;
    try {
        File srcBundle = IO.getFile("testresources/test.jar");
        byte[] srcSha = calculateHash(sha1, srcBundle);
        PutOptions options = new RepositoryPlugin.PutOptions();
        options.digest = srcSha;
        PutResult r = testRepo.put(new BufferedInputStream(new FileInputStream(srcBundle)), options);
        dstBundle = new File(r.artifact);
        assertEquals(hashToString(srcSha), hashToString(r.digest));
        assertTrue(MessageDigest.isEqual(srcSha, r.digest));
    } finally {
        if (dstBundle != null) {
            delete(dstBundle.getParentFile());
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) MessageDigest(java.security.MessageDigest) IO.getFile(aQute.lib.io.IO.getFile) File(java.io.File) PutResult(aQute.bnd.service.RepositoryPlugin.PutResult) PutOptions(aQute.bnd.service.RepositoryPlugin.PutOptions) FileInputStream(java.io.FileInputStream)

Aggregations

IO.getFile (aQute.lib.io.IO.getFile)8 File (java.io.File)8 PutResult (aQute.bnd.service.RepositoryPlugin.PutResult)3 ZipFile (java.util.zip.ZipFile)3 Version (aQute.bnd.version.Version)2 DownloadListener (aQute.bnd.service.RepositoryPlugin.DownloadListener)1 PutOptions (aQute.bnd.service.RepositoryPlugin.PutOptions)1 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)1 FileRepo (aQute.lib.deployer.FileRepo)1 UTF8Properties (aQute.lib.utf8properties.UTF8Properties)1 SHA1 (aQute.libg.cryptography.SHA1)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 OutputStream (java.io.OutputStream)1 DigestOutputStream (java.security.DigestOutputStream)1 MessageDigest (java.security.MessageDigest)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 JarOutputStream (java.util.jar.JarOutputStream)1