de.rahn.finances.server.web.config.HealthConfigurationTest.java Source code

Java tutorial

Introduction

Here is the source code for de.rahn.finances.server.web.config.HealthConfigurationTest.java

Source

/*
 * Copyright 2011-2016 Frank W. Rahn and the project authors.
 *
 * 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
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.rahn.finances.server.web.config;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import static org.springframework.http.HttpStatus.OK;

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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * Der Test zur Klasse {@link HealthConfiguration}.
 *
 * @author Frank W. Rahn
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SecuritiesManagementApplication.class, webEnvironment = RANDOM_PORT)
public class HealthConfigurationTest {

    @Autowired
    private TestRestTemplate testRestTemplate;

    /**
     * Teste die Health-Endpoints.
     */
    @Test
    public void testHealth() {
        ResponseEntity<String> answer = testRestTemplate.getForEntity("/manage/health", String.class);

        assertThat(answer.getStatusCode()).isEqualTo(OK);
        assertThat(answer.getBody()).contains("\"test\" : \"good\"");
    }

}