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.mdsal.binding.dom.adapter.test;
10 import com.google.common.cache.CacheBuilder;
11 import com.google.common.cache.CacheLoader;
12 import com.google.common.cache.LoadingCache;
13 import com.google.common.collect.ImmutableSet;
15 import org.junit.Before;
16 import org.opendaylight.binding.runtime.spi.GeneratedClassLoadingStrategy;
17 import org.opendaylight.binding.runtime.spi.ModuleInfoBackedContext;
18 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
19 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
20 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
22 public abstract class AbstractSchemaAwareTest {
23 private static final LoadingCache<Set<YangModuleInfo>, EffectiveModelContext> SCHEMA_CONTEXT_CACHE =
24 CacheBuilder.newBuilder().weakValues().build(
25 new CacheLoader<Set<YangModuleInfo>, EffectiveModelContext>() {
27 public EffectiveModelContext load(final Set<YangModuleInfo> key) {
28 return ModuleInfoBackedContext.cacheContext(
29 GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), ImmutableSet.copyOf(key))
30 .tryToCreateModelContext().get();
35 public final void setup() throws Exception {
36 setupWithSchema(getSchemaContext());
39 protected Set<YangModuleInfo> getModuleInfos() throws Exception {
40 return BindingReflections.cacheModuleInfos(Thread.currentThread().getContextClassLoader());
43 protected EffectiveModelContext getSchemaContext() throws Exception {
44 return SCHEMA_CONTEXT_CACHE.getUnchecked(getModuleInfos());
48 * Setups test with Schema context.
50 * @param context schema context
52 protected abstract void setupWithSchema(EffectiveModelContext context);