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;
  }
コード例 #2
0
  private ODataEntity sampleODataEntity() throws IOException {
    final ODataEntity entity =
        getClient()
            .getObjectFactory()
            .newEntity("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer");

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

    // add key attribute
    entity.addProperty(
        getClient()
            .getObjectFactory()
            .newPrimitiveProperty(
                "CustomerId",
                getClient()
                    .getPrimitiveValueBuilder()
                    .setText("0")
                    .setType(EdmSimpleType.Int32)
                    .build()));

    // add BackupContactInfo attribute (collection)
    final ODataCollectionValue bciv =
        new ODataCollectionValue(
            "Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails)");
    entity.addProperty(
        getClient().getObjectFactory().newCollectionProperty("BackupContactInfo", bciv));

    // add BackupContactInfo.ContactDetails attribute (complex)
    final ODataComplexValue contactDetails =
        new ODataComplexValue("Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails");
    bciv.add(contactDetails);

    // add BackupContactInfo.ContactDetails.AlternativeNames attribute (collection)
    final ODataCollectionValue altNamesValue = new ODataCollectionValue("Collection(Edm.String)");
    altNamesValue.add(
        getClient()
            .getPrimitiveValueBuilder()
            .setText("myname")
            .setType(EdmSimpleType.String)
            .build());
    contactDetails.add(
        getClient().getObjectFactory().newCollectionProperty("AlternativeNames", altNamesValue));

    // add BackupContactInfo.ContactDetails.EmailBag attribute (collection)
    final ODataCollectionValue emailBagValue = new ODataCollectionValue("Collection(Edm.String)");
    emailBagValue.add(
        getClient()
            .getPrimitiveValueBuilder()
            .setText("*****@*****.**")
            .setType(EdmSimpleType.String)
            .build());
    contactDetails.add(
        getClient().getObjectFactory().newCollectionProperty("EmailBag", emailBagValue));

    // add BackupContactInfo.ContactDetails.ContactAlias attribute (complex)
    final ODataComplexValue contactAliasValue =
        new ODataComplexValue("Microsoft.Test.OData.Services.AstoriaDefaultService.Aliases");
    contactDetails.add(
        getClient().getObjectFactory().newComplexProperty("ContactAlias", contactAliasValue));

    // add BackupContactInfo.ContactDetails.ContactAlias.AlternativeNames attribute (collection)
    final ODataCollectionValue aanv = new ODataCollectionValue("Collection(Edm.String)");
    aanv.add(
        getClient()
            .getPrimitiveValueBuilder()
            .setText("myAlternativeName")
            .setType(EdmSimpleType.String)
            .build());
    contactAliasValue.add(
        getClient().getObjectFactory().newCollectionProperty("AlternativeNames", aanv));

    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;
  }