BUG-2637: migration consequence - fix unit test
[controller.git] / opendaylight / md-sal / statistics-manager / src / test / java / test / mock / util / 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 test.mock.util;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
13 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
14
15 import java.util.concurrent.ExecutionException;
16 import java.util.concurrent.TimeUnit;
17 import java.util.concurrent.TimeoutException;
18
19 public class AbstractDataBrokerTest extends AbstractSchemaAwareTest {
20
21     private DataBrokerTestCustomizer testCustomizer;
22     private DataBroker dataBroker;
23     private DOMDataBroker domBroker;
24
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
59
60 }