Test the processing of getPCCText to ensure that it correctly produces an LST representation of an object and that the LST can then be reloaded to recreate the object. @throws PersistenceLayerException the persistence layer exception
()
| 107 | * @throws PersistenceLayerException the persistence layer exception |
| 108 | */ |
| 109 | @Test |
| 110 | public void testGetPCCText() throws PersistenceLayerException |
| 111 | { |
| 112 | OrderedPairManager opManager = new OrderedPairManager(); |
| 113 | LoadContext context = Globals.getContext(); |
| 114 | context.getVariableContext().assertLegalVariableID( |
| 115 | CControl.FACE.getDefaultValue(), context.getActiveScope(), opManager); |
| 116 | Race race = new Race(); |
| 117 | race.setName("TestRace"); |
| 118 | race.put(ObjectKey.CHALLENGE_RATING, new ChallengeRating(FormulaFactory.getFormulaFor(5))); |
| 119 | String racePCCText = race.getPCCText(); |
| 120 | assertNotNull("PCC Text for race should not be null", racePCCText); |
| 121 | |
| 122 | GenericLoader<Race> raceLoader = new GenericLoader<>(Race.class); |
| 123 | CampaignSourceEntry source; |
| 124 | try |
| 125 | { |
| 126 | source = new CampaignSourceEntry(new Campaign(), |
| 127 | new URI("file:/" + getClass().getName() + ".java")); |
| 128 | } |
| 129 | catch (URISyntaxException e) |
| 130 | { |
| 131 | throw new UnreachableError(e); |
| 132 | } |
| 133 | raceLoader.parseLine(context, null, racePCCText, source); |
| 134 | Race reconstRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "TestRace"); |
| 135 | assertEquals( |
| 136 | "getPCCText should be the same after being encoded and reloaded", |
| 137 | racePCCText, reconstRace.getPCCText()); |
| 138 | assertEquals("Racial CR was not restored after saving and reloading.", |
| 139 | race.get(ObjectKey.CHALLENGE_RATING), reconstRace |
| 140 | .get(ObjectKey.CHALLENGE_RATING)); |
| 141 | |
| 142 | FactKey.getConstant("Abb", new StringManager()); |
| 143 | PCClass aClass = new PCClass(); |
| 144 | aClass.setName("TestClass"); |
| 145 | String classPCCText = aClass.getPCCText(); |
| 146 | assertNotNull("PCC Text for race should not be null", racePCCText); |
| 147 | |
| 148 | PCClassLoader classLoader = new PCClassLoader(); |
| 149 | PCClass reconstClass = |
| 150 | classLoader.parseLine(context, null, classPCCText, |
| 151 | source); |
| 152 | assertEquals( |
| 153 | "getPCCText should be the same after being encoded and reloaded", |
| 154 | classPCCText, reconstClass.getPCCText()); |
| 155 | assertEquals( |
| 156 | "Class abbrev was not restored after saving and reloading.", aClass |
| 157 | .getAbbrev(), reconstClass.getAbbrev()); |
| 158 | |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Test the function of adding a bonus each time an associated value is chosen. |
nothing calls this directly
no test coverage detected