Merge "BUG 1330 - list key counts|values diff in payload and URI"
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / test / AbstractDataBrokerTest.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.md.sal.binding.test;
9
10 import static org.junit.Assert.assertEquals;
11
12 import java.util.concurrent.ExecutionException;
13 import java.util.concurrent.TimeUnit;
14 import java.util.concurrent.TimeoutException;
15
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21
22 import com.google.common.util.concurrent.ListenableFuture;
23
24 public class AbstractDataBrokerTest extends AbstractSchemaAwareTest {
25
26     private DataBrokerTestCustomizer testCustomizer;
27     private DataBroker dataBroker;
28     private DOMDataBroker domBroker;
29
30
31     @Override
32     protected void setupWithSchema(final SchemaContext context) {
33         testCustomizer = createDataBrokerTestCustomizer();
34         dataBroker = testCustomizer.createDataBroker();
35         domBroker = testCustomizer.createDOMDataBroker();
36         testCustomizer.updateSchema(context);
37         setupWithDataBroker(dataBroker);
38     }
39
40     protected void setupWithDataBroker(final DataBroker dataBroker) {
41         // Intentionally left No-op, subclasses may customize it
42     }
43
44    protected DataBrokerTestCustomizer createDataBrokerTestCustomizer() {
45         return new DataBrokerTestCustomizer();
46     }
47
48     public DataBroker getDataBroker() {
49         return dataBroker;
50     }
51
52     public DOMDataBroker getDomBroker() {
53         return domBroker;
54     }
55
56     protected static final void assertCommit(final ListenableFuture<RpcResult<TransactionStatus>> commit) {
57         try {
58             assertEquals(TransactionStatus.COMMITED,commit.get(500, TimeUnit.MILLISECONDS).getResult());
59         } catch (InterruptedException | ExecutionException | TimeoutException e) {
60             throw new IllegalStateException(e);
61         }
62     }
63
64
65 }