diff --git a/test/main/TestAll.java b/test/main/TestAll.java
index dea270d34..316757d47 100644
--- a/test/main/TestAll.java
+++ b/test/main/TestAll.java
@@ -27,17 +27,17 @@
***********************************************************************************/
package main;
+import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
-import com.projectswg.common.debug.Log;
-import com.projectswg.common.debug.Log.LogLevel;
-import com.projectswg.common.debug.log_wrapper.ConsoleLogWrapper;
+import com.projectswg.common.control.IntentManager;
import network.encryption.TestEncryption;
import resources.TestResources;
+import resources.server_info.DataManager;
import services.TestServices;
@RunWith(Suite.class)
@@ -50,7 +50,14 @@ public class TestAll {
@BeforeClass
public static void initLog() {
- Log.addWrapper(new ConsoleLogWrapper(LogLevel.VERBOSE));
+ IntentManager.getInstance().initialize();
+ DataManager.initialize();
+ }
+
+ @AfterClass
+ public static void terminateLog() {
+ DataManager.terminate();
+ IntentManager.getInstance().terminate();
}
}
diff --git a/test/resources/persistable/TestPersistable.java b/test/resources/persistable/TestPersistable.java
index 41e09213b..7607a6a7a 100644
--- a/test/resources/persistable/TestPersistable.java
+++ b/test/resources/persistable/TestPersistable.java
@@ -35,7 +35,8 @@ import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses({
TestSimplePersistable.class,
TestSWGPersistable.class,
- TestMailPersistable.class
+ TestMailPersistable.class,
+ TestResourcePersistable.class
})
public class TestPersistable {
diff --git a/test/resources/persistable/TestResourcePersistable.java b/test/resources/persistable/TestResourcePersistable.java
new file mode 100644
index 000000000..3dce93d5f
--- /dev/null
+++ b/test/resources/persistable/TestResourcePersistable.java
@@ -0,0 +1,100 @@
+/************************************************************************************
+ * Copyright (c) 2015 /// Project SWG /// www.projectswg.com *
+ * *
+ * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
+ * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
+ * Our goal is to create an emulator which will provide a server for players to *
+ * continue playing a game similar to the one they used to play. We are basing *
+ * it on the final publish of the game prior to end-game events. *
+ * *
+ * This file is part of Holocore. *
+ * *
+ * -------------------------------------------------------------------------------- *
+ * *
+ * Holocore is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU Affero General Public License as *
+ * published by the Free Software Foundation, either version 3 of the *
+ * License, or (at your option) any later version. *
+ * *
+ * Holocore is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU Affero General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Affero General Public License *
+ * along with Holocore. If not, see . *
+ * *
+ ***********************************************************************************/
+package resources.persistable;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import com.projectswg.common.persistable.InputPersistenceStream;
+import com.projectswg.common.persistable.OutputPersistenceStream;
+
+import services.crafting.resource.galactic.GalacticResource;
+
+@RunWith(JUnit4.class)
+public class TestResourcePersistable {
+
+ @Test
+ public void testGalacticResourcePersistable() throws IOException {
+ GalacticResource res = new GalacticResource(1, "MYRESOURCE", 15);
+ res.generateRandomStats();
+ test(res);
+ res = new GalacticResource(200, "Test", 100);
+ res.generateRandomStats();
+ test(res);
+ for (int i = 0; i < 50; i++) {
+ res.generateRandomStats();
+ test(res);
+ }
+ }
+
+ private void test(GalacticResource resource) throws IOException {
+ byte [] written = write(resource);
+ GalacticResource read = read(written);
+ test(resource, read);
+ }
+
+ private void test(GalacticResource write, GalacticResource read) {
+ Assert.assertEquals(write.getId(), read.getId());
+ Assert.assertEquals(write.getName(), read.getName());
+ Assert.assertEquals(write.getRawResourceId(), read.getRawResourceId());
+ Assert.assertEquals(write.getStats().getColdResistance(), read.getStats().getColdResistance());
+ Assert.assertEquals(write.getStats().getConductivity(), read.getStats().getConductivity());
+ Assert.assertEquals(write.getStats().getDecayResistance(), read.getStats().getDecayResistance());
+ Assert.assertEquals(write.getStats().getEntangleResistance(), read.getStats().getEntangleResistance());
+ Assert.assertEquals(write.getStats().getFlavor(), read.getStats().getFlavor());
+ Assert.assertEquals(write.getStats().getHeatResistance(), read.getStats().getHeatResistance());
+ Assert.assertEquals(write.getStats().getMalleability(), read.getStats().getMalleability());
+ Assert.assertEquals(write.getStats().getOverallQuality(), read.getStats().getOverallQuality());
+ Assert.assertEquals(write.getStats().getPotentialEnergy(), read.getStats().getPotentialEnergy());
+ Assert.assertEquals(write.getStats().getShockResistance(), read.getStats().getShockResistance());
+ Assert.assertEquals(write.getStats().getUnitToughness(), read.getStats().getUnitToughness());
+ }
+
+ private byte [] write(GalacticResource mail) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ OutputPersistenceStream os = new OutputPersistenceStream(baos);
+ os.write(mail, GalacticResource::save);
+ os.close();
+ return baos.toByteArray();
+ }
+
+ private GalacticResource read(byte [] data) throws IOException {
+ try (InputPersistenceStream is = new InputPersistenceStream(new ByteArrayInputStream(data))) {
+ GalacticResource mail = is.read(GalacticResource::create);
+ Assert.assertEquals(0, is.available());
+ return mail;
+ }
+ }
+
+}
diff --git a/test/resources/persistable/TestSWGPersistable.java b/test/resources/persistable/TestSWGPersistable.java
index 3991f92c8..b8d6c0352 100644
--- a/test/resources/persistable/TestSWGPersistable.java
+++ b/test/resources/persistable/TestSWGPersistable.java
@@ -104,12 +104,9 @@ public class TestSWGPersistable {
@Test
public void testBuildingObject() throws IOException {
- test("object/building/tatooine/shared_palace_tatooine_jabba.iff");
BuildingObject expected = (BuildingObject) ObjectCreator.createObjectFromTemplate("object/building/tatooine/shared_palace_tatooine_jabba.iff");
expected.populateCells();
- byte [] data = write(expected);
- SWGObject obj = read(data);
- test(expected, obj);
+ test(expected);
}
@Test
@@ -118,16 +115,21 @@ public class TestSWGPersistable {
}
private void test(String template) throws IOException {
- SWGObject expected = ObjectCreator.createObjectFromTemplate(template);
- byte [] data = write(expected);
- SWGObject obj = read(data);
- test(expected, obj);
+ test(ObjectCreator.createObjectFromTemplate(template));
+ }
+
+ private void test(SWGObject object) throws IOException {
+ byte [] written = write(object);
+ SWGObject read = read(written);
+ test(object, read);
}
private void test(SWGObject expected, SWGObject actual) {
Assert.assertNotNull(actual);
Assert.assertTrue("actual instanceof expected", expected.getClass().isAssignableFrom(actual.getClass()));
Assert.assertEquals("expected.equals(actual)", expected, actual);
+ Assert.assertEquals("contained objects", expected.getContainedObjects(), actual.getContainedObjects());
+ Assert.assertEquals("slots", expected.getSlots(), actual.getSlots());
}
private byte [] write(SWGObject obj) throws IOException {
diff --git a/test/services/TestServices.java b/test/services/TestServices.java
index d16daf1cf..e148640e6 100644
--- a/test/services/TestServices.java
+++ b/test/services/TestServices.java
@@ -27,13 +27,10 @@
***********************************************************************************/
package services;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
-import resources.server_info.DataManager;
import services.crafting.TestCrafting;
import services.galaxy.TestGalaxy;
import services.player.TestPlayer;
@@ -46,14 +43,4 @@ import services.player.TestPlayer;
})
public class TestServices {
- @BeforeClass
- public static void setupDataManager() {
- DataManager.initialize();
- }
-
- @AfterClass
- public static void closeDataManager() {
- DataManager.terminate();
- }
-
}
diff --git a/test/services/galaxy/travel/TestTravelHelper.java b/test/services/galaxy/travel/TestTravelHelper.java
index 4ca738aa1..9a1b126b5 100644
--- a/test/services/galaxy/travel/TestTravelHelper.java
+++ b/test/services/galaxy/travel/TestTravelHelper.java
@@ -132,7 +132,6 @@ public class TestTravelHelper {
helper.grantTicket(imperialBase, coronet, creature);
Assert.assertEquals(imperialBase, helper.getNearestTravelPoint(creature));
Assert.assertEquals(1, creature.getSlottedObject("inventory").getContainedObjects().size());
- System.out.println(creature.getSlottedObject("inventory").getContainedObjects());
List tickets = helper.getTickets(creature);
Assert.assertEquals(1, tickets.size());