From 22dd02c6a87470bce651b59a377a6a22ffffcc7a Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Mon, 2 Feb 2026 13:59:16 +0530 Subject: [PATCH] Make offline validation the documented default and add test (#246) --- core/src/org/sbml/jsbml/SBMLDocument.java | 14 ++-- .../test/SBMLDocumentValidationModeTest.java | 69 +++++++++++++++++++ 2 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 core/test/org/sbml/jsbml/test/SBMLDocumentValidationModeTest.java diff --git a/core/src/org/sbml/jsbml/SBMLDocument.java b/core/src/org/sbml/jsbml/SBMLDocument.java index e06c33ba4..ba999db87 100644 --- a/core/src/org/sbml/jsbml/SBMLDocument.java +++ b/core/src/org/sbml/jsbml/SBMLDocument.java @@ -336,9 +336,9 @@ private void removePackageDeclaration(String packageName) { * flag in the individual SBMLError objects returned by * {@link SBMLDocument#getError(int)} to determine the nature of the failures. * - *

The offline validator is not yet as complete as the online one so it is not - * currently used by default when calling {@link #checkConsistency()} but it might be - * in future versions. To get an up to date status, please check the page + *

The offline validator was initially less complete than the online one but + * has evolved and is now used by default when calling {@link #checkConsistency()}. + * The online validator remains available via {@link #checkConsistencyOnline()}. * Offline-validator-status.

* * @return the number of errors found @@ -580,9 +580,11 @@ public int checkConsistencyOnline() { /** * Validates the {@link SBMLDocument}. - * - *

The validation is currently performed using the - * SBML.org online validator (http://sbml.org/validator/).

+ * + *

The validation is currently performed using the JSBML internal + * offline validator, see {@link #checkConsistencyOffline()}. The SBML.org + * online validator (http://sbml.org/validator/) is still available via + * {@link #checkConsistencyOnline()}.

* *

* You can control the consistency checks that are performed when diff --git a/core/test/org/sbml/jsbml/test/SBMLDocumentValidationModeTest.java b/core/test/org/sbml/jsbml/test/SBMLDocumentValidationModeTest.java new file mode 100644 index 000000000..16fc9fcd8 --- /dev/null +++ b/core/test/org/sbml/jsbml/test/SBMLDocumentValidationModeTest.java @@ -0,0 +1,69 @@ +/* + * ---------------------------------------------------------------------------- + * This file is part of JSBML. Please visit + * for the latest version of JSBML and more information about SBML. + * + * Copyright (C) 2009-2022 jointly by the following organizations: + * 1. The University of Tuebingen, Germany + * 2. EMBL European Bioinformatics Institute (EBML-EBI), Hinxton, UK + * 3. The California Institute of Technology, Pasadena, CA, USA + * 4. The University of California, San Diego, La Jolla, CA, USA + * 5. The Babraham Institute, Cambridge, UK + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation. A copy of the license agreement is provided + * in the file named "LICENSE.txt" included with this software distribution + * and also available online as . + * ---------------------------------------------------------------------------- + */ + +package org.sbml.jsbml.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.sbml.jsbml.SBMLDocument; + +/** + * Tests that {@link SBMLDocument#checkConsistency()} uses the offline + * validator by default. + */ +public class SBMLDocumentValidationModeTest { + + /** + * Small test subclass of {@link SBMLDocument} that records whether the + * offline or online validation methods are called. + */ + private static class TestDocument extends SBMLDocument { + + boolean offlineCalled = false; + boolean onlineCalled = false; + + @Override + public int checkConsistencyOffline() { + offlineCalled = true; + // return a distinctive value so we can verify it is propagated + return 7; + } + + @Override + public int checkConsistencyOnline() { + onlineCalled = true; + return 13; + } + } + + @Test + public void checkConsistencyUsesOfflineValidatorByDefault() { + TestDocument doc = new TestDocument(); + + int result = doc.checkConsistency(); + + assertTrue("Offline validator should be used by default.", doc.offlineCalled); + assertFalse("Online validator should not be used when calling checkConsistency().", doc.onlineCalled); + assertEquals("checkConsistency() should return the offline validator result.", 7, result); + } +} \ No newline at end of file