/*
 * Created on Jun 19, 2004
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.apache.jmeter.save;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStreamWriter;

import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.collections.HashTree;

/**
 * @author mstover
 * 
 * To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Generation - Code and Comments
 */
public class TestSaveService extends JMeterTestCase {
	private static final String[] FILES = new String[] { "AssertionTestPlan.jmx", "AuthManagerTestPlan.jmx",
			"HeaderManagerTestPlan.jmx", "InterleaveTestPlan2.jmx", "InterleaveTestPlan.jmx", "LoopTestPlan.jmx",
			"Modification Manager.jmx", "OnceOnlyTestPlan.jmx", "proxy.jmx", "ProxyServerTestPlan.jmx",
			"SimpleTestPlan.jmx", "GuiTest.jmx", };

	private static boolean saveOut = JMeterUtils.getPropDefault("testsaveservice.saveout", false);

	public TestSaveService(String name) {
		super(name);
	}

	public void setUp() {
	}

	public void testLoadAndSave() throws Exception {
		byte[] original = new byte[1000000];

		boolean failed = false; // Did a test fail?

		for (int i = 0; i < FILES.length; i++) {
			InputStream in = new FileInputStream(new File("testfiles/" + FILES[i]));
			int len = in.read(original);

			in.close();

			in = new ByteArrayInputStream(original, 0, len);
			HashTree tree = SaveService.loadTree(in);

			in.close();

			ByteArrayOutputStream out = new ByteArrayOutputStream(1000000);

			OutputStreamWriter outs = new OutputStreamWriter(out);
			SaveService.saveTree(tree, outs);
			outs.close();// Make sure all the data is flushed out
			out.close();

			// We only check the length of the result. Comparing the
			// actual result (out.toByteArray==original) will usually
			// fail, because the order of the properties within each
			// test element may change. Comparing the lengths should be
			// enough to detect most problem cases...
            int outsz=out.size();
            // Allow for input in CRLF and output in LF only
            int lines=0;
            byte ba[]=out.toByteArray();
            for(int j=0;j<ba.length;j++) {
                if (ba[j] == '\n'){
                    lines++;
                }
            }
			if (len != outsz && len != outsz+lines) {
				failed = true;
				System.out.println();
				System.out.println("Loading file testfiles/" + FILES[i] + " and "
						+ "saving it back changes its size from " + len + " to " + outsz + ".");
                System.out.println("Diff "+(len-outsz)+" lines "+lines);
				if (saveOut) {
					String outfile = "testfiles/" + FILES[i] + ".out";
					System.out.println("Write " + outfile);
					FileOutputStream outf = new FileOutputStream(new File(outfile));
					outf.write(out.toByteArray());
					outf.close();
					System.out.println("Wrote " + outfile);
				}
			}

			// Note this test will fail if a property is added or
			// removed to any of the components used in the test
			// files. The way to solve this is to appropriately change
			// the test file.
		}
		if (failed) // TODO make these separate tests?
		{
			fail("One or more failures detected");
		}
	}
}

@@ -4,163 +4,619 @@
  * C
-reated on Jun 19, 2004%0A *%0A * To change the template for this generated file go to%0A * Window - Preferences - Java - Code Generation - Code and Comments
+opyright 2005 The Apache Software Foundation.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A * 
 %0A */%0A
+%0A
 pack
@@ -1039,141 +1039,8 @@
  * %0A
- * To change the template for this generated type comment go to Window -%0A * Preferences - Java - Code Generation - Code and Comments%0A
  */%0A
@@ -1602,35 +1602,8 @@
 %09%7D%0A%0A
-%09public void setUp() %7B%0A%09%7D%0A%0A
 %09pub

Add ASF L V 2; remove empty setUp() method