import static java.util.Objects.requireNonNull;
-import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.ListenableFuture;
this.dataBroker = requireNonNull(dataBroker);
this.encryptionService = requireNonNull(encryptionService);
- reg = rpcProvider.registerRpcImplementations(getRpcClassToInstanceMap());
+ reg = rpcProvider.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
+ .put(RemoveKeystoreEntry.class, this::removeKeystoreEntry)
+ .put(AddKeystoreEntry.class, this::addKeystoreEntry)
+ .put(AddTrustedCertificate.class, this::addTrustedCertificate)
+ .put(RemoveTrustedCertificate.class, this::removeTrustedCertificate)
+ .put(AddPrivateKey.class, this::addPrivateKey)
+ .put(RemovePrivateKey.class, this::removePrivateKey)
+ .build());
LOG.info("NETCONF keystore service started");
}
return rpcResult;
}
- private ListenableFuture<RpcResult<AddTrustedCertificateOutput>> addTrustedCertificate(
+ @VisibleForTesting
+ ListenableFuture<RpcResult<AddTrustedCertificateOutput>> addTrustedCertificate(
final AddTrustedCertificateInput input) {
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
return rpcResult;
}
- private ListenableFuture<RpcResult<AddPrivateKeyOutput>> addPrivateKey(final AddPrivateKeyInput input) {
+ @VisibleForTesting
+ ListenableFuture<RpcResult<AddPrivateKeyOutput>> addPrivateKey(final AddPrivateKeyInput input) {
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
for (PrivateKey key: input.nonnullPrivateKey().values()) {
return rpcResult;
}
-
- public ClassToInstanceMap<Rpc<?, ?>> getRpcClassToInstanceMap() {
- return ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
- .put(RemoveKeystoreEntry.class, this::removeKeystoreEntry)
- .put(AddKeystoreEntry.class, this::addKeystoreEntry)
- .put(AddTrustedCertificate.class, this::addTrustedCertificate)
- .put(RemoveTrustedCertificate.class, this::removeTrustedCertificate)
- .put(AddPrivateKey.class, this::addPrivateKey)
- .put(RemovePrivateKey.class, this::removePrivateKey)
- .build();
- }
}
import org.opendaylight.mdsal.binding.api.WriteTransaction;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netconf.api.xml.XmlUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddPrivateKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddPrivateKeyInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddPrivateKeyInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddTrustedCertificate;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddTrustedCertificateInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddTrustedCertificateInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017._private.keys.PrivateKey;
doReturn(emptyFluentFuture()).when(writeTx).commit();
try (var keystoreService = new NetconfSalKeystoreRpcs(dataBroker, encryptionService, rpcProvider)) {
final AddPrivateKeyInput input = getPrivateKeyInput();
- keystoreService.getRpcClassToInstanceMap().getInstance(AddPrivateKey.class).invoke(input).get();
+ keystoreService.addPrivateKey(input).get();
verify(writeTx, times(input.nonnullPrivateKey().size()))
.merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class));
doReturn(emptyFluentFuture()).when(writeTx).commit();
try (var keystoreService = new NetconfSalKeystoreRpcs(dataBroker, encryptionService, rpcProvider)) {
final var input = getTrustedCertificateInput();
- keystoreService.getRpcClassToInstanceMap().getInstance(AddTrustedCertificate.class).invoke(input).get();
+ keystoreService.addTrustedCertificate(input).get();
verify(writeTx, times(input.nonnullTrustedCertificate().size()))
.merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class));