2 * Copyright (c) 2016 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.yangtools.yang.binding;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
16 import java.lang.reflect.Constructor;
17 import java.lang.reflect.InvocationTargetException;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.common.QNameModule;
22 import org.opendaylight.yangtools.yang.common.Revision;
24 public class BindingMappingTest {
27 public void basicTest() {
28 assertTrue(BindingMapping.getRootPackageName(QName.create(QNameModule.create(URI.create("test:URI"),
29 Revision.of("2017-10-26")), "test")).contains("test.uri"));
30 assertNull(BindingMapping.normalizePackageName(null));
31 assertTrue(BindingMapping.normalizePackageName("1testpublic").contains("_1testpublic"));
32 assertTrue(BindingMapping.getMethodName(QName.create("testNS", "testLocalName")).equals("testLocalName"));
33 assertTrue(BindingMapping.getMethodName("TestYangIdentifier").equals("testYangIdentifier"));
34 assertTrue(BindingMapping.getClassName(QName.create("testNS", "testClass")).equals("TestClass"));
35 assertTrue(BindingMapping.getClassName("testClass").equals("TestClass"));
36 assertTrue(BindingMapping.getGetterSuffix(QName.create("test", "test")).equals("Test"));
37 assertTrue(BindingMapping.getGetterSuffix(QName.create("test", "class")).equals("XmlClass"));
38 assertTrue(BindingMapping.getPropertyName("Test").equals("test"));
39 assertTrue(BindingMapping.getPropertyName("test").equals("test"));
40 assertTrue(BindingMapping.getPropertyName("Class").equals("xmlClass"));
41 assertEquals("_5", BindingMapping.getPropertyName("5"));
42 assertEquals("", BindingMapping.getPropertyName(""));
43 assertEquals("", BindingMapping.getClassName(""));
46 @Test(expected = UnsupportedOperationException.class)
47 @SuppressWarnings({ "checkstyle:illegalThrows", "checkstyle:avoidHidingCauseException" })
48 public void privateConstructTest() throws Throwable {
49 final Constructor<BindingMapping> bindingMappingConstructor = BindingMapping.class.getDeclaredConstructor();
50 assertFalse(bindingMappingConstructor.isAccessible());
52 bindingMappingConstructor.setAccessible(true);
54 bindingMappingConstructor.newInstance();
55 fail("Expected exception for calling private constructor");
56 } catch (InvocationTargetException e) {