java-tutorials/spring-5/src/test/java/com/baeldung/security/SecurityIntegrationTest.java
Amit Pandey 2e683411e2 Bael 4461 2 (#4409)
* Deleted md file as a conflict

* [BAEL-4461] - Fixed PMD violation

* [BAEL-4461] - Fixed PMD violation

* [BAEL-4461] - Ignore empty TC

* Fix Spring 5 tests
2018-06-05 13:35:55 +02:00

41 lines
1.3 KiB
Java

package com.baeldung.security;
import com.baeldung.SpringSecurity5Application;
import org.junit.Before;
import org.junit.Ignore;
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)
public class SecurityIntegrationTest {
@Autowired
ApplicationContext context;
private WebTestClient rest;
@Before
public void setup() {
this.rest = WebTestClient.bindToApplicationContext(this.context).configureClient().build();
}
@Test
public void whenNoCredentials_thenRedirectToLogin() {
this.rest.get().uri("/").exchange().expectStatus().is3xxRedirection();
}
@Test
@Ignore
@WithMockUser
public void whenHasCredentials_thenSeesGreeting() {
this.rest.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("Hello, user");
}
}