Search in sources :

Example 1 with ZippedArtifact

use of com.thoughtworks.go.server.domain.ZippedArtifact in project gocd by gocd.

the class FileModelAndViewTest method shouldReturnModelWithZipFlagTurnedOnIfZipIsNeeded.

@Test
public void shouldReturnModelWithZipFlagTurnedOnIfZipIsNeeded() throws Exception {
    ZippedArtifact zippedArtifact = new ZippedArtifact(existFile.getParentFile(), existFile.getName());
    ModelAndView modelAndView = FileModelAndView.createFileView(zippedArtifact, "");
    assertThat(modelAndView.getModel().containsKey(FileView.NEED_TO_ZIP), is(true));
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ZippedArtifact(com.thoughtworks.go.server.domain.ZippedArtifact) Test(org.junit.Test)

Example 2 with ZippedArtifact

use of com.thoughtworks.go.server.domain.ZippedArtifact in project gocd by gocd.

the class FileModelAndView method createFileView.

public static ModelAndView createFileView(File file, String sha) throws Exception {
    boolean hasChanged = isFileChanged(file, sha);
    if (!hasChanged) {
        return new ModelAndView(new AbstractView() {

            protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception {
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                response.getWriter().close();
            }
        });
    } else {
        HashMap model = new HashMap();
        if (file instanceof ZippedArtifact) {
            model.put(FileView.NEED_TO_ZIP, true);
        }
        model.put("targetFile", file);
        return new ModelAndView("fileView", model);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AbstractView(org.springframework.web.servlet.view.AbstractView) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) HttpServletResponse(javax.servlet.http.HttpServletResponse) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) ZippedArtifact(com.thoughtworks.go.server.domain.ZippedArtifact)

Aggregations

ZippedArtifact (com.thoughtworks.go.server.domain.ZippedArtifact)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Test (org.junit.Test)1 AbstractView (org.springframework.web.servlet.view.AbstractView)1