Search in sources :

Example 1 with OrderedPairManager

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());
}
Also used : ChallengeRating(pcgen.cdom.content.ChallengeRating) GenericLoader(pcgen.persistence.lst.GenericLoader) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI) StringManager(pcgen.base.format.StringManager) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) OrderedPairManager(pcgen.base.format.OrderedPairManager) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 OrderedPairManager (pcgen.base.format.OrderedPairManager)1 StringManager (pcgen.base.format.StringManager)1 UnreachableError (pcgen.base.lang.UnreachableError)1 ChallengeRating (pcgen.cdom.content.ChallengeRating)1 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)1 GenericLoader (pcgen.persistence.lst.GenericLoader)1 PCClassLoader (pcgen.persistence.lst.PCClassLoader)1 LoadContext (pcgen.rules.context.LoadContext)1