816e118f3944f4fb29e63a8b8dbd697cdf260d7e
[controller.git] / opendaylight / netconf / config-netconf-connector / src / test / java / org / opendaylight / controller / netconf / confignetconfconnector / operations / runtimerpc / RuntimeRpcElementResolvedTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.netconf.confignetconfconnector.operations.runtimerpc;
10
11 import static org.junit.Assert.assertEquals;
12
13 import java.util.Arrays;
14 import java.util.Collection;
15 import java.util.Collections;
16 import java.util.HashMap;
17 import java.util.Map;
18
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.junit.runners.Parameterized;
22
23 @RunWith(Parameterized.class)
24 public class RuntimeRpcElementResolvedTest {
25
26     private static final String MODULE_TYPE = "moduleType";
27     private static final String INSTANCE_NAME = "instanceName";
28     @Parameterized.Parameter(0)
29     public String xpath;
30     @Parameterized.Parameter(1)
31     public Map<String, String> additional;
32
33     @Parameterized.Parameters(name = "{index}: parsed({0}) contains moduleName:{1} and instanceName:{2}")
34     public static Collection<Object[]> data() {
35         return Arrays.asList(new Object[][] {
36                 // With namespaces
37                 { "/a:modules/a:module[a:name='instanceName'][a:type='moduleType']/b:listener-state[b:peer-id='127.0.0.1']",
38                         new HashMap<String, String>() {{
39                             put("listener-state", "127.0.0.1");
40                         }}},
41                 { "/a:modules/a:module[a:name='instanceName'][a:type='moduleType']",
42                         null},
43
44                 // Without namespaces
45                 { "/modules/module[name=instanceName][type=moduleType]", null},
46                 { "/modules/module[type=moduleType][name='instanceName']", null},
47                 { "/modules/module[name=\'instanceName\'][type=\"moduleType\"]", null},
48                 { "/modules/module[type=moduleType and name=instanceName]", null},
49                 { "/modules/module[name=\"instanceName\" and type=moduleType]", null},
50                 { "/modules/module[type=\"moduleType\" and name=instanceName]", null},
51                 { "/modules/module[name=\'instanceName\' and type=\"moduleType\"]", null},
52
53                 // With inner beans
54                 { "/modules/module[name=instanceName and type=\"moduleType\"]/inner[key=b]", Collections.singletonMap("inner", "b")},
55                 { "/modules/module[name=instanceName and type=moduleType]/inner[key=b]", Collections.singletonMap("inner", "b")},
56                 { "/modules/module[name=instanceName and type=moduleType]/inner[key=\'b\']", Collections.singletonMap("inner", "b")},
57                 { "/modules/module[name=instanceName and type=moduleType]/inner[key=\"b\"]", Collections.singletonMap("inner", "b")},
58
59                 { "/modules/module[name=instanceName and type=\"moduleType\"]/inner[key2=a]/inner2[key=b]",
60                         new HashMap<String, String>() {{
61                             put("inner", "a");
62                             put("inner2", "b");
63                         }}
64                 },
65         });
66     }
67
68     @Test
69     public void testFromXpath() throws Exception {
70         final RuntimeRpcElementResolved resolved = RuntimeRpcElementResolved.fromXpath(xpath, "element", "namespace");
71         assertEquals(MODULE_TYPE, resolved.getModuleName());
72         assertEquals(INSTANCE_NAME, resolved.getInstanceName());
73         if (additional != null) {
74             assertEquals(additional, resolved.getAdditionalAttributes());
75         }
76     }
77 }