public void getOpenTypeEntityWithString(
      final ODataPubFormat format,
      final String contentType,
      final int id,
      final String prefer,
      String uuid) {
    try {
      ODataEntity entity =
          ODataObjectFactory.newEntity("Microsoft.Test.OData.Services.OpenTypesService.Row");
      entity.addProperty(
          ODataObjectFactory.newPrimitiveProperty(
              "Id",
              client
                  .getPrimitiveValueBuilder()
                  .setType(EdmSimpleType.Guid)
                  .setValue(uuid)
                  .build()));
      entity.addProperty(
          ODataObjectFactory.newPrimitiveProperty(
              "LongValue",
              client
                  .getPrimitiveValueBuilder()
                  .setType(EdmSimpleType.Int64)
                  .setValue(44L)
                  .build()));
      entity.addProperty(
          ODataObjectFactory.newPrimitiveProperty(
              "DoubleValue",
              client
                  .getPrimitiveValueBuilder()
                  .setType(EdmSimpleType.Double)
                  .setValue(4.34567D)
                  .build()));

      final ODataEntityCreateRequest createReq =
          client
              .getCUDRequestFactory()
              .getEntityCreateRequest(
                  client
                      .getURIBuilder(testOpenTypeServiceRootURL)
                      .appendEntityTypeSegment("Row")
                      .build(),
                  entity);
      createReq.setFormat(format);
      createReq.setPrefer(prefer);
      createReq.setContentType(contentType);
      final ODataEntityCreateResponse createRes = createReq.execute();
    } catch (Exception e) {
      if (e.getMessage().equals("Provided value is not compatible with Edm.Guid")) {
        assertTrue(true);
      } else {
        fail(e.getMessage());
      }
    }
  }
  public ODataEntity getInfo(final int id, final String info) {
    final ODataEntity entity =
        ODataObjectFactory.newEntity(
            "Microsoft.Test.OData.Services.AstoriaDefaultService.CustomerInfo");
    entity.setMediaEntity(true);

    entity.addProperty(
        ODataObjectFactory.newPrimitiveProperty(
            "Information",
            client.getPrimitiveValueBuilder().setText(info).setType(EdmSimpleType.String).build()));
    return entity;
  }
  public void getOpenTypeEntity(
      final ODataPubFormat format,
      final String contentType,
      final int id,
      final String prefer,
      String uuid) {
    final UUID guid;
    if (uuid.equals("random")) {
      guid = UUID.randomUUID();
    } else {
      guid = UUID.fromString(uuid);
    }
    ODataEntity entity =
        ODataObjectFactory.newEntity("Microsoft.Test.OData.Services.OpenTypesService.Row");
    entity.addProperty(
        ODataObjectFactory.newPrimitiveProperty(
            "Id",
            client.getPrimitiveValueBuilder().setType(EdmSimpleType.Guid).setValue(guid).build()));
    entity.addProperty(
        ODataObjectFactory.newPrimitiveProperty(
            "LongValue",
            client.getPrimitiveValueBuilder().setType(EdmSimpleType.Int64).setValue(44L).build()));
    entity.addProperty(
        ODataObjectFactory.newPrimitiveProperty(
            "DoubleValue",
            client
                .getPrimitiveValueBuilder()
                .setType(EdmSimpleType.Double)
                .setValue(4.34567D)
                .build()));

    final ODataEntityCreateRequest createReq =
        client
            .getCUDRequestFactory()
            .getEntityCreateRequest(
                client
                    .getURIBuilder(testOpenTypeServiceRootURL)
                    .appendEntityTypeSegment("Row")
                    .build(),
                entity);
    createReq.setFormat(format);
    createReq.setPrefer(prefer);
    createReq.setContentType(contentType);
    final ODataEntityCreateResponse createRes = createReq.execute();
    assertEquals(201, createRes.getStatusCode());
    entity = createRes.getBody();
    assertNotNull(entity);
    if (format.equals(ODataPubFormat.JSON_NO_METADATA)) {
      assertEquals(
          EdmSimpleType.String.toString(),
          entity.getProperty("Id").getPrimitiveValue().getTypeName());
      assertEquals(
          EdmSimpleType.String.toString(),
          entity.getProperty("LongValue").getPrimitiveValue().getTypeName());
      assertEquals(
          EdmSimpleType.Double.toString(),
          entity.getProperty("DoubleValue").getPrimitiveValue().getTypeName());
    } else if (format.equals(ODataPubFormat.JSON)) {
      assertEquals(
          EdmSimpleType.String.toString(),
          entity.getProperty("Id").getPrimitiveValue().getTypeName());
      assertEquals(
          EdmSimpleType.Int64.toString(),
          entity.getProperty("LongValue").getPrimitiveValue().getTypeName());
      assertEquals(
          EdmSimpleType.Double.toString(),
          entity.getProperty("DoubleValue").getPrimitiveValue().getTypeName());
    } else {
      assertEquals(
          EdmSimpleType.Guid.toString(),
          entity.getProperty("Id").getPrimitiveValue().getTypeName());
      assertEquals(
          EdmSimpleType.Int64.toString(),
          entity.getProperty("LongValue").getPrimitiveValue().getTypeName());
      assertEquals(
          EdmSimpleType.Double.toString(),
          entity.getProperty("DoubleValue").getPrimitiveValue().getTypeName());
    }
    ODataDeleteResponse deleteRes;
    try {
      deleteRes =
          client
              .getCUDRequestFactory()
              .getDeleteRequest(new URI(testOpenTypeServiceRootURL + "/Row(guid'" + guid + "')"))
              .execute();
      assertEquals(204, deleteRes.getStatusCode());
    } catch (URISyntaxException e) {
      // TODO Auto-generated catch block
      LOG.error("", e);
    }
  }
  public ODataEntity getComputerDetailsEntity(
      final int id,
      final String sampleName,
      final boolean withInlineInfo,
      final String purchaseDate,
      String dimensionValue) {

    final ODataEntity entity =
        ODataObjectFactory.newEntity(
            "Microsoft.Test.OData.Services.AstoriaDefaultService.ComputerDetail");

    entity.addProperty(
        ODataObjectFactory.newPrimitiveProperty(
            "Manufacturer",
            client
                .getPrimitiveValueBuilder()
                .setText("manufacturer name")
                .setType(EdmSimpleType.String)
                .build()));

    entity.addProperty(
        ODataObjectFactory.newPrimitiveProperty(
            "ComputerDetailId",
            client
                .getPrimitiveValueBuilder()
                .setText(String.valueOf(id))
                .setType(EdmSimpleType.Int32)
                .build()));

    entity.addProperty(
        ODataObjectFactory.newPrimitiveProperty(
            "Model",
            client
                .getPrimitiveValueBuilder()
                .setText("Model Name")
                .setType(EdmSimpleType.String)
                .build()));

    entity.addProperty(
        ODataObjectFactory.newPrimitiveProperty(
            "PurchaseDate",
            client
                .getPrimitiveValueBuilder()
                .setText(purchaseDate)
                .setType(EdmSimpleType.DateTime)
                .build()));

    // add Dimensions attribute (collection)
    final ODataComplexValue dimensions =
        new ODataComplexValue("Microsoft.Test.OData.Services.AstoriaDefaultService.Dimensions");
    dimensions.add(
        ODataObjectFactory.newPrimitiveProperty(
            "Width",
            client
                .getPrimitiveValueBuilder()
                .setText(dimensionValue)
                .setType(EdmSimpleType.Decimal)
                .build()));
    dimensions.add(
        ODataObjectFactory.newPrimitiveProperty(
            "Height",
            client
                .getPrimitiveValueBuilder()
                .setText(dimensionValue)
                .setType(EdmSimpleType.Decimal)
                .build()));
    dimensions.add(
        ODataObjectFactory.newPrimitiveProperty(
            "Depth",
            client
                .getPrimitiveValueBuilder()
                .setText(dimensionValue)
                .setType(EdmSimpleType.Decimal)
                .build()));

    entity.addProperty(ODataObjectFactory.newComplexProperty("Dimensions", dimensions));
    return entity;
  }
  public ODataEntity getNewCustomer(final int id, final String name, final boolean withInlineInfo) {

    final ODataEntity entity =
        ODataObjectFactory.newEntity(
            "Microsoft.Test.OData.Services.AstoriaDefaultService.Customer");

    // add name attribute
    entity.addProperty(
        ODataObjectFactory.newPrimitiveProperty(
            "Name",
            client.getPrimitiveValueBuilder().setText(name).setType(EdmSimpleType.String).build()));

    // add key attribute
    if (id != 0) {
      entity.addProperty(
          ODataObjectFactory.newPrimitiveProperty(
              "CustomerId",
              client
                  .getPrimitiveValueBuilder()
                  .setText(String.valueOf(id))
                  .setType(EdmSimpleType.Int32)
                  .build()));
    } else {
      entity.addProperty(
          ODataObjectFactory.newPrimitiveProperty(
              "CustomerId",
              client
                  .getPrimitiveValueBuilder()
                  .setText(String.valueOf(0))
                  .setType(EdmSimpleType.Int32)
                  .build()));
    }
    final ODataCollectionValue backupContactInfoValue =
        new ODataCollectionValue(
            "Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails)");

    final ODataComplexValue contactDetails =
        new ODataComplexValue("Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails");

    final ODataCollectionValue altNamesValue = new ODataCollectionValue("Collection(Edm.String)");
    altNamesValue.add(
        client
            .getPrimitiveValueBuilder()
            .setText("My Alternative name")
            .setType(EdmSimpleType.String)
            .build());
    contactDetails.add(ODataObjectFactory.newCollectionProperty("AlternativeNames", altNamesValue));

    final ODataCollectionValue emailBagValue = new ODataCollectionValue("Collection(Edm.String)");
    emailBagValue.add(
        client
            .getPrimitiveValueBuilder()
            .setText("*****@*****.**")
            .setType(EdmSimpleType.String)
            .build());
    contactDetails.add(ODataObjectFactory.newCollectionProperty("EmailBag", emailBagValue));

    final ODataComplexValue contactAliasValue =
        new ODataComplexValue("Microsoft.Test.OData.Services.AstoriaDefaultService.Aliases");
    contactDetails.add(ODataObjectFactory.newComplexProperty("ContactAlias", contactAliasValue));

    final ODataCollectionValue aliasAltNamesValue =
        new ODataCollectionValue("Collection(Edm.String)");
    aliasAltNamesValue.add(
        client
            .getPrimitiveValueBuilder()
            .setText("myAlternativeName")
            .setType(EdmSimpleType.String)
            .build());
    contactAliasValue.add(
        ODataObjectFactory.newCollectionProperty("AlternativeNames", aliasAltNamesValue));

    final ODataComplexValue homePhone =
        new ODataComplexValue("Microsoft.Test.OData.Services.AstoriaDefaultService.Phone");
    homePhone.add(
        ODataObjectFactory.newPrimitiveProperty(
            "PhoneNumber",
            client
                .getPrimitiveValueBuilder()
                .setText("8437568356834568")
                .setType(EdmSimpleType.String)
                .build()));
    homePhone.add(
        ODataObjectFactory.newPrimitiveProperty(
            "Extension",
            client
                .getPrimitiveValueBuilder()
                .setText("124365426534621534423ttrf")
                .setType(EdmSimpleType.String)
                .build()));
    contactDetails.add(ODataObjectFactory.newComplexProperty("HomePhone", homePhone));

    backupContactInfoValue.add(contactDetails);
    entity.addProperty(
        ODataObjectFactory.newCollectionProperty("BackupContactInfo", backupContactInfoValue));
    if (withInlineInfo) {
      final ODataInlineEntity inlineInfo =
          ODataObjectFactory.newInlineEntity(
              "Info", URI.create("Customer(" + id + ")/Info"), getInfo(id, name + "_Info"));
      inlineInfo.getEntity().setMediaEntity(true);
      entity.addLink(inlineInfo);
    }

    return entity;
  }
  @Test
  public void createNoMultipleKey() {
    final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
    final String contentType = "application/json;odata=fullmetadata";
    final String prefer = "return-content";
    try {
      final ODataEntity message =
          ODataObjectFactory.newEntity(
              "Microsoft.Test.OData.Services.AstoriaDefaultService.Message");

      message.addProperty(
          ODataObjectFactory.newPrimitiveProperty(
              "MessageId",
              client
                  .getPrimitiveValueBuilder()
                  .setText(String.valueOf(25))
                  .setType(EdmSimpleType.Int32)
                  .build()));
      message.addProperty(
          ODataObjectFactory.newPrimitiveProperty(
              "FromUsername",
              client
                  .getPrimitiveValueBuilder()
                  .setText("user")
                  .setType(EdmSimpleType.String)
                  .build()));
      message.addProperty(
          ODataObjectFactory.newPrimitiveProperty(
              "ToUsername",
              client
                  .getPrimitiveValueBuilder()
                  .setValue("usernameabc")
                  .setType(EdmSimpleType.String)
                  .build()));
      message.addProperty(
          ODataObjectFactory.newPrimitiveProperty(
              "Subject",
              client
                  .getPrimitiveValueBuilder()
                  .setValue("Subject of message")
                  .setType(EdmSimpleType.String)
                  .build()));
      message.addProperty(
          ODataObjectFactory.newPrimitiveProperty(
              "Body",
              client
                  .getPrimitiveValueBuilder()
                  .setValue("Body Content")
                  .setType(EdmSimpleType.String)
                  .build()));
      message.addProperty(
          ODataObjectFactory.newPrimitiveProperty(
              "IsRead",
              client
                  .getPrimitiveValueBuilder()
                  .setValue(false)
                  .setType(EdmSimpleType.Boolean)
                  .build()));

      final URIBuilder builder =
          client.getURIBuilder(testDefaultServiceRootURL).appendEntitySetSegment("Message");
      final ODataEntityCreateRequest req =
          client.getCUDRequestFactory().getEntityCreateRequest(builder.build(), message);
      req.setFormat(format);
      req.setContentType(contentType);
      req.setPrefer(prefer);
      final ODataEntityCreateResponse res = req.execute();
      assertNotNull(res);
      assertEquals(201, res.getStatusCode());
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }