use of pcgen.base.format.OrderedPairManager in project pcgen by PCGen.
the class PObjectTest method testGetPCCText.
/**
* Test the processing of getPCCText to ensure that it correctly produces
* an LST representation of an object and that the LST can then be reloaded
* to recrete the object.
*
* @throws PersistenceLayerException
*/
public void testGetPCCText() throws PersistenceLayerException {
OrderedPairManager opManager = new OrderedPairManager();
LoadContext context = Globals.getContext();
context.getVariableContext().assertLegalVariableID(context.getActiveScope().getLegalScope(), opManager, "Face");
Race race = new Race();
race.setName("TestRace");
race.put(ObjectKey.CHALLENGE_RATING, new ChallengeRating(FormulaFactory.getFormulaFor(5)));
String racePCCText = race.getPCCText();
assertNotNull("PCC Text for race should not be null", racePCCText);
GenericLoader<Race> raceLoader = new GenericLoader<>(Race.class);
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
raceLoader.parseLine(context, null, racePCCText, source);
Race reconstRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "TestRace");
assertEquals("getPCCText should be the same after being encoded and reloaded", racePCCText, reconstRace.getPCCText());
assertEquals("Racial CR was not restored after saving and reloading.", race.get(ObjectKey.CHALLENGE_RATING), reconstRace.get(ObjectKey.CHALLENGE_RATING));
FactKey.getConstant("Abb", new StringManager());
PCClass aClass = new PCClass();
aClass.setName("TestClass");
String classPCCText = aClass.getPCCText();
assertNotNull("PCC Text for race should not be null", racePCCText);
PCClassLoader classLoader = new PCClassLoader();
PCClass reconstClass = classLoader.parseLine(context, null, classPCCText, source);
assertEquals("getPCCText should be the same after being encoded and reloaded", classPCCText, reconstClass.getPCCText());
assertEquals("Class abbrev was not restored after saving and reloading.", aClass.getAbbrev(), reconstClass.getAbbrev());
}
Aggregations