diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-04-25 15:26:32 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-04-25 15:26:32 +0200 |
commit | 695bfc1807271a7a1ad1057202d2401e94edace5 (patch) | |
tree | ca26395e98ee29dd8c07fbb8a1b45ffcc36af5b9 /document/src/test | |
parent | e2d4b112ef1308ea1e03c22e91e8dae561071f81 (diff) |
Remove usage of junit.framework
Diffstat (limited to 'document/src/test')
26 files changed, 396 insertions, 192 deletions
diff --git a/document/src/test/java/com/yahoo/document/DocumentPathUpdateTestCase.java b/document/src/test/java/com/yahoo/document/DocumentPathUpdateTestCase.java index 40cfe762289..a14640a2f86 100755 --- a/document/src/test/java/com/yahoo/document/DocumentPathUpdateTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentPathUpdateTestCase.java @@ -7,23 +7,34 @@ import com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate; import com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate; import com.yahoo.document.serialization.*; import com.yahoo.io.GrowableByteBuffer; +import org.junit.Before; +import org.junit.Test; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * Tests applying and serializing document updates. * - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ -public class DocumentPathUpdateTestCase extends junit.framework.TestCase { +public class DocumentPathUpdateTestCase { + DocumentTypeManager docMan; DocumentType docType = null; DocumentType docType2 = null; + @Before public void setUp() { docMan = new DocumentTypeManager(); @@ -60,7 +71,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { docMan.register(docType2); } - public void testRemoveField() throws Exception { + @Test + public void testRemoveField() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); assertNull(doc.getFieldValue("strfoo")); doc.setFieldValue("strfoo", "cocacola"); @@ -69,9 +81,10 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { docUp.addFieldPathUpdate(new RemoveFieldPathUpdate(doc.getDataType(), "strfoo", null)); docUp.applyTo(doc); assertNull(doc.getFieldValue("strfoo")); - } + } - public void testApplyRemoveMultiList() throws Exception { + @Test + public void testApplyRemoveMultiList() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); assertNull(doc.getFieldValue("strarray")); Array<StringFieldValue> strArray = new Array<>(doc.getField("strarray").getDataType()); @@ -89,7 +102,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new StringFieldValue("hello hello"), docList.get(1)); } - public void testApplyRemoveEntireListField() throws Exception { + @Test + public void testApplyRemoveEntireListField() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); assertNull(doc.getFieldValue("strarray")); Array<StringFieldValue> strArray = new Array<>(doc.getField("strarray").getDataType()); @@ -103,7 +117,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertNull(doc.getFieldValue("strarray")); } - public void testApplyRemoveMultiWset() throws Exception { + @Test + public void testApplyRemoveMultiWset() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); assertNull(doc.getFieldValue("strwset")); WeightedSet<StringFieldValue> strwset = new WeightedSet<>(doc.getDataType().getField("strwset").getDataType()); @@ -119,7 +134,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new Integer(10), docWset.get(new StringFieldValue("hello hello"))); } - public void testApplyAssignSingle() throws Exception { + @Test + public void testApplyAssignSingle() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); assertNull(doc.getFieldValue("strfoo")); DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar")); @@ -128,7 +144,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new StringFieldValue("something"), doc.getFieldValue("strfoo")); } - public void testApplyAssignMath() throws Exception { + @Test + public void testApplyAssignMath() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); doc.setFieldValue(doc.getField("num"), new IntegerFieldValue(34)); DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar")); @@ -137,7 +154,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new IntegerFieldValue(2), doc.getFieldValue(doc.getField("num"))); } - public void testDivideByZero() throws Exception { + @Test + public void testDivideByZero() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); doc.setFieldValue(doc.getField("num"), new IntegerFieldValue(10)); DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar")); @@ -146,7 +164,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new IntegerFieldValue(10), doc.getFieldValue(doc.getField("num"))); } - public void testAssignMathFieldNotSet() throws Exception { + @Test + public void testAssignMathFieldNotSet() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); doc.setFieldValue(doc.getField("num"), new IntegerFieldValue(10)); DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar")); @@ -155,7 +174,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new IntegerFieldValue(10), doc.getFieldValue(doc.getField("num"))); } - public void testAssignMathMissingField() throws Exception { + @Test + public void testAssignMathMissingField() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); doc.setFieldValue(doc.getField("num"), new IntegerFieldValue(10)); DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar")); @@ -164,7 +184,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new IntegerFieldValue(10), doc.getFieldValue(doc.getField("num"))); } - public void testAssignMathTargetFieldNotSet() throws Exception { + @Test + public void testAssignMathTargetFieldNotSet() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar")); docUp.addFieldPathUpdate(new AssignFieldPathUpdate(doc.getDataType(), "num", "", "100")); @@ -172,7 +193,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new IntegerFieldValue(100), doc.getFieldValue(doc.getField("num"))); } - public void testAssignMathTargetFieldNotSetWithValue() throws Exception { + @Test + public void testAssignMathTargetFieldNotSetWithValue() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar")); docUp.addFieldPathUpdate(new AssignFieldPathUpdate(doc.getDataType(), "num", "", "$value + 5")); @@ -180,7 +202,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new IntegerFieldValue(5), doc.getFieldValue(doc.getField("num"))); } - public void testApplyAssignMultiList() throws Exception { + @Test + public void testApplyAssignMultiList() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); assertNull(doc.getFieldValue("strarray")); Array<StringFieldValue> strArray = new Array<StringFieldValue>(doc.getField("strarray").getDataType()); @@ -200,7 +223,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new StringFieldValue("assigned val 1"), docList.get(1)); } - public void testApplyAssignMultiWlist() throws Exception { + @Test + public void testApplyAssignMultiWlist() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); assertNull(doc.getFieldValue("strwset")); WeightedSet<StringFieldValue> strwset = new WeightedSet<>(doc.getDataType().getField("strwset").getDataType()); @@ -220,7 +244,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new Integer(10), docWset.get(new StringFieldValue("assigned val 1"))); } - public void testAssignWsetRemoveIfZero() throws Exception { + @Test + public void testAssignWsetRemoveIfZero() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); assertNull(doc.getFieldValue(doc.getField("strwset"))); WeightedSet<StringFieldValue> strwset = new WeightedSet<>(doc.getDataType().getField("strwset").getDataType()); @@ -238,7 +263,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new Integer(243), docWset.get(new StringFieldValue("blahdi blahdi"))); } - public void testApplyAddMultiList() throws Exception { + @Test + public void testApplyAddMultiList() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); assertNull(doc.getFieldValue("strarray")); @@ -256,7 +282,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(values, doc.getFieldValue("strarray")); } - public void testAddAndAssignList() throws Exception { + @Test + public void testAddAndAssignList() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); assertNull(doc.getFieldValue("strarray")); @@ -282,8 +309,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new StringFieldValue("new value"), docList.get(2)); } - public void testAssignSimpleMapValueWithVariable() - { + @Test + public void testAssignSimpleMapValueWithVariable() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); MapFieldValue mfv = new MapFieldValue((MapDataType)doc.getField("strmap").getDataType()); @@ -303,6 +330,7 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new StringFieldValue("bananas"), valueNow.get(new StringFieldValue("baz"))); } + @Test public void testKeyParsing() { assertEquals(new FieldPathEntry.KeyParseResult("", 2), FieldPathEntry.parseKey("{}")); assertEquals(new FieldPathEntry.KeyParseResult("abc", 5), FieldPathEntry.parseKey("{abc}")); @@ -356,8 +384,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { } } - public void testKeyWithEscapedChars() - { + @Test + public void testKeyWithEscapedChars() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); MapFieldValue mfv = new MapFieldValue((MapDataType)doc.getField("strmap").getDataType()); @@ -377,7 +405,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(new StringFieldValue("bananas"), valueNow.get(new StringFieldValue("baz"))); } - public void testAssignMap() throws Exception { + @Test + public void testAssignMap() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); MapFieldValue mfv = new MapFieldValue((MapDataType)doc.getField("structmap").getDataType()); Struct fv1 = new Struct(mfv.getDataType().getValueType()); @@ -414,7 +443,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(fv3, valueNow.get(new StringFieldValue("zoo"))); } - public void testAssignMapStruct() throws Exception { + @Test + public void testAssignMapStruct() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); MapFieldValue mfv = new MapFieldValue((MapDataType)doc.getField("structmap").getDataType()); Struct fv1 = new Struct(mfv.getDataType().getValueType()); @@ -451,7 +481,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(fv3, valueNow.get(new StringFieldValue("zoo"))); } - public void testAssignMapStructVariable() throws Exception { + @Test + public void testAssignMapStructVariable() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); MapFieldValue mfv = new MapFieldValue((MapDataType)doc.getField("structmap").getDataType()); Struct fv1 = new Struct(mfv.getDataType().getValueType()); @@ -488,7 +519,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(fv3, valueNow.get(new StringFieldValue("zoo"))); } - public void testAssignMapNoexist() throws Exception { + @Test + public void testAssignMapNoexist() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); MapFieldValue mfv = new MapFieldValue((MapDataType)doc.getField("structmap").getDataType()); @@ -504,7 +536,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(fv1, valueNow.get(new StringFieldValue("foo"))); } - public void testAssignMapNoexistNocreate() throws Exception { + @Test + public void testAssignMapNoexistNocreate() { Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo")); MapFieldValue mfv = new MapFieldValue((MapDataType)doc.getField("structmap").getDataType()); @@ -522,7 +555,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertNull(valueNow); } - public void testAssignSerialization() throws Exception { + @Test + public void testAssignSerialization() { DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar")); AssignFieldPathUpdate ass = new AssignFieldPathUpdate(docType, "num", "", "3"); ass.setCreateMissingPath(false); @@ -536,7 +570,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(docUp, docUp2); } - public void testAddSerialization() throws Exception { + @Test + public void testAddSerialization() { DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar")); Array strArray = new Array(docType.getField("strarray").getDataType()); strArray.add(new StringFieldValue("hello hello")); @@ -553,7 +588,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(docUp, docUp2); } - public void testRemoveSerialization() throws Exception { + @Test + public void testRemoveSerialization() { DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar")); RemoveFieldPathUpdate remove = new RemoveFieldPathUpdate(docType, "num", "foobar.num > 0"); docUp.addFieldPathUpdate(remove); @@ -566,7 +602,8 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(docUp, docUp2); } - public void testStartsWith() throws Exception { + @Test + public void testStartsWith() { FieldPath fp1 = docType.buildFieldPath("struct"); FieldPath fp2 = docType.buildFieldPath("struct.title"); assertTrue(fp2.startsWith(fp1)); @@ -598,6 +635,7 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { return docUp; } + @Test public void testGenerateSerializedFile() throws IOException { DocumentUpdate docUp = createDocumentUpdateForSerialization(); @@ -612,6 +650,7 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { fos.close(); } + @Test public void testReadSerializedFile() throws IOException { docMan = DocumentTestCase.setUpCppDocType(); byte[] data = DocumentTestCase.readFile("src/tests/data/serialize-fieldpathupdate-cpp.dat"); @@ -623,4 +662,5 @@ public class DocumentPathUpdateTestCase extends junit.framework.TestCase { assertEquals(compare, upd); } + } diff --git a/document/src/test/java/com/yahoo/document/DocumentTypeTestCase.java b/document/src/test/java/com/yahoo/document/DocumentTypeTestCase.java index 5416a5cc7f4..abbfd31b778 100644 --- a/document/src/test/java/com/yahoo/document/DocumentTypeTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentTypeTestCase.java @@ -1,19 +1,23 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document; +import org.junit.Test; + import java.util.Iterator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + /** * @author Thomas Gundersen * @author bratseth */ -public class DocumentTypeTestCase extends junit.framework.TestCase { - - public DocumentTypeTestCase(String name) { - super(name); - } +public class DocumentTypeTestCase { // Verify that we can register and retrieve fields. + @Test public void testSetGet() { DocumentType docType = new DocumentType("testdoc"); docType.addField("Bongle", DataType.STRING); @@ -24,6 +28,7 @@ public class DocumentTypeTestCase extends junit.framework.TestCase { } + @Test public void testInheritance() { DocumentTypeManager typeManager = new DocumentTypeManager(); diff --git a/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java b/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java index 2976aebf802..13474efc282 100644 --- a/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java @@ -11,6 +11,8 @@ import com.yahoo.document.update.ValueUpdate; import com.yahoo.io.GrowableByteBuffer; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; +import org.junit.Before; +import org.junit.Test; import java.io.FileOutputStream; import java.io.IOException; @@ -18,29 +20,38 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * Tests applying and serializing document updates. * * @author Einar M R Rosenvinge */ -public class DocumentUpdateTestCase extends junit.framework.TestCase { - DocumentTypeManager docMan; +public class DocumentUpdateTestCase { + + private DocumentTypeManager docMan; - DocumentType docType = null; - DocumentType docType2 = null; - DocumentUpdate docUp = null; + private DocumentType docType = null; + private DocumentType docType2 = null; + private DocumentUpdate docUp = null; - FieldUpdate assignSingle = null; - FieldUpdate assignMultiList = null; - FieldUpdate assignMultiWset = null; + private FieldUpdate assignSingle = null; + private FieldUpdate assignMultiList = null; + private FieldUpdate assignMultiWset = null; - FieldUpdate clearSingleField = null; - FieldUpdate removeMultiList = null; - FieldUpdate removeMultiWset = null; + private FieldUpdate clearSingleField = null; + private FieldUpdate removeMultiList = null; + private FieldUpdate removeMultiWset = null; - FieldUpdate addSingle = null; - FieldUpdate addMultiList = null; - FieldUpdate addMultiWset = null; + private FieldUpdate addSingle = null; + private FieldUpdate addMultiList = null; + private FieldUpdate addMultiWset = null; private final String documentId = "doc:something:foooo"; private final String tensorField = "tensorfield"; @@ -50,6 +61,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { return new Document(docMan.getDocumentType("foobar"), new DocumentId(documentId)); } + @Before public void setUp() { docMan = new DocumentTypeManager(); @@ -111,6 +123,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { addMultiWset = FieldUpdate.createAddAll(docType.getField("strwset"), addSet); } + @Test public void testApplyRemoveSingle() { Document doc = createDocument(); assertNull(doc.getFieldValue("strfoo")); @@ -121,6 +134,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertNull(doc.getFieldValue("strfoo")); } + @Test public void testApplyRemoveMultiList() { Document doc = createDocument(); assertNull(doc.getFieldValue("strarray")); @@ -136,6 +150,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(new StringFieldValue("hello hello"), docList.get(0)); } + @Test public void testApplyRemoveMultiWset() { Document doc = createDocument(); assertNull(doc.getFieldValue("strwset")); @@ -151,6 +166,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(new Integer(10), docWset.get(new StringFieldValue("hello hello"))); } + @Test public void testApplyAssignSingle() { Document doc = createDocument(); assertNull(doc.getFieldValue("strfoo")); @@ -159,6 +175,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(new StringFieldValue("something"), doc.getFieldValue("strfoo")); } + @Test public void testApplyAssignMultiList() { Document doc = createDocument(); assertNull(doc.getFieldValue("strarray")); @@ -175,6 +192,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(new StringFieldValue("assigned val 1"), docList.get(1)); } + @Test public void testApplyAssignMultiWlist() { Document doc = createDocument(); assertNull(doc.getFieldValue("strwset")); @@ -191,10 +209,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(new Integer(10), docWset.get(new StringFieldValue("assigned val 1"))); } - public void testApplyAddSingle() { - //Unneeded, we can't construct an add for single-value - } - + @Test public void testApplyAddMultiList() { Document doc = createDocument(); assertNull(doc.getFieldValue("strarray")); @@ -208,6 +223,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(values, doc.getFieldValue("strarray")); } + @Test public void testApplyAddMultiWset() { Document doc = createDocument(); assertNull(doc.getFieldValue("strwset")); @@ -233,6 +249,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(values, doc.getFieldValue("strwset")); } + @Test public void testUpdatesToTheSameFieldAreCombining() { DocumentType docType = new DocumentType("my_type"); Field field = new Field("my_int", DataType.INT); @@ -256,6 +273,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(new IntegerFieldValue(2), valueUpdate.getValue()); } + @Test public void testUpdateToWrongField() { DocumentType docType = new DocumentType("my_type"); DocumentUpdate update = new DocumentUpdate(docType, new DocumentId("doc:foo:")); @@ -267,6 +285,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { } } + @Test public void testSerialize() { docUp.addFieldUpdate(assignSingle); docUp.addFieldUpdate(addMultiList); @@ -310,6 +329,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(docUp, docUpDeser); } + @Test public void testCppDocUpd() throws IOException { docMan = DocumentTestCase.setUpCppDocType(); byte[] data = DocumentTestCase.readFile("src/tests/data/serializeupdatecpp.dat"); @@ -357,6 +377,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(ValueUpdate.ValueUpdateClassID.MAP, mapUpd.getValueUpdateClassID()); } + @Test public void testGenerateSerializedFile() throws IOException { docMan = DocumentTestCase.setUpCppDocType(); @@ -384,6 +405,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { fos.close(); } + @Test public void testRequireThatAddAllCombinesFieldUpdates() { DocumentType docType = new DocumentType("my_type"); Field field = new Field("my_int", DataType.INT); @@ -412,6 +434,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(new IntegerFieldValue(2), valueUpdate.getValue()); } + @Test public void testInstantiationAndEqualsHashCode() { DocumentType type = new DocumentType("doo"); DocumentUpdate d1 = new DocumentUpdate(type, new DocumentId("doc:this:is:a:test")); @@ -425,6 +448,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(d1.hashCode(), d2.hashCode()); } + @Test public void testThatApplyingToWrongTypeFails() { DocumentType t1 = new DocumentType("doo"); DocumentUpdate documentUpdate = new DocumentUpdate(t1, new DocumentId("doc:this:is:a:test")); @@ -440,7 +464,8 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { } } - public void testFieldUpdatesInDocUp() throws ParseException { + @Test + public void testFieldUpdatesInDocUp() { DocumentType t1 = new DocumentType("doo"); Field f1 = new Field("field1", DataType.STRING); Field f2 = new Field("field2", DataType.STRING); @@ -506,6 +531,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertFalse(fpUpdates.hasNext()); } + @Test public void testAddAll() { DocumentType t1 = new DocumentType("doo"); DocumentType t2 = new DocumentType("foo"); @@ -554,6 +580,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(value, extractedValue); } + @Test public void testRequireThatDocumentUpdateFlagsIsWorking() { { // create-if-non-existent = true assertDocumentUpdateFlag(true, 0); @@ -573,6 +600,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { } } + @Test public void testRequireThatCreateIfNonExistentFlagIsSerializedAndDeserialized() { docUp.setCreateIfNonExistent(true); @@ -586,6 +614,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertTrue(deserialized.getCreateIfNonExistent()); } + @Test public void testThatAssignValueUpdateForTensorFieldCanBeApplied() { Document doc = createDocument(); assertNull(doc.getFieldValue(tensorField)); @@ -597,6 +626,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(createTensorFieldValue("{{x:0}:2.0}"), tensor); } + @Test public void testThatAssignValueUpdateForTensorFieldCanBeSerializedAndDeserialized() { DocumentUpdate serializedUpdate = createTensorAssignUpdate(); DocumentSerializer serializer = DocumentSerializerFactory.createHead(new GrowableByteBuffer()); @@ -608,6 +638,7 @@ public class DocumentUpdateTestCase extends junit.framework.TestCase { assertEquals(serializedUpdate, deserializedUpdate); } + @Test public void testThatClearValueUpdateForTensorFieldCanBeApplied() { Document doc = createDocument(); doc.setFieldValue(docType.getField(tensorField), createTensorFieldValue("{{x:0}:2.0}")); diff --git a/document/src/test/java/com/yahoo/document/DocumentUtilTestCase.java b/document/src/test/java/com/yahoo/document/DocumentUtilTestCase.java deleted file mode 100644 index 2cf9123b987..00000000000 --- a/document/src/test/java/com/yahoo/document/DocumentUtilTestCase.java +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.document; - -/** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> - * @since 5.1.10 - */ -public class DocumentUtilTestCase extends junit.framework.TestCase { - - public void testBasic() { -/*** - final long heapBytes = Runtime.getRuntime().maxMemory(); - long maxPendingBytes = DocumentUtil.calculateMaxPendingSize(1.0, 1.0, 0); - almostEquals(heapBytes / 5, maxPendingBytes, 512*1024); - } - - public void test2_2() { - final long heapBytes = Runtime.getRuntime().maxMemory(); - long maxPendingBytes = DocumentUtil.calculateMaxPendingSize(2.0, 2.0, 0); - almostEquals(heapBytes / 5, maxPendingBytes, 512*1024); - } - - public void test4_4() { - final long heapBytes = Runtime.getRuntime().maxMemory(); - long maxPendingBytes = DocumentUtil.calculateMaxPendingSize(4.0, 4.0, 0); - almostEquals(heapBytes / 17, maxPendingBytes, 512*1024); - } - - public void test8_8() { - final long heapBytes = Runtime.getRuntime().maxMemory(); - long maxPendingBytes = DocumentUtil.calculateMaxPendingSize(8.0, 8.0, 0); - almostEquals(heapBytes / 65, maxPendingBytes, 512*1024); - } - - public void test10000_10000() { - long maxPendingBytes = DocumentUtil.calculateMaxPendingSize(10000.0, 10000.0, 0); - almostEquals(1*1024*1024, maxPendingBytes, 512*1024); -***/ - } - - private static void almostEquals(long expected, long actual, long off) { - System.err.println("Got actual " + (((double) actual) / 1024d / 1024d) + " MB, expected " - + (((double) expected) / 1024d / 1024d) + " MB, within +/- " + (((double) off) / 1024d / 1024d) + " MB"); - - assertTrue(actual > (expected - off) && actual < (expected + off)); - } -} diff --git a/document/src/test/java/com/yahoo/document/FieldTestCase.java b/document/src/test/java/com/yahoo/document/FieldTestCase.java index 86ae686ba3e..036de39b7fd 100644 --- a/document/src/test/java/com/yahoo/document/FieldTestCase.java +++ b/document/src/test/java/com/yahoo/document/FieldTestCase.java @@ -1,14 +1,16 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document; +import org.junit.Test; + +import static org.junit.Assert.fail; + /** - * @author <a href="thomasg@yahoo-inc.com>Thomas Gundersen</a> + * @author Thomas Gundersen */ -public class FieldTestCase extends junit.framework.TestCase { - public FieldTestCase(String name) { - super(name); - } +public class FieldTestCase { + @Test public void testIdSettingConflict() { DocumentType doc = new DocumentType("testdoc"); Field one = doc.addField("one", DataType.STRING); @@ -26,6 +28,7 @@ public class FieldTestCase extends junit.framework.TestCase { } } + @Test public void testSettingReservedId() { DocumentType doc = new DocumentType("testdoc"); try { diff --git a/document/src/test/java/com/yahoo/document/GlobalIdTestCase.java b/document/src/test/java/com/yahoo/document/GlobalIdTestCase.java index 654536e7dff..c134f8e7770 100644 --- a/document/src/test/java/com/yahoo/document/GlobalIdTestCase.java +++ b/document/src/test/java/com/yahoo/document/GlobalIdTestCase.java @@ -1,13 +1,19 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document; +import org.junit.Test; + import java.util.Arrays; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> - * @since 5.1.10 + * @author Einar M R Rosenvinge */ -public class GlobalIdTestCase extends junit.framework.TestCase { +public class GlobalIdTestCase { + private final byte[] raw0 = new byte[0]; private final byte[] raw1_0 = new byte[]{(byte) 0}; private final byte[] raw2_11 = new byte[]{(byte) 1, (byte) 1}; @@ -19,6 +25,7 @@ public class GlobalIdTestCase extends junit.framework.TestCase { private final BucketIdFactory bucketIdFactory = new BucketIdFactory(); + @Test public void testRaw0() { GlobalId gid = new GlobalId(raw0); assertEquals(12, gid.getRawId().length); @@ -39,6 +46,7 @@ public class GlobalIdTestCase extends junit.framework.TestCase { assertEquals(gid.hashCode(), gid2.hashCode()); } + @Test public void testLonger() { GlobalId gid1 = new GlobalId(raw2_11); GlobalId gid2 = new GlobalId(raw2_minus1_1); @@ -52,6 +60,7 @@ public class GlobalIdTestCase extends junit.framework.TestCase { assertEquals(gid3.hashCode(), gid4.hashCode()); } + @Test public void testCompareTo() { GlobalId gid0 = new GlobalId(raw1_0); GlobalId gid11 = new GlobalId(raw2_11); @@ -75,6 +84,7 @@ public class GlobalIdTestCase extends junit.framework.TestCase { assertEquals(bucketIdThroughFactory, bucketIdThroughGlobalId); } + @Test public void testToBucketId() { verifyGidToBucketIdMapping("userdoc:ns:1:abc"); verifyGidToBucketIdMapping("userdoc:ns:1000:abc"); @@ -84,4 +94,5 @@ public class GlobalIdTestCase extends junit.framework.TestCase { verifyGidToBucketIdMapping("doc:myns:http://foo.bar"); verifyGidToBucketIdMapping("doc:jsrthsdf:a234aleingzldkifvasdfgadf"); } + } diff --git a/document/src/test/java/com/yahoo/document/ReferenceDataTypeTestCase.java b/document/src/test/java/com/yahoo/document/ReferenceDataTypeTestCase.java index 2b5256843b7..3b9392d4d2f 100644 --- a/document/src/test/java/com/yahoo/document/ReferenceDataTypeTestCase.java +++ b/document/src/test/java/com/yahoo/document/ReferenceDataTypeTestCase.java @@ -5,14 +5,13 @@ import com.yahoo.document.datatypes.ReferenceFieldValue; import com.yahoo.document.datatypes.StringFieldValue; import org.junit.Test; -import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; /** * @author vekterli - * @since 6.65 */ public class ReferenceDataTypeTestCase { diff --git a/document/src/test/java/com/yahoo/document/StructDataTypeTestCase.java b/document/src/test/java/com/yahoo/document/StructDataTypeTestCase.java index 07b9512ee32..225aa4afc21 100755 --- a/document/src/test/java/com/yahoo/document/StructDataTypeTestCase.java +++ b/document/src/test/java/com/yahoo/document/StructDataTypeTestCase.java @@ -2,11 +2,18 @@ package com.yahoo.document; import com.yahoo.document.datatypes.Struct; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ -public class StructDataTypeTestCase extends junit.framework.TestCase { +public class StructDataTypeTestCase { + + @Test public void testSimpleInheritance() { StructDataType personType = new StructDataType("person"); Field firstName = new Field("firstname", DataType.STRING); @@ -35,6 +42,7 @@ public class StructDataTypeTestCase extends junit.framework.TestCase { assertEquals("lastname", employeeType.getFields().toArray(new Field[0])[2].getName()); } + @Test public void testCompatibleWith() { StructDataType personType = new StructDataType("person"); Field firstName = new Field("firstname", DataType.STRING); diff --git a/document/src/test/java/com/yahoo/document/annotation/AnnotationTypeRegistryTestCase.java b/document/src/test/java/com/yahoo/document/annotation/AnnotationTypeRegistryTestCase.java index cd68f0a0a7a..b4c1bc8d004 100644 --- a/document/src/test/java/com/yahoo/document/annotation/AnnotationTypeRegistryTestCase.java +++ b/document/src/test/java/com/yahoo/document/annotation/AnnotationTypeRegistryTestCase.java @@ -2,11 +2,16 @@ package com.yahoo.document.annotation; import com.yahoo.document.DataType; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ -public class AnnotationTypeRegistryTestCase extends junit.framework.TestCase { +public class AnnotationTypeRegistryTestCase { + + @Test public void testRegisterUnregister() { AnnotationTypeRegistry reg = new AnnotationTypeRegistry(); assertEquals(0, reg.getTypes().size()); @@ -47,4 +52,5 @@ public class AnnotationTypeRegistryTestCase extends junit.framework.TestCase { reg.unregister(three); assertEquals(0, reg.getTypes().size()); } + } diff --git a/document/src/test/java/com/yahoo/document/annotation/AnnotationTypeTestCase.java b/document/src/test/java/com/yahoo/document/annotation/AnnotationTypeTestCase.java index 10ea40d6f9e..deb41647361 100644 --- a/document/src/test/java/com/yahoo/document/annotation/AnnotationTypeTestCase.java +++ b/document/src/test/java/com/yahoo/document/annotation/AnnotationTypeTestCase.java @@ -2,11 +2,17 @@ package com.yahoo.document.annotation; import com.yahoo.document.DataType; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; /** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ -public class AnnotationTypeTestCase extends junit.framework.TestCase { +public class AnnotationTypeTestCase { + + @Test public void testBasic() { AnnotationType a = new AnnotationType("foo"); AnnotationType b = new AnnotationType("foo"); @@ -30,6 +36,7 @@ public class AnnotationTypeTestCase extends junit.framework.TestCase { assertFalse(c.hashCode() == b.hashCode()); } + @Test public void testBasic2() { AnnotationType a = new AnnotationType("foo", DataType.INT); AnnotationType b = new AnnotationType("foo", DataType.INT); @@ -48,6 +55,7 @@ public class AnnotationTypeTestCase extends junit.framework.TestCase { assertEquals(c.hashCode(), c.getId()); } + @Test public void testPolymorphy() { AnnotationType suuper = new AnnotationType("super"); AnnotationType sub = new AnnotationType("sub"); @@ -63,4 +71,5 @@ public class AnnotationTypeTestCase extends junit.framework.TestCase { //this would fail without polymorphy support: AnnotationReference ref2 = new AnnotationReference(refType, subAnnotation); } + } diff --git a/document/src/test/java/com/yahoo/document/annotation/Bug4259784TestCase.java b/document/src/test/java/com/yahoo/document/annotation/Bug4259784TestCase.java index 70e0f3d23c4..0a7739fd8c1 100644 --- a/document/src/test/java/com/yahoo/document/annotation/Bug4259784TestCase.java +++ b/document/src/test/java/com/yahoo/document/annotation/Bug4259784TestCase.java @@ -18,7 +18,7 @@ import org.junit.Test; import java.util.ArrayList; import java.util.List; -public class Bug4259784TestCase extends junit.framework.TestCase { +public class Bug4259784TestCase { @Test public void testSerialize() { diff --git a/document/src/test/java/com/yahoo/document/annotation/DocTestCase.java b/document/src/test/java/com/yahoo/document/annotation/DocTestCase.java index b290252685b..e117a510691 100644 --- a/document/src/test/java/com/yahoo/document/annotation/DocTestCase.java +++ b/document/src/test/java/com/yahoo/document/annotation/DocTestCase.java @@ -9,6 +9,7 @@ import com.yahoo.document.datatypes.Array; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.document.datatypes.Struct; +import org.junit.Test; import java.util.ArrayList; import java.util.Iterator; @@ -18,9 +19,9 @@ import java.util.ListIterator; /** * Contains code snippets that are used in the documentation. Not really a test case. * - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ -public class DocTestCase extends junit.framework.TestCase { +public class DocTestCase { private class Processing { private Service getService() { @@ -36,7 +37,7 @@ public class DocTestCase extends junit.framework.TestCase { private Processing processing = null; - + @Test public void testSimple1() { StringFieldValue text = new StringFieldValue("<html><head><title>Diary</title></head><body>I live in San Francisco</body></html>"); //012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 @@ -152,7 +153,6 @@ public class DocTestCase extends junit.framework.TestCase { text.setSpanTree(tree); } - public void simple4() { //the following line works inside process(Document, Arguments, Processing) in a DocumentProcessor AnnotationTypeRegistry atr = processing.getService().getDocumentTypeManager().getAnnotationTypeRegistry(); @@ -231,7 +231,6 @@ public class DocTestCase extends junit.framework.TestCase { text.setSpanTree(tree); } - public void simple5() { //the following two lines work inside process(Document, Arguments, Processing) in a DocumentProcessor DocumentTypeManager dtm = processing.getService().getDocumentTypeManager(); diff --git a/document/src/test/java/com/yahoo/document/annotation/PeekableListIteratorTestCase.java b/document/src/test/java/com/yahoo/document/annotation/PeekableListIteratorTestCase.java index aa6c1e05012..9e7bff0aaee 100644 --- a/document/src/test/java/com/yahoo/document/annotation/PeekableListIteratorTestCase.java +++ b/document/src/test/java/com/yahoo/document/annotation/PeekableListIteratorTestCase.java @@ -1,22 +1,32 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.annotation; +import org.junit.Before; +import org.junit.Test; + import java.util.ArrayList; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * Tests that PeekableListIterator behaves as expected. * - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ -public class PeekableListIteratorTestCase extends junit.framework.TestCase { +public class PeekableListIteratorTestCase { + private List<String> strings; - @Override + @Before public void setUp() { - strings = new ArrayList<String>(); + strings = new ArrayList<>(); strings.add("0"); strings.add("1"); strings.add("2"); @@ -25,6 +35,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { strings.add("5"); } + @Test public void testSimpleListIterator() { ListIterator<String> it = strings.listIterator(); assertEquals("0", it.next()); @@ -39,6 +50,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { assertEquals("1", it.next()); } + @Test public void testVarious() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); @@ -95,6 +107,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { } } + @Test public void testRemoveFirst() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); try { @@ -111,6 +124,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { assertEquals("1", strings.get(0)); } + @Test public void testPeekThenRemove() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); @@ -132,6 +146,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { assertEquals("5", strings.get(4)); } + @Test public void testPeekNextRemove() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); @@ -146,6 +161,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { assertEquals("5", strings.get(4)); } + @Test public void testPeekNextPeekRemove() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); @@ -161,6 +177,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { assertEquals("5", strings.get(4)); } + @Test public void testPeekNextNextRemove() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); @@ -176,6 +193,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { assertEquals("5", strings.get(4)); } + @Test public void testNextPeekRemove() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); @@ -190,6 +208,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { assertEquals("5", strings.get(4)); } + @Test public void testAddSimple() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); @@ -210,6 +229,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { assertEquals("5", strings.get(8)); } + @Test public void testPeekAdd() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); @@ -231,7 +251,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { assertEquals("5", strings.get(8)); } - + @Test public void testSetFirst() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); try { @@ -248,6 +268,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { assertEquals("elvis", strings.get(0)); } + @Test public void testPeekThenSet() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); @@ -270,6 +291,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { assertEquals("5", strings.get(5)); } + @Test public void testPeekNextSet() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); @@ -285,6 +307,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { assertEquals("5", strings.get(5)); } + @Test public void testPeekNextPeekSet() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); @@ -301,6 +324,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { assertEquals("5", strings.get(5)); } + @Test public void testPeekNextNextSet() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); @@ -317,6 +341,7 @@ public class PeekableListIteratorTestCase extends junit.framework.TestCase { assertEquals("5", strings.get(5)); } + @Test public void testNextPeekSet() { PeekableListIterator<String> it = new PeekableListIterator<String>(strings.listIterator()); diff --git a/document/src/test/java/com/yahoo/document/annotation/SpanNodeTestCase.java b/document/src/test/java/com/yahoo/document/annotation/SpanNodeTestCase.java index c5a14b2492d..8e9978c8452 100644 --- a/document/src/test/java/com/yahoo/document/annotation/SpanNodeTestCase.java +++ b/document/src/test/java/com/yahoo/document/annotation/SpanNodeTestCase.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.annotation; +import org.junit.Test; + import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -9,11 +11,18 @@ import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ -public class SpanNodeTestCase extends junit.framework.TestCase { +public class SpanNodeTestCase { + @Test public void testOverlaps() { //qwertyuiopasdfghjklzxcvbnm //012345678901234567890123456789 @@ -102,6 +111,7 @@ public class SpanNodeTestCase extends junit.framework.TestCase { assertTrue(a.overlaps(a)); } + @Test public void testContains() { //qwertyuiopasdfghjklzxcvbnm //012345678901234567890123456789 @@ -123,7 +133,7 @@ public class SpanNodeTestCase extends junit.framework.TestCase { assertTrue(c.contains(a)); } - + @Test public void testSpanTree() { final String text = "Hallo er et ord fra Norge"; SpanList sentence = new SpanList(); @@ -223,6 +233,7 @@ public class SpanNodeTestCase extends junit.framework.TestCase { //coming up: assert that children(Annotation) works... } + @Test public void testOrder() { { String text = "08/20/1999"; @@ -262,6 +273,7 @@ public class SpanNodeTestCase extends junit.framework.TestCase { } } + @Test public void testNonRecursiveAnnotationIterator() { AnnotationType nounType = new AnnotationType("noun"); AnnotationType detType = new AnnotationType("determiner"); @@ -359,6 +371,7 @@ public class SpanNodeTestCase extends junit.framework.TestCase { } + @Test public void testRecursion() { AnnotationType noun = new AnnotationType("noun"); AnnotationType verb = new AnnotationType("verb"); @@ -564,7 +577,7 @@ public class SpanNodeTestCase extends junit.framework.TestCase { } private static List<Annotation> annotations(SpanTree tree, SpanNode node) { - List<Annotation> list = new ArrayList<Annotation>(); + List<Annotation> list = new ArrayList<>(); Iterator<Annotation> it = tree.iterator(node); while (it.hasNext()) { list.add(it.next()); @@ -572,6 +585,7 @@ public class SpanNodeTestCase extends junit.framework.TestCase { return list; } + @Test public void testMultilevelRecursion() { // 01234567890123 String text = "Hello!Goodbye!"; @@ -604,6 +618,7 @@ public class SpanNodeTestCase extends junit.framework.TestCase { assertTrue(root.getText(text).toString().equals(text)); } + @Test public void testRecursiveIteratorDeterministicBehavior() { SpanList root = new SpanList(); SpanTree tree = new SpanTree("tree", root); @@ -643,4 +658,5 @@ public class SpanNodeTestCase extends junit.framework.TestCase { assertSame(newC, a.children().get(1)); assertEquals(2, a.children().size()); } + } diff --git a/document/src/test/java/com/yahoo/document/annotation/SystemTestCase.java b/document/src/test/java/com/yahoo/document/annotation/SystemTestCase.java index 08ffabd093c..ffa71ea7939 100755 --- a/document/src/test/java/com/yahoo/document/annotation/SystemTestCase.java +++ b/document/src/test/java/com/yahoo/document/annotation/SystemTestCase.java @@ -9,13 +9,16 @@ import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.document.datatypes.Struct; import com.yahoo.document.serialization.*; import com.yahoo.io.GrowableByteBuffer; +import org.junit.Before; +import org.junit.Test; import java.util.Iterator; /** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ -public class SystemTestCase extends junit.framework.TestCase { +public class SystemTestCase { + DocumentTypeManager manager; private void annotate(Document document) { @@ -108,11 +111,13 @@ public class SystemTestCase extends junit.framework.TestCase { System.err.println("Event is " + eventValue.getFieldValue("description") + " with " + eventValue.getFieldValue("person") + " and " + eventValue.getFieldValue("date") + " and " + eventValue.getFieldValue("place")); } + @Before public void setUp() { manager = new DocumentTypeManager(); DocumentTypeManagerConfigurer.configure(manager, "file:src/test/java/com/yahoo/document/annotation/documentmanager.systemtest.cfg"); } + @Test public void testSystemTest() { DocumentType type = manager.getDocumentType("article"); Document inDocument = new Document(type, "doc:article:boringarticle:longarticle"); @@ -127,4 +132,5 @@ public class SystemTestCase extends junit.framework.TestCase { Document outDocument = new Document(deserializer); consume(outDocument); } + } diff --git a/document/src/test/java/com/yahoo/document/datatypes/ArrayTestCase.java b/document/src/test/java/com/yahoo/document/datatypes/ArrayTestCase.java index 14624bc2fcc..d1c7ce8dcf6 100755 --- a/document/src/test/java/com/yahoo/document/datatypes/ArrayTestCase.java +++ b/document/src/test/java/com/yahoo/document/datatypes/ArrayTestCase.java @@ -3,13 +3,24 @@ package com.yahoo.document.datatypes; import com.yahoo.document.ArrayDataType; import com.yahoo.document.DataType; +import org.junit.Test; import java.util.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ -public class ArrayTestCase extends junit.framework.TestCase { +public class ArrayTestCase { + + @Test public void testToArray() { ArrayDataType dt = new ArrayDataType(DataType.STRING); Array<StringFieldValue> arr = new Array<>(dt); @@ -30,6 +41,7 @@ public class ArrayTestCase extends junit.framework.TestCase { assertEquals(new StringFieldValue("c"), b[2]); } + @Test public void testCreateIllegalArray() { ArrayList<FieldValue> arrayList = new ArrayList<>(); arrayList.add(new StringFieldValue("foo")); @@ -58,6 +70,7 @@ public class ArrayTestCase extends junit.framework.TestCase { } } + @Test public void testWrappedList() { Array<StringFieldValue> array = new Array<StringFieldValue>(DataType.getArray(DataType.STRING)); List<String> list = new ArrayList<>(); @@ -243,6 +256,7 @@ public class ArrayTestCase extends junit.framework.TestCase { } + @Test public void testListWrapperToArray() { Array<StringFieldValue> array = new Array<>(new ArrayDataType(DataType.STRING)); List<StringFieldValue> assignFrom = new ArrayList<>(3); diff --git a/document/src/test/java/com/yahoo/document/datatypes/MapTestCase.java b/document/src/test/java/com/yahoo/document/datatypes/MapTestCase.java index ff6f1544292..c4441910f2a 100644 --- a/document/src/test/java/com/yahoo/document/datatypes/MapTestCase.java +++ b/document/src/test/java/com/yahoo/document/datatypes/MapTestCase.java @@ -11,10 +11,16 @@ import com.yahoo.document.MapDataType; import com.yahoo.document.StructDataType; import com.yahoo.document.serialization.*; import com.yahoo.io.GrowableByteBuffer; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.fail; -public class MapTestCase extends junit.framework.TestCase { +public class MapTestCase { + + @Test public void testStringMap() { MapDataType mapType = new MapDataType(DataType.STRING, DataType.STRING); MapFieldValue<StringFieldValue, StringFieldValue> map = mapType.createFieldValue(); @@ -35,6 +41,7 @@ public class MapTestCase extends junit.framework.TestCase { assertEquals(map.get(new StringFieldValue("k3")).getWrappedValue(), "v3"); } + @Test public void testAdvancedMap() { MapDataType stringMapType1 = new MapDataType(DataType.STRING, DataType.STRING); MapDataType stringMapType2 = new MapDataType(DataType.STRING, DataType.STRING); @@ -84,6 +91,7 @@ public class MapTestCase extends junit.framework.TestCase { } + @Test public void testSerializationStringMap() { MapDataType mapType = new MapDataType(DataType.STRING, DataType.STRING); MapFieldValue<StringFieldValue, StringFieldValue> map = mapType.createFieldValue(); @@ -100,6 +108,7 @@ public class MapTestCase extends junit.framework.TestCase { assertCorrectSerialization(mapType, map); } + @Test public void testSerializationComplex() { ArrayDataType twoDimArray = DataType.getArray(DataType.getArray(DataType.FLOAT)); MapDataType floatToTwoDimArray = new MapDataType(DataType.FLOAT, twoDimArray); @@ -147,6 +156,7 @@ public class MapTestCase extends junit.framework.TestCase { } } + @Test public void testIllegalMapAssignment() { MapDataType type1 = new MapDataType(DataType.INT, DataType.INT); MapDataType type2 = new MapDataType(DataType.STRING, DataType.STRING); diff --git a/document/src/test/java/com/yahoo/document/datatypes/WeightedSetTestCase.java b/document/src/test/java/com/yahoo/document/datatypes/WeightedSetTestCase.java index 678a3c5b0e0..19d5b4b3a7e 100644 --- a/document/src/test/java/com/yahoo/document/datatypes/WeightedSetTestCase.java +++ b/document/src/test/java/com/yahoo/document/datatypes/WeightedSetTestCase.java @@ -3,14 +3,24 @@ package com.yahoo.document.datatypes; import com.yahoo.document.DataType; import com.yahoo.document.MapDataType; +import org.junit.Test; import java.util.LinkedHashMap; import java.util.Map; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ -public class WeightedSetTestCase extends junit.framework.TestCase { +public class WeightedSetTestCase { + + @Test public void testSet() { WeightedSet<StringFieldValue> wset = new WeightedSet<>(DataType.TAG); @@ -58,6 +68,7 @@ public class WeightedSetTestCase extends junit.framework.TestCase { } + @Test public void testAssignDoesNotIgnoreSpecialProperties() { DataType type = DataType.getWeightedSet(DataType.STRING); WeightedSet<StringFieldValue> set = new WeightedSet<>(type); @@ -89,6 +100,7 @@ public class WeightedSetTestCase extends junit.framework.TestCase { assertEquals(new Integer(10), set.get(new StringFieldValue("aba"))); } + @Test public void testWrappedMap() { WeightedSet<StringFieldValue> ws = new WeightedSet<>(DataType.getWeightedSet(DataType.STRING)); Map<String, Integer> map = new LinkedHashMap<>(); @@ -145,6 +157,7 @@ public class WeightedSetTestCase extends junit.framework.TestCase { assertEquals(new Integer(1), ws.get(new StringFieldValue("sitronbrus"))); } + @Test public void testAssigningWrappedSetToMapFieldValue() { WeightedSet<StringFieldValue> weightedSet = new WeightedSet<>(DataType.getWeightedSet(DataType.STRING)); WeightedSet<StringFieldValue> assignmentTarget = new WeightedSet<>(DataType.getWeightedSet(DataType.STRING)); @@ -157,4 +170,5 @@ public class WeightedSetTestCase extends junit.framework.TestCase { assertEquals(Integer.valueOf(1), assignmentTarget.get(new StringFieldValue("foo"))); assertEquals(Integer.valueOf(2), assignmentTarget.get(new StringFieldValue("bar"))); } + } diff --git a/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java b/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java index 5286cec4644..c3aa76a1ebb 100644 --- a/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java +++ b/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java @@ -7,24 +7,28 @@ import com.yahoo.document.select.convert.SelectionExpressionConverter; import com.yahoo.document.select.parser.ParseException; import com.yahoo.document.select.parser.TokenMgrError; import com.yahoo.yolean.Exceptions; +import org.junit.Before; +import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen * @author bratseth */ -public class DocumentSelectorTestCase extends junit.framework.TestCase { +public class DocumentSelectorTestCase { private static DocumentTypeManager manager = new DocumentTypeManager(); - public DocumentSelectorTestCase(String name) { - super(name); - } - + @Before public void setUp() { DocumentType type = new DocumentType("test"); type.addHeaderField("hint", DataType.INT); @@ -58,6 +62,7 @@ public class DocumentSelectorTestCase extends junit.framework.TestCase { manager.registerDocumentType(new DocumentType("usergroup")); } + @Test public void testParsing() throws ParseException { assertParse("3.14 > 0"); assertParse("-999 > 0"); @@ -106,6 +111,7 @@ public class DocumentSelectorTestCase extends junit.framework.TestCase { assertParse("(music.expire / 1000) > (now() - 300)"); } + @Test public void testReservedWords() throws ParseException { assertParse(null, "id == 'id' or id_t or idtype"); // ignore canonical form assertParse(null, "searchcolumn == 1 or searchcolumn_t or searchcolumntype"); @@ -122,6 +128,7 @@ public class DocumentSelectorTestCase extends junit.framework.TestCase { assertParse(null, "true or or_t or ortype"); } + @Test public void testCjkParsing() throws ParseException { assertParse("music.artist = \"\\u4f73\\u80fd\\u7d22\\u5c3c\\u60e0\\u666e\"", "music.artist = \"\u4f73\u80fd\u7d22\u5c3c\u60e0\u666e\""); @@ -129,6 +136,7 @@ public class DocumentSelectorTestCase extends junit.framework.TestCase { "music.artist = \"\\u4f73\\u80fd\\u7d22\\u5c3c\\u60e0\\u666e\""); } + @Test public void testParseTerminals() throws ParseException { // Test number values. assertParse("true"); @@ -225,6 +233,7 @@ public class DocumentSelectorTestCase extends junit.framework.TestCase { assertParse("23 + 643 / 34 % 10 > 34", "23 + 643 / 34 % 10 > 34"); } + @Test public void testParseReservedTokens() throws ParseException { assertParse("user.fieldName == \"fieldValue\""); // reserved word as document type name assertParse("documentName.user == \"fieldValue\""); // reserved word as field type name @@ -232,12 +241,14 @@ public class DocumentSelectorTestCase extends junit.framework.TestCase { assertParse("documentName.group == \"fieldValue\""); // reserved word as field type name } + @Test public void testParseBranches() throws ParseException { assertParse("((true or false) and (false or true))"); assertParse("(true or (not false and not true))"); assertParse("((243) < 300 and (\"FOO\").lowercase() == (\"foo\"))"); } + @Test public void testDocumentUpdate() throws ParseException { DocumentUpdate upd = new DocumentUpdate(manager.getDocumentType("test"), new DocumentId("doc:myspace:anything")); assertEquals(Result.TRUE, evaluate("test", upd)); @@ -250,6 +261,7 @@ public class DocumentSelectorTestCase extends junit.framework.TestCase { // TODO Fails: assertEquals(Result.TRUE, evaluate("test.hint + 1 > 13", upd)); } + @Test public void testDocumentRemove() throws ParseException { assertEquals(Result.TRUE, evaluate("test", createRemove("id:ns:test::1"))); assertEquals(Result.FALSE, evaluate("test", createRemove("id:ns:null::1"))); @@ -265,6 +277,7 @@ public class DocumentSelectorTestCase extends junit.framework.TestCase { return new DocumentRemove(new DocumentId(docId)); } + @Test public void testInvalidLogic() throws ParseException { DocumentPut put = new DocumentPut(manager.getDocumentType("test"), new DocumentId("doc:scheme:")); DocumentUpdate upd = new DocumentUpdate(manager.getDocumentType("test"), new DocumentId("doc:scheme:")); @@ -391,6 +404,7 @@ public class DocumentSelectorTestCase extends junit.framework.TestCase { return documents; } + @Test public void testOperators() throws ParseException { List<DocumentPut> documents = createDocs(); @@ -688,11 +702,13 @@ public class DocumentSelectorTestCase extends junit.framework.TestCase { assertEquals(Result.FALSE, evaluate("test.structarrmap{$x}.key == 17 AND test.stringweightedset{$x}", documents.get(1))); } - public void testTicket1769674() throws ParseException { + @Test + public void testTicket1769674() { assertParseError("music.uri=\"junk", "Lexical error at line -1, column 17. Encountered: <EOF> after : \"\\\"junk\""); } + @Test public void testThatVisitingReportsCorrectResult() throws ParseException { assertVisitWithValidNowWorks("music.expire > now()"); assertVisitWithValidNowWorks("music.expire > now() and video.expire > now()"); @@ -712,6 +728,7 @@ public class DocumentSelectorTestCase extends junit.framework.TestCase { assertVisitWithInvalidNowFails("music.name.hash() > now()", "Only attribute items are supported"); } + @Test public void testThatSelectionIsConvertedToQueries() throws ParseException { assertThatQueriesAreCreated("music.expire > now()", Arrays.asList("music"), Arrays.asList("expire:>now(0)")); assertThatQueriesAreCreated("music.expire > now() - 300", Arrays.asList("music"), Arrays.asList("expire:>now(300)")); @@ -823,4 +840,5 @@ public class DocumentSelectorTestCase extends junit.framework.TestCase { assertEquals(expectedError, e.getMessage().substring(0, expectedError.length())); } } + } diff --git a/document/src/test/java/com/yahoo/document/select/OrderingSpecificationTestCase.java b/document/src/test/java/com/yahoo/document/select/OrderingSpecificationTestCase.java index 79b667b0079..8c0f7402704 100644 --- a/document/src/test/java/com/yahoo/document/select/OrderingSpecificationTestCase.java +++ b/document/src/test/java/com/yahoo/document/select/OrderingSpecificationTestCase.java @@ -1,19 +1,17 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.select; -import com.yahoo.document.select.*; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; /** - * Date: Sep 6, 2007 - * - * @author <a href="mailto:humbe@yahoo-inc.com">Håkon Humberset</a> + * @author Håkon Humberset */ -public class OrderingSpecificationTestCase extends junit.framework.TestCase { - - public OrderingSpecificationTestCase(String name) { - super(name); - } +public class OrderingSpecificationTestCase { + @Test public void testExpressions() throws Exception { assertSelection("id.order(10,10) < 100", OrderingSpecification.DESCENDING, new OrderingSpecification(OrderingSpecification.DESCENDING, (long)99, (short)10, (short)10)); @@ -48,4 +46,5 @@ public class OrderingSpecificationTestCase extends junit.framework.TestCase { assertNull(selector.getOrdering(ordering)); } } + } diff --git a/document/src/test/java/com/yahoo/document/serialization/SerializationHelperTestCase.java b/document/src/test/java/com/yahoo/document/serialization/SerializationHelperTestCase.java index 5bbcd4abc9a..0175f87e3ee 100644 --- a/document/src/test/java/com/yahoo/document/serialization/SerializationHelperTestCase.java +++ b/document/src/test/java/com/yahoo/document/serialization/SerializationHelperTestCase.java @@ -6,20 +6,22 @@ import com.yahoo.io.GrowableByteBuffer; import com.yahoo.text.Utf8; import com.yahoo.text.Utf8Array; import com.yahoo.vespa.objects.BufferSerializer; +import org.junit.Test; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ @SuppressWarnings("deprecation") -public class SerializationHelperTestCase extends junit.framework.TestCase { - public SerializationHelperTestCase(String name) { - super(name); - } +public class SerializationHelperTestCase { - public void testGetNullTerminatedString() throws Exception { + @Test + public void testGetNullTerminatedString() { //This is a test.0ab byte[] test = {0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x0, 0x61, 0x62}; @@ -45,7 +47,8 @@ public class SerializationHelperTestCase extends junit.framework.TestCase { assertTrue(test[16] == 0x61); //a } - public void testSerializeRawField() throws UnsupportedEncodingException { + @Test + public void testSerializeRawField() { GrowableByteBuffer gbuf = new GrowableByteBuffer(); ByteBuffer rawValue = ByteBuffer.wrap(Utf8.toBytes("0123456789")); rawValue.position(7); @@ -61,4 +64,5 @@ public class SerializationHelperTestCase extends junit.framework.TestCase { assertEquals(14, gbuf.position()); assertEquals(7, rawValue.position()); } + } diff --git a/document/src/test/java/com/yahoo/document/serialization/SerializeAnnotationsTestCase.java b/document/src/test/java/com/yahoo/document/serialization/SerializeAnnotationsTestCase.java index d3228e13f38..30db0af6607 100644 --- a/document/src/test/java/com/yahoo/document/serialization/SerializeAnnotationsTestCase.java +++ b/document/src/test/java/com/yahoo/document/serialization/SerializeAnnotationsTestCase.java @@ -13,6 +13,8 @@ import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.document.datatypes.Struct; import com.yahoo.io.GrowableByteBuffer; +import org.junit.Before; +import org.junit.Test; import java.io.File; import java.io.FileInputStream; @@ -23,6 +25,8 @@ import java.nio.channels.FileChannel; import java.nio.channels.ReadableByteChannel; import java.util.ArrayList; +import static org.junit.Assert.assertEquals; + /** * Tests that serialization of annotations from Java generates the * output expected by the C++ deserialization system. @@ -33,17 +37,19 @@ import java.util.ArrayList; * AnnotationDeserialization component to handle the format changes. */ @SuppressWarnings("deprecation") -public class SerializeAnnotationsTestCase extends junit.framework.TestCase { +public class SerializeAnnotationsTestCase { + private static final String PATH = "src/tests/serialization/"; DocumentTypeManager docMan = new DocumentTypeManager(); - @Override + @Before public void setUp() { DocumentTypeManagerConfigurer.configure(docMan, "file:src/tests/serialization/" + "annotation.serialize.test.cfg"); } + @Test public void testSerializeSimpleTree() throws IOException { SpanList root = new SpanList(); root.add(new Span(0, 19)) @@ -78,6 +84,7 @@ public class SerializeAnnotationsTestCase extends junit.framework.TestCase { assertEquals(value, valueFromFile); } + @Test public void testSerializeAdvancedTree() throws IOException { SpanList root = new SpanList(); SpanTree tree = new SpanTree("html", root); @@ -211,4 +218,5 @@ public class SerializeAnnotationsTestCase extends junit.framework.TestCase { return readBuf; } + } diff --git a/document/src/test/java/com/yahoo/document/serialization/XmlStreamTestCase.java b/document/src/test/java/com/yahoo/document/serialization/XmlStreamTestCase.java index 8a519b4122d..21795044252 100644 --- a/document/src/test/java/com/yahoo/document/serialization/XmlStreamTestCase.java +++ b/document/src/test/java/com/yahoo/document/serialization/XmlStreamTestCase.java @@ -2,21 +2,22 @@ package com.yahoo.document.serialization; import com.yahoo.document.serialization.XmlStream; +import org.junit.Test; import java.io.IOException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Test for XmlStream used in document XML serialization. * - * @author <a href="humbe@yahoo-inc.com>Haakon Humberset</a> + * @author Håkon Humberset */ -public class XmlStreamTestCase extends junit.framework.TestCase { - - public XmlStreamTestCase(String name) { - super(name); - } +public class XmlStreamTestCase { /** A catch all test checking that regular usage looks good. */ + @Test public void testNormalUsage() { XmlStream xml = new XmlStream(); xml.setIndent(" "); @@ -55,6 +56,7 @@ public class XmlStreamTestCase extends junit.framework.TestCase { * Test that XML tag and attribute names are checked for validity. * Only the obvious illegal characters are tested currently. */ + @Test public void testIllegalAttributeNames() { String illegalNames[] = {">foo", "foo<bar", " foo", "bar ", "foo bar", "foo\"bar", "&foo"}; XmlStream xml = new XmlStream(); @@ -78,6 +80,7 @@ public class XmlStreamTestCase extends junit.framework.TestCase { } /** Test that XML attribute values are XML escaped. */ + @Test public void testAttributeEscaping() { //String badString = "\"&<>'\n\r\u0000"; String badString = "\"&<>'"; @@ -90,6 +93,7 @@ public class XmlStreamTestCase extends junit.framework.TestCase { } /** Test that content is XML escaped. */ + @Test public void testContentEscaping() { //String badString = "\"&<>'\n\r\u0000"; String badString = "\"&<>'"; diff --git a/document/src/test/java/com/yahoo/document/update/FieldUpdateTestCase.java b/document/src/test/java/com/yahoo/document/update/FieldUpdateTestCase.java index d3bc3f9fa68..3cf0fab80ae 100644 --- a/document/src/test/java/com/yahoo/document/update/FieldUpdateTestCase.java +++ b/document/src/test/java/com/yahoo/document/update/FieldUpdateTestCase.java @@ -6,19 +6,27 @@ import com.yahoo.document.datatypes.*; import com.yahoo.document.serialization.DocumentDeserializerFactory; import com.yahoo.document.serialization.DocumentSerializer; import com.yahoo.document.serialization.DocumentSerializerFactory; +import org.junit.Before; +import org.junit.Test; import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + /** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ -public class FieldUpdateTestCase extends junit.framework.TestCase { - Field strfoo; - Field strarray; - Field strws; - Field strws2; - DocumentTypeManager docman = new DocumentTypeManager(); +public class FieldUpdateTestCase { + + private Field strfoo; + private Field strarray; + private Field strws; + private Field strws2; + private DocumentTypeManager docman = new DocumentTypeManager(); + @Before public void setUp() { docman = new DocumentTypeManager(); @@ -36,6 +44,7 @@ public class FieldUpdateTestCase extends junit.framework.TestCase { strws2 = docman.getDocumentType("foobar").getField("strws2"); } + @Test public void testInstantiationExceptions() { //add(field, value) try { @@ -185,6 +194,7 @@ public class FieldUpdateTestCase extends junit.framework.TestCase { return copy; } + @Test public void testApplyToSingleValue() { Document testDoc = new Document(docman.getDocumentType("foobar"), new DocumentId("doc:test:ballooo")); FieldUpdate alter = FieldUpdate.create(strfoo); @@ -201,6 +211,7 @@ public class FieldUpdateTestCase extends junit.framework.TestCase { assertNull(testDoc.getFieldValue("strfoo")); } + @Test public void testApplyToArray() { Array<StringFieldValue> fruitList = new Array<>(DataType.getArray(DataType.STRING)); fruitList.add(new StringFieldValue("kiwi")); @@ -245,6 +256,7 @@ public class FieldUpdateTestCase extends junit.framework.TestCase { assertNull(testDoc.getFieldValue("strarray")); } + @Test public void testApplyToWs() { WeightedSet fruitWs = new WeightedSet(DataType.getWeightedSet(DataType.STRING)); fruitWs.put(new StringFieldValue("pineapple"), 50); @@ -351,6 +363,7 @@ public class FieldUpdateTestCase extends junit.framework.TestCase { assertNull(testDoc.getFieldValue("strws")); } + @Test public void testArithmeticUpdatesOnAutoCreatedWSetItemsAreZeroBased() { Document testDoc = new Document( docman.getDocumentType("foobar"), diff --git a/document/src/test/java/com/yahoo/document/update/SerializationTestCase.java b/document/src/test/java/com/yahoo/document/update/SerializationTestCase.java index bd3c0ff7322..f1cce1e4c4a 100644 --- a/document/src/test/java/com/yahoo/document/update/SerializationTestCase.java +++ b/document/src/test/java/com/yahoo/document/update/SerializationTestCase.java @@ -4,30 +4,32 @@ package com.yahoo.document.update; import com.yahoo.document.*; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.document.serialization.*; +import org.junit.Before; +import org.junit.Test; import java.io.FileOutputStream; +import static org.junit.Assert.assertEquals; + /** * @author bratseth */ -public class SerializationTestCase extends junit.framework.TestCase { +public class SerializationTestCase { private DocumentType documentType; private Field field; - public SerializationTestCase(String name) { - super(name); - } - + @Before public void setUp() { - documentType=new DocumentType("document1"); - field=new Field("field1", DataType.getArray(DataType.STRING)); + documentType = new DocumentType("document1"); + field = new Field("field1", DataType.getArray(DataType.STRING)); documentType.addField(field); } + @Test public void testAddSerialization() { - FieldUpdate update=FieldUpdate.createAdd(field, new StringFieldValue("value1")); + FieldUpdate update = FieldUpdate.createAdd(field, new StringFieldValue("value1")); DocumentSerializer buffer = DocumentSerializerFactory.create42(); update.serialize(buffer); @@ -43,8 +45,9 @@ public class SerializationTestCase extends junit.framework.TestCase { assertEquals("'field1' [add value1 1]", deserializedUpdate.toString()); } + @Test public void testClearSerialization() { - FieldUpdate update=FieldUpdate.createClear(field); + FieldUpdate update = FieldUpdate.createClear(field); DocumentSerializer buffer = DocumentSerializerFactory.create42(); update.serialize(buffer); diff --git a/document/src/test/java/com/yahoo/document/update/ValueUpdateTestCase.java b/document/src/test/java/com/yahoo/document/update/ValueUpdateTestCase.java index 21fda8d3063..0e90e34bb5e 100644 --- a/document/src/test/java/com/yahoo/document/update/ValueUpdateTestCase.java +++ b/document/src/test/java/com/yahoo/document/update/ValueUpdateTestCase.java @@ -3,16 +3,21 @@ package com.yahoo.document.update; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.StringFieldValue; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * Test case for ValueUpdate class. * - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ -public class ValueUpdateTestCase extends junit.framework.TestCase { +public class ValueUpdateTestCase { + + @Test public void testUpdateSimple() { - /** We cannot test much on this level anyway, most stuff in ValueUpdate is package - * private. Better tests exist in FieldUpdateTestCase. */ + // We cannot test much on this level anyway, most stuff in ValueUpdate is package + // private. Better tests exist in FieldUpdateTestCase. AssignValueUpdate upd = (AssignValueUpdate) ValueUpdate.createAssign(new StringFieldValue("newvalue")); assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, upd.getValueUpdateClassID()); @@ -20,4 +25,5 @@ public class ValueUpdateTestCase extends junit.framework.TestCase { FieldValue newValue = upd.getValue(); assertEquals(new StringFieldValue("newvalue"), newValue); } + } |