package com.dddsample.rds.e2e;

import io.restassured.RestAssured;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;

import static io.restassured.RestAssured.given;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = DEFINED_PORT)
public class InstancesApiTest {

    @LocalServerPort
    private int port;

    @Before
    public void setup() {
        RestAssured.baseURI  = "http://localhost";
        RestAssured.port     = port;
        RestAssured.basePath = "/";
    }

    @Test
    public void test__pet_website__is_running_ok() {
        given()
                .when().get("/")
                .then().statusCode(200);
    }

    @Test
    public void test__getPets_api__can__return_default_pets___by_direct_access_json_field() throws IOException {
        given()
                .when().get("/instances")
                .then().statusCode(200);
    }
}

@@ -60,16 +60,105 @@
 ssured;%0A
+import io.swagger.model.DBInstance;%0Aimport net.sf.json.JSON;%0Aimport org.json.JSONObject;%0A
 import o
@@ -174,16 +174,16 @@
 Before;%0A
-
 import o
@@ -568,16 +568,152 @@
 .given;%0A
+import static org.hamcrest.CoreMatchers.equalTo;%0Aimport static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.assertThat;%0A
 import s
@@ -1505,16 +1505,719 @@
 e(200);%0A
-
     %7D%0A
+    // run specific test:%3E%3E mvn -Dtest=*InstancesApiTest* clean test%0A    @Test%0A    public void should_able_to__create_instance_by_post() throws IOException %7B%0A        JSONObject request = new JSONObject()%0A                .put(%22instanceId%22,%22mybox%22)%0A                .put(%22engine%22,%22mysql%22)%0A                .put(%22instanceClass%22,%22t1.micro%22)%0A                .put(%22port%22,%229999%22)%0A                .put(%22availableZone%22,%22sz%22);%0A%0A%0A                given()%0A                    .contentType(%22application/json%22)%0A                    .body(request.toString())%0A                .when()%0A                    .post(%22/instances%22)%0A                .then()%0A                    .body(%22instance.instanceId%22, equalTo(%22mybox%22));%0A    %7D%0A%0A
 %7D%0A

add e2e test for instance creation