runtheshow.resource.BootTests.java Source code

Java tutorial

Introduction

Here is the source code for runtheshow.resource.BootTests.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package runtheshow.resource;

/**
 *
 * @author maxime decalf
 */
import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.client.RestTemplate;
import runtheshow.resource.config.AppConfiguration;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = AppConfiguration.class)
@WebAppConfiguration
@IntegrationTest("server.port:0")
public class BootTests {

    @Value("${local.server.port}")
    private int port;

    private RestTemplate template = new TestRestTemplate();

    @Test
    public void resourceProtected() {
        ResponseEntity<String> response = template.getForEntity("http://localhost:" + port + "/user/current",
                String.class);
        assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
    }

}