package au.gov.ga.geodesy.port.adapter.rest;

import static io.restassured.module.mockmvc.RestAssuredMockMvc.given;

import org.springframework.http.HttpStatus;
import org.springframework.test.annotation.Rollback;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.fasterxml.jackson.databind.ObjectMapper;

import au.gov.ga.geodesy.domain.model.UserRegistration;

import io.restassured.module.mockmvc.RestAssuredMockMvc;

public class UserRegistrationRestITest extends RestTest {

    private ObjectMapper mapper = new ObjectMapper();

    @BeforeClass
    public void setup() {
        RestAssuredMockMvc.mockMvc(RestTest.mvc);
    }

    @Test
    @Rollback(false)
    public void createUserRegistration() throws Exception {
        given()
            .body(mapper.writeValueAsString(new UserRegistration(
                "Lazar",
                "Bodor",
                "Geoscience Australia",
                "Software developer",
                "lazar.bodor@ga.gov.au",
                "0451061798")))

            .when()
            .post("/userRegistrations")
            .then()
            .statusCode(HttpStatus.CREATED.value());
    }
}

@@ -106,24 +106,181 @@
 Mvc.given;%0A%0A
+import static org.hamcrest.Matchers.is;%0Aimport static org.hamcrest.MatcherAssert.assertThat;%0A%0Aimport org.springframework.beans.factory.annotation.Autowired;%0A
 import org.s
@@ -311,16 +311,16 @@
 Status;%0A
-
 import o
@@ -552,16 +552,88 @@
 tration;
+%0Aimport au.gov.ga.geodesy.port.adapter.mock.InMemoryNotificationAdapter;
 %0A%0Aimport
@@ -798,16 +798,93 @@
 per();%0A%0A
+    @Autowired%0A    private InMemoryNotificationAdapter notificationAdapter;%0A%0A
     @Bef
@@ -1066,16 +1066,92 @@
 ption %7B%0A
+%0A        assertThat(notificationAdapter.getNotifications().size(), is(0));%0A%0A
         
@@ -1502,24 +1502,24 @@
     .then()%0A
-
             
@@ -1558,16 +1558,203 @@
 alue());
+%0A%0A        assertThat(notificationAdapter.getNotifications().size(), is(1));%0A        assertThat(notificationAdapter.getNotifications().get(0).getSubject(), is(%22UserRegistrationReceived%22));
 %0A    %7D%0A%7D

Check user registration notification