package org.zalando.putittorest;

import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.stereotype.Component;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.client.RestTemplate;
import org.zalando.putittorest.annotation.RestClient;
import org.zalando.riptide.AsyncRest;
import org.zalando.riptide.Rest;
import org.zalando.stups.oauth2.spring.client.StupsOAuth2RestTemplate;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(DefaultTestConfiguration.class)
@TestPropertySource(properties = {
        "rest.clients.example.timeouts.connect: 2",
        "rest.clients.example.timeouts.read: 3",
})
@Component
public class RestClientAnnotationConfigurationTest {

    @RestClient("example")
    private Rest exampleRest;

    @RestClient("example")
    private RestTemplate exampleRestTemplate;

    @RestClient("example")
    private AsyncRest exampleAsync;

    @RestClient("example")
    private AsyncRest exampleAsyncRestTemplate;

    @RestClient("ecb")
    private Rest ecbRest;

    @RestClient("ecb")
    private RestTemplate ecbRestTemplate;

    @RestClient("ecb")
    private AsyncRest ecbAsync;

    @RestClient("ecb")
    private AsyncRest ecbAsyncRestTemplate;

    @Test
    public void shouldWireOAuthCorrectly() {
        assertThat(exampleRest, is(notNullValue()));
        assertThat(exampleRestTemplate, is(instanceOf(StupsOAuth2RestTemplate.class)));
        assertThat(exampleAsync, is(notNullValue()));
        assertThat(exampleAsyncRestTemplate, is(notNullValue()));
    }

    @Test
    public void shouldWireNonOAuthCorrectly() {
        assertThat(ecbRest, is(notNullValue()));
        assertThat(ecbRestTemplate, is(instanceOf(RestTemplate.class)));
        assertThat(ecbRestTemplate, is(not(instanceOf(StupsOAuth2RestTemplate.class))));
        assertThat(ecbAsync, is(notNullValue()));
        assertThat(ecbAsyncRestTemplate, is(notNullValue()));

    }
}

@@ -379,117 +379,8 @@
 on;%0A
-import org.springframework.stereotype.Component;%0Aimport org.springframework.test.context.TestPropertySource;%0A
 impo
@@ -804,158 +804,8 @@
 ss)%0A
-@TestPropertySource(properties = %7B%0A        %22rest.clients.example.timeouts.connect: 2%22,%0A        %22rest.clients.example.timeouts.read: 3%22,%0A%7D)%0A@Component%0A
 publ

remove annotations not needed for testing