JAVA-4011: Moved 1 article from spring-5-security to

spring-boot-security
This commit is contained in:
sampadawagde
2021-01-05 23:00:14 +05:30
parent f63058acb6
commit af51e73604
6 changed files with 0 additions and 0 deletions
@@ -0,0 +1,28 @@
package com.baeldung.securityprofile;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@WebMvcTest(value = EmployeeController.class)
@ActiveProfiles("test")
public class EmployeeControllerNoSecurityUnitTest {
@Autowired
private MockMvc mockMvc;
@Test
public void whenSecurityDisabled_shouldBeOk() throws Exception {
this.mockMvc.perform(get("/employees"))
.andExpect(status().isOk());
}
}
@@ -0,0 +1,28 @@
package com.baeldung.securityprofile;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@WebMvcTest(value = EmployeeController.class)
@ActiveProfiles("prod")
public class EmployeeControllerUnitTest {
@Autowired
private MockMvc mockMvc;
@Test
public void whenSecurityEnabled_shouldBeForbidden() throws Exception {
this.mockMvc.perform(get("/employees"))
.andExpect(status().isForbidden());
}
}