package io.teiler.api.endpoint;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

import io.teiler.server.Tylr;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Tylr.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@TestPropertySource(properties = {"local.server.port=4567"})
@AutoConfigureTestDatabase
public class GroupEndpointTest {
    
    @LocalServerPort
    private int port;
    
    @Autowired
    private TestRestTemplate testRestTemplate;
    
    @Test
    public void shouldReturn401WhenViewingGroupWithoutValidUUID() {
        ResponseEntity<String> response = testRestTemplate.getForEntity("http://127.0.0.1:" + port + "/v1/group", String.class);
        Assert.assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
    }

}

@@ -176,16 +176,76 @@
 wired;%0D%0A
+import org.springframework.beans.factory.annotation.Value;%0D%0A
 import o
@@ -512,24 +512,114 @@
 tTemplate;%0D%0A
+import org.springframework.http.HttpEntity;%0D%0Aimport org.springframework.http.HttpMethod;%0D%0A
 import org.s
@@ -836,29 +836,139 @@
 ort 
-io.teiler.server.Tylr
+com.google.gson.Gson;%0D%0A%0D%0Aimport io.teiler.api.endpoint.util.Util;%0D%0Aimport io.teiler.server.Tylr;%0D%0Aimport io.teiler.server.dto.Group
 ;%0D%0A%0D
@@ -1275,24 +1275,82 @@
 ort;%0D%0A    %0D%0A
+    @Value(%22$%7Bserver.ip%7D%22)%0D%0A    private String ip;%0D%0A    %0D%0A
     @Autowir
@@ -1403,24 +1403,70 @@
 ate;%0D%0A    %0D%0A
+    @Autowired%0D%0A    private Util util;%0D%0A    %0D%0A
     @Test%0D%0A 
@@ -1617,26 +1617,708 @@
 p://
-127.0.0.1:%22 + p
+%22 + ip + %22:%22 + port + %22/v1/group%22, String.class);%0D%0A        Assert.assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());%0D%0A    %7D%0D%0A    %0D%0A    @Test%0D%0A    public void shouldReturn401WhenViewingGroupWithEmptyUUID() %7B%0D%0A        String url = %22http://%22 + ip + %22:%22 + util.getPort() + %22/v1/group%22;%0D%0A        HttpEntity entity = Util.getHttpEntityWithHeader(%22%22);%0D%0A        ResponseEntity%3CString%3E response = testRestTemplate.exchange(url, HttpMethod.GET, entity, String.class);%0D%0A        Assert.assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());%0D%0A    %7D%0D%0A%0D%0A    @Test%0D%0A    public void shouldReturn401WhenViewingGroupWithInvalidUUID() %7B%0D%0A        String url = %22http://%22 + ip + %22:%22 + util.getP
 ort
+()
  + %22
@@ -2331,100 +2331,813 @@
 oup%22
-, String.class);%0D%0A        Assert.assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCod
+;%0D%0A        HttpEntity entity = Util.getHttpEntityWithHeader(%22abcdef%22);%0D%0A        ResponseEntity%3CString%3E response = testRestTemplate.exchange(url, HttpMethod.GET, entity, String.class);%0D%0A        Assert.assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());%0D%0A    %7D%0D%0A%0D%0A    @Test%0D%0A    public void shouldReturnGroupNameWhenCreating() %7B%0D%0A        String url = %22http://%22 + ip + %22:%22 + util.getPort() + %22/v1/group%22;%0D%0A        String testString = %22Group Name%22;%0D%0A        Group testGroup = new Group(%22%22, testString);%0D%0A        Gson gson = new Gson();%0D%0A%0D%0A        ResponseEntity%3CString%3E response = testRestTemplate.postForEntity(url, gson.toJson(testGroup), String.class);%0D%0A        Group responseGroup = gson.fromJson(response.getBody(), Group.class);%0D%0A        Assert.assertEquals(testString, responseGroup.getNam
 e())

add moar unit tests