package io.specto.hoverfly.junit.api;


import io.specto.hoverfly.junit.core.Hoverfly;
import io.specto.hoverfly.junit.core.HoverflyConfiguration;
import io.specto.hoverfly.junit.core.HoverflyMode;
import io.specto.hoverfly.junit.core.SimulationSource;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static io.specto.hoverfly.junit.core.HoverflyConfig.configs;
import static io.specto.hoverfly.junit.dsl.HoverflyDsl.service;
import static io.specto.hoverfly.junit.dsl.ResponseCreators.success;
import static org.assertj.core.api.Assertions.assertThat;

public class HoverflyClientTest {


    private Hoverfly hoverfly;
    private HoverflyConfiguration configuration;

    @Before
    public void setUp() throws Exception {
        hoverfly = new Hoverfly(HoverflyMode.SIMULATE);
        hoverfly.start();
        configuration = hoverfly.getHoverflyConfig();
    }

    @Test
    public void shouldBeAbleToCreateNewInstanceOfHoverflyClient() throws Exception {


        HoverflyClient hoverflyClient = HoverflyClient.newInstance()
                .port(configuration.getAdminPort())
                .build();

        assertThat(hoverflyClient.getHealth()).isTrue();
    }

    @Test
    public void shouldSupportDefaultConfigs() throws Exception {
        hoverfly.importSimulation(SimulationSource.dsl(
                service("http://localhost:8888")
                    .get("/api/health")
                    .willReturn(success())
        ));
        HoverflyClient hoverflyClient = HoverflyClient.newInstance().build();

        assertThat(hoverflyClient.getHealth()).isTrue();
    }

    @After
    public void tearDown() throws Exception {
        if (hoverfly != null) {

            hoverfly.close();
        }
    }
}
@@ -70,24 +70,17 @@
 it.core.
-Hoverfly
+*
 ;%0Aimport
@@ -84,164 +84,70 @@
 ort 
-io.specto.hoverfly.junit.core.HoverflyConfiguration;%0Aimport io.specto.hoverfly.junit.core.HoverflyMode;%0Aimport io.specto.hoverfly.junit.core.SimulationSourc
+org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Rul
 e;%0Ai
@@ -154,37 +154,36 @@
 mport org.junit.
-After
+Test
 ;%0Aimport org.jun
@@ -189,39 +189,123 @@
 nit.
-Before;%0Aimport org.junit.Test;%0A
+contrib.java.lang.system.EnvironmentVariables;%0A%0Aimport static io.specto.hoverfly.junit.core.HoverflyConfig.configs;
 %0Aimp
@@ -352,35 +352,36 @@
 .HoverflyCon
-fig.configs
+stants.HTTPS
 ;%0Aimport sta
@@ -679,16 +679,97 @@
 ation;%0A%0A
+    @Rule%0A    public EnvironmentVariables envVars = new EnvironmentVariables();%0A%0A
     @Bef
@@ -1303,50 +1303,128 @@
 ould
-SupportDefaultConfigs() throws Exception %7B
+BeAbleToCreateHoverflyClientWithAuthToken() throws Exception %7B%0A        envVars.set(%22HOVERFLY_AUTH_TOKEN%22, %22some-token%22);
 %0A   
@@ -1512,22 +1512,25 @@
 p://
-localhost:8888
+remote.host:12345
 %22)%0A 
@@ -1568,16 +1568,86 @@
 ealth%22)%0A
+                        .header(%22Authorization%22, %22Bearer some-token%22)%0A
         
@@ -1761,16 +1761,132 @@
 stance()
+%0A                .host(%22remote.host%22)%0A                .port(12345)%0A                .withAuthToken()%0A                
 .build()

Test hoverfly client with authentication token