01: /*
02: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
03: *
04: * This file is part of TransferCM.
05: *
06: * TransferCM is free software; you can redistribute it and/or modify it under the
07: * terms of the GNU General Public License as published by the Free Software
08: * Foundation; either version 2 of the License, or (at your option) any later
09: * version.
10: *
11: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14: * details.
15: *
16: * You should have received a copy of the GNU General Public License along with
17: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18: * Fifth Floor, Boston, MA 02110-1301 USA
19: */
20:
21: package com.methodhead.res;
22:
23: import java.util.*;
24: import java.io.*;
25: import junit.framework.*;
26: import org.apache.log4j.*;
27: import com.methodhead.persistable.*;
28: import com.methodhead.test.*;
29: import org.apache.cactus.*;
30: import servletunit.struts.*;
31: import org.apache.struts.*;
32:
33: public class DefaultResPolicyTest extends CactusStrutsTestCase {
34:
35: static {
36: TestUtils.initLogger();
37: TestUtils.initDb();
38: }
39:
40: private DefaultResPolicy policy = null;
41: private FileManager fileManager = null;
42: private File file = null;
43:
44: public DefaultResPolicyTest(String name) {
45: super (name);
46: }
47:
48: public void setUp() {
49: //setLogLevel( Level.DEBUG );
50: try {
51: } catch (Exception e) {
52: fail(e.getMessage());
53: }
54: }
55:
56: public void tearDown() {
57: }
58:
59: public void testInitFileManager() {
60: try {
61: policy = new DefaultResPolicy();
62:
63: //
64: // force the request messages to be the context messages (struts will do this when an action is envoked)
65: //
66: request.setAttribute(Globals.MESSAGES_KEY, session
67: .getServletContext().getAttribute(
68: Globals.MESSAGES_KEY));
69:
70: //
71: // get the file manager and make sure its set up right
72: //
73: fileManager = new FileManager();
74: policy.initFileManager(request, fileManager);
75: assertNotNull(fileManager);
76:
77: file = fileManager.getFileForPath("Files");
78: assertNotNull(file);
79: assertEquals(request.getSession().getServletContext()
80: .getRealPath(""), file.getAbsolutePath());
81: } catch (Exception e) {
82: e.printStackTrace();
83: fail();
84: }
85: }
86: }
|