Fix odlparent-3.0.0 checkstyle issues
[mdsal.git] / dom / mdsal-dom-broker / src / test / java / org / opendaylight / mdsal / dom / broker / MountPointServiceTest.java
1 /*
2  * Copyright (c) 2014 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.broker;
9
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;
15
16 import java.util.Map;
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;
29
30 public class MountPointServiceTest {
31
32     private static final YangInstanceIdentifier PATH =
33             YangInstanceIdentifier.of(QName.create("namespace", "2012-12-12",
34         "top"));
35
36     private DOMMountPointService mountService;
37
38     @Before
39     public void setup() {
40         mountService = new DOMMountPointServiceImpl();
41     }
42
43     @Test
44     public void createSimpleMountPoint() throws Exception {
45         final DOMMountPointListener listener = mock(DOMMountPointListener.class);
46         doNothing().when(listener).onMountPointCreated(PATH);
47         mountService.registerProvisionListener(listener);
48
49         assertFalse(mountService.getMountPoint(PATH).isPresent());
50
51         mountService.createMountPoint(PATH).register();
52
53         assertTrue(mountService.getMountPoint(PATH).isPresent());
54     }
55
56     @Test
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();
64
65         assertTrue(service.getMountPoint(PATH).isPresent());
66
67         service.unregisterMountPoint(PATH);
68
69         assertFalse(service.getMountPoint(PATH).isPresent());
70     }
71
72     @Test
73     public void mountRegistrationTest() throws Exception {
74         final DOMMountPointBuilder mountBuilder = mountService.createMountPoint(PATH);
75         final ObjectRegistration<DOMMountPoint> objectRegistration = mountBuilder.register();
76
77         assertTrue(mountService.getMountPoint(PATH).isPresent());
78         assertSame(objectRegistration.getInstance(), mountService.getMountPoint(PATH).get());
79
80         objectRegistration.close();
81
82         assertFalse(mountService.getMountPoint(PATH).isPresent());
83     }
84
85     @Test
86     public void mountBuilderTest() throws Exception {
87         final DOMMountPointBuilderImpl mountBuilder = (DOMMountPointBuilderImpl) mountService.createMountPoint(PATH);
88         mountBuilder.register();
89
90         final SchemaContext mockSchemaContext = mock(SchemaContext.class);
91         mountBuilder.addInitialSchemaContext(mockSchemaContext);
92
93         assertSame(mockSchemaContext, mountBuilder.getSchemaContext());
94
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));
99     }
100 }