Convert binding read to java.util.Optional
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / 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.mdsal.binding.dom.adapter.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.mdsal.binding.api.DataBroker;
15 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17
18 public class AbstractDataBrokerTest extends AbstractSchemaAwareTest {
19
20     private DataBrokerTestCustomizer testCustomizer;
21     private DataBroker dataBroker;
22     private DOMDataBroker domBroker;
23
24     @Override
25     protected void setupWithSchema(final SchemaContext context) {
26         testCustomizer = createDataBrokerTestCustomizer();
27         dataBroker = testCustomizer.createDataBroker();
28         domBroker = testCustomizer.createDOMDataBroker();
29         testCustomizer.updateSchema(context);
30         setupWithDataBroker(dataBroker);
31     }
32
33     protected void setupWithDataBroker(final DataBroker broker) {
34         // Intentionally left No-op, subclasses may customize it
35     }
36
37     protected DataBrokerTestCustomizer createDataBrokerTestCustomizer() {
38         return new DataBrokerTestCustomizer();
39     }
40
41     public DataBroker getDataBroker() {
42         return dataBroker;
43     }
44
45     public DOMDataBroker getDomBroker() {
46         return domBroker;
47     }
48
49     protected static final void assertCommit(final ListenableFuture<Void> commit) {
50         try {
51             commit.get(500, TimeUnit.MILLISECONDS);
52         } catch (InterruptedException | ExecutionException | TimeoutException e) {
53             throw new IllegalStateException(e);
54         }
55     }
56 }