|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.sshd.sftp.client.fs; |
| 21 | + |
| 22 | +import java.net.URI; |
| 23 | +import java.util.stream.Stream; |
| 24 | + |
| 25 | +import org.apache.sshd.util.test.JUnitTestSupport; |
| 26 | +import org.junit.jupiter.api.MethodOrderer.MethodName; |
| 27 | +import org.junit.jupiter.api.Tag; |
| 28 | +import org.junit.jupiter.api.TestMethodOrder; |
| 29 | +import org.junit.jupiter.params.ParameterizedTest; |
| 30 | +import org.junit.jupiter.params.provider.Arguments; |
| 31 | +import org.junit.jupiter.params.provider.MethodSource; |
| 32 | + |
| 33 | +@TestMethodOrder(MethodName.class) |
| 34 | +@Tag("NoIoTestCase") |
| 35 | +class SftpFileSystemProviderURITest extends JUnitTestSupport { |
| 36 | + |
| 37 | + static Stream<Arguments> parameters() { |
| 38 | + return Stream.of( // |
| 39 | + Arguments.of(URI.create("sftp://username:password@host"), "host:22:username"), |
| 40 | + Arguments.of(URI.create("sftp://username:password@host:22"), "host:22:username"), |
| 41 | + Arguments.of(URI.create("sftp://username@host"), "host:22:username"), |
| 42 | + Arguments.of(URI.create("sftp://username:password@host:2222"), "host:2222:username"), |
| 43 | + Arguments.of(URI.create("sftp://username:password@host:22/path"), "host:22:username")); |
| 44 | + } |
| 45 | + |
| 46 | + @MethodSource("parameters") |
| 47 | + @ParameterizedTest(name = "uri={0}") |
| 48 | + void getFileSystemIdentifierFromUri(URI uri, String expected) { |
| 49 | + assertEquals(expected, SftpFileSystemProvider.getFileSystemIdentifier(uri), "Mismatched filesystem identifier"); |
| 50 | + } |
| 51 | + |
| 52 | + static Stream<Arguments> invalid() { |
| 53 | + return Stream.of( // |
| 54 | + Arguments.of(URI.create(""), "Host not provided"), |
| 55 | + Arguments.of(URI.create("sftp://host:22"), "UserInfo not provided"), |
| 56 | + Arguments.of(URI.create("sftp://@host:22"), "UserInfo not provided")); |
| 57 | + } |
| 58 | + |
| 59 | + @MethodSource("invalid") |
| 60 | + @ParameterizedTest(name = "uri={0}") |
| 61 | + void getFileSystemIdentifierFromInvalidUri(URI uri, String message) { |
| 62 | + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, |
| 63 | + () -> SftpFileSystemProvider.getFileSystemIdentifier(uri)); |
| 64 | + assertEquals(message, exception.getMessage()); |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments