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.dom.store.impl;
10 import static org.junit.Assert.assertNotNull;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
16 import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
17 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
20 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 public class SchemaUpdateForTransactionTest {
27 private static final YangInstanceIdentifier TOP_PATH = YangInstanceIdentifier.of(Top.QNAME);
28 private SchemaContext schemaContext;
29 private InMemoryDOMDataStore domStore;
32 public void setupStore() throws Exception {
33 this.domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.newDirectExecutorService());
34 loadSchemas(RockTheHouseInput.class);
37 public void loadSchemas(final Class<?>... classes) throws Exception {
38 final ModuleInfoBackedContext context = ModuleInfoBackedContext.create();
39 for (final Class<?> clz : classes) {
40 YangModuleInfo moduleInfo = BindingReflections.getModuleInfo(clz);
42 context.registerModuleInfo(moduleInfo);
44 this.schemaContext = context.tryToCreateSchemaContext().get();
45 this.domStore.onGlobalContextUpdated(this.schemaContext);
49 * Test suite tests allocating transaction when schema context
50 * does not contain module necessary for client write,
51 * then triggering update of global schema context
52 * and then performing write (according to new module).
55 * If transaction between allocation and schema context was
56 * unmodified, it is safe to change its schema context
57 * to new one (e.g. it will be same as if allocated after
58 * schema context update.)
61 public void testTransactionSchemaUpdate() throws Exception {
63 assertNotNull(this.domStore);
65 // We allocate transaction, initial schema context does not
66 // contain Lists model
67 final DOMStoreReadWriteTransaction writeTx = this.domStore.newReadWriteTransaction();
68 assertNotNull(writeTx);
70 // we trigger schema context update to contain Lists model
71 loadSchemas(RockTheHouseInput.class, Top.class);
74 * Writes /test in writeTx, this write should not fail
75 * with IllegalArgumentException since /test is in
78 writeTx.write(TOP_PATH, ImmutableNodes.containerNode(Top.QNAME));