예제 #1
0
  @Before
  public void before() {
    fixture = new DomainFixture(hibernateTemplate);
    factory = new DomainFactory(fixture);

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

    httpServletRequest.setCharacterEncoding("UTF-8");
    ServletRequestAccessor.setRequest(httpServletRequest);
    loginUserInPortal(fixture.findUserByName("testuser").getKey());

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

    MockTimeService timeService = new MockTimeService(new DateTime(2011, 6, 27, 12, 0, 0, 0));
    imageController.setTimeService(timeService);

    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();
  }
  @Before
  public void setUp() {
    fixture = new DomainFixture(hibernateTemplate);
    factory = new DomainFactory(fixture);

    // setup needed common data for each test
    fixture.initSystemData();

    fixture.save(
        factory.createContentHandler(
            "Custom content", ContentHandlerName.CUSTOM.getHandlerClassShortName()));

    MockHttpServletRequest httpRequest = new MockHttpServletRequest("GET", "/");
    ServletRequestAccessor.setRequest(httpRequest);

    dataSourceService = new DataSourceServiceImpl();
    dataSourceService.setContentService(contentService);
    dataSourceService.setSecurityService(securityService);
    dataSourceService.setTimeService(new MockTimeService(new DateTime(2010, 7, 1, 12, 0, 0, 0)));
    dataSourceService.setUserDao(userDao);

    fixture.createAndStoreNormalUserWithUserGroup("content-creator", "Creator", "testuserstore");
    fixture.createAndStoreNormalUserWithUserGroup("content-querier", "Querier", "testuserstore");

    // setup content type
    ContentTypeConfigBuilder ctyconf = new ContentTypeConfigBuilder("MyContent", "title");
    ctyconf.startBlock("MyContent");
    ctyconf.addInput("title", "text", "contentdata/title", "Title", true);
    ctyconf.addRelatedContentInput(
        "myRelatedContent", "contentdata/myRelatedContent", "My related content", false, true);
    ctyconf.endBlock();
    Document configAsXmlBytes = XMLDocumentFactory.create(ctyconf.toString()).getAsJDOMDocument();

    fixture.save(
        factory.createContentType(
            "MyRelatedType",
            ContentHandlerName.CUSTOM.getHandlerClassShortName(),
            configAsXmlBytes));
    fixture.save(factory.createUnit("MyUnit", "en"));
    fixture.save(
        factory.createCategory(
            "MyCategory",
            "MyRelatedType",
            "MyUnit",
            User.ANONYMOUS_UID,
            User.ANONYMOUS_UID,
            false));
    fixture.save(
        factory.createCategory(
            "MyOtherCategory",
            "MyRelatedType",
            "MyUnit",
            User.ANONYMOUS_UID,
            User.ANONYMOUS_UID,
            false));

    fixture.save(
        factory.createCategoryAccessForUser(
            "MyCategory", "content-creator", "read, create, approve, admin_browse"));
    fixture.save(
        factory.createCategoryAccessForUser("MyCategory", "content-querier", "read, admin_browse"));
    fixture.save(
        factory.createCategoryAccessForUser(
            "MyOtherCategory", "content-creator", "read, create, approve, admin_browse"));
    fixture.save(
        factory.createCategoryAccessForUser(
            "MyOtherCategory", "content-querier", "read, admin_browse"));

    fixture.flushAndClearHibernateSesssion();
  }
예제 #3
0
  @Before
  public void setUp() {
    fixture = new DomainFixture(hibernateTemplate);
    factory = new DomainFactory(fixture);

    // setup needed common data for each test
    fixture.initSystemData();

    SecurityHolder.setAnonUser(fixture.findUserByName(User.ANONYMOUS_UID).getKey());
    fixture.save(
        factory.createContentHandler(
            "Custom content", ContentHandlerName.CUSTOM.getHandlerClassShortName()));

    fixture.flushAndClearHibernateSesssion();

    // Create an article conent type that will be used in the section:
    ContentTypeConfigBuilder ctyconf = new ContentTypeConfigBuilder("article", "heading");
    ctyconf.startBlock("intro");
    ctyconf.addInput("heading", "text", "contentdata/intro/heading", "heading", true);
    ctyconf.addInput("teaser", "text", "contentdata/intro/teaser", "teaser");
    ctyconf.endBlock();
    XMLBytes configAsXmlBytes = XMLDocumentFactory.create(ctyconf.toString()).getAsBytes();
    fixture.save(
        factory.createContentType(
            "MenuItem", ContentHandlerName.CUSTOM.getHandlerClassShortName(), configAsXmlBytes));

    fixture.flushAndClearHibernateSesssion();

    // Create users that have all and no rights to work with the sections.
    GroupEntity userGroup1 =
        factory.createGroupInUserstore("aru_group", GroupType.USERSTORE_GROUP, "testuserstore");
    GroupEntity userGroup2 =
        factory.createGroupInUserstore("nru_group", GroupType.USERSTORE_GROUP, "testuserstore");
    GroupEntity userGroup3 =
        factory.createGroupInUserstore("publish_group", GroupType.USERSTORE_GROUP, "testuserstore");
    fixture.save(userGroup1, userGroup2, userGroup3);

    fixture.save(
        factory.createUser("aru", "All Rights User", UserType.NORMAL, "testuserstore", userGroup1));
    fixture.save(
        factory.createUser("nru", "No Rights User", UserType.NORMAL, "testuserstore", userGroup2));
    fixture.save(
        factory.createUser(
            "publish", "User with publish only", UserType.NORMAL, "testuserstore", userGroup3));

    fixture.flushAndClearHibernateSesssion();

    // Create a unit and a category in the archive to store the articles in, including access rights
    // on the category.
    fixture.save(
        factory.createContentHandler(
            "Custom content", ContentHandlerName.CUSTOM.getHandlerClassShortName()));
    fixture.save(factory.createUnit("Archive"));
    fixture.save(factory.createCategory("Articles", "article", "Archive", "aru", "aru"));

    fixture.save(
        factory.createCategoryAccessForUser(
            "Articles", "aru", "read, admin_browse, create, delete"));
    fixture.save(factory.createCategoryAccessForUser("Articles", "nru", "read"));

    // Create a site and a section page for testing working with sections.
    fixture.save(factory.createSite("The Newspaper", new Date(), null, "en"));

    fixture.save(
        factory.createPageMenuItem(
            "Hello World!",
            10,
            "This is the top level menu item",
            "Hello World!",
            "The Newspaper",
            "aru",
            "aru",
            false,
            null,
            "en",
            null,
            null,
            null,
            false,
            null));
    //        fixture.save(
    //            factory.createMenuItemAccess( "Hello World!", 10, fixture.findUserByName( "aru"
    // ).getUserGroup(), "read" ) );
    fixture.flushAndClearHibernateSesssion();
  }