package woofworks.login;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.Assert;
import woofworks.BaseTest;
import woofworks.dto.LoginRequestDTO;
import woofworks.dto.LoginResponseDTO;
import woofworks.service.UserService;

import static com.google.common.base.Strings.isNullOrEmpty;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class LoginRestTest extends BaseTest {
	@Autowired
	private TestRestTemplate rest;

	@Autowired
	private UserService service;

	@Before
	public void init() {
		saveUser();
	}

	@Test
	public void successfulLoginTest() {
		LoginRequestDTO request = new LoginRequestDTO();
		request.username = "user";
		request.password = "password";

		ResponseEntity<LoginResponseDTO> res = rest.postForEntity("/login", request,
				LoginResponseDTO.class);

		assertIsEqual(HttpStatus.OK, res.getStatusCode());

		LoginResponseDTO dto = res.getBody();
		Assert.isTrue(isNullOrEmpty(dto.token) == false);
	}
}

@@ -1036,16 +1036,67 @@
 ();%0A%09%7D%0A%0A
+    /**%0A     * Test to log in successfully%0A     */%0A
 %09@Test%0A%09
@@ -1163,12 +1163,13 @@
 t = 
-new 
+build
 Logi
@@ -1180,75 +1180,10 @@
 uest
-DTO();%0A%09%09request.username = %22user%22;%0A%09%09request.password = %22password%22
+()
 ;%0A%0A%09
@@ -1438,11 +1438,751 @@
 lse);%0A%09%7D
+%0A%0A    /**%0A     * Checks that the JSON string is properly formatted and returned%0A     */%0A%09@Test%0A%09public void checkJsonStringTest() %7B%0A        LoginRequestDTO request = buildLoginRequest();%0A%0A        ResponseEntity%3CString%3E res = rest.postForEntity(%22/login%22, request,%0A                String.class);%0A%0A        assertIsEqual(HttpStatus.OK, res.getStatusCode());%0A%0A        String json = res.getBody();%0A%0A        Assert.isTrue(json.startsWith(%22%7B%5C%22token%5C%22:%5C%22%22));%0A    %7D%0A%0A    /**%0A     * Builds a login DTO request%0A     *%0A     * @return%0A     */%0A    private LoginRequestDTO buildLoginRequest() %7B%0A        LoginRequestDTO request = new LoginRequestDTO();%0A        request.username = %22user%22;%0A        request.password = %22password%22;%0A%0A        return request;%0A    %7D
 %0A%7D%0A

Test to check the login JSON string