FetchAndUnzipProcess implements GeoServerProcess { ZipInputStream getZipFromUrl(String zipUrl, HttpClient client){ HttpUriRequest req = new HttpGet(zipUrl); HttpResponse response; ZipInputStream zipStream = null; try { LOGGER.fine("retrieving zip from: " + zipUrl); response = client.execute(req); StatusLine status = response.getStatusLine(); int statusCode = status.getStatusCode(); if (400 <= statusCode) { throw new ProcessException("Could not retrieve file '" + zipUrl + "'. Got HTTP " + statusCode); } else { zipStream = new ZipInputStream(response.getEntity().getContent()); } } catch (IOException ex) { throw new ProcessException(ex); } return zipStream; }  @DescribeResult(name = "filePath", description = "path to the unzipped file") String execute(
            @DescribeParameter(name = "zipUrl", min = 1, max = 1, description = "URL to the zipped file to retrieve") String zipUrl,
            @DescribeParameter(name = "token", min = 1, max = 1, description = "Token for authorizing the upload") String token
            ); String makeSafeFileName(); static final String FILE_NAME_PREFIX; }
@Test public void testGetZipFromBadUrl() { int[] badCodes = new int[]{ 400, 401, 404, 500, 501}; for(int badCode : badCodes){ HttpClient client = mockHttpClient(badCode, null); try{ instance.getZipFromUrl("http: fail("Should throw exception on HTTP error"); } catch (ProcessException ex){ } } return; }
@Test public void testGetZipFromGoodUrls() { int[] goodCodes = new int[]{200, 301, 302, 304, 307}; byte[] empty = new byte[]{}; for(int goodCode : goodCodes){ HttpClient client = mockHttpClient(goodCode, new ByteArrayInputStream(empty)); try{ ZipInputStream zipStream = instance.getZipFromUrl("http: assertNotNull(zipStream); } catch (ProcessException ex){ fail("Should not throw exception on good HTTP status codes"); } } return; }