@Test public void testJsonEncode() throws Exception { Announcement announcement = new Announcement("environment", "node", "pool", "location", ImmutableSet.of( serviceAnnouncement("foo") .addProperty("http", "http://localhost:8080") .addProperty("jmx", "jmx://localhost:1234") .build())); Map<String, Object> actual = objectCodec.fromJson(announcementCodec.toJson(announcement)); String json = Resources.toString(Resources.getResource("announcement.json"), UTF_8); Map<String, Object> expected = objectCodec.fromJson(json); // set id in expected List<Map<String, Object>> services = toServices(expected.get("services")); services.get(0).put("id", Iterables.getOnlyElement(announcement.getServices()).getId().toString()); assertEquals(actual, expected); }
@Test public void testJsonEncode() throws Exception { Announcement announcement = new Announcement("environment", "node", "pool", "location", ImmutableSet.of( serviceAnnouncement("foo") .addProperty("http", "http://localhost:8080") .addProperty("jmx", "jmx://localhost:1234") .build()) ); Map<String, Object> actual = objectCodec.fromJson(announcementCodec.toJson(announcement)); String json = Resources.toString(Resources.getResource("announcement.json"), Charsets.UTF_8); Map<String, Object> expected = objectCodec.fromJson(json); // set id in expected List<Map<String, Object>> services = (List<Map<String, Object>>) expected.get("services"); services.get(0).put("id", Iterables.getOnlyElement(announcement.getServices()).getId().toString()); assertEquals(actual, expected); }
@Test public void testJsonEncode() throws Exception { Announcement announcement = new Announcement("environment", "node", "pool", "location", ImmutableSet.of( serviceAnnouncement("foo") .addProperty("http", "http://localhost:8080") .addProperty("jmx", "jmx://localhost:1234") .build())); Map<String, Object> actual = objectCodec.fromJson(announcementCodec.toJson(announcement)); String json = Resources.toString(Resources.getResource("announcement.json"), UTF_8); Map<String, Object> expected = objectCodec.fromJson(json); // set id in expected List<Map<String, Object>> services = toServices(expected.get("services")); services.get(0).put("id", Iterables.getOnlyElement(announcement.getServices()).getId().toString()); assertEquals(actual, expected); }