2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.messagebus.app.util;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
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;
23 * Unit tests for Util.
27 @Deprecated(forRemoval = true)
28 public class UtilTest {
31 public void testResultFor() throws Exception {
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());
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());
49 public void testExpandQname() {
50 // match no path because the list of the allowed paths is empty
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());
58 // match no path because of regex pattern
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());
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());
76 // match one path only
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());
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);