Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bspastoriza19-esi-solutions
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Breixo Senra Pastoriza
bspastoriza19-esi-solutions
Commits
40bf4a1a
Commit
40bf4a1a
authored
Oct 27, 2015
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds the HasHttpStatus matcher
This matchers makes the Response status easier to check in tests.
parent
f739d617
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
26 deletions
+73
-26
OwnerResourceRestTest.java
...st/java/es/uvigo/esei/xcs/rest/OwnerResourceRestTest.java
+19
-15
OwnerResourceUnitTest.java
...st/java/es/uvigo/esei/xcs/rest/OwnerResourceUnitTest.java
+14
-11
HasHttpStatus.java
.../main/java/es/uvigo/esei/xcs/http/util/HasHttpStatus.java
+40
-0
No files found.
rest/src/test/java/es/uvigo/esei/xcs/rest/OwnerResourceRestTest.java
View file @
40bf4a1a
...
...
@@ -11,8 +11,12 @@ import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.newOwnerWithPersis
import
static
es
.
uvigo
.
esei
.
xcs
.
domain
.
entities
.
OwnersDataset
.
newOwnerWithoutPets
;
import
static
es
.
uvigo
.
esei
.
xcs
.
domain
.
entities
.
OwnersDataset
.
owner
;
import
static
es
.
uvigo
.
esei
.
xcs
.
domain
.
entities
.
OwnersDataset
.
owners
;
import
static
es
.
uvigo
.
esei
.
xcs
.
http
.
util
.
HasHttpStatus
.
hasHttpStatus
;
import
static
javax
.
ws
.
rs
.
client
.
Entity
.
json
;
import
static
org
.
hamcrest
.
CoreMatchers
.
equalTo
;
import
static
javax
.
ws
.
rs
.
core
.
Response
.
Status
.
BAD_REQUEST
;
import
static
javax
.
ws
.
rs
.
core
.
Response
.
Status
.
CREATED
;
import
static
javax
.
ws
.
rs
.
core
.
Response
.
Status
.
METHOD_NOT_ALLOWED
;
import
static
javax
.
ws
.
rs
.
core
.
Response
.
Status
.
OK
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
...
...
@@ -80,7 +84,7 @@ public class OwnerResourceRestTest {
)
throws
Exception
{
final
Response
response
=
webTarget
.
request
().
get
();
assertThat
(
response
.
getStatusInfo
(),
is
(
equalTo
(
Response
.
Status
.
OK
)
));
assertThat
(
response
,
hasHttpStatus
(
OK
));
final
Owner
owner
=
response
.
readEntity
(
Owner
.
class
);
final
Owner
expected
=
owner
(
"pepe"
);
...
...
@@ -107,8 +111,8 @@ public class OwnerResourceRestTest {
@ArquillianResteasyResource
(
BASE_PATH
+
NON_EXISTENT_LOGIN
)
ResteasyWebTarget
webTarget
)
throws
Exception
{
final
Response
response
=
webTarget
.
request
().
get
();
assertThat
(
response
.
getStatusInfo
(),
is
(
equalTo
(
Response
.
Status
.
BAD_REQUEST
)
));
assertThat
(
response
,
hasHttpStatus
(
BAD_REQUEST
));
}
@Test
@InSequence
(
6
)
...
...
@@ -131,7 +135,7 @@ public class OwnerResourceRestTest {
)
throws
Exception
{
final
Response
response
=
webTarget
.
request
().
get
();
assertThat
(
response
.
getStatusInfo
(),
is
(
equalTo
(
Response
.
Status
.
OK
)
));
assertThat
(
response
,
hasHttpStatus
(
OK
));
final
List
<
Owner
>
list
=
ListOwnerType
.
readEntity
(
response
);
assertThat
(
list
,
containsOwnersInAnyOrder
(
owners
()));
...
...
@@ -190,8 +194,8 @@ public class OwnerResourceRestTest {
private
void
testCreateOwner
(
WebTarget
webTarget
,
Owner
newOwner
,
Owner
persistentOwner
)
{
final
Response
response
=
webTarget
.
request
().
post
(
json
(
newOwner
));
assertThat
(
response
.
getStatusInfo
(),
is
(
equalTo
(
Response
.
Status
.
CREATED
)
));
assertThat
(
response
,
hasHttpStatus
(
CREATED
));
final
String
location
=
response
.
getHeaderString
(
"Location"
);
...
...
@@ -217,8 +221,8 @@ public class OwnerResourceRestTest {
owner
.
changePassword
(
"newpassword"
);
final
Response
response
=
webTarget
.
request
().
put
(
json
(
owner
));
assertThat
(
response
.
getStatusInfo
(),
is
(
equalTo
(
Response
.
Status
.
OK
)
));
assertThat
(
response
,
hasHttpStatus
(
OK
));
}
@Test
@InSequence
(
32
)
...
...
@@ -240,8 +244,8 @@ public class OwnerResourceRestTest {
@ArquillianResteasyResource
(
BASE_PATH
+
OWNER_WITHOUT_PETS_LOGIN
)
ResteasyWebTarget
webTarget
)
throws
Exception
{
final
Response
response
=
webTarget
.
request
().
delete
();
assertThat
(
response
.
getStatusInfo
(),
is
(
equalTo
(
Response
.
Status
.
OK
)
));
assertThat
(
response
,
hasHttpStatus
(
OK
));
}
@Test
@InSequence
(
42
)
...
...
@@ -263,8 +267,8 @@ public class OwnerResourceRestTest {
@ArquillianResteasyResource
(
BASE_PATH
+
OWNER_WITH_PETS_LOGIN
)
ResteasyWebTarget
webTarget
)
throws
Exception
{
final
Response
response
=
webTarget
.
request
().
delete
();
assertThat
(
response
.
getStatusInfo
(),
is
(
equalTo
(
Response
.
Status
.
OK
)
));
assertThat
(
response
,
hasHttpStatus
(
OK
));
}
@Test
@InSequence
(
45
)
...
...
@@ -286,8 +290,8 @@ public class OwnerResourceRestTest {
@ArquillianResteasyResource
(
BASE_PATH
)
ResteasyWebTarget
webTarget
)
throws
Exception
{
final
Response
response
=
webTarget
.
request
().
delete
();
assertThat
(
response
.
getStatusInfo
(),
is
(
equalTo
(
Response
.
Status
.
METHOD_NOT_ALLOWED
)
));
assertThat
(
response
,
hasHttpStatus
(
METHOD_NOT_ALLOWED
));
}
@Test
@InSequence
(
48
)
...
...
rest/src/test/java/es/uvigo/esei/xcs/rest/OwnerResourceUnitTest.java
View file @
40bf4a1a
...
...
@@ -7,8 +7,11 @@ import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.anyOwner;
import
static
es
.
uvigo
.
esei
.
xcs
.
domain
.
entities
.
OwnersDataset
.
newOwnerWithFreshPets
;
import
static
es
.
uvigo
.
esei
.
xcs
.
domain
.
entities
.
OwnersDataset
.
newOwnerWithPersistentPets
;
import
static
es
.
uvigo
.
esei
.
xcs
.
domain
.
entities
.
OwnersDataset
.
owners
;
import
static
es
.
uvigo
.
esei
.
xcs
.
http
.
util
.
HasHttpStatus
.
hasHttpStatus
;
import
static
java
.
util
.
Arrays
.
asList
;
import
static
java
.
util
.
Collections
.
emptyList
;
import
static
javax
.
ws
.
rs
.
core
.
Response
.
Status
.
CREATED
;
import
static
javax
.
ws
.
rs
.
core
.
Response
.
Status
.
OK
;
import
static
org
.
easymock
.
EasyMock
.
expect
;
import
static
org
.
easymock
.
EasyMock
.
expectLastCall
;
import
static
org
.
hamcrest
.
CoreMatchers
.
equalTo
;
...
...
@@ -66,7 +69,7 @@ public class OwnerResourceUnitTest extends EasyMockSupport {
final
Response
response
=
resource
.
get
(
owner
.
getLogin
());
assertThat
(
response
.
getStatusInfo
(),
is
(
equalTo
(
Response
.
Status
.
OK
)
));
assertThat
(
response
,
hasHttpStatus
(
OK
));
assertThat
(
response
.
getEntity
(),
is
(
instanceOf
(
Owner
.
class
)));
assertThat
((
Owner
)
response
.
getEntity
(),
is
(
equalsToOwner
(
owner
)));
}
...
...
@@ -101,8 +104,8 @@ public class OwnerResourceUnitTest extends EasyMockSupport {
replayAll
();
final
Response
response
=
resource
.
list
();
assertThat
(
response
.
getStatusInfo
(),
is
(
equalTo
(
Response
.
Status
.
OK
)
));
assertThat
(
response
,
hasHttpStatus
(
OK
));
assertThat
(
response
.
getEntity
(),
is
(
instanceOf
(
List
.
class
)));
assertThat
((
List
<
Owner
>)
response
.
getEntity
(),
containsOwnersInAnyOrder
(
owners
));
}
...
...
@@ -116,8 +119,8 @@ public class OwnerResourceUnitTest extends EasyMockSupport {
replayAll
();
final
Response
response
=
resource
.
list
();
assertThat
(
response
.
getStatusInfo
(),
is
(
equalTo
(
Response
.
Status
.
OK
)
));
assertThat
(
response
,
hasHttpStatus
(
OK
));
assertThat
(
response
.
getEntity
(),
is
(
instanceOf
(
List
.
class
)));
assertThat
((
List
<
Owner
>)
response
.
getEntity
(),
is
(
empty
()));
}
...
...
@@ -142,8 +145,8 @@ public class OwnerResourceUnitTest extends EasyMockSupport {
replayAll
();
final
Response
response
=
resource
.
create
(
newOwner
);
assertThat
(
response
.
getStatusInfo
(),
is
(
equalTo
(
Response
.
Status
.
CREATED
)
));
assertThat
(
response
,
hasHttpStatus
(
CREATED
));
assertThat
(
response
.
getHeaderString
(
"Location"
),
is
(
equalTo
(
mockUri
.
toString
())));
}
...
...
@@ -165,8 +168,8 @@ public class OwnerResourceUnitTest extends EasyMockSupport {
replayAll
();
final
Response
response
=
resource
.
update
(
owner
);
assertThat
(
response
.
getStatusInfo
(),
is
(
equalTo
(
Response
.
Status
.
OK
)
));
assertThat
(
response
,
hasHttpStatus
(
OK
));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
...
...
@@ -185,8 +188,8 @@ public class OwnerResourceUnitTest extends EasyMockSupport {
replayAll
();
final
Response
response
=
resource
.
delete
(
login
);
assertThat
(
response
.
getStatusInfo
(),
is
(
equalTo
(
Response
.
Status
.
OK
)
));
assertThat
(
response
,
hasHttpStatus
(
OK
));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
...
...
tests/src/main/java/es/uvigo/esei/xcs/http/util/HasHttpStatus.java
0 → 100644
View file @
40bf4a1a
package
es
.
uvigo
.
esei
.
xcs
.
http
.
util
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response.StatusType
;
import
org.hamcrest.Description
;
import
org.hamcrest.Factory
;
import
org.hamcrest.TypeSafeMatcher
;
public
class
HasHttpStatus
extends
TypeSafeMatcher
<
Response
>
{
private
StatusType
status
;
public
HasHttpStatus
(
StatusType
status
)
{
this
.
status
=
status
;
}
public
HasHttpStatus
(
int
statusCode
)
{
this
(
Response
.
Status
.
fromStatusCode
(
statusCode
));
}
@Override
public
void
describeTo
(
Description
description
)
{
description
.
appendValue
(
this
.
status
);
}
@Override
protected
boolean
matchesSafely
(
Response
item
)
{
return
this
.
status
.
getStatusCode
()
==
item
.
getStatus
();
}
@Factory
public
static
HasHttpStatus
hasHttpStatus
(
int
statusCode
)
{
return
new
HasHttpStatus
(
statusCode
);
}
@Factory
public
static
HasHttpStatus
hasHttpStatus
(
StatusType
status
)
{
return
new
HasHttpStatus
(
status
);
}
}
Write
Preview
Markdown
is supported
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