Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Jan Smejkal
Pa165 Secret Archive
Commits
707eb574
Commit
707eb574
authored
Mar 27, 2022
by
Juraj Fiala
Browse files
feat: Add Mission tests
parent
588bcf72
Pipeline
#123079
waiting for manual action with stage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/cz/fi/muni/pa165/seminar4/group7/secretservice/entity/Mission.java
View file @
707eb574
...
...
@@ -3,6 +3,7 @@ package cz.fi.muni.pa165.seminar4.group7.secretservice.entity;
import
com.sun.istack.NotNull
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
javax.persistence.*
;
import
java.sql.Date
;
...
...
@@ -41,7 +42,7 @@ public class Mission {
@OneToMany
(
mappedBy
=
"mission"
)
private
List
<
Resource
>
resources
;
@ManyToOne
@ManyToOne
(
cascade
=
CascadeType
.
ALL
)
@JoinColumn
(
name
=
"country_id"
)
@Getter
@Setter
...
...
src/test/java/cz/fi/muni/pa165/seminar4/group7/secretservice/MissionTest.java
0 → 100644
View file @
707eb574
package
cz.fi.muni.pa165.seminar4.group7.secretservice
;
import
cz.fi.muni.pa165.seminar4.group7.secretservice.dao.MissionDao
;
import
cz.fi.muni.pa165.seminar4.group7.secretservice.dao.ResourceDao
;
import
cz.fi.muni.pa165.seminar4.group7.secretservice.entity.Country
;
import
cz.fi.muni.pa165.seminar4.group7.secretservice.entity.Mission
;
import
cz.fi.muni.pa165.seminar4.group7.secretservice.entity.Resource
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
javax.transaction.Transactional
;
import
java.sql.Date
;
import
java.util.Calendar
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@SpringBootTest
class
MissionTest
{
@Autowired
private
MissionDao
missionDao
;
@BeforeEach
private
void
reset
()
{
missionDao
.
deleteAll
();
}
Mission
createMission
()
{
var
country
=
new
Country
().
setCode
(
"US"
);
country
.
setCommunications
(
"Everything."
)
.
setDemographics
(
"Americans."
)
.
setEconomy
(
"Big."
)
.
setGovernment
(
"Blue or red."
)
.
setMilitary
(
"Even bigger."
)
.
setName
(
"America, hell yeah!"
)
.
setGeography
(
"Smaller than widely believed."
);
var
mission
=
new
Mission
();
var
today
=
new
Date
(
Calendar
.
getInstance
().
getTime
().
getTime
());
mission
.
setCountry
(
country
);
mission
.
setDuration
(
10
);
mission
.
setObjective
(
"Retrieve bomb plans. Failure is not an option."
);
mission
.
setStart
(
today
);
return
mission
;
}
@Test
void
testCreate
()
{
var
mission
=
createMission
();
missionDao
.
save
(
mission
);
assertThat
(
missionDao
.
findAll
()).
hasSize
(
1
);
}
@Test
@Transactional
void
testFindAll
()
{
var
mission
=
createMission
();
missionDao
.
save
(
mission
);
assertThat
(
missionDao
.
findAll
().
iterator
().
next
()).
isEqualTo
(
mission
);
}
@Test
void
testFindById
()
{
var
mission
=
createMission
();
missionDao
.
save
(
mission
);
var
mission2
=
missionDao
.
findById
(
mission
.
getId
());
assertThat
(
mission2
).
isPresent
();
assertThat
(
mission2
.
get
().
getId
()).
isEqualTo
(
mission
.
getId
());
}
@Test
void
testSave
()
{
var
mission
=
createMission
();
missionDao
.
save
(
mission
);
mission
.
setObjective
(
"New objective, get out of there ASAP."
);
missionDao
.
save
(
mission
);
var
savedMission
=
missionDao
.
findById
(
mission
.
getId
());
assertThat
(
savedMission
).
isNotEmpty
();
assertThat
(
savedMission
.
get
().
getObjective
()).
isEqualTo
(
mission
.
getObjective
());
}
@Test
void
testFindEmpty
()
{
assertThat
(
missionDao
.
findById
(
1L
)).
isEmpty
();
}
@Test
void
testCreateDuplicate
()
{
var
mission
=
createMission
();
missionDao
.
save
(
mission
);
var
mission2
=
missionDao
.
findById
(
mission
.
getId
());
assertThat
(
mission2
).
isPresent
();
missionDao
.
save
(
mission2
.
get
());
assertThat
(
missionDao
.
findAll
()).
hasSize
(
1
);
}
@Test
void
testDelete
()
{
var
mission
=
createMission
();
missionDao
.
save
(
mission
);
missionDao
.
delete
(
mission
);
assertThat
(
missionDao
.
findAll
()).
hasSize
(
0
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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