読者です 読者をやめる 読者になる 読者になる

GMOクラウド VPSにplay2.1.0のセットアップ

yum install wget
yum install unzip
yum install java-1.6.0-openjdk
yum install java-1.6.0-openjdk-devel
wget http://downloads.typesafe.com/play/2.1.0/play-2.1.0.zip
unzip play-2.1.0.zip
vi .bash_profile #> play-2.1.0のパスを.bash_profileに追加
source .bash_profile

.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
PATH=$PATH:$HOME/play-2.1.0

export PATH

playのセットアップ完了。

アプリの作成

play new test #>[Enter] [2](java) [Enter]
cd test
play clean compile test stage #クリーン、コンパイル、テスト、
./stage/start #> アプリケーション実行

f:id:mitsugi-bb:20130314074015p:plain

これでOK!

少しだけソース修正

package controllers;

import play.*;
import play.mvc.*;

import views.html.*;

public class Application extends Controller {

    public static Result index() {
//        return ok(index.render("Your new application is ready.")
        return ok(index.render("あなたの新しいアプリケーションの準備完了!")
    }

}

コンパイル〜テスト。。。

play clean compile test stage
[info] Loading project definition from /root/test/project
[info] Set current project to test (in build file:/root/test/)
[success] Total time: 0 s, completed 2013/03/14 7:43:48
[info] Updating {file:/root/test/}test...
[info] Resolving org.hibernate.javax.persistence#hibernate-jpa-2.0-api;1.0.1.Fin                                                                                [info] Done updating.                                                        
[info] Compiling 4 Scala sources and 2 Java sources to /root/test/target/scala-2.10/classes...
[success] Total time: 17 s, completed 2013/03/14 7:44:05
[info] Compiling 2 Java sources to /root/test/target/scala-2.10/test-classes...
[error] Test IntegrationTest.test failed: java.lang.AssertionError: <'<?xml version="1.0" encoding="utf-8"?>
[error] <html>
[error]   <head>
[error]     <title>
[error]       Welcome to Play 2.1
[error]     </title>
[error]     <link rel="stylesheet" media="screen" href="/assets/stylesheets/main.css"/>
[error]     <link rel="shortcut icon" type="image/png" href="/assets/images/favicon.png"/>
[error]     <script src="/assets/javascripts/jquery-1.9.0.min.js" type="text/javascript">
[error]     </script>
[error]   </head>
[error]   <body style="zoom: 1;">
[error]     <h1>
[error]       あなたの新しいアプリケーションの準備完了!
[error]     </h1>
[error]   </body>
[error] </html>
[error] '> should contain the String:<'Your new application is ready.'>
[error]     at play.test.Helpers.running(Helpers.java:426)
[error]     at IntegrationTest.test(IntegrationTest.java:20)
[error]     ...
[error] Caused by: java.lang.AssertionError: <'<?xml version="1.0" encoding="utf-8"?>
[error] <html>
[error]   <head>
[error]     <title>
[error]       Welcome to Play 2.1
[error]     </title>
[error]     <link rel="stylesheet" media="screen" href="/assets/stylesheets/main.css"/>
[error]     <link rel="shortcut icon" type="image/png" href="/assets/images/favicon.png"/>
[error]     <script src="/assets/javascripts/jquery-1.9.0.min.js" type="text/javascript">
[error]     </script>
[error]   </head>
[error]   <body style="zoom: 1;">
[error]     <h1>
[error]       あなたの新しいアプリケーションの準備完了!
[error]     </h1>
[error]   </body>
[error] </html>
[error] '> should contain the String:<'Your new application is ready.'>
[error]     at org.fest.assertions.Fail.failure(Fail.java:228)
[error]     at org.fest.assertions.Assert.failure(Assert.java:149)
[error]     at org.fest.assertions.StringAssert.contains(StringAssert.java:73)
[error]     at IntegrationTest$1.invoke(IntegrationTest.java:23)
[error]     at IntegrationTest$1.invoke(IntegrationTest.java:20)
[error]     at play.test.Helpers.running(Helpers.java:424)
[error]     ... 32 more
[info] IntegrationTest
[info] x IntegrationTest.test
[info] 
[info] 
[info] Total for test IntegrationTest
[info] Finished in 0.039 seconds
[info] 1 tests, 1 failures, 0 errors
[info] ApplicationTest
[info] + ApplicationTest.simpleCheck
[info] + ApplicationTest.renderTemplate
[info] 
[info] 
[info] Total for test ApplicationTest
[info] Finished in 0.014 seconds
[info] 2 tests, 0 failures, 0 errors
[error] Failed: : Total 3, Failed 1, Errors 0, Passed 2, Skipped 0
[error] Failed tests:
[error]     IntegrationTest
java.lang.RuntimeException: Tests unsuccessful
    at scala.sys.package$.error(package.scala:27)
    at scala.Predef$.error(Predef.scala:123)
    at sbt.Tests$.showResults(Tests.scala:192)
    at sbt.Defaults$$anonfun$testTasks$6.apply(Defaults.scala:296)
    at sbt.Defaults$$anonfun$testTasks$6.apply(Defaults.scala:294)
    at sbt.Scoped$$anonfun$hf4$1.apply(Structure.scala:580)
    at sbt.Scoped$$anonfun$hf4$1.apply(Structure.scala:580)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:49)
    at sbt.Scoped$Reduced$$anonfun$combine$1$$anonfun$apply$12.apply(Structure.scala:311)
    at sbt.Scoped$Reduced$$anonfun$combine$1$$anonfun$apply$12.apply(Structure.scala:311)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:41)
    at sbt.std.Transform$$anon$5.work(System.scala:71)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:232)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:232)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.Execute.work(Execute.scala:238)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:232)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:232)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:679)
[error] (test:test) Tests unsuccessful
[error] Total time: 9 s, completed 2013/03/14 7:44:14

IntegrationTestで失敗。

「inMemoryDatabaseでポート3333でfakeApplicationを立ち上げて、ブラウザでアクセスして結果に該当の文字列が含まれているかどうか」というテストに引っかかっておりました。

というわけでテスト修正

import org.junit.*;

import play.mvc.*;
import play.test.*;
import play.libs.F.*;

import static play.test.Helpers.*;
import static org.fest.assertions.Assertions.*;

import static org.fluentlenium.core.filter.FilterConstructor.*;

public class IntegrationTest {

    /**
     * add your integration test here
     * in this example we just check if the welcome page is being shown
     */   
    @Test
    public void test() {
        running(testServer(3333, fakeApplication(inMemoryDatabase())), HTMLUNIT, new Callback<TestBrowser>() {
            public void invoke(TestBrowser browser) {
                browser.goTo("http://localhost:3333");
//                assertThat(browser.pageSource()).contains("Your new application is ready.");
                assertThat(browser.pageSource()).contains("あなたの新しいアプリケーションの準備完了!");
            }
        });
    }
  
}

再度コンパイル、テスト。でそのまま実行

play clean compile test stage
./target/start

f:id:mitsugi-bb:20130314075119p:plain

プログラム修正ができました。