Skip to content

Commit

Permalink
Merge pull request #32 from s-chepurnov/test-utf8
Browse files Browse the repository at this point in the history
кодировка UTF-8 в тестах
  • Loading branch information
sgmdlt authored May 13, 2024
2 parents 3ee8c7e + ca60c18 commit d9c5518
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

Expand All @@ -20,12 +21,19 @@
import io.hexlet.blog.util.ModelGenerator;
import io.hexlet.blog.util.UserUtils;
import jakarta.transaction.Transactional;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import java.nio.charset.StandardCharsets;

@SpringBootTest
@Transactional
@AutoConfigureMockMvc
public class PostsCommentsControllerTest {

@Autowired
private WebApplicationContext wac;

@Autowired
private MockMvc mockMvc;

Expand All @@ -47,7 +55,13 @@ public class PostsCommentsControllerTest {

@BeforeEach
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac)
.defaultResponseCharacterEncoding(StandardCharsets.UTF_8)
.apply(springSecurity())
.build();

token = jwt().jwt(builder -> builder.subject("[email protected]"));

testPost = Instancio.of(modelGenerator.getPostModel())
.create();
testPost.setAuthor(userUtils.getTestUser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
Expand All @@ -29,11 +30,18 @@
import io.hexlet.blog.repository.PostRepository;
import io.hexlet.blog.util.ModelGenerator;
import io.hexlet.blog.util.UserUtils;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import java.nio.charset.StandardCharsets;

@SpringBootTest
@AutoConfigureMockMvc
public class PostsControllerTest {

@Autowired
private WebApplicationContext wac;

@Autowired
private MockMvc mockMvc;

Expand All @@ -58,7 +66,13 @@ public class PostsControllerTest {

@BeforeEach
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac)
.defaultResponseCharacterEncoding(StandardCharsets.UTF_8)
.apply(springSecurity())
.build();

token = jwt().jwt(builder -> builder.subject("[email protected]"));

testPost = Instancio.of(modelGenerator.getPostModel())
.create();
testPost.setAuthor(userUtils.getTestUser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;

import org.instancio.Instancio;
Expand All @@ -26,11 +28,16 @@
import io.hexlet.blog.repository.UserRepository;
import io.hexlet.blog.util.ModelGenerator;
import net.datafaker.Faker;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

@SpringBootTest
@AutoConfigureMockMvc
public class UsersControllerTest {

@Autowired
private WebApplicationContext wac;

@Autowired
private MockMvc mockMvc;

Expand All @@ -52,7 +59,13 @@ public class UsersControllerTest {

@BeforeEach
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac)
.defaultResponseCharacterEncoding(StandardCharsets.UTF_8)
.apply(springSecurity())
.build();

token = jwt().jwt(builder -> builder.subject("[email protected]"));

testUser = Instancio.of(modelGenerator.getUserModel())
.create();
userRepository.save(testUser);
Expand Down

0 comments on commit d9c5518

Please sign in to comment.