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 java.util.concurrent.Future;
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;
23 import com.google.common.collect.HashMultimap;
24 import com.google.common.collect.Multimap;
26 public class MessageCapturingFlowService implements OpendaylightOfMigrationTestModelService, AutoCloseable {
28 private Future<RpcResult<KnockKnockOutput>> knockKnockResult;
30 private final Multimap<InstanceIdentifier<?>, KnockKnockInput> receivedKnocks = HashMultimap.create();
31 private RoutedRpcRegistration<OpendaylightOfMigrationTestModelService> registration;
33 public Future<RpcResult<KnockKnockOutput>> getKnockKnockResult() {
34 return knockKnockResult;
37 public MessageCapturingFlowService setKnockKnockResult(Future<RpcResult<KnockKnockOutput>> kkOutput) {
38 this.knockKnockResult = kkOutput;
42 public Multimap<InstanceIdentifier<?>, KnockKnockInput> getReceivedKnocks() {
43 return receivedKnocks;
46 public MessageCapturingFlowService registerTo(RpcProviderRegistry registry) {
47 registration = registry.addRoutedRpcImplementation(OpendaylightOfMigrationTestModelService.class, this);
48 assertNotNull(registration);
52 public void close() throws Exception {
56 public MessageCapturingFlowService registerPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
57 registration.registerPath(context, path);
61 public MessageCapturingFlowService unregisterPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
62 registration.unregisterPath(context, path);
66 public static MessageCapturingFlowService create() {
67 return new MessageCapturingFlowService();
70 public static MessageCapturingFlowService create(RpcProviderRegistry registry) {
71 MessageCapturingFlowService ret = new MessageCapturingFlowService();
72 ret.registerTo(registry);
77 public Future<RpcResult<KnockKnockOutput>> knockKnock(KnockKnockInput input) {
78 receivedKnocks.put(input.getKnockerId(), input);
79 return knockKnockResult;