-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'url-storage-path' into 'master'
Use correct storagePath by default See merge request ghsc/hazdev/pdl!140
- Loading branch information
Showing
5 changed files
with
56 additions
and
4 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
53 changes: 53 additions & 0 deletions
53
src/test/java/gov/usgs/earthquake/distribution/URLProductStorageTest.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,53 @@ | ||
package gov.usgs.earthquake.distribution; | ||
|
||
import gov.usgs.earthquake.product.ProductId; | ||
import gov.usgs.util.Config; | ||
|
||
import java.net.URL; | ||
import java.util.Date; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
|
||
public class URLProductStorageTest { | ||
|
||
/** | ||
* Test that storage path is configured properly by default | ||
* and includes all product id components (so url is unique per product). | ||
*/ | ||
@Test | ||
public void testDefaultStoragePath() throws Exception { | ||
URLProductStorage storage = new URLProductStorage(); | ||
Config config = new Config(); | ||
config.setProperty(URLProductStorage.URL_PROPERTY_NAME, "http://testserver/product/"); | ||
storage.configure(config); | ||
|
||
ProductId id = new ProductId("example_source", "example_type", "example_code", new Date()); | ||
String path = storage.getProductPath(id); | ||
Assert.assertTrue("contains source", path.contains("example_source")); | ||
Assert.assertTrue("contains type", path.contains("example_type")); | ||
Assert.assertTrue("contains code", path.contains("example_code")); | ||
Assert.assertTrue( | ||
"contains updateTime", | ||
path.contains("" + id.getUpdateTime().getTime())); | ||
} | ||
|
||
/** | ||
* Test that url is constructed by combining base url and product path. | ||
*/ | ||
@Test | ||
public void testGetProductUrl() throws Exception { | ||
URLProductStorage storage = new URLProductStorage(); | ||
Config config = new Config(); | ||
config.setProperty(URLProductStorage.URL_PROPERTY_NAME, "http://testserver/product/"); | ||
storage.configure(config); | ||
|
||
ProductId id = new ProductId("source", "type", "code", new Date()); | ||
URL url = storage.getProductURL(id); | ||
Assert.assertEquals("Computes URL", | ||
url.toExternalForm(), | ||
"http://testserver/product/" + storage.getProductPath(id)); | ||
} | ||
|
||
} |