Make AbstractDataBrokerTestCustomizer#getDomBroker public
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / test / AbstractBaseDataBrokerTest.java
1 /*
2  * Copyright (c) 2017 Red Hat, 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 com.google.common.util.concurrent.ListenableFuture;
11 import java.util.concurrent.ExecutionException;
12 import java.util.concurrent.TimeUnit;
13 import java.util.concurrent.TimeoutException;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17
18 public abstract class AbstractBaseDataBrokerTest extends AbstractSchemaAwareTest {
19
20     private static final int ASSERT_COMMIT_DEFAULT_TIMEOUT = 5000;
21
22     private AbstractDataBrokerTestCustomizer testCustomizer;
23     private DataBroker dataBroker;
24     private DOMDataBroker domBroker;
25
26     protected abstract AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer();
27
28     public AbstractDataBrokerTestCustomizer getDataBrokerTestCustomizer() {
29         if (testCustomizer == null) {
30             throw new IllegalStateException("testCustomizer not yet set by call to createDataBrokerTestCustomizer()");
31         }
32         return testCustomizer;
33     }
34
35     @Override
36     protected void setupWithSchema(final SchemaContext context) {
37         testCustomizer = createDataBrokerTestCustomizer();
38         dataBroker = testCustomizer.createDataBroker();
39         domBroker = testCustomizer.getDOMDataBroker();
40         testCustomizer.updateSchema(context);
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         assertCommit(commit, ASSERT_COMMIT_DEFAULT_TIMEOUT);
53     }
54
55     protected static final void assertCommit(final ListenableFuture<Void> commit, long timeoutInMS) {
56         try {
57             commit.get(timeoutInMS, TimeUnit.MILLISECONDS);
58         } catch (InterruptedException | ExecutionException | TimeoutException e) {
59             throw new IllegalStateException(e);
60         }
61     }
62 }