Search in sources :

Example 46 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AbilityDepthTest method runTest.

@Override
protected void runTest() throws Throwable {
    Ability top = createAbility("TopAbility");
    Ability mid = createAbility("MidAbility");
    Ability target = createAbility("TargetAbility");
    ParseResult result = firstToken.parseToken(context, top, firstPrefix + mid.getKeyName());
    if (!result.passed()) {
        result.printMessages();
        fail();
    }
    result = secondToken.parseToken(context, mid, secondPrefix + target.getKeyName());
    if (!result.passed()) {
        result.printMessages();
        fail();
    }
    finishLoad();
    assocCheck = new NoAssociations(pc);
    CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.AUTOMATIC, top));
    assertEquals(0, getCount());
    pc.addAbility(cas, "This", "That");
    //		directAbilityFacet.add(id, cas, UserSelection.getInstance());
    assertTrue(containsExpected(mid));
    assertTrue(containsExpected(target));
    assertEquals(3, getCount());
    pc.removeAbility(cas, "This", "That");
    //		directAbilityFacet.remove(id, cas, UserSelection.getInstance());
    assertEquals(0, getCount());
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) NoAssociations(tokenmodel.testsupport.NoAssociations) ParseResult(pcgen.rules.persistence.token.ParseResult) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection)

Example 47 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AbstractAddListTokenTest method testFromAbility.

@Test
public void testFromAbility() throws PersistenceLayerException {
    Ability source = create(Ability.class, "Source");
    context.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, source);
    T granted = createGrantedObject();
    processToken(source);
    assertEquals(0, getCount());
    CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.AUTOMATIC, source));
    directAbilityFacet.add(id, cas, UserSelection.getInstance());
    assertTrue(containsExpected(granted));
    assertEquals((directAbilityFacet == getTargetFacet()) ? 2 : 1, getCount());
    directAbilityFacet.remove(id, cas, UserSelection.getInstance());
    assertEquals(0, getCount());
    assertTrue(cleanedSideEffects());
}
Also used : Ability(pcgen.core.Ability) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) Test(org.junit.Test)

Example 48 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AutoLangListTest method testFromAbility.

@Test
public void testFromAbility() throws PersistenceLayerException {
    Ability source = create(Ability.class, "Source");
    ParseResult result = new MultToken().parseToken(context, source, "YES");
    if (result != ParseResult.SUCCESS) {
        result.printMessages();
        fail("Test Setup Failed");
    }
    context.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, source);
    Language granted = createGrantedObject();
    processToken(source);
    assertEquals(0, getCount());
    CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.AUTOMATIC, source), "Granted");
    directAbilityFacet.add(id, cas, UserSelection.getInstance());
    assertTrue(containsExpected(granted));
    assertEquals(1, getCount());
    directAbilityFacet.remove(id, cas, UserSelection.getInstance());
    assertEquals(0, getCount());
    assertTrue(cleanedSideEffects());
}
Also used : Ability(pcgen.core.Ability) ParseResult(pcgen.rules.persistence.token.ParseResult) Language(pcgen.core.Language) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) MultToken(plugin.lsttokens.ability.MultToken) Test(org.junit.Test) AbstractTokenModelTest(tokenmodel.testsupport.AbstractTokenModelTest)

Example 49 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AbstractCNASEnforcingFacetTest method testTypeAddSingleRemove.

@Test
public void testTypeAddSingleRemove() {
    Object source1 = new Object();
    CNAbilitySelection t1 = getObject();
    getFacet().add(id, t1, source1);
    assertEquals(1, getFacet().getCount(id));
    assertFalse(getFacet().isEmpty(id));
    assertNotNull(getFacet().getSet(id));
    assertEquals(1, getFacet().getSet(id).size());
    assertEquals(t1, getFacet().getSet(id).iterator().next());
    assertEventCount(1, 0);
    // Remove
    getFacet().remove(id, t1, source1);
    assertEquals(0, getFacet().getCount(id));
    assertTrue(getFacet().isEmpty(id));
    assertNotNull(getFacet().getSet(id));
    assertTrue(getFacet().getSet(id).isEmpty());
    assertEventCount(1, 1);
}
Also used : CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) Test(org.junit.Test)

Example 50 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AbstractCNASEnforcingFacetTest method testGetSetIndependence.

@Test
public void testGetSetIndependence() {
    Object source1 = new Object();
    CNAbilitySelection t1 = getObject();
    CNAbilitySelection t2 = getObject();
    getFacet().add(id, t1, source1);
    Collection<CNAbilitySelection> set = getFacet().getSet(id);
    try {
        set.add(t2);
        // If we can modify, then make sure it's independent of the facet
        assertEquals(1, getFacet().getCount(id));
        assertFalse(getFacet().isEmpty(id));
        assertNotNull(getFacet().getSet(id));
        assertEquals(1, getFacet().getSet(id).size());
        assertEquals(t1, getFacet().getSet(id).iterator().next());
    } catch (UnsupportedOperationException e) {
    // This is ok too
    }
    try {
        set.remove(t1);
        // If we can modify, then make sure it's independent of the facet
        assertEquals(1, getFacet().getCount(id));
        assertFalse(getFacet().isEmpty(id));
        assertNotNull(getFacet().getSet(id));
        assertEquals(1, getFacet().getSet(id).size());
        assertEquals(t1, getFacet().getSet(id).iterator().next());
    } catch (UnsupportedOperationException e) {
    // This is ok too
    }
    List<CNAbilitySelection> pct = new ArrayList<>();
    pct.add(t1);
    pct.add(t2);
    try {
        set.addAll(pct);
        // If we can modify, then make sure it's independent of the facet
        assertEquals(1, getFacet().getCount(id));
        assertFalse(getFacet().isEmpty(id));
        assertNotNull(getFacet().getSet(id));
        assertEquals(1, getFacet().getSet(id).size());
        assertEquals(t1, getFacet().getSet(id).iterator().next());
    } catch (UnsupportedOperationException e) {
    // This is ok too
    }
    try {
        set.removeAll(pct);
        // If we can modify, then make sure it's independent of the facet
        assertEquals(1, getFacet().getCount(id));
        assertFalse(getFacet().isEmpty(id));
        assertNotNull(getFacet().getSet(id));
        assertEquals(1, getFacet().getSet(id).size());
        assertEquals(t1, getFacet().getSet(id).iterator().next());
    } catch (UnsupportedOperationException e) {
    // This is ok too
    }
    try {
        set.retainAll(new ArrayList<CNAbilitySelection>());
        // If we can modify, then make sure it's independent of the facet
        assertEquals(1, getFacet().getCount(id));
        assertFalse(getFacet().isEmpty(id));
        assertNotNull(getFacet().getSet(id));
        assertEquals(1, getFacet().getSet(id).size());
        assertEquals(t1, getFacet().getSet(id).iterator().next());
    } catch (UnsupportedOperationException e) {
    // This is ok too
    }
    getFacet().add(id, t1, source1);
    try {
        set.clear();
        // If we can modify, then make sure it's independent of the facet
        assertEquals(1, getFacet().getCount(id));
        assertFalse(getFacet().isEmpty(id));
        assertNotNull(getFacet().getSet(id));
        assertEquals(1, getFacet().getSet(id).size());
        assertEquals(t1, getFacet().getSet(id).iterator().next());
    } catch (UnsupportedOperationException e) {
    // This is ok too
    }
}
Also used : CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)70 CNAbility (pcgen.cdom.content.CNAbility)35 Test (org.junit.Test)28 Ability (pcgen.core.Ability)26 ArrayList (java.util.ArrayList)17 AbilityCategory (pcgen.core.AbilityCategory)7 CDOMReference (pcgen.cdom.base.CDOMReference)6 PlayerCharacter (pcgen.core.PlayerCharacter)6 ParseResult (pcgen.rules.persistence.token.ParseResult)6 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)5 AbilityRefChoiceSet (pcgen.cdom.choiceset.AbilityRefChoiceSet)5 Nature (pcgen.cdom.enumeration.Nature)5 PCTemplate (pcgen.core.PCTemplate)5 CharID (pcgen.cdom.enumeration.CharID)4 List (java.util.List)3 AbilityChoiceSet (pcgen.cdom.base.ChoiceSet.AbilityChoiceSet)3 SpecialAbility (pcgen.core.SpecialAbility)3 BonusObj (pcgen.core.bonus.BonusObj)3 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)3 HashSet (java.util.HashSet)2