diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemDocumentExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemDocumentExpr.java index 3ecbca5cd..f61b8a8c4 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemDocumentExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemDocumentExpr.java @@ -96,12 +96,12 @@ public class WbItemDocumentExpr implements WbExpression { @JsonProperty("nameDescs") public List getNameDescs() { - return nameDescs; + return Collections.unmodifiableList(nameDescs); } @JsonProperty("statementGroups") public List getStatementGroups() { - return statementGroups; + return Collections.unmodifiableList(statementGroups); } @Override diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbReferenceExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbReferenceExpr.java index 7310b0d60..6f1383229 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbReferenceExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbReferenceExpr.java @@ -24,6 +24,7 @@ package org.openrefine.wikidata.schema; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.apache.commons.lang.Validate; @@ -77,7 +78,7 @@ public class WbReferenceExpr implements WbExpression { @JsonProperty("snaks") public List getSnaks() { - return snakExprs; + return Collections.unmodifiableList(snakExprs); } @Override diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementExpr.java index 69e27b326..e57eace9a 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementExpr.java @@ -134,12 +134,12 @@ public class WbStatementExpr { @JsonProperty("qualifiers") public List getQualifiers() { - return qualifierExprs; + return Collections.unmodifiableList(qualifierExprs); } @JsonProperty("references") public List getReferences() { - return referenceExprs; + return Collections.unmodifiableList(referenceExprs); } @Override diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementGroupExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementGroupExpr.java index 724c8656d..6949439a1 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementGroupExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementGroupExpr.java @@ -24,6 +24,7 @@ package org.openrefine.wikidata.schema; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.jsoup.helper.Validate; @@ -79,7 +80,7 @@ public class WbStatementGroupExpr { @JsonProperty("statements") public List getStatements() { - return statementExprs; + return Collections.unmodifiableList(statementExprs); } @Override diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WikibaseSchema.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WikibaseSchema.java index 413a7dc6b..7230cbef9 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WikibaseSchema.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WikibaseSchema.java @@ -25,6 +25,7 @@ package org.openrefine.wikidata.schema; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.openrefine.wikidata.qa.QAWarningStore; @@ -90,7 +91,7 @@ public class WikibaseSchema implements OverlayModel { */ @JsonIgnore public List getItemDocumentExpressions() { - return itemDocumentExprs; + return Collections.unmodifiableList(itemDocumentExprs); } public void setItemDocumentExpressions(List exprs) { diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbItemDocumentExprTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbItemDocumentExprTest.java index dc8187f13..2b5293a24 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbItemDocumentExprTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbItemDocumentExprTest.java @@ -24,10 +24,12 @@ package org.openrefine.wikidata.schema; import java.util.Collections; +import java.util.List; import org.openrefine.wikidata.testing.JacksonSerializationTest; import org.openrefine.wikidata.updates.ItemUpdate; import org.openrefine.wikidata.updates.ItemUpdateBuilder; +import org.testng.Assert; import org.testng.annotations.Test; import org.wikidata.wdtk.datamodel.helpers.Datamodel; import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; @@ -89,4 +91,14 @@ public class WbItemDocumentExprTest extends WbExpressionTest { public void testSerialize() { JacksonSerializationTest.canonicalSerialization(WbItemDocumentExpr.class, expr, jsonRepresentation); } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testUnmodifiableNameDescsList() { + expr.getNameDescs().clear(); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testUnmodifiableStatementGroupsList() { + expr.getStatementGroups().clear(); + } } diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbReferenceExprTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbReferenceExprTest.java index 58cabd3f4..d04e3ae5a 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbReferenceExprTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbReferenceExprTest.java @@ -25,8 +25,10 @@ package org.openrefine.wikidata.schema; import java.util.Arrays; import java.util.Collections; +import java.util.List; import org.openrefine.wikidata.testing.JacksonSerializationTest; +import org.testng.Assert; import org.testng.annotations.Test; import org.wikidata.wdtk.datamodel.helpers.Datamodel; import org.wikidata.wdtk.datamodel.interfaces.Reference; @@ -77,4 +79,9 @@ public class WbReferenceExprTest extends WbExpressionTest { throws JsonProcessingException { JacksonSerializationTest.canonicalSerialization(WbReferenceExpr.class, expr, jsonRepresentation); } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testUnmodifiableList() { + expr.getSnaks().clear(); + } } diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbStatementExprTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbStatementExprTest.java index 17ee758b5..51b23b0d6 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbStatementExprTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbStatementExprTest.java @@ -23,11 +23,13 @@ ******************************************************************************/ package org.openrefine.wikidata.schema; +import org.testng.Assert; import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Arrays; import java.util.Collections; +import java.util.List; import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException; import org.openrefine.wikidata.testing.JacksonSerializationTest; @@ -155,4 +157,14 @@ public class WbStatementExprTest extends WbExpressionTest { public void testSerialize() { JacksonSerializationTest.canonicalSerialization(WbStatementExpr.class, statementExpr, jsonRepresentation); } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testUnmodifiableQualifiersList() { + statementExpr.getQualifiers().clear(); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testUnmodifiableReferencesList() { + statementExpr.getReferences().clear(); + } } diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbStatementGroupExprTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbStatementGroupExprTest.java index 2c568d7f5..e9ad42d1f 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbStatementGroupExprTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbStatementGroupExprTest.java @@ -24,9 +24,11 @@ package org.openrefine.wikidata.schema; import java.util.Collections; +import java.util.List; import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException; import org.openrefine.wikidata.testing.JacksonSerializationTest; +import org.testng.Assert; import org.testng.annotations.Test; import org.wikidata.wdtk.datamodel.helpers.Datamodel; import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; @@ -90,4 +92,9 @@ public class WbStatementGroupExprTest extends WbExpressionTest { throws JsonProcessingException { JacksonSerializationTest.canonicalSerialization(WbStatementGroupExpr.class, expr, jsonRepresentation); } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testUnmodifiableList() { + expr.getStatements().clear(); + } } diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java index 3bae4d83c..ce49c8fd4 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java @@ -23,6 +23,7 @@ ******************************************************************************/ package org.openrefine.wikidata.schema; +import org.testng.Assert; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -157,4 +158,11 @@ public class WikibaseSchemaTest extends WikidataRefineTest { expected.add(update1); assertEquals(expected, updates); } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testUnmodifiableList() throws IOException { + String serialized = TestingData.jsonFromFile("schema/inception.json"); + WikibaseSchema schema = WikibaseSchema.reconstruct(serialized); + schema.getItemDocumentExpressions().clear(); + } }