1 package org.opendaylight.controller.sal.binding.test.connect.dom;
3 import static junit.framework.Assert.assertNotNull;
5 import java.util.concurrent.Future;
7 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
8 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
16 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.opendaylight.yangtools.yang.common.RpcResult;
20 import com.google.common.collect.HashMultimap;
21 import com.google.common.collect.Multimap;
23 public class MessageCapturingFlowService implements SalFlowService, AutoCloseable {
25 private Future<RpcResult<AddFlowOutput>> addFlowResult;
26 private Future<RpcResult<RemoveFlowOutput>> removeFlowResult;
27 private Future<RpcResult<UpdateFlowOutput>> updateFlowResult;
29 private final Multimap<InstanceIdentifier<?>, AddFlowInput> receivedAddFlows = HashMultimap.create();
30 private final Multimap<InstanceIdentifier<?>, RemoveFlowInput> receivedRemoveFlows = HashMultimap.create();
31 private final Multimap<InstanceIdentifier<?>, UpdateFlowInput> receivedUpdateFlows = HashMultimap.create();
32 private RoutedRpcRegistration<SalFlowService> registration;
35 public Future<RpcResult<AddFlowOutput>> addFlow(AddFlowInput arg0) {
36 receivedAddFlows.put(arg0.getNode().getValue(), arg0);
41 public Future<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput arg0) {
42 receivedRemoveFlows.put(arg0.getNode().getValue(), arg0);
43 return removeFlowResult;
47 public Future<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput arg0) {
48 receivedUpdateFlows.put(arg0.getNode().getValue(), arg0);
49 return updateFlowResult;
52 public Future<RpcResult<AddFlowOutput>> getAddFlowResult() {
56 public MessageCapturingFlowService setAddFlowResult(Future<RpcResult<AddFlowOutput>> addFlowResult) {
57 this.addFlowResult = addFlowResult;
61 public Future<RpcResult<RemoveFlowOutput>> getRemoveFlowResult() {
62 return removeFlowResult;
65 public MessageCapturingFlowService setRemoveFlowResult(Future<RpcResult<RemoveFlowOutput>> removeFlowResult) {
66 this.removeFlowResult = removeFlowResult;
70 public Future<RpcResult<UpdateFlowOutput>> getUpdateFlowResult() {
71 return updateFlowResult;
74 public MessageCapturingFlowService setUpdateFlowResult(Future<RpcResult<UpdateFlowOutput>> updateFlowResult) {
75 this.updateFlowResult = updateFlowResult;
79 public Multimap<InstanceIdentifier<?>, AddFlowInput> getReceivedAddFlows() {
80 return receivedAddFlows;
83 public Multimap<InstanceIdentifier<?>, RemoveFlowInput> getReceivedRemoveFlows() {
84 return receivedRemoveFlows;
87 public Multimap<InstanceIdentifier<?>, UpdateFlowInput> getReceivedUpdateFlows() {
88 return receivedUpdateFlows;
91 public MessageCapturingFlowService registerTo(RpcProviderRegistry registry) {
92 registration = registry.addRoutedRpcImplementation(SalFlowService.class, this);
93 assertNotNull(registration);
97 public void close() throws Exception {
101 public MessageCapturingFlowService registerPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
102 registration.registerPath(context, path);
106 public MessageCapturingFlowService unregisterPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
107 registration.unregisterPath(context, path);
111 public static MessageCapturingFlowService create() {
112 return new MessageCapturingFlowService();
115 public static MessageCapturingFlowService create(RpcProviderRegistry registry) {
116 MessageCapturingFlowService ret = new MessageCapturingFlowService();
117 ret.registerTo(registry);