-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
pmml-model/src/test/java/org/jpmml/model/PMMLOutputStreamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2024 Villu Ruusmann | ||
*/ | ||
package org.jpmml.model; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.OutputStream; | ||
|
||
import javax.xml.transform.stream.StreamResult; | ||
|
||
import org.dmg.pmml.PMML; | ||
import org.dmg.pmml.Version; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
public class PMMLOutputStreamTest { | ||
|
||
@Test | ||
public void marshal() throws Exception { | ||
PMML pmml = new PMML(); | ||
|
||
try { | ||
marshal(pmml, Version.XPMML); | ||
|
||
fail(); | ||
} catch(IllegalArgumentException iae){ | ||
// Ignored | ||
} | ||
|
||
String string = marshal(pmml, Version.PMML_4_4); | ||
|
||
assertTrue(string.contains(Version.PMML_4_4.getNamespaceURI())); | ||
assertFalse(string.contains(Version.PMML_4_3.getNamespaceURI())); | ||
|
||
string = marshal(pmml, Version.PMML_4_3); | ||
|
||
assertFalse(string.contains(Version.PMML_4_4.getNamespaceURI())); | ||
assertTrue(string.contains(Version.PMML_4_3.getNamespaceURI())); | ||
} | ||
|
||
static | ||
private String marshal(PMML pmml, Version version) throws Exception { | ||
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); | ||
|
||
try(OutputStream os = new PMMLOutputStream(buffer, version)){ | ||
JAXBUtil.marshalPMML(pmml, new StreamResult(os)); | ||
} | ||
|
||
return buffer.toString("UTF-8"); | ||
} | ||
} |