Skip to content

Commit

Permalink
#2 Crud de Cursos - Testes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhê Cardoso committed Feb 4, 2021
1 parent 0c5b21d commit 01b40bb
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .idea/hatcher-api.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@
<artifactId>hibernate-validator</artifactId>
<version>6.1.6.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ CREATE TABLE public.registration_course (
course_name varchar(100) NOT NULL,
description varchar NULL,
CONSTRAINT registration_course_pkey PRIMARY KEY (id)
);

INSERT INTO public.registration_course
(course_name, description)
VALUES('Sistemas', 'Description');
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.ayty.hatcher.api.v1.competence.service;

import org.assertj.core.api.Assertions;
import org.ayty.hatcher.api.v1.competence.dto.Course;
import org.ayty.hatcher.api.v1.competence.jpa.CourseRepository;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.persistence.GeneratedValue;
import javax.validation.ConstraintViolationException;

import java.util.List;

import static org.assertj.core.api.Assertions.*;


@RunWith(SpringRunner.class)
@DataJpaTest
public class CourseRepositoryTest {
@Autowired
private CourseRepository courseRepository;
@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void createShouldPersistData(){
Course course = new Course(null, "name", "desc");
this.courseRepository.save(course);
assertThat(course.getId()).isNotNull();
assertThat(course.getName()).isEqualTo("name");
assertThat(course.getDescription()).isEqualTo("desc");

}

@Test
public void deleteShouldRemoveData() {
Course course = new Course(null, "name", "desc");
this.courseRepository.save(course);
this.courseRepository.delete(course);
assertThat(courseRepository.findById(course.getId())).isEmpty();

}

@Test
public void updateShouldChangeAndPersistData(){
Course course = new Course(null, "name", "desc");
this.courseRepository.save(course);
course.setName("name2");
course.setDescription("Desc2");
this.courseRepository.save(course);
this.courseRepository.findById(course.getId());
assertThat(course.getId()).isNotNull();
assertThat(course.getName()).isEqualTo("name2");
assertThat(course.getDescription()).isEqualTo("Desc2");

}

@Test
public void nameNullShouldThrownConstraintViolationException(){
thrown.expect(ConstraintViolationException.class);
thrown.expectMessage("Não pode ser deixado vazio");
this.courseRepository.save(new Course());
}

}

0 comments on commit 01b40bb

Please sign in to comment.