Execute the ShardedDOMDataTreeTransaction.submit() async.
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / test / java / org / opendaylight / mdsal / dom / store / inmemory / InMemoryDOMDataStoreFactoryTest.java
1 /*
2  * Copyright (c) 2016 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.dom.store.inmemory;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Mockito.doNothing;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.mock;
16 import static org.mockito.Mockito.verify;
17
18 import org.junit.Test;
19 import org.opendaylight.controller.md.sal.dom.store.impl.TestModel;
20 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
21 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
24
25 public class InMemoryDOMDataStoreFactoryTest {
26
27     @Test
28     public void basicTest() throws Exception {
29         final String testStoreName = "TestStore";
30         final DOMSchemaService domSchemaService = mock(DOMSchemaService.class);
31         doReturn(null).when(domSchemaService).registerSchemaContextListener(any(SchemaContextListener.class));
32
33         final InMemoryDOMDataStore inMemoryDOMDataStore =
34                 InMemoryDOMDataStoreFactory.create(testStoreName, domSchemaService);
35         assertNotNull(inMemoryDOMDataStore);
36         assertEquals(testStoreName, inMemoryDOMDataStore.getIdentifier());
37
38         final DOMDataTreeChangeListener domDataTreeChangeListener = mock(DOMDataTreeChangeListener.class);
39         doReturn("testListener").when(domDataTreeChangeListener).toString();
40         doNothing().when(domDataTreeChangeListener).onDataTreeChanged(any());
41         inMemoryDOMDataStore.onGlobalContextUpdated(TestModel.createTestContext());
42         inMemoryDOMDataStore.registerTreeChangeListener(YangInstanceIdentifier.EMPTY, domDataTreeChangeListener);
43
44         final AutoCloseable autoCloseable = mock(AutoCloseable.class);
45         doNothing().when(autoCloseable).close();
46         inMemoryDOMDataStore.setCloseable(autoCloseable);
47         inMemoryDOMDataStore.close();
48         verify(autoCloseable).close();
49     }
50 }