Exemple #1
0
 /**
  * Binds Json data to this form - that is, handles form submission.
  *
  * @param data data to submit
  * @return a copy of this form filled with the new data
  */
 public Form<T> bind(com.fasterxml.jackson.databind.JsonNode data, String... allowedFields) {
   return bind(
       play.libs.Scala.asJava(
           play.api.data.FormUtils.fromJson(
               "", play.api.libs.json.Json.parse(play.libs.Json.stringify(data)))),
       allowedFields);
 }
 public static Result route(Application app, FakeRequest fakeRequest, byte[] body, long timeout) {
   return wrapScalaResult(
       Scala.orNull(
           play.api.test.Helpers.jRoute(
               app.getWrappedApplication(), fakeRequest.getWrappedRequest(), body)),
       timeout);
 }
 public final Seq<play.api.db.evolutions.Evolution> evolutions(String db) {
   Collection<Evolution> evolutions = getEvolutions(db);
   if (evolutions != null) {
     List<play.api.db.evolutions.Evolution> scalaEvolutions =
         evolutions
             .stream()
             .map(
                 e ->
                     new play.api.db.evolutions.Evolution(
                         e.getRevision(), e.getSqlUp(), e.getSqlDown()))
             .collect(toList());
     return Scala.asScala(scalaEvolutions);
   } else {
     return Scala.asScala(Collections.emptyList());
   }
 }
Exemple #4
0
 @SuppressWarnings("unchecked")
 public static Result route(Application app, RequestBuilder requestBuilder, long timeout) {
   final scala.Option<scala.concurrent.Future<play.api.mvc.Result>> opt =
       play.api.test.Helpers.jRoute(
           app.getWrappedApplication(),
           requestBuilder.build()._underlyingRequest(),
           requestBuilder.body());
   return wrapScalaResult(Scala.orNull(opt), timeout);
 }
  /**
   * Create a fake application.
   *
   * @param path application environment root path
   * @param classloader application environment class loader
   * @param additionalConfiguration additional configuration for the application
   */
  @SuppressWarnings("unchecked")
  public FakeApplication(
      File path, ClassLoader classloader, Map<String, ? extends Object> additionalConfiguration) {

    this.application =
        new play.api.test.FakeApplication(
            path,
            classloader,
            Scala.asScala((Map<String, Object>) additionalConfiguration),
            scala.PartialFunction$.MODULE$.<scala.Tuple2<String, String>, Handler>empty());
    this.config = application.injector().instanceOf(Config.class);
    this.injector = application.injector().instanceOf(Injector.class);
  }
Exemple #6
0
 /**
  * Retrieve the URL where the user should be redirected to start the OpenID authentication process
  */
 public static F.Promise<String> redirectURL(
     String openID,
     String callbackURL,
     Map<String, String> axRequired,
     Map<String, String> axOptional,
     String realm) {
   if (axRequired == null) axRequired = new HashMap<String, String>();
   if (axOptional == null) axOptional = new HashMap<String, String>();
   return F.Promise.wrap(
       play.api.libs.openid.OpenID.redirectURL(
           openID,
           callbackURL,
           JavaConversions.mapAsScalaMap(axRequired).toSeq(),
           JavaConversions.mapAsScalaMap(axOptional).toSeq(),
           Scala.Option(realm)));
 }
 public static Result route(Application app, FakeRequest fakeRequest, long timeout) {
   final scala.Option<scala.concurrent.Future<play.api.mvc.Result>> opt =
       play.api.test.Helpers.jRoute(app.getWrappedApplication(), fakeRequest.fake);
   return wrapScalaResult(Scala.orNull(opt), timeout);
 }
 /** Constructs a in-memory (h2) database configuration to add to a FakeApplication. */
 public static Map<String, String> inMemoryDatabase(String name, Map<String, String> options) {
   return Scala.asJava(play.api.test.Helpers.inMemoryDatabase(name, Scala.asScala(options)));
 }
Exemple #9
0
  protected Map<String, String> requestData(Http.Request request) {

    Map<String, String[]> urlFormEncoded = new HashMap<>();
    if (request.body().asFormUrlEncoded() != null) {
      urlFormEncoded = request.body().asFormUrlEncoded();
    }

    Map<String, String[]> multipartFormData = new HashMap<>();
    if (request.body().asMultipartFormData() != null) {
      multipartFormData = request.body().asMultipartFormData().asFormUrlEncoded();
    }

    Map<String, String> jsonData = new HashMap<>();
    if (request.body().asJson() != null) {
      jsonData =
          play.libs.Scala.asJava(
              play.api.data.FormUtils.fromJson(
                  "",
                  play.api.libs.json.Json.parse(
                      play.libs.Json.stringify(request.body().asJson()))));
    }

    Map<String, String[]> queryString = request.queryString();

    Map<String, String> data = new HashMap<>();

    for (String key : urlFormEncoded.keySet()) {
      String[] values = urlFormEncoded.get(key);
      if (key.endsWith("[]")) {
        String k = key.substring(0, key.length() - 2);
        for (int i = 0; i < values.length; i++) {
          data.put(k + "[" + i + "]", values[i]);
        }
      } else {
        if (values.length > 0) {
          data.put(key, values[0]);
        }
      }
    }

    for (String key : multipartFormData.keySet()) {
      String[] values = multipartFormData.get(key);
      if (key.endsWith("[]")) {
        String k = key.substring(0, key.length() - 2);
        for (int i = 0; i < values.length; i++) {
          data.put(k + "[" + i + "]", values[i]);
        }
      } else {
        if (values.length > 0) {
          data.put(key, values[0]);
        }
      }
    }

    for (String key : jsonData.keySet()) {
      data.put(key, jsonData.get(key));
    }

    for (String key : queryString.keySet()) {
      String[] values = queryString.get(key);
      if (key.endsWith("[]")) {
        String k = key.substring(0, key.length() - 2);
        for (int i = 0; i < values.length; i++) {
          data.put(k + "[" + i + "]", values[i]);
        }
      } else {
        if (values.length > 0) {
          data.put(key, values[0]);
        }
      }
    }

    return data;
  }
 /**
  * Retrieves a configuration value as a <code>String</code>.
  *
  * @param key configuration key (relative to configuration root key)
  * @return a configuration value or <code>null</code>
  */
 @SuppressWarnings("unused")
 private static String getString(String key) {
   return Scala.orNull(
       conf.getString(
           key, scala.Option.<scala.collection.immutable.Set<java.lang.String>>empty()));
 }