Toggle navigation
Toggle navigation
This project
Loading...
Sign in
grogv3
/
grog-cubi
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jean-Francois Leveque
2016-12-05 12:40:01 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3b3a9aa01cc1a9ec024ad7c62e2433155c335ea3
3b3a9aa0
1 parent
ac79f06c
Country (pages et backing beans) et index : réécriture et tests.
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
209 additions
and
38 deletions
src/main/java/org/legrog/web/xyz/AddCountryBean.java → src/main/java/org/legrog/web/xyz/AddCountryView.java
src/main/java/org/legrog/web/xyz/ListCountriesBean.java → src/main/java/org/legrog/web/xyz/ListCountriesView.java
src/main/java/org/legrog/web/xyz/SharedService.java
src/main/java/org/legrog/web/xyz/SharedServiceSpring.java
src/main/java/org/legrog/web/xyz/addCountry.xhtml
src/main/java/org/legrog/web/xyz/listCountries.xhtml
src/main/webapp/index.xhtml
src/test/java/org/legrog/web/xyz/AddCountryViewTest.java
src/test/java/org/legrog/web/xyz/ListCountriesViewTest.java
src/main/java/org/legrog/web/xyz/AddCountry
Bean
.java
→
src/main/java/org/legrog/web/xyz/AddCountry
View
.java
View file @
3b3a9aa
package
org
.
legrog
.
web
.
xyz
;
import
org.legrog.entities.Country
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.enterprise.context.RequestScoped
;
import
javax.inject.Inject
;
import
javax.inject.Named
;
import
java.io.Serializable
;
@Named
@RequestScoped
public
class
AddCountryBean
{
@Inject
public
class
AddCountryView
implements
Serializable
{
transient
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
private
SharedService
sharedService
;
private
String
countryName
;
public
String
getCountryName
()
{
return
countryName
;
public
AddCountryView
()
{
}
public
void
setCountryName
(
String
countryName
)
{
this
.
countryName
=
countryName
;
@Inject
public
AddCountryView
(
SharedService
sharedService
)
{
this
.
sharedService
=
sharedService
;
}
public
String
add
()
{
public
void
add
()
{
Country
country
=
new
Country
();
country
.
setCountryName
(
countryName
);
sharedService
.
addCountry
(
country
);
return
"success"
;
country
=
sharedService
.
addCountry
(
country
);
countryName
=
""
;
}
public
String
getCountryName
()
{
return
countryName
;
}
public
void
setCountryName
(
String
countryName
)
{
this
.
countryName
=
countryName
;
}
}
...
...
src/main/java/org/legrog/web/xyz/ListCountries
Bean
.java
→
src/main/java/org/legrog/web/xyz/ListCountries
View
.java
View file @
3b3a9aa
...
...
@@ -6,22 +6,23 @@ import javax.annotation.PostConstruct;
import
javax.enterprise.context.RequestScoped
;
import
javax.inject.Inject
;
import
javax.inject.Named
;
import
java.io.Serializable
;
import
java.util.List
;
@Named
@RequestScoped
public
class
ListCountries
Bean
{
@Inject
public
class
ListCountries
View
implements
Serializable
{
private
SharedService
sharedService
;
private
List
<
Country
>
countries
;
public
List
<
Country
>
getCountries
()
{
return
countries
;
public
ListCountriesView
()
{
}
public
void
setCountries
(
List
<
Country
>
countries
)
{
this
.
countries
=
countries
;
@Inject
public
ListCountriesView
(
SharedService
sharedService
)
{
this
.
sharedService
=
sharedService
;
}
@PostConstruct
...
...
@@ -29,4 +30,12 @@ public class ListCountriesBean {
countries
=
sharedService
.
getAllCountries
();
}
public
List
<
Country
>
getCountries
()
{
return
countries
;
}
public
void
setCountries
(
List
<
Country
>
countries
)
{
this
.
countries
=
countries
;
}
}
...
...
src/main/java/org/legrog/web/xyz/SharedService.java
View file @
3b3a9aa
...
...
@@ -6,7 +6,7 @@ import java.util.List;
public
interface
SharedService
{
void
addCountry
(
Country
country
);
Country
addCountry
(
Country
country
);
List
<
Country
>
getAllCountries
();
...
...
src/main/java/org/legrog/web/xyz/SharedServiceSpring.java
View file @
3b3a9aa
...
...
@@ -30,8 +30,9 @@ public class SharedServiceSpring implements SharedService {
private
List
<
DisplayNameMask
>
allDisplayNameMasks
;
public
void
addCountry
(
Country
country
)
{
public
Country
addCountry
(
Country
country
)
{
countryRepository
.
save
(
country
);
return
country
;
}
public
List
<
Country
>
getAllCountries
()
{
...
...
src/main/java/org/legrog/web/xyz/addCountry.xhtml
View file @
3b3a9aa
...
...
@@ -3,20 +3,40 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:h=
"http://xmlns.jcp.org/jsf/html"
xmlns:ui=
"http://xmlns.jcp.org/jsf/facelets"
xmlns:f=
"http://xmlns.jcp.org/jsf/core"
>
xmlns:jsf=
"http://xmlns.jcp.org/jsf"
>
<body>
<h:form>
<h:commandLink
action=
"home"
>
<h:outputText
value=
"Menu principal"
/>
</h:commandLink>
<ul>
<li>
<a
jsf:outcome=
"/index"
>
Menu principal
</a>
</li>
<li>
Éditeurs
<ul>
<li>
<a
jsf:outcome=
"/publisher/listPublisherVersions"
>
Liste des versions des éditeurs
</a>
</li>
<li>
<a
jsf:outcome=
"/publisher/listPublisherActions"
>
Liste des actions des éditeurs
</a>
</li>
<li>
<a
jsf:outcome=
"/publisher/publisherVersion"
>
Ajouter un éditeur
</a>
</li>
</ul>
</li>
<li>
Pays
<ul>
<li>
<a
jsf:outcome=
"listCountries"
>
Liste des pays
</a>
</li>
</ul>
</li>
</ul>
<form
action=
""
jsf:id=
"country"
>
<h:panelGrid
columns=
"2"
>
<
h:outputText
value=
'Nom du pays'
/
>
<
h:inputText
value=
'#{addCountryBean
.countryName}'
/>
<h:outputText
value=
'Add'
/>
<
h:commandButton
action=
"#{addCountryBean.add}"
value=
"Add"
/
>
<
label
for=
"name"
>
Nom du pays
</label
>
<
input
type=
"text"
id=
"name"
jsf:value=
'#{addCountryView
.countryName}'
/>
<
button
jsf:action=
"#{addCountryView.add}"
>
Ajouter
</button
>
</h:panelGrid>
</
h:
form>
</form>
</body>
</html>
...
...
src/main/java/org/legrog/web/xyz/listCountries.xhtml
View file @
3b3a9aa
...
...
@@ -2,17 +2,37 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:h=
"http://xmlns.jcp.org/jsf/html"
xmlns:ui=
"http://xmlns.jcp.org/jsf/facelets"
xmlns:
f=
"http://xmlns.jcp.org/jsf/core
"
>
xmlns:
jsf=
"http://xmlns.jcp.org/jsf
"
>
<body>
<h:form>
<h:commandLink
action=
"home"
>
<h:outputText
value=
"Menu principal"
/>
</h:commandLink>
</h:form>
<ul>
<ui:repeat
value=
"#{listCountriesBean.countries}"
var=
"country"
>
<li>
<a
jsf:outcome=
"/index"
>
Menu principal
</a>
</li>
<li>
Éditeurs
<ul>
<li>
<a
jsf:outcome=
"/publisher/listPublisherVersions"
>
Liste des versions des éditeurs
</a>
</li>
<li>
<a
jsf:outcome=
"/publisher/listPublisherActions"
>
Liste des actions des éditeurs
</a>
</li>
<li>
<a
jsf:outcome=
"/publisher/publisherVersion"
>
Ajouter un éditeur
</a>
</li>
</ul>
</li>
<li>
Pays
<ul>
<li>
<a
jsf:outcome=
"addCountry"
>
Ajouter un pays
</a>
</li>
</ul>
</li>
</ul>
<ul>
<ui:repeat
value=
"#{listCountriesView.countries}"
var=
"country"
>
<li>
#{country.countryName}
</li>
</ui:repeat>
</ul>
...
...
src/main/webapp/index.xhtml
View file @
3b3a9aa
...
...
@@ -5,6 +5,8 @@
xmlns:jsf=
"http://xmlns.jcp.org/jsf"
>
<body>
<ul>
<li>
Éditeurs
<ul>
<li>
<a
jsf:outcome=
"publisher/listPublisherVersions"
>
Liste des versions des éditeurs
</a>
</li>
...
...
@@ -14,6 +16,18 @@
<li>
<a
jsf:outcome=
"publisher/publisherVersion"
>
Ajouter un éditeur
</a>
</li>
</ul>
</li>
<li>
Pays
<ul>
<li>
<a
jsf:outcome=
"xyz/listCountries"
>
Liste des pays
</a>
</li>
<li>
<a
jsf:outcome=
"xyz/addCountry"
>
Ajouter un pays
</a>
</li>
</ul>
</li>
</ul>
</body>
</html>
\ No newline at end of file
...
...
src/test/java/org/legrog/web/xyz/AddCountryViewTest.java
0 → 100644
View file @
3b3a9aa
package
org
.
legrog
.
web
.
xyz
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.DisplayName
;
import
org.junit.jupiter.api.Nested
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.junit.platform.runner.JUnitPlatform
;
import
org.junit.runner.RunWith
;
import
org.legrog.entities.Country
;
import
org.legrog.test.MockitoExtension
;
import
org.mockito.*
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Classe testant AddCountryView
*/
@RunWith
(
JUnitPlatform
.
class
)
@ExtendWith
(
MockitoExtension
.
class
)
@DisplayName
(
"Adds a country to the list"
)
public
class
AddCountryViewTest
{
@Nested
@DisplayName
(
"add method"
)
class
addTests
{
private
AddCountryView
addCountryView
;
@Captor
ArgumentCaptor
<
Country
>
countryArgumentCaptor
;
@BeforeEach
public
void
setup
(
@Mock
SharedService
sharedServiceMock
)
{
addCountryView
=
new
AddCountryView
(
sharedServiceMock
);
addCountryView
.
setCountryName
(
"Zanzibar"
);
addCountryView
.
add
();
}
@Test
@DisplayName
(
"uses the SharedService add with right argument"
)
public
void
testSharedServiceAdd
(
@Mock
SharedService
sharedServiceMock
)
{
Mockito
.
verify
(
sharedServiceMock
).
addCountry
(
countryArgumentCaptor
.
capture
());
Country
country
=
countryArgumentCaptor
.
getValue
();
assertThat
(
country
.
getCountryName
()).
isEqualTo
(
"Zanzibar"
);
}
}
}
src/test/java/org/legrog/web/xyz/ListCountriesViewTest.java
0 → 100644
View file @
3b3a9aa
package
org
.
legrog
.
web
.
xyz
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.DisplayName
;
import
org.junit.jupiter.api.Nested
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.junit.platform.runner.JUnitPlatform
;
import
org.junit.runner.RunWith
;
import
org.legrog.entities.Country
;
import
org.legrog.test.MockitoExtension
;
import
org.mockito.*
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
* Classe testant ListCountriesView
*/
@RunWith
(
JUnitPlatform
.
class
)
@ExtendWith
(
MockitoExtension
.
class
)
@DisplayName
(
"Shows the country list"
)
public
class
ListCountriesViewTest
{
private
ListCountriesView
listCountriesView
;
private
List
<
Country
>
countryList
;
@BeforeEach
public
void
setup
(
@Mock
SharedService
sharedService
)
throws
Exception
{
countryList
=
new
ArrayList
<
Country
>();
listCountriesView
=
new
ListCountriesView
(
sharedService
);
when
(
sharedService
.
getAllCountries
()).
thenReturn
(
countryList
);
}
@Nested
@DisplayName
(
"init method"
)
class
initTests
{
@Test
@DisplayName
(
"should get all countries"
)
public
void
getAllCountriesTest
()
{
listCountriesView
.
init
();
assertThat
(
listCountriesView
.
getCountries
()).
isEqualTo
(
countryList
);
}
}
}
\ No newline at end of file
Please
register
or
login
to post a comment