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;
  }
  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 void geoSpacialTest(final ODataPubFormat format, final String contentType, final String prefer, final int id) {
        try {
            final ODataEntity entity =
                    ODataFactory.newEntity("Microsoft.Test.OData.Services.AstoriaDefaultService.AllSpatialTypes");
            entity.addProperty(ODataFactory.newPrimitiveProperty("Id",
                    new ODataPrimitiveValue.Builder().setText(String.valueOf(id)).setType(EdmSimpleType.Int32).build()));

            final Point point1 = new Point(Geospatial.Dimension.GEOGRAPHY);
            point1.setX(6.2);
            point1.setY(1.1);
            final Point point2 = new Point(Geospatial.Dimension.GEOGRAPHY);
            point2.setX(33.33);
            point2.setY(-2.5);

            // create a point
            entity.addProperty(ODataFactory.newPrimitiveProperty("GeogPoint",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeographyPoint).
                    setValue(point1).build()));

            // create  multiple point
            final List<Point> points = new ArrayList<Point>();
            points.add(point1);
            points.add(point2);
            final MultiPoint multipoint = new MultiPoint(Geospatial.Dimension.GEOGRAPHY, points);
            entity.addProperty(ODataFactory.newPrimitiveProperty("GeogMultiPoint",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeographyMultiPoint).
                    setValue(multipoint).build()));

            // create a line
            final List<Point> linePoints = new ArrayList<Point>();
            linePoints.add(point1);
            linePoints.add(point2);
            final LineString lineString = new LineString(Geospatial.Dimension.GEOGRAPHY, linePoints);

            entity.addProperty(ODataFactory.newPrimitiveProperty("GeogLine",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeographyLineString).
                    setValue(lineString).build()));

            // create a polygon
            linePoints.set(1, point2);
            linePoints.add(point2);
            linePoints.add(point1);
            final Polygon polygon = new Polygon(Geospatial.Dimension.GEOGRAPHY, linePoints, linePoints);
            entity.addProperty(ODataFactory.newPrimitiveProperty("GeogPolygon",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeographyPolygon).
                    setValue(polygon).build()));

            // create a multi line string
            final List<LineString> multipleLines = new ArrayList<LineString>();
            multipleLines.add(lineString);
            multipleLines.add(lineString);
            final MultiLineString multiLine = new MultiLineString(Geospatial.Dimension.GEOGRAPHY, multipleLines);
            entity.addProperty(ODataFactory.newPrimitiveProperty("GeogMultiLine",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeographyMultiLineString).
                    setValue(multiLine).build()));

            // create a multi polygon        
            final List<Polygon> polygons = new ArrayList<Polygon>();
            polygons.add(polygon);
            polygons.add(polygon);
            final MultiPolygon multiPolygon = new MultiPolygon(Geospatial.Dimension.GEOGRAPHY, polygons);
            entity.addProperty(ODataFactory.newPrimitiveProperty("GeogMultiPolygon",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeographyMultiPolygon).
                    setValue(multiPolygon).build()));

            // create  acolletion of various shapes
            final List<Geospatial> geospatialCollection = new ArrayList<Geospatial>();
            geospatialCollection.add(point1);
            geospatialCollection.add(lineString);
            geospatialCollection.add(polygon);
            final GeospatialCollection collection = new GeospatialCollection(Geospatial.Dimension.GEOGRAPHY,
                    geospatialCollection);
            entity.addProperty(ODataFactory.newPrimitiveProperty("GeogCollection",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeographyCollection).
                    setValue(collection).build()));

            // with geometry test

            final Point goemPoint1 = new Point(Geospatial.Dimension.GEOMETRY);
            goemPoint1.setX(6.2);
            goemPoint1.setY(1.1);
            final Point goemPoint2 = new Point(Geospatial.Dimension.GEOMETRY);
            goemPoint2.setX(33.33);
            goemPoint2.setY(-2.5);

            // create a point
            entity.addProperty(ODataFactory.newPrimitiveProperty("GeomPoint",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeometryPoint).
                    setValue(goemPoint2).build()));

            // create  multiple point
            final List<Point> geomPoints = new ArrayList<Point>();
            geomPoints.add(point1);
            geomPoints.add(point2);
            final MultiPoint geomMultipoint = new MultiPoint(Geospatial.Dimension.GEOMETRY, geomPoints);
            entity.addProperty(ODataFactory.newPrimitiveProperty("GeomMultiPoint",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeometryMultiPoint).
                    setValue(geomMultipoint).build()));

            // create a line
            final List<Point> geomLinePoints = new ArrayList<Point>();
            geomLinePoints.add(goemPoint1);
            geomLinePoints.add(goemPoint2);
            final LineString geomLineString = new LineString(Geospatial.Dimension.GEOMETRY, geomLinePoints);

            entity.addProperty(ODataFactory.newPrimitiveProperty("GeomLine",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeometryLineString).
                    setValue(geomLineString).build()));

            // create a polygon
            geomLinePoints.set(1, goemPoint2);
            geomLinePoints.add(goemPoint2);
            geomLinePoints.add(goemPoint1);
            final Polygon geomPolygon = new Polygon(Geospatial.Dimension.GEOMETRY, geomLinePoints, geomLinePoints);
            entity.addProperty(ODataFactory.newPrimitiveProperty("GeomPolygon",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeometryPolygon).
                    setValue(geomPolygon).build()));

            // create a multi line string
            final List<LineString> geomMultipleLines = new ArrayList<LineString>();
            geomMultipleLines.add(geomLineString);
            geomMultipleLines.add(geomLineString);
            final MultiLineString geomMultiLine = new MultiLineString(Geospatial.Dimension.GEOMETRY, geomMultipleLines);
            entity.addProperty(ODataFactory.newPrimitiveProperty("GeomMultiLine",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeometryMultiLineString).
                    setValue(geomMultiLine).build()));

            // create a multi polygon        
            final List<Polygon> geomPolygons = new ArrayList<Polygon>();
            geomPolygons.add(geomPolygon);
            geomPolygons.add(geomPolygon);
            final MultiPolygon geomMultiPolygon = new MultiPolygon(Geospatial.Dimension.GEOMETRY, geomPolygons);
            entity.addProperty(ODataFactory.newPrimitiveProperty("GeomMultiPolygon",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeographyMultiPolygon).
                    setValue(geomMultiPolygon).build()));

            // create  a collection of various shapes
            final List<Geospatial> geomspatialCollection = new ArrayList<Geospatial>();
            geomspatialCollection.add(goemPoint1);
            geomspatialCollection.add(geomLineString);
            final GeospatialCollection geomCollection = new GeospatialCollection(Geospatial.Dimension.GEOMETRY,
                    geomspatialCollection);
            entity.addProperty(ODataFactory.newPrimitiveProperty("GeomCollection",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeometryCollection).
                    setValue(geomCollection).build()));

            // create request
            final ODataEntityCreateRequest createReq = ODataCUDRequestFactory.
                    getEntityCreateRequest(new ODataURIBuilder(testDefaultServiceRootURL).
                    appendEntityTypeSegment("AllGeoTypesSet").build(), entity);
            createReq.setFormat(format);
            createReq.setContentType(contentType);
            createReq.setPrefer(prefer);
            final ODataEntityCreateResponse createRes = createReq.execute();
            final ODataEntity entityAfterCreate = createRes.getBody();
            final ODataProperty geogCollection = entityAfterCreate.getProperty("GeogCollection");
            if (format.equals(ODataPubFormat.JSON) || format.equals(ODataPubFormat.JSON_NO_METADATA)) {
                assertTrue(geogCollection.hasComplexValue());
            } else {
                assertEquals(EdmSimpleType.GeographyCollection.toString(), geogCollection.getPrimitiveValue().
                        getTypeName());

                final ODataProperty geometryCollection = entityAfterCreate.getProperty("GeomCollection");
                assertEquals(EdmSimpleType.GeographyCollection.toString(),
                        geogCollection.getPrimitiveValue().getTypeName());

                int count = 0;
                for (Geospatial g : geogCollection.getPrimitiveValue().<GeospatialCollection>toCastValue()) {
                    assertNotNull(g);
                    count++;
                }
                assertEquals(3, count);
                count = 0;
                for (Geospatial g : geometryCollection.getPrimitiveValue().<GeospatialCollection>toCastValue()) {
                    assertNotNull(g);
                    count++;
                }
                assertEquals(2, count);
            }
            // update geog points 
            final Point updatePoint1 = new Point(Geospatial.Dimension.GEOGRAPHY);
            updatePoint1.setX(21.2);
            updatePoint1.setY(31.1);
            final Point updatePoint2 = new Point(Geospatial.Dimension.GEOGRAPHY);
            updatePoint2.setX(99.99);
            updatePoint2.setY(-3.24);
            ODataProperty property = entityAfterCreate.getProperty("GeogPoint");
            entityAfterCreate.removeProperty(property);
            entityAfterCreate.addProperty(ODataFactory.newPrimitiveProperty("GeogPoint",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeographyPoint).
                    setValue(updatePoint1).build()));
            updateGeog(format, contentType, prefer, entityAfterCreate, UpdateType.REPLACE, entityAfterCreate.getETag());

            // update geography line  
            final List<Point> updateLinePoints = new ArrayList<Point>();
            updateLinePoints.add(updatePoint1);
            updateLinePoints.add(updatePoint2);
            final LineString updateLineString = new LineString(Geospatial.Dimension.GEOGRAPHY, updateLinePoints);
            ODataProperty lineProperty = entityAfterCreate.getProperty("GeogLine");
            entityAfterCreate.removeProperty(lineProperty);
            entityAfterCreate.addProperty(ODataFactory.newPrimitiveProperty("GeogLine",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeographyLineString).
                    setValue(updateLineString).build()));
            //updateGeog(format,contentType, prefer, entityAfterCreate, UpdateType.REPLACE,entityAfterCreate.getETag());

            // update a geography polygon
            updateLinePoints.set(1, updatePoint2);
            updateLinePoints.add(updatePoint2);
            updateLinePoints.add(updatePoint1);
            final Polygon updatePolygon =
                    new Polygon(Geospatial.Dimension.GEOGRAPHY, updateLinePoints, updateLinePoints);
            ODataProperty polygonProperty = entityAfterCreate.getProperty("GeogPolygon");
            entityAfterCreate.removeProperty(polygonProperty);
            entityAfterCreate.addProperty(ODataFactory.newPrimitiveProperty("GeogPolygon",
                    new ODataGeospatialValue.Builder().setType(EdmSimpleType.GeographyPolygon).
                    setValue(updatePolygon).build()));
            //updateGeog(format,contentType, prefer, entityAfterCreate, UpdateType.REPLACE,entityAfterCreate.getETag());

            // delete the entity
            ODataURIBuilder deleteUriBuilder = new ODataURIBuilder(testDefaultServiceRootURL).
                    appendEntityTypeSegment("AllGeoTypesSet(" + id + ")");
            ODataDeleteRequest deleteReq = ODataCUDRequestFactory.getDeleteRequest(deleteUriBuilder.build());
            deleteReq.setFormat(format);
            deleteReq.setContentType(contentType);
            assertEquals(204, deleteReq.execute().getStatusCode());
        } catch (Exception e) {
            LOG.error("", e);
            if (format.equals(ODataPubFormat.JSON) || format.equals(ODataPubFormat.JSON_NO_METADATA)) {
                assertTrue(true);
            } else {
                fail(e.getMessage());
            }
        } catch (AssertionError e) {
            LOG.error("", e);
            fail(e.getMessage());
        }
    }
  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());
    }
  }