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.dom.broker;
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertSame;
12 import static org.junit.Assert.assertTrue;
13 import static org.mockito.Mockito.doNothing;
14 import static org.mockito.Mockito.mock;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
20 import org.opendaylight.mdsal.dom.api.DOMMountPointListener;
21 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
22 import org.opendaylight.mdsal.dom.api.DOMMountPointService.DOMMountPointBuilder;
23 import org.opendaylight.mdsal.dom.api.DOMService;
24 import org.opendaylight.mdsal.dom.broker.DOMMountPointServiceImpl.DOMMountPointBuilderImpl;
25 import org.opendaylight.yangtools.concepts.ObjectRegistration;
26 import org.opendaylight.yangtools.yang.common.QName;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
28 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
30 public class MountPointServiceTest {
32 private static final YangInstanceIdentifier PATH = YangInstanceIdentifier.of(QName.create("namespace", "12-12-2012",
35 private DOMMountPointService mountService;
39 mountService = new DOMMountPointServiceImpl();
43 public void createSimpleMountPoint() throws Exception {
44 final DOMMountPointListener listener = mock(DOMMountPointListener.class);
45 doNothing().when(listener).onMountPointCreated(PATH);
46 mountService.registerProvisionListener(listener);
48 assertFalse(mountService.getMountPoint(PATH).isPresent());
50 mountService.createMountPoint(PATH).register();
52 assertTrue(mountService.getMountPoint(PATH).isPresent());
56 public void unregisterTest() throws Exception {
57 final DOMMountPointListener listener = mock(DOMMountPointListener.class);
58 doNothing().when(listener).onMountPointCreated(PATH);
59 doNothing().when(listener).onMountPointRemoved(PATH);
60 final DOMMountPointServiceImpl mountService = new DOMMountPointServiceImpl();
61 mountService.registerProvisionListener(listener);
62 mountService.createMountPoint(PATH).register();
64 assertTrue(mountService.getMountPoint(PATH).isPresent());
66 mountService.unregisterMountPoint(PATH);
68 assertFalse(mountService.getMountPoint(PATH).isPresent());
72 public void mountRegistrationTest() throws Exception {
73 final DOMMountPointBuilder mountBuilder = mountService.createMountPoint(PATH);
74 final ObjectRegistration<DOMMountPoint> objectRegistration = mountBuilder.register();
76 assertTrue(mountService.getMountPoint(PATH).isPresent());
77 assertSame(objectRegistration.getInstance(), mountService.getMountPoint(PATH).get());
79 objectRegistration.close();
81 assertFalse(mountService.getMountPoint(PATH).isPresent());
85 public void mountBuilderTest() throws Exception {
86 final DOMMountPointBuilderImpl mountBuilder = (DOMMountPointBuilderImpl) mountService.createMountPoint(PATH);
87 mountBuilder.register();
89 final SchemaContext mockSchemaContext = mock(SchemaContext.class);
90 mountBuilder.addInitialSchemaContext(mockSchemaContext);
92 assertSame(mockSchemaContext, mountBuilder.getSchemaContext());
94 final Map<Class<? extends DOMService>, DOMService> services = mountBuilder.getServices();
95 assertTrue(services.isEmpty());
96 mountBuilder.addService(DOMService.class, mock(DOMService.class));
97 assertTrue(services.containsKey(DOMService.class));