/**
  * Builds XML or JSON Representation of Project for Create and Update methods.
  *
  * @param item Project
  * @param media APPLICATION_XML or APPLICATION_JSON
  * @return XML or JSON Representation
  */
 public static Representation getRepresentation(TaskModel item, MediaType media) {
   if (media.equals(MediaType.APPLICATION_JSON)) {
     return new JacksonRepresentation<TaskModel>(item);
   } else if (media.equals(MediaType.APPLICATION_XML)) {
     XStream xstream = XStreamFactory.getInstance().getXStream(media, false);
     XstreamRepresentation<TaskModel> rep = new XstreamRepresentation<TaskModel>(media, item);
     configure(xstream);
     rep.setXstream(xstream);
     return rep;
   } else {
     Engine.getLogger(AbstractSitoolsTestCase.class.getName())
         .warning("Only JSON or XML supported in tests");
     return null; // TODO complete test with ObjectRepresentation
   }
 }
  /**
   * REST API Response Representation wrapper for single or multiple items expexted
   *
   * @param media MediaType expected
   * @param representation service response representation
   * @param dataClass class expected for items of the Response object
   * @param isArray if true wrap the data property else wrap the item property
   * @return Response
   */
  public static Response getResponseOrderandUserstorage(
      MediaType media, Representation representation, Class<?> dataClass, boolean isArray) {
    try {
      if (!media.isCompatible(MediaType.APPLICATION_JSON)
          && !media.isCompatible(MediaType.APPLICATION_XML)) {
        Engine.getLogger(AbstractSitoolsTestCase.class.getName())
            .warning("Only JSON or XML supported in tests");
        return null;
      }

      XStream xstream = XStreamFactory.getInstance().getXStreamReader(media);
      xstream.autodetectAnnotations(false);
      xstream.alias("response", Response.class);

      // for order
      xstream.alias("order", Order.class);

      // for userstorage
      xstream.alias("userstorage", UserStorage.class);
      xstream.alias("diskStorage", DiskStorage.class);

      if (isArray) {
        xstream.alias("item", dataClass);
        xstream.alias("item", Object.class, dataClass);
        // xstream.omitField(Response.class, "data");
        if (media.isCompatible(MediaType.APPLICATION_JSON)) {
          xstream.addImplicitCollection(Response.class, "data", dataClass);
          xstream.addImplicitCollection(Order.class, "events", Event.class);
          xstream.addImplicitCollection(Order.class, "resourceCollection", String.class);
        }

      } else {
        xstream.alias("item", dataClass);
        xstream.alias("item", Object.class, dataClass);

        if (dataClass == Order.class) {
          xstream.aliasField("order", Response.class, "item");
          if (media.isCompatible(MediaType.APPLICATION_JSON)) {
            xstream.addImplicitCollection(Order.class, "events", Event.class);
            xstream.addImplicitCollection(Order.class, "resourceCollection", String.class);
          }
        }
        if (dataClass == UserStorage.class) {
          xstream.aliasField("userstorage", Response.class, "item");
        }
      }
      xstream.aliasField("data", Response.class, "data");

      SitoolsXStreamRepresentation<Response> rep =
          new SitoolsXStreamRepresentation<Response>(representation);
      rep.setXstream(xstream);

      if (media.isCompatible(getMediaTest())) {
        Response response = rep.getObject("response");

        return response;
      } else {
        Engine.getLogger(AbstractSitoolsTestCase.class.getName())
            .warning("Only JSON or XML supported in tests");
        return null; // TODO complete test with ObjectRepresentation
      }
    } finally {
      RIAPUtils.exhaust(representation);
    }
  }