-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added public get accommodation endpoints
- Loading branch information
1 parent
fe2a43e
commit 17ebf64
Showing
2 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/test/java/org/example/bookingappliation/controller/AccommodationControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.example.bookingappliation.controller; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import javax.sql.DataSource; | ||
import lombok.SneakyThrows; | ||
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.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.jdbc.datasource.init.ScriptUtils; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
class AccommodationControllerTest { | ||
private static final String ADD_THREE_ACCOMMODATIONS | ||
= "database/accommodations/insert-accommodations.sql"; | ||
private static final String ADD_TEST_USER | ||
= "database/users/insert-users.sql"; | ||
private static final String ADD_TEST_BOOKING | ||
= "database/bookings/insert-booking.sql"; | ||
private static final String DELETE_DATA | ||
= "database/deletes/delete-users-accommodations-bookings-addresses.sql"; | ||
private static MockMvc mockMvc; | ||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@BeforeAll | ||
static void beforeAll(@Autowired WebApplicationContext applicationContext, | ||
@Autowired DataSource dataSource) { | ||
teardown(dataSource); | ||
mockMvc = MockMvcBuilders | ||
.webAppContextSetup(applicationContext) | ||
.apply(springSecurity()) | ||
.build(); | ||
} | ||
|
||
@BeforeEach | ||
void setUp(@Autowired DataSource dataSource) throws SQLException { | ||
teardown(dataSource); | ||
try (Connection connection = dataSource.getConnection()) { | ||
connection.setAutoCommit(true); | ||
ScriptUtils.executeSqlScript(connection, | ||
new ClassPathResource(ADD_THREE_ACCOMMODATIONS)); | ||
ScriptUtils.executeSqlScript(connection, | ||
new ClassPathResource(ADD_TEST_USER)); | ||
ScriptUtils.executeSqlScript(connection, | ||
new ClassPathResource(ADD_TEST_BOOKING)); | ||
} | ||
} | ||
|
||
@Test | ||
void name() { | ||
assertEquals(true, true); | ||
} | ||
|
||
@AfterEach | ||
void tearDown(@Autowired DataSource dataSource) { | ||
teardown(dataSource); | ||
} | ||
|
||
@AfterAll | ||
static void afterAll(@Autowired DataSource dataSource) { | ||
teardown(dataSource); | ||
} | ||
|
||
@SneakyThrows | ||
static void teardown(DataSource dataSource) { | ||
try (Connection connection = dataSource.getConnection()) { | ||
connection.setAutoCommit(true); | ||
ScriptUtils.executeSqlScript(connection, | ||
new ClassPathResource(DELETE_DATA)); | ||
} | ||
} | ||
} |