@Test public void verifyUploadedContentHasProperStructureAndCanBeUnzipped() { doAnswer(verifyRequestContent()) .when(responseHandleFunction) .apply(any(HttpServletRequest.class), any(HttpServletResponse.class)); ResourceUploadRequest resourceUploadRequest = new ResourceUploadRequest("localhost", port, SESSION_ID); String responseWithPath = resourceUploadRequest.upload("files_for_upload"); verify(responseHandleFunction, times(1)).apply(any(HttpServletRequest.class), any(HttpServletResponse.class)); assertThat(responseWithPath, is(EXPECTED_RETURN_FOLDER)); }
public String upload(String resourcesPath) { LOGGER.debug("Uploading resources from path:" + resourcesPath); File zip = addResourcesToZip(resourcesPath); CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost request = new HttpPost(String.format(FILE_UPLOAD_EXTENSION_PATH, sessionId)); request.setHeader(HTTP.CONTENT_TYPE, "application/octet-stream"); request.setHeader(HTTP.CONTENT_ENCODING, Consts.ISO_8859_1.name()); try { FileInputStream fileInputStream = new FileInputStream(zip); InputStreamEntity entity = new InputStreamEntity(fileInputStream); request.setEntity(entity); CloseableHttpResponse execute = httpClient.execute(httpHost, request); int statusCode = execute.getStatusLine().getStatusCode(); String content = contentAsString(execute); if (HttpStatus.SC_OK == statusCode) { return content; } else { throw new ResourceUploadException(statusCode, content); } } catch (IOException e) { throw Throwables.propagate(e); } }
ResourceUploadRequest { public String upload(String resourcesPath) { LOGGER.debug("Uploading resources from path:" + resourcesPath); File zip = addResourcesToZip(resourcesPath); CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost request = new HttpPost(String.format(FILE_UPLOAD_EXTENSION_PATH, sessionId)); request.setHeader(HTTP.CONTENT_TYPE, "application/octet-stream"); request.setHeader(HTTP.CONTENT_ENCODING, Consts.ISO_8859_1.name()); try { FileInputStream fileInputStream = new FileInputStream(zip); InputStreamEntity entity = new InputStreamEntity(fileInputStream); request.setEntity(entity); CloseableHttpResponse execute = httpClient.execute(httpHost, request); int statusCode = execute.getStatusLine().getStatusCode(); String content = contentAsString(execute); if (HttpStatus.SC_OK == statusCode) { return content; } else { throw new ResourceUploadException(statusCode, content); } } catch (IOException e) { throw Throwables.propagate(e); } } }
ResourceUploadRequest { public String upload(String resourcesPath) { LOGGER.debug("Uploading resources from path:" + resourcesPath); File zip = addResourcesToZip(resourcesPath); CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost request = new HttpPost(String.format(FILE_UPLOAD_EXTENSION_PATH, sessionId)); request.setHeader(HTTP.CONTENT_TYPE, "application/octet-stream"); request.setHeader(HTTP.CONTENT_ENCODING, Consts.ISO_8859_1.name()); try { FileInputStream fileInputStream = new FileInputStream(zip); InputStreamEntity entity = new InputStreamEntity(fileInputStream); request.setEntity(entity); CloseableHttpResponse execute = httpClient.execute(httpHost, request); int statusCode = execute.getStatusLine().getStatusCode(); String content = contentAsString(execute); if (HttpStatus.SC_OK == statusCode) { return content; } else { throw new ResourceUploadException(statusCode, content); } } catch (IOException e) { throw Throwables.propagate(e); } } ResourceUploadRequest(String host, int port, String sessionId); }
ResourceUploadRequest { public String upload(String resourcesPath) { LOGGER.debug("Uploading resources from path:" + resourcesPath); File zip = addResourcesToZip(resourcesPath); CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost request = new HttpPost(String.format(FILE_UPLOAD_EXTENSION_PATH, sessionId)); request.setHeader(HTTP.CONTENT_TYPE, "application/octet-stream"); request.setHeader(HTTP.CONTENT_ENCODING, Consts.ISO_8859_1.name()); try { FileInputStream fileInputStream = new FileInputStream(zip); InputStreamEntity entity = new InputStreamEntity(fileInputStream); request.setEntity(entity); CloseableHttpResponse execute = httpClient.execute(httpHost, request); int statusCode = execute.getStatusLine().getStatusCode(); String content = contentAsString(execute); if (HttpStatus.SC_OK == statusCode) { return content; } else { throw new ResourceUploadException(statusCode, content); } } catch (IOException e) { throw Throwables.propagate(e); } } ResourceUploadRequest(String host, int port, String sessionId); String upload(String resourcesPath); }
ResourceUploadRequest { public String upload(String resourcesPath) { LOGGER.debug("Uploading resources from path:" + resourcesPath); File zip = addResourcesToZip(resourcesPath); CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost request = new HttpPost(String.format(FILE_UPLOAD_EXTENSION_PATH, sessionId)); request.setHeader(HTTP.CONTENT_TYPE, "application/octet-stream"); request.setHeader(HTTP.CONTENT_ENCODING, Consts.ISO_8859_1.name()); try { FileInputStream fileInputStream = new FileInputStream(zip); InputStreamEntity entity = new InputStreamEntity(fileInputStream); request.setEntity(entity); CloseableHttpResponse execute = httpClient.execute(httpHost, request); int statusCode = execute.getStatusLine().getStatusCode(); String content = contentAsString(execute); if (HttpStatus.SC_OK == statusCode) { return content; } else { throw new ResourceUploadException(statusCode, content); } } catch (IOException e) { throw Throwables.propagate(e); } } ResourceUploadRequest(String host, int port, String sessionId); String upload(String resourcesPath); static final String FILE_UPLOAD_EXTENSION_PATH; }