Search in sources :

Example 6 with HttpRequest

use of org.mockserver.model.HttpRequest 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

HttpRequest (org.mockserver.model.HttpRequest)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Test (org.junit.Test)4 TreeMap (java.util.TreeMap)3 Configuration (org.apache.hadoop.conf.Configuration)3 MockServerClient (org.mockserver.client.server.MockServerClient)3 HttpResponse (org.mockserver.model.HttpResponse)3 Timer (org.apache.hadoop.util.Timer)2 ClientAndServer (org.mockserver.integration.ClientAndServer)2 ClientAndServer.startClientAndServer (org.mockserver.integration.ClientAndServer.startClientAndServer)2 Span (com.uber.jaeger.Span)1 URI (java.net.URI)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 BasicHttpRequest (org.apache.http.message.BasicHttpRequest)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