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
Manuel Barciela Martín
DAAExample
Commits
aadbd925
Commit
aadbd925
authored
Mar 15, 2018
by
Manuel Barciela Martín
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for entitie pet
parent
f004b2f1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
9 deletions
+99
-9
mysql.sql
db/mysql.sql
+8
-0
Pet.java
src/main/java/es/uvigo/esei/daa/entities/Pet.java
+0
-4
PetResource.java
src/main/java/es/uvigo/esei/daa/rest/PetResource.java
+5
-5
PetUnitTest.java
src/test/java/es/uvigo/esei/daa/entities/PetUnitTest.java
+86
-0
No files found.
db/mysql.sql
View file @
aadbd925
...
...
@@ -13,4 +13,12 @@ CREATE TABLE `daaexample`.`users` (
PRIMARY
KEY
(
`login`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
CREATE
TABLE
`daaexample`
.
`pets`
(
`idPet`
int
NOT
NULL
AUTO_INCREMENT
,
`name`
varchar
(
50
)
NOT
NULL
,
`idOwner`
int
NOT
NULL
,
PRIMARY
KEY
(
`idPet`
),
FOREING
KEY
(
`idOwner`
)
REFERENCES
people
(
id
),
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
GRANT
ALL
ON
`daaexample`
.
*
TO
'daa'
@
'localhost'
IDENTIFIED
BY
'daa'
;
src/main/java/es/uvigo/esei/daa/entities/Pet.java
View file @
aadbd925
...
...
@@ -28,10 +28,6 @@ public class Pet {
return
idOwner
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
...
...
src/main/java/es/uvigo/esei/daa/rest/PetResource.java
View file @
aadbd925
...
...
@@ -10,7 +10,7 @@ import javax.ws.rs.core.MediaType;
import
javax.ws.rs.core.Response
;
import
es.uvigo.esei.daa.dao.DAOException
;
import
es.uvigo.esei.daa.entities.Pe
rson
;
import
es.uvigo.esei.daa.entities.Pe
t
;
@Path
(
"/pets"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
...
...
@@ -20,17 +20,17 @@ public class PetResource {
@Path
(
"/{idPet}"
)
public
Response
get
(
@PathParam
(
"idPet"
)
int
idPet
)
{
try
{
final
Pe
rson
person
=
this
.
dao
.
get
(
id
);
final
Pe
t
pet
=
this
.
dao
.
get
(
id
);
return
Response
.
ok
(
pe
rson
).
build
();
return
Response
.
ok
(
pe
t
).
build
();
}
catch
(
IllegalArgumentException
iae
)
{
LOG
.
log
(
Level
.
FINE
,
"Invalid pe
rson
id in get method"
,
iae
);
LOG
.
log
(
Level
.
FINE
,
"Invalid pe
t
id in get method"
,
iae
);
return
Response
.
status
(
Response
.
Status
.
BAD_REQUEST
)
.
entity
(
iae
.
getMessage
())
.
build
();
}
catch
(
DAOException
e
)
{
LOG
.
log
(
Level
.
SEVERE
,
"Error getting a pe
rson
"
,
e
);
LOG
.
log
(
Level
.
SEVERE
,
"Error getting a pe
t
"
,
e
);
return
Response
.
serverError
()
.
entity
(
e
.
getMessage
())
...
...
src/test/java/es/uvigo/esei/daa/entities/PetUnitTest.java
0 → 100644
View file @
aadbd925
package
es
.
uvigo
.
esei
.
daa
.
entities
;
import
static
org
.
hamcrest
.
CoreMatchers
.
equalTo
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
org.junit.Test
;
import
nl.jqno.equalsverifier.EqualsVerifier
;
import
nl.jqno.equalsverifier.Warning
;
public
class
PetUnitTest
{
@Test
public
void
testIntStringString
()
{
final
int
id
=
1
;
final
String
name
=
"cocodrilo"
;
final
int
idOwner
=
4
;
final
Pet
pet
=
new
Pet
(
id
,
name
,
idOwner
);
assertThat
(
pet
.
getId
(),
equalTo
(
id
));
assertThat
(
pet
.
getName
(),
equalTo
(
name
));
assertThat
(
pet
.
getIdOwner
(),
equalTo
(
idOwner
));
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testPetIntStringIntNullName
()
{
new
Pet
(
1
,
null
,
3
);
}
@Test
public
void
testSetName
()
{
final
int
id
=
1
;
final
int
idOwner
=
5
;
final
Pet
pet
=
new
Pet
(
id
,
"gato"
,
idOwner
);
pet
.
setName
(
"manoplas"
);
assertThat
(
pet
.
getId
(),
is
(
equalTo
(
id
)));
assertThat
(
pet
.
getName
(),
is
(
equalTo
(
"manoplas"
)));
assertThat
(
pet
.
getIdOwner
(),
is
(
equalTo
(
idOwner
)));
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testSetNullName
()
{
final
Pet
person
=
new
Pet
(
1
,
"Coco"
,
3
);
person
.
setName
(
null
);
}
@Test
public
void
testnewOwner
()
{
final
int
id
=
1
;
final
String
name
=
"manoplas"
;
final
Pet
pet
=
new
Pet
(
id
,
name
,
2
);
pet
.
setOwner
(
4
);
assertThat
(
pet
.
getId
(),
is
(
equalTo
(
id
)));
assertThat
(
pet
.
getName
(),
is
(
equalTo
(
name
)));
assertThat
(
pet
.
getIdOwner
(),
is
(
equalTo
(
4
)));
}
@Test
public
void
testEqualsObject
()
{
final
Pet
petA
=
new
Pet
(
1
,
"Name A"
,
2
);
final
Pet
petB
=
new
Pet
(
1
,
"Name B"
,
3
);
assertTrue
(
petA
.
equals
(
petB
));
}
@Test
public
void
testEqualsHashcode
()
{
EqualsVerifier
.
forClass
(
Pet
.
class
)
.
withIgnoredFields
(
"name"
,
"idOwner"
)
.
suppress
(
Warning
.
STRICT_INHERITANCE
)
.
suppress
(
Warning
.
NONFINAL_FIELDS
)
.
verify
();
}
}
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