Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
MilderJoghurt
rlf-server
Commits
f5fc08c8
Commit
f5fc08c8
authored
May 28, 2015
by
Fjen Undso
Browse files
test: add initial SessionController tests
parent
329c1c64
Changes
1
Hide whitespace changes
Inline
Side-by-side
test/ControllerTest.java
0 → 100644
View file @
f5fc08c8
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
play
.
mvc
.
Http
.
Status
.
OK
;
import
static
play
.
test
.
Helpers
.
contentAsString
;
import
static
play
.
test
.
Helpers
.
contentType
;
import
static
play
.
test
.
Helpers
.
status
;
import
java.util.Arrays
;
import
java.util.List
;
import
models.Session
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
play.libs.Json
;
import
play.mvc.Result
;
import
play.test.FakeApplication
;
import
play.test.Helpers
;
import
com.avaje.ebean.EbeanServer
;
import
com.avaje.ebeaninternal.server.ddl.DdlGenerator
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
controllers.SessionController
;
public
class
ControllerTest
{
public
static
FakeApplication
app
;
public
static
DdlGenerator
ddl
;
public
static
EbeanServer
server
;
@Before
public
void
setup
()
{
app
=
Helpers
.
fakeApplication
(
Helpers
.
inMemoryDatabase
());
Helpers
.
start
(
app
);
}
@After
public
void
stopApp
()
{
Helpers
.
stop
(
app
);
}
@Test
public
void
testGetSessionsEmpty
()
{
// Empty Sessionlist
Result
result
=
SessionController
.
getSessions
();
assertEquals
(
OK
,
status
(
result
));
assertEquals
(
"application/json"
,
contentType
(
result
));
JsonNode
json
=
Json
.
parse
(
contentAsString
(
result
));
Session
[]
sessionArray
=
Json
.
fromJson
(
json
,
Session
[].
class
);
assertEquals
(
0
,
sessionArray
.
length
);
}
@Test
public
void
testGetSessions
()
{
// Filled Sessionlist
Session
s1
=
new
Session
(
"owner1"
,
"Session1"
);
s1
.
save
();
Session
s2
=
new
Session
(
"owner1"
,
"Session2"
);
s2
.
save
();
Result
result
=
SessionController
.
getSessions
();
assertEquals
(
OK
,
status
(
result
));
assertEquals
(
"application/json"
,
contentType
(
result
));
JsonNode
json
=
Json
.
parse
(
contentAsString
(
result
));
Session
[]
sessionArray
=
Json
.
fromJson
(
json
,
Session
[].
class
);
List
<
Session
>
sessionList
=
Arrays
.
asList
(
sessionArray
);
assertEquals
(
2
,
sessionArray
.
length
);
assertEquals
(
Session
.
find
.
all
(),
sessionList
);
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment