6784c0cc919ae1f637a1b7c14e0addebcfc3400e
[controller.git] / opendaylight / md-sal / sal-binding-dom-it / src / test / java / org / opendaylight / controller / sal / binding / test / bugfix / DOMCodecBug02Test.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.binding.test.bugfix;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import java.util.Collections;
14 import java.util.Map;
15 import java.util.concurrent.Callable;
16 import java.util.concurrent.ExecutorService;
17 import java.util.concurrent.Executors;
18 import java.util.concurrent.Future;
19
20 import javassist.ClassPool;
21
22 import org.junit.Test;
23 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
24 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
25 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
26 import org.opendaylight.controller.sal.binding.test.util.BindingBrokerTestFactory;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.opendaylight.yangtools.yang.common.QName;
35 import org.opendaylight.yangtools.yang.common.RpcResult;
36
37 import com.google.common.util.concurrent.ListeningExecutorService;
38 import com.google.common.util.concurrent.MoreExecutors;
39
40 public class DOMCodecBug02Test extends AbstractDataServiceTest {
41
42     private static final QName NODE_ID_QNAME = QName.create(Node.QNAME, "id");
43     private static final String NODE_ID = "node:1";
44
45     private static final NodeKey NODE_KEY = new NodeKey(new NodeId(NODE_ID));
46
47     private static final Map<QName, Object> NODE_KEY_BI = Collections.<QName, Object> singletonMap(NODE_ID_QNAME,
48             NODE_ID);
49
50     private static final InstanceIdentifier<Nodes> NODES_INSTANCE_ID_BA = InstanceIdentifier.builder(Nodes.class) //
51             .toInstance();
52
53     private static final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier NODES_INSTANCE_ID_BI = //
54     org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.builder() //
55             .node(Nodes.QNAME) //
56             .toInstance();
57
58     private static final InstanceIdentifier<Node> NODE_INSTANCE_ID_BA = InstanceIdentifier.builder(Nodes.class) //
59             .child(Node.class, NODE_KEY).toInstance();
60
61     private static final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier NODE_INSTANCE_ID_BI = //
62     org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.builder() //
63             .node(Nodes.QNAME) //
64             .nodeWithKey(Node.QNAME, NODE_KEY_BI) //
65             .toInstance();
66     private static final NodeRef NODE_REF = new NodeRef(NODE_INSTANCE_ID_BA);
67
68     /**
69      * This test is ignored, till found out better way to test generation of
70      * classes without leaking of instances from previous run
71      *
72      * @throws Exception
73      */
74
75     @Override
76     public void setUp() {
77         ListeningExecutorService executor = MoreExecutors.sameThreadExecutor();
78         BindingBrokerTestFactory factory = new BindingBrokerTestFactory();
79         factory.setExecutor(executor);
80         factory.setClassPool(new ClassPool());
81         factory.setStartWithParsedSchema(getStartWithSchema());
82         testContext = factory.getTestContext();
83         testContext.start();
84
85         baDataService = testContext.getBindingDataBroker();
86         biDataService = testContext.getDomDataBroker();
87         dataStore = testContext.getDomDataStore();
88         mappingService = testContext.getBindingToDomMappingService();
89     };
90
91     @Test
92     public void testSchemaContextNotAvailable() throws Exception {
93
94         ExecutorService testExecutor = Executors.newFixedThreadPool(1);
95         testContext.loadYangSchemaFromClasspath();
96         Future<Future<RpcResult<TransactionStatus>>> future = testExecutor
97                 .submit(new Callable<Future<RpcResult<TransactionStatus>>>() {
98                     @Override
99                     public Future<RpcResult<TransactionStatus>> call() throws Exception {
100                         NodesBuilder nodesBuilder = new NodesBuilder();
101                         nodesBuilder.setNode(Collections.<Node> emptyList());
102                         DataModificationTransaction transaction = baDataService.beginTransaction();
103                         transaction.putOperationalData(NODES_INSTANCE_ID_BA, nodesBuilder.build());
104                         return transaction.commit();
105                     }
106                 });
107
108         RpcResult<TransactionStatus> result = future.get().get();
109         assertEquals(TransactionStatus.COMMITED, result.getResult());
110
111         Nodes nodes = checkForNodes();
112         assertNotNull(nodes);
113
114     }
115
116     private Nodes checkForNodes() {
117         return (Nodes) baDataService.readOperationalData(NODES_INSTANCE_ID_BA);
118
119     }
120
121     @Override
122     protected boolean getStartWithSchema() {
123         return false;
124     }
125
126 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.