--- /dev/null
+/*
+ * Copyright (c) 2016 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.mdsal.binding.dom.adapter;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.api.DataTreeCommitCohort;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeCandidate;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
+import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
+import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
+
+public class BindingDOMDataTreeCommitCohortAdapterTest {
+
+ @Test
+ public void canCommitTest() throws Exception {
+ final DataTreeCommitCohort<?> cohort = mock(DataTreeCommitCohort.class);
+ final BindingNormalizedNodeCodecRegistry registry = mock(BindingNormalizedNodeCodecRegistry.class);
+ final BindingToNormalizedNodeCodec codec =
+ new BindingToNormalizedNodeCodec(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), registry);
+
+ final BindingDOMDataTreeCommitCohortAdapter adapter =
+ new BindingDOMDataTreeCommitCohortAdapter<>(codec, cohort);
+ assertNotNull(adapter);
+
+ final DOMDataTreeCandidate domDataTreeCandidate = mock(DOMDataTreeCandidate.class);
+ final DOMDataTreeIdentifier domDataTreeIdentifier =
+ new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
+ doReturn(InstanceIdentifier.create(DataObject.class)).when(registry).fromYangInstanceIdentifier(any());
+ final BindingCodecTree bindingCodecTree = mock(BindingCodecTree.class);
+ final BindingCodecTreeNode bindingCodecTreeNode = mock(BindingCodecTreeNode.class);
+ doReturn(bindingCodecTreeNode).when(bindingCodecTree).getSubtreeCodec(any(InstanceIdentifier.class));
+ doReturn(bindingCodecTree).when(registry).getCodecContext();
+ doReturn(domDataTreeIdentifier).when(domDataTreeCandidate).getRootPath();
+ doReturn(mock(DataTreeCandidateNode.class)).when(domDataTreeCandidate).getRootNode();
+ assertNotNull(LazyDataTreeModification.create(codec, domDataTreeCandidate));
+
+ doReturn(null).when(cohort).canCommit(any(), any());
+ adapter.canCommit(new Object(), domDataTreeCandidate, null);
+ verify(cohort).canCommit(any(), any());
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 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.mdsal.binding.dom.adapter;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+import com.google.common.base.Optional;
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.api.MountPointService.MountPointListener;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
+import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+
+public class BindingDOMMountPointServiceAdapterTest {
+
+ @Test
+ public void basicTest() throws Exception {
+ final BindingNormalizedNodeCodecRegistry registry = mock(BindingNormalizedNodeCodecRegistry.class);
+ final BindingToNormalizedNodeCodec codec =
+ new BindingToNormalizedNodeCodec(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), registry);
+ doReturn(YangInstanceIdentifier.EMPTY).when(registry).toYangInstanceIdentifier(any());
+ final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
+
+ final BindingDOMMountPointServiceAdapter adapter =
+ new BindingDOMMountPointServiceAdapter(mountPointService, codec);
+
+ doReturn(Optional.absent()).when(mountPointService).getMountPoint(any());
+ assertFalse(adapter.getMountPoint(InstanceIdentifier.create(DataObject.class)).isPresent());
+
+ doReturn(Optional.of(mock(DOMMountPoint.class))).when(mountPointService).getMountPoint(any());
+ assertTrue(adapter.getMountPoint(InstanceIdentifier.create(DataObject.class)).isPresent());
+
+ assertNotNull(adapter.registerListener(InstanceIdentifier.create(DataObject.class),
+ mock(MountPointListener.class)));
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 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.mdsal.binding.dom.adapter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
+import java.lang.reflect.Method;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class DirectGetterRouteContextExtractorTest {
+
+ private static final InstanceIdentifier INSTANCE_IDENTIFIER = InstanceIdentifier.create(DataObject.class);
+ private static final String EXCEPTION_TEXT = "testException";
+
+ @Test
+ public void basicTest() throws Exception {
+ final Method testMthd = this.getClass().getDeclaredMethod("testMethod", DataObject.class);
+ testMthd.setAccessible(true);
+ final ContextReferenceExtractor referenceExtractor = DirectGetterRouteContextExtractor.create(testMthd);
+ assertEquals(testMethod(mock(DataObject.class)), referenceExtractor.extract(mock(DataObject.class)));
+
+ try {
+ referenceExtractor.extract(null);
+ fail("Expected exception");
+ } catch (NullPointerException e) {
+ assertTrue(e.getMessage().equals(EXCEPTION_TEXT));
+ }
+ }
+
+ private static InstanceIdentifier testMethod(DataObject data) {
+ if (data == null) {
+ throw new NullPointerException(EXCEPTION_TEXT);
+ }
+ return INSTANCE_IDENTIFIER;
+ }
+}
\ No newline at end of file