Skip to content

Commit

Permalink
Added public get accommodation endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
IhorTrokhymchuk committed May 3, 2024
1 parent fe2a43e commit 17ebf64
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(
auth -> auth.requestMatchers("auth/**", "/error", "/swagger-ui**",
"payments/success/**", "payments/cancel/**", "types/**")
"payments/success/**", "payments/cancel/**", "types/**",
"accommodations**")
.permitAll()
.anyRequest()
.authenticated()
Expand Down
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));
}
}
}

0 comments on commit 17ebf64

Please sign in to comment.