-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add test coverage for reachability implementations
- Loading branch information
Showing
11 changed files
with
115 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
core/src/main/java/ch/cyberduck/core/diagnostics/HostnameReachability.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package ch.cyberduck.core.diagnostics; | ||
|
||
/* | ||
* Copyright (c) 2002-2024 iterate GmbH. All rights reserved. | ||
* https://cyberduck.io/ | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
import ch.cyberduck.core.Host; | ||
import ch.cyberduck.core.HostnameConfigurator; | ||
import ch.cyberduck.core.exception.BackgroundException; | ||
import ch.cyberduck.core.exception.ResolveFailedException; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class HostnameReachability implements Reachability { | ||
private static final Logger log = LogManager.getLogger(HostnameReachability.class); | ||
|
||
@Override | ||
public void test(final Host bookmark) throws BackgroundException { | ||
final HostnameConfigurator configurator = bookmark.getProtocol().getFeature(HostnameConfigurator.class); | ||
final String hostname = configurator.getHostname(bookmark.getHostname()); | ||
if(StringUtils.isBlank(hostname)) { | ||
if(log.isWarnEnabled()) { | ||
log.warn(String.format("Missing hostname in %s", bookmark)); | ||
} | ||
throw new ResolveFailedException(); | ||
} | ||
} | ||
|
||
@Override | ||
public Monitor monitor(final Host bookmark, final Callback callback) { | ||
return Monitor.disabled; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
core/src/test/java/ch/cyberduck/core/diagnostics/HostnameReachabilityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package ch.cyberduck.core.diagnostics; | ||
|
||
/* | ||
* Copyright (c) 2002-2024 iterate GmbH. All rights reserved. | ||
* https://cyberduck.io/ | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
import ch.cyberduck.core.Host; | ||
import ch.cyberduck.core.Scheme; | ||
import ch.cyberduck.core.TestProtocol; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class HostnameReachabilityTest { | ||
|
||
@Test | ||
public void testIsReachable() { | ||
final Reachability r = new HostnameReachability(); | ||
assertFalse(r.isReachable( | ||
new Host(new TestProtocol(Scheme.http)) | ||
)); | ||
assertTrue(r.isReachable( | ||
new Host(new TestProtocol(Scheme.http), "cyberduck.io") | ||
)); | ||
assertTrue(r.isReachable( | ||
new Host(new TestProtocol(Scheme.http) { | ||
@Override | ||
public String getDefaultHostname() { | ||
return "cyberduck.io"; | ||
} | ||
}) | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters