Merge "Bug 2682 - Switch sal-binding-dom-it to sal-test-model"
[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 org.junit.Assert.assertNotNull;
11
12 import java.util.concurrent.Future;
13
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
15 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.KnockKnockInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.KnockKnockOutput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.OpendaylightOfMigrationTestModelService;
19 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22
23 import com.google.common.collect.HashMultimap;
24 import com.google.common.collect.Multimap;
25
26 public class MessageCapturingFlowService implements OpendaylightOfMigrationTestModelService, AutoCloseable {
27
28     private Future<RpcResult<KnockKnockOutput>> knockKnockResult;
29
30     private final Multimap<InstanceIdentifier<?>, KnockKnockInput> receivedKnocks = HashMultimap.create();
31     private RoutedRpcRegistration<OpendaylightOfMigrationTestModelService> registration;
32
33     public Future<RpcResult<KnockKnockOutput>> getKnockKnockResult() {
34         return knockKnockResult;
35     }
36
37     public MessageCapturingFlowService setKnockKnockResult(Future<RpcResult<KnockKnockOutput>> kkOutput) {
38         this.knockKnockResult = kkOutput;
39         return this;
40     }
41
42     public Multimap<InstanceIdentifier<?>, KnockKnockInput> getReceivedKnocks() {
43         return receivedKnocks;
44     }
45
46     public MessageCapturingFlowService registerTo(RpcProviderRegistry registry) {
47         registration = registry.addRoutedRpcImplementation(OpendaylightOfMigrationTestModelService.class, this);
48         assertNotNull(registration);
49         return this;
50     }
51
52     public void close() throws Exception {
53         registration.close();
54     }
55
56     public MessageCapturingFlowService registerPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
57         registration.registerPath(context, path);
58         return this;
59     }
60
61     public MessageCapturingFlowService unregisterPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
62         registration.unregisterPath(context, path);
63         return this;
64     }
65
66     public static MessageCapturingFlowService create() {
67         return new MessageCapturingFlowService();
68     }
69
70     public static MessageCapturingFlowService create(RpcProviderRegistry registry) {
71         MessageCapturingFlowService ret = new MessageCapturingFlowService();
72         ret.registerTo(registry);
73         return ret;
74     }
75
76     @Override
77     public Future<RpcResult<KnockKnockOutput>> knockKnock(KnockKnockInput input) {
78         receivedKnocks.put(input.getKnockerId(), input);
79         return knockKnockResult;
80     }
81
82
83 }