@Test public void testEmptyMissionBody() throws IOException { final Logger logger = Logger.getLogger(DynamoDBJSONRootWorker.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(EMPTY_MISSION_BODY_FILE); } catch (final IOException e1) { fail("Could not read file: " + EMPTY_MISSION_BODY_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); try { DynamoDBJSONRootWorker.getMissionToManifestMap(url, ImageIngester.DEFAULT_CONNECT_TIMEOUT); } catch (final IOException e) { fail(e.getMessage()); } handler.flush(); assertTrue(os.toString().contains("WARNING: Missing mission manifest for MERB: {}")); } finally { try { os.close(); } 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();  }