what is syntax of data.yml?

33 views
Skip to first unread message

wgm

unread,
Aug 27, 2011, 12:13:13 AM8/27/11
to play-framework
before I run the junit test ,I load some data from data.yml which
under ‘test’ directory.but it throw following exception:
A java.lang.RuntimeException has been caught, Cannot load fixture
data.yml: java.lang.String cannot be cast to java.util.Map
In /test/BasicTest.java, line 103 :
Fixtures.loadModels("data.yml");
java.lang.RuntimeException: Cannot load fixture data.yml:
java.lang.String cannot be cast to java.util.Map
at play.test.Fixtures.loadModels(Fixtures.java:221)
at BasicTest.fullTest(BasicTest.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod
$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:
15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:
41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:
20)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:
28)
at play.test.PlayJUnitRunner$StartPlay
$2$1.evaluate(PlayJUnitRunner.java:98)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
76)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at play.test.PlayJUnitRunner.run(PlayJUnitRunner.java:48)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
at org.junit.runner.JUnitCore.run(JUnitCore.java:117)
at play.test.TestEngine.run(TestEngine.java:101)
at controllers.TestRunner.run(TestRunner.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:
540)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:498)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:
474)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:
469)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:157)
at play.server.PlayHandler$NettyInvocation.execute(PlayHandler.java:
237)
at play.Invoker$Invocation.run(Invoker.java:264)
at play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:217)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:
441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ScheduledThreadPoolExecutor
$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor
$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:207)
at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassCastException: java.lang.String cannot be
cast to java.util.Map
at play.test.Fixtures.loadModels(Fixtures.java:192)
... 53 more


The data.yml as following:
User(wgm):
email:w...@163.com
password:123456
fullname:wuguoming

User(jeff):
email:je...@163.com
password:123456
fullname:jeff

Post(firstWgmPost):
title:about the model layer
postedAt:2011-8-26
author:wgm
content:>
The model has a central position in a Play! application.
It is the domain-specific
representation of the information on which the application
operates.

Martin fowler defines it as:

Responsible for representing concepts of the business,
information about the
business situation, and business rules. State that
reflects the business situation
is controlled and used here, even though the technical
details of storing it are
delegated to the infrastructure. This layer is the heart
of business software.

Post(secondWgmPost):
title:Just a test of YABE
postedAt:2011-8-27
author:wgm
content:>
Well, it's just a test.

Post(jeffPost):
title:The MVC application
postedAt:2011-8-28
author:jeff
content:>
A Play! application follows the MVC architectural pattern
as applied to the
architecture of the Web.

This pattern splits the application into separate
layers:the Presentation
layer and the Model layer. The Presentation layer is
further split into a
View and a Controller layer.

Comment(c1):
author:guest
post:firstWgmPost
postedAt:2011-8-28
content:>
You are right !

Comment(c2):
author:mike
post:secondWgmPost
postedAt:2011-8-29
content:>
I knew that ...

Comment(c3):
author:tom
post:secondWgmPost
postedAt:2011-8-30
content:>
This post is useless ?

Could someone advice me why throw such exception?And what is syntax of
data.yml?

Keith Swallow

unread,
Aug 27, 2011, 12:13:15 PM8/27/11
to play-fr...@googlegroups.com
Hi Wgm,

This error message implies that you are pulling a string from your fixtures file and are trying to cast it to a Map in your model file. Perhaps you are getting one blog post when you expect many to appear in a map?

Cheers,

Keith
Reply all
Reply to author
Forward
0 new messages