Improve NETCONF session ID handling
[netconf.git] / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / netconf / test / tool / operations / DefaultOperationsCreator.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.netconf.test.tool.operations;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Optional;
13 import java.util.Set;
14 import org.opendaylight.netconf.api.capability.Capability;
15 import org.opendaylight.netconf.server.api.operations.NetconfOperation;
16 import org.opendaylight.netconf.server.api.operations.NetconfOperationService;
17 import org.opendaylight.netconf.test.tool.rpc.DataList;
18 import org.opendaylight.netconf.test.tool.rpc.SimulatedCommit;
19 import org.opendaylight.netconf.test.tool.rpc.SimulatedCreateSubscription;
20 import org.opendaylight.netconf.test.tool.rpc.SimulatedDiscardChanges;
21 import org.opendaylight.netconf.test.tool.rpc.SimulatedEditConfig;
22 import org.opendaylight.netconf.test.tool.rpc.SimulatedGet;
23 import org.opendaylight.netconf.test.tool.rpc.SimulatedGetConfig;
24 import org.opendaylight.netconf.test.tool.rpc.SimulatedLock;
25 import org.opendaylight.netconf.test.tool.rpc.SimulatedUnLock;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
27
28 public final class DefaultOperationsCreator implements OperationsCreator {
29
30     @Override
31     public NetconfOperationService getNetconfOperationService(final Set<Capability> caps,
32             final SessionIdType sessionId) {
33         return new SimulatedOperationService(sessionId);
34     }
35
36     static class SimulatedOperationService implements NetconfOperationService {
37         private final SessionIdType currentSessionId;
38
39         SimulatedOperationService(final SessionIdType currentSessionId) {
40             this.currentSessionId = requireNonNull(currentSessionId);
41         }
42
43         @Override
44         public Set<NetconfOperation> getNetconfOperations() {
45             final DataList storage = new DataList();
46             final SimulatedGet sGet = new SimulatedGet(currentSessionId, storage);
47             final SimulatedEditConfig sEditConfig = new SimulatedEditConfig(currentSessionId, storage);
48             final SimulatedGetConfig sGetConfig = new SimulatedGetConfig(currentSessionId, storage, Optional.empty());
49             final SimulatedCommit sCommit = new SimulatedCommit(currentSessionId);
50             final SimulatedLock sLock = new SimulatedLock(currentSessionId);
51             final SimulatedUnLock sUnlock = new SimulatedUnLock(currentSessionId);
52             final SimulatedCreateSubscription sCreateSubs = new SimulatedCreateSubscription(currentSessionId,
53                 Optional.empty());
54             final SimulatedDiscardChanges sDiscardChanges = new SimulatedDiscardChanges(currentSessionId);
55             return Set.of(sGet, sGetConfig, sEditConfig, sCommit, sLock, sUnlock, sCreateSubs, sDiscardChanges);
56         }
57
58         @Override
59         public void close() {
60         }
61     }
62 }