Binding v2 runtime - adapters - abstract data broker test
[mdsal.git] / binding2 / mdsal-binding2-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / javav2 / dom / adapter / test / AbstractDataBrokerTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.mdsal.binding.javav2.dom.adapter.test;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.concurrent.ExecutionException;
13 import java.util.concurrent.TimeUnit;
14 import java.util.concurrent.TimeoutException;
15 import org.opendaylight.mdsal.binding.javav2.api.DataBroker;
16 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18
19 @Beta
20 public class AbstractDataBrokerTest extends AbstractSchemaAwareTest {
21
22     private DataBrokerTestCustomizer testCustomizer;
23     private DataBroker dataBroker;
24     private DOMDataBroker domBroker;
25
26     @Override
27     protected void setupWithSchema(final SchemaContext context) {
28         testCustomizer = createDataBrokerTestCustomizer();
29         dataBroker = testCustomizer.createDataBroker();
30         domBroker = testCustomizer.createDOMDataBroker();
31         testCustomizer.updateSchema(context);
32         setupWithDataBroker(dataBroker);
33     }
34
35     protected void setupWithDataBroker(final DataBroker dataBroker) {
36         // Intentionally left No-op, subclasses may customize it
37     }
38
39     protected DataBrokerTestCustomizer createDataBrokerTestCustomizer() {
40         return new DataBrokerTestCustomizer();
41     }
42
43     public DataBroker getDataBroker() {
44         return dataBroker;
45     }
46
47     public DOMDataBroker getDomBroker() {
48         return domBroker;
49     }
50
51     protected static final void assertCommit(final ListenableFuture<Void> commit) {
52         try {
53             commit.get(500, TimeUnit.MILLISECONDS);
54         } catch (InterruptedException | ExecutionException | TimeoutException e) {
55             throw new IllegalStateException(e);
56         }
57     }
58 }