001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2007
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.tests.embedded.jsf.bean;
034:
035: import com.flexive.shared.CacheAdmin;
036: import com.flexive.shared.EJBLookup;
037: import com.flexive.shared.FxContext;
038: import com.flexive.shared.exceptions.FxAccountInUseException;
039: import com.flexive.shared.exceptions.FxApplicationException;
040: import com.flexive.shared.exceptions.FxLoginFailedException;
041: import com.flexive.shared.exceptions.FxLogoutFailedException;
042: import com.flexive.shared.security.UserGroup;
043: import static com.flexive.tests.embedded.FxTestUtils.login;
044: import static com.flexive.tests.embedded.FxTestUtils.logout;
045: import com.flexive.tests.embedded.TestUsers;
046: import com.flexive.war.beans.admin.main.UserGroupBean;
047: import org.testng.annotations.AfterClass;
048: import org.testng.annotations.BeforeClass;
049: import org.testng.annotations.Test;
050:
051: import java.util.List;
052:
053: /**
054: * UserGroupBean tests
055: *
056: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
057: */
058: @Test(groups={"jsf"})
059: public class UserGroupBeanTest {
060: private UserGroupBean userGroupBean = null;
061:
062: @BeforeClass
063: public void beforeClass() throws FxLoginFailedException,
064: FxAccountInUseException {
065: userGroupBean = new UserGroupBean();
066: login(TestUsers.SUPERVISOR);
067: }
068:
069: @AfterClass
070: public void afterClass() throws FxLoginFailedException,
071: FxAccountInUseException, FxLogoutFailedException {
072: logout();
073: }
074:
075: @Test
076: public void testGetList() {
077: List<UserGroup> groups = userGroupBean.getList();
078: assert groups.size() > 0 : "No user groups defined";
079: }
080:
081: @Test
082: public void testCreate() throws FxApplicationException {
083: try {
084: userGroupBean.setId(-1);
085: userGroupBean.setColor(null);
086: userGroupBean.setName("TESTNG_TEST_GROUP");
087: userGroupBean
088: .setMandator(CacheAdmin.getEnvironment()
089: .getMandator(
090: FxContext.get().getTicket()
091: .getMandatorId()));
092: String result = userGroupBean.create();
093: assert "userGroupOverview".equals(result) : "Invalid outcome: "
094: + result;
095: } finally {
096: deleteUserGroup();
097: }
098:
099: }
100:
101: /**
102: * Delete the user group created in the usergroupbean, if any.
103: *
104: * @throws FxApplicationException
105: */
106: private void deleteUserGroup() throws FxApplicationException {
107: if (userGroupBean.getId() != -1) {
108: EJBLookup.getUserGroupEngine()
109: .remove(userGroupBean.getId());
110: }
111: if (userGroupBean.getCreatedGroupId() != -1) {
112: EJBLookup.getUserGroupEngine().remove(
113: userGroupBean.getCreatedGroupId());
114: }
115: }
116: }
|