Skip to content

Commit

Permalink
Feature/integration test (#43)
Browse files Browse the repository at this point in the history
Feature/integration test
  • Loading branch information
enzoftware authored Jun 17, 2019
2 parents 0abeb05 + 1eaca77 commit 5a24c71
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserService {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.proyection.projection.Integration.Suite;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources",
glue = {"io.proyection.projection.Integration.Test"},
plugin = {
"pretty",
"html:target/cucumber",
"json:target/cucumber.json",
"junit:target/cucumber_junit_report.xml"
}
)
public class ProjectionIntegrationSuite {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package io.proyection.projection.Integration.Test;

import static org.mockito.Mockito.doNothing;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.junit.Assert;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import io.proyection.projection.domain.Task;
import io.proyection.projection.service.TaskService;

public class TaskIntegrationTest {

private final TaskService taskService = new TaskService();
private static Task task = new Task();
private String mensaje = "";
private String nombreTask = "";

@Mock
private HttpServletResponse response;

@Given("^despues de iniciar sesion en la aplicacion$")
public void despues_de_iniciar_sesion_en_la_aplicacion() throws Throwable {
MockitoAnnotations.initMocks(this);
doNothing().when(response).sendRedirect("http://localhost:8080");
Assert.assertTrue(true);
}

@When("^hago click en el boton agregar tarea$")
public void hago_click_en_el_boton_agregar_tarea() throws Throwable {
MockitoAnnotations.initMocks(this);
doNothing().when(response).sendRedirect("http://localhost:8080/tasks");
Assert.assertTrue(true);
}

@When("^en la nueva pantalla escribo en el campo Nombre el valor de \"([^\"]*)\"$")
public void en_la_nueva_pantalla_escribo_en_el_campo_Nombre_el_valor_de(String arg1) throws Throwable {
nombreTask = arg1;
task.setSummary(nombreTask);
Assert.assertTrue(true); }

@When("^en la nueva pantalla escribo en el campo Descripcion el valor de \"([^\"]*)\"$")
public void en_la_nueva_pantalla_escribo_en_el_campo_Descripcion_el_valor_de(String arg1) throws Throwable {
nombreTask = arg1;
task.setAcceptanceCriteria(nombreTask);
Assert.assertTrue(true); }

@When("^en la nueva pantalla escribo en el campo Fecha Límite el valor de \"([^\"]*)\"$")
public void en_la_nueva_pantalla_escribo_en_el_campo_Fecha_Límite_el_valor_de(String arg1) throws Throwable {
try {
nombreTask = arg1;
Date date1=new SimpleDateFormat("dd/MM/yyyy").parse(nombreTask);
task.setLimitDate(date1);
} catch (Exception e) {
System.out.println("Error: "+e.getMessage());
}

}

@When("^presiono el boton de Guardar$")
public void presiono_el_boton_de_Guardar() throws Throwable {
try {
task = taskService.saveOrUpdateTask(task, "usuario");
mensaje = "Se creo correctamente la Tarea";
Assert.assertTrue(true);
} catch (Exception e) {
mensaje = "Error: " + e.getMessage();
Assert.fail(mensaje);
}
}

@Then("^el sistema me muestra el mensaje de: \"([^\"]*)\"$")
public void el_sistema_me_muestra_el_mensaje_de(String arg1) throws Throwable {
Assert.assertEquals(arg1, mensaje);
}

@When("^hago click sobre la tarea existente \"([^\"]*)\"$")
public void hago_click_sobre_la_tarea_existente(String arg1) throws Throwable {
Assert.assertTrue(true);
}

@When("^hago click en la opción actualizar tarea$")
public void hago_click_en_la_opciÃ_n_actualizar_tarea() throws Throwable {
try {
task.setDone(true);
Assert.assertTrue(true);
} catch (Exception e) {
System.out.print("Error actualizar: " + e.getMessage());
}

}

@When("^presiono el boton de Actualizar$")
public void presiono_el_boton_de_Actualizar() throws Throwable {
try {
taskService.saveOrUpdateTask(task, "usuario");
mensaje = "Se actualizo correctamente la Tarea";
Assert.assertTrue(true);
} catch (Exception e) {
mensaje = "Error: " + e.getMessage();
Assert.fail(mensaje);
}
}

@When("^se muestra la pantalla de inicio$")
public void se_muestra_la_pantalla_de_inicio() throws Throwable {
// Write code here that turns the phrase above into concrete actions

}

@Then("^el sistema me muestra un listado con las tareas existentes$")
public void el_sistema_me_muestra_un_listado_con_las_tareas_existentes() throws Throwable {
try {
List<Task> lista = (List<Task>) taskService.findAllTask(task.getUsername());
Assert.assertTrue(lista.size()>=0);
} catch (Exception e) {
System.out.print("Error actualizar: " + e.getMessage());
}

}

@When("^hago click en la opción eliminar tarea$")
public void hago_click_en_la_opciÃ_n_eliminar_tarea() throws Throwable {
try {
taskService.deleteTaskByIdentifier(task.getId(), task.getUsername());
mensaje = "Se elimino correctamente la Tarea";
Assert.assertTrue(true);
} catch (Exception e) {
mensaje = "Error: " + e.getMessage();
Assert.fail(mensaje);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package io.proyection.projection.Integration.Test;

import javax.servlet.http.HttpServletResponse;

import org.junit.Assert;
import org.mockito.Mock;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import io.proyection.projection.domain.User;
import io.proyection.projection.service.UserService;

public class UserIntegrationTest {

private final UserService userService = new UserService();
private static User user = new User();
private String mensaje = "";
private String nombre = "";

@Mock
private HttpServletResponse response;

@Given("^user name is \"([^\"]*)\"$")
public void user_name_is(String arg1) throws Throwable {
user.setUsername(nombre);
user.setPassword("test");
Assert.assertTrue(user.getUsername() == "");
}

@When("^post method save user is \"([^\"]*)\"$")
public void post_method_save_user_is(String arg1) throws Throwable {
try {
userService.saveUser(user);
mensaje = "name is compulsory";
Assert.assertTrue(true);
} catch (Exception e) {
System.out.println("Error: "+e.getMessage());
}
}

@Then("^the user recieves the message \"([^\"]*)\"$")
public void the_user_recieves_the_message(String arg1) throws Throwable {
Assert.assertTrue(mensaje == arg1);
}

@Given("^user password is \"([^\"]*)\"$")
public void user_password_is(String arg1) throws Throwable {
user.setPassword(nombre);
user.setUsername("test00");
Assert.assertTrue(user.getPassword() == "");
}

@When("^post method save users is \"([^\"]*)\"$")
public void post_method_save_users_is(String arg1) throws Throwable {
try {
userService.saveUser(user);
mensaje = "password is compulsory";
Assert.assertTrue(true);
} catch (Exception e) {
System.out.println("Error: "+e.getMessage());
}

}

@Then("^the user recieves the messagesito \"([^\"]*)\"$")
public void the_user_recieves_the_messagesito(String arg1) throws Throwable {
Assert.assertTrue(mensaje == arg1);
}
}
File renamed without changes.
File renamed without changes.

0 comments on commit 5a24c71

Please sign in to comment.