private void loginUserInPortal(UserKey userKey) { SecurityHolder.setRunAsUser(userKey); SecurityHolder.setUser(userKey); }
@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(); }