import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.MutableClassToInstanceMap;
import java.util.HashMap;
import java.util.Map;
});
}
- final class DOMMountPointBuilderImpl implements DOMMountPointBuilder {
+ private final class DOMMountPointBuilderImpl implements DOMMountPointBuilder {
private final MutableClassToInstanceMap<DOMService> services = MutableClassToInstanceMap.create();
private final YangInstanceIdentifier path;
this.path = requireNonNull(path);
}
- @VisibleForTesting
- SchemaContext getSchemaContext() {
- return schemaContext;
- }
-
- @VisibleForTesting
- Map<Class<? extends DOMService>, DOMService> getServices() {
- return services;
- }
-
@Override
public <T extends DOMService> DOMMountPointBuilder addService(final Class<T> type, final T impl) {
services.putInstance(requireNonNull(type), requireNonNull(impl));
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.dom.broker;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMMountPointListener;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService.DOMMountPointBuilder;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+public class DOMMountPointServiceImplTest {
+
+ private static final YangInstanceIdentifier PATH =
+ YangInstanceIdentifier.of(QName.create("namespace", "2012-12-12",
+ "top"));
+
+ private DOMMountPointService mountPointService;
+
+ @Before
+ public void setup() {
+ mountPointService = new DOMMountPointServiceImpl();
+ }
+
+ @Test
+ public void testMountPointRegistration() {
+ final DOMMountPointListener mountPointListener = mock(DOMMountPointListener.class);
+ doNothing().when(mountPointListener).onMountPointCreated(PATH);
+ mountPointService.registerProvisionListener(mountPointListener);
+
+ // Create a mount point with schema context and a DOMService
+ final DOMMountPointBuilder mountPointBuilder = mountPointService.createMountPoint(PATH);
+
+ final SchemaContext schemaContext = mock(SchemaContext.class);
+ mountPointBuilder.addInitialSchemaContext(schemaContext);
+
+ final DOMRpcService rpcService = mock(DOMRpcService.class);
+ mountPointBuilder.addService(DOMRpcService.class, rpcService);
+
+ mountPointBuilder.register();
+
+ // Verify listener has been notified and mount point is accessible from mount point service
+ verify(mountPointListener).onMountPointCreated(eq(PATH));
+ assertTrue(mountPointService.getMountPoint(PATH).isPresent());
+
+ // Verify mount point schema context and service
+ final DOMMountPoint mountPoint = mountPointService.getMountPoint(PATH).get();
+ assertTrue(mountPoint.getService(DOMRpcService.class).isPresent());
+ assertEquals(rpcService, mountPoint.getService(DOMRpcService.class).get());
+
+ assertEquals(schemaContext, mountPoint.getSchemaContext());
+ }
+
+ @Test
+ public void testMountPointDestruction() {
+ final DOMMountPointListener mountPointListener = mock(DOMMountPointListener.class);
+ doNothing().when(mountPointListener).onMountPointRemoved(PATH);
+
+ final ObjectRegistration<DOMMountPoint> mountPointRegistration =
+ mountPointService.createMountPoint(PATH).register();
+
+ mountPointService.registerProvisionListener(mountPointListener);
+
+ mountPointRegistration.close();
+
+ // Verify listener has been notified and mount point is not present in mount point service
+ verify(mountPointListener).onMountPointRemoved(eq(PATH));
+ assertFalse(mountPointService.getMountPoint(PATH).isPresent());
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.dom.broker;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
-
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.mdsal.dom.api.DOMMountPoint;
-import org.opendaylight.mdsal.dom.api.DOMMountPointListener;
-import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.mdsal.dom.api.DOMMountPointService.DOMMountPointBuilder;
-import org.opendaylight.mdsal.dom.api.DOMService;
-import org.opendaylight.mdsal.dom.broker.DOMMountPointServiceImpl.DOMMountPointBuilderImpl;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-
-public class MountPointServiceTest {
-
- private static final YangInstanceIdentifier PATH =
- YangInstanceIdentifier.of(QName.create("namespace", "2012-12-12",
- "top"));
-
- private DOMMountPointService mountService;
-
- @Before
- public void setup() {
- mountService = new DOMMountPointServiceImpl();
- }
-
- @Test
- public void createSimpleMountPoint() {
- final DOMMountPointListener listener = mock(DOMMountPointListener.class);
- doNothing().when(listener).onMountPointCreated(PATH);
- mountService.registerProvisionListener(listener);
-
- assertFalse(mountService.getMountPoint(PATH).isPresent());
-
- mountService.createMountPoint(PATH).register();
-
- assertTrue(mountService.getMountPoint(PATH).isPresent());
- }
-
- @Test
- public void unregisterTest() {
- final DOMMountPointListener listener = mock(DOMMountPointListener.class);
- doNothing().when(listener).onMountPointCreated(PATH);
- doNothing().when(listener).onMountPointRemoved(PATH);
- final DOMMountPointServiceImpl service = new DOMMountPointServiceImpl();
- service.registerProvisionListener(listener);
- final ObjectRegistration<DOMMountPoint> mountPointReg = service.createMountPoint(PATH).register();
-
- assertTrue(service.getMountPoint(PATH).isPresent());
-
- mountPointReg.close();
-
- assertFalse(service.getMountPoint(PATH).isPresent());
- }
-
- @Test
- public void mountRegistrationTest() {
- final DOMMountPointBuilder mountBuilder = mountService.createMountPoint(PATH);
- final ObjectRegistration<DOMMountPoint> objectRegistration = mountBuilder.register();
-
- assertTrue(mountService.getMountPoint(PATH).isPresent());
- assertSame(objectRegistration.getInstance(), mountService.getMountPoint(PATH).get());
-
- objectRegistration.close();
-
- assertFalse(mountService.getMountPoint(PATH).isPresent());
- }
-
- @Test
- public void mountBuilderTest() {
- final DOMMountPointBuilderImpl mountBuilder = (DOMMountPointBuilderImpl) mountService.createMountPoint(PATH);
- mountBuilder.register();
-
- final SchemaContext mockSchemaContext = mock(SchemaContext.class);
- mountBuilder.addInitialSchemaContext(mockSchemaContext);
-
- assertSame(mockSchemaContext, mountBuilder.getSchemaContext());
-
- final Map<Class<? extends DOMService>, DOMService> services = mountBuilder.getServices();
- assertTrue(services.isEmpty());
- mountBuilder.addService(DOMService.class, mock(DOMService.class));
- assertTrue(services.containsKey(DOMService.class));
- }
-}