<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-test-util</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-binding2-test-model</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<!--
Preconditions.checkArgument(currentArg != null);
QName currentQName = BindingReflections.findQName(currentArg.getType());
- Optional<DataNodeContainer> currentContainer = Optional.absent();
+ Optional<DataNodeContainer> currentContainer;
if (BindingReflections.isNotification(currentArg.getType())) {
currentContainer = findNotification(ctx, currentQName);
} else if (BindingReflections.isOperationType(currentArg.getType())) {
private static Optional<DataNodeContainer> findNotification(final SchemaContext ctx, final QName notificationQName) {
for (final NotificationDefinition notification : ctx.getNotifications()) {
if (notification.getQName().equals(notificationQName)) {
- return Optional.<DataNodeContainer> of(notification);
+ return Optional.of(notification);
}
}
return Optional.absent();
final String actionOutputName =
new StringBuilder(operationName).append(BindingMapping.RPC_OUTPUT_SUFFIX).toString();
if (targetType.equals(actionInputName)) {
- return Optional.<DataNodeContainer> of(operation.getInput());
+ return Optional.of(operation.getInput());
} else if (targetType.equals(actionOutputName)) {
- return Optional.<DataNodeContainer> of(operation.getOutput());
+ return Optional.of(operation.getOutput());
}
return Optional.absent();
}
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.mdsal.binding.javav2.runtime.context;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.javav2.generator.impl.GeneratedClassLoadingStrategy;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class BindingRuntimeContextTest {
+
+ private SchemaContext schemaContext;
+ private BindingRuntimeContext brc;
+ private DataNodeContainer myCont;
+
+ @Before
+ public void setup() throws URISyntaxException, FileNotFoundException, ReactorException {
+ schemaContext = YangParserTestUtils.parseYangSources(
+ new File(getClass().getResource("/yang/test-runtime.yang").toURI()));
+ myCont = (DataNodeContainer) schemaContext.getChildNodes().iterator().next();
+ brc = BindingRuntimeContext.create(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), schemaContext);
+ }
+
+ @Test
+ public void basicTest() {
+ assertNotNull(brc.getSchemaContext());
+ assertNotNull(brc.getStrategy());
+ assertNotNull(brc.getChoiceCaseChildren(myCont));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.mdsal.binding.javav2.runtime.context;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.javav2.generator.impl.GeneratedClassLoadingStrategy;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+
+public class ModuleInfoBackedContextTest {
+
+ private ModuleInfoBackedContext moduleInfoBackedContext;
+
+ @Before
+ public void setup() throws ReactorException, FileNotFoundException, URISyntaxException {
+ moduleInfoBackedContext = ModuleInfoBackedContext.create();
+ }
+
+ @Test
+ public void createTestWithStrategy() {
+ assertNotNull(ModuleInfoBackedContext.create(
+ GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy()));
+ }
+
+ @Test(expected = ClassNotFoundException.class)
+ public void loadClassTest() throws ClassNotFoundException {
+ moduleInfoBackedContext.loadClass("org.opendaylight.mdsal.gen.javav2.test.rev990939.Dummy");
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.mdsal.binding.javav2.runtime.context.util;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.javav2.spec.base.InstanceIdentifier;
+import org.opendaylight.mdsal.gen.javav2.org.test.runtime.rev170710.data.MyCont;
+import org.opendaylight.mdsal.gen.javav2.org.test.runtime.rev170710.data.my_cont.MyChoice;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class BindingSchemaContextUtilsTest {
+
+ private SchemaContext schemaContext;
+ private DataNodeContainer myCont;
+ private ChoiceSchemaNode myChoice;
+
+ private static final InstanceIdentifier<MyCont> MY_CONT_NODE_PATH
+ = InstanceIdentifier.create(MyCont.class);
+
+
+ @Before
+ public void setup() throws URISyntaxException, FileNotFoundException, ReactorException {
+ schemaContext = YangParserTestUtils.parseYangSources(
+ new File(getClass().getResource("/yang/test-runtime.yang").toURI()));
+ myCont = (DataNodeContainer) schemaContext.getChildNodes().iterator().next();
+ myChoice = (ChoiceSchemaNode) myCont.getChildNodes().iterator().next();
+ }
+
+ @Test
+ public void utilTest() {
+ assertNotNull(BindingSchemaContextUtils.findDataNodeContainer(schemaContext, MY_CONT_NODE_PATH));
+ assertNotNull(BindingSchemaContextUtils.findInstantiatedChoice(myCont, MyChoice.class));
+ assertNotNull(BindingSchemaContextUtils.findInstantiatedCase(myChoice, myChoice.getCaseNodeByName("one")));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.mdsal.binding.javav2.runtime.javassist;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+
+import com.google.common.collect.ImmutableList;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtField;
+import javassist.bytecode.AccessFlag;
+import org.junit.Test;
+
+public class JavassistUtilsTest {
+
+ @Test
+ public void forClassPool() throws Exception {
+ final JavassistUtils javassistUtils = JavassistUtils.forClassPool(ClassPool.getDefault());
+ final ClassGenerator classGenerator = mock(ClassGenerator.class);
+ doNothing().when(classGenerator).process(any());
+ final CtClass ctInterface = javassistUtils.createClass("TestInterface", classGenerator);
+ ctInterface.setModifiers(AccessFlag.INTERFACE);
+ final CtClass ctClass = javassistUtils.createClass("TestClass", ctInterface, classGenerator);
+ javassistUtils.ensureClassLoader(ctClass.getClass());
+ assertNotNull(ctClass);
+ assertNotNull(javassistUtils.get(ClassPool.getDefault(), ctClass.getClass()));
+
+ CtField ctField = javassistUtils.field(ctClass, "testField", Object.class);
+ assertEquals(ctField, ctClass.getField("testField"));
+ ctField = javassistUtils.staticField(ctClass, "testStaticField", Object.class);
+ assertEquals(ctField, ctClass.getField("testStaticField"));
+
+ final MethodGenerator methodGenerator = mock(MethodGenerator.class);
+ doNothing().when(methodGenerator).process(any());
+ javassistUtils.method(ctClass, Void.class, "testMethod", Object.class, methodGenerator);
+ javassistUtils.method(ctInterface, Void.class, "testInterfaceMethod", Object.class, methodGenerator);
+ javassistUtils.method(ctClass, Void.class, "testMethod2", ImmutableList.of(Object.class), methodGenerator);
+ javassistUtils.staticMethod(ctClass, Void.class, "testStaticMethod", Object.class, methodGenerator);
+ javassistUtils.implementMethodsFrom(ctClass, ctInterface, methodGenerator);
+ assertNotNull(ctClass.getDeclaredMethod("testMethod"));
+ assertNotNull(ctClass.getDeclaredMethod("testMethod2"));
+ assertNotNull(ctClass.getDeclaredMethod("testStaticMethod"));
+ assertNotNull(ctClass.getDeclaredMethod("testInterfaceMethod"));
+
+ final ClassCustomizer classCustomizer = mock(ClassCustomizer.class);
+ doNothing().when(classCustomizer).customizeClass(any());
+ assertNotNull(javassistUtils.instantiatePrototype("javassist.CtNewClass", "leWut", classCustomizer));
+ }
+
+ @Test
+ public void privateConstructTest() throws Exception {
+ assertFalse(JavassistUtils.class.getDeclaredConstructor(ClassPool.class).isAccessible());
+ }
+}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import java.lang.reflect.Constructor;
-import java.util.Collections;
import java.util.List;
import java.util.concurrent.Future;
import org.junit.Test;
BindingReflections.getModelRootPackageName("org.opendaylight.mdsal.gen.javav2.test.rev990939"));
assertEquals("ModuleInfoClassName should be equal to string", "test.$YangModuleInfoImpl",
BindingReflections.getModuleInfoClassName("test"));
- assertEquals("Module info should be empty Set", Collections.EMPTY_SET, BindingReflections.loadModuleInfos());
assertFalse("Should not be RpcType", BindingReflections.isOperationType(TreeNode.class));
assertFalse("Should not be AugmentationChild", BindingReflections.isAugmentationChild(TreeNode.class));
assertTrue("Should be BindingClass", BindingReflections.isBindingClass(TreeNode.class));
.resolveOperationOutputClass(TestImplementation.class.getDeclaredMethod("rpcMethodTest2")).isPresent());
assertTrue(BindingReflections.getQName(TestImplementation.class).toString().equals("test"));
+ assertNotNull(BindingReflections.getQNameModule(TestImplementation.class));
}
@SuppressWarnings("rawtypes")
--- /dev/null
+module test-runtime {
+ namespace "org.test.runtime";
+ prefix "tst";
+ revision "2017-07-10" {
+ }
+
+ container my-cont {
+ choice my-choice {
+ case one {
+ leaf one {
+ type string;
+ }
+ }
+ case two {
+ leaf two {
+ type string;
+ }
+ }
+
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+module test-runtime {
+ namespace "org.test.runtime";
+ prefix "tst";
+ revision "2017-07-10" {
+ }
+
+ container my-cont {
+ choice my-choice {
+ case one {
+ leaf one {
+ type string;
+ }
+ }
+ case two {
+ leaf two {
+ type string;
+ }
+ }
+
+ }
+ }
+}
\ No newline at end of file