⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 securitytests.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (C) 2006  Open Source Strategies, Inc. *  * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *  * This program 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 General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *//* Copyright (c) 2005-2006 Open Source Strategies, Inc. */package com.opensourcestrategies.crmsfa.test;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.security.Security;import org.ofbiz.security.SecurityFactory;import junit.framework.TestCase;import com.opensourcestrategies.crmsfa.security.CrmsfaSecurity;/** * This is a class of unit tests for CRM/SFA application's security permissions. * To run these, edit ${ofbiz.home}/base/config/test-containers.xml and add the line * <property name="crm-security" value="com.opensourcestrategies.crmsfa.test.SecurityTests"/> * to <container name="junit-container" class="org.ofbiz.base.container.JunitContainer"> * * Then, from the command prompt, do either * $ java -jar ofbiz.jar -test *  * or * $ ant run-tests *  * This will be run along with other test suites, such as those for the entity engine or the service engine *    * This test suite requires crmsfa/data/CRMSFADemoData.xml and CRMSFASecurityData.xml to be installed   * * Also, make sure that your "test" delegator is set to the correct datasource in framework/entity/config/entityengine.xml *   * @author sichen * */public class SecurityTests extends TestCase {        public static final String module = SecurityTests.class.getName();    public static final String DELEGATOR = "test";    private GenericDelegator delegator = null;    private Security security = null;        public SecurityTests (String name) {        super(name);    }        protected void setUp() throws Exception {        this.delegator = GenericDelegator.getGenericDelegator(DELEGATOR);        this.security = SecurityFactory.getInstance(delegator);    }        // DemoSalesManager for DemoAccount1        /**     * This is a template for a security unit case.  This tests if DemoSalesManager userLogin has permission to update     * DemoAccount1       * @throws Exception     */    public void testDemoAccount1DemoSalesManagerUpdate() throws Exception {        try {            GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));            boolean hasPermission = false;            if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_UPDATE", userLogin, "DemoAccount1")) {                hasPermission = true;            }            TestCase.assertEquals("DemoSalesManager has update permission for DemoAccount1", true, hasPermission);        } catch (GenericEntityException ex) {            TestCase.fail(ex.getMessage());        }    }    public void testDemoAccount1DemoSalesManagerView() throws Exception {        try {            GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));            boolean hasPermission = false;            if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_VIEW", userLogin, "DemoAccount1")) {                hasPermission = true;            }            TestCase.assertEquals("DemoSalesManager has view permission for DemoAccount1", true, hasPermission);        } catch (GenericEntityException ex) {            TestCase.fail(ex.getMessage());        }    }    public void testDemoAccount1DemoSalesManagerDeactivate() throws Exception {        try {            GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));            boolean hasPermission = false;            if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_DEACTIVATE", userLogin, "DemoAccount1")) {                hasPermission = true;            }            TestCase.assertEquals("DemoSalesManager has deactivate permission for DemoAccount1", true, hasPermission);        } catch (GenericEntityException ex) {            TestCase.fail(ex.getMessage());        }    }    public void testDemoAccount1DemoSalesManagerReassign() throws Exception {        try {            GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));            boolean hasPermission = false;            if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_REASSIGN", userLogin, "DemoAccount1")) {                hasPermission = true;            }            TestCase.assertEquals("DemoSalesManager has reassign permission for DemoAccount1", true, hasPermission);        } catch (GenericEntityException ex) {            TestCase.fail(ex.getMessage());        }    }        // DemoSalesRep1 for DemoAccount1    public void testDemoAccount1DemoSalesRep1View() throws Exception {        try {            GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));            boolean hasPermission = false;            if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_VIEW", userLogin, "DemoAccount1")) {                hasPermission = true;            }            TestCase.assertEquals("DemoSalesRep1 has view permission for DemoAccount1", true, hasPermission);        } catch (GenericEntityException ex) {            TestCase.fail(ex.getMessage());        }    }    public void testDemoAccount1DemoSalesRep1Update() throws Exception {        try {            GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));            boolean hasPermission = false;            if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_UPDATE", userLogin, "DemoAccount1")) {                hasPermission = true;            }            TestCase.assertEquals("DemoSalesRep1 has update permission for DemoAccount1", false, hasPermission);        } catch (GenericEntityException ex) {            TestCase.fail(ex.getMessage());        }    }    public void testDemoAccount1DemoSalesRep1Deactivate() throws Exception {        try {            GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));            boolean hasPermission = false;            if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_DEACTIVATE", userLogin, "DemoAccount1")) {                hasPermission = true;            }            TestCase.assertEquals("DemoSalesRep1 has deactivate permission for DemoAccount1", false, hasPermission);        } catch (GenericEntityException ex) {            TestCase.fail(ex.getMessage());        }    }    public void testDemoAccount1DemoSalesRep1Reassign() throws Exception {        try {            GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));            boolean hasPermission = false;            if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_REASSIGN", userLogin, "DemoAccount1")) {                hasPermission = true;            }            TestCase.assertEquals("DemoSalesRep1 has reassign permission for DemoAccount1", false, hasPermission);        } catch (GenericEntityException ex) {            TestCase.fail(ex.getMessage());        }    }            // DemoSalesRep2 for DemoAccount1    public void testDemoAccount1DemoSalesRep2View() throws Exception {        try {            GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2"));            boolean hasPermission = false;            if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_VIEW", userLogin, "DemoAccount1")) {                hasPermission = true;            }            TestCase.assertEquals("DemoSalesRep2 has view permission for DemoAccount1", true, hasPermission);        } catch (GenericEntityException ex) {            TestCase.fail(ex.getMessage());        }    }    public void testDemoAccount1DemoSalesRep2Update() throws Exception {        try {            GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2"));            boolean hasPermission = false;            if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_UPDATE", userLogin, "DemoAccount1")) {                hasPermission = true;            }            TestCase.assertEquals("DemoSalesRep2 has update permission for DemoAccount1", true, hasPermission);        } catch (GenericEntityException ex) {            TestCase.fail(ex.getMessage());        }    }    public void testDemoAccount1DemoSalesRep2Deactivate() throws Exception {        try {            GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2"));            boolean hasPermission = false;            if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_DEACTIVATE", userLogin, "DemoAccount1")) {                hasPermission = true;            }            TestCase.assertEquals("DemoSalesRep2 has deactivate permission for DemoAccount1", false, hasPermission);        } catch (GenericEntityException ex) {            TestCase.fail(ex.getMessage());        }    }    public void testDemoAccount1DemoSalesRep2Reassign() throws Exception {        try {            GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2"));            boolean hasPermission = false;            if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_REASSIGN", userLogin, "DemoAccount1")) {                hasPermission = true;            }            TestCase.assertEquals("DemoSalesRep2 has reassign permission for DemoAccount1", false, hasPermission);        } catch (GenericEntityException ex) {            TestCase.fail(ex.getMessage());        }    }    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -