Search in sources :

Example 1 with SearchResultWebTO

use of org.nzbhydra.searching.SearchResultWebTO in project nzbhydra2 by theotherp.

the class NzbDownloadingTests method shouldSendUrlToDownloader.

@Test
public void shouldSendUrlToDownloader() throws Exception {
    baseConfig.getDownloading().getDownloaders().get(0).setNzbAddingType(NzbAddingType.SEND_LINK);
    // http://127.0.0.1:7070/sabnzbd/api?apikey=apikey&output=json&mode=addurl&name=http://127.0.0.1:5076/getnzb/api/5293954792479313301?apikey&nzbname=someNzb.nzb
    // http://192.168.1.111:5077/getnzb/api/-338204003302262369?apikey
    HttpRequest expectedRequest = HttpRequest.request("/sabnzbd/api").withQueryStringParameter("mode", "addurl").withQueryStringParameter("name", "http://localhost/getnzb/api/" + searchResultId + "?apikey=apikey").withMethod("POST");
    mockServer.when(expectedRequest).respond(HttpResponse.response().withStatusCode(200).withBody("{\"isStatus\":true}"));
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.put("/internalapi/downloader/addNzbs");
    SearchResultWebTO item = SearchResultWebTO.builder().searchResultId(String.valueOf(searchResultId)).build();
    AddFilesRequest addNzbsRequest = new AddFilesRequest("sabnzbd", Collections.singletonList(new AddFilesRequest.SearchResult(item.getSearchResultId(), item.getOriginalCategory())), "");
    request.contentType(MediaType.APPLICATION_JSON_VALUE);
    request.content(new ObjectMapper().writeValueAsString(addNzbsRequest));
    request.with(csrf());
    ResultActions perform = mvc.perform(request);
    perform.andExpect(status().is(200));
    mockServer.verify(expectedRequest);
}
Also used : HttpRequest(org.mockserver.model.HttpRequest) SearchResultWebTO(org.nzbhydra.searching.SearchResultWebTO) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) AddFilesRequest(org.nzbhydra.downloading.AddFilesRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Test (org.junit.Test)1 HttpRequest (org.mockserver.model.HttpRequest)1 AddFilesRequest (org.nzbhydra.downloading.AddFilesRequest)1 SearchResultWebTO (org.nzbhydra.searching.SearchResultWebTO)1 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 ResultActions (org.springframework.test.web.servlet.ResultActions)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1