001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.security.jacc.mappingprovider;
017:
018: import junit.framework.TestCase;
019: import org.apache.geronimo.security.jacc.mappingprovider.PolicyConfigurationGeneric;
020: import org.apache.geronimo.security.jacc.mappingprovider.GeronimoPolicyConfigurationFactory;
021:
022: /**
023: * @version $Rev: 613094 $ $Date: 2008-01-18 00:00:10 -0800 (Fri, 18 Jan 2008) $
024: */
025: public class GeronimoPolicyConfigurationFactoryTest extends TestCase {
026:
027: private static final String CONTEXT_ID = "testContextID";
028: private static GeronimoPolicyConfigurationFactory policyConfigurationFactory = new GeronimoPolicyConfigurationFactory();
029:
030: /**
031: * 3.1.1.1 specifies that policyConfigurationFactory.getPolicyConfiguration always returns an open PolicyConfiguration
032: * @throws Exception
033: */
034: public void testPolicyConfigurationOpen() throws Exception {
035: testPolicyConfigurationOpen(false);
036: testPolicyConfigurationOpen(true);
037: testPolicyConfigurationOpen(false);
038: }
039:
040: private void testPolicyConfigurationOpen(boolean remove)
041: throws Exception {
042: PolicyConfigurationGeneric policyConfiguration = (PolicyConfigurationGeneric) policyConfigurationFactory
043: .getPolicyConfiguration(CONTEXT_ID, remove);
044: assertEquals(PolicyConfigurationGeneric.OPEN,
045: policyConfiguration.getState());
046: policyConfiguration.commit();
047: assertEquals(PolicyConfigurationGeneric.IN_SERVICE,
048: policyConfiguration.getState());
049: policyConfiguration = (PolicyConfigurationGeneric) policyConfigurationFactory
050: .getPolicyConfiguration(CONTEXT_ID, remove);
051: assertEquals(PolicyConfigurationGeneric.OPEN,
052: policyConfiguration.getState());
053: policyConfiguration.delete();
054: assertEquals(PolicyConfigurationGeneric.DELETED,
055: policyConfiguration.getState());
056: policyConfiguration = (PolicyConfigurationGeneric) policyConfigurationFactory
057: .getPolicyConfiguration(CONTEXT_ID, remove);
058: assertEquals(PolicyConfigurationGeneric.OPEN,
059: policyConfiguration.getState());
060: policyConfiguration = (PolicyConfigurationGeneric) policyConfigurationFactory
061: .getPolicyConfiguration(CONTEXT_ID, remove);
062: assertEquals(PolicyConfigurationGeneric.OPEN,
063: policyConfiguration.getState());
064: }
065:
066: /**
067: * spec p. 71:
068: * For a given value of policy context identifier, this method must always return the same instance of PolicyConfiguration and there must be at
069: * most one actual instance of a PolicyConfiguration with a given policy context identifier (during a process context).
070: *
071: * @throws Exception
072: */
073: public void testSamePolicyConfigurationInstance() throws Exception {
074: PolicyConfigurationGeneric policyConfiguration1 = (PolicyConfigurationGeneric) policyConfigurationFactory
075: .getPolicyConfiguration(CONTEXT_ID, false);
076: PolicyConfigurationGeneric policyConfiguration2 = (PolicyConfigurationGeneric) policyConfigurationFactory
077: .getPolicyConfiguration(CONTEXT_ID, false);
078: assertSame(policyConfiguration1, policyConfiguration2);
079: policyConfiguration2 = (PolicyConfigurationGeneric) policyConfigurationFactory
080: .getPolicyConfiguration(CONTEXT_ID, false);
081: assertSame(policyConfiguration1, policyConfiguration2);
082: policyConfiguration2 = (PolicyConfigurationGeneric) policyConfigurationFactory
083: .getPolicyConfiguration(CONTEXT_ID, true);
084: assertSame(policyConfiguration1, policyConfiguration2);
085: policyConfiguration2.commit();
086: policyConfiguration2 = (PolicyConfigurationGeneric) policyConfigurationFactory
087: .getPolicyConfiguration(CONTEXT_ID, false);
088: assertSame(policyConfiguration1, policyConfiguration2);
089: policyConfiguration2.commit();
090: policyConfiguration2 = (PolicyConfigurationGeneric) policyConfigurationFactory
091: .getPolicyConfiguration(CONTEXT_ID, true);
092: assertSame(policyConfiguration1, policyConfiguration2);
093:
094: policyConfiguration2.delete();
095: policyConfiguration2 = (PolicyConfigurationGeneric) policyConfigurationFactory
096: .getPolicyConfiguration(CONTEXT_ID, false);
097: assertSame(policyConfiguration1, policyConfiguration2);
098: policyConfiguration2.delete();
099: policyConfiguration2 = (PolicyConfigurationGeneric) policyConfigurationFactory
100: .getPolicyConfiguration(CONTEXT_ID, true);
101: assertSame(policyConfiguration1, policyConfiguration2);
102:
103: }
104: }
|