@Test public void testReadPMMLFromMessage() throws Exception { PMML pmml = PMMLUtils.buildSkeletonPMML(); String pmmlString = PMMLUtils.toString(pmml); assertEquals(PMMLUtils.VERSION, AppPMMLUtils.readPMMLFromUpdateKeyMessage( "MODEL", pmmlString, null).getVersion()); Path pmmlPath = getTempDir().resolve("out.pmml"); Files.write(pmmlPath, Collections.singleton(pmmlString)); assertEquals(PMMLUtils.VERSION, AppPMMLUtils.readPMMLFromUpdateKeyMessage( "MODEL-REF", pmmlPath.toAbsolutePath().toString(), null).getVersion()); assertNull(AppPMMLUtils.readPMMLFromUpdateKeyMessage("MODEL-REF", "no-such-path", null)); }
@Test public void testPreviousPMMLVersion() throws Exception { String pmml42 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<PMML xmlns=\"http://www.dmg.org/PMML-4_2\" version=\"4.2.1\">\n" + " <Header>\n" + " <Application name=\"Oryx\"/>\n" + " </Header>\n" + " <TreeModel functionName=\"classification\">\n" + " <Node recordCount=\"123.0\"/>\n" + " </TreeModel>\n" + "</PMML>\n"; PMML model = PMMLUtils.fromString(pmml42); // Actually transforms to latest version: assertEquals(PMMLUtils.VERSION, model.getVersion()); }
@Test public void unmarshal() throws Exception { Version[] versions = Version.values(); for(Version version : versions){ PMML pmml; try(InputStream is = ResourceUtil.getStream(version)){ pmml = PMMLUtil.unmarshal(is); } assertEquals(pmml.getVersion(), Version.PMML_4_3.getVersion()); assertEquals(pmml.getBaseVersion(), version.getVersion()); } } }
@Test public void copyState(){ PMML pmml = new PMML(Version.PMML_4_3.getVersion(), new Header(), new DataDictionary()); // Initialize the live list instance pmml.getModels(); CustomPMML customPmml = new CustomPMML(); ReflectionUtil.copyState(pmml, customPmml); assertSame(pmml.getVersion(), customPmml.getVersion()); assertSame(pmml.getHeader(), customPmml.getHeader()); assertSame(pmml.getDataDictionary(), customPmml.getDataDictionary()); assertFalse(pmml.hasModels()); assertFalse(customPmml.hasModels()); pmml.addModels(new RegressionModel()); assertTrue(pmml.hasModels()); assertTrue(customPmml.hasModels()); assertSame(pmml.getModels(), customPmml.getModels()); try { ReflectionUtil.copyState(customPmml, pmml); fail(); } catch(IllegalArgumentException iae){ // Ignored } }