forked from metaschema-framework/metaschema-java
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
acb6cef
commit 04b0886
Showing
5 changed files
with
86 additions
and
5 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
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
41 changes: 41 additions & 0 deletions
41
databind/src/test/java/gov/nist/secauto/metaschema/databind/io/DefaultBoundLoaderTest.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,41 @@ | ||
|
||
package gov.nist.secauto.metaschema.databind.io; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import gov.nist.secauto.metaschema.core.metapath.ISequence; | ||
import gov.nist.secauto.metaschema.core.metapath.MetapathExpression; | ||
import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; | ||
import gov.nist.secauto.metaschema.core.model.IModule; | ||
import gov.nist.secauto.metaschema.core.model.MetaschemaException; | ||
import gov.nist.secauto.metaschema.core.model.xml.ModuleLoader; | ||
import gov.nist.secauto.metaschema.databind.IBindingContext; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
class DefaultBoundLoaderTest { | ||
|
||
@Test | ||
void testIssue187() throws IOException, MetaschemaException { | ||
|
||
IModule module = new ModuleLoader().load(Paths.get("src/test/resources/content/issue187-metaschema.xml")); | ||
|
||
IBindingContext bindingContext = IBindingContext.instance(); | ||
|
||
bindingContext.registerModule(module, Files.createTempDirectory(Paths.get("target"), "modules-")); | ||
|
||
IBoundLoader loader = bindingContext.newBoundLoader(); | ||
|
||
IDocumentNodeItem docItem = loader.loadAsNodeItem(Paths.get("src/test/resources/content/issue187-instance.xml")); | ||
|
||
MetapathExpression metapath = MetapathExpression.compile("//a//b", docItem.getStaticContext()); | ||
|
||
ISequence<?> result = metapath.evaluate(docItem); | ||
|
||
assertEquals(8, result.size()); | ||
} | ||
} |
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,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<a xmlns="http://csrc.nist.gov/ns/test/metaschema/issue187-test"> | ||
<a value="a1"> | ||
<b> | ||
<b value="value1"/> | ||
</b> | ||
<b> | ||
<b value="value2"/> | ||
</b> | ||
</a> | ||
<a value="a2"> | ||
<b> | ||
<b value="value1"/> | ||
</b> | ||
<b> | ||
<b value="value2"/> | ||
</b> | ||
</a> | ||
</a> |
22 changes: 22 additions & 0 deletions
22
databind/src/test/resources/content/issue187-metaschema.xml
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,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?xml-model href="../../../../../core/metaschema/schema/xml/metaschema.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<METASCHEMA xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0"> | ||
<schema-name>Test Metaschema with an external entity</schema-name> | ||
<schema-version>1.0.0</schema-version> | ||
<short-name>issue187-test</short-name> | ||
<namespace>http://csrc.nist.gov/ns/test/metaschema/issue187-test</namespace> | ||
<json-base-uri>http://csrc.nist.gov/ns/test/metaschema/issue187-test</json-base-uri> | ||
<define-assembly name="a"> | ||
<root-name>a</root-name> | ||
<define-flag name="value" as-type="string"/> | ||
<model> | ||
<assembly ref="a" max-occurs="unbounded"> | ||
<group-as name="as" in-json="ARRAY" /> | ||
</assembly> | ||
<assembly ref="a" max-occurs="unbounded"> | ||
<use-name>b</use-name> | ||
<group-as name="bs" in-json="ARRAY" /> | ||
</assembly> | ||
</model> | ||
</define-assembly> | ||
</METASCHEMA> |