Migrate OSGI compendium reference
[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(
36             final ListenableFuture<RpcResult<KnockKnockOutput>> kkOutput) {
37         this.knockKnockResult = kkOutput;
38         return this;
39     }
40
41     public Multimap<InstanceIdentifier<?>, KnockKnockInput> getReceivedKnocks() {
42         return receivedKnocks;
43     }
44
45     public MessageCapturingFlowService registerTo(final RpcProviderRegistry registry) {
46         registration = registry.addRoutedRpcImplementation(OpendaylightOfMigrationTestModelService.class, this);
47         assertNotNull(registration);
48         return this;
49     }
50
51     @Override
52     public void close() {
53         registration.close();
54     }
55
56     public MessageCapturingFlowService registerPath(final Class<? extends BaseIdentity> context,
57             final InstanceIdentifier<?> path) {
58         registration.registerPath(context, path);
59         return this;
60     }
61
62     public MessageCapturingFlowService unregisterPath(final Class<? extends BaseIdentity> context,
63             final InstanceIdentifier<?> path) {
64         registration.unregisterPath(context, path);
65         return this;
66     }
67
68     public static MessageCapturingFlowService create() {
69         return new MessageCapturingFlowService();
70     }
71
72     public static MessageCapturingFlowService create(final RpcProviderRegistry registry) {
73         MessageCapturingFlowService ret = new MessageCapturingFlowService();
74         ret.registerTo(registry);
75         return ret;
76     }
77
78     @Override
79     public ListenableFuture<RpcResult<KnockKnockOutput>> knockKnock(final KnockKnockInput input) {
80         receivedKnocks.put(input.getKnockerId(), input);
81         return knockKnockResult;
82     }
83 }