| // Copyright (C) 2023 GerritForge Ltd. |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package com.gerritforge.gerrit.modules.virtualhost; |
| |
| import static com.google.common.truth.Truth.assertThat; |
| |
| import java.net.URI; |
| import java.util.Optional; |
| import org.junit.Test; |
| |
| public class VirtualHostHttpCanonicalWebUrlProviderTest { |
| @Test |
| public void buildFromServerName() { |
| URI baseUri = URI.create("http://failure.com/"); |
| String actual = |
| VirtualHostHttpCanonicalWebUrlProvider.getVirtualHostHttpCanonicalWebUrl( |
| baseUri, Optional.of("gerrithub.io")); |
| |
| assertThat(actual).isEqualTo("http://gerrithub.io/"); |
| } |
| |
| @Test |
| public void fallbackToHttpCanonicalUrl() { |
| URI baseUri = URI.create("https://dom0.com/"); |
| String actual = |
| VirtualHostHttpCanonicalWebUrlProvider.getVirtualHostHttpCanonicalWebUrl( |
| baseUri, Optional.empty()); |
| |
| assertThat(actual).isEqualTo("https://dom0.com/"); |
| } |
| |
| @Test |
| public void copyPortNumberFromCanonicalUrl() { |
| URI baseUri = URI.create("http://localhost:8080/"); |
| String actual = |
| VirtualHostHttpCanonicalWebUrlProvider.getVirtualHostHttpCanonicalWebUrl( |
| baseUri, Optional.of("second.localhost")); |
| |
| assertThat(actual).isEqualTo("http://second.localhost:8080/"); |
| } |
| } |