package com.aemreunal.controller;

import org.junit.Test;
import com.aemreunal.domain.user.UserCreator;
import com.aemreunal.domain.user.UserGetter;
import com.aemreunal.domain.user.UserInfo;
import com.aemreunal.domain.user.UserRemover;

import static org.junit.Assert.assertTrue;

/*
 ***************************
 * Copyright (c) 2014      *
 *                         *
 * This code belongs to:   *
 *                         *
 * @author Ahmet Emre Ünal *
 * S001974                 *
 *                         *
 * aemreunal@gmail.com     *
 * emre.unal@ozu.edu.tr    *
 *                         *
 * aemreunal.com           *
 ***************************
 */

/*
 * https://code.google.com/p/rest-assured/
 *
 * Documentation: http://code.google.com/p/rest-assured/wiki/Usage
 */

public class UserTest {
    @Test
    public void testCreateUser() {
        UserInfo userInfo = UserCreator.createRandomUser();
        System.out.println(userInfo);
    }

    @Test
    public void testGetUser() {
        UserInfo createdUserInfo = UserCreator.createRandomUser();
        // TODO add expected status code for 404 not found assertion post-delete
        UserInfo requestedUserInfo = UserGetter.getUser(createdUserInfo.username);
        assertTrue("The created and requested objects do not match!", createdUserInfo.equals(requestedUserInfo));
    }

    @Test
    public void testDeleteUser() {
        UserInfo createdUserInfo = UserCreator.createRandomUser();
        UserRemover.removeUser(createdUserInfo.username);
        UserGetter.failToFindUser(createdUserInfo.username);
        UserRemover.failToRemoveUser(createdUserInfo.username);
    }

    @Test
    public void testFailToGetUserWithValidUsername() {
        UserGetter.failToFindUser("nonExistantUser");
    }

    @Test
    public void testFailToGetUserWithInvalidUsername() {
        UserGetter.failToGetUser("nönğüiasdşe-g");
    }

    @Test
    public void testFailToCreateUserWithSameUsername() {
        UserInfo createdUserInfo = UserCreator.createRandomUser();
        UserCreator.failToCreateUser(createdUserInfo.username);
    }

    @Test
    public void testFailToCreateUserDueToLongUsername() {
        UserCreator.failToCreateUser("aUsernameWithMoreThanTheMaximumNumberOfCharactersAllowedForTheField");
    }

    @Test
    public void testFailToCreateUserDueToSpaceInUsername() {
        UserCreator.failToCreateUser("Hello world!");
    }

    @Test
    public void testFailToCreateUserDueToIllegalUsername() {
        UserCreator.failToCreateUser("HelloWorld!");
        UserCreator.failToCreateUser("Hellö");
        UserCreator.failToCreateUser("Héllo");
        UserCreator.failToCreateUser("HşiğüçöıWOrlasda");
        UserCreator.failToCreateUser("123Hello");
        UserCreator.failToCreateUser("123 Hello");
    }
}

@@ -806,16 +806,136 @@
 rTest %7B%0A
+%0A    public static final String LONG_USERNAME = %22aUsernameWithMoreThanTheMaximumNumberOfCharactersAllowedForTheField%22;%0A%0A
     @Tes
@@ -2012,30 +2012,218 @@
 iasd%C5%9Fe-g%22);%0A
+        UserGetter.failToGetUser(%22Hello world%22);%0A        UserGetter.failToGetUser(%22Hello!%22);%0A        UserGetter.failToGetUser(%22w%C3%B6rldais%22);%0A        UserGetter.failToGetUser(LONG_USERNAME);%0A
     %7D%0A
-
 %0A    @Test%0A 
@@ -2420,324 +2420,8 @@
  %7D%0A%0A
-    @Test%0A    public void testFailToCreateUserDueToLongUsername() %7B%0A        UserCreator.failToCreateUser(%22aUsernameWithMoreThanTheMaximumNumberOfCharactersAllowedForTheField%22);%0A    %7D%0A%0A    @Test%0A    public void testFailToCreateUserDueToSpaceInUsername() %7B%0A        UserCreator.failToCreateUser(%22Hello world!%22);%0A    %7D%0A%0A
     
@@ -2738,24 +2738,24 @@
 123Hello%22);%0A
-
         User
@@ -2789,20 +2789,127 @@
 23 Hello%22);%0A
+        UserCreator.failToCreateUser(%22Hello world!%22);%0A        UserCreator.failToCreateUser(LONG_USERNAME);%0A
     %7D%0A%7D%0A

Refactor user tests