AdminApplicationTest.java 2.51 KB
Newer Older
1
/*
Johannes Edmeier committed
2
 * Copyright 2014-2017 the original author or authors.
3 4 5 6 7
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
Johannes Edmeier committed
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9 10 11 12 13 14 15 16 17 18 19
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.codecentric.boot.admin.server;

import de.codecentric.boot.admin.server.config.EnableAdminServer;

20
import org.junit.After;
Johannes Edmeier committed
21 22
import org.junit.Before;
import org.springframework.boot.SpringBootConfiguration;
23
import org.springframework.boot.WebApplicationType;
24
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
25 26 27 28 29 30
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;
31

32
public class AdminApplicationTest extends AbstractAdminApplicationTest {
33
    private ConfigurableApplicationContext instance;
34

Johannes Edmeier committed
35
    @Before
36
    public void setUp() throws Exception {
37 38 39 40
        instance = new SpringApplicationBuilder().sources(TestAdminApplication.class)
                                                 .web(WebApplicationType.REACTIVE)
                                                 .run("--server.port=0", "--management.endpoints.web.base-path=/mgmt",
                                                         "--info.test=foobar", "--eureka.client.enabled=false");
41

42
        super.setUp(instance.getEnvironment().getProperty("local.server.port", Integer.class, 0));
Johannes Edmeier committed
43
    }
44

45 46 47
    @After
    public void shutdown() {
        instance.close();
Johannes Edmeier committed
48
    }
49 50

    @EnableAdminServer
Johannes Edmeier committed
51 52
    @EnableAutoConfiguration
    @SpringBootConfiguration
53
    @EnableWebFluxSecurity
54
    public static class TestAdminApplication {
55 56

        @Bean
57
        public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
58 59 60 61 62
            return http.authorizeExchange().anyExchange().permitAll()//
                       .and().csrf().disable()//
                       .build();
        }

63 64
    }
}