diff options
author | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2022-07-28 14:44:47 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2022-07-28 14:51:35 +0200 |
commit | 695209a356ecae42536fd394189a98cf5274518e (patch) | |
tree | fff14a30ce9efde18a83d15ff08bbdb672119477 /config-model/src/test/java/com/yahoo/schema/parser | |
parent | 9dab1e67022884f6644b3d8c9b02c6b3c466a879 (diff) |
Convert config-model to junit5
Diffstat (limited to 'config-model/src/test/java/com/yahoo/schema/parser')
4 files changed, 90 insertions, 93 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/parser/ConvertIntermediateTestCase.java b/config-model/src/test/java/com/yahoo/schema/parser/ConvertIntermediateTestCase.java index 516c259013f..8f9f8032054 100644 --- a/config-model/src/test/java/com/yahoo/schema/parser/ConvertIntermediateTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/parser/ConvertIntermediateTestCase.java @@ -4,10 +4,10 @@ package com.yahoo.schema.parser; import com.yahoo.document.DocumentTypeManager; import static com.yahoo.config.model.test.TestUtil.joinLines; -import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertThrows; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author arnej @@ -15,12 +15,12 @@ import static org.junit.Assert.assertThrows; public class ConvertIntermediateTestCase { @Test - public void can_convert_minimal_schema() throws Exception { + void can_convert_minimal_schema() throws Exception { String input = joinLines - ("schema foo {", - " document foo {", - " }", - "}"); + ("schema foo {", + " document foo {", + " }", + "}"); var collection = new IntermediateCollection(); ParsedSchema schema = collection.addSchemaFromString(input); assertEquals("foo", schema.getDocument().name()); @@ -32,7 +32,7 @@ public class ConvertIntermediateTestCase { } @Test - public void can_convert_schema_files() throws Exception { + void can_convert_schema_files() throws Exception { var collection = new IntermediateCollection(); collection.addSchemaFromFile("src/test/derived/deriver/child.sd"); collection.addSchemaFromFile("src/test/derived/deriver/grandparent.sd"); @@ -50,7 +50,7 @@ public class ConvertIntermediateTestCase { } @Test - public void can_convert_structs_and_annotations() throws Exception { + void can_convert_structs_and_annotations() throws Exception { var collection = new IntermediateCollection(); collection.addSchemaFromFile("src/test/converter/child.sd"); collection.addSchemaFromFile("src/test/converter/other.sd"); @@ -62,34 +62,34 @@ public class ConvertIntermediateTestCase { var dt = docMan.getDocumentType("child"); assertTrue(dt != null); for (var parent : dt.getInheritedTypes()) { - System.err.println("dt "+dt.getName()+" inherits from "+parent.getName()); + System.err.println("dt " + dt.getName() + " inherits from " + parent.getName()); } for (var field : dt.fieldSetAll()) { - System.err.println("dt "+dt.getName()+" contains field "+field.getName()+" of type "+field.getDataType()); + System.err.println("dt " + dt.getName() + " contains field " + field.getName() + " of type " + field.getDataType()); } dt = docMan.getDocumentType("parent"); assertTrue(dt != null); for (var parent : dt.getInheritedTypes()) { - System.err.println("dt "+dt.getName()+" inherits from "+parent.getName()); + System.err.println("dt " + dt.getName() + " inherits from " + parent.getName()); } for (var field : dt.fieldSetAll()) { - System.err.println("dt "+dt.getName()+" contains field "+field.getName()+" of type "+field.getDataType()); + System.err.println("dt " + dt.getName() + " contains field " + field.getName() + " of type " + field.getDataType()); } dt = docMan.getDocumentType("grandparent"); assertTrue(dt != null); for (var parent : dt.getInheritedTypes()) { - System.err.println("dt "+dt.getName()+" inherits from "+parent.getName()); + System.err.println("dt " + dt.getName() + " inherits from " + parent.getName()); } for (var field : dt.fieldSetAll()) { - System.err.println("dt "+dt.getName()+" contains field "+field.getName()+" of type "+field.getDataType()); + System.err.println("dt " + dt.getName() + " contains field " + field.getName() + " of type " + field.getDataType()); } dt = docMan.getDocumentType("other"); assertTrue(dt != null); for (var parent : dt.getInheritedTypes()) { - System.err.println("dt "+dt.getName()+" inherits from "+parent.getName()); + System.err.println("dt " + dt.getName() + " inherits from " + parent.getName()); } for (var field : dt.fieldSetAll()) { - System.err.println("dt "+dt.getName()+" contains field "+field.getName()+" of type "+field.getDataType()); + System.err.println("dt " + dt.getName() + " contains field " + field.getName() + " of type " + field.getDataType()); } } } diff --git a/config-model/src/test/java/com/yahoo/schema/parser/IntermediateCollectionTestCase.java b/config-model/src/test/java/com/yahoo/schema/parser/IntermediateCollectionTestCase.java index c4ee1d27c8c..6ebfea41d84 100644 --- a/config-model/src/test/java/com/yahoo/schema/parser/IntermediateCollectionTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/parser/IntermediateCollectionTestCase.java @@ -10,10 +10,9 @@ import java.io.File; import java.io.FileReader; import java.util.List; -import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertThrows; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /** * @author arnej @@ -21,12 +20,12 @@ import static org.junit.Assert.assertThrows; public class IntermediateCollectionTestCase { @Test - public void can_add_minimal_schema() throws Exception { + void can_add_minimal_schema() throws Exception { String input = joinLines - ("schema foo {", - " document foo {", - " }", - "}"); + ("schema foo {", + " document foo {", + " }", + "}"); var collection = new IntermediateCollection(); ParsedSchema schema = collection.addSchemaFromString(input); assertEquals("foo", schema.name()); @@ -35,12 +34,12 @@ public class IntermediateCollectionTestCase { } @Test - public void names_may_differ() throws Exception { + void names_may_differ() throws Exception { String input = joinLines - ("schema foo_search {", - " document foo {", - " }", - "}"); + ("schema foo_search {", + " document foo {", + " }", + "}"); var collection = new IntermediateCollection(); ParsedSchema schema = collection.addSchemaFromString(input); assertEquals("foo_search", schema.name()); @@ -49,7 +48,7 @@ public class IntermediateCollectionTestCase { } @Test - public void can_add_schema_files() throws Exception { + void can_add_schema_files() throws Exception { var collection = new IntermediateCollection(); collection.addSchemaFromFile("src/test/derived/deriver/child.sd"); collection.addSchemaFromFile("src/test/derived/deriver/grandparent.sd"); @@ -75,7 +74,7 @@ public class IntermediateCollectionTestCase { } @Test - public void can_add_schemas() throws Exception { + void can_add_schemas() throws Exception { var collection = new IntermediateCollection(); collection.addSchemaFromReader(readerOf("src/test/derived/deriver/child.sd")); collection.addSchemaFromReader(readerOf("src/test/derived/deriver/grandparent.sd")); @@ -101,7 +100,7 @@ public class IntermediateCollectionTestCase { } @Test - public void can_add_extra_rank_profiles() throws Exception { + void can_add_extra_rank_profiles() throws Exception { var collection = new IntermediateCollection(); collection.addSchemaFromFile("src/test/derived/rankprofilemodularity/test.sd"); collection.addRankProfileFile("test", "src/test/derived/rankprofilemodularity/test/outside_schema1.profile"); @@ -128,32 +127,32 @@ public class IntermediateCollectionTestCase { } @Test - public void name_mismatch_throws() throws Exception { + void name_mismatch_throws() throws Exception { var collection = new IntermediateCollection(); var ex = assertThrows(IllegalArgumentException.class, () -> - collection.addSchemaFromReader(readerOf("src/test/cfg/application/sdfilenametest/schemas/notmusic.sd"))); + collection.addSchemaFromReader(readerOf("src/test/cfg/application/sdfilenametest/schemas/notmusic.sd"))); assertEquals("The file containing schema 'music' must be named 'music.sd', was 'notmusic.sd'", - ex.getMessage()); + ex.getMessage()); } @Test - public void bad_parse_throws() throws Exception { + void bad_parse_throws() throws Exception { var collection = new IntermediateCollection(); var ex = assertThrows(ParseException.class, () -> - collection.addSchemaFromFile("src/test/examples/badparse.sd")); + collection.addSchemaFromFile("src/test/examples/badparse.sd")); assertTrue(ex.getMessage().startsWith("Failed parsing schema from src/test/examples/badparse.sd: Encountered")); ex = assertThrows(ParseException.class, () -> - collection.addSchemaFromReader(readerOf("src/test/examples/badparse.sd"))); + collection.addSchemaFromReader(readerOf("src/test/examples/badparse.sd"))); assertTrue(ex.getMessage().startsWith("Failed parsing schema from src/test/examples/badparse.sd: Encountered")); collection.addSchemaFromFile("src/test/derived/rankprofilemodularity/test.sd"); collection.addRankProfileFile("test", "src/test/derived/rankprofilemodularity/test/outside_schema1.profile"); ex = assertThrows(ParseException.class, () -> - collection.addRankProfileFile("test", "src/test/examples/badparse.sd")); + collection.addRankProfileFile("test", "src/test/examples/badparse.sd")); assertTrue(ex.getMessage().startsWith("Failed parsing rank-profile from src/test/examples/badparse.sd: Encountered")); } @Test - public void can_resolve_document_inheritance() throws Exception { + void can_resolve_document_inheritance() throws Exception { var collection = new IntermediateCollection(); collection.addSchemaFromFile("src/test/derived/deriver/child.sd"); collection.addSchemaFromFile("src/test/derived/deriver/grandparent.sd"); @@ -172,63 +171,63 @@ public class IntermediateCollectionTestCase { } @Test - public void can_detect_schema_inheritance_cycles() throws Exception { + void can_detect_schema_inheritance_cycles() throws Exception { var collection = new IntermediateCollection(); collection.addSchemaFromString("schema foo inherits bar { document foo {} }"); collection.addSchemaFromString("schema bar inherits qux { document bar {} }"); collection.addSchemaFromString("schema qux inherits foo { document qux {} }"); assertEquals(collection.getParsedSchemas().size(), 3); var ex = assertThrows(IllegalArgumentException.class, () -> - collection.resolveInternalConnections()); + collection.resolveInternalConnections()); assertTrue(ex.getMessage().startsWith("Inheritance/reference cycle for schemas: ")); } @Test - public void can_detect_document_inheritance_cycles() throws Exception { + void can_detect_document_inheritance_cycles() throws Exception { var collection = new IntermediateCollection(); collection.addSchemaFromString("schema foo { document foo inherits bar {} }"); collection.addSchemaFromString("schema bar { document bar inherits qux {} }"); collection.addSchemaFromString("schema qux { document qux inherits foo {} }"); assertEquals(collection.getParsedSchemas().size(), 3); var ex = assertThrows(IllegalArgumentException.class, () -> - collection.resolveInternalConnections()); - System.err.println("ex: "+ex.getMessage()); + collection.resolveInternalConnections()); + System.err.println("ex: " + ex.getMessage()); assertTrue(ex.getMessage().startsWith("Inheritance/reference cycle for documents: ")); } @Test - public void can_detect_missing_doc() throws Exception { + void can_detect_missing_doc() throws Exception { var collection = new IntermediateCollection(); collection.addSchemaFromString("schema foo { document foo inherits bar {} }"); collection.addSchemaFromString("schema qux { document qux inherits foo {} }"); assertEquals(collection.getParsedSchemas().size(), 2); var ex = assertThrows(IllegalArgumentException.class, () -> - collection.resolveInternalConnections()); + collection.resolveInternalConnections()); assertEquals("document foo inherits from unavailable document bar", ex.getMessage()); } @Test - public void can_detect_document_reference_cycle() throws Exception { + void can_detect_document_reference_cycle() throws Exception { var collection = new IntermediateCollection(); collection.addSchemaFromString("schema foo { document foo { field oneref type reference<bar> {} } }"); collection.addSchemaFromString("schema bar { document bar { field tworef type reference<foo> {} } }"); assertEquals(collection.getParsedSchemas().size(), 2); var ex = assertThrows(IllegalArgumentException.class, () -> - collection.resolveInternalConnections()); - System.err.println("ex: "+ex.getMessage()); + collection.resolveInternalConnections()); + System.err.println("ex: " + ex.getMessage()); assertTrue(ex.getMessage().startsWith("Inheritance/reference cycle for documents: ")); } @Test - public void can_detect_cycles_with_reference() throws Exception { + void can_detect_cycles_with_reference() throws Exception { var collection = new IntermediateCollection(); collection.addSchemaFromString("schema foo { document foodoc inherits bardoc {} }"); collection.addSchemaFromString("schema bar { document bardoc { field myref type reference<qux> { } } }"); collection.addSchemaFromString("schema qux inherits foo { document qux inherits foodoc {} }"); assertEquals(collection.getParsedSchemas().size(), 3); var ex = assertThrows(IllegalArgumentException.class, () -> - collection.resolveInternalConnections()); - System.err.println("ex: "+ex.getMessage()); + collection.resolveInternalConnections()); + System.err.println("ex: " + ex.getMessage()); assertTrue(ex.getMessage().startsWith("Inheritance/reference cycle for documents: ")); } diff --git a/config-model/src/test/java/com/yahoo/schema/parser/ParsedDocumentTestCase.java b/config-model/src/test/java/com/yahoo/schema/parser/ParsedDocumentTestCase.java index 9245b64b09e..a594f9ae535 100644 --- a/config-model/src/test/java/com/yahoo/schema/parser/ParsedDocumentTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/parser/ParsedDocumentTestCase.java @@ -1,9 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.schema.parser; -import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author arnej @@ -11,7 +12,7 @@ import static org.junit.Assert.assertThrows; public class ParsedDocumentTestCase { @Test - public void fields_can_be_added_once() throws Exception { + void fields_can_be_added_once() throws Exception { var doc = new ParsedDocument("foo"); var stringType = ParsedType.fromName("string"); doc.addField(new ParsedField("bar1", stringType)); @@ -19,11 +20,11 @@ public class ParsedDocumentTestCase { doc.addField(new ParsedField("bar2", stringType)); doc.addField(new ParsedField("bar3", stringType)); var e = assertThrows(IllegalArgumentException.class, () -> - doc.addField(new ParsedField("zap", stringType))); - System.err.println("As expected: "+e); + doc.addField(new ParsedField("zap", stringType))); + System.err.println("As expected: " + e); assertEquals("document 'foo' error: Duplicate (case insensitively) field 'zap' in document type 'foo'", e.getMessage()); e = assertThrows(IllegalArgumentException.class, () -> - doc.addField(new ParsedField("ZAP", stringType))); + doc.addField(new ParsedField("ZAP", stringType))); assertEquals("document 'foo' error: Duplicate (case insensitively) field 'ZAP' in document type 'foo'", e.getMessage()); } diff --git a/config-model/src/test/java/com/yahoo/schema/parser/SchemaParserTestCase.java b/config-model/src/test/java/com/yahoo/schema/parser/SchemaParserTestCase.java index 77d1b55019d..150c237bbba 100644 --- a/config-model/src/test/java/com/yahoo/schema/parser/SchemaParserTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/parser/SchemaParserTestCase.java @@ -8,12 +8,9 @@ import static com.yahoo.config.model.test.TestUtil.joinLines; import java.io.File; -import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertThrows; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /** * @author arnej @@ -38,12 +35,12 @@ public class SchemaParserTestCase { } @Test - public void minimal_schema_can_be_parsed() throws Exception { + void minimal_schema_can_be_parsed() throws Exception { String input = joinLines - ("schema foo {", - " document foo {", - " }", - "}"); + ("schema foo {", + " document foo {", + " }", + "}"); ParsedSchema schema = parseString(input); assertEquals("foo", schema.name()); assertTrue(schema.hasDocument()); @@ -51,10 +48,10 @@ public class SchemaParserTestCase { } @Test - public void document_only_can_be_parsed() throws Exception { + void document_only_can_be_parsed() throws Exception { String input = joinLines - ("document bar {", - "}"); + ("document bar {", + "}"); ParsedSchema schema = parseString(input); assertEquals("bar", schema.name()); assertTrue(schema.hasDocument()); @@ -62,28 +59,28 @@ public class SchemaParserTestCase { } @Test - public void multiple_documents_disallowed() { + void multiple_documents_disallowed() { String input = joinLines ("schema foo {", - " document foo {", - " }", - " document foo2 {", - " }", - "}"); + " document foo {", + " }", + " document foo2 {", + " }", + "}"); var e = assertThrows(IllegalArgumentException.class, () -> parseString(input)); assertEquals("schema 'foo' error: already has document 'foo' so cannot add document 'foo2'", e.getMessage()); } @Test - public void backwards_path_is_disallowed() { + void backwards_path_is_disallowed() { assertEquals("'..' is not allowed in path", - assertThrows(IllegalArgumentException.class, - () -> parseString("schema foo {\n" + - " constant my_constant_tensor {\n" + - " file: foo/../bar\n" + - " type: tensor<float>(x{},y{})\n" + - " }\n" + - "}\n")).getMessage()); + assertThrows(IllegalArgumentException.class, + () -> parseString("schema foo {\n" + + " constant my_constant_tensor {\n" + + " file: foo/../bar\n" + + " type: tensor<float>(x{},y{})\n" + + " }\n" + + "}\n")).getMessage()); } void checkFileParses(String fileName) throws Exception { @@ -95,7 +92,7 @@ public class SchemaParserTestCase { // TODO: Many (all)? of the files below are parsed from other tests and can be removed from here @Test - public void parse_various_old_sdfiles() throws Exception { + void parse_various_old_sdfiles() throws Exception { checkFileParses("src/test/cfg/search/data/travel/schemas/TTData.sd"); checkFileParses("src/test/cfg/search/data/travel/schemas/TTEdge.sd"); checkFileParses("src/test/cfg/search/data/travel/schemas/TTPOI.sd"); |