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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Miguel Reboiro Jato
daaexample
Commits
f2727523
Commit
f2727523
authored
Feb 10, 2020
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removes non-principal tests
Tests that are not fundamental have been removed.
parent
6341d60f
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
6 additions
and
1415 deletions
+6
-1415
README.md
README.md
+3
-13
pom.xml
pom.xml
+0
-365
package-lock.json
src/main/angular/package-lock.json
+1
-1
package.json
src/main/angular/package.json
+1
-1
PeopleDAOTest.java
src/test/java/es/uvigo/esei/daa/dao/PeopleDAOTest.java
+0
-136
PeopleDAOUnitTest.java
src/test/java/es/uvigo/esei/daa/dao/PeopleDAOUnitTest.java
+0
-259
PeopleResourceUnitTest.java
...t/java/es/uvigo/esei/daa/rest/PeopleResourceUnitTest.java
+0
-242
AcceptanceTestSuite.java
...st/java/es/uvigo/esei/daa/suites/AcceptanceTestSuite.java
+0
-15
IntegrationTestSuite.java
...t/java/es/uvigo/esei/daa/suites/IntegrationTestSuite.java
+0
-2
UnitTestSuite.java
src/test/java/es/uvigo/esei/daa/suites/UnitTestSuite.java
+1
-5
PeopleWebTest.java
src/test/java/es/uvigo/esei/daa/web/PeopleWebTest.java
+0
-134
MainPage.java
src/test/java/es/uvigo/esei/daa/web/pages/MainPage.java
+0
-242
No files found.
README.md
View file @
f2727523
...
...
@@ -60,6 +60,9 @@ La aplicación se servirá en local:
Para detener la ejecución podemos utilizar
`Ctrl+C`
.
*Nota*
: si accedes a la URL del backend también verás la aplicación de frontend,
pero no se redesplegará automáticamente con los cambios.
### Construcción con tests de unidad e integración
En esta construcción se ejecutarán todos los tests relacionados con el backend:
...
...
@@ -73,16 +76,3 @@ memoria.
El comando para lanzar esta construcción es:
`mvn install`
### Construcción con tests de unidad, integración y aceptación
Esta construcción es similar a la previa, añadiendo las
**
pruebas de
aceptación
**
, que comprueban que las fucionalidades de la aplicación están
correctamente implementadas.
En estas pruebas se descarga y arranca el un servidor Tomcat 8 en el que se
despliega la aplicación configurada para utilizar una base de datos HSQL. Las
pruebas se hacen sobre la interfaz web con Selenium, que iniciará un Firefox
local de forma automática.
`mvn -Pacceptance-tests-cargo install`
pom.xml
View file @
f2727523
...
...
@@ -45,7 +45,6 @@
<spring-test-dbunit.version>
1.3.0
</spring-test-dbunit.version>
<hsqldb.version>
2.3.3
</hsqldb.version>
<mysql.version>
5.1.45
</mysql.version>
<geckodriver.version>
v0.26.0
</geckodriver.version>
<equalsverifier.version>
2.4.2
</equalsverifier.version>
<!-- Plugins -->
...
...
@@ -419,185 +418,6 @@
</build>
<profiles>
<profile>
<id>
acceptance-tests-cargo
</id>
<activation>
<activeByDefault>
false
</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-failsafe-plugin
</artifactId>
<version>
${maven-failsafe-plugin.version}
</version>
<configuration>
<includes>
<includes>
**/IntegrationTestSuite.java
</includes>
<includes>
**/AcceptanceTestSuite.java
</includes>
</includes>
<systemProperties>
<webdriver.gecko.driver>
${geckodriver.uncompressed.path}
</webdriver.gecko.driver>
</systemProperties>
</configuration>
<executions>
<execution>
<id>
default-integration-tests
</id>
<goals>
<goal>
integration-test
</goal>
<goal>
verify
</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.jacoco
</groupId>
<artifactId>
jacoco-maven-plugin
</artifactId>
<version>
${jacoco-maven-plugin.version}
</version>
<configuration>
<port>
${jacoco.port}
</port>
</configuration>
<executions>
<execution>
<id>
jacoco-agent
</id>
<phase>
pre-integration-test
</phase>
<goals>
<goal>
prepare-agent
</goal>
</goals>
<configuration>
<propertyName>
jacoco.agent.itArgLine
</propertyName>
</configuration>
</execution>
<execution>
<id>
jacoco-report
</id>
<phase>
post-integration-test
</phase>
<goals>
<goal>
dump
</goal>
<goal>
report
</goal>
</goals>
<configuration>
<outputDirectory>
${project.reporting.outputDirectory}/jacoco-it
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- current version -->
<groupId>
fr.avianey.mojo
</groupId>
<artifactId>
hsqldb-maven-plugin
</artifactId>
<version>
${hsqldb-maven-plugin.version}
</version>
<!-- default value for in memory jdbc:hsqldb:hsql://localhost/xdb override
only values you want to change -->
<configuration>
<driver>
org.hsqldb.jdbc.JDBCDriver
</driver>
<path>
mem:daatestdb
</path>
<address>
localhost
</address>
<name>
daatestdb
</name>
<username>
sa
</username>
<password
/>
</configuration>
<!-- call start and stop -->
<executions>
<execution>
<id>
start-hsqldb
</id>
<phase>
pre-integration-test
</phase>
<goals>
<goal>
start
</goal>
</goals>
</execution>
<execution>
<id>
stop-hsqldb
</id>
<phase>
post-integration-test
</phase>
<goals>
<goal>
stop
</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.codehaus.cargo
</groupId>
<artifactId>
cargo-maven2-plugin
</artifactId>
<version>
${cargo-maven2-plugin.version}
</version>
<configuration>
<container>
<containerId>
tomcat8x
</containerId>
<zipUrlInstaller>
<url>
https://repo1.maven.org/maven2/org/apache/tomcat/tomcat/${tomcat.version}/tomcat-${tomcat.version}.zip
</url>
<downloadDir>
${project.servers.directory}/downloads
</downloadDir>
<extractDir>
${project.servers.directory}/extracts
</extractDir>
</zipUrlInstaller>
<dependencies>
<dependency>
<groupId>
org.hsqldb
</groupId>
<artifactId>
hsqldb
</artifactId>
</dependency>
</dependencies>
</container>
<configuration>
<home>
${project.build.directory}/catalina-base
</home>
<files>
<copy>
<file>
tomcat/server.hsqldb.xml
</file>
<tofile>
conf/server.xml
</tofile>
</copy>
</files>
<properties>
<cargo.jvmargs>
${jacoco.agent.itArgLine},output=tcpserver,port=${jacoco.port}
-Drunmode=TEST
</cargo.jvmargs>
<cargo.servlet.port>
9080
</cargo.servlet.port>
<cargo.datasource.datasource.h2>
cargo.datasource.jndi=jdbc/daaexample|
cargo.datasource.driver=org.hsqldb.jdbc.JDBCDriver|
cargo.datasource.url=jdbc:hsqldb:hsql://localhost/daatestdb|
cargo.datasource.username=sa|
cargo.datasource.password=|
cargo.datasource.maxActive=8|
cargo.datasource.maxIdle=4|
cargo.datasource.maxWait=10000
</cargo.datasource.datasource.h2>
</properties>
</configuration>
</configuration>
<executions>
<execution>
<id>
start-tomcat
</id>
<phase>
pre-integration-test
</phase>
<goals>
<goal>
start
</goal>
</goals>
<configuration>
<skip>
${cargo.tomcat.start.skip}
</skip>
</configuration>
</execution>
<execution>
<id>
run-tomcat
</id>
<phase>
pre-integration-test
</phase>
<goals>
<goal>
run
</goal>
</goals>
<configuration>
<skip>
${cargo.tomcat.run.skip}
</skip>
</configuration>
</execution>
<execution>
<id>
stop-tomcat
</id>
<phase>
post-integration-test
</phase>
<goals>
<goal>
stop
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>
run
</id>
<activation>
...
...
@@ -788,191 +608,6 @@
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>
geckodriver-download-unix
</id>
<activation>
<os>
<family>
unix
</family>
</os>
</activation>
<properties>
<geckodriver.url>
https://github.com/mozilla/geckodriver/releases/download/${geckodriver.version}/geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz
</geckodriver.url>
<geckodriver.basepath>
${settings.localRepository}${file.separator}geckodriver${file.separator}${os.name}${file.separator}${os.arch}${file.separator}${project.build.directory}${file.separator}
</geckodriver.basepath>
<geckodriver.compressed.path>
${geckodriver.basepath}${file.separator}geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz
</geckodriver.compressed.path>
<geckodriver.uncompressed.path>
${geckodriver.basepath}${file.separator}geckodriver
</geckodriver.uncompressed.path>
</properties>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-antrun-plugin
</artifactId>
<version>
${maven-antrun-plugin.version}
</version>
<executions>
<execution>
<id>
download-geckodriver
</id>
<phase>
process-test-resources
</phase>
<configuration>
<target>
<mkdir
dir=
"${geckodriver.basepath}"
/>
<get
src=
"${geckodriver.url}"
dest=
"${geckodriver.compressed.path}"
skipexisting=
"true"
/>
<untar
src=
"${geckodriver.compressed.path}"
dest=
"${geckodriver.basepath}"
compression=
"gzip"
/>
<chmod
file=
"${geckodriver.uncompressed.path}"
perm=
"a+x"
/>
</target>
</configuration>
<goals>
<goal>
run
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>
geckodriver-download-windows
</id>
<activation>
<os>
<family>
windows
</family>
</os>
</activation>
<properties>
<geckodriver.url>
https://github.com/mozilla/geckodriver/releases/download/${geckodriver.version}/geckodriver-${geckodriver.version}-${geckodriver.suffix}.zip
</geckodriver.url>
<geckodriver.basepath>
${settings.localRepository}${file.separator}geckodriver${file.separator}${os.name}${file.separator}${os.arch}
</geckodriver.basepath>
<geckodriver.compressed.path>
${geckodriver.basepath}${file.separator}geckodriver-${geckodriver.version}-${geckodriver.suffix}.zip
</geckodriver.compressed.path>
<geckodriver.uncompressed.path>
${geckodriver.basepath}${file.separator}geckodriver.exe
</geckodriver.uncompressed.path>
</properties>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-antrun-plugin
</artifactId>
<version>
${maven-antrun-plugin.version}
</version>
<executions>
<execution>
<id>
download-geckodriver
</id>
<phase>
process-test-resources
</phase>
<configuration>
<target>
<mkdir
dir=
"${geckodriver.basepath}"
/>
<get
src=
"${geckodriver.url}"
dest=
"${geckodriver.compressed.path}"
skipexisting=
"true"
/>
<unzip
src=
"${geckodriver.compressed.path}"
dest=
"${file.separator}${geckodriver.basepath}"
/>
<chmod
file=
"${geckodriver.uncompressed.path}"
perm=
"a+x"
/>
</target>
</configuration>
<goals>
<goal>
run
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>
geckodriver-properties-unix-amd64
</id>
<activation>
<os>
<family>
unix
</family>
<arch>
amd64
</arch>
</os>
</activation>
<properties>
<geckodriver.suffix>
linux64
</geckodriver.suffix>
</properties>
</profile>
<profile>
<id>
geckodriver-properties-unix-x86
</id>
<activation>
<os>
<family>
unix
</family>
<arch>
x86
</arch>
</os>
</activation>
<properties>
<geckodriver.suffix>
linux86
</geckodriver.suffix>
</properties>
</profile>
<profile>
<id>
geckodriver-properties-windows-amd64
</id>
<activation>
<os>
<family>
windows
</family>
<arch>
amd64
</arch>
</os>
</activation>
<properties>
<geckodriver.suffix>
win64
</geckodriver.suffix>
</properties>
</profile>
<profile>
<id>
geckodriver-properties-windows-x86
</id>
<activation>
<os>
<family>
windows
</family>
<arch>
x86
</arch>
</os>
</activation>
<properties>
<geckodriver.suffix>
win32
</geckodriver.suffix>
</properties>
</profile>
<profile>
<id>
geckodriver-properties-and-download-mac
</id>
<activation>
<os>
<family>
mac
</family>
</os>
</activation>
<properties>
<geckodriver.suffix>
macos
</geckodriver.suffix>
<geckodriver.url>
https://github.com/mozilla/geckodriver/releases/download/${geckodriver.version}/geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz
</geckodriver.url>
<geckodriver.basepath>
${settings.localRepository}${file.separator}geckodriver${file.separator}${os.name}${file.separator}${os.arch}
</geckodriver.basepath>
<geckodriver.compressed.path>
${geckodriver.basepath}${file.separator}geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz
</geckodriver.compressed.path>
<geckodriver.uncompressed.path>
${geckodriver.basepath}${file.separator}geckodriver
</geckodriver.uncompressed.path>
</properties>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-antrun-plugin
</artifactId>
<version>
${maven-antrun-plugin.version}
</version>
<executions>
<execution>
<id>
download-geckodriver
</id>
<phase>
process-test-resources
</phase>
<configuration>
<target>
<mkdir
dir=
"${geckodriver.basepath}"
/>
<get
src=
"${geckodriver.url}"
dest=
"${geckodriver.compressed.path}"
skipexisting=
"true"
/>
<untar
src=
"${geckodriver.compressed.path}"
dest=
"${geckodriver.basepath}"
compression=
"gzip"
/>
<chmod
file=
"${geckodriver.uncompressed.path}"
perm=
"a+x"
/>
</target>
</configuration>
<goals>
<goal>
run
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
src/main/angular/package-lock.json
View file @
f2727523
{
"name"
:
"daa-example"
,
"version"
:
"0.2.0-alpha.
8
"
,
"version"
:
"0.2.0-alpha.
9
"
,
"lockfileVersion"
:
1
,
"requires"
:
true
,
"dependencies"
:
{
...
...
src/main/angular/package.json
View file @
f2727523
{
"name"
:
"daa-example"
,
"version"
:
"0.2.0-alpha.
8
"
,
"version"
:
"0.2.0-alpha.
9
"
,
"scripts"
:
{
"ng"
:
"./node_modules/.bin/ng"
,
"start"
:
"./node_modules/.bin/ng serve"
,
...
...
src/test/java/es/uvigo/esei/daa/dao/PeopleDAOTest.java
deleted
100644 → 0
View file @
6341d60f
package
es
.
uvigo
.
esei
.
daa
.
dao
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
existentId
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
existentPerson
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
newName
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
newPerson
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
newSurname
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
nonExistentId
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
nonExistentPerson
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
people
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
peopleWithout
;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
IsEqualToPerson
.
containsPeopleInAnyOrder
;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
IsEqualToPerson
.
equalsToPerson
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
javax.sql.DataSource
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.TestExecutionListeners
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
com.github.springtestdbunit.DbUnitTestExecutionListener
;
import
com.github.springtestdbunit.annotation.DatabaseSetup
;
import
com.github.springtestdbunit.annotation.ExpectedDatabase
;
import
es.uvigo.esei.daa.entities.Person
;
import
es.uvigo.esei.daa.listeners.ApplicationContextBinding
;
import
es.uvigo.esei.daa.listeners.ApplicationContextJndiBindingTestExecutionListener
;
import
es.uvigo.esei.daa.listeners.DbManagement
;
import
es.uvigo.esei.daa.listeners.DbManagementTestExecutionListener
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
"classpath:contexts/mem-context.xml"
)
@TestExecutionListeners
({
DbUnitTestExecutionListener
.
class
,
DbManagementTestExecutionListener
.
class
,
ApplicationContextJndiBindingTestExecutionListener
.
class
})
@ApplicationContextBinding
(
jndiUrl
=
"java:/comp/env/jdbc/daaexample"
,
type
=
DataSource
.
class
)
@DbManagement
(
create
=
"classpath:db/hsqldb.sql"
,
drop
=
"classpath:db/hsqldb-drop.sql"
)
@DatabaseSetup
(
"/datasets/dataset.xml"
)
@ExpectedDatabase
(
"/datasets/dataset.xml"
)
public
class
PeopleDAOTest
{
private
PeopleDAO
dao
;
@Before
public
void
setUp
()
throws
Exception
{
this
.
dao
=
new
PeopleDAO
();
}
@Test
public
void
testList
()
throws
DAOException
{
assertThat
(
this
.
dao
.
list
(),
containsPeopleInAnyOrder
(
people
()));
}
@Test
public
void
testGet
()
throws
DAOException
{
final
Person
person
=
this
.
dao
.
get
(
existentId
());
assertThat
(
person
,
is
(
equalsToPerson
(
existentPerson
())));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testGetNonExistentId
()
throws
DAOException
{
this
.
dao
.
get
(
nonExistentId
());
}
@Test
@ExpectedDatabase
(
"/datasets/dataset-delete.xml"
)
public
void
testDelete
()
throws
DAOException
{
this
.
dao
.
delete
(
existentId
());
assertThat
(
this
.
dao
.
list
(),
containsPeopleInAnyOrder
(
peopleWithout
(
existentId
())));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testDeleteNonExistentId
()
throws
DAOException
{
this
.
dao
.
delete
(
nonExistentId
());
}
@Test
@ExpectedDatabase
(
"/datasets/dataset-modify.xml"
)
public
void
testModify
()
throws
DAOException
{
final
Person
person
=
existentPerson
();
person
.
setName
(
newName
());
person
.
setSurname
(
newSurname
());
this
.
dao
.
modify
(
person
);
final
Person
persistentPerson
=
this
.
dao
.
get
(
person
.
getId
());
assertThat
(
persistentPerson
,
is
(
equalsToPerson
(
person
)));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testModifyNonExistentId
()
throws
DAOException
{
this
.
dao
.
modify
(
nonExistentPerson
());
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testModifyNullPerson
()
throws
DAOException
{
this
.
dao
.
modify
(
null
);
}
@Test
@ExpectedDatabase
(
"/datasets/dataset-add.xml"
)
public
void
testAdd
()
throws
DAOException
{
final
Person
person
=
this
.
dao
.
add
(
newName
(),
newSurname
());
assertThat
(
person
,
is
(
equalsToPerson
(
newPerson
())));
final
Person
persistentPerson
=
this
.
dao
.
get
(
person
.
getId
());
assertThat
(
persistentPerson
,
is
(
equalsToPerson
(
newPerson
())));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testAddNullName
()
throws
DAOException
{
this
.
dao
.
add
(
null
,
newSurname
());
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testAddNullSurname
()
throws
DAOException
{
this
.
dao
.
add
(
newName
(),
null
);
}
}
src/test/java/es/uvigo/esei/daa/dao/PeopleDAOUnitTest.java
deleted
100644 → 0
View file @
6341d60f
package
es
.
uvigo
.
esei
.
daa
.
dao
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
existentId
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
existentPerson
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
newName
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
newPerson
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
newSurname
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
people
;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
IsEqualToPerson
.
containsPeopleInAnyOrder
;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
IsEqualToPerson
.
equalsToPerson
;
import
static
org
.
easymock
.
EasyMock
.
anyString
;
import
static
org
.
easymock
.
EasyMock
.
eq
;
import
static
org
.
easymock
.
EasyMock
.
expect
;
import
static
org
.
easymock
.
EasyMock
.
reset
;
import
static
org
.
hamcrest
.
CoreMatchers
.
equalTo
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
java.sql.SQLException
;
import
org.junit.Test
;
import
com.mysql.jdbc.Statement
;
import
es.uvigo.esei.daa.entities.Person
;
import
es.uvigo.esei.daa.util.DatabaseQueryUnitTest
;
public
class
PeopleDAOUnitTest
extends
DatabaseQueryUnitTest
{
@Test
public
void
testList
()
throws
Exception
{
final
Person
[]
people
=
people
();
for
(
Person
person
:
people
)
{
expectPersonRow
(
person
);
}
expect
(
result
.
next
()).
andReturn
(
false
);
result
.
close
();
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
assertThat
(
peopleDAO
.
list
(),
containsPeopleInAnyOrder
(
people
));
}
@Test
(
expected
=
DAOException
.
class
)
public
void
testListUnexpectedException
()
throws
Exception
{
expect
(
result
.
next
()).
andThrow
(
new
SQLException
());
result
.
close
();
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
peopleDAO
.
list
();
}
@Test
public
void
testGet
()
throws
Exception
{
final
Person
existentPerson
=
existentPerson
();
expectPersonRow
(
existentPerson
);
result
.
close
();
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
assertThat
(
peopleDAO
.
get
(
existentId
()),
is
(
equalTo
(
existentPerson
)));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testGetMissing
()
throws
Exception
{
expect
(
result
.
next
()).
andReturn
(
false
);
result
.
close
();
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
peopleDAO
.
get
(
existentId
());
}
@Test
(
expected
=
DAOException
.
class
)
public
void
testGetUnexpectedException
()
throws
Exception
{
expect
(
result
.
next
()).
andThrow
(
new
SQLException
());
result
.
close
();
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
peopleDAO
.
get
(
existentId
());
}
@Test
public
void
testAdd
()
throws
Exception
{
final
Person
person
=
newPerson
();
reset
(
connection
);
expect
(
connection
.
prepareStatement
(
anyString
(),
eq
(
Statement
.
RETURN_GENERATED_KEYS
)))
.
andReturn
(
statement
);
expect
(
statement
.
executeUpdate
()).
andReturn
(
1
);
expect
(
statement
.
getGeneratedKeys
()).
andReturn
(
result
);
// Key retrieval
expect
(
result
.
next
()).
andReturn
(
true
);
expect
(
result
.
getInt
(
1
)).
andReturn
(
person
.
getId
());
connection
.
close
();
result
.
close
();
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
final
Person
newPerson
=
peopleDAO
.
add
(
person
.
getName
(),
person
.
getSurname
());
assertThat
(
newPerson
,
is
(
equalsToPerson
(
person
)));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testAddNullName
()
throws
Exception
{
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
resetAll
();
// No expectations
peopleDAO
.
add
(
null
,
newSurname
());
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testAddNullSurname
()
throws
Exception
{
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
resetAll
();
// No expectations
peopleDAO
.
add
(
newName
(),
null
);
}
@Test
(
expected
=
DAOException
.
class
)
public
void
testAddZeroUpdatedRows
()
throws
Exception
{
reset
(
connection
);
expect
(
connection
.
prepareStatement
(
anyString
(),
eq
(
1
)))
.
andReturn
(
statement
);
expect
(
statement
.
executeUpdate
()).
andReturn
(
0
);
connection
.
close
();
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
peopleDAO
.
add
(
newName
(),
newSurname
());
}
@Test
(
expected
=
DAOException
.
class
)
public
void
testAddNoGeneratedKey
()
throws
Exception
{
reset
(
connection
);
expect
(
connection
.
prepareStatement
(
anyString
(),
eq
(
1
)))
.
andReturn
(
statement
);
expect
(
statement
.
executeUpdate
()).
andReturn
(
1
);
expect
(
statement
.
getGeneratedKeys
()).
andReturn
(
result
);
expect
(
result
.
next
()).
andReturn
(
false
);
result
.
close
();
connection
.
close
();
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
peopleDAO
.
add
(
newName
(),
newSurname
());
}
@Test
(
expected
=
DAOException
.
class
)
public
void
testAddUnexpectedException
()
throws
Exception
{
reset
(
connection
);
expect
(
connection
.
prepareStatement
(
anyString
(),
eq
(
1
)))
.
andReturn
(
statement
);
expect
(
statement
.
executeUpdate
()).
andThrow
(
new
SQLException
());
connection
.
close
();
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
peopleDAO
.
add
(
newName
(),
newSurname
());
}
@Test
public
void
testDelete
()
throws
Exception
{
expect
(
statement
.
executeUpdate
()).
andReturn
(
1
);
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
peopleDAO
.
delete
(
existentId
());
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testDeleteInvalidId
()
throws
Exception
{
expect
(
statement
.
executeUpdate
()).
andReturn
(
0
);
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
peopleDAO
.
delete
(
existentId
());
}
@Test
(
expected
=
DAOException
.
class
)
public
void
testDeleteUnexpectedException
()
throws
Exception
{
expect
(
statement
.
executeUpdate
()).
andThrow
(
new
SQLException
());
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
peopleDAO
.
delete
(
existentId
());
}
@Test
public
void
testModify
()
throws
Exception
{
expect
(
statement
.
executeUpdate
()).
andReturn
(
1
);
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
peopleDAO
.
modify
(
existentPerson
());
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testModifyNullPerson
()
throws
Exception
{
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
resetAll
();
// No expectations
peopleDAO
.
modify
(
null
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testModifyZeroUpdatedRows
()
throws
Exception
{
expect
(
statement
.
executeUpdate
()).
andReturn
(
0
);
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
peopleDAO
.
modify
(
existentPerson
());
}
@Test
(
expected
=
DAOException
.
class
)
public
void
testModifyUnexpectedException
()
throws
Exception
{
expect
(
statement
.
executeUpdate
()).
andThrow
(
new
SQLException
());
replayAll
();
final
PeopleDAO
peopleDAO
=
new
PeopleDAO
();
peopleDAO
.
modify
(
existentPerson
());
}
private
void
expectPersonRow
(
Person
person
)
throws
SQLException
{
expect
(
result
.
next
()).
andReturn
(
true
);
expect
(
result
.
getInt
(
"id"
)).
andReturn
(
person
.
getId
());
expect
(
result
.
getString
(
"name"
)).
andReturn
(
person
.
getName
());
expect
(
result
.
getString
(
"surname"
)).
andReturn
(
person
.
getSurname
());
}
}
src/test/java/es/uvigo/esei/daa/rest/PeopleResourceUnitTest.java
deleted
100644 → 0
View file @
6341d60f
package
es
.
uvigo
.
esei
.
daa
.
rest
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
existentId
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
existentPerson
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
newName
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
newPerson
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
newSurname
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
people
;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
HasHttpStatus
.
hasBadRequestStatus
;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
HasHttpStatus
.
hasInternalServerErrorStatus
;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
HasHttpStatus
.
hasOkStatus
;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
IsEqualToPerson
.
containsPeopleInAnyOrder
;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
IsEqualToPerson
.
equalsToPerson
;
import
static
java
.
util
.
Arrays
.
asList
;
import
static
org
.
easymock
.
EasyMock
.
anyInt
;
import
static
org
.
easymock
.
EasyMock
.
anyObject
;
import
static
org
.
easymock
.
EasyMock
.
anyString
;
import
static
org
.
easymock
.
EasyMock
.
createMock
;
import
static
org
.
easymock
.
EasyMock
.
expect
;
import
static
org
.
easymock
.
EasyMock
.
expectLastCall
;
import
static
org
.
easymock
.
EasyMock
.
replay
;
import
static
org
.
easymock
.
EasyMock
.
verify
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
java.util.List
;
import
javax.ws.rs.core.Response
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
es.uvigo.esei.daa.dao.DAOException
;
import
es.uvigo.esei.daa.dao.PeopleDAO
;
import
es.uvigo.esei.daa.entities.Person
;
public
class
PeopleResourceUnitTest
{
private
PeopleDAO
daoMock
;
private
PeopleResource
resource
;
@Before
public
void
setUp
()
throws
Exception
{
daoMock
=
createMock
(
PeopleDAO
.
class
);
resource
=
new
PeopleResource
(
daoMock
);
}
@After
public
void
tearDown
()
throws
Exception
{
try
{
verify
(
daoMock
);
}
finally
{
daoMock
=
null
;
resource
=
null
;
}
}
@Test
@SuppressWarnings
(
"unchecked"
)
public
void
testList
()
throws
Exception
{
final
List
<
Person
>
people
=
asList
(
people
());
expect
(
daoMock
.
list
()).
andReturn
(
people
);
replay
(
daoMock
);
final
Response
response
=
resource
.
list
();
assertThat
(
response
,
hasOkStatus
());
assertThat
((
List
<
Person
>)
response
.
getEntity
(),
containsPeopleInAnyOrder
(
people
()));
}
@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
testGet
()
throws
Exception
{
final
Person
person
=
existentPerson
();
expect
(
daoMock
.
get
(
person
.
getId
())).
andReturn
(
person
);
replay
(
daoMock
);
final
Response
response
=
resource
.
get
(
person
.
getId
());
assertThat
(
response
,
hasOkStatus
());
assertThat
((
Person
)
response
.
getEntity
(),
is
(
equalsToPerson
(
person
)));
}
@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
Person
person
=
existentPerson
();
person
.
setName
(
newName
());
person
.
setSurname
(
newSurname
());
daoMock
.
modify
(
person
);
replay
(
daoMock
);
final
Response
response
=
resource
.
modify
(
person
.
getId
(),
person
.
getName
(),
person
.
getSurname
());
assertThat
(
response
,
hasOkStatus
());
assertEquals
(
person
,
response
.
getEntity
());
}
@Test
public
void
testModifyDAOException
()
throws
Exception
{
daoMock
.
modify
(
anyObject
());
expectLastCall
().
andThrow
(
new
DAOException
());
replay
(
daoMock
);
final
Response
response
=
resource
.
modify
(
existentId
(),
newName
(),
newSurname
());
assertThat
(
response
,
hasInternalServerErrorStatus
());
}
@Test
public
void
testModifyIllegalArgumentException
()
throws
Exception
{
daoMock
.
modify
(
anyObject
());
expectLastCall
().
andThrow
(
new
IllegalArgumentException
());
replay
(
daoMock
);
final
Response
response
=
resource
.
modify
(
existentId
(),
newName
(),
newSurname
());
assertThat
(
response
,
hasBadRequestStatus
());
}
@Test
public
void
testModifyNullPointerException
()
throws
Exception
{
daoMock
.
modify
(
anyObject
());
expectLastCall
().
andThrow
(
new
NullPointerException
());
replay
(
daoMock
);
final
Response
response
=
resource
.
modify
(
existentId
(),
newName
(),
newSurname
());
assertThat
(
response
,
hasBadRequestStatus
());
}
@Test
public
void
testAdd
()
throws
Exception
{
expect
(
daoMock
.
add
(
newName
(),
newSurname
()))
.
andReturn
(
newPerson
());
replay
(
daoMock
);
final
Response
response
=
resource
.
add
(
newName
(),
newSurname
());
assertThat
(
response
,
hasOkStatus
());
assertThat
((
Person
)
response
.
getEntity
(),
is
(
equalsToPerson
(
newPerson
())));
}
@Test
public
void
testAddDAOException
()
throws
Exception
{
expect
(
daoMock
.
add
(
anyString
(),
anyString
()))
.
andThrow
(
new
DAOException
());
replay
(
daoMock
);
final
Response
response
=
resource
.
add
(
newName
(),
newSurname
());
assertThat
(
response
,
hasInternalServerErrorStatus
());
}
@Test
public
void
testAddIllegalArgumentException
()
throws
Exception
{
expect
(
daoMock
.
add
(
anyString
(),
anyString
()))
.
andThrow
(
new
IllegalArgumentException
());
replay
(
daoMock
);
final
Response
response
=
resource
.
add
(
newName
(),
newSurname
());
assertThat
(
response
,
hasBadRequestStatus
());
}
}
src/test/java/es/uvigo/esei/daa/suites/AcceptanceTestSuite.java
deleted
100644 → 0
View file @
6341d60f
package
es
.
uvigo
.
esei
.
daa
.
suites
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
import
es.uvigo.esei.daa.web.PeopleWebTest
;
@SuiteClasses
({
PeopleWebTest
.
class
})
@RunWith
(
Suite
.
class
)
public
class
AcceptanceTestSuite
{
}
src/test/java/es/uvigo/esei/daa/suites/IntegrationTestSuite.java
View file @
f2727523
...
...
@@ -4,12 +4,10 @@ import org.junit.runner.RunWith;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
import
es.uvigo.esei.daa.dao.PeopleDAOTest
;
import
es.uvigo.esei.daa.rest.PeopleResourceTest
;
import
es.uvigo.esei.daa.rest.UsersResourceTest
;
@SuiteClasses
({
PeopleDAOTest
.
class
,
PeopleResourceTest
.
class
,
UsersResourceTest
.
class
})
...
...
src/test/java/es/uvigo/esei/daa/suites/UnitTestSuite.java
View file @
f2727523
...
...
@@ -4,14 +4,10 @@ import org.junit.runner.RunWith;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
import
es.uvigo.esei.daa.dao.PeopleDAOUnitTest
;
import
es.uvigo.esei.daa.entities.PersonUnitTest
;
import
es.uvigo.esei.daa.rest.PeopleResourceUnitTest
;
@SuiteClasses
({
PersonUnitTest
.
class
,
PeopleDAOUnitTest
.
class
,
PeopleResourceUnitTest
.
class
PersonUnitTest
.
class
})
@RunWith
(
Suite
.
class
)
public
class
UnitTestSuite
{
...
...
src/test/java/es/uvigo/esei/daa/web/PeopleWebTest.java
deleted
100644 → 0
View file @
6341d60f
package
es
.
uvigo
.
esei
.
daa
.
web
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
existentId
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
existentPerson
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
newName
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
newPerson
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
newSurname
;
import
static
es
.
uvigo
.
esei
.
daa
.
dataset
.
PeopleDataset
.
people
;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
IsEqualToPerson
.
containsPeopleInAnyOrder
;
import
static
es
.
uvigo
.
esei
.
daa
.
matchers
.
IsEqualToPerson
.
equalsToPerson
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
java.util.concurrent.TimeUnit
;
import
javax.sql.DataSource
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.firefox.FirefoxDriver
;
import
org.openqa.selenium.firefox.FirefoxOptions
;
import
org.openqa.selenium.firefox.FirefoxProfile
;
import
org.openqa.selenium.html5.LocalStorage
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.TestExecutionListeners
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
com.github.springtestdbunit.DbUnitTestExecutionListener
;
import
com.github.springtestdbunit.annotation.DatabaseSetup
;
import
com.github.springtestdbunit.annotation.ExpectedDatabase
;
import
es.uvigo.esei.daa.entities.Person
;
import
es.uvigo.esei.daa.listeners.ApplicationContextBinding
;
import
es.uvigo.esei.daa.listeners.ApplicationContextJndiBindingTestExecutionListener
;
import
es.uvigo.esei.daa.listeners.DbManagement
;
import
es.uvigo.esei.daa.listeners.DbManagementTestExecutionListener
;
import
es.uvigo.esei.daa.web.pages.MainPage
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
"classpath:contexts/hsql-context.xml"
)
@TestExecutionListeners
({
DbUnitTestExecutionListener
.
class
,
DbManagementTestExecutionListener
.
class
,
ApplicationContextJndiBindingTestExecutionListener
.
class
})
@ApplicationContextBinding
(
jndiUrl
=
"java:/comp/env/jdbc/daaexample"
,
type
=
DataSource
.
class
)
@DbManagement
(
create
=
"classpath:db/hsqldb.sql"
,
drop
=
"classpath:db/hsqldb-drop.sql"
)
@DatabaseSetup
(
"/datasets/dataset.xml"
)
@ExpectedDatabase
(
"/datasets/dataset.xml"
)
public
class
PeopleWebTest
{
private
static
final
int
DEFAULT_WAIT_TIME
=
1
;
private
WebDriver
driver
;
private
MainPage
mainPage
;
@Before
public
void
setUp
()
throws
Exception
{
final
String
baseUrl
=
"http://localhost:9080/DAAExample/"
;
final
FirefoxProfile
profile
=
new
FirefoxProfile
();
profile
.
setPreference
(
"browser.privatebrowsing.autostart"
,
true
);
final
FirefoxOptions
options
=
new
FirefoxOptions
();
options
.
setProfile
(
profile
);
final
FirefoxDriver
firefoxDriver
;
driver
=
firefoxDriver
=
new
FirefoxDriver
();
driver
.
get
(
baseUrl
);
// Driver will wait DEFAULT_WAIT_TIME if it doesn't find and element.
driver
.
manage
().
timeouts
().
implicitlyWait
(
DEFAULT_WAIT_TIME
,
TimeUnit
.
SECONDS
);
driver
.
manage
().
window
().
maximize
();
// Login as "admin:adminpass"
final
LocalStorage
localStorage
=
firefoxDriver
.
getLocalStorage
();
// YWRtaW46YWRtaW5wYXNz
localStorage
.
setItem
(
"user"
,
"{\"login\":\"admin\",\"password\":\"adminpass\"}"
);
mainPage
=
new
MainPage
(
driver
,
baseUrl
);
mainPage
.
navigateTo
();
}
@After
public
void
tearDown
()
throws
Exception
{
driver
.
quit
();
driver
=
null
;
mainPage
=
null
;
}
@Test
public
void
testList
()
throws
Exception
{
assertThat
(
mainPage
.
listPeople
(),
containsPeopleInAnyOrder
(
people
()));
}
@Test
@ExpectedDatabase
(
"/datasets/dataset-add.xml"
)
public
void
testAdd
()
throws
Exception
{
final
Person
newPerson
=
mainPage
.
addPerson
(
newName
(),
newSurname
());
assertThat
(
newPerson
,
is
(
equalsToPerson
(
newPerson
())));
}
@Test
@ExpectedDatabase
(
"/datasets/dataset-modify.xml"
)
public
void
testEdit
()
throws
Exception
{
final
Person
person
=
existentPerson
();
person
.
setName
(
newName
());
person
.
setSurname
(
newSurname
());
mainPage
.
editPerson
(
person
);
final
Person
webPerson
=
mainPage
.
getPerson
(
person
.
getId
());
assertThat
(
webPerson
,
is
(
equalsToPerson
(
person
)));
}
@Test
@ExpectedDatabase
(
"/datasets/dataset-delete.xml"
)
public
void
testDelete
()
throws
Exception
{
mainPage
.
deletePerson
(
existentId
());
assertFalse
(
mainPage
.
hasPerson
(
existentId
()));
}
}
src/test/java/es/uvigo/esei/daa/web/pages/MainPage.java
deleted
100644 → 0
View file @
6341d60f
package
es
.
uvigo
.
esei
.
daa
.
web
.
pages
;
import
static
java
.
util
.
stream
.
Collectors
.
toList
;
import
static
org
.
openqa
.
selenium
.
support
.
ui
.
ExpectedConditions
.
presenceOfElementLocated
;
import
static
org
.
openqa
.
selenium
.
support
.
ui
.
ExpectedConditions
.
textToBePresentInElement
;
import
java.util.List
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.NoSuchElementException
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.support.ui.WebDriverWait
;
import
es.uvigo.esei.daa.entities.Person
;
import
es.uvigo.esei.daa.util.JSWaiter
;
public
class
MainPage
{
private
static
final
String
TABLE_ID
=
"people-list"
;
private
static
final
String
FORM_ID
=
"people-form"
;
private
static
final
String
ID_PREFIX
=
"person-"
;
private
final
WebDriver
driver
;
private
final
WebDriverWait
wait
;
private
final
String
baseUrl
;
public
MainPage
(
WebDriver
driver
,
String
baseUrl
)
{
this
.
driver
=
driver
;
this
.
baseUrl
=
baseUrl
;
this
.
wait
=
new
WebDriverWait
(
driver
,
1
);
}
public
void
navigateTo
()
{
this
.
driver
.
get
(
this
.
baseUrl
+
"#/people"
);
this
.
wait
.
until
(
presenceOfElementLocated
(
By
.
id
(
TABLE_ID
)));
}
public
int
countPeople
()
{
return
new
PeopleTable
(
this
.
driver
).
countPeople
();
}
public
List
<
Person
>
listPeople
()
{
return
new
PeopleTable
(
this
.
driver
).
listPeople
();
}
public
Person
getLastPerson
()
{
return
new
PeopleTable
(
this
.
driver
).
getPersonInLastRow
();
}
public
Person
getPerson
(
int
id
)
{
return
new
PeopleTable
(
this
.
driver
).
getPersonById
(
id
);
}
public
boolean
hasPerson
(
int
id
)
{
return
new
PeopleTable
(
this
.
driver
).
hasPerson
(
id
);
}
public
Person
addPerson
(
String
name
,
String
surname
)
{
final
PersonForm
form
=
new
PersonForm
(
this
.
driver
);
form
.
clear
();
form
.
setName
(
name
);
form
.
setSurname
(
surname
);
form
.
submit
();
final
PeopleTable
table
=
new
PeopleTable
(
driver
);
return
table
.
getPerson
(
name
,
surname
);
}
public
void
editPerson
(
Person
person
)
{
final
PeopleTable
table
=
new
PeopleTable
(
this
.
driver
);
table
.
editPerson
(
person
.
getId
());
final
PersonForm
form
=
new
PersonForm
(
this
.
driver
);
form
.
setName
(
person
.
getName
());
form
.
setSurname
(
person
.
getSurname
());
form
.
submit
();
}
public
void
deletePerson
(
int
id
)
{
final
PeopleTable
table
=
new
PeopleTable
(
this
.
driver
);
table
.
deletePerson
(
id
);
JSWaiter
.
wait
(
driver
).
untilAngular5Ready
();
}
private
final
static
class
PeopleTable
{
private
final
WebDriver
driver
;
private
final
WebElement
table
;
public
PeopleTable
(
WebDriver
driver
)
{
this
.
driver
=
driver
;
this
.
table
=
this
.
driver
.
findElement
(
By
.
id
(
TABLE_ID
));
}
public
boolean
hasPerson
(
int
id
)
{
try
{
return
this
.
getPersonRow
(
id
)
!=
null
;
}
catch
(
NoSuchElementException
nsee
)
{
return
false
;
}
}
public
void
editPerson
(
int
id
)
{
final
WebElement
personRow
=
this
.
getPersonRow
(
id
);
personRow
.
findElement
(
By
.
className
(
"edit"
)).
click
();
}
public
void
deletePerson
(
int
id
)
{
final
WebElement
personRow
=
this
.
getPersonRow
(
id
);
personRow
.
findElement
(
By
.
className
(
"delete"
)).
click
();
this
.
acceptDialog
();
}
public
Person
getPersonById
(
int
id
)
{
return
rowToPerson
(
getPersonRow
(
id
));
}
public
Person
getPerson
(
String
name
,
String
surname
)
{
return
rowToPerson
(
getPersonRow
(
name
,
surname
));
}
public
Person
getPersonInLastRow
()
{
final
WebElement
row
=
this
.
table
.
findElement
(
By
.
cssSelector
(
"tbody > tr:last-child"
));
return
rowToPerson
(
row
);
}
private
WebElement
getPersonRow
(
int
id
)
{
return
this
.
table
.
findElement
(
By
.
id
(
ID_PREFIX
+
id
));
}
public
WebElement
getPersonRow
(
String
name
,
String
surname
)
{
final
List
<
WebElement
>
rows
=
table
.
findElements
(
By
.
cssSelector
(
"tbody > tr"
));
for
(
WebElement
row
:
rows
)
{
final
String
rowName
=
row
.
findElement
(
By
.
className
(
"name"
)).
getText
();
final
String
rowSurname
=
row
.
findElement
(
By
.
className
(
"surname"
)).
getText
();
if
(
rowName
.
equals
(
name
)
&&
rowSurname
.
equals
(
surname
))
{
return
row
;
}
}
throw
new
IllegalArgumentException
(
String
.
format
(
"No row found with name '%s' and surname '%s'"
,
name
,
surname
));
}
public
int
countPeople
()
{
return
getRows
().
size
();
}
public
List
<
Person
>
listPeople
()
{
return
getRows
().
stream
()
.
map
(
this
::
rowToPerson
)
.
collect
(
toList
());
}
private
List
<
WebElement
>
getRows
()
{
final
String
xpathQuery
=
"//tbody/tr[starts-with(@id, '"
+
ID_PREFIX
+
"')]"
;
return
this
.
table
.
findElements
(
By
.
xpath
(
xpathQuery
));
}
private
Person
rowToPerson
(
WebElement
row
)
{
return
new
Person
(
Integer
.
parseInt
(
row
.
getAttribute
(
"id"
).
substring
(
ID_PREFIX
.
length
())),
row
.
findElement
(
By
.
className
(
"name"
)).
getText
(),
row
.
findElement
(
By
.
className
(
"surname"
)).
getText
()
);
}
private
void
acceptDialog
()
{
driver
.
switchTo
().
alert
().
accept
();
}
}
public
final
static
class
PersonForm
{
private
final
WebDriverWait
wait
;
private
final
WebElement
fieldName
;
private
final
WebElement
fieldSurname
;
private
final
WebElement
buttonClear
;
private
final
WebElement
buttonSubmit
;
public
PersonForm
(
WebDriver
driver
)
{
this
.
wait
=
new
WebDriverWait
(
driver
,
1
);
final
WebElement
form
=
driver
.
findElement
(
By
.
id
(
FORM_ID
));
this
.
fieldName
=
form
.
findElement
(
By
.
name
(
"name"
));
this
.
fieldSurname
=
form
.
findElement
(
By
.
name
(
"surname"
));
this
.
buttonClear
=
form
.
findElement
(
By
.
id
(
"btnClear"
));
this
.
buttonSubmit
=
form
.
findElement
(
By
.
id
(
"btnSubmit"
));
}
public
void
submit
()
{
this
.
buttonSubmit
.
click
();
this
.
waitForCleanFields
();
}
public
void
clear
()
{
this
.
buttonClear
.
click
();
this
.
waitForCleanFields
();
}
public
void
setName
(
String
name
)
{
this
.
fieldName
.
clear
();
this
.
fieldName
.
sendKeys
(
name
);
}
public
void
setSurname
(
String
surname
)
{
this
.
fieldSurname
.
clear
();
this
.
fieldSurname
.
sendKeys
(
surname
);
}
public
String
getName
()
{
return
this
.
fieldName
.
getText
();
}
public
String
getSurname
()
{
return
this
.
fieldSurname
.
getText
();
}
private
void
waitForCleanFields
()
{
wait
.
until
(
textToBePresentInElement
(
fieldName
,
""
));
wait
.
until
(
textToBePresentInElement
(
fieldSurname
,
""
));
}
}
}
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