Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Alvaro Ordóñez Romero
/
DAE-aha00026-aor00039
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1667d397
authored
Nov 08, 2023
by
Alvaro Ordóñez Romero
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Creación de ViajeRepository y ViajeTestRepository
parent
d6100bd5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
10 deletions
src/main/java/com/carpooling/carpoolingaoraha/entidades/Reserva.java
src/main/java/com/carpooling/carpoolingaoraha/entidades/Viaje.java
src/main/java/com/carpooling/carpoolingaoraha/repositorios/ViajeRepository.java
src/test/java/com/carpooling/carpoolingaoraha/entidades/SistemaCarPoolingTest.java
src/test/java/com/carpooling/carpoolingaoraha/entidades/UsuarioTest.java
src/test/java/com/carpooling/carpoolingaoraha/entidades/ViajeTest.java
src/test/java/com/carpooling/carpoolingaoraha/repositorios/ViajeRepositoryTest.java
src/main/java/com/carpooling/carpoolingaoraha/entidades/Reserva.java
View file @
1667d397
...
...
@@ -37,8 +37,7 @@ public class Reserva {
this
.
conductor
=
conductor
;
this
.
idReserva
=
++
incrementaReserva
;
this
.
numPasajeros
=
nAsientos
;
this
.
viaje
=
new
Viaje
(
origen
,
destino
,
fechaSalida
,
nAsientos
,
precioAsiento
);
this
.
viaje
.
setIdViaje
(
this
.
idReserva
);
this
.
viaje
=
new
Viaje
(
origen
,
destino
,
fechaSalida
,
nAsientos
,
precioAsiento
,
this
.
idReserva
);
this
.
sistema
=
new
SistemaCarPooling
();
this
.
sistema
.
addViaje
(
this
.
viaje
);
this
.
sistema
.
addReserva
(
this
);
...
...
src/main/java/com/carpooling/carpoolingaoraha/entidades/Viaje.java
View file @
1667d397
...
...
@@ -12,16 +12,15 @@ public class Viaje {
private
int
nAsientos
;
private
int
precioAsiento
;
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
int
idViaje
;
public
Viaje
(){}
public
Viaje
(
String
origen
,
String
destino
,
Date
fechaSalida
,
int
nAsientos
,
int
precioAsiento
)
{
public
Viaje
(
String
origen
,
String
destino
,
Date
fechaSalida
,
int
nAsientos
,
int
precioAsiento
,
int
idViaje
)
{
this
.
origen
=
origen
;
this
.
destino
=
destino
;
this
.
fechaSalida
=
fechaSalida
;
this
.
nAsientos
=
nAsientos
;
this
.
precioAsiento
=
precioAsiento
;
this
.
idViaje
=
0
;
this
.
idViaje
=
idViaje
;
}
public
int
getIdViaje
()
{
...
...
src/main/java/com/carpooling/carpoolingaoraha/repositorios/ViajeRepository.java
0 → 100644
View file @
1667d397
package
com
.
carpooling
.
carpoolingaoraha
.
repositorios
;
import
com.carpooling.carpoolingaoraha.entidades.Viaje
;
import
org.springframework.data.jpa.repository.JpaRepository
;
public
interface
ViajeRepository
extends
JpaRepository
<
Viaje
,
Integer
>
{
Viaje
findByIdViaje
(
Integer
iD
);
}
src/test/java/com/carpooling/carpoolingaoraha/entidades/SistemaCarPoolingTest.java
View file @
1667d397
...
...
@@ -21,7 +21,7 @@ public class SistemaCarPoolingTest {
public
void
testAddViaje
()
throws
ParseException
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Date
fecha
=
dateFormat
.
parse
(
"2023-10-07"
);
Viaje
viaje
=
new
Viaje
(
"Origen"
,
"Destino"
,
fecha
,
3
,
10
);
Viaje
viaje
=
new
Viaje
(
"Origen"
,
"Destino"
,
fecha
,
3
,
10
,
5
);
sistema
.
addViaje
(
viaje
);
assertTrue
(
sistema
.
getViajes
().
contains
(
viaje
));
}
...
...
src/test/java/com/carpooling/carpoolingaoraha/entidades/UsuarioTest.java
View file @
1667d397
...
...
@@ -48,9 +48,9 @@ public class UsuarioTest {
// Inicializar la lista de viajes con datos de ejemplo
List
<
Viaje
>
todosLosViajes
=
new
ArrayList
<>();
Viaje
viaje1
=
new
Viaje
(
"Origen1"
,
"Destino1"
,
new
Date
(),
3
,
20
);
Viaje
viaje2
=
new
Viaje
(
"Origen2"
,
"Destino2"
,
new
Date
(),
2
,
15
);
Viaje
viaje3
=
new
Viaje
(
"Origen3"
,
"Destino3"
,
new
Date
(),
1
,
10
);
Viaje
viaje1
=
new
Viaje
(
"Origen1"
,
"Destino1"
,
new
Date
(),
3
,
20
,
5
);
Viaje
viaje2
=
new
Viaje
(
"Origen2"
,
"Destino2"
,
new
Date
(),
2
,
15
,
5
);
Viaje
viaje3
=
new
Viaje
(
"Origen3"
,
"Destino3"
,
new
Date
(),
1
,
10
,
5
);
todosLosViajes
.
add
(
viaje1
);
todosLosViajes
.
add
(
viaje2
);
...
...
src/test/java/com/carpooling/carpoolingaoraha/entidades/ViajeTest.java
View file @
1667d397
...
...
@@ -12,7 +12,7 @@ public class ViajeTest {
@Before
public
void
testConstructor
()
{
viaje
=
new
Viaje
(
"Origen"
,
"Destino"
,
new
Date
(),
3
,
20
);
viaje
=
new
Viaje
(
"Origen"
,
"Destino"
,
new
Date
(),
3
,
20
,
5
);
}
@Test
...
...
src/test/java/com/carpooling/carpoolingaoraha/repositorios/ViajeRepositoryTest.java
0 → 100644
View file @
1667d397
package
com
.
carpooling
.
carpoolingaoraha
.
repositorios
;
import
com.carpooling.carpoolingaoraha.entidades.Viaje
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
;
import
org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
@RunWith
(
SpringRunner
.
class
)
@DataJpaTest
@AutoConfigureTestDatabase
(
replace
=
AutoConfigureTestDatabase
.
Replace
.
NONE
)
public
class
ViajeRepositoryTest
{
@Autowired
private
ViajeRepository
repository
;
@Test
public
void
testInsertViaje
(){
Viaje
viaje
=
new
Viaje
();
viaje
.
setDestino
(
"Canarias"
);
int
idViaje
=
1
;
viaje
.
setIdViaje
(
idViaje
);
repository
.
save
(
viaje
);
Viaje
viajeGuardado
=
repository
.
findByIdViaje
(
idViaje
);
Assert
.
assertNotNull
(
viajeGuardado
);
Assert
.
assertEquals
(
idViaje
,
viajeGuardado
.
getIdViaje
());
Assert
.
assertEquals
(
"Canarias"
,
viajeGuardado
.
getDestino
());
}
}
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