CCM NG/ccm-cms: Fixed some tests

CCM NG/ccm-core: Vaadin prototype (UI)


git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4678 8810af33-2d31-482b-a856-94f89814c4df
ccm-docs
jensp 2017-04-17 18:56:03 +00:00
parent 1969271f95
commit e3c9d3c9c9
6 changed files with 346 additions and 19 deletions

View File

@ -30,6 +30,7 @@
<!-- JAX-RS --> <!-- JAX-RS -->
<!--<servlet> <!--<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name> <servlet-name>javax.ws.rs.core.Application</servlet-name>
</servlet> </servlet>
<servlet-mapping> <servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name> <servlet-name>javax.ws.rs.core.Application</servlet-name>
@ -63,11 +64,11 @@
<servlet-mapping> <servlet-mapping>
<servlet-name>vaadin-servlet</servlet-name> <servlet-name>vaadin-servlet</servlet-name>
<url-pattern>/vaadin/</url-pattern> <url-pattern>/vaadin/*</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet-mapping> <servlet-mapping>
<servlet-name>vaadin-servlet</servlet-name> <servlet-name>vaadin-servlet</servlet-name>
<url-pattern>/VAADIN/</url-pattern> <url-pattern>/VAADIN/*</url-pattern>
</servlet-mapping> </servlet-mapping>
</web-app> </web-app>

View File

@ -235,7 +235,9 @@ public class ContentItemManagerTest {
}) })
public void createContentItem() { public void createContentItem() {
shiro.getSystemUser().execute(() -> { shiro.getSystemUser().execute(() -> {
final ContentSection section = sectionRepo.findByLabel("info"); final ContentSection section = sectionRepo
.findByLabel("info")
.get();
final Folder folder = section.getRootDocumentsFolder(); final Folder folder = section.getRootDocumentsFolder();
final Article article = itemManager.createContentItem("new-article", final Article article = itemManager.createContentItem("new-article",
@ -274,7 +276,9 @@ public class ContentItemManagerTest {
+ "ContentItemManagerTest/data.xml") + "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class) @ShouldThrowException(IllegalArgumentException.class)
public void createItemTypeNotInSection() { public void createItemTypeNotInSection() {
final ContentSection section = sectionRepo.findByLabel("info"); final ContentSection section = sectionRepo
.findByLabel("info")
.get();
final Folder folder = section.getRootDocumentsFolder(); final Folder folder = section.getRootDocumentsFolder();
itemManager.createContentItem("Test", section, folder, Event.class); itemManager.createContentItem("Test", section, folder, Event.class);
@ -294,7 +298,9 @@ public class ContentItemManagerTest {
@ShouldThrowException(IllegalArgumentException.class) @ShouldThrowException(IllegalArgumentException.class)
public void createItemNameIsNull() { public void createItemNameIsNull() {
shiro.getSystemUser().execute(() -> { shiro.getSystemUser().execute(() -> {
final ContentSection section = sectionRepo.findByLabel("info"); final ContentSection section = sectionRepo
.findByLabel("info")
.get();
final Folder folder = section.getRootDocumentsFolder(); final Folder folder = section.getRootDocumentsFolder();
itemManager.createContentItem(null, section, folder, Article.class); itemManager.createContentItem(null, section, folder, Article.class);
@ -315,7 +321,9 @@ public class ContentItemManagerTest {
@ShouldThrowException(IllegalArgumentException.class) @ShouldThrowException(IllegalArgumentException.class)
public void createItemNameIsEmpty() { public void createItemNameIsEmpty() {
shiro.getSystemUser().execute(() -> { shiro.getSystemUser().execute(() -> {
final ContentSection section = sectionRepo.findByLabel("info"); final ContentSection section = sectionRepo
.findByLabel("info")
.get();
final Folder folder = section.getRootDocumentsFolder(); final Folder folder = section.getRootDocumentsFolder();
itemManager.createContentItem(" ", section, folder, Article.class); itemManager.createContentItem(" ", section, folder, Article.class);
@ -337,7 +345,9 @@ public class ContentItemManagerTest {
@ShouldThrowException(IllegalArgumentException.class) @ShouldThrowException(IllegalArgumentException.class)
public void createItemFolderIsNull() { public void createItemFolderIsNull() {
shiro.getSystemUser().execute(() -> { shiro.getSystemUser().execute(() -> {
final ContentSection section = sectionRepo.findByLabel("info"); final ContentSection section = sectionRepo
.findByLabel("info")
.get();
itemManager.createContentItem("Test", section, null, Article.class); itemManager.createContentItem("Test", section, null, Article.class);
}); });
@ -370,7 +380,9 @@ public class ContentItemManagerTest {
}) })
public void createContentItemWithWorkflow() { public void createContentItemWithWorkflow() {
shiro.getSystemUser().execute(() -> { shiro.getSystemUser().execute(() -> {
final ContentSection section = sectionRepo.findByLabel("info"); final ContentSection section = sectionRepo
.findByLabel("info")
.get();
final Folder folder = section.getRootDocumentsFolder(); final Folder folder = section.getRootDocumentsFolder();
final WorkflowTemplate workflowTemplate = workflowTemplateRepo final WorkflowTemplate workflowTemplate = workflowTemplateRepo
@ -415,7 +427,9 @@ public class ContentItemManagerTest {
@ShouldThrowException(IllegalArgumentException.class) @ShouldThrowException(IllegalArgumentException.class)
public void createItemTypeNotInSectionWithWorkflow() { public void createItemTypeNotInSectionWithWorkflow() {
shiro.getSystemUser().execute(() -> { shiro.getSystemUser().execute(() -> {
final ContentSection section = sectionRepo.findByLabel("info"); final ContentSection section = sectionRepo
.findByLabel("info")
.get();
final Folder folder = section.getRootDocumentsFolder(); final Folder folder = section.getRootDocumentsFolder();
final WorkflowTemplate workflowTemplate = workflowTemplateRepo final WorkflowTemplate workflowTemplate = workflowTemplateRepo
@ -444,7 +458,9 @@ public class ContentItemManagerTest {
@ShouldThrowException(IllegalArgumentException.class) @ShouldThrowException(IllegalArgumentException.class)
public void createItemNameIsNullWithWorkflow() { public void createItemNameIsNullWithWorkflow() {
shiro.getSystemUser().execute(() -> { shiro.getSystemUser().execute(() -> {
final ContentSection section = sectionRepo.findByLabel("info"); final ContentSection section = sectionRepo
.findByLabel("info")
.get();
final Folder folder = section.getRootDocumentsFolder(); final Folder folder = section.getRootDocumentsFolder();
final WorkflowTemplate workflowTemplate = workflowTemplateRepo final WorkflowTemplate workflowTemplate = workflowTemplateRepo
@ -473,7 +489,9 @@ public class ContentItemManagerTest {
@ShouldThrowException(IllegalArgumentException.class) @ShouldThrowException(IllegalArgumentException.class)
public void createItemNameIsNullWorkflowIsNull() { public void createItemNameIsNullWorkflowIsNull() {
shiro.getSystemUser().execute(() -> { shiro.getSystemUser().execute(() -> {
final ContentSection section = sectionRepo.findByLabel("info"); final ContentSection section = sectionRepo
.findByLabel("info")
.get();
final Folder folder = section.getRootDocumentsFolder(); final Folder folder = section.getRootDocumentsFolder();
itemManager.createContentItem(null, itemManager.createContentItem(null,
@ -499,7 +517,9 @@ public class ContentItemManagerTest {
@ShouldThrowException(IllegalArgumentException.class) @ShouldThrowException(IllegalArgumentException.class)
public void createItemFolderIsNullWithWorkflow() { public void createItemFolderIsNullWithWorkflow() {
shiro.getSystemUser().execute(() -> { shiro.getSystemUser().execute(() -> {
final ContentSection section = sectionRepo.findByLabel("info"); final ContentSection section = sectionRepo
.findByLabel("info")
.get();
final WorkflowTemplate workflowTemplate = workflowTemplateRepo final WorkflowTemplate workflowTemplate = workflowTemplateRepo
.findById(-110L).get(); .findById(-110L).get();
@ -573,7 +593,8 @@ public class ContentItemManagerTest {
} }
/** /**
* Verifies that null null null null null null null null null null null null {@link ContentItemManager#move(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder) * Verifies that null null null null null null null null null null null null
* null null null null null null null null null {@link ContentItemManager#move(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder)
* throws an {@link IllegalArgumentException} if the type of the item to * throws an {@link IllegalArgumentException} if the type of the item to
* copy has not been registered in content section to which the target * copy has not been registered in content section to which the target
* folder belongs. * folder belongs.

View File

@ -242,7 +242,9 @@ public class ContentSectionManagerTest {
excludeColumns = {"object_id"}) excludeColumns = {"object_id"})
@InSequence(200) @InSequence(200)
public void renameSection() { public void renameSection() {
final ContentSection section = repository.findByLabel("info"); final ContentSection section = repository
.findByLabel("info")
.get();
manager.renameContentSection(section, "content"); manager.renameContentSection(section, "content");
@ -284,7 +286,9 @@ public class ContentSectionManagerTest {
"grantee_id"}) "grantee_id"})
@InSequence(300) @InSequence(300)
public void addRole() { public void addRole() {
final ContentSection section = repository.findByLabel("info"); final ContentSection section = repository
.findByLabel("info")
.get();
manager.addRoleToContentSection(section, manager.addRoleToContentSection(section,
"reviewer", "reviewer",
@ -330,7 +334,9 @@ public class ContentSectionManagerTest {
@ShouldThrowException(IllegalArgumentException.class) @ShouldThrowException(IllegalArgumentException.class)
@InSequence(302) @InSequence(302)
public void addRoleNameIsNull() { public void addRoleNameIsNull() {
final ContentSection section = repository.findByLabel("info"); final ContentSection section = repository
.findByLabel("info")
.get();
manager.addRoleToContentSection(section, manager.addRoleToContentSection(section,
null, null,
@ -354,7 +360,9 @@ public class ContentSectionManagerTest {
@ShouldThrowException(IllegalArgumentException.class) @ShouldThrowException(IllegalArgumentException.class)
@InSequence(302) @InSequence(302)
public void addRoleNameIsEmpty() { public void addRoleNameIsEmpty() {
final ContentSection section = repository.findByLabel("info"); final ContentSection section = repository
.findByLabel("info")
.get();
manager.addRoleToContentSection(section, manager.addRoleToContentSection(section,
" ", " ",
@ -375,7 +383,9 @@ public class ContentSectionManagerTest {
excludeColumns = {"object_id"}) excludeColumns = {"object_id"})
@InSequence(350) @InSequence(350)
public void removeRole() { public void removeRole() {
final ContentSection section = repository.findByLabel("info"); final ContentSection section = repository
.findByLabel("info")
.get();
final Role role = roleRepository.findByName("info_publisher").get(); final Role role = roleRepository.findByName("info_publisher").get();
manager.removeRoleFromContentSection(section, role); manager.removeRoleFromContentSection(section, role);
@ -395,7 +405,9 @@ public class ContentSectionManagerTest {
@ShouldThrowException(IllegalArgumentException.class) @ShouldThrowException(IllegalArgumentException.class)
@InSequence(351) @InSequence(351)
public void removeRoleNull() { public void removeRoleNull() {
final ContentSection section = repository.findByLabel("info"); final ContentSection section = repository
.findByLabel("info")
.get();
manager.removeRoleFromContentSection(section, null); manager.removeRoleFromContentSection(section, null);
} }

View File

@ -0,0 +1,83 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.admin.ui;
import com.vaadin.cdi.CDIUI;
import com.vaadin.cdi.CDIViewProvider;
import com.vaadin.cdi.URLMapping;
import com.vaadin.navigator.Navigator;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.UI;
import org.apache.shiro.subject.Subject;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@URLMapping("vaadin")
@CDIUI("admin")
public class AdminUIVaadin extends UI {
private static final long serialVersionUID = -1352590567964037112L;
// private TabSheet tabSheet;
// @Inject
// private UserRepository userRepo;
@Inject
private CDIViewProvider viewProvider;
@Inject
private Subject subject;
@Override
protected void init(VaadinRequest request) {
final Navigator navigator = new Navigator(this, this);
navigator.addProvider(viewProvider);
if (subject.isAuthenticated()) {
navigator.navigateTo(AdminView.VIEWNAME);
} else {
navigator.navigateTo(LoginView.VIEWNAME);
}
// tabSheet = new TabSheet();
//
// final TabSheet userGroupsRoles = new TabSheet();
// final Grid<User> usersTable = new Grid<>();
// usersTable.setItems(userRepo.findAll());
// usersTable.addColumn(User::getName).setCaption("User name");
// usersTable.addColumn(User::getGivenName).setCaption("Given name");
// usersTable.addColumn(User::getFamilyName).setCaption("Family name");
// usersTable
// .addColumn(user -> user.getPrimaryEmailAddress().getAddress())
// .setCaption("E-Mail");
// usersTable.addColumn(User::isBanned).setCaption("Banned?");
// userGroupsRoles.addTab(usersTable, "Users");
//
// tabSheet.addTab(userGroupsRoles, "Users/Groups/Roles");
// setContent(tabSheet);
}
}

View File

@ -0,0 +1,76 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.admin.ui;
import com.vaadin.cdi.CDIView;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Grid;
import com.vaadin.ui.TabSheet;
import org.libreccm.security.User;
import org.libreccm.security.UserRepository;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@CDIView(value = AdminView.VIEWNAME,
uis = {AdminUIVaadin.class})
public class AdminView extends CustomComponent implements View {
private static final long serialVersionUID = -2959302663954819489L;
public static final String VIEWNAME = "admin";
@Inject
private UserRepository userRepo;
private final TabSheet tabSheet;
private final Grid<User> usersTable;
public AdminView() {
tabSheet = new TabSheet();
final TabSheet userGroupsRoles = new TabSheet();
usersTable = new Grid<>();
// usersTable.setItems(userRepo.findAll());
usersTable.addColumn(User::getName).setCaption("User name");
usersTable.addColumn(User::getGivenName).setCaption("Given name");
usersTable.addColumn(User::getFamilyName).setCaption("Family name");
usersTable
.addColumn(user -> user.getPrimaryEmailAddress().getAddress())
.setCaption("E-Mail");
usersTable.addColumn(User::isBanned).setCaption("Banned?");
userGroupsRoles.addTab(usersTable, "Users");
tabSheet.addTab(userGroupsRoles, "Users/Groups/Roles");
setCompositionRoot(tabSheet);
}
@Override
public void enter(final ViewChangeListener.ViewChangeEvent event) {
usersTable.setItems(userRepo.findAll());
}
}

View File

@ -0,0 +1,134 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.admin.ui;
import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.ui.admin.AdminUiConstants;
import com.vaadin.cdi.CDIView;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.server.UserError;
import com.vaadin.ui.Button;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.TextField;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.l10n.GlobalizationHelper;
import java.util.ResourceBundle;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@CDIView(LoginView.VIEWNAME)
public class LoginView extends CustomComponent implements View {
private static final long serialVersionUID = 997966222985596011L;
public static final String VIEWNAME = "login";
@Inject
private ConfigurationManager confManager;
@Inject
private GlobalizationHelper globalizationHelper;
@Inject
private Subject subject;
private ResourceBundle bundle;
private final FormLayout layout;
private final TextField userName;
private final TextField password;
private final Button submitButton;
public LoginView() {
layout = new FormLayout();
layout.setSizeFull();
userName = new TextField();
userName.setCaption("User name");
layout.addComponent(userName);
password = new PasswordField("Password");
layout.addComponent(password);
submitButton = new Button("Login");
submitButton.addClickListener(event -> login(event));
layout.addComponent(submitButton);
setCompositionRoot(layout);
}
@PostConstruct
private void postConstruct() {
bundle = ResourceBundle.getBundle(
"com.arsdigita.ui.login.LoginResources",
globalizationHelper.getNegotiatedLocale());
}
private void login(final Button.ClickEvent event) {
final UsernamePasswordToken token = new UsernamePasswordToken(
userName.getValue(),
password.getValue());
token.setRememberMe(true);
try {
subject.login(token);
} catch (AuthenticationException ex) {
layout.setComponentError(
new UserError(bundle.getString("login.error.loginFail")));
return;
}
getUI().getNavigator().navigateTo(AdminView.VIEWNAME);
}
@Override
public void enter(final ViewChangeListener.ViewChangeEvent event) {
final KernelConfig kernelConfig = confManager
.findConfiguration(KernelConfig.class);
if (kernelConfig.emailIsPrimaryIdentifier()) {
userName.setCaption(bundle
.getString("login.userRegistrationForm.email"));
} else {
userName.setCaption(bundle
.getString("login.userRegistrationForm.screenName"));
}
password.setCaption(
bundle.getString("login.userRegistrationForm.password"));
submitButton.setCaption(bundle
.getString("login.userRegistrationForm.title"));
}
}