X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fmessagebus-util%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmessagebus%2Fapp%2Futil%2FUtilTest.java;fp=opendaylight%2Fmd-sal%2Fmessagebus-util%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmessagebus%2Fapp%2Futil%2FUtilTest.java;h=05425f01ad3d30f8e01a26cbe823f6245cfcdc9c;hp=0000000000000000000000000000000000000000;hb=277612ebea9b441977cdb8460b2e76090df6f9e8;hpb=23fe9ca678ada6263fec5dd996f4025e4a32fcf5 diff --git a/opendaylight/md-sal/messagebus-util/src/test/java/org/opendaylight/controller/messagebus/app/util/UtilTest.java b/opendaylight/md-sal/messagebus-util/src/test/java/org/opendaylight/controller/messagebus/app/util/UtilTest.java new file mode 100644 index 0000000000..05425f01ad --- /dev/null +++ b/opendaylight/md-sal/messagebus-util/src/test/java/org/opendaylight/controller/messagebus/app/util/UtilTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.messagebus.app.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +import org.junit.Test; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; +/** + * @author ppalmar + * + */ +public class UtilTest { + + @Test + public void testResultFor() throws Exception { + { + final String expectedResult = "dummy string"; + RpcResult rpcResult = Util.resultRpcSuccessFor(expectedResult).get(); + assertEquals(expectedResult, rpcResult.getResult()); + assertTrue(rpcResult.isSuccessful()); + assertTrue(rpcResult.getErrors().isEmpty()); + } + { + final Integer expectedResult = 42; + RpcResult rpcResult = Util.resultRpcSuccessFor(expectedResult).get(); + assertEquals(expectedResult, rpcResult.getResult()); + assertTrue(rpcResult.isSuccessful()); + assertTrue(rpcResult.getErrors().isEmpty()); + } + } + + @Test + public void testExpandQname() throws Exception { + // match no path because the list of the allowed paths is empty + { + final List paths = new ArrayList<>(); + final Pattern regexPattern = Pattern.compile(".*"); // match everything + final List matchingPaths = Util.expandQname(paths, regexPattern); + assertTrue(matchingPaths.isEmpty()); + } + + // match no path because of regex pattern + { + final List paths = createSchemaPathList(); + final Pattern regexPattern = Pattern.compile("^@.*"); + final List matchingPaths = Util.expandQname(paths, regexPattern); + assertTrue(matchingPaths.isEmpty()); + } + + // match all paths + { + final List paths = createSchemaPathList(); + final Pattern regexPattern = Pattern.compile(".*"); + final List matchingPaths = Util.expandQname(paths, regexPattern); + assertTrue(matchingPaths.contains(paths.get(0))); + assertTrue(matchingPaths.contains(paths.get(1))); + assertEquals(paths.size(), matchingPaths.size()); + } + + // match one path only + { + final List paths = createSchemaPathList(); + final Pattern regexPattern = Pattern.compile(".*yyy$"); + final List matchingPaths = Util.expandQname(paths, regexPattern); + assertTrue(matchingPaths.contains(paths.get(1))); + assertEquals(1, matchingPaths.size()); + } + } + + private static List createSchemaPathList() { + final QName qname1 = QName.create("urn:odl:xxx", "2015-01-01", "localName"); + final QName qname2 = QName.create("urn:odl:yyy", "2015-01-01", "localName"); + final SchemaPath path1 = SchemaPath.create(true, qname1); + final SchemaPath path2 = SchemaPath.create(true, qname2); + return Arrays.asList(path1, path2); + } +}