Bulk-add copyright headers to java files
[controller.git] / opendaylight / md-sal / sal-binding-dom-it / src / test / java / org / opendaylight / controller / sal / binding / test / connect / dom / MessageCapturingFlowService.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.binding.test.connect.dom;
9
10 import static junit.framework.Assert.assertNotNull;
11
12 import java.util.concurrent.Future;
13
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;
26
27 import com.google.common.collect.HashMultimap;
28 import com.google.common.collect.Multimap;
29
30 public class MessageCapturingFlowService implements SalFlowService, AutoCloseable {
31
32     private Future<RpcResult<AddFlowOutput>> addFlowResult;
33     private Future<RpcResult<RemoveFlowOutput>> removeFlowResult;
34     private Future<RpcResult<UpdateFlowOutput>> updateFlowResult;
35
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;
40
41     @Override
42     public Future<RpcResult<AddFlowOutput>> addFlow(AddFlowInput arg0) {
43         receivedAddFlows.put(arg0.getNode().getValue(), arg0);
44         return addFlowResult;
45     }
46
47     @Override
48     public Future<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput arg0) {
49         receivedRemoveFlows.put(arg0.getNode().getValue(), arg0);
50         return removeFlowResult;
51     }
52
53     @Override
54     public Future<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput arg0) {
55         receivedUpdateFlows.put(arg0.getNode().getValue(), arg0);
56         return updateFlowResult;
57     }
58
59     public Future<RpcResult<AddFlowOutput>> getAddFlowResult() {
60         return addFlowResult;
61     }
62
63     public MessageCapturingFlowService setAddFlowResult(Future<RpcResult<AddFlowOutput>> addFlowResult) {
64         this.addFlowResult = addFlowResult;
65         return this;
66     }
67
68     public Future<RpcResult<RemoveFlowOutput>> getRemoveFlowResult() {
69         return removeFlowResult;
70     }
71
72     public MessageCapturingFlowService setRemoveFlowResult(Future<RpcResult<RemoveFlowOutput>> removeFlowResult) {
73         this.removeFlowResult = removeFlowResult;
74         return this;
75     }
76
77     public Future<RpcResult<UpdateFlowOutput>> getUpdateFlowResult() {
78         return updateFlowResult;
79     }
80
81     public MessageCapturingFlowService setUpdateFlowResult(Future<RpcResult<UpdateFlowOutput>> updateFlowResult) {
82         this.updateFlowResult = updateFlowResult;
83         return this;
84     }
85
86     public Multimap<InstanceIdentifier<?>, AddFlowInput> getReceivedAddFlows() {
87         return receivedAddFlows;
88     }
89
90     public Multimap<InstanceIdentifier<?>, RemoveFlowInput> getReceivedRemoveFlows() {
91         return receivedRemoveFlows;
92     }
93
94     public Multimap<InstanceIdentifier<?>, UpdateFlowInput> getReceivedUpdateFlows() {
95         return receivedUpdateFlows;
96     }
97
98     public MessageCapturingFlowService registerTo(RpcProviderRegistry registry) {
99         registration = registry.addRoutedRpcImplementation(SalFlowService.class, this);
100         assertNotNull(registration);
101         return this;
102     }
103
104     public void close() throws Exception {
105         registration.close();
106     }
107
108     public MessageCapturingFlowService registerPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
109         registration.registerPath(context, path);
110         return this;
111     }
112
113     public MessageCapturingFlowService unregisterPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
114         registration.unregisterPath(context, path);
115         return this;
116     }
117     
118     public static MessageCapturingFlowService create() {
119         return new MessageCapturingFlowService();
120     }
121     
122     public static MessageCapturingFlowService create(RpcProviderRegistry registry) {
123         MessageCapturingFlowService ret = new MessageCapturingFlowService();
124         ret.registerTo(registry);
125         return ret;
126     }
127     
128     
129 }