/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.imperius.cimspl.samples.simplepolicies;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.imperius.cimspl.client.TestClient;
import org.apache.imperius.spl.parser.exceptions.SPLException;
public class TestSimplePolicies extends TestCase
{
public TestSimplePolicies(String arg0) {
super(arg0);
}
public static Test suite() {
TestSuite suite = new TestSuite(TestSimplePolicies.class);
TestSetup wrapper = new TestSetup(suite) {
protected void setUp() throws Exception {
oneTimeSetUp();
}
protected void tearDown() throws Exception {
oneTimeTearDown();
}
};
return wrapper;
}
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
protected static void oneTimeSetUp() throws Exception {
}
protected static void oneTimeTearDown() throws Exception {
}
/**
* @param args
*/
public static void testMain()
{
String userDir = System.getProperty("user.dir");
System.out.println("user dir is " + userDir);
testCIMSPLClientSideProvider(userDir + "/resources/policies/");
}
private static void testCIMSPLClientSideProvider(String path)
{
try
{
TestClient tc = new TestClient();
List policyList = _getPolicyNames();
Iterator policyNameIterator = policyList.iterator();
while(policyNameIterator.hasNext())
{
String policyName = (String)policyNameIterator.next();
try
{
tc.deletePolicy(policyName);
}
catch(SPLException e)
{
}
tc.createPolicy(path, policyName);
tc.executePolicy(policyName);
}
try
{
tc.deletePolicy("testElement1Policy");
tc.deletePolicy("CascadedPolicyInvocation");
}
catch(SPLException e)
{
}
tc.createPolicy(path,"testElement1Policy");
tc.createPolicy(path,"CascadedPolicyInvocation");
tc.executePolicy("CascadedPolicyInvocation");
tc.shutdown();
}
catch (SPLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static List _getPolicyNames()
{
List policyNameList = new ArrayList();
policyNameList.add("SimplePolicy1.0.1");
policyNameList.add("ComplexPolicy");
policyNameList.add("InvokeMethodSample");
policyNameList.add("MacroSample");
policyNameList.add("MultiplePolicySample");
return policyNameList;
}
}