001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.dependencyfinder.webwork;
034:
035: import java.util.*;
036: import java.io.*;
037:
038: import junit.framework.*;
039:
040: import com.jeantessier.dependency.*;
041: import com.jeantessier.classreader.*;
042:
043: import com.opensymphony.xwork.*;
044:
045: public class TestExtractAction extends TestCase {
046: private Map application;
047:
048: private ExtractAction action;
049:
050: protected void setUp() throws Exception {
051: super .setUp();
052:
053: application = new HashMap();
054: application.put("source", "classes" + File.separator
055: + "test.class");
056:
057: action = new ExtractAction();
058: }
059:
060: public void testFirstExtract() {
061: action.setApplication(application);
062: String result = action.doExtract();
063:
064: assertEquals("Result", Action.SUCCESS, result);
065: assertNotNull("Missing dispatcher", application
066: .get("dispatcher"));
067: assertNotNull("Missing factory", application.get("factory"));
068: assertNotNull("Missing monitor", application.get("monitor"));
069: }
070:
071: public void testUpdate() {
072: ClassfileLoaderDispatcher dispatcher = new ModifiedOnlyDispatcher(
073: ClassfileLoaderEventSource.DEFAULT_DISPATCHER);
074: NodeFactory factory = new NodeFactory();
075: CodeDependencyCollector collector = new CodeDependencyCollector(
076: factory);
077: DeletingVisitor deletingVisitor = new DeletingVisitor(factory);
078: Monitor monitor = new Monitor(collector, deletingVisitor);
079:
080: application.put("dispatcher", dispatcher);
081: application.put("factory", factory);
082: application.put("monitor", monitor);
083:
084: action.setApplication(application);
085: String result = action.doUpdate();
086:
087: assertEquals("Result", Action.SUCCESS, result);
088: assertSame("Dispatcher", dispatcher, application
089: .get("dispatcher"));
090: assertSame("Factory", factory, application.get("factory"));
091: assertSame("Monitor", monitor, application.get("monitor"));
092: }
093:
094: public void testExtract() {
095: ClassfileLoaderDispatcher dispatcher = new ModifiedOnlyDispatcher(
096: ClassfileLoaderEventSource.DEFAULT_DISPATCHER);
097: NodeFactory factory = new NodeFactory();
098: CodeDependencyCollector collector = new CodeDependencyCollector(
099: factory);
100: DeletingVisitor deletingVisitor = new DeletingVisitor(factory);
101: Monitor monitor = new Monitor(collector, deletingVisitor);
102:
103: application.put("dispatcher", dispatcher);
104: application.put("factory", factory);
105: application.put("monitor", monitor);
106:
107: action.setApplication(application);
108: String result = action.doExtract();
109:
110: assertEquals("Result", Action.SUCCESS, result);
111: assertNotSame("Dispatcher", dispatcher, application
112: .get("dispatcher"));
113: assertNotSame("Factory", factory, application.get("factory"));
114: assertNotSame("Monitor", monitor, application.get("monitor"));
115: }
116: }
|