001: /*
002: * <copyright>
003: *
004: * Copyright 2001-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026: package org.cougaar.tools.csmart.util.parser;
027:
028: import junit.framework.*;
029: import java.io.*;
030: import java.util.*;
031:
032: public class SimpleParserTest extends TestCase {
033: File testFile = null; // handle to test file, to remove when done
034: private static final String testFileName = "simpleParser.dat";
035: private SimpleParser sp = new SimpleParser();
036:
037: public SimpleParserTest(String name) {
038: super (name);
039: }
040:
041: // Build the test file from here, so we dont need to check it in
042: // and dont need to make assumptions about the config path, cwd
043: // of where the tests are run from
044: protected void setUp() {
045: try {
046: testFile = new File(testFileName);
047: } catch (NullPointerException e) {
048: }
049: try {
050: PrintWriter writer = new PrintWriter(new FileOutputStream(
051: testFile));
052: writer
053: .println("# This is a test script used by JUnit to test the Simple Parser");
054: writer.println("# ");
055: writer
056: .println("# *********** DO NOT MODIFY!!!!! Modifying will break the regression testing.");
057: writer.println("");
058: writer
059: .println("Asset One, 1, 2, 3, 4, 5, 6, AA, BB, CC, DD");
060: writer.close();
061: } catch (SecurityException e) {
062: fail("Got exception writing test file: " + e);
063: } catch (FileNotFoundException e) {
064: fail("Got exception writing test file: " + e);
065: }
066:
067: try {
068: sp.load(testFileName);
069: sp.parse();
070: } catch (IOException e) {
071: }
072: }
073:
074: protected void tearDown() {
075: if (testFile != null) {
076: try {
077: testFile.delete();
078: } catch (SecurityException e) {
079: }
080: }
081: }
082:
083: public void testParse() {
084: ArrayList a = sp.getList();
085: assertNotNull(a);
086: }
087:
088: public void testEntires() {
089: ArrayList a = sp.getList();
090:
091: ArrayList b = null;
092:
093: b = (ArrayList) a.get(0);
094: // Test the first entry (Asset One)
095: assertEquals("Asset One", (String) b.get(0));
096: assertEquals("1", (String) b.get(1));
097: assertEquals("2", (String) b.get(2));
098: assertEquals("3", (String) b.get(3));
099: assertEquals("4", (String) b.get(4));
100: assertEquals("5", (String) b.get(5));
101: assertEquals("6", (String) b.get(6));
102: assertEquals("AA", (String) b.get(7));
103: assertEquals("BB", (String) b.get(8));
104: assertEquals("CC", (String) b.get(9));
105: assertEquals("DD", (String) b.get(10));
106:
107: }
108:
109: public static Test suite() {
110: return new TestSuite(SimpleParserTest.class);
111: }
112:
113: public static void main(String[] args) {
114: junit.textui.TestRunner.run(suite());
115: }
116:
117: } // SimpleParserTest
|