Remove DOMDataTreeProducer-related classes
[controller.git] / opendaylight / md-sal / messagebus-util / src / test / java / org / opendaylight / controller / messagebus / app / util / UtilTest.java
1 /*
2  * Copyright (c) 2015 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 package org.opendaylight.controller.messagebus.app.util;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12
13 import java.util.ArrayList;
14 import java.util.Arrays;
15 import java.util.List;
16 import java.util.regex.Pattern;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21
22 /**
23  * Unit tests for Util.
24  *
25  * @author ppalmar
26  */
27 @Deprecated(forRemoval = true)
28 public class UtilTest {
29
30     @Test
31     public void testResultFor() throws Exception {
32         {
33             final String expectedResult = "dummy string";
34             RpcResult<String> rpcResult = Util.resultRpcSuccessFor(expectedResult).get();
35             assertEquals(expectedResult, rpcResult.getResult());
36             assertTrue(rpcResult.isSuccessful());
37             assertTrue(rpcResult.getErrors().isEmpty());
38         }
39         {
40             final Integer expectedResult = 42;
41             RpcResult<Integer> rpcResult = Util.resultRpcSuccessFor(expectedResult).get();
42             assertEquals(expectedResult, rpcResult.getResult());
43             assertTrue(rpcResult.isSuccessful());
44             assertTrue(rpcResult.getErrors().isEmpty());
45         }
46     }
47
48     @Test
49     public void testExpandQname() {
50         // match no path because the list of the allowed paths is empty
51         {
52             final List<SchemaPath> paths = new ArrayList<>();
53             final Pattern regexPattern = Pattern.compile(".*"); // match everything
54             final List<SchemaPath> matchingPaths = Util.expandQname(paths, regexPattern);
55             assertTrue(matchingPaths.isEmpty());
56         }
57
58         // match no path because of regex pattern
59         {
60             final List<SchemaPath> paths = createSchemaPathList();
61             final Pattern regexPattern = Pattern.compile("^@.*");
62             final List<SchemaPath> matchingPaths = Util.expandQname(paths, regexPattern);
63             assertTrue(matchingPaths.isEmpty());
64         }
65
66         // match all paths
67         {
68             final List<SchemaPath> paths = createSchemaPathList();
69             final Pattern regexPattern = Pattern.compile(".*");
70             final List<SchemaPath> matchingPaths = Util.expandQname(paths, regexPattern);
71             assertTrue(matchingPaths.contains(paths.get(0)));
72             assertTrue(matchingPaths.contains(paths.get(1)));
73             assertEquals(paths.size(), matchingPaths.size());
74         }
75
76         // match one path only
77         {
78             final List<SchemaPath> paths = createSchemaPathList();
79             final Pattern regexPattern = Pattern.compile(".*yyy$");
80             final List<SchemaPath> matchingPaths = Util.expandQname(paths, regexPattern);
81             assertTrue(matchingPaths.contains(paths.get(1)));
82             assertEquals(1, matchingPaths.size());
83         }
84     }
85
86     private static List<SchemaPath> createSchemaPathList() {
87         final QName qname1 = QName.create("urn:odl:xxx", "2015-01-01", "localName");
88         final QName qname2 = QName.create("urn:odl:yyy", "2015-01-01", "localName");
89         final SchemaPath path1 = SchemaPath.create(true, qname1);
90         final SchemaPath path2 = SchemaPath.create(true, qname2);
91         return Arrays.asList(path1, path2);
92     }
93 }