blob: 8ba0bd815ea8188a4a71aa0c66f7d3198a069e6c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document;
import com.yahoo.document.datatypes.*;
import org.junit.Before;
import org.junit.Test;
/**
* Tests for ticket 6394548
*/
public class IncompatibleFieldTypesTest {
private DataType arrayOfStrings;
private StructDataType struct;
private StructuredFieldValue root;
@Before
public void setUp() {
arrayOfStrings = new ArrayDataType(DataType.STRING);
struct = new StructDataType("fancypants");
struct.addField(new Field("stringarray", arrayOfStrings, false));
DataType weightedSetOfStrings = DataType.getWeightedSet(DataType.STRING, false, false);
struct.addField(new Field("stringws", weightedSetOfStrings, false));
root = struct.createFieldValue();
root.setFieldValue("stringarray", arrayOfStrings.createFieldValue());
root.setFieldValue("stringws", weightedSetOfStrings.createFieldValue());
}
@Test(expected = IllegalArgumentException.class)
public void testAddingIncompatibleFieldToArrayFails() {
System.out.println(root.getFieldValue("stringarray").getDataType().createFieldValue().getClass().getName());
System.out.println(root.getFieldValue("stringarray").getDataType().createFieldValue().getDataType().toString());
((Array)root.getFieldValue("stringarray")).add(new IntegerFieldValue(1234));
}
@Test(expected = IllegalArgumentException.class)
public void testAddingIncompatibleFieldToWeightedSetFails() {
System.out.println(root.getFieldValue("stringws").getDataType().createFieldValue().getClass().getName());
System.out.println(root.getFieldValue("stringws").getDataType().createFieldValue().getDataType().toString());
((WeightedSet<FieldValue>)root.getFieldValue("stringws")).put(new IntegerFieldValue(1234), 100);
}
}
|