@Test public void testMissingSolURL() { final Logger logger = Logger.getLogger(DynamoDBMissionWorker.class.getName()); Handler handler; final ByteArrayOutputStream os = new ByteArrayOutputStream(); final URL url = PowerMock.createMock(URL.class); PowerMock.mockStatic(JSONUtils.class); PowerMock.mockStatic(NetworkUtils.class); String manifest = null; try { manifest = WorkerTestUtils.readFile(MISSING_SOL_URL_FILE); } catch (final IOException e) { fail("Could not read file: " + MISSING_SOL_URL_FILE); } try { NetworkUtils.getDataFromURL(url, null, ImageIngester.DEFAULT_CONNECT_TIMEOUT); PowerMock.expectLastCall().andReturn(manifest.getBytes()); PowerMock.replayAll(); handler = new StreamHandler(os, new SimpleFormatter()); logger.setUseParentHandlers(false); logger.addHandler(handler); DynamoDBMissionWorker.getSolJSON(url, ImageIngester.DEFAULT_CONNECT_TIMEOUT); handler.flush(); assertTrue(os.toString().contains("WARNING: Sol missing required keys")); } catch (final IOException e) { fail(e.getMessage()); } finally { try { os.close(); } catch (final IOException e) { fail(e.getMessage()); } } }
public static Map<Integer, String> getSolJSON(final URL url, final int connectTimeout) throws IOException { final Map<Integer, String> map = new HashMap<Integer, String>(); final JsonNode manifest = JSONParser.getJSONFromURL(url, connectTimeout); if (!manifest.has(RESOURCE_TYPE_KEY) || !SUPPORTED_TYPES.contains(manifest.get(RESOURCE_TYPE_KEY).asText())) { throw new IllegalArgumentException("Manifest version verification failed"); } if (!manifest.has(SOLS_LIST_KEY)) { throw new IllegalArgumentException("Manifest does not contain a sol list"); } final ArrayNode sols = (ArrayNode) manifest.get(SOLS_LIST_KEY); for (int i = 0; i < sols.size(); i++) { final JsonNode sol = sols.path(i); if (sol.has(SOL_ID_KEY) && sol.has(SOL_URL_KEY)) { final Integer solID = sol.get(SOL_ID_KEY).asInt(); final String solURL = sol.get(SOL_URL_KEY).asText(); if (solID != null && solURL != null) { map.put(solID, solURL); } else { LOGGER.warning("Sol contains unexpected values: " + sol); } } else { LOGGER.warning("Sol missing required keys: "); } } return map; }
DynamoDBMissionWorker implements Callable<Map<Integer, String>> { public static Map<Integer, String> getSolJSON(final URL url, final int connectTimeout) throws IOException { final Map<Integer, String> map = new HashMap<Integer, String>(); final JsonNode manifest = JSONParser.getJSONFromURL(url, connectTimeout); if (!manifest.has(RESOURCE_TYPE_KEY) || !SUPPORTED_TYPES.contains(manifest.get(RESOURCE_TYPE_KEY).asText())) { throw new IllegalArgumentException("Manifest version verification failed"); } if (!manifest.has(SOLS_LIST_KEY)) { throw new IllegalArgumentException("Manifest does not contain a sol list"); } final ArrayNode sols = (ArrayNode) manifest.get(SOLS_LIST_KEY); for (int i = 0; i < sols.size(); i++) { final JsonNode sol = sols.path(i); if (sol.has(SOL_ID_KEY) && sol.has(SOL_URL_KEY)) { final Integer solID = sol.get(SOL_ID_KEY).asInt(); final String solURL = sol.get(SOL_URL_KEY).asText(); if (solID != null && solURL != null) { map.put(solID, solURL); } else { LOGGER.warning("Sol contains unexpected values: " + sol); } } else { LOGGER.warning("Sol missing required keys: "); } } return map; } }
DynamoDBMissionWorker implements Callable<Map<Integer, String>> { public static Map<Integer, String> getSolJSON(final URL url, final int connectTimeout) throws IOException { final Map<Integer, String> map = new HashMap<Integer, String>(); final JsonNode manifest = JSONParser.getJSONFromURL(url, connectTimeout); if (!manifest.has(RESOURCE_TYPE_KEY) || !SUPPORTED_TYPES.contains(manifest.get(RESOURCE_TYPE_KEY).asText())) { throw new IllegalArgumentException("Manifest version verification failed"); } if (!manifest.has(SOLS_LIST_KEY)) { throw new IllegalArgumentException("Manifest does not contain a sol list"); } final ArrayNode sols = (ArrayNode) manifest.get(SOLS_LIST_KEY); for (int i = 0; i < sols.size(); i++) { final JsonNode sol = sols.path(i); if (sol.has(SOL_ID_KEY) && sol.has(SOL_URL_KEY)) { final Integer solID = sol.get(SOL_ID_KEY).asInt(); final String solURL = sol.get(SOL_URL_KEY).asText(); if (solID != null && solURL != null) { map.put(solID, solURL); } else { LOGGER.warning("Sol contains unexpected values: " + sol); } } else { LOGGER.warning("Sol missing required keys: "); } } return map; } DynamoDBMissionWorker(final String manifestURL, final int connectTimeout); }
DynamoDBMissionWorker implements Callable<Map<Integer, String>> { public static Map<Integer, String> getSolJSON(final URL url, final int connectTimeout) throws IOException { final Map<Integer, String> map = new HashMap<Integer, String>(); final JsonNode manifest = JSONParser.getJSONFromURL(url, connectTimeout); if (!manifest.has(RESOURCE_TYPE_KEY) || !SUPPORTED_TYPES.contains(manifest.get(RESOURCE_TYPE_KEY).asText())) { throw new IllegalArgumentException("Manifest version verification failed"); } if (!manifest.has(SOLS_LIST_KEY)) { throw new IllegalArgumentException("Manifest does not contain a sol list"); } final ArrayNode sols = (ArrayNode) manifest.get(SOLS_LIST_KEY); for (int i = 0; i < sols.size(); i++) { final JsonNode sol = sols.path(i); if (sol.has(SOL_ID_KEY) && sol.has(SOL_URL_KEY)) { final Integer solID = sol.get(SOL_ID_KEY).asInt(); final String solURL = sol.get(SOL_URL_KEY).asText(); if (solID != null && solURL != null) { map.put(solID, solURL); } else { LOGGER.warning("Sol contains unexpected values: " + sol); } } else { LOGGER.warning("Sol missing required keys: "); } } return map; } DynamoDBMissionWorker(final String manifestURL, final int connectTimeout); static Map<Integer, String> getSolJSON(final URL url, final int connectTimeout); @Override Map<Integer, String> call(); }
DynamoDBMissionWorker implements Callable<Map<Integer, String>> { public static Map<Integer, String> getSolJSON(final URL url, final int connectTimeout) throws IOException { final Map<Integer, String> map = new HashMap<Integer, String>(); final JsonNode manifest = JSONParser.getJSONFromURL(url, connectTimeout); if (!manifest.has(RESOURCE_TYPE_KEY) || !SUPPORTED_TYPES.contains(manifest.get(RESOURCE_TYPE_KEY).asText())) { throw new IllegalArgumentException("Manifest version verification failed"); } if (!manifest.has(SOLS_LIST_KEY)) { throw new IllegalArgumentException("Manifest does not contain a sol list"); } final ArrayNode sols = (ArrayNode) manifest.get(SOLS_LIST_KEY); for (int i = 0; i < sols.size(); i++) { final JsonNode sol = sols.path(i); if (sol.has(SOL_ID_KEY) && sol.has(SOL_URL_KEY)) { final Integer solID = sol.get(SOL_ID_KEY).asInt(); final String solURL = sol.get(SOL_URL_KEY).asText(); if (solID != null && solURL != null) { map.put(solID, solURL); } else { LOGGER.warning("Sol contains unexpected values: " + sol); } } else { LOGGER.warning("Sol missing required keys: "); } } return map; } DynamoDBMissionWorker(final String manifestURL, final int connectTimeout); static Map<Integer, String> getSolJSON(final URL url, final int connectTimeout); @Override Map<Integer, String> call();  }