From d1c06d83e84099e3bbbc353c6ef6f69b136516dd Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Fri, 4 Aug 2023 09:27:06 -0400 Subject: [PATCH] Integrating further metaschema-java refactoring. --- .../oscal/lib/OscalBindingContext.java | 8 +- .../nist/secauto/oscal/lib/OscalUtils.java | 68 -------- .../function/library/HasOscalNamespace.java | 3 + .../function/library/ResolveProfile.java | 3 + .../control/catalog/AbstractControl.java | 2 +- .../lib/model/metadata/AbstractProperty.java | 1 + .../oscal/lib/model/metadata/IProperty.java | 4 +- .../lib/profile/resolver/ProfileResolver.java | 149 +++++++++--------- .../merge/FlatteningStructuringVisitor.java | 2 +- .../policy/ReferenceCountingVisitor.java | 18 ++- .../resolver/support/AbstractEntityItem.java | 2 +- .../resolver/support/BasicIndexer.java | 18 ++- .../profile/resolver/support/IIndexer.java | 33 ++-- .../nist/secauto/oscal/java/ExamplesTest.java | 23 +-- .../oscal/java/MetaschemaVisitorTest.java | 38 +++-- .../oscal/java/OscalBindingContextTest.java | 6 +- .../secauto/oscal/java/ReadWriteTest.java | 14 +- .../resolver/ProfileResolutionTests.java | 13 +- .../oscal/lib/profile/resolver/TestUtil.java | 2 +- .../policy/ReferenceCountingVisitorTest.java | 2 +- .../FilterNonSelectedVisitorTest.java | 2 +- .../resolver/selection/ImportTest.java | 9 +- src/test/resources/log4j2-test.xml | 4 +- src/test/resources/profile-test-helper.xsl | 75 +++++++++ 24 files changed, 276 insertions(+), 223 deletions(-) create mode 100644 src/test/resources/profile-test-helper.xsl diff --git a/src/main/java/gov/nist/secauto/oscal/lib/OscalBindingContext.java b/src/main/java/gov/nist/secauto/oscal/lib/OscalBindingContext.java index cd427f25..67bcba83 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/OscalBindingContext.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/OscalBindingContext.java @@ -26,9 +26,9 @@ package gov.nist.secauto.oscal.lib; -import gov.nist.secauto.metaschema.binding.DefaultBindingContext; -import gov.nist.secauto.metaschema.binding.IBindingMatcher; import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; +import gov.nist.secauto.metaschema.databind.DefaultBindingContext; +import gov.nist.secauto.metaschema.databind.IBindingMatcher; import gov.nist.secauto.oscal.lib.model.AssessmentPlan; import gov.nist.secauto.oscal.lib.model.AssessmentResults; import gov.nist.secauto.oscal.lib.model.Catalog; @@ -51,6 +51,8 @@ public class OscalBindingContext extends DefaultBindingContext { @NonNull + public static final String NS_OSCAL = "http://csrc.nist.gov/ns/oscal/1.0"; + @NonNull private static final OscalBindingContext SINGLETON = new OscalBindingContext(); @NonNull @@ -186,7 +188,7 @@ private static final class Matcher implements IBindingMatcher { @Override public Class getBoundClassForXmlQName(QName startElementQName) { Class clazz = null; - if ("http://csrc.nist.gov/ns/oscal/1.0".equals(startElementQName.getNamespaceURI())) { + if (NS_OSCAL.equals(startElementQName.getNamespaceURI())) { switch (startElementQName.getLocalPart()) { case "catalog": clazz = Catalog.class; diff --git a/src/main/java/gov/nist/secauto/oscal/lib/OscalUtils.java b/src/main/java/gov/nist/secauto/oscal/lib/OscalUtils.java index 9a1fb520..42b26735 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/OscalUtils.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/OscalUtils.java @@ -26,22 +26,12 @@ package gov.nist.secauto.oscal.lib; -import com.fasterxml.jackson.databind.util.ByteBufferBackedInputStream; - import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.model.BackMatter.Resource; -import gov.nist.secauto.oscal.lib.model.BackMatter.Resource.Base64; import gov.nist.secauto.oscal.lib.model.BackMatter.Resource.Rlink; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -import java.io.IOException; import java.net.URI; -import java.nio.ByteBuffer; import java.util.List; -import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -49,7 +39,6 @@ import edu.umd.cs.findbugs.annotations.Nullable; public final class OscalUtils { - public static final String OSCAL_VERSION = "1.0.4"; private static final Pattern INTERNAL_REFERENCE_FRAGMENT_PATTERN = Pattern.compile("^#(.+)$"); private OscalUtils() { @@ -103,37 +92,6 @@ public static String internalReferenceFragmentToId(@NonNull String fragment) { return retval; } - public static boolean hasBase64Data(@NonNull Resource resource) { - return resource.getBase64() != null; - } - - @Nullable - public static ByteBuffer getBase64Data(@NonNull Resource resource) { - Base64 base64 = resource.getBase64(); - - ByteBuffer retval = null; - if (base64 != null) { - retval = base64.getValue(); - } - return retval; - } - - @Nullable - public static URI getResourceURI(@NonNull Resource resource, @Nullable String preferredMediaType) { - URI retval; - if (hasBase64Data(resource)) { - UUID uuid = resource.getUuid(); - if (uuid == null) { - throw new IllegalArgumentException("resource has a null UUID"); - } - retval = ObjectUtils.notNull(URI.create("#" + uuid)); - } else { - Rlink rlink = findMatchingRLink(resource, preferredMediaType); - retval = rlink == null ? null : rlink.getHref(); - } - return retval; - } - @Nullable public static Rlink findMatchingRLink(@NonNull Resource resource, @Nullable String preferredMediaType) { // find a suitable rlink reference @@ -153,30 +111,4 @@ public static Rlink findMatchingRLink(@NonNull Resource resource, @Nullable Stri } return retval; } - - @Nullable - public static InputSource newInputSource(@NonNull Resource resource, @NonNull EntityResolver resolver, - @Nullable String preferredMediaType) throws IOException { - URI uri = getResourceURI(resource, preferredMediaType); - if (uri == null) { - throw new IOException(String.format("unable to determine URI for resource '%s'", resource.getUuid())); - } - - InputSource retval; - try { - retval = resolver.resolveEntity(null, uri.toASCIIString()); - } catch (SAXException ex) { - throw new IOException(ex); - } - - if (hasBase64Data(resource)) { - // handle base64 encoded data - ByteBuffer buffer = getBase64Data(resource); - if (buffer == null) { - throw new IOException(String.format("null base64 value for resource '%s'", resource.getUuid())); - } - retval.setByteStream(new ByteBufferBackedInputStream(buffer)); - } - return retval; - } } diff --git a/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/HasOscalNamespace.java b/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/HasOscalNamespace.java index fa9256ce..1d29f3ee 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/HasOscalNamespace.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/HasOscalNamespace.java @@ -38,6 +38,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem; import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.lib.model.AssessmentPart; import gov.nist.secauto.oscal.lib.model.ControlPart; import gov.nist.secauto.oscal.lib.model.Property; @@ -52,6 +53,7 @@ public final class HasOscalNamespace { @NonNull static final IFunction SIGNATURE_ONE_ARG = IFunction.builder() .name("has-oscal-namespace") + .namespace(OscalBindingContext.NS_OSCAL) .argument(IArgument.newBuilder() .name("namespace") .type(IStringItem.class) @@ -69,6 +71,7 @@ public final class HasOscalNamespace { @NonNull static final IFunction SIGNATURE_TWO_ARGS = IFunction.builder() .name("has-oscal-namespace") + .namespace(OscalBindingContext.NS_OSCAL) .argument(IArgument.newBuilder() .name("propOrPart") .type(IAssemblyNodeItem.class) diff --git a/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/ResolveProfile.java b/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/ResolveProfile.java index e29cf2b9..f2edfa53 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/ResolveProfile.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/ResolveProfile.java @@ -36,6 +36,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.lib.model.Catalog; import gov.nist.secauto.oscal.lib.profile.resolver.ProfileResolutionException; import gov.nist.secauto.oscal.lib.profile.resolver.ProfileResolver; @@ -50,6 +51,7 @@ public final class ResolveProfile { @NonNull static final IFunction SIGNATURE_NO_ARG = IFunction.builder() .name("resolve-profile") + .namespace(OscalBindingContext.NS_OSCAL) .returnType(INodeItem.class) .focusDependent() .contextDependent() @@ -61,6 +63,7 @@ public final class ResolveProfile { @NonNull static final IFunction SIGNATURE_ONE_ARG = IFunction.builder() .name("resolve-profile") + .namespace(OscalBindingContext.NS_OSCAL) .argument(IArgument.newBuilder() .name("profile") .type(INodeItem.class) diff --git a/src/main/java/gov/nist/secauto/oscal/lib/model/control/catalog/AbstractControl.java b/src/main/java/gov/nist/secauto/oscal/lib/model/control/catalog/AbstractControl.java index bbfa44a0..23a3df33 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/model/control/catalog/AbstractControl.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/model/control/catalog/AbstractControl.java @@ -26,10 +26,10 @@ package gov.nist.secauto.oscal.lib.model.control.catalog; -import gov.nist.secauto.metaschema.binding.io.IDeserializationHandler; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.io.IDeserializationHandler; import gov.nist.secauto.oscal.lib.model.Control; import gov.nist.secauto.oscal.lib.model.ControlPart; import gov.nist.secauto.oscal.lib.model.Link; diff --git a/src/main/java/gov/nist/secauto/oscal/lib/model/metadata/AbstractProperty.java b/src/main/java/gov/nist/secauto/oscal/lib/model/metadata/AbstractProperty.java index fa30290c..ef91b23d 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/model/metadata/AbstractProperty.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/model/metadata/AbstractProperty.java @@ -112,6 +112,7 @@ public Builder uuid(@NonNull UUID uuid) { return this; } + @SuppressWarnings("PMD.NullAssignment") // needed @NonNull public Builder namespace(@NonNull URI namespace) { if (IProperty.OSCAL_NAMESPACE.equals(namespace)) { diff --git a/src/main/java/gov/nist/secauto/oscal/lib/model/metadata/IProperty.java b/src/main/java/gov/nist/secauto/oscal/lib/model/metadata/IProperty.java index a026e78c..dae33a69 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/model/metadata/IProperty.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/model/metadata/IProperty.java @@ -26,6 +26,8 @@ package gov.nist.secauto.oscal.lib.model.metadata; +import gov.nist.secauto.oscal.lib.OscalBindingContext; + import java.net.URI; import edu.umd.cs.findbugs.annotations.NonNull; @@ -33,7 +35,7 @@ public interface IProperty { @SuppressWarnings("null") @NonNull - URI OSCAL_NAMESPACE = URI.create("http://csrc.nist.gov/ns/oscal"); + URI OSCAL_NAMESPACE = URI.create(OscalBindingContext.NS_OSCAL); @SuppressWarnings("null") @NonNull URI RMF_NAMESPACE = URI.create("http://csrc.nist.gov/ns/rmf"); diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolver.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolver.java index c431700f..fd9836f9 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolver.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolver.java @@ -26,12 +26,10 @@ package gov.nist.secauto.oscal.lib.profile.resolver; -import gov.nist.secauto.metaschema.binding.io.BindingException; -import gov.nist.secauto.metaschema.binding.io.DeserializationFeature; -import gov.nist.secauto.metaschema.binding.io.IBoundLoader; -import gov.nist.secauto.metaschema.binding.model.IAssemblyClassBinding; -import gov.nist.secauto.metaschema.binding.model.RootAssemblyDefinition; +import com.fasterxml.jackson.databind.util.ByteBufferBackedInputStream; + import gov.nist.secauto.metaschema.core.metapath.DynamicContext; +import gov.nist.secauto.metaschema.core.metapath.IDocumentLoader; import gov.nist.secauto.metaschema.core.metapath.ISequence; import gov.nist.secauto.metaschema.core.metapath.MetapathExpression; import gov.nist.secauto.metaschema.core.metapath.StaticContext; @@ -45,10 +43,17 @@ import gov.nist.secauto.metaschema.core.metapath.item.node.IRootAssemblyNodeItem; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.io.BindingException; +import gov.nist.secauto.metaschema.databind.io.DeserializationFeature; +import gov.nist.secauto.metaschema.databind.io.IBoundLoader; +import gov.nist.secauto.metaschema.databind.model.IAssemblyClassBinding; +import gov.nist.secauto.metaschema.databind.model.RootAssemblyDefinition; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.lib.OscalUtils; import gov.nist.secauto.oscal.lib.model.BackMatter; import gov.nist.secauto.oscal.lib.model.BackMatter.Resource; +import gov.nist.secauto.oscal.lib.model.BackMatter.Resource.Base64; +import gov.nist.secauto.oscal.lib.model.BackMatter.Resource.Rlink; import gov.nist.secauto.oscal.lib.model.Catalog; import gov.nist.secauto.oscal.lib.model.Control; import gov.nist.secauto.oscal.lib.model.Merge; @@ -74,15 +79,14 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.nio.ByteBuffer; import java.nio.file.Path; import java.time.ZoneOffset; import java.time.ZonedDateTime; @@ -128,7 +132,8 @@ public enum StructuringDirective { private DynamicContext dynamicContext; /** - * Gets the configured loader or creates a new default loader if no loader was configured. + * Gets the configured loader or creates a new default loader if no loader was + * configured. * * @return the bound loader */ @@ -155,7 +160,7 @@ public void setBoundLoader(@NonNull IBoundLoader loader) { public DynamicContext getDynamicContext() { synchronized (this) { if (dynamicContext == null) { - dynamicContext = new StaticContext().newDynamicContext(); + dynamicContext = StaticContext.builder().build().newDynamicContext(); dynamicContext.setDocumentLoader(getBoundLoader()); } assert dynamicContext != null; @@ -170,11 +175,6 @@ public void setDynamicContext(@NonNull DynamicContext dynamicContext) { } } - @NonNull - protected EntityResolver getEntityResolver(@NonNull URI documentUri) { - return new DocumentEntityResolver(documentUri); - } - @Nullable private static IRootAssemblyNodeItem getRoot( @NonNull IDocumentNodeItem document, @@ -359,25 +359,30 @@ protected IIndexer resolveImport( LOGGER.atDebug().log("resolving profile import '{}'", importUri); } - InputSource source = newImportSource(importUri, profileItem); - URI sourceUri = ObjectUtils.notNull(URI.create(source.getSystemId())); + IDocumentNodeItem importedDocument = getImport(importUri, profileItem); + URI importedUri = importedDocument.getDocumentUri(); + assert importedUri != null; // always non-null + + // Import import = Import. + // InputSource source = newImportSource(importUri, profileItem); + // URI sourceUri = ObjectUtils.notNull(URI.create(source.getSystemId())); // check for import cycle try { requireNonCycle( - sourceUri, + importedUri, importHistory); } catch (ImportCycleException ex) { throw new IOException(ex); } // track the import in the import history - importHistory.push(sourceUri); + importHistory.push(importedUri); try { - IDocumentNodeItem document = getDynamicContext().getDocumentLoader().loadAsNodeItem(source); - IDocumentNodeItem importedCatalog = resolve(document, importHistory); + IDocumentNodeItem importedCatalog = resolve(importedDocument, importHistory); - // Create a defensive deep copy of the document and associated values, since we will be making + // Create a defensive deep copy of the document and associated values, since we + // will be making // changes to the data. try { IRootAssemblyNodeItem importedCatalogRoot = ObjectUtils.requireNonNull(getRoot(importedCatalog, CATALOG)); @@ -397,45 +402,70 @@ protected IIndexer resolveImport( } finally { // pop the resolved catalog from the import history URI poppedUri = ObjectUtils.notNull(importHistory.pop()); - assert sourceUri.equals(poppedUri); + assert importedUri.equals(poppedUri); } } - @NonNull - protected InputSource newImportSource( + private IDocumentNodeItem getImport( @NonNull URI importUri, - @NonNull IRootAssemblyNodeItem profileItem) throws IOException { + @NonNull IRootAssemblyNodeItem importingProfile) throws IOException { - // Get the entity resolver to resolve relative references in the profile - EntityResolver resolver = getEntityResolver( - ObjectUtils.requireNonNull(profileItem.getDocumentNodeItem().getDocumentUri())); + URI importingDocumentUri = ObjectUtils.requireNonNull(importingProfile.getDocumentNodeItem().getDocumentUri()); - InputSource source; + IDocumentNodeItem retval; if (OscalUtils.isInternalReference(importUri)) { // handle internal reference String uuid = OscalUtils.internalReferenceFragmentToId(importUri); - Profile profile = toProfile(profileItem); + Profile profile = INodeItem.toValue(importingProfile); Resource resource = profile.getResourceByUuid(ObjectUtils.notNull(UUID.fromString(uuid))); if (resource == null) { throw new IOException( String.format("unable to find the resource identified by '%s' used in profile import", importUri)); } - source = OscalUtils.newInputSource(resource, resolver, null); + retval = getImport(resource, importingDocumentUri); } else { - try { - source = resolver.resolveEntity(null, importUri.toASCIIString()); - } catch (SAXException ex) { - throw new IOException(ex); - } + URI uri = importingDocumentUri.resolve(importUri); + assert uri != null; + + retval = getDynamicContext().getDocumentLoader().loadAsNodeItem(uri); } + return retval; + } - if (source == null || source.getSystemId() == null) { - throw new IOException(String.format("Unable to resolve import '%s'.", importUri.toString())); + @Nullable + private IDocumentNodeItem getImport( + @NonNull Resource resource, + @NonNull URI baseUri) throws IOException { + + IDocumentLoader loader = getDynamicContext().getDocumentLoader(); + + IDocumentNodeItem retval = null; + // first try base64 data + Base64 base64 = resource.getBase64(); + ByteBuffer buffer = base64 == null ? null : base64.getValue(); + if (buffer != null) { + URI resourceUri = baseUri.resolve("#" + resource.getUuid()); + assert resourceUri != null; + try (InputStream is = new ByteBufferBackedInputStream(buffer)) { + retval = loader.loadAsNodeItem(is, resourceUri); + } } - return source; + if (retval == null) { + Rlink rlink = OscalUtils.findMatchingRLink(resource, null); + URI uri = rlink == null ? null : rlink.getHref(); + + if (uri == null) { + throw new IOException(String.format("unable to determine URI for resource '%s'", resource.getUuid())); + } + + uri = baseUri.resolve(uri); + assert uri != null; + retval = loader.loadAsNodeItem(uri); + } + return retval; } private static void requireNonCycle(@NonNull URI uri, @NonNull Stack importHistory) @@ -507,14 +537,17 @@ protected void structureFlat(@NonNull Catalog resolvedCatalog, @NonNull IRootAss // { // // rebuild an index - // IDocumentNodeItem resolvedCatalogItem = DefaultNodeItemFactory.instance().newDocumentNodeItem( + // IDocumentNodeItem resolvedCatalogItem = + // DefaultNodeItemFactory.instance().newDocumentNodeItem( // new RootAssemblyDefinition( // ObjectUtils.notNull( - // (IAssemblyClassBinding) OscalBindingContext.instance().getClassBinding(Catalog.class))), + // (IAssemblyClassBinding) + // OscalBindingContext.instance().getClassBinding(Catalog.class))), // resolvedCatalog, // profileDocument.getBaseUri()); // - // // FIXME: need to find a better way to create an index that doesn't auto select groups + // // FIXME: need to find a better way to create an index that doesn't auto + // select groups // IIndexer indexer = new BasicIndexer(); // ControlSelectionVisitor selectionVisitor // = new ControlSelectionVisitor(IControlFilter.ALWAYS_MATCH, indexer); @@ -721,34 +754,4 @@ private static void handleReferences(@NonNull Catalog resolvedCatalog, @NonNull index.append(profileIndex); } - private class DocumentEntityResolver implements EntityResolver { - @NonNull - private final URI documentUri; - - public DocumentEntityResolver(@NonNull URI documentUri) { - this.documentUri = documentUri; - } - - @NonNull - protected URI getDocumentUri() { - return documentUri; - } - - @Override - public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { - - URI resolvedUri = getDocumentUri().resolve(systemId); - - EntityResolver resolver = getDynamicContext().getDocumentLoader().getEntityResolver(); - - InputSource retval; - if (resolver == null) { - retval = new InputSource(resolvedUri.toASCIIString()); - } else { - retval = resolver.resolveEntity(publicId, resolvedUri.toASCIIString()); - } - return retval; - } - - } } diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/merge/FlatteningStructuringVisitor.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/merge/FlatteningStructuringVisitor.java index 0266421a..c61faacd 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/merge/FlatteningStructuringVisitor.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/merge/FlatteningStructuringVisitor.java @@ -26,11 +26,11 @@ package gov.nist.secauto.oscal.lib.profile.resolver.merge; -import gov.nist.secauto.oscal.lib.model.BackMatter.Resource; import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.IRootAssemblyNodeItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.oscal.lib.model.BackMatter.Resource; import gov.nist.secauto.oscal.lib.model.CatalogGroup; import gov.nist.secauto.oscal.lib.model.Control; import gov.nist.secauto.oscal.lib.model.ControlPart; diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/ReferenceCountingVisitor.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/ReferenceCountingVisitor.java index 8689dfde..510413ff 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/ReferenceCountingVisitor.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/ReferenceCountingVisitor.java @@ -136,7 +136,8 @@ public static ReferenceCountingVisitor instance() { } public ReferenceCountingVisitor() { - // visit everything except parts, roles, locations, parties, parameters, and resources, which are + // visit everything except parts, roles, locations, parties, parameters, and + // resources, which are // handled differently by this visitor super(ObjectUtils.notNull(EnumSet.complementOf( EnumSet.of( @@ -170,7 +171,8 @@ protected Void aggregateResults(Void first, Void second, Context context) { // // BackMatter backMatter = profile.getBackMatter(); // if (backMatter != null) { - // for (BackMatter.Resource resource : CollectionUtil.listOrEmpty(backMatter.getResources())) { + // for (BackMatter.Resource resource : + // CollectionUtil.listOrEmpty(backMatter.getResources())) { // visitResource(resource); // } // } @@ -211,7 +213,8 @@ public Void visitGroup( Context context) { IIndexer index = context.getIndexer(); // handle the group if it is selected - // a group will only be selected if it contains a descendant control that is selected + // a group will only be selected if it contains a descendant control that is + // selected if (IIndexer.SelectionStatus.SELECTED.equals(index.getSelectionStatus(item))) { CatalogGroup group = ObjectUtils.requireNonNull((CatalogGroup) item.getValue()); String id = group.getId(); @@ -416,7 +419,8 @@ private static void resolvePart( .forEach(child -> handleLink(ObjectUtils.notNull((IAssemblyNodeItem) child), context)); item.getModelItemsByName("prose") .forEach(child -> handleMarkup(ObjectUtils.notNull((IFieldNodeItem) child), context)); - // item.getModelItemsByName("part").forEach(child -> visitor.visitPart(ObjectUtils.notNull(child), + // item.getModelItemsByName("part").forEach(child -> + // visitor.visitPart(ObjectUtils.notNull(child), // context)); } @@ -432,7 +436,8 @@ private static void handleMarkup( @NonNull IFieldNodeItem contextItem, @NonNull IMarkupString text, @NonNull Context context) { - for (Node node : CollectionUtil.toIterable(text.getNodesAsStream().iterator())) { + for (Node node : CollectionUtil.toIterable( + ObjectUtils.notNull(text.getNodesAsStream().iterator()))) { if (node instanceof InsertAnchorNode) { handleInsert(contextItem, (InsertAnchorNode) node, context); } else if (node instanceof InlineLinkNode) { @@ -567,7 +572,8 @@ protected void entityDispatch(@NonNull IEntityItem entity, @NonNull Context cont // } // // @Override - // protected Void aggregateResults(Object first, Object second, Object context) { + // protected Void aggregateResults(Object first, Object second, Object context) + // { // return null; // } diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractEntityItem.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractEntityItem.java index b1348842..67c4ad34 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractEntityItem.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractEntityItem.java @@ -84,7 +84,7 @@ public void setInstance(IModelNodeItem item) { @NonNull @SuppressWarnings("unchecked") public T getInstanceValue() { - return (T) getInstance().getValue(); + return ObjectUtils.notNull((T) getInstance().getValue()); } @Override diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/BasicIndexer.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/BasicIndexer.java index 213d8b4c..420cb976 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/BasicIndexer.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/BasicIndexer.java @@ -26,7 +26,6 @@ package gov.nist.secauto.oscal.lib.profile.resolver.support; -import gov.nist.secauto.oscal.lib.model.BackMatter.Resource; import gov.nist.secauto.metaschema.core.datatype.adapter.UuidAdapter; import gov.nist.secauto.metaschema.core.metapath.MetapathExpression; import gov.nist.secauto.metaschema.core.metapath.MetapathExpression.ResultType; @@ -34,6 +33,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.oscal.lib.model.BackMatter.Resource; import gov.nist.secauto.oscal.lib.model.CatalogGroup; import gov.nist.secauto.oscal.lib.model.Control; import gov.nist.secauto.oscal.lib.model.ControlPart; @@ -190,11 +190,14 @@ public Collection getEntitiesByItemType(@NonNull IEntityItem.ItemTy return entityGroup == null ? CollectionUtil.emptyList() : ObjectUtils.notNull(entityGroup.values()); } // - // public EntityItem getEntity(@NonNull ItemType itemType, @NonNull UUID identifier) { - // return getEntity(itemType, ObjectUtils.notNull(identifier.toString()), false); + // public EntityItem getEntity(@NonNull ItemType itemType, @NonNull UUID + // identifier) { + // return getEntity(itemType, ObjectUtils.notNull(identifier.toString()), + // false); // } // - // public EntityItem getEntity(@NonNull ItemType itemType, @NonNull String identifier) { + // public EntityItem getEntity(@NonNull ItemType itemType, @NonNull String + // identifier) { // return getEntity(itemType, identifier, itemType.isUuid()); // } @@ -327,10 +330,11 @@ protected final AbstractEntityItem.Builder newBuilder( /** * Create a new builder with the provided info. *

- * This method can be overloaded to support applying additional data to the returned builder. + * This method can be overloaded to support applying additional data to the + * returned builder. *

- * When working with identifiers that are case insensitve, it is important to ensure that the - * identifiers are normalized to lower case. + * When working with identifiers that are case insensitve, it is important to + * ensure that the identifiers are normalized to lower case. * * @param item * the Metapath node to associate with the entity diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/IIndexer.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/IIndexer.java index e07b4784..76e517b3 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/IIndexer.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/IIndexer.java @@ -32,6 +32,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; import gov.nist.secauto.metaschema.core.util.CustomCollectors; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.lib.profile.resolver.support.IEntityItem.ItemType; import org.apache.logging.log4j.Level; @@ -58,7 +59,7 @@ enum SelectionStatus { } MetapathExpression HAS_PROP_KEEP_METAPATH = MetapathExpression - .compile("prop[@name='keep' and has-oscal-namespace('http://csrc.nist.gov/ns/oscal')]/@value = 'always'"); + .compile("prop[@name='keep' and has-oscal-namespace('" + OscalBindingContext.NS_OSCAL + "')]/@value = 'always'"); Predicate KEEP_ENTITY_PREDICATE = new Predicate<>() { @@ -76,8 +77,8 @@ static boolean isReferencedEntity(@NonNull IEntityItem entity) { } /** - * Keep entities that have a reference count greater than zero or are required to be kept based on - * the "keep"="always property. + * Keep entities that have a reference count greater than zero or are required + * to be kept based on the "keep"="always property. * * @param entities * the entity items to filter @@ -88,8 +89,8 @@ static Stream getReferencedEntitiesAsStream(@NonNull Collection serializer = bindingContext.newSerializer(Format.YAML, Catalog.class); // serialize the catalog as yaml - serializer.serialize( - (Catalog) INodeItem.toValue(resolvedCatalog), - ObjectUtils.notNull(System.out)); + @SuppressWarnings("resource") // not owned + OutputStream os = ObjectUtils.notNull(System.out); + + serializer.serialize((Catalog) INodeItem.toValue(resolvedCatalog), os); } } diff --git a/src/test/java/gov/nist/secauto/oscal/java/MetaschemaVisitorTest.java b/src/test/java/gov/nist/secauto/oscal/java/MetaschemaVisitorTest.java index 2247a5b6..0e50b3d3 100644 --- a/src/test/java/gov/nist/secauto/oscal/java/MetaschemaVisitorTest.java +++ b/src/test/java/gov/nist/secauto/oscal/java/MetaschemaVisitorTest.java @@ -26,13 +26,14 @@ package gov.nist.secauto.oscal.java; -import gov.nist.secauto.metaschema.binding.io.IBoundLoader; import gov.nist.secauto.metaschema.core.metapath.DynamicContext; import gov.nist.secauto.metaschema.core.metapath.ISequence; import gov.nist.secauto.metaschema.core.metapath.MetapathExpression; import gov.nist.secauto.metaschema.core.metapath.StaticContext; import gov.nist.secauto.metaschema.core.metapath.item.IItem; import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.io.IBoundLoader; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.lib.metapath.function.library.ResolveProfile; @@ -57,10 +58,10 @@ void test() throws FileNotFoundException, IOException, URISyntaxException { OscalBindingContext bindingContext = OscalBindingContext.instance(); IBoundLoader loader = bindingContext.newBoundLoader(); - StaticContext staticContext = new StaticContext(); - @SuppressWarnings("null") - @NonNull URI baseUri = new File("").getAbsoluteFile().toURI(); - staticContext.setBaseUri(baseUri); + URI baseUri = ObjectUtils.notNull(new File("").getAbsoluteFile().toURI()); + StaticContext staticContext = StaticContext.builder() + .baseUri(baseUri) + .build(); DynamicContext dynamicContext = staticContext.newDynamicContext(); dynamicContext.setDocumentLoader(loader); @@ -82,31 +83,40 @@ void test() throws FileNotFoundException, IOException, URISyntaxException { // File("resolved-catalog.xml"))); // evaluatePath(MetapathExpression.compile("resolve-profile(doc(resolve-uri(/profile/import/@href, - // document-uri(/profile))))/(profile, catalog)//control/@id"), nodeItem, dynamicContext); + // document-uri(/profile))))/(profile, catalog)//control/@id"), nodeItem, + // dynamicContext); evaluatePath(MetapathExpression.compile("//control/@id"), resolvedProfile, dynamicContext); // evaluatePath(MetapathExpression.compile("doc(resolve-uri(/profile/import/@href, - // document-uri(/profile)))/catalog/metadata/last-modified"), nodeItem, dynamicContext); + // document-uri(/profile)))/catalog/metadata/last-modified"), nodeItem, + // dynamicContext); // evaluatePath( // MetapathExpression.compile("doc(resolve-uri(/profile/import/@href, - // document-uri(/profile)))/catalog/metadata/last-modified - /catalog/metadata/last-modified"), + // document-uri(/profile)))/catalog/metadata/last-modified - + // /catalog/metadata/last-modified"), // nodeItem, dynamicContext); // evaluatePath(MetapathExpression.compile("doc(resolve-uri(/profile/import/@href, - // document-uri(/profile)))/catalog/metadata/last-modified + duration('PT1H')"), nodeItem, + // document-uri(/profile)))/catalog/metadata/last-modified + duration('PT1H')"), + // nodeItem, // dynamicContext); // evaluatePath(MetapathExpression.compile("doc(resolve-uri(/profile/import/@href, // document-uri(/profile)))/catalog/metadata/last-modified,/catalog/metadata/last-modified"), // nodeItem, dynamicContext); // evaluatePath(MetapathExpression.compile("doc('target/download/content/NIST_SP-800-53_rev5_catalog.xml')"), // nodeItem, dynamicContext); - // evaluatePath(Metapath.parseMetapathString("2 eq 1 + 1[/catalog]"), nodeContext, visitor); + // evaluatePath(Metapath.parseMetapathString("2 eq 1 + 1[/catalog]"), + // nodeContext, visitor); // evaluatePath(Metapath.parseMetapathString("/catalog/back-matter/resource[rlink/@href='https://doi.org/10.6028/NIST.SP.800-53r5']"), // nodeItem, dynamicContext); - // evaluatePath(MetapathExpression.compile("/catalog//(@id,@uuid)"), nodeItem, dynamicContext); - // evaluatePath(MetapathExpression.compile("exists(/catalog//(@id,@uuid))"), nodeItem, + // evaluatePath(MetapathExpression.compile("/catalog//(@id,@uuid)"), nodeItem, + // dynamicContext); + // evaluatePath(MetapathExpression.compile("exists(/catalog//(@id,@uuid))"), + // nodeItem, // dynamicContext); - // evaluatePath(MetapathExpression.compile("/catalog//control//prop/@name"), nodeItem, + // evaluatePath(MetapathExpression.compile("/catalog//control//prop/@name"), + // nodeItem, // dynamicContext); - // evaluatePath(Metapath.parseMetapathString("(/catalog//control[@id='ac-1'])"), nodeItem, + // evaluatePath(Metapath.parseMetapathString("(/catalog//control[@id='ac-1'])"), + // nodeItem, // dynamicContext); } diff --git a/src/test/java/gov/nist/secauto/oscal/java/OscalBindingContextTest.java b/src/test/java/gov/nist/secauto/oscal/java/OscalBindingContextTest.java index 24246736..233d39e2 100644 --- a/src/test/java/gov/nist/secauto/oscal/java/OscalBindingContextTest.java +++ b/src/test/java/gov/nist/secauto/oscal/java/OscalBindingContextTest.java @@ -29,10 +29,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import gov.nist.secauto.metaschema.binding.io.Format; -import gov.nist.secauto.metaschema.binding.io.IBoundLoader; -import gov.nist.secauto.metaschema.binding.io.ISerializer; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.io.Format; +import gov.nist.secauto.metaschema.databind.io.IBoundLoader; +import gov.nist.secauto.metaschema.databind.io.ISerializer; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.lib.model.Catalog; import gov.nist.secauto.oscal.lib.model.Profile; diff --git a/src/test/java/gov/nist/secauto/oscal/java/ReadWriteTest.java b/src/test/java/gov/nist/secauto/oscal/java/ReadWriteTest.java index cac6d7b9..4ea3924e 100644 --- a/src/test/java/gov/nist/secauto/oscal/java/ReadWriteTest.java +++ b/src/test/java/gov/nist/secauto/oscal/java/ReadWriteTest.java @@ -28,12 +28,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue; -import gov.nist.secauto.metaschema.binding.IBindingContext; -import gov.nist.secauto.metaschema.binding.io.DeserializationFeature; -import gov.nist.secauto.metaschema.binding.io.Format; -import gov.nist.secauto.metaschema.binding.io.IDeserializer; -import gov.nist.secauto.metaschema.binding.io.ISerializer; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.IBindingContext; +import gov.nist.secauto.metaschema.databind.io.DeserializationFeature; +import gov.nist.secauto.metaschema.databind.io.Format; +import gov.nist.secauto.metaschema.databind.io.IDeserializer; +import gov.nist.secauto.metaschema.databind.io.ISerializer; import gov.nist.secauto.oscal.lib.model.Catalog; import org.apache.logging.log4j.LogManager; @@ -50,6 +50,8 @@ class ReadWriteTest { private static final Logger LOGGER = LogManager.getLogger(ReadWriteTest.class); + private static final int ITERATIONS = 1; + @NonNull private static CLASS measureDeserializer( @NonNull String format, @@ -169,6 +171,6 @@ void testOscalCatalogMetrics(@NonNull @TempDir Path tempDir) throws IOException // outDir.mkdirs(); // Path outPath = outDir.toPath(); Path outPath = tempDir; - chainReadWrite(catalogSourceXml, Catalog.class, outPath, 1); + chainReadWrite(catalogSourceXml, Catalog.class, outPath, ITERATIONS); } } diff --git a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolutionTests.java b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolutionTests.java index 6c7a8a5b..5554e8c3 100644 --- a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolutionTests.java +++ b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolutionTests.java @@ -31,12 +31,12 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; -import gov.nist.secauto.metaschema.binding.io.DefaultBoundLoader; -import gov.nist.secauto.metaschema.binding.io.Format; -import gov.nist.secauto.metaschema.binding.io.ISerializer; import gov.nist.secauto.metaschema.core.metapath.DynamicContext; import gov.nist.secauto.metaschema.core.metapath.StaticContext; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +import gov.nist.secauto.metaschema.databind.io.DefaultBoundLoader; +import gov.nist.secauto.metaschema.databind.io.Format; +import gov.nist.secauto.metaschema.databind.io.ISerializer; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.lib.model.Catalog; import gov.nist.secauto.oscal.lib.profile.resolver.selection.ImportCycleException; @@ -74,7 +74,7 @@ import edu.umd.cs.findbugs.annotations.NonNull; class ProfileResolutionTests { - private static final String XSLT_PATH = "oscal/src/utils/resolver-pipeline/oscal-profile-test-helper.xsl"; + private static final String XSLT_PATH = "src/test/resources/profile-test-helper.xsl"; private static final String PROFILE_UNIT_TEST_PATH = "oscal/src/specifications/profile-resolution/profile-resolution-examples"; private static final String JUNIT_TEST_PATH = "src/test/resources"; @@ -86,7 +86,7 @@ class ProfileResolutionTests { @BeforeAll static void setup() throws SaxonApiException { - DynamicContext context = new StaticContext().newDynamicContext(); + DynamicContext context = StaticContext.builder().build().newDynamicContext(); context.setDocumentLoader(new DefaultBoundLoader(OscalBindingContext.instance())); profileResolver = new ProfileResolver(); profileResolver.setDynamicContext(context); @@ -183,7 +183,8 @@ void performTest(String profileName) throws IOException, SaxonApiException { StringWriter writer = new StringWriter(); serializer.serialize(catalog, writer); - // OscalBindingContext.instance().newSerializer(Format.YAML, Catalog.class).serialize(catalog, + // OscalBindingContext.instance().newSerializer(Format.YAML, + // Catalog.class).serialize(catalog, // System.out); // System.out.println("Pre scrub: " + writer.getBuffer().toString()); diff --git a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/TestUtil.java b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/TestUtil.java index 99b7f0ff..47a6214d 100644 --- a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/TestUtil.java +++ b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/TestUtil.java @@ -26,11 +26,11 @@ package gov.nist.secauto.oscal.lib.profile.resolver; -import gov.nist.secauto.metaschema.binding.model.IAssemblyClassBinding; import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemFactory; import gov.nist.secauto.metaschema.core.model.IRootAssemblyDefinition; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.IAssemblyClassBinding; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.lib.model.Catalog; import gov.nist.secauto.oscal.lib.model.control.AbstractParameter; diff --git a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/ReferenceCountingVisitorTest.java b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/ReferenceCountingVisitorTest.java index 16bc7180..823317c0 100644 --- a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/ReferenceCountingVisitorTest.java +++ b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/ReferenceCountingVisitorTest.java @@ -26,9 +26,9 @@ package gov.nist.secauto.oscal.lib.profile.resolver.policy; -import gov.nist.secauto.metaschema.binding.io.Format; import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +import gov.nist.secauto.metaschema.databind.io.Format; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.lib.model.Catalog; import gov.nist.secauto.oscal.lib.profile.resolver.TestUtil; diff --git a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/FilterNonSelectedVisitorTest.java b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/FilterNonSelectedVisitorTest.java index 2db57f7a..8a9f8ef0 100644 --- a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/FilterNonSelectedVisitorTest.java +++ b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/FilterNonSelectedVisitorTest.java @@ -28,9 +28,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import gov.nist.secauto.metaschema.binding.io.Format; import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +import gov.nist.secauto.metaschema.databind.io.Format; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.lib.model.Catalog; import gov.nist.secauto.oscal.lib.model.CatalogGroup; diff --git a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/ImportTest.java b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/ImportTest.java index fa267221..88e2b9ed 100644 --- a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/ImportTest.java +++ b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/ImportTest.java @@ -26,7 +26,6 @@ package gov.nist.secauto.oscal.lib.profile.resolver.selection; -import gov.nist.secauto.metaschema.binding.model.IAssemblyClassBinding; import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemFactory; @@ -34,6 +33,7 @@ import gov.nist.secauto.metaschema.core.model.IRootAssemblyDefinition; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.IAssemblyClassBinding; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.lib.model.Catalog; import gov.nist.secauto.oscal.lib.model.IncludeAll; @@ -82,9 +82,6 @@ void test() throws ProfileResolutionException { // setup the imported catalog IDocumentNodeItem importedCatalogDocumentItem = newImportedCatalog(); - // setup the profile - Profile profile = new Profile(); - ProfileImport profileImport = new ProfileImport(); profileImport.setIncludeAll(new IncludeAll()); profileImport.setExcludeControls(Collections.singletonList( @@ -92,6 +89,10 @@ void test() throws ProfileResolutionException { .withId("control1") .build())); profileImport.setHref(cwd); + + // setup the profile + Profile profile = new Profile(); + profile.addImport(profileImport); IDocumentNodeItem profileDocumentItem = INodeItemFactory.instance().newDocumentNodeItem( diff --git a/src/test/resources/log4j2-test.xml b/src/test/resources/log4j2-test.xml index bc7f9040..e347850b 100644 --- a/src/test/resources/log4j2-test.xml +++ b/src/test/resources/log4j2-test.xml @@ -13,10 +13,10 @@ - + - + diff --git a/src/test/resources/profile-test-helper.xsl b/src/test/resources/profile-test-helper.xsl new file mode 100644 index 00000000..06c5f40b --- /dev/null +++ b/src/test/resources/profile-test-helper.xsl @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ... + + + + ... + + + + ... + + + + ... + + + + + + + + + + \ No newline at end of file