/*
* Copyright (c) 2007 Tom Parker <thpr@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package plugin.lsttokens.template;
import org.junit.Test;
import pcgen.cdom.base.CDOMReference;
import pcgen.cdom.enumeration.ListKey;
import pcgen.cdom.reference.CDOMGroupRef;
import pcgen.core.Ability;
import pcgen.core.AbilityCategory;
import pcgen.core.PCTemplate;
import pcgen.persistence.PersistenceLayerException;
import pcgen.rules.context.LoadContext;
import pcgen.rules.persistence.CDOMLoader;
import pcgen.rules.persistence.token.CDOMPrimaryToken;
import plugin.lsttokens.testsupport.AbstractListKeyTokenTestCase;
import plugin.lsttokens.testsupport.CDOMTokenLoader;
import plugin.lsttokens.testsupport.ConsolidationRule;
public class FeatTokenTest extends
AbstractListKeyTokenTestCase<PCTemplate, Ability>
{
static FeatToken token = new FeatToken();
static CDOMTokenLoader<PCTemplate> loader = new CDOMTokenLoader<PCTemplate>(
PCTemplate.class);
@Override
public char getJoinCharacter()
{
return '|';
}
@Override
public Class<Ability> getTargetClass()
{
return Ability.class;
}
@Override
public boolean isTypeLegal()
{
return true;
}
@Override
public boolean isAllLegal()
{
return false;
}
@Override
public boolean isClearDotLegal()
{
return false;
}
@Override
public boolean isClearLegal()
{
return true;
}
@Override
public Class<PCTemplate> getCDOMClass()
{
return PCTemplate.class;
}
@Override
public CDOMLoader<PCTemplate> getLoader()
{
return loader;
}
@Override
public CDOMPrimaryToken<PCTemplate> getToken()
{
return token;
}
@Override
protected Ability construct(LoadContext loadContext, String one)
{
Ability obj = loadContext.getReferenceContext().constructCDOMObject(Ability.class, one);
loadContext.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, obj);
return obj;
}
@Test
public void testInvalidInputEmpty() throws PersistenceLayerException
{
assertFalse(parse(""));
assertNoSideEffects();
}
@Test
public void testInvalidInputOnlyPre() throws PersistenceLayerException
{
construct(primaryContext, "TestWP1");
try
{
assertFalse(parse("PRECLASS:1,Fighter=1"));
}
catch (IllegalArgumentException e)
{
// this is okay too :)
}
assertNoSideEffects();
}
@Test
public void testRoundRobinOneParen() throws PersistenceLayerException
{
construct(primaryContext, "TestWP1");
construct(secondaryContext, "TestWP1");
runRoundRobin("TestWP1 (Paren)");
}
@Test
public void testRoundRobinTwoParen() throws PersistenceLayerException
{
construct(primaryContext, "TestWP1");
construct(primaryContext, "TestWP2");
construct(secondaryContext, "TestWP1");
construct(secondaryContext, "TestWP2");
runRoundRobin("TestWP1 (Paren)|TestWP2 (Other)");
}
@Test
public void testRoundRobinDupeParen() throws PersistenceLayerException
{
construct(primaryContext, "TestWP1");
construct(secondaryContext, "TestWP1");
runRoundRobin("TestWP1 (Other)|TestWP1 (That)");
}
@Override
public boolean allowDups()
{
return false;
}
@Override
protected ConsolidationRule getConsolidationRule()
{
return ConsolidationRule.OVERWRITE;
}
@Override
protected ListKey<CDOMReference<Ability>> getListKey()
{
return ListKey.FEAT_TOKEN_LIST;
}
@Override
protected CDOMGroupRef<Ability> getTypeReference()
{
return primaryContext.getReferenceContext().getCDOMTypeReference(getTargetClass(),
AbilityCategory.FEAT, "Type1");
}
@Override
protected CDOMGroupRef<Ability> getAllReference()
{
return primaryContext.getReferenceContext().getCDOMAllReference(getTargetClass(),
AbilityCategory.FEAT);
}
}