/*
 * 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.ode.axis2;

import org.apache.axis2.transport.http.SimpleHTTPServer;

import java.net.URL;
import java.io.File;
import java.io.FilenameFilter;
import java.io.FileFilter;

/**
 *
 *
 */
public class RampartTest extends Axis2TestBase {

    protected void setUp() throws Exception {
        startServer("TestRampart", "webapp/WEB-INF/conf/axis2.xml");
    }

    public void testPolicySamples() throws Exception {
        File[] policies = new File(server.getBundleDir("TestRampart")).listFiles(new FileFilter() {
            public boolean accept(File pathname) {
                return pathname.isDirectory() && pathname.getName().matches("process-policy-sample\\d*");
            }
        });
        for (int i = 0; i < policies.length; i++) {
            String prevPackage = i>0?policies[i-1].getName():null;
            String nextPackage = policies[i].getName();
            // make sure everything is clean to avoid side effects
            if (prevPackage!=null && server.isDeployed(prevPackage)) server.undeployProcess("TestRampart/"+prevPackage);
            if (server.isDeployed(nextPackage)) server.undeployProcess("TestRampart/"+nextPackage);

            executeTest("TestRampart/"+nextPackage);
        }
    }

    public void executeTest(String bundleName) throws Exception {
        server.deployProcess(bundleName);
        try {
            String response = server.sendRequestFile("http://localhost:8080/processes/helloWorld",
                    bundleName, "testRequest.soap");
            System.out.println(response);
            assertTrue(response.contains("helloResponse") && response.contains("Hello World"));
        } finally {
            server.undeployProcess(bundleName);
        }
    }
}

@@ -890,16 +890,356 @@
 PServer;
+%0Aimport org.testng.annotations.Test;%0Aimport org.testng.annotations.Factory;%0Aimport org.testng.annotations.BeforeMethod;%0Aimport org.testng.annotations.DataProvider;%0Aimport org.testng.annotations.AfterMethod;%0Aimport org.testng.annotations.AfterClass;%0Aimport org.testng.annotations.BeforeClass;%0Aimport static org.testng.AssertJUnit.assertTrue;
 %0A%0Aimport
@@ -1331,16 +1331,41 @@
 eFilter;
+%0Aimport java.util.Arrays;
 %0A%0A/**%0A *
@@ -1430,125 +1430,39 @@
     
-protected void setUp() throws Exception %7B%0A        startServer(%22TestRampart%22, %22webapp/WEB-INF/conf/axis2.xml%22);%0A    %7D%0A
+@DataProvider(name = %22bundles%22)
 %0A   
@@ -1469,20 +1469,26 @@
  public 
-void
+Object%5B%5D%5B%5D
  testPol
@@ -1558,27 +1558,47 @@
 ile(
-server.getBundleDir
+getClass().getClassLoader().getResource
 (%22Te
@@ -1608,16 +1608,26 @@
 ampart%22)
+.getFile()
 ).listFi
@@ -1832,16 +1832,76 @@
     %7D);%0A
+        Object%5B%5D%5B%5D bundles = new Object%5Bpolicies.length%5D%5B%5D;%0A
         
@@ -1960,33 +1960,51 @@
     
-String prevPackage = i%3E0?
+bundles%5Bi%5D = new Object%5B%5D%7B%22TestRampart/%22 + 
 poli
@@ -2013,10 +2013,8 @@
 es%5Bi
--1
 %5D.ge
@@ -2024,13 +2024,9 @@
 me()
-:null
+%7D
 ;%0A  
@@ -2035,414 +2035,495 @@
     
-    String nextPackage = policies%5Bi%5D.getName();%0A            // make sure everything is clean to avoid side effects%0A            if (prevPackage!=null && server.isDeployed(prevPackage)) server.undeployProcess(%22TestRampart/%22+prevPackage
+%7D%0A//        bundles = new Object%5B%5D%5B%5D%7Bnew Object%5B%5D%7B%22TestRampart/process-policy-sample05%22%7D%7D;%0A        return bundles;%0A    %7D%0A%0A%0A    @BeforeClass%0A    protected void setUp() throws Exception %7B%0A        // mind the annotatio above also%0A        startServer(%22TestRampart%22, %22webapp/WEB-INF/conf/axis2.xml%22
 );%0A    
+%7D%0A%0A
     
-    if (server.isDeployed(nextPackage)) server.undeployProcess(%22TestRampart/%22+nextPackage);%0A%0A            executeTest(%22TestRampart/%22+nextPackage);%0A        %7D%0A    %7D%0A
+@AfterClass%0A    protected void tearDown() throws Exception %7B%0A        // simply change the annotation, see above%0A        super.tearDown();%0A    %7D%0A%0A    @Test(dataProvider = %22bundles%22)
 %0A   
@@ -2542,20 +2542,23 @@
  execute
-Test
+Process
 (String 
@@ -2580,32 +2580,111 @@
 ows Exception %7B%0A
+        if (server.isDeployed(bundleName)) server.undeployProcess(bundleName);%0A
         server.d
@@ -2799,11 +2799,11 @@
 st:8
-080
+888
 /pro

leverage the TestNG parameters