/* * 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.controller.sal.binding.test.connect.dom; import static junit.framework.Assert.assertNotNull; import java.util.concurrent.Future; import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput; import org.opendaylight.yangtools.yang.binding.BaseIdentity; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; public class MessageCapturingFlowService implements SalFlowService, AutoCloseable { private Future> addFlowResult; private Future> removeFlowResult; private Future> updateFlowResult; private final Multimap, AddFlowInput> receivedAddFlows = HashMultimap.create(); private final Multimap, RemoveFlowInput> receivedRemoveFlows = HashMultimap.create(); private final Multimap, UpdateFlowInput> receivedUpdateFlows = HashMultimap.create(); private RoutedRpcRegistration registration; @Override public Future> addFlow(AddFlowInput arg0) { receivedAddFlows.put(arg0.getNode().getValue(), arg0); return addFlowResult; } @Override public Future> removeFlow(RemoveFlowInput arg0) { receivedRemoveFlows.put(arg0.getNode().getValue(), arg0); return removeFlowResult; } @Override public Future> updateFlow(UpdateFlowInput arg0) { receivedUpdateFlows.put(arg0.getNode().getValue(), arg0); return updateFlowResult; } public Future> getAddFlowResult() { return addFlowResult; } public MessageCapturingFlowService setAddFlowResult(Future> addFlowResult) { this.addFlowResult = addFlowResult; return this; } public Future> getRemoveFlowResult() { return removeFlowResult; } public MessageCapturingFlowService setRemoveFlowResult(Future> removeFlowResult) { this.removeFlowResult = removeFlowResult; return this; } public Future> getUpdateFlowResult() { return updateFlowResult; } public MessageCapturingFlowService setUpdateFlowResult(Future> updateFlowResult) { this.updateFlowResult = updateFlowResult; return this; } public Multimap, AddFlowInput> getReceivedAddFlows() { return receivedAddFlows; } public Multimap, RemoveFlowInput> getReceivedRemoveFlows() { return receivedRemoveFlows; } public Multimap, UpdateFlowInput> getReceivedUpdateFlows() { return receivedUpdateFlows; } public MessageCapturingFlowService registerTo(RpcProviderRegistry registry) { registration = registry.addRoutedRpcImplementation(SalFlowService.class, this); assertNotNull(registration); return this; } public void close() throws Exception { registration.close(); } public MessageCapturingFlowService registerPath(Class context, InstanceIdentifier path) { registration.registerPath(context, path); return this; } public MessageCapturingFlowService unregisterPath(Class context, InstanceIdentifier path) { registration.unregisterPath(context, path); return this; } public static MessageCapturingFlowService create() { return new MessageCapturingFlowService(); } public static MessageCapturingFlowService create(RpcProviderRegistry registry) { MessageCapturingFlowService ret = new MessageCapturingFlowService(); ret.registerTo(registry); return ret; } }