@Test public void testGetMissionToManifestMap() { final URL url = PowerMock.createMock(URL.class); PowerMock.mockStatic(JSONUtils.class); PowerMock.mockStatic(NetworkUtils.class); String manifest = null; try { manifest = WorkerTestUtils.readFile(ROOT_JSON_FILE); } catch (final IOException e1) { fail("Could not read file: " + ROOT_JSON_FILE); } try { NetworkUtils.getDataFromURL(url, null, ImageIngester.DEFAULT_CONNECT_TIMEOUT); PowerMock.expectLastCall().andReturn(manifest.getBytes()); PowerMock.replayAll(); final Map<String, String> missionMap = DynamoDBJSONRootWorker.getMissionToManifestMap(url, ImageIngester.DEFAULT_CONNECT_TIMEOUT); assertEquals(EXPECTED_MAP, missionMap); } catch (final IOException e) { fail(e.getMessage()); } }
public static Map<String, String> getMissionToManifestMap(final URL rootJsonUrl, final int connectTimeout) throws IOException { final Map<String, String> map = new HashMap<String, String>(); final JsonNode root = JSONParser.getJSONFromURL(rootJsonUrl, connectTimeout); final Iterator<Entry<String, JsonNode>> it = root.fields(); while (it.hasNext()) { final Entry<String, JsonNode> pair = it.next(); final String mission = pair.getKey(); if (pair.getKey() == null) { LOGGER.warning("Null mission name"); continue; } final JsonNode missionObject = pair.getValue(); if (missionObject == null) { LOGGER.warning("Null mission object for: " + mission); continue; } if (!missionObject.has(IMAGE_RESOURCE_KEY)) { LOGGER.warning("Missing mission manifest for " + mission + ": " + missionObject.toString()); continue; } final String manifestValue = missionObject.get(IMAGE_RESOURCE_KEY).asText(); map.put(mission, manifestValue); } return map; }
DynamoDBJSONRootWorker implements Callable<Map<String, String>> { public static Map<String, String> getMissionToManifestMap(final URL rootJsonUrl, final int connectTimeout) throws IOException { final Map<String, String> map = new HashMap<String, String>(); final JsonNode root = JSONParser.getJSONFromURL(rootJsonUrl, connectTimeout); final Iterator<Entry<String, JsonNode>> it = root.fields(); while (it.hasNext()) { final Entry<String, JsonNode> pair = it.next(); final String mission = pair.getKey(); if (pair.getKey() == null) { LOGGER.warning("Null mission name"); continue; } final JsonNode missionObject = pair.getValue(); if (missionObject == null) { LOGGER.warning("Null mission object for: " + mission); continue; } if (!missionObject.has(IMAGE_RESOURCE_KEY)) { LOGGER.warning("Missing mission manifest for " + mission + ": " + missionObject.toString()); continue; } final String manifestValue = missionObject.get(IMAGE_RESOURCE_KEY).asText(); map.put(mission, manifestValue); } return map; } }
DynamoDBJSONRootWorker implements Callable<Map<String, String>> { public static Map<String, String> getMissionToManifestMap(final URL rootJsonUrl, final int connectTimeout) throws IOException { final Map<String, String> map = new HashMap<String, String>(); final JsonNode root = JSONParser.getJSONFromURL(rootJsonUrl, connectTimeout); final Iterator<Entry<String, JsonNode>> it = root.fields(); while (it.hasNext()) { final Entry<String, JsonNode> pair = it.next(); final String mission = pair.getKey(); if (pair.getKey() == null) { LOGGER.warning("Null mission name"); continue; } final JsonNode missionObject = pair.getValue(); if (missionObject == null) { LOGGER.warning("Null mission object for: " + mission); continue; } if (!missionObject.has(IMAGE_RESOURCE_KEY)) { LOGGER.warning("Missing mission manifest for " + mission + ": " + missionObject.toString()); continue; } final String manifestValue = missionObject.get(IMAGE_RESOURCE_KEY).asText(); map.put(mission, manifestValue); } return map; } DynamoDBJSONRootWorker(final String rootURL, final int connectTimeout); }
DynamoDBJSONRootWorker implements Callable<Map<String, String>> { public static Map<String, String> getMissionToManifestMap(final URL rootJsonUrl, final int connectTimeout) throws IOException { final Map<String, String> map = new HashMap<String, String>(); final JsonNode root = JSONParser.getJSONFromURL(rootJsonUrl, connectTimeout); final Iterator<Entry<String, JsonNode>> it = root.fields(); while (it.hasNext()) { final Entry<String, JsonNode> pair = it.next(); final String mission = pair.getKey(); if (pair.getKey() == null) { LOGGER.warning("Null mission name"); continue; } final JsonNode missionObject = pair.getValue(); if (missionObject == null) { LOGGER.warning("Null mission object for: " + mission); continue; } if (!missionObject.has(IMAGE_RESOURCE_KEY)) { LOGGER.warning("Missing mission manifest for " + mission + ": " + missionObject.toString()); continue; } final String manifestValue = missionObject.get(IMAGE_RESOURCE_KEY).asText(); map.put(mission, manifestValue); } return map; } DynamoDBJSONRootWorker(final String rootURL, final int connectTimeout); static Map<String, String> getMissionToManifestMap(final URL rootJsonUrl, final int connectTimeout); @Override Map<String, String> call(); }
DynamoDBJSONRootWorker implements Callable<Map<String, String>> { public static Map<String, String> getMissionToManifestMap(final URL rootJsonUrl, final int connectTimeout) throws IOException { final Map<String, String> map = new HashMap<String, String>(); final JsonNode root = JSONParser.getJSONFromURL(rootJsonUrl, connectTimeout); final Iterator<Entry<String, JsonNode>> it = root.fields(); while (it.hasNext()) { final Entry<String, JsonNode> pair = it.next(); final String mission = pair.getKey(); if (pair.getKey() == null) { LOGGER.warning("Null mission name"); continue; } final JsonNode missionObject = pair.getValue(); if (missionObject == null) { LOGGER.warning("Null mission object for: " + mission); continue; } if (!missionObject.has(IMAGE_RESOURCE_KEY)) { LOGGER.warning("Missing mission manifest for " + mission + ": " + missionObject.toString()); continue; } final String manifestValue = missionObject.get(IMAGE_RESOURCE_KEY).asText(); map.put(mission, manifestValue); } return map; } DynamoDBJSONRootWorker(final String rootURL, final int connectTimeout); static Map<String, String> getMissionToManifestMap(final URL rootJsonUrl, final int connectTimeout); @Override Map<String, String> call();  }