content: package io.reflectoring.coderadar.rest.project;
  
  import static io.reflectoring.coderadar.rest.JsonHelper.fromJson;
  import static io.reflectoring.coderadar.rest.ResultMatchers.containsResource;
  import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
  import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
  
  import io.reflectoring.coderadar.graph.projectadministration.domain.ProjectEntity;
  import io.reflectoring.coderadar.graph.projectadministration.project.repository.ProjectRepository;
  import io.reflectoring.coderadar.rest.ControllerTestTemplate;
  import io.reflectoring.coderadar.rest.domain.GetProjectResponse;
  import java.util.Date;
  import org.junit.jupiter.api.Assertions;
  import org.junit.jupiter.api.Test;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
  
  class GetProjectControllerIntegrationTest extends ControllerTestTemplate {
  
    @Autowired private ProjectRepository projectRepository;
  
    @Test
    void getProjectWithId() throws Exception {
  
      ProjectEntity testProject = new ProjectEntity();
      testProject.setVcsUrl("https://valid.url");
      testProject.setName("project");
      testProject.setVcsStart(new Date());
      testProject.setVcsUsername("testUser");
      testProject = projectRepository.save(testProject);
  
      mvc()
          .perform(get("/api/projects/" + testProject.getId()))
          .andExpect(status().isOk())
          .andExpect(containsResource(GetProjectResponse.class))
          .andDo(
              result -> {
                GetProjectResponse response =
                    fromJson(result.getResponse().getContentAsString(), GetProjectResponse.class);
                Assertions.assertEquals("project", response.getName());
              })
          .andDo(document("projects/get"));
    }
  
    @Test
    void getProjectWithIdThrowsErrorWhenProjectDoesNotExist() throws Exception {
      mvc()
          .perform(get("/api/projects/1"))
          .andExpect(status().isNotFound())
          .andExpect(
              MockMvcResultMatchers.jsonPath("errorMessage").value("Project with id 1 not found."));
    }
  }
  