0

play 2.1 でコントローラーのテストを実行すると、奇妙な問題が発生します。

    package controllers;

import static org.fest.assertions.Assertions.assertThat;
import static play.mvc.Http.Status.OK;
import static play.test.Helpers.callAction;
import static play.test.Helpers.charset;
import static play.test.Helpers.contentType;
import static play.test.Helpers.status;

import models.Section;
import models.Topic;

import org.junit.Test;

import play.mvc.Result;

public class TopicsTest extends BaseControllerTest{
    @Test
    public void testCallList() {
        Section s = new Section();
        s.name = "Music section";
        s.id = 1L;
        s.description = "section about music";
        s.save();
        System.out.println(Section.find.where().eq("name", "Music section").findUnique().id); // output 1
        Result result = callAction(controllers.routes.ref.Topics.list(1));
        assertThat(status(result)).isEqualTo(OK);
    }
}

コントローラーのコードは非常にシンプルで、dev で動作します。ちょうどよくモード。それを確認してください:

public static Result list(Long id) {
    return ok(list.render(Section.find.byId(id)));
}

エラー スタック トレース:

java.lang.RuntimeException: java.lang.NoSuchMethodError: models.Section.getName()Ljava/lang/String;
    at play.libs.F$Promise$6.apply(F.java:401)
    at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:253)
    at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:249)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:29)
    at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.liftedTree1$1(BatchingExecutor.scala:67)
    at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.processBatch$1(BatchingExecutor.scala:66)
    at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply$mcV$sp(BatchingExecutor.scala:82)
    at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply(BatchingExecutor.scala:59)
    at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply(BatchingExecutor.scala:59)
    at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:72)
    at akka.dispatch.BatchingExecutor$Batch.run(BatchingExecutor.scala:58)
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:137)
    at scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1441)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:262)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
Caused by: java.lang.NoSuchMethodError: models.Section.getName()Ljava/lang/String;
    at views.html.topics.list$.apply(list.template.scala:32)
    at views.html.topics.list$.render(list.template.scala:62)
    at views.html.topics.list.render(list.template.scala)
    at controllers.Topics.list(Topics.java:24)
    at controllers.ref.ReverseTopics$$anonfun$list$3.apply(routes_reverseRouting.scala:761)
    at controllers.ref.ReverseTopics$$anonfun$list$3.apply(routes_reverseRouting.scala:761)
    at play.core.Router$HandlerInvoker$$anon$6$$anon$2.invocation(Router.scala:141)
    at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:31)
    at play.core.j.JavaAction$$anon$2.apply(JavaAction.scala:74)
    at play.core.j.JavaAction$$anon$2.apply(JavaAction.scala:73)
    at play.libs.F$Promise$PromiseActor.onReceive(F.java:420)
    at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:159)
    at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425)
    at akka.actor.ActorCell.invoke(ActorCell.scala:386)
    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:230)
    at akka.dispatch.Mailbox.run(Mailbox.scala:212)
    at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:502)
    ... 4 more

解決策を見つけるのを手伝ってください。または、このテストを偽造してください。

4

1 に答える 1

1

Play がモデル クラスのフィールドにアクセスできないようです (getter と setter を生成していないようです)。その場合の非常に明白な解決策は、独自のゲッター (およびセッター) を明示的に記述して、Play が何があってもそれらを見つけられるようにすることです。

于 2013-06-06T16:53:03.110 に答える