summaryrefslogtreecommitdiffstats
path: root/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/ListNodeDataProcessorTest.java
blob: ddb30ef3158de267b3639ac9e867c05368f83d44 (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.fd.honeycomb.test.tools;

import static io.fd.honeycomb.test.tools.InjectionTestData.AUGMENT_LIST_DATA_PATH;
import static io.fd.honeycomb.test.tools.InjectionTestData.AUGMENT_LIST_RESOURCE;
import static io.fd.honeycomb.test.tools.InjectionTestData.CONTAINER_UNDER_LIST_DATA_PATH;
import static io.fd.honeycomb.test.tools.InjectionTestData.NESTED_LIST_DATA_PATH;
import static io.fd.honeycomb.test.tools.InjectionTestData.NESTED_LIST_RESOURCE;
import static io.fd.honeycomb.test.tools.InjectionTestData.ROOT_LIST_DATA_PATH;
import static io.fd.honeycomb.test.tools.InjectionTestData.ROOT_LIST_RESOURCE;
import static io.fd.honeycomb.test.tools.InjectionTestData.SIMPLES_LIST_RESOURCE;
import static io.fd.honeycomb.test.tools.InjectionTestData.SIMPLE_LIST_DATA_PATH;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.RootList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.simple.container.SimpleList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.simple.container.augmented.container.ListInAugment;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.simple.container.simple.list.NestedList;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;

public class ListNodeDataProcessorTest extends AbstractYangDataProcessorTest {

    private ListNodeDataProcessor processor;

    @Override
    void setUp() {
        processor = new ListNodeDataProcessor(moduleInfoBackedContext.getSchemaContext(), serializer);
    }

    @Test
    public void testCanProcessPositive() {
        assertTrue(processor.canProcess(codec.deserialize(SIMPLE_LIST_DATA_PATH)));
        assertTrue(processor.canProcess(codec.deserialize(NESTED_LIST_DATA_PATH)));
    }

    @Test
    public void testCanProcessNegative() {
        assertFalse(processor.canProcess(codec.deserialize(CONTAINER_UNDER_LIST_DATA_PATH)));
        assertFalse(processor.canProcess(YangInstanceIdentifier.EMPTY));
    }

    @Test
    public void testGetNodeDataSimpleList() {
        final DataObject nodeData = processor.getNodeData(codec.deserialize(SIMPLE_LIST_DATA_PATH), SIMPLES_LIST_RESOURCE);
        assertNotNull(nodeData);
        assertEquals("nameUnderSimpleList", ((SimpleList) nodeData).getName());
    }

    @Test
    public void testGetNodeDataNestedList() {
        final DataObject nodeData = processor.getNodeData(codec.deserialize(NESTED_LIST_DATA_PATH), NESTED_LIST_RESOURCE);
        assertNotNull(nodeData);
        assertEquals("nameUnderNestedList", ((NestedList) nodeData).getNestedName());
    }

    @Test
    public void testGetNodeDataRootList() {
        final DataObject nodeData = processor.getNodeData(codec.deserialize(ROOT_LIST_DATA_PATH), ROOT_LIST_RESOURCE);
        assertNotNull(nodeData);
        assertEquals("rootName", ((RootList) nodeData).getRootName());
    }

    @Test
    public void testGetNodeDataAugmentList() {
        final DataObject nodeData = processor.getNodeData(codec.deserialize(AUGMENT_LIST_DATA_PATH), AUGMENT_LIST_RESOURCE);
        assertNotNull(nodeData);
        assertEquals("keyInAugment", ((ListInAugment) nodeData).getKeyInAugment());
    }
}