Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

olabusayoT
Copy link
Contributor

  • currently we pass it in directly without trying to resolve it, which was ok in 3.8.0 because the URI got resolved before we ever got to validation, so we call resolveSchemaLocation on the uriForLoading so that Xerces Validation can use that.
  • added tests to verify

DAFFODIL-2950

- currently we pass it in directly without trying to resolve it, which was ok in  3.8.0 because the URI got resolved before we ever got to validation, so we call resolveSchemaLocation on the uriForLoading so that Xerces Validation can use that.
- added tests to verify

DAFFODIL-2950
@olabusayoT olabusayoT force-pushed the daf-2950-resolveURIForValidation branch from 4ed482e to 578a204 Compare November 2, 2024 00:16
fail();
}
} catch (Exception e) {
assertTrue(e.getMessage().contains("Could not find file or resource"));
Copy link
Member

Choose a reason for hiding this comment

The 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 compileSource and onPath should succeed. Feels like this catch block wants to just contain fail();, or alternatively just remove the try/catch so that any thrown exceptions will cause the test to fail. Maybe we just need a finally block to delete the tmp file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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 fail() and the end of the try block in case the exception isn't thrown. It might be a bit cleaner to rewrite it like this:

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.

try {
if (!pf.isError()) {
tempFile.delete();
pf.onPath("/");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have withValidationMode(full) so that we make sure full validation mode works when the URI has a file scheme? I assume that's what this test is checking for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the withValidationMode(Full) case is already tested in the first CompileSource test

Copy link
Member

@stevedlawrence stevedlawrence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, just needs some comments in the tests

fail();
}
} catch (Exception e) {
assertTrue(e.getMessage().contains("Could not find file or resource"));
Copy link
Member

Choose a reason for hiding this comment

The 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 fail() and the end of the try block in case the exception isn't thrown. It might be a bit cleaner to rewrite it like this:

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.

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.*;
Copy link
Member

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.

- fix * in import for java tests
- refactor test code and add comments to make purpose more clear
- rename Scala test that had Java in the name

DAFFODIL-2950
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants