aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/prelude/hitfield/XmlRendererTestCase.java
blob: 9b98b798686a588e981fced510bf1f784b0e41e2 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.hitfield;

import com.yahoo.data.access.simple.Value;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class XmlRendererTestCase {

    @Test
    void testWeightedSet1() {
        Value.ArrayValue top = new Value.ArrayValue();
        top
                .add(new Value.ArrayValue()
                        .add(new Value.StringValue("per"))
                        .add(new Value.LongValue(10)))
                .add(new Value.ArrayValue()
                        .add(new Value.StringValue("paal"))
                        .add(new Value.LongValue(20)))
                .add(new Value.ArrayValue()
                        .add(new Value.StringValue("espen"))
                        .add(new Value.LongValue(30)));
        String rendered = XmlRenderer.render(new StringBuilder(), top).toString();
        String correct = "\n"
                + "      <item weight=\"10\">per</item>\n"
                + "      <item weight=\"20\">paal</item>\n"
                + "      <item weight=\"30\">espen</item>\n"
                + "    ";
        assertEquals(correct, rendered);
    }

    @Test
    void testWeightedSet2() {
        Value.ObjectValue top = new Value.ObjectValue();
        top
                .put("foo", new Value.ArrayValue()
                        .add(new Value.ArrayValue()
                                .add(new Value.StringValue("per"))
                                .add(new Value.LongValue(10)))
                        .add(new Value.ArrayValue()
                                .add(new Value.StringValue("paal"))
                                .add(new Value.LongValue(20)))
                        .add(new Value.ArrayValue()
                                .add(new Value.StringValue("espen"))
                                .add(new Value.LongValue(30))))
                .put("bar", new Value.ArrayValue()
                        .add(new Value.ObjectValue()
                                .put("item", new Value.StringValue("per"))
                                .put("weight", new Value.LongValue(10)))
                        .add(new Value.ObjectValue()
                                .put("item", new Value.StringValue("paal"))
                                .put("weight", new Value.LongValue(20)))
                        .add(new Value.ObjectValue()
                                .put("weight", new Value.LongValue(30))
                                .put("item", new Value.StringValue("espen"))));
        String rendered = XmlRenderer.render(new StringBuilder(), top).toString();
        String correct = "\n"
                + "      <struct-field name=\"foo\">\n"
                + "        <item weight=\"10\">per</item>\n"
                + "        <item weight=\"20\">paal</item>\n"
                + "        <item weight=\"30\">espen</item>\n"
                + "      </struct-field>\n"
                + "      <struct-field name=\"bar\">\n"
                + "        <item weight=\"10\">per</item>\n"
                + "        <item weight=\"20\">paal</item>\n"
                + "        <item weight=\"30\">espen</item>\n"
                + "      </struct-field>\n"
                + "    ";
        assertEquals(correct, rendered);
    }

}