32545a185476aff520e5808a6b9e101797916c53
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / test / util / MockSchemaService.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.util;
9
10 import com.google.common.collect.ClassToInstanceMap;
11 import com.google.common.collect.ImmutableClassToInstanceMap;
12 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
13 import org.opendaylight.mdsal.dom.api.DOMSchemaServiceExtension;
14 import org.opendaylight.yangtools.concepts.ListenerRegistration;
15 import org.opendaylight.yangtools.util.ListenerRegistry;
16 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
18 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
19
20 public final class MockSchemaService implements DOMSchemaService, EffectiveModelContextProvider {
21
22     private EffectiveModelContext schemaContext;
23
24     final ListenerRegistry<EffectiveModelContextListener> listeners = ListenerRegistry.create();
25
26     @Override
27     public synchronized EffectiveModelContext getGlobalContext() {
28         return schemaContext;
29     }
30
31     @Override
32     public ListenerRegistration<EffectiveModelContextListener> registerSchemaContextListener(
33             final EffectiveModelContextListener listener) {
34         return listeners.register(listener);
35     }
36
37     @Override
38     public synchronized EffectiveModelContext getEffectiveModelContext() {
39         return schemaContext;
40     }
41
42     @Override
43     public ClassToInstanceMap<DOMSchemaServiceExtension> getExtensions() {
44         return ImmutableClassToInstanceMap.of();
45     }
46
47     public synchronized void changeSchema(final EffectiveModelContext newContext) {
48         schemaContext = newContext;
49         listeners.streamListeners().forEach(listener -> listener.onModelContextUpdated(schemaContext));
50     }
51 }