@Test public void serviceDocument() throws Exception { Edm edm = mock(Edm.class); EdmServiceMetadata metadata = mock(EdmServiceMetadata.class); EdmEntitySetInfo entitySetInfo1 = mock(EdmEntitySetInfo.class); when(entitySetInfo1.isDefaultEntityContainer()).thenReturn(true); when(entitySetInfo1.getEntitySetName()).thenReturn("EntitySet"); EdmEntitySetInfo entitySetInfo2 = mock(EdmEntitySetInfo.class); when(entitySetInfo2.getEntityContainerName()).thenReturn("Container2"); when(entitySetInfo2.getEntitySetName()).thenReturn("EntitySet2"); when(metadata.getEntitySetInfos()).thenReturn(Arrays.asList(entitySetInfo1, entitySetInfo2)); when(edm.getServiceMetadata()).thenReturn(metadata); final ODataResponse response = new JsonEntityProvider().writeServiceDocument(edm, "http: assertNotNull(response); assertNotNull(response.getEntity()); assertNull("EntitypProvider must not set content header", response.getContentHeader()); assertEquals(ODataServiceVersion.V10, response.getHeader(ODataHttpHeaders.DATASERVICEVERSION)); final String json = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertNotNull(json); assertEquals("{\"d\":{\"EntitySets\":[\"EntitySet\",\"Container2.EntitySet2\"]}}", json); }
public static void writeServiceDocument(final Writer writer, final Edm edm) throws EntityProviderException { final EdmServiceMetadata serviceMetadata = edm.getServiceMetadata(); JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer); try { jsonStreamWriter.beginObject() .name(FormatJson.D) .beginObject() .name(FormatJson.ENTITY_SETS) .beginArray(); boolean first = true; for (EdmEntitySetInfo info : serviceMetadata.getEntitySetInfos()) { if (first) { first = false; } else { jsonStreamWriter.separator(); } jsonStreamWriter.stringValue(createEntitySetName(info)); } jsonStreamWriter.endArray() .endObject() .endObject(); } catch (final IOException e) { throw new EntityProviderProducerException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } catch (final EdmException e) { throw new EntityProviderProducerException(e.getMessageReference(), e); } catch (final ODataException e) { throw new EntityProviderProducerException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }
JsonServiceDocumentProducer { public static void writeServiceDocument(final Writer writer, final Edm edm) throws EntityProviderException { final EdmServiceMetadata serviceMetadata = edm.getServiceMetadata(); JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer); try { jsonStreamWriter.beginObject() .name(FormatJson.D) .beginObject() .name(FormatJson.ENTITY_SETS) .beginArray(); boolean first = true; for (EdmEntitySetInfo info : serviceMetadata.getEntitySetInfos()) { if (first) { first = false; } else { jsonStreamWriter.separator(); } jsonStreamWriter.stringValue(createEntitySetName(info)); } jsonStreamWriter.endArray() .endObject() .endObject(); } catch (final IOException e) { throw new EntityProviderProducerException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } catch (final EdmException e) { throw new EntityProviderProducerException(e.getMessageReference(), e); } catch (final ODataException e) { throw new EntityProviderProducerException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } } }
JsonServiceDocumentProducer { public static void writeServiceDocument(final Writer writer, final Edm edm) throws EntityProviderException { final EdmServiceMetadata serviceMetadata = edm.getServiceMetadata(); JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer); try { jsonStreamWriter.beginObject() .name(FormatJson.D) .beginObject() .name(FormatJson.ENTITY_SETS) .beginArray(); boolean first = true; for (EdmEntitySetInfo info : serviceMetadata.getEntitySetInfos()) { if (first) { first = false; } else { jsonStreamWriter.separator(); } jsonStreamWriter.stringValue(createEntitySetName(info)); } jsonStreamWriter.endArray() .endObject() .endObject(); } catch (final IOException e) { throw new EntityProviderProducerException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } catch (final EdmException e) { throw new EntityProviderProducerException(e.getMessageReference(), e); } catch (final ODataException e) { throw new EntityProviderProducerException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }  }
JsonServiceDocumentProducer { public static void writeServiceDocument(final Writer writer, final Edm edm) throws EntityProviderException { final EdmServiceMetadata serviceMetadata = edm.getServiceMetadata(); JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer); try { jsonStreamWriter.beginObject() .name(FormatJson.D) .beginObject() .name(FormatJson.ENTITY_SETS) .beginArray(); boolean first = true; for (EdmEntitySetInfo info : serviceMetadata.getEntitySetInfos()) { if (first) { first = false; } else { jsonStreamWriter.separator(); } jsonStreamWriter.stringValue(createEntitySetName(info)); } jsonStreamWriter.endArray() .endObject() .endObject(); } catch (final IOException e) { throw new EntityProviderProducerException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } catch (final EdmException e) { throw new EntityProviderProducerException(e.getMessageReference(), e); } catch (final ODataException e) { throw new EntityProviderProducerException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }  static void writeServiceDocument(final Writer writer, final Edm edm); }
JsonServiceDocumentProducer { public static void writeServiceDocument(final Writer writer, final Edm edm) throws EntityProviderException { final EdmServiceMetadata serviceMetadata = edm.getServiceMetadata(); JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer); try { jsonStreamWriter.beginObject() .name(FormatJson.D) .beginObject() .name(FormatJson.ENTITY_SETS) .beginArray(); boolean first = true; for (EdmEntitySetInfo info : serviceMetadata.getEntitySetInfos()) { if (first) { first = false; } else { jsonStreamWriter.separator(); } jsonStreamWriter.stringValue(createEntitySetName(info)); } jsonStreamWriter.endArray() .endObject() .endObject(); } catch (final IOException e) { throw new EntityProviderProducerException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } catch (final EdmException e) { throw new EntityProviderProducerException(e.getMessageReference(), e); } catch (final ODataException e) { throw new EntityProviderProducerException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }  static void writeServiceDocument(final Writer writer, final Edm edm);  }