PModeManager implements IPModeSet { @Override public IPMode get(String id) { return deployedPModes.get(id); } PModeManager(final InternalConfiguration config); @Override IPMode get(String id); @Override Collection<IPMode> getAll(); @Override boolean containsId(String id); @Override String add(IPMode pmode); @Override void replace(IPMode pmode); @Override void remove(String id); @Override void removeAll();  }
@Test public void testDefaultConfig() { try { PModeManager manager = new PModeManager(config); Field pmodeStorage = PModeManager.class.getDeclaredField("deployedPModes"); pmodeStorage.setAccessible(true); assertTrue(pmodeStorage.get(manager) instanceof InMemoryPModeSet); } catch (Throwable t) { t.printStackTrace(); fail(); } }
@Test public void testStorageLoading() { ClassLoader ccl = this.getClass().getClassLoader(); URLClassLoader ecl = new URLClassLoader(new URL[] { ccl.getResource("pmodeManager/") }, ccl); Thread.currentThread().setContextClassLoader(ecl); PModeManager manager = null; try { manager = new PModeManager(config); } catch (PModeSetException pse) { fail(); } try { Field pmodeStorage = PModeManager.class.getDeclaredField("deployedPModes"); pmodeStorage.setAccessible(true); IPModeSet storageComp = (IPModeSet) pmodeStorage.get(manager); assertNotNull(storageComp); assertEquals(TestNOpPModeSet.class, storageComp.getClass()); } catch (Throwable t) { t.printStackTrace(); fail(); } TestNOpPModeSet.failOnInit = true; try { manager = new PModeManager(config); fail(); } catch (PModeSetException pse) { } Thread.currentThread().setContextClassLoader(ccl); }
@Test public void testValidatorLoading() { ClassLoader ccl = this.getClass().getClassLoader(); URLClassLoader ecl = new URLClassLoader(new URL[] { ccl.getResource("pmodeManager/") }, ccl); Thread.currentThread().setContextClassLoader(ecl); PModeManager manager = null; try { manager = new PModeManager(config); } catch (PModeSetException pse) { fail(); } try { Field pmodeValidators = PModeManager.class.getDeclaredField("validators"); pmodeValidators.setAccessible(true); List<IPModeValidator> validators = (List<IPModeValidator>) pmodeValidators.get(manager); assertNotNull(validators); assertEquals(2, validators.size()); assertTrue( validators.parallelStream().anyMatch(v -> v.getName().equals(new TestValidatorAllWrong().getName())) && validators.parallelStream().anyMatch(v -> v.getName().equals(new TestValidatorAllGood().getName()))); } catch (Throwable t) { t.printStackTrace(); fail(); } Thread.currentThread().setContextClassLoader(ccl); }