2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.sal.binding.test;
10 import javassist.ClassPool;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.impl.ForwardedBindingDataBroker;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
16 import org.opendaylight.controller.md.sal.dom.broker.impl.DOMDataBrokerImpl;
17 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
18 import org.opendaylight.controller.sal.binding.test.util.MockSchemaService;
19 import org.opendaylight.controller.sal.core.api.model.SchemaService;
20 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
21 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
22 import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 import com.google.common.collect.ImmutableMap;
26 import com.google.common.util.concurrent.ListeningExecutorService;
27 import com.google.common.util.concurrent.MoreExecutors;
29 public class DataBrokerTestCustomizer {
31 private DOMDataBroker domDataBroker;
32 private final RuntimeGeneratedMappingServiceImpl mappingService;
33 private final MockSchemaService schemaService;
34 private ImmutableMap<LogicalDatastoreType, DOMStore> datastores;
36 public ImmutableMap<LogicalDatastoreType, DOMStore> createDatastores() {
37 return ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
38 .put(LogicalDatastoreType.OPERATIONAL, createOperationalDatastore())
39 .put(LogicalDatastoreType.CONFIGURATION,createConfigurationDatastore())
43 public DataBrokerTestCustomizer() {
44 schemaService = new MockSchemaService();
45 mappingService = new RuntimeGeneratedMappingServiceImpl(ClassPool.getDefault());
48 public DOMStore createConfigurationDatastore() {
49 InMemoryDOMDataStore store = new InMemoryDOMDataStore("CFG", MoreExecutors.sameThreadExecutor());
50 schemaService.registerSchemaContextListener(store);
54 public DOMStore createOperationalDatastore() {
55 InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", MoreExecutors.sameThreadExecutor());
56 schemaService.registerSchemaContextListener(store);
60 public DOMDataBroker createDOMDataBroker() {
61 return new DOMDataBrokerImpl(getDatastores(), getCommitCoordinatorExecutor());
64 public ListeningExecutorService getCommitCoordinatorExecutor() {
65 return MoreExecutors.sameThreadExecutor();
68 public DataBroker createDataBroker() {
69 return new ForwardedBindingDataBroker(getDOMDataBroker(), getMappingService(), getSchemaService());
72 private SchemaService getSchemaService() {
76 private BindingIndependentMappingService getMappingService() {
77 return mappingService;
80 private DOMDataBroker getDOMDataBroker() {
81 if(domDataBroker == null) {
82 domDataBroker = createDOMDataBroker();
87 private ImmutableMap<LogicalDatastoreType, DOMStore> getDatastores() {
88 if(datastores == null) {
89 datastores = createDatastores();
94 public void updateSchema(final SchemaContext ctx) {
95 schemaService.changeSchema(ctx);
96 mappingService.onGlobalContextUpdated(ctx);