### Question:
JsonServiceDocumentConsumer { public ServiceDocumentImpl parseJson(final InputStream in) throws EntityProviderException { return readServiceDocument(createJsonReader(in)); }  ServiceDocumentImpl parseJson(final InputStream in);  }### Answer:
@Test public void test() throws EntityProviderException { JsonServiceDocumentConsumer parser = new JsonServiceDocumentConsumer(); InputStream in = ClassLoader.class.getResourceAsStream("/svcDocJson.json"); ServiceDocument serviceDoc = parser.parseJson(in); List<EdmEntitySetInfo> entitySetsInfo = serviceDoc.getEntitySetsInfo(); assertNotNull(entitySetsInfo); assertEquals(7, entitySetsInfo.size()); for (EdmEntitySetInfo entitySetInfo : entitySetsInfo) { if (!entitySetInfo.isDefaultEntityContainer()) { if ("Container2".equals(entitySetInfo.getEntityContainerName())) { assertEquals("Photos", entitySetInfo.getEntitySetName()); } else if ("Container.Nr1".equals(entitySetInfo.getEntityContainerName())) { assertEquals("Employees", entitySetInfo.getEntitySetName()); } else { fail(); } } } }
@Test public void checkDecodingOfEntitySetNames() throws Exception { JsonServiceDocumentConsumer parser = new JsonServiceDocumentConsumer(); InputStream in = ClassLoader.class.getResourceAsStream("/svcDocJson.json"); ServiceDocument serviceDoc = parser.parseJson(in); EdmEntitySetInfo entitySetInfo = serviceDoc.getEntitySetsInfo().get(6); assertEquals(":EncodedName", entitySetInfo.getEntitySetName()); assertEquals("%3AEncodedName", entitySetInfo.getEntitySetUri().toASCIIString()); }
@Test(expected = EntityProviderException.class) public void testInvalidServiceDocument() throws EntityProviderException { JsonServiceDocumentConsumer parser = new JsonServiceDocumentConsumer(); InputStream in = ClassLoader.class.getResourceAsStream("/invalidSvcDocJson.json"); parser.parseJson(in); }
@Test(expected = EntityProviderException.class) public void testServiceDocumentWithInvalidStructure() throws EntityProviderException { JsonServiceDocumentConsumer parser = new JsonServiceDocumentConsumer(); InputStream in = ClassLoader.class.getResourceAsStream("/invalidSvcDocJson2.json"); parser.parseJson(in); }
@Test public void test() throws EntityProviderException { JsonServiceDocumentConsumer parser = new JsonServiceDocumentConsumer(); InputStream in = ClassLoader.class.getResourceAsStream("/svcDocJson.txt"); ServiceDocument serviceDoc = parser.parseJson(in); List<EdmEntitySetInfo> entitySetsInfo = serviceDoc.getEntitySetsInfo(); assertNotNull(entitySetsInfo); assertEquals(6, entitySetsInfo.size()); for (EdmEntitySetInfo entitySetInfo : entitySetsInfo) { if (!entitySetInfo.isDefaultEntityContainer()) { if ("Container2".equals(entitySetInfo.getEntityContainerName())) { assertEquals("Photos", entitySetInfo.getEntitySetName()); } else if ("Container.Nr1".equals(entitySetInfo.getEntityContainerName())) { assertEquals("Employees", entitySetInfo.getEntitySetName()); } else { fail(); } } } }
@Test(expected = EntityProviderException.class) public void testInvalidServiceDocument() throws EntityProviderException { JsonServiceDocumentConsumer parser = new JsonServiceDocumentConsumer(); InputStream in = ClassLoader.class.getResourceAsStream("/invalidSvcDocJson.txt"); parser.parseJson(in); }
@Test(expected = EntityProviderException.class) public void testServiceDocumentWithInvalidStructure() throws EntityProviderException { JsonServiceDocumentConsumer parser = new JsonServiceDocumentConsumer(); InputStream in = ClassLoader.class.getResourceAsStream("/invalidSvcDocJson2.txt"); parser.parseJson(in); }