forked from opensearch-project/geospatial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set User-Agent in http request (opensearch-project#300)
Signed-off-by: Heemin Kim <[email protected]>
- Loading branch information
Showing
10 changed files
with
128 additions
and
31 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
15 changes: 15 additions & 0 deletions
15
src/main/java/org/opensearch/geospatial/shared/Constants.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,15 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.geospatial.shared; | ||
|
||
import java.util.Locale; | ||
|
||
import org.opensearch.Version; | ||
|
||
public class Constants { | ||
public static final String USER_AGENT_KEY = "User-Agent"; | ||
public static final String USER_AGENT_VALUE = String.format(Locale.ROOT, "OpenSearch/%s vanilla", Version.CURRENT.toString()); | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/test/java/org/opensearch/geospatial/ip2geo/common/DatasourceManifestTests.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,38 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.geospatial.ip2geo.common; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.net.URLConnection; | ||
|
||
import lombok.SneakyThrows; | ||
|
||
import org.opensearch.common.SuppressForbidden; | ||
import org.opensearch.geospatial.ip2geo.Ip2GeoTestCase; | ||
import org.opensearch.geospatial.shared.Constants; | ||
|
||
@SuppressForbidden(reason = "unit test") | ||
public class DatasourceManifestTests extends Ip2GeoTestCase { | ||
|
||
@SneakyThrows | ||
public void testInternalBuild_whenCalled_thenCorrectUserAgentValueIsSet() { | ||
URLConnection connection = mock(URLConnection.class); | ||
File manifestFile = new File(this.getClass().getClassLoader().getResource("ip2geo/manifest.json").getFile()); | ||
when(connection.getInputStream()).thenReturn(new FileInputStream(manifestFile)); | ||
|
||
// Run | ||
DatasourceManifest manifest = DatasourceManifest.Builder.internalBuild(connection); | ||
|
||
// Verify | ||
verify(connection).addRequestProperty(Constants.USER_AGENT_KEY, Constants.USER_AGENT_VALUE); | ||
assertEquals("https://test.com/db.zip", manifest.getUrl()); | ||
} | ||
} |
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