Search in sources :

Example 81 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreVarTest method test2857849and2862276.

public void test2857849and2862276() {
    LoadContext context = Globals.getContext();
    final PCClass spellcaster = new PCClass();
    spellcaster.setName("Spellcaster");
    context.getReferenceContext().importObject(spellcaster);
    context.unconditionallyProcess(spellcaster, "SPELLTYPE", "Arcane");
    context.unconditionallyProcess(spellcaster, "SPELLSTAT", "INT");
    context.unconditionallyProcess(spellcaster, "PREVARGTEQ", "BASESPELLSTAT,2");
    PCClassLoader loader = new PCClassLoader();
    try {
        SourceEntry se = new CampaignSourceEntry(new Campaign(), new URI("file://test"));
        loader.completeObject(context, se, spellcaster);
        context.getReferenceContext().resolveReferences(null);
        PlayerCharacter character = this.getCharacter();
        setPCStat(character, intel, 16);
        assertTrue(spellcaster.qualifies(character, spellcaster));
    } catch (URISyntaxException | PersistenceLayerException e) {
        fail(e.getMessage());
    }
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Campaign(pcgen.core.Campaign) PlayerCharacter(pcgen.core.PlayerCharacter) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader) SourceEntry(pcgen.persistence.lst.SourceEntry) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) URISyntaxException(java.net.URISyntaxException) PCClass(pcgen.core.PCClass) URI(java.net.URI)

Example 82 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreVarTest method test2857849a.

public void test2857849a() {
    final PCClass warrior = new PCClass();
    warrior.setName("Warrior");
    LoadContext context = Globals.getContext();
    context.unconditionallyProcess(warrior, "DEFINE", "MyVar|0");
    context.unconditionallyProcess(warrior, "BONUS", "VAR|MyVar|2");
    PCClassLoader loader = new PCClassLoader();
    try {
        SourceEntry se = new CampaignSourceEntry(new Campaign(), new URI("file://test"));
        final PCClass notawarrior = loader.parseLine(context, null, "CLASS:NotAWarrior\tPREVARGTEQ:MyVar,1", se);
        loader.completeObject(context, se, warrior);
        loader.completeObject(context, se, notawarrior);
        PlayerCharacter character = this.getCharacter();
        assertFalse(notawarrior.qualifies(character, notawarrior));
        character.incrementClassLevel(1, warrior);
        assertTrue(notawarrior.qualifies(character, notawarrior));
    } catch (URISyntaxException | PersistenceLayerException e) {
        fail(e.getMessage());
    }
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Campaign(pcgen.core.Campaign) PlayerCharacter(pcgen.core.PlayerCharacter) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader) SourceEntry(pcgen.persistence.lst.SourceEntry) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) URISyntaxException(java.net.URISyntaxException) PCClass(pcgen.core.PCClass) URI(java.net.URI)

Example 83 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreVarTest method test2857848a.

public void test2857848a() {
    LoadContext context = Globals.getContext();
    final PCClass spellcaster = new PCClass();
    spellcaster.setName("Spellcaster");
    context.getReferenceContext().importObject(spellcaster);
    Skill concentration = context.getReferenceContext().constructCDOMObject(Skill.class, "Concentration");
    context.unconditionallyProcess(spellcaster, "SPELLTYPE", "Arcane");
    context.unconditionallyProcess(spellcaster, "SPELLSTAT", "INT");
    context.unconditionallyProcess(spellcaster, "CSKILL", "Concentration");
    context.unconditionallyProcess(spellcaster, "BONUS", "SKILL|Concentration|5|PREVARGT:BASESPELLSTAT,2");
    assertTrue(context.getReferenceContext().resolveReferences(null));
    PlayerCharacter character = this.getCharacter();
    setPCStat(character, intel, 16);
    PCClassLoader loader = new PCClassLoader();
    try {
        SourceEntry se = new CampaignSourceEntry(new Campaign(), new URI("file://test"));
        loader.completeObject(context, se, spellcaster);
        assertEquals(0, SkillModifier.modifier(concentration, character).intValue());
        character.incrementClassLevel(1, spellcaster);
        assertEquals(5, SkillModifier.modifier(concentration, character).intValue());
    } catch (URISyntaxException | PersistenceLayerException e) {
        fail(e.getMessage());
    }
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Skill(pcgen.core.Skill) PlayerCharacter(pcgen.core.PlayerCharacter) Campaign(pcgen.core.Campaign) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader) SourceEntry(pcgen.persistence.lst.SourceEntry) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) URISyntaxException(java.net.URISyntaxException) PCClass(pcgen.core.PCClass) URI(java.net.URI)

Example 84 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class TableLoaderTest method testBasic.

//TODO Blank Data in middle of Row?
//TODO Blank Data at end of row?
@Test
public void testBasic() {
    try {
        loader.loadLstString(context, uri, "#Let me tell you about this table\n\n,,,\n" + "STARTTABLE:A\n\n,,,\n" + "#It's the story of a parsing test\n" + "Name,Value,\n\n,,,\n" + "\"#And testing tolerance\",For lots of things\n" + "STRING,NUMBER,,\n\n,,,\n\n" + "#Because really....\n" + "This,1\n\n" + "#Why call the comments?\n,,,\n" + "\"That\",\"2\"\n" + "\"The \"\"Other\"\"\",\"3\"\n,,,\n\n" + "ENDTABLE:A\n" + "#They seem to just take up a lot of space");
        DataTable a = context.getReferenceContext().silentlyGetConstructedCDOMObject(DataTable.class, "A");
        assertEquals(2, a.getColumnCount());
        assertEquals(new StringManager(), a.getFormat(0));
        assertEquals(new NumberManager(), a.getFormat(1));
        assertEquals("This", a.get("Name", 0));
        assertEquals("That", a.get("Name", 1));
        assertEquals("The \"Other\"", a.get("Name", 2));
        assertEquals(1, a.get("Value", 0));
        assertEquals(2, a.get("Value", 1));
        assertEquals(3, a.get("Value", 2));
        assertEquals(2, a.lookupExact("That", "Value"));
    } catch (PersistenceLayerException e) {
        fail("Did not Expect Failure: " + e.getLocalizedMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) DataTable(pcgen.cdom.format.table.DataTable) NumberManager(pcgen.base.format.NumberManager) StringManager(pcgen.base.format.StringManager) Test(org.junit.Test)

Example 85 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreClassTest method testInvalidNegate.

/**
	 * Test that an error is produced if separators are incorrect
	 * @throws Exception
	 */
@Test
public void testInvalidNegate() throws Exception {
    try {
        PreClassParser parser = new PreClassParser();
        Prerequisite prereq = parser.parse("class", "1,Monk=1[Cleric=1]", false, false);
        fail("Should have thrown a PersistenceLayerException.");
    } catch (PersistenceLayerException e) {
    // Ignore, this is the expected result.
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) PreClassParser(plugin.pretokens.parser.PreClassParser) Prerequisite(pcgen.core.prereq.Prerequisite) Test(org.junit.Test)

Aggregations

PersistenceLayerException (pcgen.persistence.PersistenceLayerException)180 IOException (java.io.IOException)74 Prerequisite (pcgen.core.prereq.Prerequisite)62 StringWriter (java.io.StringWriter)17 StringTokenizer (java.util.StringTokenizer)17 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)15 LoadContext (pcgen.rules.context.LoadContext)14 URI (java.net.URI)12 Campaign (pcgen.core.Campaign)11 ParseResult (pcgen.rules.persistence.token.ParseResult)11 PCClass (pcgen.core.PCClass)10 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)10 PrerequisiteWriterInterface (pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface)10 URISyntaxException (java.net.URISyntaxException)8 TreeSet (java.util.TreeSet)8 CDOMReference (pcgen.cdom.base.CDOMReference)8 PlayerCharacter (pcgen.core.PlayerCharacter)8 PrerequisiteException (pcgen.core.prereq.PrerequisiteException)8 PCClassLoader (pcgen.persistence.lst.PCClassLoader)8