OLM unit testing update 91/78091/2
authordoha.khaled <dkhaled.ext@orange.com>
Thu, 22 Nov 2018 13:17:32 +0000 (15:17 +0200)
committerguillaume.lambert <guillaume.lambert@orange.com>
Mon, 26 Nov 2018 10:50:23 +0000 (11:50 +0100)
JIRA: TRNSPRTPCE-59
Change-Id: Ic513dd8d5e36fd35b436cd4d397d7f2eb80c8572
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
olm/src/test/java/org/opendaylight/transportpce/olm/OlmProviderTest.java
olm/src/test/java/org/opendaylight/transportpce/olm/stub/CompositeRoutedRpcRegistrationStub.java [new file with mode: 0644]
olm/src/test/java/org/opendaylight/transportpce/olm/stub/RpcProviderRegistryStub.java [new file with mode: 0644]
olm/src/test/java/org/opendaylight/transportpce/olm/stub/RpcProviderRegistryStub2.java [new file with mode: 0644]
olm/src/test/java/org/opendaylight/transportpce/olm/util/OtsPmHolderTest.java [new file with mode: 0644]

index 634f517c4fc71133c14929f44271136969c29bcb..2a8cec9bdb3d1fc9418b3ff272d53bb46b076935 100644 (file)
@@ -1,18 +1,81 @@
 /*
- * Copyright © 2017 AT&T and others.  All rights reserved.
+ * Copyright © 2018 Orange 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.transportpce.olm;
 
+import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.MountPoint;
+import org.opendaylight.controller.md.sal.binding.api.MountPointService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
+import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
+import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
+import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
+import org.opendaylight.transportpce.common.mapping.PortMapping;
+import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
+import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
+import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
+import org.opendaylight.transportpce.olm.power.PowerMgmt;
+import org.opendaylight.transportpce.olm.service.OlmPowerService;
+import org.opendaylight.transportpce.olm.service.OlmPowerServiceImpl;
+import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
+import org.opendaylight.transportpce.olm.stub.MountPointStub;
+import org.opendaylight.transportpce.olm.stub.RpcProviderRegistryStub;
+import org.opendaylight.transportpce.olm.stub.RpcProviderRegistryStub2;
+import org.opendaylight.transportpce.test.AbstractTest;
+
+public class OlmProviderTest extends AbstractTest {
+
+    private MountPoint mountPoint;
+    private MountPointService mountPointService;
+    private DeviceTransactionManager deviceTransactionManager;
+    private CrossConnect crossConnect;
+    private OpenRoadmInterfaces openRoadmInterfaces;
+    private PortMapping portMapping;
+    private PowerMgmt powerMgmt;
+    private OlmPowerService olmPowerService;
+    private RpcProviderRegistry rpcProviderRegistry;
+    private OlmProvider olmProvider;
+
+    @Before
+    public void setUp() {
+        this.mountPoint = new MountPointStub(this.getDataBroker());
+        this.mountPointService = new MountPointServiceStub(mountPoint);
+        this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
+        this.crossConnect = new CrossConnectImpl(this.deviceTransactionManager);
+        this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager));
+        this.portMapping = new PortMappingImpl(this.getDataBroker(), this.deviceTransactionManager,
+            this.openRoadmInterfaces);
+        this.powerMgmt = new PowerMgmt(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
+            this.deviceTransactionManager);
+        this.olmPowerService = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmt,
+            this.deviceTransactionManager, this.portMapping);
+        this.rpcProviderRegistry = new RpcProviderRegistryStub();
+        this.olmProvider = new OlmProvider(this.rpcProviderRegistry, this.olmPowerService);
+
+    }
+
+
+    @Test
+    public void testInitAndClose() {
+        this.olmProvider.init();
+        this.olmProvider.close();
+    }
+
 
-public class OlmProviderTest {
     @Test
-    public void init() throws Exception {
-        //TODO implement test
+    public void testClose2() {
+        this.rpcProviderRegistry = new RpcProviderRegistryStub2();
+        this.olmProvider = new OlmProvider(this.rpcProviderRegistry, this.olmPowerService);
+        this.olmProvider.init();
+        this.olmProvider.close();
     }
 
 }
diff --git a/olm/src/test/java/org/opendaylight/transportpce/olm/stub/CompositeRoutedRpcRegistrationStub.java b/olm/src/test/java/org/opendaylight/transportpce/olm/stub/CompositeRoutedRpcRegistrationStub.java
new file mode 100644 (file)
index 0000000..69a9790
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright © 2018 Orange 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.transportpce.olm.stub;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nonnull;
+import org.opendaylight.controller.md.sal.binding.impl.BindingDOMRpcProviderServiceAdapter;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.RpcService;
+
+public class CompositeRoutedRpcRegistrationStub<T extends RpcService> implements
+    BindingAwareBroker.RoutedRpcRegistration<T> {
+    private final Class<T> type;
+    private final T instance;
+    private final BindingDOMRpcProviderServiceAdapter adapter;
+    private final Map<InstanceIdentifier<?>, ObjectRegistration<T>> registrations = new HashMap(2);
+
+    CompositeRoutedRpcRegistrationStub(final Class<T> type, final T impl,
+        final BindingDOMRpcProviderServiceAdapter providerAdapter) {
+        this.type = type;
+        this.instance = impl;
+        this.adapter = providerAdapter;
+    }
+
+    @Override public void registerInstance(Class<? extends BaseIdentity> context, InstanceIdentifier<?> myinstance) {
+
+    }
+
+    @Override public void unregisterInstance(Class<? extends BaseIdentity> context, InstanceIdentifier<?> myinstance) {
+
+    }
+
+    @Override public void registerPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
+
+    }
+
+    @Override public void unregisterPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
+
+    }
+
+    @Override public Class<T> getServiceType() {
+        return null;
+    }
+
+    @Override public void close() {
+
+    }
+
+    @Nonnull
+    @Override public T getInstance() {
+        return null;
+    }
+}
diff --git a/olm/src/test/java/org/opendaylight/transportpce/olm/stub/RpcProviderRegistryStub.java b/olm/src/test/java/org/opendaylight/transportpce/olm/stub/RpcProviderRegistryStub.java
new file mode 100644 (file)
index 0000000..41e942d
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2018 Orange 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.transportpce.olm.stub;
+
+import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.RpcService;
+
+public class RpcProviderRegistryStub implements RpcProviderRegistry {
+    @Override public <T extends RpcService> BindingAwareBroker.RpcRegistration<T> addRpcImplementation(
+        Class<T> serviceInterface, T implementation) throws IllegalStateException {
+        return new CompositeRoutedRpcRegistrationStub(serviceInterface, implementation, null);
+    }
+
+    @Override public <T extends RpcService> BindingAwareBroker.RoutedRpcRegistration<T> addRoutedRpcImplementation(
+        Class<T> serviceInterface, T implementation) throws IllegalStateException {
+        return null;
+    }
+
+    @Override public <L extends RouteChangeListener<RpcContextIdentifier,
+        InstanceIdentifier<?>>> ListenerRegistration<L> registerRouteChangeListener(L listener) {
+        return null;
+    }
+
+    @Override public <T extends RpcService> T getRpcService(Class<T> serviceInterface) {
+        return null;
+    }
+}
diff --git a/olm/src/test/java/org/opendaylight/transportpce/olm/stub/RpcProviderRegistryStub2.java b/olm/src/test/java/org/opendaylight/transportpce/olm/stub/RpcProviderRegistryStub2.java
new file mode 100644 (file)
index 0000000..a4a7e60
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2018 Orange 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.transportpce.olm.stub;
+
+import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.RpcService;
+
+public class RpcProviderRegistryStub2 implements RpcProviderRegistry {
+    @Override public <T extends RpcService> BindingAwareBroker.RpcRegistration<T> addRpcImplementation(
+        Class<T> serviceInterface, T implementation) throws IllegalStateException {
+        return null;
+    }
+
+    @Override public <T extends RpcService> BindingAwareBroker.RoutedRpcRegistration<T> addRoutedRpcImplementation(
+        Class<T> serviceInterface, T implementation) throws IllegalStateException {
+        return null;
+    }
+
+    @Override public <L extends RouteChangeListener<RpcContextIdentifier,
+        InstanceIdentifier<?>>> ListenerRegistration<L> registerRouteChangeListener(L listener) {
+        return null;
+    }
+
+    @Override public <T extends RpcService> T getRpcService(Class<T> serviceInterface) {
+        return null;
+    }
+}
diff --git a/olm/src/test/java/org/opendaylight/transportpce/olm/util/OtsPmHolderTest.java b/olm/src/test/java/org/opendaylight/transportpce/olm/util/OtsPmHolderTest.java
new file mode 100644 (file)
index 0000000..b0873f9
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright © 2018 Orange 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.transportpce.olm.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class OtsPmHolderTest {
+
+    @Test
+    public void test() {
+        OtsPmHolder otspmholder0 = new OtsPmHolder("name", Double.valueOf(12), "interface");
+
+        Assert.assertEquals("name", otspmholder0.getOtsParameterName());
+        Assert.assertEquals(Double.valueOf(12), otspmholder0.getOtsParameterVal());
+        Assert.assertEquals("interface", otspmholder0.getOtsInterfaceName());
+
+        otspmholder0.setOtsParameterName("name 2");
+        otspmholder0.setOtsParameterVal(Double.valueOf(120));
+        otspmholder0.setOtsInterfaceName("interface 2");
+
+        Assert.assertEquals("name 2", otspmholder0.getOtsParameterName());
+        Assert.assertEquals(Double.valueOf(120), otspmholder0.getOtsParameterVal());
+        Assert.assertEquals("interface 2", otspmholder0.getOtsInterfaceName());
+    }
+}