Merge "Exclude protocol buffer generated source from Sonar renamed package to exclude...
[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.concurrent.Callable;
15 import java.util.concurrent.ExecutorService;
16 import java.util.concurrent.Executors;
17 import java.util.concurrent.Future;
18
19 import org.junit.Test;
20 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
21 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
22 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
23 import org.opendaylight.controller.sal.binding.test.util.BindingBrokerTestFactory;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.opendaylight.yangtools.yang.common.RpcResult;
29
30 import com.google.common.util.concurrent.ListeningExecutorService;
31 import com.google.common.util.concurrent.MoreExecutors;
32
33 @SuppressWarnings("deprecation")
34 public class DOMCodecBug02Test extends AbstractDataServiceTest {
35
36     private static final InstanceIdentifier<Nodes> NODES_INSTANCE_ID_BA = InstanceIdentifier.builder(Nodes.class) //
37             .toInstance();
38
39     /**
40      * This test is ignored, till found out better way to test generation of
41      * classes without leaking of instances from previous run
42      *
43      * @throws Exception
44      */
45
46     @Override
47     public void setUp() {
48         ListeningExecutorService executor = MoreExecutors.sameThreadExecutor();
49         BindingBrokerTestFactory factory = new BindingBrokerTestFactory();
50         factory.setExecutor(executor);
51         factory.setStartWithParsedSchema(getStartWithSchema());
52         testContext = factory.getTestContext();
53         testContext.start();
54
55         baDataService = testContext.getBindingDataBroker();
56         biDataService = testContext.getDomDataBroker();
57         dataStore = testContext.getDomDataStore();
58         mappingService = testContext.getBindingToDomMappingService();
59     };
60
61     @Test
62     public void testSchemaContextNotAvailable() throws Exception {
63
64         ExecutorService testExecutor = Executors.newFixedThreadPool(1);
65         testContext.loadYangSchemaFromClasspath();
66         Future<Future<RpcResult<TransactionStatus>>> future = testExecutor
67                 .submit(new Callable<Future<RpcResult<TransactionStatus>>>() {
68                     @Override
69                     public Future<RpcResult<TransactionStatus>> call() throws Exception {
70                         NodesBuilder nodesBuilder = new NodesBuilder();
71                         nodesBuilder.setNode(Collections.<Node> emptyList());
72                         DataModificationTransaction transaction = baDataService.beginTransaction();
73                         transaction.putOperationalData(NODES_INSTANCE_ID_BA, nodesBuilder.build());
74                         return transaction.commit();
75                     }
76                 });
77
78         RpcResult<TransactionStatus> result = future.get().get();
79         assertEquals(TransactionStatus.COMMITED, result.getResult());
80
81         Nodes nodes = checkForNodes();
82         assertNotNull(nodes);
83
84     }
85
86     private Nodes checkForNodes() {
87         return (Nodes) baDataService.readOperationalData(NODES_INSTANCE_ID_BA);
88
89     }
90
91     @Override
92     protected boolean getStartWithSchema() {
93         return false;
94     }
95
96 }