Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
DAAExample
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
Santiago Gómez Vilar
DAAExample
Commits
2e5babc8
Commit
2e5babc8
authored
Mar 08, 2019
by
Santi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test pets
parent
f0ea308b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
194 additions
and
42 deletions
+194
-42
main.html
src/main/webapp/main.html
+45
-38
PetsResourceTest.java
src/test/java/es/uvigo/esei/daa/rest/PetsResourceTest.java
+3
-2
PetsResourceUnitTest.java
...est/java/es/uvigo/esei/daa/rest/PetsResourceUnitTest.java
+146
-2
No files found.
src/main/webapp/main.html
View file @
2e5babc8
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"UTF-8"
>
<meta
charset=
"UTF-8"
>
<title>
DAA Example
</title>
<title>
DAA Example
</title>
<link
rel=
"stylesheet"
<link
rel=
"stylesheet"
href=
"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
>
</head>
<body>
<header>
<header>
<div
class=
"navbar navbar-dark bg-dark box-shadow"
>
<div
class=
"container d-flex justify-content-between"
>
<a
href=
"#"
class=
"navbar-brand d-flex align-items-center"
>
...
...
@@ -18,26 +18,33 @@
<button
id=
"logout"
class=
"btn btn-dark"
>
Cerrar sesión
</button>
</div>
</div>
</header>
</header>
<div
class=
"container"
>
<div
class=
"container"
>
<div
id=
"people-container"
>
<h1
class=
"display-5 mt-3 mb-3"
>
Personas
</h1>
</div>
<div
id=
"pet-container"
>
<h1
class=
"display-5 mt-3 mb-3"
>
Mascotas
</h1>
</div>
</div>
<script
type=
"text/javascript"
<script
type=
"text/javascript"
src=
"http://code.jquery.com/jquery-2.2.4.min.js"
></script>
<script
type=
"text/javascript"
src=
"js/dao/people.js"
></script>
<script
type=
"text/javascript"
src=
"js/view/people.js"
></script>
<script
type=
"text/javascript"
src=
"js/login.js"
></script>
<script
type=
"text/javascript"
>
<script
type=
"text/javascript"
src=
"js/dao/people.js"
></script>
<script
type=
"text/javascript"
src=
"js/view/people.js"
></script>
<script
type=
"text/javascript"
src=
"js/dao/pets.js"
></script>
<script
type=
"text/javascript"
src=
"js/view/pets.js"
></script>
<script
type=
"text/javascript"
src=
"js/login.js"
></script>
<script
type=
"text/javascript"
>
$
(
document
).
ready
(
function
()
{
$
(
'#logout'
).
click
(
function
(
event
)
{
function
()
{
$
(
'#logout'
).
click
(
function
(
event
)
{
event
.
preventDefault
();
doLogout
();
});
document
.
getElementById
(
"pet-container"
).
style
.
display
=
"none"
;
document
.
getElementById
(
'people-container'
).
style
.
display
=
'block'
;
var
view
=
new
PeopleView
(
new
PeopleDAO
(),
'people-container'
,
'people-container'
...
...
@@ -45,6 +52,6 @@
view
.
init
();
});
</script>
</script>
</body>
</html>
\ No newline at end of file
src/test/java/es/uvigo/esei/daa/rest/PetsResourceTest.java
View file @
2e5babc8
...
...
@@ -69,14 +69,15 @@ public class PetsResourceTest extends JerseyTest {
config
.
property
(
"com.sun.jersey.api.json.POJOMappingFeature"
,
Boolean
.
TRUE
);
}
//
@Test
@Test
public
void
testList
()
throws
IOException
{
final
Response
response
=
target
(
"pets"
).
request
()
.
header
(
"Authorization"
,
"Basic "
+
userToken
(
adminLogin
()))
.
get
();
assertThat
(
response
,
hasOkStatus
());
final
List
<
Pet
>
pets
=
response
.
readEntity
(
new
GenericType
<
List
<
Pet
>>(){});
final
List
<
Pet
>
pets
=
response
.
readEntity
(
new
GenericType
<
List
<
Pet
>>()
{
});
assertThat
(
pets
,
containsPetsInAnyOrder
(
pets
()));
}
...
...
src/test/java/es/uvigo/esei/daa/rest/PetsResourceUnitTest.java
View file @
2e5babc8
package
es
.
uvigo
.
esei
.
daa
.
rest
;
import
es.uvigo.esei.daa.dao.DAOException
;
import
es.uvigo.esei.daa.dao.PetsDAO
;
import
es.uvigo.esei.daa.entities.Pet
;
import
org.hamcrest.CoreMatchers
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
javax.ws.rs.core.Response
;
import
java.util.List
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PetsDataset
.
existentPet
;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
HasHttpStatus
.
hasOkStatus
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
newName
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PetsDataset
.*;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
HasHttpStatus
.*;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
IsEqualToPet
.
containsPetsInAnyOrder
;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
IsEqualToPet
.
equalsToPet
;
import
static
java
.
util
.
Arrays
.
asList
;
import
static
org
.
easymock
.
EasyMock
.*;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
PetsResourceUnitTest
{
...
...
@@ -51,5 +58,142 @@ public class PetsResourceUnitTest {
assertThat
((
Pet
)
response
.
getEntity
(),
is
(
equalsToPet
(
pet
)));
}
@Test
@SuppressWarnings
(
"unchecked"
)
public
void
testList
()
throws
Exception
{
final
List
<
Pet
>
people
=
asList
(
pets
());
expect
(
daoMock
.
list
()).
andReturn
(
people
);
replay
(
daoMock
);
final
Response
response
=
resource
.
list
();
assertThat
(
response
,
hasOkStatus
());
assertThat
((
List
<
Pet
>)
response
.
getEntity
(),
containsPetsInAnyOrder
(
pets
()));
}
@Test
public
void
testListDAOException
()
throws
Exception
{
expect
(
daoMock
.
list
()).
andThrow
(
new
DAOException
());
replay
(
daoMock
);
final
Response
response
=
resource
.
list
();
assertThat
(
response
,
hasInternalServerErrorStatus
());
}
@Test
public
void
testGetDAOException
()
throws
Exception
{
expect
(
daoMock
.
get
(
anyInt
())).
andThrow
(
new
DAOException
());
replay
(
daoMock
);
final
Response
response
=
resource
.
get
(
existentId
());
assertThat
(
response
,
hasInternalServerErrorStatus
());
}
@Test
public
void
testGetIllegalArgumentException
()
throws
Exception
{
expect
(
daoMock
.
get
(
anyInt
())).
andThrow
(
new
IllegalArgumentException
());
replay
(
daoMock
);
final
Response
response
=
resource
.
get
(
existentId
());
assertThat
(
response
,
hasBadRequestStatus
());
}
@Test
public
void
testDelete
()
throws
Exception
{
daoMock
.
delete
(
anyInt
());
replay
(
daoMock
);
final
Response
response
=
resource
.
delete
(
1
);
assertThat
(
response
,
hasOkStatus
());
}
@Test
public
void
testDeleteDAOException
()
throws
Exception
{
daoMock
.
delete
(
anyInt
());
expectLastCall
().
andThrow
(
new
DAOException
());
replay
(
daoMock
);
final
Response
response
=
resource
.
delete
(
1
);
assertThat
(
response
,
hasInternalServerErrorStatus
());
}
@Test
public
void
testDeleteIllegalArgumentException
()
throws
Exception
{
daoMock
.
delete
(
anyInt
());
expectLastCall
().
andThrow
(
new
IllegalArgumentException
());
replay
(
daoMock
);
final
Response
response
=
resource
.
delete
(
1
);
assertThat
(
response
,
hasBadRequestStatus
());
}
// @Test
public
void
testModify
()
throws
Exception
{
final
Pet
pet
=
existentPet
();
pet
.
setName
(
newName
());
pet
.
setOwner
(
newOwner
());
daoMock
.
modify
(
pet
);
replay
(
daoMock
);
final
Response
response
=
resource
.
modify
(
pet
.
getId
(),
pet
.
getName
(),
pet
.
getOwner
());
assertThat
(
response
,
hasOkStatus
());
assertEquals
(
pet
,
response
.
getEntity
());
}
@Test
public
void
testAdd
()
throws
Exception
{
expect
(
daoMock
.
add
(
newName
(),
newOwner
()))
.
andReturn
(
newPet
());
replay
(
daoMock
);
final
Response
response
=
resource
.
add
(
newName
(),
newOwner
());
assertThat
(
response
,
hasOkStatus
());
assertThat
((
Pet
)
response
.
getEntity
(),
CoreMatchers
.
is
(
equalsToPet
(
newPet
())));
}
@Test
public
void
testAddDAOException
()
throws
Exception
{
expect
(
daoMock
.
add
(
anyString
(),
anyInt
()))
.
andThrow
(
new
DAOException
());
replay
(
daoMock
);
final
Response
response
=
resource
.
add
(
newName
(),
newOwner
());
assertThat
(
response
,
hasInternalServerErrorStatus
());
}
@Test
public
void
testAddIllegalArgumentException
()
throws
Exception
{
expect
(
daoMock
.
add
(
anyString
(),
anyInt
()))
.
andThrow
(
new
IllegalArgumentException
());
replay
(
daoMock
);
final
Response
response
=
resource
.
add
(
newName
(),
newOwner
());
assertThat
(
response
,
hasBadRequestStatus
());
}
}
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