Skip to content

Commit

Permalink
Removed a faulty sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Dec 2, 2024
1 parent 7e6b10f commit 6395ba7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,9 @@ public void write(int b) throws IOException {
} else

if(string.endsWith(">")){
String updatedString = string.replace(Version.PMML_4_4.getNamespaceURI(), this.version.getNamespaceURI());
string = string.replace(Version.PMML_4_4.getNamespaceURI(), this.version.getNamespaceURI());

if(Objects.equals(string, updatedString)){
throw new IllegalStateException();
}

super.out.write(updatedString.getBytes("UTF-8"));
super.out.write(string.getBytes("UTF-8"));

this.buffer = null;
} else
Expand Down
54 changes: 54 additions & 0 deletions pmml-model/src/test/java/org/jpmml/model/PMMLOutputStreamTest.java
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");
}
}

0 comments on commit 6395ba7

Please sign in to comment.