Skip to content

Commit

Permalink
[ui, portfolio] integration tests for ProjectDetailsPageController
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichel35 committed Aug 6, 2015
1 parent a9716a3 commit 353b76f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class PortfolioPageController {

private static final String MANAGER_PAGE = "portfolio/manager"
private static final String PORTFOLIO_PAGE = "portfolio/portfolio"
private static final String REVISION_VIEW = "portfolio/revision"
private static final String MENU_PORTFOLIO = "portfolio"
private static final String MENU_PORTFOLIO_MANAGER = "portfolioManager"

Expand Down Expand Up @@ -101,8 +100,6 @@ class PortfolioPageController {
return model
}



private ModelAndView buildManagerViewData(ModelAndView model, Project project) {

def commits = revisionService.getHistory(project.id, project.class)
Expand All @@ -122,51 +119,4 @@ class PortfolioPageController {
return model
}

@RequestMapping("/ui/portfolio/manager/{projectKey}/revisions/{commitID}")
public ModelAndView getRevisionPage(@PathVariable projectKey, @PathVariable commitID) {

def project = findProjectOrFail(projectKey)

def commit = revisionService.findCommitByID(project.id, project.class, commitID)

if (commit == null) {
throw new InvalidCommitInformationException("No commit associated to this ID");
}

def previousCommit = revisionService.getPreviousCommit(project.id, project.class, commitID)

def version = revisionService.getSnapshot(commit)
def oldVersion = previousCommit != null ? revisionService.getSnapshot(previousCommit) : new Project(id: project.id)

def changes = revisionService.compare oldVersion, version

def model = new ModelAndView(REVISION_VIEW)
model.addObject "project", project
model.addObject "commit", commit
model.addObject "previousCommit", previousCommit
model.addObject "changes", changes

return model
}

private Project findProjectOrFail(String projectKey) {

def project = projectDAO.findByKey(projectKey)

if (project == null) {
throw new ProjectNotFoundException();
}

return project
}

@ResponseStatus(value=HttpStatus.NOT_FOUND)
@ExceptionHandler([
InvalidCommitInformationException.class,
ProjectNotFoundException.class
])
public void handlePageNotFoundException() {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import com.tocea.corolla.users.dto.UserDto
@Slf4j
public class ProjectDetailsPageController {

private static final String DETAILS_VIEW = "project/details"
private static final String DETAILS_VIEW = "project/details"
private static final String REVISION_VIEW = "portfolio/revision"

@Autowired
private IProjectDAO projectDAO;
Expand All @@ -59,6 +60,11 @@ public class ProjectDetailsPageController {

@Autowired
private Gate gate;

@ModelAttribute("menu")
public String setMenu() {
return "projectDetails"
}

@RequestMapping(value="/ui/projects/{projectKey}")
public ModelAndView getProjectDetails(@PathVariable projectKey) {
Expand All @@ -84,7 +90,6 @@ public class ProjectDetailsPageController {
}

if (_result.hasErrors()) {
log.info "error found in project data : {}", _result.fieldErrors;
def model = buildManagerViewData(new ModelAndView(DETAILS_VIEW), project)
model.addObject "selectedTab", "edit"
return model
Expand All @@ -96,6 +101,33 @@ public class ProjectDetailsPageController {

}

@RequestMapping("/ui/projects/{projectKey}/revisions/{commitID}")
public ModelAndView getRevisionPage(@PathVariable projectKey, @PathVariable commitID) {

def project = findProjectOrFail(projectKey)

def commit = revisionService.findCommitByID(project.id, project.class, commitID)

if (commit == null) {
throw new InvalidCommitInformationException("No commit associated to this ID");
}

def previousCommit = revisionService.getPreviousCommit(project.id, project.class, commitID)

def version = revisionService.getSnapshot(commit)
def oldVersion = previousCommit != null ? revisionService.getSnapshot(previousCommit) : new Project(id: project.id)

def changes = revisionService.compare oldVersion, version

def model = new ModelAndView(REVISION_VIEW)
model.addObject "project", project
model.addObject "commit", commit
model.addObject "previousCommit", previousCommit
model.addObject "changes", changes

return model
}

private ModelAndView buildManagerViewData(ModelAndView model, Project project) {

def commits = revisionService.getHistory(project.id, project.class)
Expand All @@ -105,7 +137,6 @@ public class ProjectDetailsPageController {
model.addObject "status", statusDAO.findOne(project.statusId)
model.addObject "category", project.categoryId ? projectCategoryDAO.findOne(project.categoryId) : null
model.addObject "owner", owner ? new UserDto(owner) : null
model.addObject "menu", "projectDetails"
model.addObject "folderNodeTypes", folderNodeTypeDAO.findAll()
model.addObject "branches", branchDAO.findByProjectId(project.id)
model.addObject "commits", commits
Expand All @@ -115,6 +146,17 @@ public class ProjectDetailsPageController {
return model
}

private Project findProjectOrFail(String projectKey) {

def project = projectDAO.findByKey(projectKey)

if (project == null) {
throw new ProjectNotFoundException();
}

return project
}

@ResponseStatus(value=HttpStatus.NOT_FOUND)
@ExceptionHandler([
InvalidCommitInformationException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
th:text="${commit.author}" /></td>
<td><a th:if="${commits[0].id} != ${commit.id}" href="#" class="label label-warning"
style="margin-right: 5px;"> Restore </a> <a
th:href="@{/ui/portfolio/manager/}+${project.key}+@{/revisions/}+${commit.id}" class="label label-primary">
th:href="@{/ui/projects/}+${project.key}+@{/revisions/}+${commit.id}" class="label label-primary">
Changelog </a></td>
</tr>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public void basicUserShouldNotAccessEditFormView() throws Exception {
@Test
public void adminShouldEditFolderType() throws Exception {

System.out.println("wtf existingType: "+existingType.getId()+ " - "+existingType.getName());
mvc
.perform(
post("/ui/admin/folder-node-types/edit/"+existingType.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrlPattern;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.Collection;

import javax.servlet.Filter;

import org.junit.Before;
Expand All @@ -22,7 +20,6 @@
import com.tocea.corolla.products.commands.CreateProjectStatusCommand;
import com.tocea.corolla.products.domain.Project;
import com.tocea.corolla.products.domain.ProjectStatus;
import com.tocea.corolla.revisions.domain.ICommit;
import com.tocea.corolla.revisions.services.IRevisionService;
import com.tocea.corolla.ui.AbstractSpringTest;
import com.tocea.corolla.ui.security.AuthUser;
Expand Down Expand Up @@ -86,16 +83,6 @@ public void setUp() {

}

private String buildRevisionPageURL(Project project, String commitID) {

return
new StringBuilder(PORTFOLIO_MANAGER_URL)
.append(project.getKey())
.append("/revisions/")
.append(commitID)
.toString();
}

@Test
public void basicUserShouldAccessPortfolioView() throws Exception {

Expand Down Expand Up @@ -155,54 +142,4 @@ public void shouldRedirectIfProjectDoesNotExist() throws Exception {

}

@Test
public void basicUserShouldAccessRequirementRevisionPage() throws Exception {

Collection<ICommit> commits = revisionService.getHistory(existingProject.getId(), existingProject.getClass());

String commitID = commits.iterator().next().getId();

String URL = buildRevisionPageURL(existingProject, commitID);

mvc
.perform(
get(URL).with(user(new AuthUser(basicUser, basicRole)))
)
.andExpect(status().isOk());

}

@Test
public void shouldNotAccessRequirementRevisionPageWithInvalidProjectKey() throws Exception {

Collection<ICommit> commits = revisionService.getHistory(existingProject.getId(), existingProject.getClass());

String commitID = commits.iterator().next().getId();

Project invalidProject = new Project();
invalidProject.setKey("blblbl");

String URL = buildRevisionPageURL(invalidProject, commitID);

mvc
.perform(
get(URL).with(user(new AuthUser(basicUser, basicRole)))
)
.andExpect(status().isNotFound());

}

@Test
public void shouldNotAccessRequirementRevisionPageWithInvalidCommitID() throws Exception {

String URL = buildRevisionPageURL(existingProject, "blblbl");

mvc
.perform(
get(URL).with(user(new AuthUser(basicUser, basicRole)))
)
.andExpect(status().isNotFound());

}

}

0 comments on commit 353b76f

Please sign in to comment.