Merge "Removing { } from NormalizedNodeJsonBodyWriter"
[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.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TopBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
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<Top> TOP_INSTANCE_ID_BA = InstanceIdentifier.builder(Top.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         mappingService = testContext.getBindingToDomMappingService();
58     };
59
60     @Test
61     public void testSchemaContextNotAvailable() throws Exception {
62
63         ExecutorService testExecutor = Executors.newFixedThreadPool(1);
64         testContext.loadYangSchemaFromClasspath();
65         Future<Future<RpcResult<TransactionStatus>>> future = testExecutor
66                 .submit(new Callable<Future<RpcResult<TransactionStatus>>>() {
67                     @Override
68                     public Future<RpcResult<TransactionStatus>> call() throws Exception {
69                         TopBuilder topBuilder = new TopBuilder();
70                         topBuilder.setTopLevelList(Collections.<TopLevelList> emptyList());
71                         DataModificationTransaction transaction = baDataService.beginTransaction();
72                         transaction.putOperationalData(TOP_INSTANCE_ID_BA, topBuilder.build());
73                         return transaction.commit();
74                     }
75                 });
76
77         RpcResult<TransactionStatus> result = future.get().get();
78         assertEquals(TransactionStatus.COMMITED, result.getResult());
79
80         Top top = checkForTop();
81         assertNotNull(top);
82
83     }
84
85     private Top checkForTop() {
86         return (Top) baDataService.readOperationalData(TOP_INSTANCE_ID_BA);
87
88     }
89
90     @Override
91     protected boolean getStartWithSchema() {
92         return false;
93     }
94
95 }