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

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.