entrega segundo laboratorio

parent 7fa2d29e
......@@ -11,7 +11,7 @@
<groupId>com.trabajopractico</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Laboratorio</name>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>18</java.version>
......@@ -59,6 +59,83 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- inicio plugin docker -->
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.40.2</version>
<configuration>
<logDate>default</logDate>
<autoPull>true</autoPull>
<verbose>true</verbose>
<!-- <dockerHost>unix:///var/run/docker.sock</dockerHost> -->
<dockerHost>npipe:////./pipe/docker_engine</dockerHost>
<images>
<image>
<alias>${db}</alias>
<name>postgres:13.8-alpine</name>
<run>
<env>
<POSTGRES_USER>laboratorioadm</POSTGRES_USER>
<POSTGRES_PASSWORD>laboratorioadm</POSTGRES_PASSWORD>
<POSTGRES_DB>laboratorio</POSTGRES_DB>
</env>
<wait>
<log>database system is ready to accept connections</log>
<time>20000</time>
</wait>
<log>
<prefix>DB:</prefix>
<color>yellow</color>
</log>
</run>
</image>
<image>
<name>${project.name}:${project.version}</name>
<build>
<from>openjdk:18</from>
<assembly>
<name>build</name>
<descriptorRef>artifact</descriptorRef>
</assembly>
<ports>
<port>8080</port>
</ports>
<cmd>java -jar build/${project.name}-${project.version}.jar</cmd>
</build>
<run>
<ports>
<port>${spring.port}:8080</port>
</ports>
<env>
<SPRING_DATASOURCE_URL>jdbc:postgresql://${db}:5432/laboratorio</SPRING_DATASOURCE_URL>
<SPRING_DATASOURCE_USER>laboratorioadm</SPRING_DATASOURCE_USER>
<SPRING_DATASOURCE_PASSWORD>laboratorioadm</SPRING_DATASOURCE_PASSWORD>
</env>
<log>
<prefix>spring: </prefix>
<color>blue</color>
</log>
<dependsOn>
<container>${db}</container>
</dependsOn>
<links>
<link>${db}</link>
</links>
<wait>
<time>10000</time>
</wait>
</run>
</image>
</images>
</configuration>
</plugin>
<!-- FIN DEL PLUGIN DOCKER -->
</plugins>
</build>
......
......@@ -3,10 +3,7 @@ package com.trabajopractico.demo;
import com.trabajopractico.demo.backend.model.Operacion;
import com.trabajopractico.demo.backend.model.OperacionType;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
......@@ -16,6 +13,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
import static org.junit.jupiter.api.Assertions.assertEquals;
@Disabled
@SpringBootTest (webEnvironment=SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@AutoConfigureWebTestClient
......
......@@ -2,10 +2,7 @@ package com.trabajopractico.demo;
import com.trabajopractico.demo.backend.model.Operacion;
import com.trabajopractico.demo.backend.model.OperacionType;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
......@@ -15,6 +12,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
import static org.junit.jupiter.api.Assertions.assertEquals;
@SpringBootTest (webEnvironment=SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@AutoConfigureWebTestClient
......
package com.trabajopractico.demo;
import com.trabajopractico.demo.backend.model.Operacion;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SpringBootTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class TestPuertos {
TestRestTemplate restTemplate = new TestRestTemplate();
HttpHeaders headers = new HttpHeaders();
@Test
@Order(1)
public void depositoFirst() {
HttpEntity<String> entity = new HttpEntity<String>(null, headers);
restTemplate.exchange("http://localhost:8082/api"+"/operaciones/deleteall",HttpMethod.GET, entity, Operacion.class);
ResponseEntity<Operacion> response = restTemplate.exchange("http://localhost:8082/api"+"/operaciones/deposito?tipo=DEPOSITO&monto=1000",HttpMethod.POST, entity, Operacion.class);
assertEquals(1000.0,response.getBody().getMonto());
// assertTrue(true);
}
@Test
@Order(2)
public void depositoSecond() {
HttpEntity<String> entity = new HttpEntity<String>(null, headers);
restTemplate.exchange("http://localhost:8085/api"+"/operaciones/deleteall",HttpMethod.GET, entity, Operacion.class);
ResponseEntity<Operacion> response = restTemplate.exchange("http://localhost:8085/api"+"/operaciones/deposito?tipo=DEPOSITO&monto=5000",HttpMethod.POST, entity, Operacion.class);
assertEquals(5000.0,response.getBody().getMonto());
//assertTrue(true);
}
@Test
@Order(3)
public void depositoTercero() {
HttpEntity<String> entity = new HttpEntity<String>(null, headers);
restTemplate.exchange("http://localhost:8083/api"+"/operaciones/deleteall",HttpMethod.GET, entity, Operacion.class);
ResponseEntity<Operacion> response = restTemplate.exchange("http://localhost:8083/api"+"/operaciones/deposito?tipo=DEPOSITO&monto=200",HttpMethod.POST, entity, Operacion.class);
assertEquals(200.0,response.getBody().getMonto());
}
@Test
@Order(4)
public void saldosPuertos() {
HttpEntity<String> entity = new HttpEntity<String>(null, headers);
ResponseEntity<Operacion> response = restTemplate.exchange("http://localhost:8082/api/operaciones/consulta",HttpMethod.GET, entity, Operacion.class);
assertEquals(1000.0,response.getBody().getMonto());
response = restTemplate.exchange("http://localhost:8085/api/operaciones/consulta",HttpMethod.GET, entity, Operacion.class);
assertEquals(5000.0,response.getBody().getMonto());
response = restTemplate.exchange("http://localhost:8083/api/operaciones/consulta",HttpMethod.GET, entity, Operacion.class);
assertEquals(200.0,response.getBody().getMonto());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment