Migrate OSGI compendium reference
[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 @Deprecated
19 public abstract class AbstractBaseDataBrokerTest extends AbstractSchemaAwareTest {
20
21     private static final int ASSERT_COMMIT_DEFAULT_TIMEOUT = 5000;
22
23     private AbstractDataBrokerTestCustomizer testCustomizer;
24     private DataBroker dataBroker;
25     private DOMDataBroker domBroker;
26
27     protected abstract AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer();
28
29     public AbstractDataBrokerTestCustomizer getDataBrokerTestCustomizer() {
30         if (testCustomizer == null) {
31             throw new IllegalStateException("testCustomizer not yet set by call to createDataBrokerTestCustomizer()");
32         }
33         return testCustomizer;
34     }
35
36     @Override
37     protected void setupWithSchema(final SchemaContext context) {
38         testCustomizer = createDataBrokerTestCustomizer();
39         dataBroker = testCustomizer.createDataBroker();
40         domBroker = testCustomizer.getDOMDataBroker();
41         testCustomizer.updateSchema(context);
42     }
43
44     public DataBroker getDataBroker() {
45         return dataBroker;
46     }
47
48     public DOMDataBroker getDomBroker() {
49         return domBroker;
50     }
51
52     protected static final void assertCommit(final ListenableFuture<Void> commit) {
53         assertCommit(commit, ASSERT_COMMIT_DEFAULT_TIMEOUT);
54     }
55
56     protected static final void assertCommit(final ListenableFuture<Void> commit, long timeoutInMS) {
57         try {
58             commit.get(timeoutInMS, TimeUnit.MILLISECONDS);
59         } catch (InterruptedException | ExecutionException | TimeoutException e) {
60             throw new IllegalStateException(e);
61         }
62     }
63 }