|
From: <th...@us...> - 2007-09-30 21:27:05
|
Revision: 4199
http://pcgen.svn.sourceforge.net/pcgen/?rev=4199&view=rev
Author: thpr
Date: 2007-09-30 14:27:09 -0700 (Sun, 30 Sep 2007)
Log Message:
-----------
Commit a hack at runtime load testing framework
Added Paths:
-----------
branches/cdom/code/src/itest/pcgen/
branches/cdom/code/src/itest/pcgen/tokenruntimeload/
branches/cdom/code/src/itest/pcgen/tokenruntimeload/AbstractIntegrationTestCase.java
branches/cdom/code/src/itest/pcgen/tokenruntimeload/TemplateTest.java
branches/cdom/code/src/itest/pcgen/tokenruntimeload/WeaponProfTest.java
Added: branches/cdom/code/src/itest/pcgen/tokenruntimeload/AbstractIntegrationTestCase.java
===================================================================
--- branches/cdom/code/src/itest/pcgen/tokenruntimeload/AbstractIntegrationTestCase.java (rev 0)
+++ branches/cdom/code/src/itest/pcgen/tokenruntimeload/AbstractIntegrationTestCase.java 2007-09-30 21:27:09 UTC (rev 4199)
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2007 Tom Parker <th...@us...>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This program 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 Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package pcgen.tokenruntimeload;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import junit.framework.TestCase;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+import pcgen.cdom.graph.PCGenGraph;
+import pcgen.core.Campaign;
+import pcgen.core.PObject;
+import pcgen.persistence.EditorLoadContext;
+import pcgen.persistence.LoadContext;
+import pcgen.persistence.PersistenceLayerException;
+import pcgen.persistence.lst.CampaignSourceEntry;
+import pcgen.persistence.lst.LstLoader;
+import pcgen.persistence.lst.LstToken;
+import pcgen.persistence.lst.TokenStore;
+
+public abstract class AbstractIntegrationTestCase<T extends PObject> extends
+ TestCase
+{
+ protected PCGenGraph primaryGraph;
+ protected PCGenGraph secondaryGraph;
+ protected LoadContext primaryContext;
+ protected LoadContext secondaryContext;
+ protected T primaryProf;
+ protected T secondaryProf;
+ protected String prefix = "";
+ protected int expectedPrimaryMessageCount = 0;
+
+ private static boolean classSetUpFired = false;
+ protected static CampaignSourceEntry testCampaign;
+ protected static CampaignSourceEntry modCampaign;
+
+ public abstract LstLoader<T> getLoader();
+
+ @BeforeClass
+ public static final void classSetUp() throws URISyntaxException
+ {
+ testCampaign =
+ new CampaignSourceEntry(new Campaign(), new URI(
+ "file:/Test%20Case"));
+ modCampaign =
+ new CampaignSourceEntry(new Campaign(), new URI(
+ "file:/Test%20Case%20Modifier"));
+ classSetUpFired = true;
+ }
+
+ @Override
+ @Before
+ public void setUp() throws PersistenceLayerException, URISyntaxException
+ {
+ if (!classSetUpFired)
+ {
+ classSetUp();
+ }
+ primaryGraph = new PCGenGraph();
+ secondaryGraph = new PCGenGraph();
+ primaryContext = new EditorLoadContext();
+ secondaryContext = new EditorLoadContext();
+ primaryProf =
+ primaryContext.ref.constructCDOMObject(getCDOMClass(),
+ "TestObj");
+ secondaryProf =
+ secondaryContext.ref.constructCDOMObject(getCDOMClass(),
+ "TestObj");
+ }
+
+ public abstract Class<? extends T> getCDOMClass();
+
+ public static void addToken(LstToken tok)
+ {
+ TokenStore.inst().addToTokenMap(tok);
+ }
+
+ protected void verifyClean()
+ {
+ // Ensure the graphs are the same at the start
+ assertEquals(primaryGraph, secondaryGraph);
+ // Ensure the graphs are the same at the start
+ assertTrue(primaryProf.isCDOMEqual(secondaryProf));
+ }
+}
Added: branches/cdom/code/src/itest/pcgen/tokenruntimeload/TemplateTest.java
===================================================================
--- branches/cdom/code/src/itest/pcgen/tokenruntimeload/TemplateTest.java (rev 0)
+++ branches/cdom/code/src/itest/pcgen/tokenruntimeload/TemplateTest.java 2007-09-30 21:27:09 UTC (rev 4199)
@@ -0,0 +1,129 @@
+package pcgen.tokenruntimeload;
+
+import java.net.URISyntaxException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import pcgen.cdom.enumeration.AbilityCategory;
+import pcgen.cdom.enumeration.AbilityNature;
+import pcgen.cdom.enumeration.AssociationKey;
+import pcgen.cdom.enumeration.IntegerKey;
+import pcgen.cdom.enumeration.ObjectKey;
+import pcgen.cdom.enumeration.SubRegion;
+import pcgen.cdom.graph.PCGraphGrantsEdge;
+import pcgen.core.Ability;
+import pcgen.core.PCTemplate;
+import pcgen.persistence.PersistenceLayerException;
+import pcgen.persistence.lst.LstObjectFileLoader;
+import pcgen.persistence.lst.PCTemplateLoader;
+import pcgen.util.enumeration.Visibility;
+import plugin.lsttokens.pcclass.LevelsperfeatToken;
+import plugin.lsttokens.template.AddLevelToken;
+import plugin.lsttokens.template.BonusfeatsToken;
+import plugin.lsttokens.template.BonusskillpointsToken;
+import plugin.lsttokens.template.CrToken;
+import plugin.lsttokens.template.FaceToken;
+import plugin.lsttokens.template.FavoredclassToken;
+import plugin.lsttokens.template.FeatToken;
+import plugin.lsttokens.template.GenderlockToken;
+import plugin.lsttokens.template.HandsToken;
+import plugin.lsttokens.template.HdToken;
+import plugin.lsttokens.template.HitdieToken;
+import plugin.lsttokens.template.LangbonusToken;
+import plugin.lsttokens.template.LegsToken;
+import plugin.lsttokens.template.LevelToken;
+import plugin.lsttokens.template.LeveladjustmentToken;
+import plugin.lsttokens.template.NonppToken;
+import plugin.lsttokens.template.RacesubtypeToken;
+import plugin.lsttokens.template.RacetypeToken;
+import plugin.lsttokens.template.ReachToken;
+import plugin.lsttokens.template.RegionToken;
+import plugin.lsttokens.template.RemovableToken;
+import plugin.lsttokens.template.RepeatlevelToken;
+import plugin.lsttokens.template.SizeToken;
+import plugin.lsttokens.template.SubraceToken;
+import plugin.lsttokens.template.SubregionToken;
+import plugin.lsttokens.template.VisibleToken;
+import plugin.lsttokens.template.WeaponbonusToken;
+import plugin.lsttokens.testsupport.TokenRegistration;
+
+public class TemplateTest extends AbstractIntegrationTestCase<PCTemplate>
+{
+
+ static PCTemplateLoader loader = new PCTemplateLoader();
+
+ @Override
+ @Before
+ public final void setUp() throws PersistenceLayerException,
+ URISyntaxException
+ {
+ super.setUp();
+ TokenRegistration.register(new AddLevelToken());
+ TokenRegistration.register(new BonusfeatsToken());
+ TokenRegistration.register(new BonusskillpointsToken());
+ TokenRegistration.register(new CrToken());
+ TokenRegistration.register(new FaceToken());
+ TokenRegistration.register(new FavoredclassToken());
+ TokenRegistration.register(new FeatToken());
+ TokenRegistration.register(new GenderlockToken());
+ TokenRegistration.register(new HandsToken());
+ TokenRegistration.register(new HdToken());
+ TokenRegistration.register(new HitdieToken());
+ TokenRegistration.register(new LangbonusToken());
+ TokenRegistration.register(new LegsToken());
+ TokenRegistration.register(new LeveladjustmentToken());
+ TokenRegistration.register(new LevelsperfeatToken());
+ TokenRegistration.register(new LevelToken());
+ TokenRegistration.register(new NonppToken());
+ TokenRegistration.register(new RacesubtypeToken());
+ TokenRegistration.register(new RacetypeToken());
+ TokenRegistration.register(new ReachToken());
+ TokenRegistration.register(new RegionToken());
+ TokenRegistration.register(new RemovableToken());
+ TokenRegistration.register(new RepeatlevelToken());
+ TokenRegistration.register(new SizeToken());
+ TokenRegistration.register(new SubraceToken());
+ TokenRegistration.register(new SubregionToken());
+ TokenRegistration.register(new VisibleToken());
+ TokenRegistration.register(new WeaponbonusToken());
+ }
+
+ @Override
+ public Class<PCTemplate> getCDOMClass()
+ {
+ return PCTemplate.class;
+ }
+
+ @Override
+ public LstObjectFileLoader<PCTemplate> getLoader()
+ {
+ return loader;
+ }
+
+ @Test
+ public void testImportBasicTemplate() throws PersistenceLayerException
+ {
+ verifyClean();
+ primaryProf =
+ loader.parseFullLine(primaryContext, 1,
+ "TestTemplate\tHANDS:2\t"
+ + "SUBREGION:New South Wales\tVISIBLE:NO\tFEAT:Feat1",
+ testCampaign);
+ secondaryProf.put(IntegerKey.HANDS, Integer.valueOf(2));
+ secondaryProf.put(ObjectKey.SUBREGION, SubRegion
+ .valueOf("New South Wales"));
+ secondaryProf.put(ObjectKey.VISIBILITY, Visibility.NO);
+ secondaryProf.put(ObjectKey.SOURCE_URI, testCampaign.getURI());
+ secondaryProf.setName("TestTemplate");
+ PCGraphGrantsEdge edge =
+ new PCGraphGrantsEdge(secondaryProf, secondaryContext.ref
+ .getCDOMReference(Ability.class, AbilityCategory.FEAT,
+ "Feat1"), "FEAT");
+ edge
+ .setAssociation(AssociationKey.ABILITY_NATURE, AbilityNature.NORMAL);
+ edge.setAssociation(AssociationKey.SOURCE_URI, null);
+ secondaryGraph.addEdge(edge);
+ verifyClean();
+ }
+}
Added: branches/cdom/code/src/itest/pcgen/tokenruntimeload/WeaponProfTest.java
===================================================================
--- branches/cdom/code/src/itest/pcgen/tokenruntimeload/WeaponProfTest.java (rev 0)
+++ branches/cdom/code/src/itest/pcgen/tokenruntimeload/WeaponProfTest.java 2007-09-30 21:27:09 UTC (rev 4199)
@@ -0,0 +1,55 @@
+package pcgen.tokenruntimeload;
+
+import java.net.URISyntaxException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import pcgen.cdom.enumeration.IntegerKey;
+import pcgen.cdom.enumeration.ObjectKey;
+import pcgen.core.WeaponProf;
+import pcgen.persistence.PersistenceLayerException;
+import pcgen.persistence.lst.LstObjectFileLoader;
+import pcgen.persistence.lst.WeaponProfLoader;
+import plugin.lsttokens.testsupport.TokenRegistration;
+import plugin.lsttokens.weaponprof.HandsToken;
+
+public class WeaponProfTest extends AbstractIntegrationTestCase<WeaponProf>
+{
+
+ static HandsToken token = new HandsToken();
+ static WeaponProfLoader loader = new WeaponProfLoader();
+
+ @Override
+ @Before
+ public final void setUp() throws PersistenceLayerException,
+ URISyntaxException
+ {
+ super.setUp();
+ TokenRegistration.register(token);
+ }
+
+ @Override
+ public Class<WeaponProf> getCDOMClass()
+ {
+ return WeaponProf.class;
+ }
+
+ @Override
+ public LstObjectFileLoader<WeaponProf> getLoader()
+ {
+ return loader;
+ }
+
+ @Test
+ public void testImportBasicWeaponProf() throws PersistenceLayerException
+ {
+ verifyClean();
+ primaryProf =
+ loader.parseFullLine(primaryContext, 1, "TestWP1\tHANDS:2",
+ testCampaign);
+ secondaryProf.put(IntegerKey.HANDS, Integer.valueOf(2));
+ secondaryProf.put(ObjectKey.SOURCE_URI, testCampaign.getURI());
+ verifyClean();
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|