public ODataEntity validateEntities(
      final String serviceRootURL,
      final ODataPubFormat format,
      final ODataEntity original,
      final int actualObjectId,
      final Collection<String> expands,
      final String entitySetName) {

    final URIBuilder uriBuilder =
        client
            .getURIBuilder(serviceRootURL)
            .appendEntityTypeSegment(entitySetName)
            .appendKeySegment(actualObjectId);

    // search expanded
    if (expands != null) {
      for (String expand : expands) {
        uriBuilder.expand(expand);
      }
    }
    final ODataEntityRequest req =
        client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
    req.setFormat(format);

    final ODataRetrieveResponse<ODataEntity> res = req.execute();
    assertEquals(200, res.getStatusCode());

    final ODataEntity actual = res.getBody();
    assertNotNull(actual);

    validateLinks(original.getAssociationLinks(), actual.getAssociationLinks());
    validateLinks(original.getEditMediaLinks(), actual.getEditMediaLinks());
    validateLinks(original.getNavigationLinks(), actual.getNavigationLinks());

    // validate equalities of properties
    checkProperties(original.getProperties(), actual.getProperties());
    return actual;
  }
  private void readAndWrite(final ODataPubFormat format) {
    final InputStream input = getClass().getResourceAsStream("Customer_-10." + getSuffix(format));
    final ODataEntity entity =
        getClient()
            .getBinder()
            .getODataEntity(
                getClient()
                    .getDeserializer()
                    .toEntry(input, getClient().getResourceFactory().entryClassForFormat(format)));
    assertNotNull(entity);

    assertEquals("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer", entity.getName());
    assertTrue(entity.getEditLink().toASCIIString().endsWith("/Customer(-10)"));
    assertEquals(5, entity.getNavigationLinks().size());
    assertEquals(2, entity.getEditMediaLinks().size());

    boolean check = false;

    for (ODataLink link : entity.getNavigationLinks()) {
      if ("Wife".equals(link.getName())
          && (link.getLink().toASCIIString().endsWith("/Customer(-10)/Wife"))) {
        check = true;
      }
    }

    assertTrue(check);

    final ODataEntity written =
        getClient()
            .getBinder()
            .getODataEntity(
                getClient()
                    .getBinder()
                    .getEntry(
                        entity, getClient().getResourceFactory().entryClassForFormat(format)));
    assertEquals(entity, written);
  }