summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorGeir Storli <geirstorli@yahoo.no>2017-03-01 12:55:20 +0100
committerGitHub <noreply@github.com>2017-03-01 12:55:20 +0100
commitd72765afb3748d295c86169cab1e2c98f7450e4e (patch)
treeba60955f79577266e1bd4c82045ffeea384c6d8e /config-model
parentbe31c1f94e902d4bc6aa5bcf7d9bec358bb4a784 (diff)
parent935642e1c99842eaef357d956085d02d40070efe (diff)
Merge pull request #1890 from yahoo/bjorncs/validate-datatype-imported-fields
Verify that changing target type of reference field is not allowed
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentTypeChangeValidatorTest.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentTypeChangeValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentTypeChangeValidatorTest.java
index 1c4564851d8..685ef3b1cc1 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentTypeChangeValidatorTest.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentTypeChangeValidatorTest.java
@@ -1,14 +1,24 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.application.validation.change.search;
+import com.yahoo.document.DocumentType;
+import com.yahoo.document.Field;
+import com.yahoo.document.ReferenceDataType;
+import com.yahoo.document.StructDataType;
+import com.yahoo.documentmodel.NewDocumentType;
+import com.yahoo.searchdefinition.FieldSets;
import com.yahoo.vespa.model.application.validation.ValidationOverrides;
import com.yahoo.vespa.model.application.validation.change.VespaConfigChangeAction;
+import com.yahoo.vespa.model.application.validation.change.VespaRefeedAction;
import org.junit.Test;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import static com.yahoo.vespa.model.application.validation.change.ConfigChangeTestUtils.newRefeedAction;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* Test validation of changes between a current and next document type used in a document database.
@@ -167,4 +177,31 @@ public class DocumentTypeChangeValidatorTest {
"Field 'f3' changed: data type: 's1:{f1:string,f2:int}' -> 's1:{f1:int,f2:string}'"));
}
+ @Test
+ public void requireThatChangingTargetTypeOfReferenceFieldIsNotOK() throws Exception {
+ DocumentTypeChangeValidator validator = new DocumentTypeChangeValidator(
+ createDocumentTypeWithReferenceField("oldDoc"),
+ createDocumentTypeWithReferenceField("newDoc"));
+ List<VespaConfigChangeAction> result = validator.validate(ValidationOverrides.empty());
+ assertEquals(1, result.size());
+ VespaConfigChangeAction action = result.get(0);
+ assertTrue(action instanceof VespaRefeedAction);
+ assertEquals(
+ "type='refeed', " +
+ "message='Field 'ref' changed: data type: 'Reference<oldDoc>' -> 'Reference<newDoc>'', " +
+ "services=[], documentType=''",
+ action.toString());
+ }
+
+ private static NewDocumentType createDocumentTypeWithReferenceField(String nameReferencedDocumentType) {
+ StructDataType headerfields = new StructDataType("headerfields");
+ headerfields.addField(new Field("ref", new ReferenceDataType(new DocumentType(nameReferencedDocumentType), 0)));
+ return new NewDocumentType(
+ new NewDocumentType.Name("mydoc"),
+ headerfields,
+ new StructDataType("bodyfields"),
+ new FieldSets(),
+ Collections.emptySet());
+ }
+
}