package com.aemreunal.controller;

import org.apache.http.HttpStatus;
import org.junit.Before;
import org.junit.Test;
import com.aemreunal.domain.project.ProjectCreator;
import com.aemreunal.domain.user.UserCreator;
import com.aemreunal.domain.user.UserInfo;
import com.aemreunal.domain.user.UserRemover;

/*
 ***************************
 * 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 T2ProjectTest {
    private UserInfo testUser;

    @Before
    public void createTestUser() {
        testUser = UserCreator.createRandomUser();
    }

    @Test
    public void testCreateProject() {
        ProjectCreator.createRandomProject(testUser.username);
    }

    @Test
    public void testCreateMultipleProjects1() {
        ProjectCreator.createRandomProject(testUser.username);
        ProjectCreator.createRandomProject(testUser.username);
        ProjectCreator.createRandomProject(testUser.username);
    }

    @Test
    public void testCreateMultipleProjects2() {
        ProjectCreator.createRandomProject(testUser.username);
        ProjectCreator.createRandomProject(testUser.username);
        ProjectCreator.createRandomProject(testUser.username);
        UserInfo otherTestUser = UserCreator.createRandomUser();
        ProjectCreator.createRandomProject(otherTestUser.username);
        ProjectCreator.createRandomProject(otherTestUser.username);
        ProjectCreator.createRandomProject(otherTestUser.username);
    }

    @Test
    public void failToCreateProjectDueToUser() {
        ProjectCreator.failToCreateProjectWithBadUsername("nonExistantUser", "test", "test", true);
        ProjectCreator.failToCreateProjectWithBadUsername("Invalid username", "test", "test", false);
        ProjectCreator.failToCreateProjectWithBadUsername("Invalidüşernamé", "test", "test", false);
        ProjectCreator.failToCreateProjectWithBadUsername("user!", "test", "test", false);
    }

    @Test
    public void failToCreateInvalidProjects() {
        ProjectCreator.failToCreateProject(testUser.username, T1UserTest.LONG_NAME, "test", HttpStatus.SC_BAD_REQUEST);
        ProjectCreator.failToCreateProject(testUser.username, "test", T1UserTest.LONG_NAME + T1UserTest.LONG_NAME + T1UserTest.LONG_NAME + T1UserTest.LONG_NAME, HttpStatus.SC_BAD_REQUEST);
        ProjectCreator.failToCreateProject(testUser.username, T1UserTest.LONG_NAME, T1UserTest.LONG_NAME + T1UserTest.LONG_NAME + T1UserTest.LONG_NAME + T1UserTest.LONG_NAME, HttpStatus.SC_BAD_REQUEST);
    }

    @Test
    public void failToCreateDeletedUserProject() {
        UserInfo otherTestUser = UserCreator.createRandomUser();
        ProjectCreator.createRandomProject(otherTestUser.username);
        ProjectCreator.createRandomProject(otherTestUser.username);
        UserRemover.removeUser(otherTestUser.username);
        ProjectCreator.failToCreateProjectWithBadUsername(otherTestUser.username, "test", "test", true);
        ProjectCreator.failToCreateProjectWithBadUsername(otherTestUser.username, "test", "test", true);
    }
}

@@ -28,16 +28,44 @@
 oller;%0A%0A
+import java.util.ArrayList;%0A
 import o
@@ -91,16 +91,16 @@
 Status;%0A
-
 import o
@@ -183,32 +183,132 @@
 ProjectCreator;%0A
+import com.aemreunal.domain.project.ProjectGetter;%0Aimport com.aemreunal.domain.project.ProjectInfo;%0A
 import com.aemre
@@ -427,16 +427,51 @@
 mover;%0A%0A
+import static org.junit.Assert.*;%0A%0A
 /*%0A ****
@@ -1156,29 +1156,25 @@
 public void 
-testC
+c
 reateProject
@@ -1266,37 +1266,33 @@
     public void 
-testC
+c
 reateMultiplePro
@@ -1528,13 +1528,9 @@
 oid 
-testC
+c
 reat
@@ -3587,11 +3587,449 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void getProjects() %7B%0A        ProjectInfo createdProject1 = ProjectCreator.createRandomProject(testUser.username);%0A        ProjectInfo createdProject2 = ProjectCreator.createRandomProject(testUser.username);%0A        ArrayList%3CProjectInfo%3E projects = ProjectGetter.getAllProjects(testUser.username);%0A        assertTrue(projects.contains(createdProject1));%0A        assertTrue(projects.contains(createdProject2));%0A    %7D
 %0A%7D%0A

Add test