Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete method #9

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
pipeline {
agent any
stages {
stage ('Build Backend') {
steps {
bat 'mvn clean package -DskipTests=true'
}
}
stage ('Unit Tests') {
steps {
bat 'mvn test'
}
}
stage ('Deploy Backend') {
steps {
deploy adapters: [tomcat8(credentialsId: 'TomcatLogin', path: '', url: 'http://localhost:8001/')], contextPath: 'tasks-backend', war: 'target/tasks-backend.war'
}
}
stage ('API Tests') {
steps {
dir('api-tests'){
git credentialsId: 'GitHubLogin', url: 'https://github.com/elyfranmedeiros/tasks-api-test'
bat 'mvn test'
}
}
}
stage ('Deploy Frontend') {
steps {
dir('frontend') {
git credentialsId: 'GitHubLogin', url: 'https://github.com/elyfranmedeiros/tasks-frontend'
bat 'mvn clean package'
deploy adapters: [tomcat8(credentialsId: 'TomcatLogin', path: '', url: 'http://localhost:8001/')], contextPath: 'tasks', war: 'target/tasks.war'
}
}
}
stage ('Functional Tests') {
steps {
dir('functional-tests'){
git credentialsId: 'GitHubLogin', url: 'https://github.com/elyfranmedeiros/tasks-functional-tests'
bat 'mvn test'
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import br.ce.wcaquino.taskbackend.model.Task;
Expand Down Expand Up @@ -42,4 +45,10 @@ public ResponseEntity<Task> save(@RequestBody Task todo) throws ValidationExcept
Task saved = todoRepo.save(todo);
return new ResponseEntity<Task>(saved, HttpStatus.CREATED);
}

@DeleteMapping(value = "/{id}")
@ResponseStatus(code = HttpStatus.NO_CONTENT)
public void delete(@PathVariable Long id) {
todoRepo.deleteById(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package br.ce.wcaquino.taskbackend.controller;

import static org.junit.Assert.*;

import java.time.LocalDate;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import br.ce.wcaquino.taskbackend.model.Task;
import br.ce.wcaquino.taskbackend.repo.TaskRepo;
import br.ce.wcaquino.taskbackend.utils.ValidationException;

public class TaskControllerTest {

@Mock
private TaskRepo todoRepo;

@InjectMocks
private TaskController controller;

private LocalDate date;
private Task task;

@Before
public void before() {
MockitoAnnotations.initMocks(this);
task = new Task();
}

@Test
public void testEmptyDescription() {
date = LocalDate.now();
task.setDueDate(date);
try {
controller.save(task);
Assert.fail("Não deveria chegar a esse ponto");
} catch (ValidationException e) {
assertEquals("Fill the task description", e.getMessage());
}
}

@Test
public void testEmptyDueDate() {
task.setTask("Desc");
try {
controller.save(task);
Assert.fail("Não deveria chegar a esse ponto");
} catch (ValidationException e) {
assertEquals("Fill the due date", e.getMessage());
}
}

@Test
public void testOldDate() {
date = LocalDate.of(2005, 10, 10);
task.setDueDate(date);
task.setTask("Desc");
try {
controller.save(task);
Assert.fail("Não deveria chegar a esse ponto");
} catch (ValidationException e) {
assertEquals("Due date must not be in past", e.getMessage());
}
}

@Test
public void testTaskSavedSuccessfully() throws ValidationException {
date = LocalDate.now();
task.setDueDate(date);
task.setTask("Desc");
controller.save(task);
Mockito.verify(todoRepo).save(task);
}

}
29 changes: 29 additions & 0 deletions src/test/java/br/ce/wcaquino/taskbackend/utils/DateUtilsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package br.ce.wcaquino.taskbackend.utils;

import static org.junit.Assert.*;

import java.time.LocalDate;

import org.junit.Test;

public class DateUtilsTest {

@Test
public void testFutureDate() {
LocalDate date = LocalDate.of(2030, 10, 12);
assertTrue(DateUtils.isEqualOrFutureDate(date));
}

@Test
public void testCurrentDate() {
LocalDate date = LocalDate.now();
assertTrue(DateUtils.isEqualOrFutureDate(date));
}

@Test
public void testOldDate() {
LocalDate date = LocalDate.of(2010, 10, 12);
assertFalse(DateUtils.isEqualOrFutureDate(date));
}

}