001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.gl.batch;
017:
018: import java.io.File;
019:
020: import org.kuali.kfs.context.KualiTestBase;
021: import org.kuali.kfs.context.SpringContext;
022: import org.kuali.module.gl.batch.collector.CollectorInputFileType;
023: import org.kuali.module.gl.batch.collector.CollectorStep;
024: import org.kuali.test.ConfigureContext;
025:
026: /**
027: * Tests the CollecterStep. DEPENDENCIES: Collector card xml file transaction1.xml must be in /opt/kuali/dev/staging/collector/ this
028: * file can be obtained by running the project's ant dist-local, or copying from
029: * build/externalConfigDirectory/static/staging/collector/
030: */
031: @ConfigureContext
032: public class CollectorStepTest extends KualiTestBase {
033: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
034: .getLogger(CollectorStepTest.class);
035:
036: /**
037: * Constructs a CollectorStepTest instance
038: */
039: public CollectorStepTest() {
040: super ();
041: }
042:
043: /**
044: * Creats .done file for test input file.
045: *
046: * @see junit.framework.TestCase#setUp()
047: */
048: @Override
049: protected void setUp() throws Exception {
050: super .setUp();
051:
052: // warren: this is just testing code to list out the contents of the staging directory
053: File directory = new File("/opt/kuali/unt/staging/");
054: if (directory.exists() && directory.isDirectory()) {
055: File[] files = directory.listFiles();
056: for (File file : files) {
057: System.err.println("TESTING: " + file.getName());
058: if (file.isDirectory()) {
059: File[] files2 = file.listFiles();
060: for (File file2 : files2) {
061: System.err.println("TESTING2: "
062: + file2.getName());
063: }
064: }
065: }
066: }
067:
068: String doneFileName = generateDoneFileName();
069:
070: File doneFile = new File(doneFileName);
071: if (!doneFile.exists()) {
072: doneFile.createNewFile();
073: }
074: }
075:
076: /**
077: * Deletes the file created in setUp()
078: */
079: protected void deleteDoneFile() {
080: File doneFile = new File(generateDoneFileName());
081: if (doneFile.exists()) {
082: doneFile.delete();
083: }
084: }
085:
086: /**
087: * Determines if the .done file with the expected file name exists
088: *
089: * @return true if the done file exists, false otherwise
090: */
091: protected boolean isDoneFileExists() {
092: File doneFile = new File(generateDoneFileName());
093: return doneFile.exists();
094: }
095:
096: /**
097: * Generates the standard name of the .done file to check
098: *
099: * @return the full path and name of the done file to check
100: */
101: protected String generateDoneFileName() {
102: return SpringContext.getBean(CollectorInputFileType.class)
103: .getDirectoryPath()
104: + "/gl_collector1.done";
105: }
106:
107: /**
108: * Tests the whole step completes successfully.
109: */
110: // @RelatesTo(RelatesTo.JiraIssue.KULUT29)
111: public void testAll() throws Exception {
112: try {
113: CollectorStep collectorStep = SpringContext
114: .getBean(CollectorStep.class);
115: boolean goodExit = collectorStep.execute(getClass()
116: .getName());
117:
118: assertTrue("collector step did not exit with pass",
119: goodExit);
120: assertFalse("done file was not removed", isDoneFileExists());
121: } finally {
122: deleteDoneFile();
123: }
124: }
125: }
|