2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.binding.test.connect.dom;
10 import static org.junit.Assert.assertNotNull;
12 import java.util.concurrent.Future;
14 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
23 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.opendaylight.yangtools.yang.common.RpcResult;
27 import com.google.common.collect.HashMultimap;
28 import com.google.common.collect.Multimap;
30 public class MessageCapturingFlowService implements SalFlowService, AutoCloseable {
32 private Future<RpcResult<AddFlowOutput>> addFlowResult;
33 private Future<RpcResult<RemoveFlowOutput>> removeFlowResult;
34 private Future<RpcResult<UpdateFlowOutput>> updateFlowResult;
36 private final Multimap<InstanceIdentifier<?>, AddFlowInput> receivedAddFlows = HashMultimap.create();
37 private final Multimap<InstanceIdentifier<?>, RemoveFlowInput> receivedRemoveFlows = HashMultimap.create();
38 private final Multimap<InstanceIdentifier<?>, UpdateFlowInput> receivedUpdateFlows = HashMultimap.create();
39 private RoutedRpcRegistration<SalFlowService> registration;
42 public Future<RpcResult<AddFlowOutput>> addFlow(AddFlowInput arg0) {
43 receivedAddFlows.put(arg0.getNode().getValue(), arg0);
48 public Future<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput arg0) {
49 receivedRemoveFlows.put(arg0.getNode().getValue(), arg0);
50 return removeFlowResult;
54 public Future<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput arg0) {
55 receivedUpdateFlows.put(arg0.getNode().getValue(), arg0);
56 return updateFlowResult;
59 public Future<RpcResult<AddFlowOutput>> getAddFlowResult() {
63 public MessageCapturingFlowService setAddFlowResult(Future<RpcResult<AddFlowOutput>> addFlowResult) {
64 this.addFlowResult = addFlowResult;
68 public Future<RpcResult<RemoveFlowOutput>> getRemoveFlowResult() {
69 return removeFlowResult;
72 public MessageCapturingFlowService setRemoveFlowResult(Future<RpcResult<RemoveFlowOutput>> removeFlowResult) {
73 this.removeFlowResult = removeFlowResult;
77 public Future<RpcResult<UpdateFlowOutput>> getUpdateFlowResult() {
78 return updateFlowResult;
81 public MessageCapturingFlowService setUpdateFlowResult(Future<RpcResult<UpdateFlowOutput>> updateFlowResult) {
82 this.updateFlowResult = updateFlowResult;
86 public Multimap<InstanceIdentifier<?>, AddFlowInput> getReceivedAddFlows() {
87 return receivedAddFlows;
90 public Multimap<InstanceIdentifier<?>, RemoveFlowInput> getReceivedRemoveFlows() {
91 return receivedRemoveFlows;
94 public Multimap<InstanceIdentifier<?>, UpdateFlowInput> getReceivedUpdateFlows() {
95 return receivedUpdateFlows;
98 public MessageCapturingFlowService registerTo(RpcProviderRegistry registry) {
99 registration = registry.addRoutedRpcImplementation(SalFlowService.class, this);
100 assertNotNull(registration);
104 public void close() throws Exception {
105 registration.close();
108 public MessageCapturingFlowService registerPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
109 registration.registerPath(context, path);
113 public MessageCapturingFlowService unregisterPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
114 registration.unregisterPath(context, path);
118 public static MessageCapturingFlowService create() {
119 return new MessageCapturingFlowService();
122 public static MessageCapturingFlowService create(RpcProviderRegistry registry) {
123 MessageCapturingFlowService ret = new MessageCapturingFlowService();
124 ret.registerTo(registry);