Commit c0ffd8dce261bbc71460da4fcbb729f045deb450

Authored by andre.guimaraes
2 parents 43f826f7 b2492581
Exists in master

Merge branch 'testes-automatizados'

@@ -177,8 +177,7 @@ @@ -177,8 +177,7 @@
177 <groupId>io.swagger</groupId> 177 <groupId>io.swagger</groupId>
178 <artifactId>swagger-annotations</artifactId> 178 <artifactId>swagger-annotations</artifactId>
179 <version>1.5.12</version> 179 <version>1.5.12</version>
180 - </dependency>  
181 - 180 + </dependency>
182 <dependency> 181 <dependency>
183 <groupId>io.swagger</groupId> 182 <groupId>io.swagger</groupId>
184 <artifactId>swagger-jaxrs</artifactId> 183 <artifactId>swagger-jaxrs</artifactId>
src/main/java/br/gov/ans/dao/DAO.java
@@ -79,8 +79,7 @@ public class DAO&lt;T&gt; implements Serializable{ @@ -79,8 +79,7 @@ public class DAO&lt;T&gt; implements Serializable{
79 79
80 return query; 80 return query;
81 } 81 }
82 -  
83 - 82 +
84 @Transactional 83 @Transactional
85 @SuppressWarnings("unchecked") 84 @SuppressWarnings("unchecked")
86 public List<T> getPaginatedResultList(int first, int pageSize) { 85 public List<T> getPaginatedResultList(int first, int pageSize) {
src/test/java/br/gov/ans/templates/teste/BaseTest.java 0 → 100644
@@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
  1 +package br.gov.ans.templates.teste;
  2 +
  3 +
  4 +import org.junit.BeforeClass;
  5 +
  6 +import com.jayway.restassured.RestAssured;
  7 +
  8 +public class BaseTest {
  9 +
  10 + protected static final String USUARIO = "teste-rest-assured";
  11 + protected static final String SENHA = "assured-testes";
  12 + protected static final String HOST = "http://ansdsjboss01";
  13 + protected static final int PORTA = 80;
  14 +
  15 + @BeforeClass
  16 + public static void setup() {
  17 + RestAssured.baseURI = HOST;
  18 + RestAssured.port = PORTA;
  19 + RestAssured.basePath = "/templates-broker/service/";
  20 + }
  21 +
  22 +}
src/test/java/br/gov/ans/templates/teste/FunctionalTest.java
@@ -1,42 +0,0 @@ @@ -1,42 +0,0 @@
1 -package br.gov.ans.templates.teste;  
2 -  
3 -  
4 -import org.junit.BeforeClass;  
5 -  
6 -import com.jayway.restassured.RestAssured;  
7 -  
8 -public class FunctionalTest {  
9 -  
10 - protected final String USUARIO = "andre.guimaraes";  
11 - protected final String SENHA = "1qaz2wsx";  
12 - protected static final Boolean DESENVOLVIMENTO = true;  
13 -  
14 - @BeforeClass  
15 - public static void setup() {  
16 - if(DESENVOLVIMENTO){  
17 - String port = System.getProperty("server.port");  
18 - if (port == null) {  
19 - RestAssured.port = Integer.valueOf(8080);  
20 - } else {  
21 - RestAssured.port = Integer.valueOf(port);  
22 - }  
23 - }  
24 -  
25 - String basePath = System.getProperty("server.base");  
26 - if(basePath==null){  
27 - basePath = "/templates-broker/service/";  
28 - }  
29 - RestAssured.basePath = basePath;  
30 -  
31 - String baseHost = System.getProperty("server.host");  
32 - if(baseHost==null){  
33 - if(DESENVOLVIMENTO){  
34 - baseHost = "http://localhost";  
35 - }else{  
36 -// baseHost = "http://ansprwww02.ans.gov.br";  
37 - }  
38 - }  
39 - RestAssured.baseURI = baseHost;  
40 -  
41 - }  
42 -}  
src/test/java/br/gov/ans/templates/teste/TemplateTest.java 0 → 100644
@@ -0,0 +1,116 @@ @@ -0,0 +1,116 @@
  1 +package br.gov.ans.templates.teste;
  2 +
  3 +
  4 +import static com.jayway.restassured.RestAssured.given;
  5 +
  6 +import java.time.LocalDateTime;
  7 +
  8 +import org.junit.FixMethodOrder;
  9 +import org.junit.Test;
  10 +import org.junit.runners.MethodSorters;
  11 +
  12 +import br.gov.ans.templates.to.Template;
  13 +
  14 +@FixMethodOrder(MethodSorters.NAME_ASCENDING)
  15 +public class TemplateTest extends BaseTest{
  16 +
  17 + private static final String nomeTemplate = "teste-auto-" + LocalDateTime.now();
  18 +
  19 + @Test
  20 + public void A_deveIncluirTemplate(){
  21 + Template template = new Template();
  22 +
  23 + template.setNome(nomeTemplate);
  24 + template.setDescricao("Teste automatizado realizado pelo REST Assured.");
  25 + template.setResponsavel("teste-rest-assured");
  26 + template.setExemplo("Não há");
  27 + template.setCorpo("<html><body><h1>TESTE AUTOMATIZADO!</h1></body></html>");
  28 +
  29 + given()
  30 + .auth()
  31 + .basic(USUARIO, SENHA)
  32 + .contentType("application/json")
  33 + .body(template)
  34 + .expect()
  35 + .statusCode(201)
  36 + .when()
  37 + .post("/templates");
  38 + }
  39 +
  40 + @Test
  41 + public void B_deveListarTemplates(){
  42 + given()
  43 + .auth()
  44 + .basic(USUARIO, SENHA)
  45 + .expect()
  46 + .statusCode(200)
  47 + .when()
  48 + .get("/templates");
  49 + }
  50 +
  51 + @Test
  52 + public void C_deveConsultarTemplate(){
  53 + given()
  54 + .auth()
  55 + .basic(USUARIO, SENHA)
  56 + .expect()
  57 + .statusCode(200)
  58 + .when()
  59 + .get("/templates/" + nomeTemplate);
  60 + }
  61 +
  62 + @Test
  63 + public void D_deveRetornarCorpoTemplate(){
  64 + given()
  65 + .auth()
  66 + .basic(USUARIO, SENHA)
  67 + .expect()
  68 + .statusCode(200)
  69 + .when()
  70 + .get("/templates/" + nomeTemplate + "/corpo");
  71 + }
  72 +
  73 + @Test
  74 + public void E_deveAtualizarTemplate(){
  75 + Template template = new Template();
  76 +
  77 + template.setNome(nomeTemplate);
  78 + template.setDescricao("Teste automatizado de edição realizado pelo REST Assured.");
  79 + template.setResponsavel("teste-rest-assured");
  80 + template.setExemplo("Não há");
  81 + template.setCorpo("<html><body><h1>TESTE AUTOMATIZADO DE EDIÇÃO!</h1></body></html>");
  82 +
  83 + given()
  84 + .auth()
  85 + .basic(USUARIO, SENHA)
  86 + .contentType("application/json")
  87 + .body(template)
  88 + .expect()
  89 + .statusCode(200)
  90 + .when()
  91 + .put("/templates/" + nomeTemplate);
  92 + }
  93 +
  94 + @Test
  95 + public void F_deveListarVersoesTemplate(){
  96 + given()
  97 + .auth()
  98 + .basic(USUARIO, SENHA)
  99 + .expect()
  100 + .statusCode(200)
  101 + .when()
  102 + .get("/templates/" + nomeTemplate + "/versoes");
  103 + }
  104 +
  105 + @Test
  106 + public void G_deveExcluirTemplate(){
  107 + given()
  108 + .auth()
  109 + .basic(USUARIO, SENHA)
  110 + .expect()
  111 + .statusCode(200)
  112 + .when()
  113 + .delete("/templates/" + nomeTemplate);
  114 + }
  115 +
  116 + }
src/test/java/br/gov/ans/templates/teste/TemplatesTest.java
@@ -1,62 +0,0 @@ @@ -1,62 +0,0 @@
1 -package br.gov.ans.templates.teste;  
2 -  
3 -  
4 -import static com.jayway.restassured.RestAssured.given;  
5 -  
6 -import java.io.File;  
7 -import java.io.FileInputStream;  
8 -  
9 -import org.junit.FixMethodOrder;  
10 -import org.junit.Test;  
11 -import org.junit.runners.MethodSorters;  
12 -  
13 -import br.gov.ans.templates.to.Template;  
14 -  
15 -import com.jayway.restassured.response.Response;  
16 -  
17 -@FixMethodOrder(MethodSorters.NAME_ASCENDING)  
18 -public class TemplatesTest extends FunctionalTest{  
19 -  
20 -// @Test  
21 - public void AA_incluirTemplateTest(){  
22 - Response response = given()  
23 - .auth()  
24 - .basic(USUARIO, SENHA)  
25 - .contentType("application/json")  
26 - .body(buildTemplate("gear-nota-gefap-deferimento.mustache"))  
27 - .when().post("/templates");  
28 -  
29 -// processoCriado = response.getBody().as(RetornoGeracaoProcedimento.class).getProcedimentoFormatado().replaceAll("[^0-9+]", "");  
30 -  
31 - response.then().statusCode(201);  
32 - }  
33 -  
34 - public Template buildTemplate(String arquivo){  
35 - Template template = new Template();  
36 -  
37 - template.setNome("gear-nota-gefap-deferimento");  
38 - template.setDescricao("Notas Técnicas de Deferimento antes e depois do Reajuste do sistema GEAR.");  
39 - template.setResponsavel("cristiano.rocha");  
40 - template.setExemplo("Não informado");  
41 - template.setCorpo(new String(readFile(arquivo)));  
42 -  
43 - return template;  
44 - }  
45 -  
46 - public byte[] readFile(String nome){  
47 - ClassLoader classLoader = getClass().getClassLoader();  
48 -  
49 - File file = new File(classLoader.getResource(nome).getFile());  
50 -  
51 - byte[] bytes = new byte[(int) file.length()];  
52 -  
53 - try {  
54 - FileInputStream fileInputStream = new FileInputStream(file);  
55 - fileInputStream.read(bytes);  
56 - } catch (Exception e) {  
57 - e.printStackTrace();  
58 - }  
59 -  
60 - return bytes;  
61 - }  
62 - }