Commit a04ab153 authored by Cotrena federico's avatar Cotrena federico

test

parent a4700d96
Pipeline #93 failed with stages
package com.sistemaDistribuido.Banco.backend.controller;
import com.sistemaDistribuido.Banco.backend.dto.InteresDto;
import com.sistemaDistribuido.Banco.backend.model.Cuenta;
import com.sistemaDistribuido.Banco.backend.service.CuentaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;
@RestController
......@@ -25,17 +25,17 @@ public class CuentaController{
}
@PostMapping("/depositar")
public Cuenta depositar( @RequestParam Cuenta cantidad) {
public Cuenta depositar( @RequestBody Cuenta cantidad) {
return this.cuentaService.depositar(cantidad);
}
@PostMapping("/extraer")
public Cuenta extraccion( @RequestParam Cuenta cantidad) {
public Cuenta extraccion( @RequestBody Cuenta cantidad) {
return this.cuentaService.extraccion(cantidad);
}
@PostMapping("/interes")
public Cuenta interes( @RequestParam int interes) {
return this.cuentaService.interes(interes);
public Cuenta interes( @RequestBody InteresDto interes) {
return this.cuentaService.interes((int) interes.interes);
}
......
package com.sistemaDistribuido.Banco.backend.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(path = "", produces = "application/json")
public class HelloWordController {
@GetMapping("/saludar")
public String sayHello() {
return "Hello dev";
}
}
\ No newline at end of file
package com.sistemaDistribuido.Banco.backend.dto;
public class InteresDto {
public double interes;
}
......@@ -52,10 +52,10 @@ public class CuentaServiceImpl implements CuentaService {
@Override
public Cuenta interes(int interes) {
Cuenta cuentainteres = repository.findById(1L).get();
interes = interes +(interes/100*cuentainteres.getSaldo());
cuentainteres.setSaldo(cuentainteres.getSaldo()-interes);
int i = cuentainteres.getSaldo()*interes/100;
cuentainteres.setSaldo(cuentainteres.getSaldo()-i);
// transacionesRepository.save(new Transacciones(interes,Transacciones.Tipo.INTERES));
transacionesRepository.save(new Transacciones(interes,"INTERES",LocalDateTime.now()));
transacionesRepository.save(new Transacciones(i,"INTERES",LocalDateTime.now()));
return cuentainteres;
......
package com.sistemaDistribuido.Banco;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import net.minidev.json.JSONObject;
import org.hamcrest.Matchers;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
public class Test1 {
......@@ -27,18 +32,81 @@ public class Test1 {
}
@Test
public void Extraccion() {
Map<String, Object> map = new HashMap<>();
map.put("id", 1);
map.put("saldo", 2000);
RestAssured
.given()
.request().param("id",1,"saldo",2000)
.contentType(ContentType.JSON)
.body(map)
.baseUri(urlBase)
.and()
.queryParam("format", "json")
.when()
.post("/cuentas/depositar")
.post("/cuentas/extraer")
.then()
.log().all()
.and().assertThat().statusCode(is(equalTo(200)))
.and().body("saldo", Matchers.equalTo( 0));
}
@Test
public void deposito() {
Map<String, Object> map = new HashMap<>();
map.put("id", 1);
map.put("saldo", 3000);
RestAssured
.given()
.contentType(ContentType.JSON)
.body(map)
.baseUri(urlBase)
.and()
.queryParam("format", "json")
.when()
.post("/cuentas/depositar")
.then()
.log().all()
.and().assertThat().statusCode(is(equalTo(200)))
.and().body("saldo", Matchers.equalTo( 3000));
}
@Test
public void interes() {
Map<String, Object> map = new HashMap<>();
map.put("interes", 10.0);
RestAssured
.given()
.contentType(ContentType.JSON)
.body(map)
.baseUri(urlBase)
.and()
.queryParam("format", "json")
.when()
.post("/cuentas/interes")
.then()
.log().all()
.and().assertThat().statusCode(is(equalTo(200)))
.and().body("saldo", Matchers.equalTo( 2700));
}
@Test
public void balance() {
RestAssured
.given()
.baseUri(urlBase)
.and()
.queryParam("format", "json")
.when()
.get("/transacciones/balance")
.then()
.log().all()
.and().assertThat().statusCode(is(equalTo(200)))
.and().body(Matchers.equalTo(4000.0));
}
}
\ No newline at end of file
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