X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fopenflow%2Fmd%2Fcore%2Fplan%2FEventFactory.java;fp=openflowplugin%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fopenflow%2Fmd%2Fcore%2Fplan%2FEventFactory.java;h=0000000000000000000000000000000000000000;hb=6e5df2b3308ffdc906dc1ef84a4ddde37f8080f6;hp=0f738e9512423b15179f350a2686014fc39e0d61;hpb=436d3b53fa2293b6d11348732db9bcc371e80642;p=openflowplugin.git diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/plan/EventFactory.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/plan/EventFactory.java deleted file mode 100644 index 0f738e9512..0000000000 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/plan/EventFactory.java +++ /dev/null @@ -1,157 +0,0 @@ -/** - * Copyright (c) 2013 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.openflowplugin.openflow.md.core.plan; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.concurrent.Callable; - -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; -import org.opendaylight.yangtools.yang.binding.Notification; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author mirehak - */ -public abstract class EventFactory { - - private static final Logger LOG = LoggerFactory - .getLogger(EventFactory.class); - - /** default protocol version */ - public static final Short DEFAULT_VERSION = 4; - - /** - * @param xid - * transaction id - * @param version - * version id - * @param builder - * message builder instance - * @return default notification event - */ - public static SwitchTestNotificationEvent createDefaultNotificationEvent( - long xid, short version, Object builder) { - SwitchTestNotificationEventImpl event = new SwitchTestNotificationEventImpl(); - Notification notification = build(setupHeader(xid, version, builder)); - event.setNotification(notification); - return event; - } - - /** - * @param xid - * transaction id - * @param version - * version id - * @param builder - * rpc response builder instance - * @return default notification event - */ - public static SwitchTestRcpResponseEvent createDefaultRpcResponseEvent( - long xid, short version, Object builder) { - SwitchTestRcpResponseEventImpl event = new SwitchTestRcpResponseEventImpl(); - OfHeader rpcResponse = build(setupHeader(xid, version, builder)); - event.setResponse(rpcResponse); - event.setXid(xid); - return event; - } - - /** - * @param setupHeader - * @return - */ - @SuppressWarnings("unchecked") - private static E build(Object builder) { - E notification = null; - try { - Class builderClazz = builder.getClass(); - notification = (E) builderClazz.getMethod("build", new Class[0]) - .invoke(builder, new Object[0]); - } catch (Exception e) { - LOG.error(e.getMessage(), e); - } - return notification; - } - - /** - * @param xid - * transaction id - * @param rpcName - * name of rpc method - * @return default notification event - */ - public static SwitchTestWaitForRpcEvent createDefaultWaitForRpcEvent( - long xid, String rpcName) { - SwitchTestWaitForRpcEventImpl event = new SwitchTestWaitForRpcEventImpl(); - event.setRpcName(rpcName); - event.setXid(xid); - return event; - } - - /** - * @param events - * @return wait for all wrapper - */ - public static SwitchTestWaitForAllEvent createDefaultWaitForAllEvent( - SwitchTestWaitForRpcEvent... events) { - SwitchTestWaitForAllEventImpl eventBag = new SwitchTestWaitForAllEventImpl(); - HashSet eventsSet = new HashSet<>(Arrays.asList(events)); - eventBag.setEventBag(eventsSet); - return eventBag; - } - - /** - * @param xid - * @param version - * @param builder - * @return original builder - */ - public static E setupHeader(long xid, short version, E builder) { - try { - Class builderClazz = builder.getClass(); - builderClazz.getMethod("setXid", Long.class).invoke(builder, xid); - builderClazz.getMethod("setVersion", Short.class).invoke(builder, - version); - } catch (Exception e) { - LOG.error(e.getMessage(), e); - } - - return builder; - } - - /** - * use {@link #DEFAULT_VERSION} - * @param xid - * @param builder - * @return original builder - */ - public static E setupHeader(long xid, E builder) { - return setupHeader(xid, DEFAULT_VERSION, builder); - } - - /** - * @param connectionConductor - * @return scenario callback - */ - public static SwitchTestCallbackEventImpl createConnectionReadyCallback( - final ConnectionReadyListener connectionConductor) { - SwitchTestCallbackEventImpl connectionReadyCallback = new SwitchTestCallbackEventImpl(); - connectionReadyCallback.setCallable(new Callable() { - @Override - public Void call() throws Exception { - connectionConductor.onConnectionReady(); - return null; - } - }); - return connectionReadyCallback; - } - -}