package org.fedorahosted.flies.core.rest;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.notNullValue;
import static org.testng.Assert.fail;

import java.net.URI;

import org.fedorahosted.flies.rest.client.ProjectResource;
import org.fedorahosted.flies.rest.dto.Project;
import org.fedorahosted.flies.rest.dto.ProjectRefs;
import org.jboss.resteasy.client.ClientRequestFactory;
import org.jboss.resteasy.client.ClientResponse;
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.seam.mock.SeamTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

@Test(groups={"seam-tests"})
public class ProjectServiceSeamTest extends SeamTest {

	ClientRequestFactory clientRequestFactory;
	ProjectResource projectService;
	
	@BeforeClass
	public void prepareRestEasyClientFramework() throws Exception {

		ResteasyProviderFactory instance = ResteasyProviderFactory.getInstance();
		RegisterBuiltin.register(instance);

		clientRequestFactory = 
			new ClientRequestFactory(
					new SeamMockClientExecutor(this), new URI("/restv1/"));

		projectService = clientRequestFactory.createProxy(ProjectResource.class);
	
	}
	

	public void retrieveListofProjects() throws Exception{

		ClientResponse<ProjectRefs> response = projectService.getProjects();
		
		assertThat( response.getStatus(), is(200) );
		assertThat( response.getEntity(), notNullValue() );
		assertThat( response.getEntity().getProjects().size(), is(1) );

	}


	public void retrieveNonExistingProject(){

		ClientResponse<Project> response = projectService.getProject("invalid-project");
		assertThat( response.getStatus(), is(404) );
	}

	public void retrieveExistingProject(){

		ClientResponse<Project> response = projectService.getProject("sample-project");
		assertThat( response.getStatus(), lessThan(400) );
	}
	
	public void createProject(){
		fail("Not implemented");
	}
	
	public void createProjectThatAlreadyExists(){
		fail("Not implemented");
	}

	public void createProjectWithInvalidData(){
		fail("Not implemented");
	}

	public void updateProjectWithInvalidData() {
		fail("Not implemented");
	}

	public void updateProject() {
		fail("Not implemented");
	}
	
	public void deleteProject(){
		fail("Not implemented");
	}
	
	public void deleteProjectThatDoesNotExist(){
		fail("Not implemented");
	}
}
@@ -286,16 +286,92 @@
 t.URI;%0A%0A
+import javax.ws.rs.core.Response;%0Aimport javax.ws.rs.core.Response.Status;%0A%0A
 import o
@@ -2075,25 +2075,24 @@
 (400) );%0A%09%7D%0A
-%09
 %0A%09public voi
@@ -2116,33 +2116,233 @@
 %7B%0A%09%09
-fail(%22Not implemented%22
+Project project = new Project(%22my-new-project%22, %22My New Project%22, %22Another test project%22);%0A%09%09Response response = projectService.addProject(project);%0A%09%09%0A%09%09assertThat( response.getStatus(), is( Status.CREATED.getStatusCode())
 );
-%0A
 %09%7D%0A%09

add create project test implementation