diff --git a/core/src/test/groovy/com/muwire/core/Destinations.groovy b/core/src/test/groovy/com/muwire/core/Destinations.groovy new file mode 100644 index 00000000..71742114 --- /dev/null +++ b/core/src/test/groovy/com/muwire/core/Destinations.groovy @@ -0,0 +1,9 @@ +package com.muwire.core + +import net.i2p.data.Destination + +class Destinations { + + Destination dest1 = new Destination("KvwWPKMSAtzf7Yruj8TQaHi2jaQpSNsXJskbpmSBTxkcYlDB2GllH~QBu-cs4FSYdaRmKDUUx7793jjnYJgTMbrjqeIL5-BTORZ09n6PUfhSejDpJjdkUxaV1OHRatfYs70RNBv7rvdj1-nXUow5tMfOJtoWVocUoKefUGFQFbJLDDkBqjm1kFyKFZv6m6S6YqXxBgVB1qYicooy67cNQF5HLUFtP15pk5fMDNGz5eNCjPfC~2Gp8FF~OpSy92HT0XN7uAMJykPcbdnWfcvVwqD7eS0K4XEnsqnMPLEiMAhqsugEFiFqtB3Wmm7UHVc03lcAfRhr1e2uZBNFTtM2Uol4MD5sCCKRZVHGcH-WGPSEz0BM5YO~Xi~dQ~N3NVud32PVzhh8xoGcAlhTqMqAbRJndCv-H6NflX90pYmbirCTIDOaR9758mThrqX0d4CwCn4jFXer52l8Qe8CErGoLuB-4LL~Gwrn7R1k7ZQc2PthkqeW8MfigyiN7hZVkul9AAAA") + Destination dest2 = new Destination("KvwWPKMSAtzf7Yruj8TQaHi2jaQpSNsXJskbpmSBTxkcYlDB2GllH~QBu-cs4FSYdaRmKDUUx7793jjnYJgTMbrjqeIL5-BTORZ09n6PUfhSejDpJjdkUxaV1OHRatfYs70RNBv7rvdj1-nXUow5tMfOJtoWVocUoKefUGFQFbJLDDkBqjm1kFyKFZv6m6S6YqXxBgVB1qYicooy67cNQF5HLUFtP15pk5fMDNGz5eNCjPfC~2Gp8FF~OpSy92HT0XN7uAMJykPcbdnWfcvVwqD7eS0K4XEnsqnMPLEiMAhqsugEFiFqtB3Wmm7UHVc03lcAfRhr1e2uZBNFTtM2Uol4MD5sCCKRZVHGcH-WGPSEz0BM5YO~Xi~dQ~N3NVud32PVzhh8xoGcAlhTqMqAbRJndCv-H6NflX90pYmbirCTIDOaR9758mThrqX0d4CwCn4jFXer52l8Qe8CErGoLuB-4LL~Gwrn7R1k7ZQc2PthkqeW8MfigyiN7hZVkul8AAAA") +} diff --git a/core/src/test/groovy/com/muwire/core/files/PersisterServiceTest.groovy b/core/src/test/groovy/com/muwire/core/files/PersisterServiceTest.groovy index a5fe4b3b..b210f8ee 100644 --- a/core/src/test/groovy/com/muwire/core/files/PersisterServiceTest.groovy +++ b/core/src/test/groovy/com/muwire/core/files/PersisterServiceTest.groovy @@ -3,6 +3,8 @@ package com.muwire.core.files import org.junit.Before import org.junit.Test +import com.muwire.core.Destinations +import com.muwire.core.DownloadedFile import com.muwire.core.EventBus import com.muwire.core.InfoHash import com.muwire.core.SharedFile @@ -163,4 +165,36 @@ class PersisterServiceTest { assert loadedFile2.file == sharedFile2.getCanonicalFile() assert loadedFile2.infoHash == ih2 } + + @Test + void testDownloadedFile() { + writeToSharedFile(sharedFile1, 1) + FileHasher fh = new FileHasher() + InfoHash ih1 = fh.hashFile(sharedFile1) + + File persisted = initPersisted() + + Destinations dests = new Destinations() + def json1 = [:] + json1.file = sharedFile1.getCanonicalFile().toString() + json1.length = 1 + json1.infoHash = Base32.encode(ih1.getRoot()) + json1.hashList = [Base32.encode(ih1.getHashList())] + json1.sources = [ dests.dest1.toBase64(), dests.dest2.toBase64()] + + json1 = JsonOutput.toJson(json1) + persisted.write json1 + + PersisterService ps = new PersisterService(persisted, eventBus, 100, null) + ps.start() + Thread.sleep(2000) + + assert listener.publishedFiles.size() == 1 + def loadedFile1 = listener.publishedFiles[0] + assert loadedFile1 instanceof DownloadedFile + assert loadedFile1.sources.size() == 2 + assert loadedFile1.sources.contains(dests.dest1) + assert loadedFile1.sources.contains(dests.dest2) + + } }