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());
}
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());
}
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());
}
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);
}
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
}
}
Aggregations