2 * Copyright (c) 2016 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.dom.store.inmemory;
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;
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;
25 public class InMemoryDOMDataStoreFactoryTest {
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));
33 final InMemoryDOMDataStore inMemoryDOMDataStore =
34 InMemoryDOMDataStoreFactory.create(testStoreName, domSchemaService);
35 assertNotNull(inMemoryDOMDataStore);
36 assertEquals(testStoreName, inMemoryDOMDataStore.getIdentifier());
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);
44 final AutoCloseable autoCloseable = mock(AutoCloseable.class);
45 doNothing().when(autoCloseable).close();
46 inMemoryDOMDataStore.setCloseable(autoCloseable);
47 inMemoryDOMDataStore.close();
48 verify(autoCloseable).close();