Newer
Older
task-bldg / src / test / java / osm / surveyor / task / plateau / PlateauControllerTest.java
@haya4 haya4 16 days ago 1 KB Plateau API test
package osm.surveyor.task.plateau;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Files;
import java.nio.file.Path;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.util.FileSystemUtils;


@SpringBootTest
@AutoConfigureMockMvc
class PlateauControllerTest {
	
	@Autowired
	private final String rootUrl = "/plateau";
	private static final String dirStr = "plateau-data";		// task-bldg.plateau.dir=plateau-data

	@BeforeAll
	static void setUpBeforeClass() throws Exception {
		Path dir = Path.of(dirStr);
		FileSystemUtils.deleteRecursively(dir);
	}

	@AfterAll
	static void tearDownAfterClass() throws Exception {
	}

	@BeforeEach
	void setUp() throws Exception {
	}

	@AfterEach
	void tearDown() throws Exception {
	}
	
	@Test
    @DisplayName("'./plateau/01100' is Sapporo 2020")
	void testGetPlateau(@Autowired MockMvc mvc) throws Exception {
		mvc.perform(
                MockMvcRequestBuilders.get(rootUrl+"/01100"))
                .andExpect(MockMvcResultMatchers.status().isOk())
                .andExpect(MockMvcResultMatchers.content().string("HelloWorld"));
        
		Path base = Path.of(dirStr);
		boolean exists = Files.exists(base);
		assertTrue(exists);
	}
}