コード例 #1
0
  @Before
  public void before() {
    factory = fixture.getFactory();

    fixture.initSystemData();
    fixture.createAndStoreUserAndUserGroup(
        "testuser", "testuser fullname", UserType.NORMAL, "testuserstore");

    ServletRequestAttributes servletRequestAttributes =
        new ServletRequestAttributes(httpServletRequest);
    RequestContextHolder.setRequestAttributes(servletRequestAttributes);
    httpServletRequest.setCharacterEncoding("UTF-8");
    ServletRequestAccessor.setRequest(httpServletRequest);

    loginUserInAdmin(fixture.findUserByName("testuser").getKey());
    loginUserInPortal(fixture.findUserByName("testuser").getKey());

    imageController.setGroupDao(groupDao);
    imageController.setContentDao(contentDao);
    imageController.setSecurityService(securityService);
    imageController.setImageService(imageService);
    imageController.setDisableParamEncoding(true);

    previewService = Mockito.mock(PreviewService.class);
    Mockito.when(previewService.isInPreview()).thenReturn(false);
    Mockito.when(previewService.getPreviewContext()).thenReturn(PreviewContext.NO_PREVIEW);

    site1 = factory.createSite("MySite", new Date(), null, "en");
    fixture.save(site1);
    MenuItemEntity firstPage = createPage("Firstpage", null, "MySite");
    fixture.save(firstPage);

    site1.setFirstPage(firstPage);

    fixture.flushAndClearHibernateSesssion();

    fixture.save(
        factory.createContentHandler(
            "Image content", ContentHandlerName.IMAGE.getHandlerClassShortName()));
    fixture.save(
        factory.createContentType(
            "ImageContentType", ContentHandlerName.IMAGE.getHandlerClassShortName()));
    fixture.save(factory.createUnit("ImageUnit"));
    fixture.save(
        factory.createCategory(
            "ImageCategory", "ImageContentType", "ImageUnit", "testuser", "testuser"));
    fixture.save(
        factory.createCategoryAccessForUser("ImageCategory", "testuser", "read, create, approve"));

    fixture.flushAndClearHibernateSesssion();
  }
コード例 #2
0
  private void checkContentIsOnline(final ContentEntity content) {
    if (previewService.isInPreview()) {
      PreviewContext previewContext = previewService.getPreviewContext();
      if (previewContext.isPreviewingContent()
          && previewContext
              .getContentPreviewContext()
              .treatContentAsAvailableEvenIfOffline(content.getKey())) {
        // when in preview, the content doesn't need to be online
        return;
      }
    }

    if (!content.isOnline(timeService.getNowAsDateTime())) {
      throw AttachmentNotFoundException.notFound(content.getKey());
    }
  }