[176227] Generate test case not working.
diff --git a/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/consumption/core/command/Axis2ClientTestCaseIntegrateCommand.java b/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/consumption/core/command/Axis2ClientTestCaseIntegrateCommand.java
new file mode 100644
index 0000000..60062e3
--- /dev/null
+++ b/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/consumption/core/command/Axis2ClientTestCaseIntegrateCommand.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * Copyright (c) 2007 WSO2 Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * WSO2 Inc. - initial API and implementation
+ * yyyymmdd bug      Email and other contact information
+ * -------- -------- -----------------------------------------------------------
+ * 20070518        187311 sandakith@wso2.com - Lahiru Sandakith, Fixing test resource addition
+ *******************************************************************************/
+package org.eclipse.jst.ws.axis2.consumption.core.command;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.JavaProject;
+import org.eclipse.jst.ws.axis2.consumption.core.data.DataModel;
+import org.eclipse.jst.ws.axis2.consumption.core.messages.Axis2ConsumptionUIMessages;
+import org.eclipse.jst.ws.axis2.core.plugin.messages.Axis2CoreUIMessages;
+import org.eclipse.jst.ws.axis2.core.utils.FileUtils;
+import org.eclipse.jst.ws.internal.common.J2EEUtils;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.eclipse.wst.ws.internal.common.BundleUtils;
+
+
+/**
+ * This Class will first check whether Axis2 Client will generate the TestCase
+ * and if so then it will integrate that test to the initiated dynamic web project
+ *
+ */
+public class Axis2ClientTestCaseIntegrateCommand extends AbstractDataModelOperation {
+
+    private DataModel model;
+    private IProject project;
+
+    public Axis2ClientTestCaseIntegrateCommand(IProject project_,DataModel model_){
+        this.model = model_;
+        this.project = project_;
+    }
+    
+    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+        IStatus status = Status.OK_STATUS;
+        String workspaceDirectory = ResourcesPlugin.getWorkspace().getRoot().
+                                                    getLocation().toOSString();
+        // Check whether the service generate test case is enabled
+        if(model.isTestCaseCheck()){
+        	try{
+        	// Then add the latest junit.jar from to the project class path
+            IPath junitPath = new Path(CopyJUnitJarToProject(workspaceDirectory));
+
+            // make the test folder as source folder.
+            // Get the Project Handler
+            IJavaProject javaProj = new JavaProject(project,null);
+            // to get existing class path entries
+            IClasspathEntry[] classpathEntries = javaProj.getRawClasspath(); 
+            // increase the class path entries array by 1 to make room for the new source directory
+            // where path is the new source directory
+            IClasspathEntry newClasspathEntry = JavaCore
+                                .newSourceEntry(getPathToTestFolder(project,workspaceDirectory)); 
+            IClasspathEntry junitClasspathEntry = JavaCore.newLibraryEntry (junitPath,null,null); 
+           
+            int classPathLength = classpathEntries.length;
+            IClasspathEntry[] newClasspathEntryArray = new IClasspathEntry[classPathLength+2];
+            for (int i = 0; i < classpathEntries.length; i++) {
+                newClasspathEntryArray[i]= classpathEntries[i];
+            }
+           
+            // add new Class Path Entries of junit.jar and test directory
+            newClasspathEntryArray[classPathLength] = newClasspathEntry;
+            newClasspathEntryArray[classPathLength+1] = junitClasspathEntry;
+           
+            javaProj.setRawClasspath(newClasspathEntryArray,monitor);
+           
+            } catch (JavaModelException e) {
+                throw new ExecutionException(e.getMessage());
+            } catch (IOException e) {
+            	 throw new ExecutionException(e.getMessage());
+			}
+        }
+
+        return status;
+       
+    }
+   
+    /**
+     * Copy the Junit jar from the framework location to the project classpath.
+     * @param workspace
+     * @return absolute path location of the copying file
+     * @throws ExecutionException
+     * @throws IOException
+     */
+    private String CopyJUnitJarToProject(String workspace) throws ExecutionException, IOException {
+    	File relativeWebInfJunitFile = new File(FileUtils.addAnotherNodeToPath(
+    												J2EEUtils.getWebInfPath(project).toOSString(),
+    												Axis2CoreUIMessages.DIR_LIB+File.separator+
+    												Axis2ConsumptionUIMessages.JUNIT_JAR));
+    	
+    	File obsaluteWebInfJunitFile = new File(FileUtils.addAnotherNodeToPath(
+    														workspace, 
+    														relativeWebInfJunitFile.toString()));
+		FileUtils.copy(getFrameworkJunitFile(), obsaluteWebInfJunitFile);
+		return obsaluteWebInfJunitFile.getAbsolutePath();
+	}
+
+    /**
+     * returns the Framework JUnit File location.
+     * @return
+     * @throws ExecutionException
+     */
+	private File getFrameworkJunitFile() throws ExecutionException {
+    	IPath junitJarPath=BundleUtils.getJarredPluginPath(Axis2ConsumptionUIMessages.JUNIT_BUNDLE);
+    	if (junitJarPath != null){
+    		return new File(FileUtils.addAnotherNodeToPath(junitJarPath.toOSString(),
+    						Axis2ConsumptionUIMessages.JUNIT_JAR));
+    	}else{
+    		throw new ExecutionException(Axis2ConsumptionUIMessages.ERROR_JUNIT_JAR_NOT_FOUND);
+    	}
+    }
+
+	/**
+	 * returns the path to the newly generated test folder 
+	 * @param project
+	 * @param workspace
+	 * @return IPath to the test folder
+	 */
+    private IPath getPathToTestFolder(IProject project, String workspace) {
+        String pathToTest = project.getFullPath().toOSString() + File.separator
+                            + Axis2CoreUIMessages.DIR_TEST;
+        IPath pathToTestFolder = new Path(pathToTest);
+        return pathToTestFolder;
+    }
+   
+}
diff --git a/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/consumption/core/messages/Axis2ConsumptionUI.properties b/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/consumption/core/messages/Axis2ConsumptionUI.properties
index 4eff5dd..73e6dda 100644
--- a/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/consumption/core/messages/Axis2ConsumptionUI.properties
+++ b/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/consumption/core/messages/Axis2ConsumptionUI.properties
@@ -13,6 +13,7 @@
 #										 runtime to the framework for 168762
 # 20070511   186440 sandakith@wso2.com - Lahiru Sandakith fix 186440
 # 20070517   187307 sandakith@wso2.com - Lahiru Sandakith
+# 20070518        187311 sandakith@wso2.com - Lahiru Sandakith, Fixing test resource addition
 ###############################################################################
 
 
@@ -36,3 +37,4 @@
 ERROR_INVALID_FILE_READ_WRITEL=Exception occurred while reading or writing files {0}
 ERROR_INVALID_WSDL_FILE_READ_WRITEL=Exception occurred while reading or writing WSDL {0}
 ERROR_CODEGEN_EXCEPTION=Exception occurred while code generation for WSDL {0}
+ERROR_JUNIT_JAR_NOT_FOUND=Exception occurred while copying junit.jar
\ No newline at end of file
diff --git a/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/consumption/core/messages/Axis2ConsumptionUIMessages.java b/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/consumption/core/messages/Axis2ConsumptionUIMessages.java
index 04686e6..df1e515 100644
--- a/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/consumption/core/messages/Axis2ConsumptionUIMessages.java
+++ b/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/consumption/core/messages/Axis2ConsumptionUIMessages.java
@@ -13,6 +13,7 @@
  * 20070426   183046 sandakith@wso2.com - Lahiru Sandakith
  * 20070511   186440 sandakith@wso2.com - Lahiru Sandakith fix 186440
  * 20070517   187307 sandakith@wso2.com - Lahiru Sandakith
+ * 20070518        187311 sandakith@wso2.com - Lahiru Sandakith, Fixing test resource addition
  *******************************************************************************/
 package org.eclipse.jst.ws.axis2.consumption.core.messages;
 
@@ -28,6 +29,8 @@
 	public static final String DIR_DOT_PLUGINS=".plugins";						//$NON-NLS-1$
 	public static final String AXIS2_PROJECT="org.eclipse.jst.ws.axis2";		//$NON-NLS-1$
 	public static final String CODEGEN_RESULTS="codegen";						//$NON-NLS-1$
+	public static final String JUNIT_JAR="junit.jar";							//$NON-NLS-1$
+	public static final String JUNIT_BUNDLE="org.junit";						//$NON-NLS-1$
 	
 	private Axis2ConsumptionUIMessages() {
 		// Do not instantiate
@@ -53,6 +56,7 @@
 	public static String ERROR_INVALID_FILE_READ_WRITEL;
 	public static String ERROR_INVALID_WSDL_FILE_READ_WRITEL;
 	public static String ERROR_CODEGEN_EXCEPTION;
+	public static String ERROR_JUNIT_JAR_NOT_FOUND;
 	
 	static {
 		NLS.initializeMessages(BUNDLE_NAME, Axis2ConsumptionUIMessages.class);
diff --git a/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/creation/core/data/DataModel.java b/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/creation/core/data/DataModel.java
index 78ad0b3..0400d62 100644
--- a/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/creation/core/data/DataModel.java
+++ b/bundles/org.eclipse.jst.ws.axis2.consumption.core/src/org/eclipse/jst/ws/axis2/creation/core/data/DataModel.java
@@ -11,6 +11,7 @@
  * -------- -------- -----------------------------------------------------------
  * 20070110   168762 sandakith@wso2.com - Lahiru Sandakith, Initial code to introduse the Axis2 
  * 										  runtime to the framework for 168762
+ * 20070518   187311 sandakith@wso2.com - Lahiru Sandakith, Fixing test resource addition
  *******************************************************************************/
 package org.eclipse.jst.ws.axis2.creation.core.data;
 
@@ -30,7 +31,6 @@
 	private boolean generateServerSideInterface;
     private boolean serverXMLCheck;
 	private boolean generateAllCheck;
-	private boolean testCaseCheck;
 	private String databindingType;
 	private String namespaseToPackageMapping;
 
@@ -131,14 +131,6 @@
 		super.setServiceName(serviceName);
 	}
 
-	public boolean isTestCaseCheck() {
-		return testCaseCheck;
-	}
-
-	public void setTestCaseCheck(boolean testCaseCheck) {
-		this.testCaseCheck = testCaseCheck;
-	}
-
 	public String getPackageText() {
 		return super.getPackageText();
 	}
diff --git a/bundles/org.eclipse.jst.ws.axis2.consumption.ui/src/org/eclipse/jst/ws/internal/axis2/consumption/ui/wsrt/Axis2WebServiceClient.java b/bundles/org.eclipse.jst.ws.axis2.consumption.ui/src/org/eclipse/jst/ws/internal/axis2/consumption/ui/wsrt/Axis2WebServiceClient.java
index 592697b..22ae8a0 100644
--- a/bundles/org.eclipse.jst.ws.axis2.consumption.ui/src/org/eclipse/jst/ws/internal/axis2/consumption/ui/wsrt/Axis2WebServiceClient.java
+++ b/bundles/org.eclipse.jst.ws.axis2.consumption.ui/src/org/eclipse/jst/ws/internal/axis2/consumption/ui/wsrt/Axis2WebServiceClient.java
@@ -11,13 +11,16 @@
  * -------- -------- -----------------------------------------------------------
  * 20070230   168762 sandakith@wso2.com - Lahiru Sandakith, Initial code to introduse the Axis2 
  * 										  runtime to the framework for 168762
+ * 20070518   187311 sandakith@wso2.com - Lahiru Sandakith, Fixing test resource addition
  *******************************************************************************/
 package org.eclipse.jst.ws.internal.axis2.consumption.ui.wsrt;
 
 import java.util.Vector;
 
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.jst.ws.axis2.consumption.core.command.Axis2ClientCodegenCommand;
 import org.eclipse.jst.ws.axis2.consumption.core.command.Axis2ClientDefaultingCommand;
+import org.eclipse.jst.ws.axis2.consumption.core.command.Axis2ClientTestCaseIntegrateCommand;
 import org.eclipse.jst.ws.axis2.consumption.core.command.Axis2WebservicesServerCommand;
 import org.eclipse.jst.ws.axis2.consumption.core.data.DataModel;
 import org.eclipse.jst.ws.internal.axis2.consumption.ui.task.DefaultsForHTTPBasicAuthCommand;
@@ -58,6 +61,8 @@
 		commands.add(new Axis2ClientDefaultingCommand(model,this));
 		commands.add(new Axis2WebservicesServerCommand(model, project));
 		commands.add(new Axis2ClientCodegenCommand(model));
+		commands.add(new Axis2ClientTestCaseIntegrateCommand(
+				ResourcesPlugin.getWorkspace().getRoot().getProject(project),model));
 		
 		return new SimpleCommandFactory(commands);
 	}
diff --git a/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/core/plugin/messages/Axis2CoreUIMessages.java b/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/core/plugin/messages/Axis2CoreUIMessages.java
index 6dc2822..b207ad9 100644
--- a/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/core/plugin/messages/Axis2CoreUIMessages.java
+++ b/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/core/plugin/messages/Axis2CoreUIMessages.java
@@ -16,6 +16,7 @@
  * 20070511   186440 sandakith@wso2.com - Lahiru Sandakith fix 186440
  * 20070510   172926 sandakith@wso2.com - Lahiru Sandakith, Fix 172926 Use Util Classes
  * 20070517   187307 sandakith@wso2.com - Lahiru Sandakith, Fix 187307 Property File Fix
+ * 20070518        187311 sandakith@wso2.com - Lahiru Sandakith, Fixing test resource addition
  *******************************************************************************/
 package org.eclipse.jst.ws.axis2.core.plugin.messages;
 
@@ -28,6 +29,7 @@
 	public static final String DIR_TEMPWAR="tempwar";							//$NON-NLS-1$
 	public static final String DIR_EXPLOADED_TEMPWAR="exploadedwar";			//$NON-NLS-1$
 	public static final String DIR_LIB="lib";									//$NON-NLS-1$
+	public static final String DIR_TEST="test";									//$NON-NLS-1$
 	public static final String FILE_AXIS2_WAR="axis2.war";						//$NON-NLS-1$
 	public static final String  NULL="";										//$NON-NLS-1$
 	public static final String ADB="adb";										//$NON-NLS-1$
diff --git a/bundles/org.eclipse.jst.ws.axis2.creation.core/src/org/eclipse/jst/ws/axis2/creation/core/command/Axis2WSDL2JavaCommand.java b/bundles/org.eclipse.jst.ws.axis2.creation.core/src/org/eclipse/jst/ws/axis2/creation/core/command/Axis2WSDL2JavaCommand.java
index 3613578..25f46f0 100644
--- a/bundles/org.eclipse.jst.ws.axis2.creation.core/src/org/eclipse/jst/ws/axis2/creation/core/command/Axis2WSDL2JavaCommand.java
+++ b/bundles/org.eclipse.jst.ws.axis2.creation.core/src/org/eclipse/jst/ws/axis2/creation/core/command/Axis2WSDL2JavaCommand.java
@@ -13,6 +13,7 @@
  * 										  runtime to the framework for 168762
  * 20070426   183046 sandakith@wso2.com - Lahiru Sandakith
  * 20070507   184729 sandakith@wso2.com - Lahiru Sandakith
+ * 20070518   187311 sandakith@wso2.com - Lahiru Sandakith, Fixing test resource addition
  *******************************************************************************/
 package org.eclipse.jst.ws.axis2.creation.core.command;
 
@@ -77,7 +78,7 @@
             false,	//sync always false
             true,   //is serverside true
             model.isServerXMLCheck(),
-            model.isTestCaseCheck(),
+            false,  //No test case with out stub
             model.isGenerateAllCheck(),
             (model.getServiceName()!=null)?model.getServiceName():null,
             (model.getPortName()!=null)?model.getPortName():null,
diff --git a/bundles/org.eclipse.jst.ws.axis2.creation.ui/src/org/eclipse/jst/ws/internal/axis2/creation/ui/widgets/skeleton/WSDL2JAVASkelConfigWidget.java b/bundles/org.eclipse.jst.ws.axis2.creation.ui/src/org/eclipse/jst/ws/internal/axis2/creation/ui/widgets/skeleton/WSDL2JAVASkelConfigWidget.java
index 52fd5b4..426c949 100644
--- a/bundles/org.eclipse.jst.ws.axis2.creation.ui/src/org/eclipse/jst/ws/internal/axis2/creation/ui/widgets/skeleton/WSDL2JAVASkelConfigWidget.java
+++ b/bundles/org.eclipse.jst.ws.axis2.creation.ui/src/org/eclipse/jst/ws/internal/axis2/creation/ui/widgets/skeleton/WSDL2JAVASkelConfigWidget.java
@@ -12,6 +12,7 @@
  * 20070110   168762 sandakith@wso2.com - Lahiru Sandakith, Initial code to introduse the Axis2 
  * 										  runtime to the framework for 168762
  * 20070425   183046 sandakith@wso2.com - Lahiru Sandakith
+ * 20070518   187311 sandakith@wso2.com - Lahiru Sandakith, Fixing test resource addition
  *******************************************************************************/
 package org.eclipse.jst.ws.internal.axis2.creation.ui.widgets.skeleton;
 
@@ -62,7 +63,6 @@
 	//check box for server side interface
 	private Button generateServerSideInterfaceCheckBoxButton;
 	private Button generateAllCheckBoxButton;
-	private Button testCaseCheckBoxButton;
 	private Combo databindingTypeCombo;
 	// Text box to have the portname
 	private Combo portNameCombo;
@@ -175,24 +175,6 @@
 		gd.horizontalSpan = 3;
 		fillLabel4 = new Label(mainComp, SWT.HORIZONTAL | SWT.NULL);
 
-		// generate test case option
-		gd = new GridData(GridData.FILL_HORIZONTAL);
-		gd.horizontalSpan = 3;
-		testCaseCheckBoxButton = new Button(mainComp, SWT.CHECK);
-		testCaseCheckBoxButton.setLayoutData(gd);
-		testCaseCheckBoxButton
-		.setText(Axis2CreationUIMessages.LABEL_GENERATE_TESTCASE_CAPTION);
-		testCaseCheckBoxButton.setSelection(ServerModel.isServiceTestcase());
-		model.setTestCaseCheck(ServerModel.isServiceTestcase());
-		testCaseCheckBoxButton.addSelectionListener(new SelectionListener() {
-			public void widgetSelected(SelectionEvent e) {
-				model.setTestCaseCheck(testCaseCheckBoxButton.getSelection());
-			}
-
-			public void widgetDefaultSelected(SelectionEvent e) {
-			}
-		});
-
 		model.setServerXMLCheck(true);
 
 		//the server side interface option
@@ -333,7 +315,6 @@
 		model.setGenerateAllCheck(generateAllCheckBoxButton.getSelection());
 		model.setGenerateServerSideInterface(
 				generateServerSideInterfaceCheckBoxButton.getSelection());
-		model.setTestCaseCheck(testCaseCheckBoxButton.getSelection());
 		model.setNamespaseToPackageMapping(getNs2PkgMapping());
 	}