2017-11-17 19:41:59 +01:00
|
|
|
package com.baeldung.security;
|
|
|
|
|
|
|
|
import com.baeldung.SpringSecurity5Application;
|
|
|
|
import org.junit.Before;
|
2018-06-05 17:05:55 +05:30
|
|
|
import org.junit.Ignore;
|
2017-11-17 19:41:59 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
import org.springframework.security.test.context.support.WithMockUser;
|
|
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
import org.springframework.test.web.reactive.server.WebTestClient;
|
|
|
|
|
|
|
|
@RunWith(SpringRunner.class)
|
|
|
|
@ContextConfiguration(classes = SpringSecurity5Application.class)
|
2018-03-04 17:52:56 +02:00
|
|
|
public class SecurityIntegrationTest {
|
2017-11-17 19:41:59 +01:00
|
|
|
|
|
|
|
@Autowired
|
|
|
|
ApplicationContext context;
|
|
|
|
|
|
|
|
private WebTestClient rest;
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setup() {
|
2018-03-04 17:52:56 +02:00
|
|
|
this.rest = WebTestClient.bindToApplicationContext(this.context).configureClient().build();
|
2017-11-17 19:41:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void whenNoCredentials_thenRedirectToLogin() {
|
2018-03-04 17:52:56 +02:00
|
|
|
this.rest.get().uri("/").exchange().expectStatus().is3xxRedirection();
|
2017-11-17 19:41:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2018-06-05 17:05:55 +05:30
|
|
|
@Ignore
|
2017-11-17 19:41:59 +01:00
|
|
|
@WithMockUser
|
|
|
|
public void whenHasCredentials_thenSeesGreeting() {
|
2018-03-04 17:52:56 +02:00
|
|
|
this.rest.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("Hello, user");
|
2017-11-17 19:41:59 +01:00
|
|
|
}
|
|
|
|
}
|