Skip to content

Commit

Permalink
Fixed multiple bugs causing an issue around validating a content inst…
Browse files Browse the repository at this point in the history
…ance. The first was that the module was not being loaded for constraint validation due to the load happening inside the disabled schema validation block. The second was a tricky issue on loading the module, where some definitions were mistaken found to be inline, when they had separate definition classes.
  • Loading branch information
david-waltermire committed Nov 2, 2024
1 parent e17bafc commit 9c7c850
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ public final QName getDefinitionQName() {
return definitionQName.get();
}

@Override
public final boolean isInline() {
// never inline
return false;
}

@Override
public final INSTANCE getInlineInstance() {
// never inline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public Class<? extends IBoundObject> getBoundClassForXmlQName(QName rootQName) {
public Class<? extends IBoundObject> getBoundClassForJsonName(String rootName) {
return getRootJsonName().equals(rootName) ? getClazz() : null;
}

@Override
public String toString() {
return getDefinition().getRootXmlQName().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ public interface IBoundDefinitionModelComplex
@NonNull
Map<String, IBoundProperty<?>> getJsonProperties(@Nullable Predicate<IBoundInstanceFlag> flagFilter);

@Override
default boolean isInline() {
return getBoundClass().getEnclosingClass() != null;
}

@Nullable
Method getBeforeDeserializeMethod();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ public final QName getDefinitionQName() {
return definitionQName.get();
}

@Override
public boolean isInline() {
return getBoundClass().getEnclosingClass() != null;
}

@Override
public Method getBeforeDeserializeMethod() {
return beforeDeserializeMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ public void execute() throws CommandExecutionException {

IValidationResult validationResult = null;
try {
IModule module = bindingContext.registerModule(
getModule(getCommandLine(), bindingContext));

IModule module = bindingContext.registerModule(getModule(getCommandLine(), bindingContext));
if (!cmdLine.hasOption(NO_SCHEMA_VALIDATION_OPTION)) {
// perform schema validation
validationResult = getSchemaValidationProvider(module, getCommandLine(), bindingContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import gov.nist.secauto.metaschema.cli.processor.ExitCode;
import gov.nist.secauto.metaschema.cli.processor.ExitStatus;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -44,7 +45,8 @@ void evaluateResult(@NonNull ExitStatus status, @NonNull ExitCode expectedCode,
}

private static Stream<Arguments> providesValues() {
@SuppressWarnings("serial") List<Arguments> values = new LinkedList<>() {
@SuppressWarnings("serial")
List<Arguments> values = new LinkedList<>() {
{
add(Arguments.of(new String[] {}, ExitCode.INVALID_COMMAND,
NO_EXCEPTION_CLASS));
Expand Down Expand Up @@ -179,6 +181,15 @@ private static Stream<Arguments> providesValues() {
"../core/metaschema/schema/metaschema/metaschema-module-metaschema.xml",
},
ExitCode.OK, NO_EXCEPTION_CLASS));
add(Arguments.of(
new String[] { "validate-content",
"-m",
"src/test/resources/content/215-module.xml",
"src/test/resources/content/215.xml",
"--disable-schema-validation",
"--show-stack-trace"
},
ExitCode.FAIL, NO_EXCEPTION_CLASS));
}
};

Expand All @@ -198,4 +209,16 @@ void testAllCommands(@NonNull String[] args, @NonNull ExitCode expectedExitCode,
evaluateResult(CLI.runCli(fullArgs), expectedExitCode, expectedThrownClass);
}
}

@Test
void test() {
String[] cliArgs = { "validate-content",
"-m",
"src/test/resources/content/215-module.xml",
"src/test/resources/content/215.xml",
"--disable-schema-validation",
"--show-stack-trace"
};
CLI.runCli(cliArgs);
}
}

0 comments on commit 9c7c850

Please sign in to comment.