2 * Copyright (c) 2014 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.sal.binding.test.connect.dom;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
13 import com.google.common.base.Optional;
14 import com.google.common.util.concurrent.CheckedFuture;
15 import com.google.common.util.concurrent.Futures;
16 import com.google.common.util.concurrent.ListenableFuture;
17 import com.google.common.util.concurrent.MoreExecutors;
18 import java.util.Collections;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
23 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
24 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
25 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
26 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
27 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
28 import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
29 import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener;
30 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
31 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
32 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
33 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
34 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
35 import org.opendaylight.controller.sal.binding.api.mount.MountProviderInstance;
36 import org.opendaylight.controller.sal.binding.api.mount.MountProviderService;
37 import org.opendaylight.controller.sal.binding.test.util.BindingBrokerTestFactory;
38 import org.opendaylight.controller.sal.binding.test.util.BindingTestContext;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.List11SimpleAugment;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.TllComplexAugment;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1Key;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11Key;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.top.top.level.list.list1.list1._1.Cont;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
49 import org.opendaylight.yangtools.concepts.ListenerRegistration;
50 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
51 import org.opendaylight.yangtools.yang.common.QName;
52 import org.opendaylight.yangtools.yang.common.RpcResult;
53 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
54 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
55 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
56 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
57 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
58 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
60 public class CrossBrokerMountPointTest {
62 private static final QName TLL_NAME_QNAME = QName.create(TopLevelList.QNAME, "name");
63 private static final String TLL_NAME = "foo:1";
65 private static final TopLevelListKey TLL_KEY = new TopLevelListKey(TLL_NAME);
67 private static final Map<QName, Object> TLL_KEY_BI = Collections.<QName, Object> singletonMap(TLL_NAME_QNAME,
70 private static final InstanceIdentifier<TopLevelList> TLL_INSTANCE_ID_BA = InstanceIdentifier.builder(Top.class) //
71 .child(TopLevelList.class, TLL_KEY).build();
73 private static final List1Key LIST1_KEY = new List1Key("foo");
74 private static final List11Key LIST11_KEY = new List11Key(1);
76 private static final InstanceIdentifier<Cont> AUG_CONT_ID_BA = TLL_INSTANCE_ID_BA
77 .builder().augmentation(TllComplexAugment.class) //
78 .child(List1.class, LIST1_KEY) //
79 .child(List11.class, LIST11_KEY) //
80 .augmentation(List11SimpleAugment.class) //
84 private static final QName AUG_CONT = QName.create(List11.QNAME,
85 Cont.QNAME.getLocalName());
87 private static final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier TLL_INSTANCE_ID_BI = //
88 org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.builder() //
90 .node(TopLevelList.QNAME) //
91 .nodeWithKey(TopLevelList.QNAME, TLL_KEY_BI) //
94 private static final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier GROUP_STATISTICS_ID_BI = org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier
96 .builder(TLL_INSTANCE_ID_BI)
97 .nodeWithKey(QName.create(TllComplexAugment.QNAME, "list1"), QName.create(TllComplexAugment.QNAME, "attr-str"),
98 LIST1_KEY.getAttrStr())
99 .nodeWithKey(QName.create(TllComplexAugment.QNAME, "list1-1"), QName.create(TllComplexAugment.QNAME, "attr-int"),
100 LIST11_KEY.getAttrInt())
101 .node(AUG_CONT).build();
103 private BindingTestContext testContext;
104 private MountProviderService bindingMountPointService;
105 private DOMMountPointService domMountPointService;
108 public void setup() {
109 final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
110 testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
111 testFactory.setStartWithParsedSchema(true);
112 testContext = testFactory.getTestContext();
115 bindingMountPointService = testContext.getBindingMountProviderService();
116 domMountPointService = testContext.getDomMountProviderService();
118 // biRpcInvoker = testContext.getDomRpcInvoker();
119 assertNotNull(bindingMountPointService);
120 assertNotNull(domMountPointService);
122 // flowService = MessageCapturingFlowService.create(baRpcRegistry);
126 public void testMountPoint() {
127 final Integer attrIntValue = 500;
128 domMountPointService.createMountPoint(TLL_INSTANCE_ID_BI)
129 .addService(DOMDataBroker.class, new DOMDataBroker() {
132 public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store,
133 final YangInstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) {
134 throw new UnsupportedOperationException();
138 public DOMDataWriteTransaction newWriteOnlyTransaction() {
139 throw new UnsupportedOperationException();
143 public DOMDataReadWriteTransaction newReadWriteTransaction() {
144 return new DOMDataReadWriteTransaction() {
147 public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
148 final LogicalDatastoreType store, final YangInstanceIdentifier path) {
149 if(store == LogicalDatastoreType.OPERATIONAL && path.getLastPathArgument().equals(GROUP_STATISTICS_ID_BI.getLastPathArgument())) {
151 final ContainerNode data = Builders.containerBuilder()
152 .withNodeIdentifier(new NodeIdentifier(AUG_CONT))
153 .withChild(ImmutableNodes.leafNode(QName.create(AUG_CONT, "attr-int"), attrIntValue))
156 return Futures.immediateCheckedFuture(Optional.<NormalizedNode<?,?>>of(data));
158 return Futures.immediateFailedCheckedFuture(new ReadFailedException(TLL_NAME, new Exception()));
162 public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
163 final YangInstanceIdentifier path) {
164 throw new UnsupportedOperationException();
168 public Object getIdentifier() {
173 public boolean cancel() {
178 public ListenableFuture<RpcResult<TransactionStatus>> commit() {
183 public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
184 throw new UnsupportedOperationException();
188 public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
189 final NormalizedNode<?, ?> data) {
190 throw new UnsupportedOperationException();
194 public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
195 final NormalizedNode<?, ?> data) {
196 throw new UnsupportedOperationException();
200 public CheckedFuture<Void, TransactionCommitFailedException> submit() {
201 throw new UnsupportedOperationException();
208 public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
209 throw new UnsupportedOperationException();
213 public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
214 throw new UnsupportedOperationException();
218 public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
219 return Collections.emptyMap();
225 final MountProviderInstance bindingMountPoint = bindingMountPointService.getMountPoint(TLL_INSTANCE_ID_BA);
226 assertNotNull(bindingMountPoint);
228 final Cont data = (Cont) bindingMountPoint.readOperationalData(AUG_CONT_ID_BA);
230 assertEquals(attrIntValue ,data.getAttrInt());