1 /*
2  *  CVS: $Id: GameFileReaderTest.java,v 1.7 2004/07/22 18:02:08 marcus Exp $
3  * 
4  *  This file is part of Zuul.
5  *
6  *  Zuul is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10 *
11 *  Zuul is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with Zuul; if not, write to the Free Software
18 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 * 
20 *  Copyrigth 2004 by mthies2s
21 * 
22 */
23
24package org.jzuul.engine.test;
25
26import java.io.FileInputStream;
27import java.io.FileNotFoundException;
28import java.io.IOException;
29
30import org.jdom.JDOMException;
31import org.jzuul.engine.exceptions.ConnectAllRoomsFailed;
32import org.jzuul.engine.exceptions.NoSuchRoomException;
33
34import org.jzuul.engine.Engine;
35import org.jzuul.engine.GameFileReader;
36import junit.framework.TestCase;
37
38/**
39 * 
40 */
41public class GameFileReaderTest extends TestCase {
42
43    /**
44     * Constructor for GameFileReaderTest.
45     * @param arg0
46     */
47    public GameFileReaderTest(String arg0) {
48        super(arg0);
49        Engine.DEBUG = 0;
50    }
51
52    public void testGameFileReader() {
53        GameFileReader malformed = null;
54        try {
55            malformed = new GameFileReader(new FileInputStream("org/jzuul/engine/test/resources/malformed.xml"));
56            fail("Exception expected");
57        } catch (Exception e) {
58        }
59        assertNull(malformed);
60
61        GameFileReader wellformed = null;
62        try {
63            wellformed = new GameFileReader(new FileInputStream("org/jzuul/engine/test/resources/wellformed.xml"));
64        } catch (Exception e) {
65            fail("Not expected " + e.getMessage()); // should never happen
66        }
67        assertNotNull(wellformed);
68
69        //without dtd:
70        wellformed = null;
71        try {
72            wellformed = new GameFileReader(new FileInputStream("org/jzuul/engine/test/resources/wellformed.xml"),false);
73        } catch (Exception e) {
74            fail("Not expected " + e.getMessage()); // should never happen
75        }
76        assertNotNull(wellformed);
77
78
79
80    }
81
82    public void testGetMap() {
83        GameFileReader r = null;
84        try {
85            r = new GameFileReader(new FileInputStream("org/jzuul/engine/test/resources/circle.xml"));
86        } catch (Exception e) {
87            fail("Not expected " + e.getMessage()); // should never happen
88            
89        }
90        assertNotNull(r);
91        try {
92            assertNotNull(r.getMap("default"));
93        } catch (ConnectAllRoomsFailed e1) {
94            fail("not expected " + e1.getMessage());
95        } catch (NoSuchRoomException e1) {
96            fail("not expected " + e1.getMessage() );
97        }
98        r = null;
99
00        try {
01            r = new GameFileReader(new FileInputStream("org/jzuul/engine/test/resources/missing_room.xml"));
02            r.getMap("default").verifyMap();
03            fail("exception expected");
04        } catch (FileNotFoundException e2) {
05            fail("not expected " + e2.getMessage());
06        } catch (IOException e2) {
07            fail("not expected " + e2.getMessage());
08        } catch (JDOMException e2) {
09            fail("not expected " + e2.getMessage());
10        } catch (ConnectAllRoomsFailed e1) {
11            fail("not expected " + e1.getMessage());
12        } catch (NoSuchRoomException e1) {
13            // this is what we expect
14        }
15
16        assertNotNull(r);
17        
18
19    }
20
21}
22