2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.binding.test.connect.dom;
10 import static org.junit.Assert.assertNotNull;
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;
24 public class MessageCapturingFlowService implements OpendaylightOfMigrationTestModelService, AutoCloseable {
26 private ListenableFuture<RpcResult<KnockKnockOutput>> knockKnockResult;
28 private final Multimap<InstanceIdentifier<?>, KnockKnockInput> receivedKnocks = HashMultimap.create();
29 private RoutedRpcRegistration<OpendaylightOfMigrationTestModelService> registration;
31 public ListenableFuture<RpcResult<KnockKnockOutput>> getKnockKnockResult() {
32 return knockKnockResult;
35 public MessageCapturingFlowService setKnockKnockResult(
36 final ListenableFuture<RpcResult<KnockKnockOutput>> kkOutput) {
37 this.knockKnockResult = kkOutput;
41 public Multimap<InstanceIdentifier<?>, KnockKnockInput> getReceivedKnocks() {
42 return receivedKnocks;
45 public MessageCapturingFlowService registerTo(final RpcProviderRegistry registry) {
46 registration = registry.addRoutedRpcImplementation(OpendaylightOfMigrationTestModelService.class, this);
47 assertNotNull(registration);
56 public MessageCapturingFlowService registerPath(final Class<? extends BaseIdentity> context,
57 final InstanceIdentifier<?> path) {
58 registration.registerPath(context, path);
62 public MessageCapturingFlowService unregisterPath(final Class<? extends BaseIdentity> context,
63 final InstanceIdentifier<?> path) {
64 registration.unregisterPath(context, path);
68 public static MessageCapturingFlowService create() {
69 return new MessageCapturingFlowService();
72 public static MessageCapturingFlowService create(final RpcProviderRegistry registry) {
73 MessageCapturingFlowService ret = new MessageCapturingFlowService();
74 ret.registerTo(registry);
79 public ListenableFuture<RpcResult<KnockKnockOutput>> knockKnock(final KnockKnockInput input) {
80 receivedKnocks.put(input.getKnockerId(), input);
81 return knockKnockResult;