Skip to content

Commit

Permalink
controller test
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavomcarmo committed Jan 1, 2025
1 parent c6e870b commit 3078842
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class BoletimDiarioTest {

@Autowired
ResourceLoader resourceLoader;
private ResourceLoader resourceLoader;

@Test
public void listarMedicoesTest() throws IOException {
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/br/com/esign/qualidadearsmac/ControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package br.com.esign.qualidadearsmac;

import java.io.IOException;
import java.nio.file.Files;

import org.json.JSONException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

@ContextConfiguration(classes = Application.class)
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class ControllerTest {

@LocalServerPort
private int port;

@Autowired
private TestRestTemplate restTemplate;

@Autowired
private ResourceLoader resourceLoader;

@Test
public void testBoletimEndpoint() throws IOException, JSONException {
Resource boletimResource = resourceLoader.getResource("classpath:boletim.json");
String expected = new String(Files.readAllBytes(boletimResource.getFile().toPath()));
String url = String.format("http://localhost:%s/boletim?data=26/12/2024", port);
String actual = restTemplate.getForObject(url, String.class);
JSONAssert.assertEquals(expected, actual, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class EstacoesGeoJsonTest {

@Autowired
ResourceLoader resourceLoader;
private ResourceLoader resourceLoader;

@Test
public void listarEstacoesTest() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class PrometheusTest {

@Autowired
ResourceLoader resourceLoader;
private ResourceLoader resourceLoader;

@Test
public void listMetricsTest() throws IOException {
Expand Down

0 comments on commit 3078842

Please sign in to comment.