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 =
33 YangInstanceIdentifier.of(QName.create("namespace", "2012-12-12",
36 private DOMMountPointService mountService;
40 mountService = new DOMMountPointServiceImpl();
44 public void createSimpleMountPoint() throws Exception {
45 final DOMMountPointListener listener = mock(DOMMountPointListener.class);
46 doNothing().when(listener).onMountPointCreated(PATH);
47 mountService.registerProvisionListener(listener);
49 assertFalse(mountService.getMountPoint(PATH).isPresent());
51 mountService.createMountPoint(PATH).register();
53 assertTrue(mountService.getMountPoint(PATH).isPresent());
57 public void unregisterTest() throws Exception {
58 final DOMMountPointListener listener = mock(DOMMountPointListener.class);
59 doNothing().when(listener).onMountPointCreated(PATH);
60 doNothing().when(listener).onMountPointRemoved(PATH);
61 final DOMMountPointServiceImpl service = new DOMMountPointServiceImpl();
62 service.registerProvisionListener(listener);
63 service.createMountPoint(PATH).register();
65 assertTrue(service.getMountPoint(PATH).isPresent());
67 service.unregisterMountPoint(PATH);
69 assertFalse(service.getMountPoint(PATH).isPresent());
73 public void mountRegistrationTest() throws Exception {
74 final DOMMountPointBuilder mountBuilder = mountService.createMountPoint(PATH);
75 final ObjectRegistration<DOMMountPoint> objectRegistration = mountBuilder.register();
77 assertTrue(mountService.getMountPoint(PATH).isPresent());
78 assertSame(objectRegistration.getInstance(), mountService.getMountPoint(PATH).get());
80 objectRegistration.close();
82 assertFalse(mountService.getMountPoint(PATH).isPresent());
86 public void mountBuilderTest() throws Exception {
87 final DOMMountPointBuilderImpl mountBuilder = (DOMMountPointBuilderImpl) mountService.createMountPoint(PATH);
88 mountBuilder.register();
90 final SchemaContext mockSchemaContext = mock(SchemaContext.class);
91 mountBuilder.addInitialSchemaContext(mockSchemaContext);
93 assertSame(mockSchemaContext, mountBuilder.getSchemaContext());
95 final Map<Class<? extends DOMService>, DOMService> services = mountBuilder.getServices();
96 assertTrue(services.isEmpty());
97 mountBuilder.addService(DOMService.class, mock(DOMService.class));
98 assertTrue(services.containsKey(DOMService.class));