From fd8851f71334c56adfc317bf986e540ce17b0410 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Thu, 1 Jun 2017 06:32:19 +0200 Subject: [PATCH] Make testutils a JAR instead of a POM and start to use it for holding test fakes of genius APIs Change-Id: Iaa44b3c7031f2d5a6129354e993157f8eb82680d Signed-off-by: Michael Vorburger --- arputil/arputil-impl/pom.xml | 1 - commons/testutils/pom.xml | 7 ++- .../testutils/TestInterfaceManager.java | 48 +++++++++++++++++++ .../interfacemanager-impl/pom.xml | 1 - itm/itm-impl/pom.xml | 3 +- lockmanager/lockmanager-impl/pom.xml | 1 - resourcemanager/resourcemanager-impl/pom.xml | 1 - 7 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 commons/testutils/src/main/java/org/opendaylight/genius/testutils/TestInterfaceManager.java diff --git a/arputil/arputil-impl/pom.xml b/arputil/arputil-impl/pom.xml index a7011ea57..19c0bf6c5 100644 --- a/arputil/arputil-impl/pom.xml +++ b/arputil/arputil-impl/pom.xml @@ -97,7 +97,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html org.opendaylight.genius testutils ${genius.version} - pom test diff --git a/commons/testutils/pom.xml b/commons/testutils/pom.xml index 3e24168c7..68b78d00e 100644 --- a/commons/testutils/pom.xml +++ b/commons/testutils/pom.xml @@ -19,12 +19,17 @@ and is available at http://www.eclipse.org/legal/epl-v10.html org.opendaylight.genius testutils - pom ODL :: genius :: ${project.artifactId} + + ${project.groupId} + interfacemanager-api + ${project.version} + + diff --git a/commons/testutils/src/main/java/org/opendaylight/genius/testutils/TestInterfaceManager.java b/commons/testutils/src/main/java/org/opendaylight/genius/testutils/TestInterfaceManager.java new file mode 100644 index 000000000..0d4093bff --- /dev/null +++ b/commons/testutils/src/main/java/org/opendaylight/genius/testutils/TestInterfaceManager.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 Red Hat, 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.genius.testutils; + +import static org.opendaylight.yangtools.testutils.mockito.MoreAnswers.realOrException; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import org.mockito.Mockito; +import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo; +import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager; + +/** + * IInterfaceManager implementation for tests. + * + * @author Michael Vorburger + */ +public abstract class TestInterfaceManager implements IInterfaceManager { + + // Implementation similar to e.g. the org.opendaylight.genius.mdsalutil.interfaces.testutils.TestIMdsalApiManager + + public static TestInterfaceManager newInstance() { + TestInterfaceManager testInterfaceManager = Mockito.mock(TestInterfaceManager.class, realOrException()); + testInterfaceManager.interfaceInfos = new ConcurrentHashMap<>(); + return testInterfaceManager; + } + + private Map interfaceInfos; + + public void addInterfaceInfo(InterfaceInfo interfaceInfo) { + interfaceInfos.put(interfaceInfo.getInterfaceName(), interfaceInfo); + } + + @Override + public InterfaceInfo getInterfaceInfo(String interfaceName) { + InterfaceInfo interfaceInfo = interfaceInfos.get(interfaceName); + if (interfaceInfo == null) { + throw new IllegalStateException( + "must addInterfaceInfo() to TestInterfaceManager before getInterfaceInfo: " + interfaceName); + } + return interfaceInfo; + } +} diff --git a/interfacemanager/interfacemanager-impl/pom.xml b/interfacemanager/interfacemanager-impl/pom.xml index fdc041227..f8e55176e 100644 --- a/interfacemanager/interfacemanager-impl/pom.xml +++ b/interfacemanager/interfacemanager-impl/pom.xml @@ -94,7 +94,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html org.opendaylight.genius testutils ${genius.version} - pom test diff --git a/itm/itm-impl/pom.xml b/itm/itm-impl/pom.xml index bf833f6f3..ebc7ba56b 100644 --- a/itm/itm-impl/pom.xml +++ b/itm/itm-impl/pom.xml @@ -79,7 +79,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html org.opendaylight.genius testutils ${genius.version} - pom test @@ -209,4 +208,4 @@ and is available at http://www.eclipse.org/legal/epl-v10.html ${nexus.site.url}/${project.artifactId}/ - \ No newline at end of file + diff --git a/lockmanager/lockmanager-impl/pom.xml b/lockmanager/lockmanager-impl/pom.xml index 585d3ff90..3ac6b0478 100644 --- a/lockmanager/lockmanager-impl/pom.xml +++ b/lockmanager/lockmanager-impl/pom.xml @@ -46,7 +46,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html org.opendaylight.genius testutils ${project.version} - pom test diff --git a/resourcemanager/resourcemanager-impl/pom.xml b/resourcemanager/resourcemanager-impl/pom.xml index 218b9edc9..9260ddc6e 100644 --- a/resourcemanager/resourcemanager-impl/pom.xml +++ b/resourcemanager/resourcemanager-impl/pom.xml @@ -63,7 +63,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html org.opendaylight.genius testutils ${genius.version} - pom test -- 2.36.6