-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve Main Schema URI used for Validation #1358
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,9 @@ | |
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.*; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.Channels; | ||
import java.nio.channels.ReadableByteChannel; | ||
|
@@ -1444,5 +1443,45 @@ public void testJavaAPICompileResource() throws IOException, ClassNotFoundExcept | |
} | ||
} | ||
|
||
@Test | ||
public void testJavaAPICompileSource1() throws IOException, URISyntaxException, InvalidUsageException { | ||
org.apache.daffodil.japi.Compiler c = Daffodil.compiler(); | ||
URI uri = new URI("/test/japi/mySchema1.dfdl.xsd"); | ||
ProcessorFactory pf = c.compileSource(uri); | ||
DataProcessor dp = pf.onPath("/").withValidationMode(ValidationMode.Full); | ||
|
||
java.io.File file = getResource("/test/japi/myDataBroken.dat"); | ||
java.io.FileInputStream fis = new java.io.FileInputStream(file); | ||
try (InputSourceDataInputStream dis = new InputSourceDataInputStream(fis)) { | ||
JDOMInfosetOutputter outputter = new JDOMInfosetOutputter(); | ||
ParseResult res = dp.parse(dis, outputter); | ||
assertTrue(res.isError()); | ||
|
||
Diagnostic d = res.getDiagnostics().get(0); | ||
LocationInSchemaFile loc = d.getLocationsInSchemaFiles().get(0); | ||
assertTrue(loc.toString().replace("\\", "/").contains("in " + uri.getPath())); | ||
} | ||
} | ||
|
||
@Test | ||
public void testJavaAPICompileSource2() throws IOException { | ||
org.apache.daffodil.japi.Compiler c = Daffodil.compiler(); | ||
File tempFile = File.createTempFile("testJavaAPI", ".schema"); | ||
File schemaFile = getResource("/test/japi/mySchema2.dfdl.xsd"); | ||
FileUtils.copyFile(schemaFile, tempFile); | ||
ProcessorFactory pf = c.compileSource(tempFile.toURI()); | ||
try { | ||
if (!pf.isError()) { | ||
tempFile.delete(); | ||
pf.onPath("/"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the withValidationMode(Full) case is already tested in the first CompileSource test |
||
} else { | ||
tempFile.delete(); | ||
fail(); | ||
} | ||
} catch (Exception e) { | ||
assertTrue(e.getMessage().contains("Could not find file or resource")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this supposed to fail? Looks to me like testJavaAPI.schema should exist, so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this test is intended to test the case where compileSource succeeds, but onPath can't find the file when it tries to resolve the schemaLocation. It's mainly a coverage test. That's also why we don't call withValidationMode(Full) here, since onPath is where we do the resolution There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, can you add a comment to that affect? Also, in that case I think this needs a try {
assertFalse(pf.isError)
// delete file needed by Xerces for full validation
tempFile.delete()
// should throw FileNotFoundException because ...
pf.onPath("/")
// fail if exception was not thrown
fail()
} catch (Exception e) {
assertTrue(e.getMessage().contains(...))
} finally {
if (tempFile.exists) tempFile.delete()
} Removes the conditionals to make it a bit easier to see what's expected. |
||
} | ||
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we generally try to avoid these star imports.