Gridarta Editor
DefaultMapManagerTest.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.mapmanager;
21 
22 import java.awt.Point;
23 import java.io.File;
24 import java.io.IOException;
33 import net.sf.gridarta.utils.Size2D;
34 import org.junit.Test;
35 
40 public class DefaultMapManagerTest {
41 
47  @Test
48  public void testRevertResizedMap() throws DuplicateArchetypeException, IOException {
49  final File file = File.createTempFile("gridarta", null);
50  try {
51  final TestMapControlCreator testMapControlCreator = new TestMapControlCreator();
52  final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator();
53  final Size2D originalSize = new Size2D(2, 1);
54  final Size2D newSize = new Size2D(1, 2);
55  final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(testMapControlCreator.getPathManager().getMapFile(file), "test", originalSize);
57  final MapManager<TestGameObject, TestMapArchObject, TestArchetype> mapManager = testMapControlCreator.getMapManager();
58 
59  mapModel.beginTransaction("test");
60  try {
61  mapModelHelper.insertFloor(mapModel, new Point(1, 0));
62  } finally {
63  mapModel.endTransaction();
64  }
65  mapControl.save();
66  TestMapModelHelper.checkMapContents(mapModel, "|floor");
67 
68  mapModel.beginTransaction("test");
69  try {
70  mapModel.getMapArchObject().setMapSize(newSize);
71  } finally {
72  mapModel.endTransaction();
73  }
74  mapModel.beginTransaction("test");
75  try {
76  mapModelHelper.insertFloor(mapModel, new Point(0, 1));
77  } finally {
78  mapModel.endTransaction();
79  }
80  TestMapModelHelper.checkMapContents(mapModel, "", "floor");
81 
82  mapModel.beginTransaction("test");
83  try {
84  mapManager.revert(mapControl);
85  } finally {
86  mapModel.endTransaction();
87  }
88  TestMapModelHelper.checkMapContents(mapModel, "|floor");
89  } finally {
90  //noinspection ResultOfMethodCallIgnored
91  file.delete();
92  }
93  }
94 
95 }
void save()
Saves the map to a file.
A MapModel reflects the data of a map.
Definition: MapModel.java:75
A MapManager manages all opened maps.
Definition: MapManager.java:37
void endTransaction()
End a transaction.
Helper class for creating MapModel instances for regression tests.
Helper class for creating MapControl instances for regression tests.
MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath)
Returns a MapFile instance from an AbsoluteMapPath.
A MapArchObject implementation for testing purposes.
MapModel< G, A, R > getMapModel()
Returns the map model.
TestGameObject insertFloor(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point)
Inserts a floorArchetype game object into a map model.
void testRevertResizedMap()
A map that has been resized must still be revertable.
void revert(@NotNull MapControl< G, A, R > mapControl)
Reverts one map.
Base package of all Gridarta classes.
An Exception indicating that an Archetype name is not unique.
GameObjects are the objects based on Archetypes found on maps.
static void checkMapContents(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final String... lines)
Checks for expected MapModel&#39;s contents.
TestMapModelHelper newMapModelCreator()
Creates a new TestMapModelHelper instance.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35
An Archetype implementation for testing purposes.
A GameObject implementation for testing purposes.
void beginTransaction(@NotNull String name)
Starts a new transaction.
MapManager< TestGameObject, TestMapArchObject, TestArchetype > getMapManager()
Returns the MapManager.
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30
MapControl< TestGameObject, TestMapArchObject, TestArchetype > newMapControl(@Nullable final MapFile mapFile, @NotNull final String mapName, @NotNull final Size2D mapSize)
Creates a new map control.