Example usage for org.springframework.web.servlet ModelAndView getView

List of usage examples for org.springframework.web.servlet ModelAndView getView

Introduction

In this page you can find the example usage for org.springframework.web.servlet ModelAndView getView.

Prototype

@Nullable
public View getView() 

Source Link

Document

Return the View object, or null if we are using a view name to be resolved by the DispatcherServlet via a ViewResolver.

Usage

From source file:au.com.gaiaresources.bdrs.controller.theme.ThemeControllerTest.java

@Test
public void testEditSubmit() throws Exception {
    ManagedFile mf = new ManagedFile();
    mf.setContentType("application/zip");
    mf.setFilename("testTheme.zip");
    mf.setCredit("");
    mf.setLicense("");
    mf.setDescription("");
    managedFileDAO.save(mf);//from   ww  w.  ja v a2  s. c  o  m
    fileService.createFile(mf.getClass(), mf.getId(), mf.getFilename(), createTestTheme(DEFAULT_CONFIG_VALUES));

    login("root", "password", new String[] { Role.ROOT });
    Portal portal = getRequestContext().getPortal();

    request.setMethod("POST");
    request.setRequestURI("/bdrs/root/theme/edit.htm");
    request.setParameter("portalPk", portal.getId().toString());
    request.setParameter("name", "Test Theme");
    request.setParameter("themeFileUUID", mf.getUuid());
    request.setParameter("active", "true");

    ModelAndView mv = handle(request, response);
    ModelAndViewAssert.assertModelAttributeValue(mv, "portalId", portal.getId());
    Assert.assertTrue(mv.getView() instanceof RedirectView);
    RedirectView redirect = (RedirectView) mv.getView();
    Assert.assertEquals("/bdrs/root/theme/edit.htm", redirect.getUrl());

    Theme theme = themeDAO.getTheme((Integer) mv.getModel().get("themeId"));
    Assert.assertEquals(request.getParameter("name"), theme.getName());
    Assert.assertEquals(request.getParameter("themeFileUUID"), theme.getThemeFileUUID());
    Assert.assertEquals(Boolean.parseBoolean(request.getParameter("active")), theme.isActive());

    Assert.assertEquals(DEFAULT_CONFIG_VALUES.size(), theme.getThemeElements().size());
    for (ThemeElement elem : theme.getThemeElements()) {
        String expectedValue = DEFAULT_CONFIG_VALUES.get(elem.getKey());
        Assert.assertEquals(expectedValue, elem.getDefaultValue());
        Assert.assertEquals(expectedValue, elem.getCustomValue());
    }

    // Check that the save theme files have been decompressed and processed correctly.
    // Check the raw file directory.
    File rawDir = fileService.getTargetDirectory(theme, Theme.THEME_DIR_RAW, false);
    Assert.assertEquals(TEST_CSS_RAW_CONTENT, FileUtils.fileRead(new File(rawDir, TEST_CSS_FILE_PATH)));
    Assert.assertEquals(TEST_TEMPLATE_RAW_CONTENT,
            FileUtils.fileRead(new File(rawDir, TEST_TEMPLATE_FILE_PATH)));
    Assert.assertEquals(TEST_JS_RAW_CONTENT, FileUtils.fileRead(new File(rawDir, TEST_JS_FILE_PATH)));
    BufferedImage rawImg = ImageIO.read(new File(rawDir, TEST_IMAGE_FILE_PATH));
    Assert.assertEquals(IMAGE_WIDTH, rawImg.getWidth());
    Assert.assertEquals(IMAGE_HEIGHT, rawImg.getHeight());

    // Check the processed file directory
    File processedDir = fileService.getTargetDirectory(theme, Theme.THEME_DIR_PROCESSED, false);
    Assert.assertEquals(String.format(TEST_CSS_DEFAULT_CONTENT_TMPL, theme.getId()).trim(),
            FileUtils.fileRead(new File(processedDir, TEST_CSS_FILE_PATH)).trim());
    Assert.assertEquals(String.format(TEST_TEMPLATE_DEFAULT_CONTENT, theme.getId()).trim(),
            FileUtils.fileRead(new File(processedDir, TEST_TEMPLATE_FILE_PATH)).trim());
    Assert.assertEquals(TEST_JS_DEFAULT_CONTENT,
            FileUtils.fileRead(new File(processedDir, TEST_JS_FILE_PATH)).trim());
    BufferedImage processedImg = ImageIO.read(new File(processedDir, TEST_IMAGE_FILE_PATH));
    Assert.assertEquals(IMAGE_WIDTH, processedImg.getWidth());
    Assert.assertEquals(IMAGE_HEIGHT, processedImg.getHeight());

    assertThemePage(theme.getId().intValue());
}

From source file:au.com.gaiaresources.bdrs.controller.theme.ThemeControllerTest.java

@Test
public void testEditThemeFileSubmit() throws Exception {
    ManagedFile mf = new ManagedFile();
    mf.setContentType("application/zip");
    mf.setFilename("testTheme.zip");
    mf.setCredit("");
    mf.setLicense("");
    mf.setDescription("");
    managedFileDAO.save(mf);/* w ww  .j  a va  2 s . c  o m*/
    fileService.createFile(mf.getClass(), mf.getId(), mf.getFilename(), createTestTheme(DEFAULT_CONFIG_VALUES));

    Portal portal = getRequestContext().getPortal();

    Map<String, ThemeElement> themeElementMap = new HashMap<String, ThemeElement>();
    List<ThemeElement> themeElements = new ArrayList<ThemeElement>(DEFAULT_CONFIG_VALUES.size());
    for (Map.Entry<String, String> entry : DEFAULT_CONFIG_VALUES.entrySet()) {
        ThemeElement te = new ThemeElement();
        te.setKey(entry.getKey());
        te.setDefaultValue(entry.getValue());
        te.setCustomValue(entry.getValue());
        te.setType(ThemeElementType.TEXT);
        te = themeDAO.save(te);
        themeElements.add(te);
        themeElementMap.put(te.getKey(), te);
    }

    Theme theme = new Theme();
    theme.setActive(true);
    theme.setName("Test Theme");
    theme.setThemeFileUUID(mf.getUuid());
    theme.setCssFiles(new String[] { TEST_CSS_FILE_PATH });
    theme.setJsFiles(new String[] { TEST_JS_FILE_PATH });
    theme.setPortal(portal);
    theme.setThemeElements(themeElements);
    theme = themeDAO.save(theme);

    ZipUtils.decompressToDir(new ZipFile(fileService.getFile(mf, mf.getFilename()).getFile()),
            fileService.getTargetDirectory(theme, Theme.THEME_DIR_RAW, true));

    login("root", "password", new String[] { Role.ROOT });

    request.setMethod("POST");
    request.setRequestURI("/bdrs/root/theme/editThemeFile.htm");
    request.setParameter("themePk", theme.getId().toString());
    request.setParameter("themeFileName", TEST_CSS_FILE_PATH);
    request.setParameter("themeFileContent", TEST_CSS_MODIFIED_RAW_CONTENT);

    ModelAndView mv = handle(request, response);
    ModelAndViewAssert.assertModelAttributeValue(mv, "portalId", portal.getId());
    Assert.assertTrue(mv.getView() instanceof RedirectView);
    RedirectView redirect = (RedirectView) mv.getView();
    Assert.assertEquals("/bdrs/root/theme/edit.htm", redirect.getUrl());

    // Check that the save theme files have been decompressed and processed correctly.
    // Check the raw file directory.
    File rawDir = fileService.getTargetDirectory(theme, Theme.THEME_DIR_RAW, false);
    Assert.assertEquals(TEST_CSS_MODIFIED_RAW_CONTENT,
            FileUtils.fileRead(new File(rawDir, TEST_CSS_FILE_PATH)));
    Assert.assertEquals(TEST_TEMPLATE_RAW_CONTENT,
            FileUtils.fileRead(new File(rawDir, TEST_TEMPLATE_FILE_PATH)));
    Assert.assertEquals(TEST_JS_RAW_CONTENT, FileUtils.fileRead(new File(rawDir, TEST_JS_FILE_PATH)));
    BufferedImage rawImg = ImageIO.read(new File(rawDir, TEST_IMAGE_FILE_PATH));
    Assert.assertEquals(IMAGE_WIDTH, rawImg.getWidth());
    Assert.assertEquals(IMAGE_HEIGHT, rawImg.getHeight());

    // Check the processed file directory
    File processedDir = fileService.getTargetDirectory(theme, Theme.THEME_DIR_PROCESSED, false);

    Assert.assertEquals(String.format(TEST_CSS_MODIFIED_DEFAULT_CONTENT_TMPL, theme.getId()).trim(),
            FileUtils.fileRead(new File(processedDir, TEST_CSS_FILE_PATH)).trim());
    Assert.assertEquals(String.format(TEST_TEMPLATE_DEFAULT_CONTENT, theme.getId()).trim(),
            FileUtils.fileRead(new File(processedDir, TEST_TEMPLATE_FILE_PATH)).trim());
    Assert.assertEquals(TEST_JS_DEFAULT_CONTENT,
            FileUtils.fileRead(new File(processedDir, TEST_JS_FILE_PATH)).trim());
    BufferedImage processedImg = ImageIO.read(new File(processedDir, TEST_IMAGE_FILE_PATH));
    Assert.assertEquals(IMAGE_WIDTH, processedImg.getWidth());
    Assert.assertEquals(IMAGE_HEIGHT, processedImg.getHeight());
}

From source file:au.com.gaiaresources.bdrs.controller.theme.ThemeControllerTest.java

@Test
public void testEditThemeFileRevertSubmit() throws Exception {
    ManagedFile mf = new ManagedFile();
    mf.setContentType("application/zip");
    mf.setFilename("testTheme.zip");
    mf.setCredit("");
    mf.setLicense("");
    mf.setDescription("");
    managedFileDAO.save(mf);//from   w w w .ja va  2s.  c  o m
    fileService.createFile(mf.getClass(), mf.getId(), mf.getFilename(), createTestTheme(DEFAULT_CONFIG_VALUES));

    Portal portal = getRequestContext().getPortal();

    Map<String, ThemeElement> themeElementMap = new HashMap<String, ThemeElement>();
    List<ThemeElement> themeElements = new ArrayList<ThemeElement>(DEFAULT_CONFIG_VALUES.size());
    for (Map.Entry<String, String> entry : DEFAULT_CONFIG_VALUES.entrySet()) {
        ThemeElement te = new ThemeElement();
        te.setKey(entry.getKey());
        te.setDefaultValue(entry.getValue());
        te.setCustomValue(entry.getValue());
        te.setType(ThemeElementType.TEXT);
        te = themeDAO.save(te);
        themeElements.add(te);
        themeElementMap.put(te.getKey(), te);
    }

    Theme theme = new Theme();
    theme.setActive(true);
    theme.setName("Test Theme");
    theme.setThemeFileUUID(mf.getUuid());
    theme.setCssFiles(new String[] { TEST_CSS_FILE_PATH });
    theme.setJsFiles(new String[] { TEST_JS_FILE_PATH });
    theme.setPortal(portal);
    theme.setThemeElements(themeElements);
    theme = themeDAO.save(theme);

    ZipUtils.decompressToDir(new ZipFile(fileService.getFile(mf, mf.getFilename()).getFile()),
            fileService.getTargetDirectory(theme, Theme.THEME_DIR_RAW, true));

    File rawDir = fileService.getTargetDirectory(theme, Theme.THEME_DIR_RAW, false);
    File cssFile = new File(rawDir, TEST_CSS_FILE_PATH);
    FileUtils.fileDelete(cssFile.getAbsolutePath());
    FileUtils.fileWrite(cssFile.getAbsolutePath(), "Mary had a little lamb");

    login("root", "password", new String[] { Role.ROOT });

    request.setMethod("POST");
    request.setRequestURI("/bdrs/root/theme/editThemeFile.htm");
    request.setParameter("themePk", theme.getId().toString());
    request.setParameter("themeFileName", TEST_CSS_FILE_PATH);
    request.setParameter("themeFileContent", TEST_CSS_MODIFIED_RAW_CONTENT);
    request.setParameter("revert", "Revert File");

    ModelAndView mv = handle(request, response);
    ModelAndViewAssert.assertModelAttributeValue(mv, "portalId", portal.getId());
    Assert.assertTrue(mv.getView() instanceof RedirectView);
    RedirectView redirect = (RedirectView) mv.getView();
    Assert.assertEquals("/bdrs/root/theme/edit.htm", redirect.getUrl());

    // Check that the save theme files have been decompressed and processed correctly.
    // Check the raw file directory.
    Assert.assertEquals(TEST_CSS_RAW_CONTENT, FileUtils.fileRead(new File(rawDir, TEST_CSS_FILE_PATH)));
    Assert.assertEquals(TEST_TEMPLATE_RAW_CONTENT,
            FileUtils.fileRead(new File(rawDir, TEST_TEMPLATE_FILE_PATH)));
    Assert.assertEquals(TEST_JS_RAW_CONTENT, FileUtils.fileRead(new File(rawDir, TEST_JS_FILE_PATH)));
    BufferedImage rawImg = ImageIO.read(new File(rawDir, TEST_IMAGE_FILE_PATH));
    Assert.assertEquals(IMAGE_WIDTH, rawImg.getWidth());
    Assert.assertEquals(IMAGE_HEIGHT, rawImg.getHeight());

    // Check the processed file directory
    File processedDir = fileService.getTargetDirectory(theme, Theme.THEME_DIR_PROCESSED, false);

    Assert.assertEquals(String.format(TEST_CSS_DEFAULT_CONTENT_TMPL, theme.getId()).trim(),
            FileUtils.fileRead(new File(processedDir, TEST_CSS_FILE_PATH)).trim());
    Assert.assertEquals(String.format(TEST_TEMPLATE_DEFAULT_CONTENT, theme.getId()).trim(),
            FileUtils.fileRead(new File(processedDir, TEST_TEMPLATE_FILE_PATH)).trim());
    Assert.assertEquals(TEST_JS_DEFAULT_CONTENT,
            FileUtils.fileRead(new File(processedDir, TEST_JS_FILE_PATH)).trim());
    BufferedImage processedImg = ImageIO.read(new File(processedDir, TEST_IMAGE_FILE_PATH));
    Assert.assertEquals(IMAGE_WIDTH, processedImg.getWidth());
    Assert.assertEquals(IMAGE_HEIGHT, processedImg.getHeight());
}

From source file:au.com.gaiaresources.bdrs.controller.theme.ThemeControllerTest.java

@Test
public void testEditCustomSubmit() throws Exception {
    ManagedFile mf = new ManagedFile();
    mf.setContentType("application/zip");
    mf.setFilename("testTheme.zip");
    mf.setCredit("");
    mf.setLicense("");
    mf.setDescription("");
    managedFileDAO.save(mf);/* w  w w  . jav  a2s. co m*/
    fileService.createFile(mf.getClass(), mf.getId(), mf.getFilename(), createTestTheme(DEFAULT_CONFIG_VALUES));

    Portal portal = getRequestContext().getPortal();

    Map<String, ThemeElement> themeElementMap = new HashMap<String, ThemeElement>();
    List<ThemeElement> themeElements = new ArrayList<ThemeElement>(DEFAULT_CONFIG_VALUES.size());
    for (Map.Entry<String, String> entry : DEFAULT_CONFIG_VALUES.entrySet()) {
        ThemeElement te = new ThemeElement();
        te.setKey(entry.getKey());
        te.setDefaultValue(entry.getValue());
        te.setCustomValue(entry.getValue());
        te.setType(ThemeElementType.TEXT);
        te = themeDAO.save(te);
        themeElements.add(te);
        themeElementMap.put(te.getKey(), te);
    }

    Theme theme = new Theme();
    theme.setActive(true);
    theme.setName("Test Theme");
    theme.setThemeFileUUID(mf.getUuid());
    theme.setCssFiles(new String[] { TEST_CSS_FILE_PATH });
    theme.setJsFiles(new String[] { TEST_JS_FILE_PATH });
    theme.setPortal(portal);
    theme.setThemeElements(themeElements);
    theme = themeDAO.save(theme);

    ZipUtils.decompressToDir(new ZipFile(fileService.getFile(mf, mf.getFilename()).getFile()),
            fileService.getTargetDirectory(theme, Theme.THEME_DIR_RAW, true));

    login("root", "password", new String[] { Role.ROOT });

    request.setMethod("POST");
    request.setRequestURI("/bdrs/root/theme/edit.htm");
    request.setParameter("portalPk", portal.getId().toString());
    request.setParameter("themePk", theme.getId().toString());
    request.setParameter("name", theme.getName());
    request.setParameter("themeFileUUID", theme.getThemeFileUUID());
    request.setParameter("active", String.valueOf(theme.isActive()));
    for (Map.Entry<String, String> customEntry : CUSTOM_CONFIG_VALUES.entrySet()) {
        ThemeElement te = themeElementMap.get(customEntry.getKey());
        request.setParameter(String.format(ThemeController.THEME_ELEMENT_CUSTOM_VALUE_TEMPLATE, te.getId()),
                customEntry.getValue());
    }

    ModelAndView mv = handle(request, response);
    ModelAndViewAssert.assertModelAttributeValue(mv, "portalId", portal.getId());
    Assert.assertTrue(mv.getView() instanceof RedirectView);
    RedirectView redirect = (RedirectView) mv.getView();
    Assert.assertEquals("/bdrs/root/theme/edit.htm", redirect.getUrl());

    Theme actualTheme = themeDAO.getTheme((Integer) mv.getModel().get("themeId"));
    Assert.assertEquals(theme.getName(), actualTheme.getName());
    Assert.assertEquals(theme.getThemeFileUUID(), actualTheme.getThemeFileUUID());
    Assert.assertEquals(theme.isActive(), actualTheme.isActive());

    Assert.assertEquals(DEFAULT_CONFIG_VALUES.size(), actualTheme.getThemeElements().size());
    for (ThemeElement elem : actualTheme.getThemeElements()) {
        String expectedDefaultValue = DEFAULT_CONFIG_VALUES.get(elem.getKey());
        Assert.assertEquals(expectedDefaultValue, elem.getDefaultValue());

        String expectedCustomValue = CUSTOM_CONFIG_VALUES.get(elem.getKey());
        Assert.assertEquals(expectedCustomValue, elem.getCustomValue());
    }

    // Check that the save theme files have been decompressed and processed correctly.
    // Check the raw file directory.
    File rawDir = fileService.getTargetDirectory(actualTheme, Theme.THEME_DIR_RAW, false);
    Assert.assertEquals(TEST_CSS_RAW_CONTENT, FileUtils.fileRead(new File(rawDir, TEST_CSS_FILE_PATH)));
    Assert.assertEquals(TEST_TEMPLATE_RAW_CONTENT,
            FileUtils.fileRead(new File(rawDir, TEST_TEMPLATE_FILE_PATH)));
    Assert.assertEquals(TEST_JS_RAW_CONTENT, FileUtils.fileRead(new File(rawDir, TEST_JS_FILE_PATH)));
    BufferedImage rawImg = ImageIO.read(new File(rawDir, TEST_IMAGE_FILE_PATH));
    Assert.assertEquals(IMAGE_WIDTH, rawImg.getWidth());
    Assert.assertEquals(IMAGE_HEIGHT, rawImg.getHeight());

    // Check the processed file directory
    File processedDir = fileService.getTargetDirectory(actualTheme, Theme.THEME_DIR_PROCESSED, false);
    Assert.assertEquals(String.format(TEST_CSS_CUSTOM_CONTENT_TMPL, actualTheme.getId()).trim(),
            FileUtils.fileRead(new File(processedDir, TEST_CSS_FILE_PATH)).trim());
    Assert.assertEquals(String.format(TEST_TEMPLATE_CUSTOM_CONTENT, actualTheme.getId()).trim(),
            FileUtils.fileRead(new File(processedDir, TEST_TEMPLATE_FILE_PATH)).trim());
    Assert.assertEquals(TEST_JS_CUSTOM_CONTENT,
            FileUtils.fileRead(new File(processedDir, TEST_JS_FILE_PATH)).trim());
    BufferedImage processedImg = ImageIO.read(new File(processedDir, TEST_IMAGE_FILE_PATH));
    Assert.assertEquals(IMAGE_WIDTH, processedImg.getWidth());
    Assert.assertEquals(IMAGE_HEIGHT, processedImg.getHeight());
}

From source file:au.com.gaiaresources.bdrs.controller.theme.ThemeControllerTest.java

@Test
public void testEditRevertSubmit() throws Exception {
    ManagedFile mf = new ManagedFile();
    mf.setContentType("application/zip");
    mf.setFilename("testTheme.zip");
    mf.setCredit("");
    mf.setLicense("");
    mf.setDescription("");
    managedFileDAO.save(mf);/* ww  w . ja v a2  s.  c  o  m*/
    fileService.createFile(mf.getClass(), mf.getId(), mf.getFilename(), createTestTheme(DEFAULT_CONFIG_VALUES));

    Portal portal = getRequestContext().getPortal();

    Map<String, ThemeElement> themeElementMap = new HashMap<String, ThemeElement>();
    List<ThemeElement> themeElements = new ArrayList<ThemeElement>(DEFAULT_CONFIG_VALUES.size());
    for (Map.Entry<String, String> entry : DEFAULT_CONFIG_VALUES.entrySet()) {
        ThemeElement te = new ThemeElement();
        te.setKey(entry.getKey());
        te.setDefaultValue(entry.getValue());
        te.setCustomValue(CUSTOM_CONFIG_VALUES.get(entry.getKey()));
        te.setType(ThemeElementType.TEXT);
        te = themeDAO.save(te);
        themeElements.add(te);
        themeElementMap.put(te.getKey(), te);
    }

    Theme theme = new Theme();
    theme.setActive(true);
    theme.setName("Test Theme");
    theme.setThemeFileUUID(mf.getUuid());
    theme.setCssFiles(new String[] { TEST_CSS_FILE_PATH });
    theme.setJsFiles(new String[] { TEST_JS_FILE_PATH });
    theme.setPortal(portal);
    theme.setThemeElements(themeElements);
    theme = themeDAO.save(theme);

    ZipUtils.decompressToDir(new ZipFile(fileService.getFile(mf, mf.getFilename()).getFile()),
            fileService.getTargetDirectory(theme, Theme.THEME_DIR_RAW, true));

    login("root", "password", new String[] { Role.ROOT });

    request.setMethod("POST");
    request.setRequestURI("/bdrs/root/theme/edit.htm");
    request.setParameter("portalPk", portal.getId().toString());
    request.setParameter("themePk", theme.getId().toString());
    request.setParameter("name", theme.getName());
    request.setParameter("themeFileUUID", theme.getThemeFileUUID());
    request.setParameter("active", String.valueOf(theme.isActive()));
    request.setParameter("revert", "Revert Theme");
    for (Map.Entry<String, String> customEntry : CUSTOM_CONFIG_VALUES.entrySet()) {
        ThemeElement te = themeElementMap.get(customEntry.getKey());
        request.setParameter(String.format(ThemeController.THEME_ELEMENT_CUSTOM_VALUE_TEMPLATE, te.getId()),
                customEntry.getValue());
    }

    ModelAndView mv = handle(request, response);
    ModelAndViewAssert.assertModelAttributeValue(mv, "portalId", portal.getId());
    Assert.assertTrue(mv.getView() instanceof RedirectView);
    RedirectView redirect = (RedirectView) mv.getView();
    Assert.assertEquals("/bdrs/root/theme/edit.htm", redirect.getUrl());

    Theme actualTheme = themeDAO.getTheme((Integer) mv.getModel().get("themeId"));
    Assert.assertEquals(theme.getName(), actualTheme.getName());
    Assert.assertEquals(theme.getThemeFileUUID(), actualTheme.getThemeFileUUID());
    Assert.assertEquals(theme.isActive(), actualTheme.isActive());

    Assert.assertEquals(DEFAULT_CONFIG_VALUES.size(), actualTheme.getThemeElements().size());
    for (ThemeElement elem : actualTheme.getThemeElements()) {
        String expectedDefaultValue = DEFAULT_CONFIG_VALUES.get(elem.getKey());
        Assert.assertEquals(expectedDefaultValue, elem.getDefaultValue());
        Assert.assertEquals(expectedDefaultValue, elem.getCustomValue());
    }

    // Check that the save theme files have been decompressed and processed correctly.
    // Check the raw file directory.
    File rawDir = fileService.getTargetDirectory(actualTheme, Theme.THEME_DIR_RAW, false);
    Assert.assertEquals(TEST_CSS_RAW_CONTENT, FileUtils.fileRead(new File(rawDir, TEST_CSS_FILE_PATH)));
    Assert.assertEquals(TEST_TEMPLATE_RAW_CONTENT,
            FileUtils.fileRead(new File(rawDir, TEST_TEMPLATE_FILE_PATH)));
    Assert.assertEquals(TEST_JS_RAW_CONTENT, FileUtils.fileRead(new File(rawDir, TEST_JS_FILE_PATH)));
    BufferedImage rawImg = ImageIO.read(new File(rawDir, TEST_IMAGE_FILE_PATH));
    Assert.assertEquals(IMAGE_WIDTH, rawImg.getWidth());
    Assert.assertEquals(IMAGE_HEIGHT, rawImg.getHeight());

    // Check the processed file directory
    File processedDir = fileService.getTargetDirectory(actualTheme, Theme.THEME_DIR_PROCESSED, false);
    Assert.assertEquals(String.format(TEST_CSS_DEFAULT_CONTENT_TMPL, theme.getId()).trim(),
            FileUtils.fileRead(new File(processedDir, TEST_CSS_FILE_PATH)).trim());
    Assert.assertEquals(String.format(TEST_TEMPLATE_DEFAULT_CONTENT, theme.getId()).trim(),
            FileUtils.fileRead(new File(processedDir, TEST_TEMPLATE_FILE_PATH)).trim());
    Assert.assertEquals(TEST_JS_DEFAULT_CONTENT,
            FileUtils.fileRead(new File(processedDir, TEST_JS_FILE_PATH)).trim());
    BufferedImage processedImg = ImageIO.read(new File(processedDir, TEST_IMAGE_FILE_PATH));
    Assert.assertEquals(IMAGE_WIDTH, processedImg.getWidth());
    Assert.assertEquals(IMAGE_HEIGHT, processedImg.getHeight());

    assertThemePage(theme.getId().intValue());
}

From source file:org.terasoluna.gfw.web.logging.TraceLoggingInterceptor.java

/**
 * Logic to output end log/*from   w w w  .j  a v a2s  .co m*/
 * <p>
 * Outputs the end log.<br>
 * Outputs warning log if difference of time between start time and end time is more than the nano-seconds value<br>
 * set as warning log output timing.
 * </p>
 * @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#postHandle(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.web.servlet.ModelAndView)
 */
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) {

    if (!(handler instanceof HandlerMethod)) {
        return;
    }

    long startTime = 0;
    if (request.getAttribute(START_ATTR) != null) {
        startTime = ((Long) request.getAttribute(START_ATTR)).longValue();
    }
    long handlingTime = System.nanoTime() - startTime;
    request.removeAttribute(START_ATTR);
    request.setAttribute(HANDLING_ATTR, handlingTime);
    String formattedHandlingTime = String.format("%1$,3d", handlingTime);

    boolean isWarnHandling = handlingTime > warnHandlingNanos;

    if (!isEnabledLogLevel(isWarnHandling)) {
        return;
    }

    HandlerMethod handlerMethod = (HandlerMethod) handler;
    Method m = handlerMethod.getMethod();
    Object view = null;
    Map<String, Object> model = null;
    if (modelAndView != null) {
        view = modelAndView.getView();
        model = modelAndView.getModel();
        if (view == null) {
            view = modelAndView.getViewName();
        }
    }

    logger.trace("[END CONTROLLER  ] {}.{}({})-> view={}, model={}",
            new Object[] { m.getDeclaringClass().getSimpleName(), m.getName(), buildMethodParams(handlerMethod),
                    view, model });
    String handlingTimeMessage = "[HANDLING TIME   ] {}.{}({})-> {} ns";
    if (isWarnHandling) {
        logger.warn(handlingTimeMessage + " > {}", new Object[] { m.getDeclaringClass().getSimpleName(),
                m.getName(), buildMethodParams(handlerMethod), formattedHandlingTime, warnHandlingNanos });
    } else {
        logger.trace(handlingTimeMessage, new Object[] { m.getDeclaringClass().getSimpleName(), m.getName(),
                buildMethodParams(handlerMethod), formattedHandlingTime });
    }
}

From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.TestSharedBuildNumberController.java

@Test
public void testDoHandleDeleteBuildNumberPost02() throws IOException, ServletException {
    this.setUpSecurity();

    expect(this.request.getParameter("action")).andReturn("delete").atLeastOnce();
    expect(this.request.getMethod()).andReturn("POST").atLeastOnce();
    expect(this.request.getParameter("id")).andReturn("31");
    this.service.deleteSharedBuildNumber(31);
    expectLastCall();/*from  w w w  .j av  a 2s. c o m*/

    replay(this.service, this.request, this.response);

    ModelAndView modelAndView = this.controller.doHandle(this.request, this.response);

    assertNotNull("The model and view should not be null.", modelAndView);

    View view = modelAndView.getView();

    assertNotNull("The view should not be null.", view);
    assertTrue("The view should be a redirect view.", view instanceof RedirectView);
    assertEquals("The redirect URL is not correct.", "/admin/admin.html?item=sharedBuildNumbers",
            ((RedirectView) view).getUrl());
}

From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.TestSharedBuildNumberController.java

@Test
public void testDoHandleAddBuildNumberPost03() throws IOException, ServletException {
    this.setUpSecurity();

    Capture<SharedBuildNumber> capture = new Capture<SharedBuildNumber>();

    expect(this.request.getParameter("action")).andReturn("add");
    expect(this.request.getMethod()).andReturn("POST");
    expect(this.request.getParameter("name")).andReturn("Hello Again");
    expect(this.request.getParameter("description")).andReturn("This is another description.");
    expect(this.request.getParameter("format")).andReturn("2.3.0.{d}.{0}");
    expect(this.request.getParameter("dateFormat")).andReturn("YMdHms");
    expect(this.request.getParameter("counter")).andReturn("19");
    expect(this.service.getNextBuildNumberId()).andReturn(71);
    this.service.saveSharedBuildNumber(capture(capture));
    expectLastCall();/*from  www  .j  ava2s.  co  m*/

    replay(this.service, this.request, this.response);

    ModelAndView modelAndView = this.controller.doHandle(this.request, this.response);

    assertNotNull("The model and view should not be null.", modelAndView);

    View view = modelAndView.getView();

    assertNotNull("The view should not be null.", view);
    assertTrue("The view should be a redirect view.", view instanceof RedirectView);
    assertEquals("The redirect URL is not correct.", "/admin/admin.html?item=sharedBuildNumbers",
            ((RedirectView) view).getUrl());

    SharedBuildNumber number = capture.getValue();
    assertNotNull("The shared build number should not be null.", number);
    assertEquals("The ID is not correct.", 71, number.getId());
    assertEquals("The name is not correct.", "Hello Again", number.getName());
    assertEquals("The description is not correct.", "This is another description.", number.getDescription());
    assertEquals("The format is not correct.", "2.3.0.{d}.{0}", number.getFormat());
    assertEquals("The date format is not correct.", "YMdHms", number.getDateFormat());
    assertEquals("The counter is not correct.", 19, number.getCounter());
}

From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.TestSharedBuildNumberController.java

@Test
public void testDoHandleEditBuildNumberPost04() throws IOException, ServletException {
    this.setUpSecurity();

    SharedBuildNumber originalNumber = new SharedBuildNumber(45);

    Capture<SharedBuildNumber> capture = new Capture<SharedBuildNumber>();

    expect(this.request.getParameter("action")).andReturn("edit");
    expect(this.request.getMethod()).andReturn("POST");
    expect(this.request.getParameter("id")).andReturn("45");
    expect(this.service.getSharedBuildNumber(45)).andReturn(originalNumber);
    expect(this.request.getParameter("name")).andReturn("Hello Again");
    expect(this.request.getParameter("description")).andReturn("This is another description.");
    expect(this.request.getParameter("format")).andReturn("2.3.0.{d}.{0}");
    expect(this.request.getParameter("dateFormat")).andReturn("YMdHms");
    expect(this.request.getParameter("counter")).andReturn("0");
    this.service.saveSharedBuildNumber(capture(capture));
    expectLastCall();/*from w  w w. ja va  2s.c  o  m*/

    replay(this.service, this.request, this.response);

    ModelAndView modelAndView = this.controller.doHandle(this.request, this.response);

    assertNotNull("The model and view should not be null.", modelAndView);

    View view = modelAndView.getView();

    assertNotNull("The view should not be null.", view);
    assertTrue("The view should be a redirect view.", view instanceof RedirectView);
    assertEquals("The redirect URL is not correct.", "/admin/admin.html?item=sharedBuildNumbers",
            ((RedirectView) view).getUrl());

    SharedBuildNumber number = capture.getValue();
    assertNotNull("The shared build number should not be null.", number);
    assertSame("The shared build number is not correct.", originalNumber, number);
    assertEquals("The ID is not correct.", 45, number.getId());
    assertEquals("The name is not correct.", "Hello Again", number.getName());
    assertEquals("The description is not correct.", "This is another description.", number.getDescription());
    assertEquals("The format is not correct.", "2.3.0.{d}.{0}", number.getFormat());
    assertEquals("The date format is not correct.", "YMdHms", number.getDateFormat());
    assertEquals("The counter is not correct.", 1, number.getCounter());
}

From source file:org.kmnet.com.fw.web.logging.TraceLoggingInterceptor.java

/**
 * Logic to output end log//from w w  w. j  a  v  a 2s  .  c  om
 * <p>
 * Outputs the end log.<br>
 * Outputs warning log if difference of time between start time and end time is more than the nano-seconds value<br>
 * set as warning log output timing.
 * </p>
 * @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#postHandle(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.web.servlet.ModelAndView)
 */
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) {

    if (!(handler instanceof HandlerMethod)) {
        return;
    }

    long startTime = 0;
    if (request.getAttribute(START_ATTR) != null) {
        startTime = ((Long) request.getAttribute(START_ATTR)).longValue();
    }
    long handlingTime = System.nanoTime() - startTime;
    request.removeAttribute(START_ATTR);
    request.setAttribute(HANDLING_ATTR, handlingTime);
    String formattedHandlingTime = String.format("%1$,3d", handlingTime);

    boolean isWarnHandling = (handlingTime > warnHandlingNanos);

    if (isWarnHandling) {
        if (!logger.isWarnEnabled()) {
            return;
        }
    } else if (!logger.isTraceEnabled()) {
        return;
    }

    HandlerMethod handlerMethod = (HandlerMethod) handler;
    Method m = handlerMethod.getMethod();
    Object view = null;
    Map<String, Object> model = null;
    if (modelAndView != null) {
        view = modelAndView.getView();
        model = modelAndView.getModel();
        if (view == null) {
            view = modelAndView.getViewName();
        }
    }

    logger.trace("[END CONTROLLER  ] {}.{}({})-> view={}, model={}",
            new Object[] { m.getDeclaringClass().getSimpleName(), m.getName(), buildMethodParams(handlerMethod),
                    view, model });
    String handlingTimeMessage = "[HANDLING TIME   ] {}.{}({})-> {} ns";
    if (isWarnHandling) {
        logger.warn(handlingTimeMessage + " > {}", new Object[] { m.getDeclaringClass().getSimpleName(),
                m.getName(), buildMethodParams(handlerMethod), formattedHandlingTime, warnHandlingNanos });
    } else {
        logger.trace(handlingTimeMessage, new Object[] { m.getDeclaringClass().getSimpleName(), m.getName(),
                buildMethodParams(handlerMethod), formattedHandlingTime });
    }
}