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