1
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
41public class GameFileReaderTest extends TestCase {
42
43
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()); }
67 assertNotNull(wellformed);
68
69 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()); }
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());
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 }
15
16 assertNotNull(r);
17
18
19 }
20
21}
22