[BAEL-9712] - Created spring-5-security-oauth module

This commit is contained in:
amit2103
2018-11-19 00:04:52 +05:30
parent 3237f36c2a
commit 96d121bcae
28 changed files with 114 additions and 18 deletions
@@ -1,56 +0,0 @@
package com.baeldung.oauth2extractors;
import com.baeldung.oauth2extractors.configuration.SecurityConfig;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import javax.servlet.Filter;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ExtractorsApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration(classes = {SecurityConfig.class})
@ActiveProfiles("oauth2-extractors-github")
public class ExtractorsUnitTest {
@Autowired
private WebApplicationContext context;
@Autowired
private Filter springSecurityFilterChain;
private MockMvc mvc;
@Before
public void setup() {
mvc = MockMvcBuilders
.webAppContextSetup(context)
.addFilters(springSecurityFilterChain)
.build();
}
@Test
public void contextLoads() throws Exception {
}
@Test
public void givenValidRequestWithoutAuthentication_shouldFailWith302() throws Exception {
mvc
.perform(get("/"))
.andExpect(status().isFound())
.andReturn();
}
}