diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-05-19 12:03:06 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-05-19 12:03:06 +0200 |
commit | 5c24dc5c9642a8d9ed70aee4c950fd0678a1ebec (patch) | |
tree | bd9b74bf00c832456f0b83c1b2cd7010be387d68 /config-model/src/test/java/com/yahoo/schema/NameFieldCheckTestCase.java | |
parent | f17c4fe7de4c55f5c4ee61897eab8c2f588d8405 (diff) |
Rename the 'searchdefinition' package to 'schema'
Diffstat (limited to 'config-model/src/test/java/com/yahoo/schema/NameFieldCheckTestCase.java')
-rw-r--r-- | config-model/src/test/java/com/yahoo/schema/NameFieldCheckTestCase.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/NameFieldCheckTestCase.java b/config-model/src/test/java/com/yahoo/schema/NameFieldCheckTestCase.java new file mode 100644 index 00000000000..9b4b6864309 --- /dev/null +++ b/config-model/src/test/java/com/yahoo/schema/NameFieldCheckTestCase.java @@ -0,0 +1,80 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.schema; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests that "name" is not allowed as name for a field. + * + * And that duplicate names are not allowed. + * + * @author Lars Christian Jensen + */ +public class NameFieldCheckTestCase extends AbstractSchemaTestCase { + + @Test + public void testNameField() { + try { + ApplicationBuilder.createFromString( + "search simple {\n" + + " document name-check {\n" + + " field title type string {\n" + + " indexing: summary | index\n" + + " }\n" + + " # reserved name, should trigger error\n" + + " field sddocname type string {\n" + + " indexing: index\n" + + " }\n" + + " }\n" + + "}"); + fail("Should throw exception."); + } catch (Exception expected) { + // Success + } + } + + @Test + public void testDuplicateNamesInSearchDifferentType() { + try { + ApplicationBuilder.createFromString( + "search duplicatenamesinsearch {\n" + + " document {\n" + + " field grpphotoids64 type string { }\n" + + " }\n" + + " field grpphotoids64 type array<long> {\n" + + " indexing: input grpphotoids64 | split \" \" | for_each {\n" + + " base64decode } | attribute\n" + + " }\n" + + "}"); + fail("Should throw exception."); + } catch (Exception e) { + assertEquals("For schema 'duplicatenamesinsearch', field 'grpphotoids64': " + + "Incompatible types. Expected Array<long> for index field 'grpphotoids64', got string.", e.getMessage()); + } + } + + @Test + public void testDuplicateNamesInDoc() { + try { + ApplicationBuilder.createFromString( + "search duplicatenamesindoc {\n" + + " document {\n" + + " field foo type int {\n" + + " indexing: attribute\n" + + " }\n" + + " field fOo type string {\n" + + " indexing: index\n" + + " }\n" + + " }\n" + + "}"); + fail("Should throw exception."); + } catch (Exception e) { + assertTrue(e.getMessage().matches(".*Duplicate.*")); + } + } + +} |