Search in sources :

Example 71 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class ArmorProfTokenTest method constructTyped.

@Override
protected CDOMObject constructTyped(LoadContext loadContext, String one) {
    CDOMObject cdo = loadContext.getReferenceContext().constructCDOMObject(Equipment.class, one);
    cdo.addToListFor(ListKey.TYPE, Type.getConstant("Armor"));
    return cdo;
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject)

Example 72 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class AbstractPreRoundRobin method runSimpleRoundRobin.

public static void runSimpleRoundRobin(String s, String d) {
    try {
        Prerequisite p = PreParserFactory.getInstance().parse(s);
        PrerequisiteWriterInterface writer = PrerequisiteWriterFactory.getInstance().getWriter(p.getKind());
        if (writer == null) {
            fail("Could not find Writer for: " + p.getKind());
        }
        StringWriter w = new StringWriter();
        writer.write(w, p);
        assertEquals(d, w.toString());
        /*
			 * Now try new system
			 */
        LoadContext context = new EditorLoadContext();
        CDOMObject obj = new ObjectCache();
        int colonLoc = s.indexOf(':');
        String key = s.substring(0, colonLoc);
        String value = s.substring(colonLoc + 1);
        if (context.processToken(obj, key, value)) {
            context.commit();
        } else {
            context.rollback();
            Logging.replayParsedMessages();
            fail();
        }
        Logging.clearParseMessages();
        Collection<String> output = context.unparse(obj);
        if (output == null || output.isEmpty()) {
            // Uh Oh
            fail("Unable to unparse: " + key + ":" + value);
        }
        assertEquals(1, output.size());
        assertEquals(d, output.iterator().next());
    } catch (PersistenceLayerException e) {
        e.printStackTrace();
        fail(e.getLocalizedMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) EditorLoadContext(pcgen.rules.context.EditorLoadContext) StringWriter(java.io.StringWriter) CDOMObject(pcgen.cdom.base.CDOMObject) ObjectCache(pcgen.cdom.inst.ObjectCache) EditorLoadContext(pcgen.rules.context.EditorLoadContext) LoadContext(pcgen.rules.context.LoadContext) PrerequisiteWriterInterface(pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 73 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class LocalSkillCostFacetTest method testAddBadSource.

@Test
public void testAddBadSource() {
    Skill t1 = getObject();
    PCClassLevel pcl = new PCClassLevel();
    DataFacetChangeEvent<CharID, CDOMObject> dfce = new DataFacetChangeEvent<>(id, pcl, new Object(), DataFacetChangeEvent.DATA_ADDED);
    ListKey<CDOMReference<Skill>> lk = ListKey.LOCALCSKILL;
    pcl.addToListFor(lk, CDOMDirectSingleRef.getRef(t1));
    try {
        getFacet().dataAdded(dfce);
        fail();
    } catch (IllegalArgumentException e) {
    // Yep!
    }
}
Also used : DataFacetChangeEvent(pcgen.cdom.facet.event.DataFacetChangeEvent) Skill(pcgen.core.Skill) CDOMObject(pcgen.cdom.base.CDOMObject) CDOMObject(pcgen.cdom.base.CDOMObject) CharID(pcgen.cdom.enumeration.CharID) CDOMReference(pcgen.cdom.base.CDOMReference) PCClassLevel(pcgen.cdom.inst.PCClassLevel) Test(org.junit.Test)

Example 74 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class LocalSkillCostFacetTest method testRemoveSecondSource.

@Test
public void testRemoveSecondSource() {
    Skill t1 = getObject();
    assertFalse(getFacet().contains(id, class1, SkillCost.CLASS, t1));
    addCost(id, class1, t1, SkillCost.CLASS);
    PCClassLevel pcl = new PCClassLevel();
    pcl.put(ObjectKey.PARENT, class1);
    DataFacetChangeEvent<CharID, CDOMObject> dfce = new DataFacetChangeEvent<>(id, pcl, new Object(), DataFacetChangeEvent.DATA_ADDED);
    ListKey<CDOMReference<Skill>> lk = ListKey.LOCALCSKILL;
    pcl.addToListFor(lk, CDOMDirectSingleRef.getRef(t1));
    getFacet().dataAdded(dfce);
    assertTrue(getFacet().contains(id, class1, SkillCost.CLASS, t1));
    removeCosts(id, pcl);
    assertTrue(getFacet().contains(id, class1, SkillCost.CLASS, t1));
}
Also used : DataFacetChangeEvent(pcgen.cdom.facet.event.DataFacetChangeEvent) Skill(pcgen.core.Skill) CDOMObject(pcgen.cdom.base.CDOMObject) CDOMObject(pcgen.cdom.base.CDOMObject) CharID(pcgen.cdom.enumeration.CharID) CDOMReference(pcgen.cdom.base.CDOMReference) PCClassLevel(pcgen.cdom.inst.PCClassLevel) Test(org.junit.Test)

Example 75 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class MovementFacetTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    CDOMObject cdo1 = new PCTemplate();
    cdo1.setName("Templ");
    CDOMObject cdo2 = new Race();
    cdo2.setName("Race");
    PCStat pcs1 = new PCStat();
    pcs1.setName("Stat1");
    PCStat pcs2 = new PCStat();
    pcs2.setName("Stat2");
    Movement st1 = new Movement(1);
    Movement st2 = new Movement(1);
    cdo1.addToListFor(ListKey.MOVEMENT, st1);
    cdo2.addToListFor(ListKey.MOVEMENT, st2);
    source = new CDOMObject[] { cdo1, cdo2 };
    target = new Movement[] { st1, st2 };
}
Also used : Movement(pcgen.core.Movement) CDOMObject(pcgen.cdom.base.CDOMObject) Race(pcgen.core.Race) PCTemplate(pcgen.core.PCTemplate) PCStat(pcgen.core.PCStat)

Aggregations

CDOMObject (pcgen.cdom.base.CDOMObject)235 Test (org.junit.Test)68 CharID (pcgen.cdom.enumeration.CharID)53 PCTemplate (pcgen.core.PCTemplate)30 ArrayList (java.util.ArrayList)22 PCClass (pcgen.core.PCClass)18 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)17 Race (pcgen.core.Race)17 Equipment (pcgen.core.Equipment)15 PlayerCharacter (pcgen.core.PlayerCharacter)15 Map (java.util.Map)14 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)14 CDOMReference (pcgen.cdom.base.CDOMReference)14 BonusObj (pcgen.core.bonus.BonusObj)14 IdentityHashMap (java.util.IdentityHashMap)12 Set (java.util.Set)12 VariableKey (pcgen.cdom.enumeration.VariableKey)11 HashMap (java.util.HashMap)10 CNAbility (pcgen.cdom.content.CNAbility)10 Spell (pcgen.core.spell.Spell)9