use of org.nzbhydra.downloading.FileZipResponse in project nzbhydra2 by theotherp.
the class SearchingResultsUiTest method prepareFiveResultsFromTwoIndexers.
protected void prepareFiveResultsFromTwoIndexers() throws Exception {
replaceConfig(getClass().getResource("twoIndexers.json"));
mockWebServer.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
int mockServerPort = mockWebServer.getPort();
String mockServerBaseUrl = "http://127.0.0.1:" + mockServerPort + "/";
if (request.getRequestUrl().queryParameter("apikey") != null && request.getRequestUrl().queryParameter("apikey").equals("apikey1")) {
NewznabXmlItem result1 = RssItemBuilder.builder("indexer1-result1").pubDate(Instant.now().minus(1, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink1").hasNfo(false).grabs(1).size(mbToBytes(1)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5000")))).category("TV").build();
NewznabXmlItem result2 = RssItemBuilder.builder("indexer1-result2").pubDate(Instant.now().minus(2, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink2").hasNfo(true).grabs(2).size(mbToBytes(2)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5040")))).category("TV SD").build();
NewznabXmlItem result3 = RssItemBuilder.builder("indexer1-result3").pubDate(Instant.now().minus(3, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink3").comments("comments").grabs(3).size(mbToBytes(3)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5030")))).category("TV HD").build();
NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(result1, result2, result3), 0, 3);
return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
} else if (request.getRequestUrl().queryParameter("apikey") != null && request.getRequestUrl().queryParameter("apikey").equals("apikey2")) {
NewznabXmlItem result5 = RssItemBuilder.builder("indexer2-result2").pubDate(Instant.now().minus(5, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink5").grabs(5).size(mbToBytes(5)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "2040")))).category("Movies HD").build();
NewznabXmlItem result4 = RssItemBuilder.builder("indexer2-result1").pubDate(Instant.now().minus(4, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink4").grabs(4).size(mbToBytes(4)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "2000")))).category("Movies").build();
NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(result4, result5), 0, 2);
return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
} else if (request.getPath().endsWith("nzbzip")) {
System.out.println("Returning NZB ZIP response");
String body = request.getBody().readString(Charset.defaultCharset());
ObjectMapper objectMapper = new ObjectMapper();
try {
List<Long> ids = objectMapper.readValue(body, new TypeReference<List<Long>>() {
});
FileZipResponse response = new FileZipResponse(true, "bla", null, ids, Collections.emptyList());
return new MockResponse().setBody(objectMapper.writeValueAsString(response)).setHeader("Content-Type", "application/xml; charset=utf-8");
} catch (IOException e) {
}
throw new RuntimeException("Unable to handle nzbzip");
} else if (request.getPath().contains("nzblink")) {
System.out.println("Returning NZB");
return new MockResponse().setBody("nzb").setHeader("Content-Type", "application/x-nzb; charset=utf-8");
} else {
throw new RuntimeException("Unexpected api key " + request.getRequestUrl().queryParameter("apikey"));
}
}
});
}
Aggregations