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 / BindingBrokerTestFactory.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.base.Preconditions;
12 import com.google.common.util.concurrent.ListeningExecutorService;
13 import com.google.common.util.concurrent.MoreExecutors;
14 import java.util.concurrent.ExecutorService;
15 import javassist.ClassPool;
16
17 @Beta
18 public class BindingBrokerTestFactory {
19
20     private static final ClassPool CLASS_POOL = ClassPool.getDefault();
21     private boolean startWithParsedSchema = true;
22     private ExecutorService executor;
23     private ClassPool classPool;
24
25     public boolean isStartWithParsedSchema() {
26         return startWithParsedSchema;
27     }
28
29     public void setStartWithParsedSchema(final boolean startWithParsedSchema) {
30         this.startWithParsedSchema = startWithParsedSchema;
31     }
32
33     public ExecutorService getExecutor() {
34         return executor;
35     }
36
37     public void setExecutor(final ExecutorService executor) {
38         this.executor = executor;
39     }
40
41     public BindingTestContext getTestContext() {
42         Preconditions.checkState(executor != null, "Executor is not set.");
43         final ListeningExecutorService listenableExecutor = MoreExecutors.listeningDecorator(executor);
44         return new BindingTestContext(listenableExecutor, getClassPool(), startWithParsedSchema);
45     }
46
47     public ClassPool getClassPool() {
48         if (classPool == null) {
49             return CLASS_POOL;
50         }
51
52         return classPool;
53     }
54
55     public void setClassPool(final ClassPool classPool) {
56         this.classPool = classPool;
57     }
58 }