Skip to content

Commit a46f521

Browse files
author
Libor Rysavy
committed
Fix work with relative paths in DataStoreService
1 parent 5d581da commit a46f521

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/main/java/com/gooddata/UriPrefixer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import org.springframework.web.util.UriComponentsBuilder;
77

8+
import java.io.File;
89
import java.net.URI;
910

1011
import static com.gooddata.util.Validate.notEmpty;
@@ -52,8 +53,9 @@ public URI getUriPrefix() {
5253
*/
5354
public URI mergeUris(URI uri) {
5455
notNull(uri, "uri");
56+
final String path = new File(uriPrefix.getRawPath(), uri.getRawPath()).getAbsolutePath();
5557
return UriComponentsBuilder.fromUri(uriPrefix)
56-
.path(uri.getRawPath())
58+
.replacePath(path)
5759
.query(uri.getRawQuery())
5860
.fragment(uri.getRawFragment())
5961
.build().toUri();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (C) 2007-2014, GoodData(R) Corporation. All rights reserved.
3+
*/
4+
package com.gooddata;
5+
6+
import org.testng.annotations.Test;
7+
8+
import java.net.URI;
9+
10+
import static org.hamcrest.CoreMatchers.is;
11+
import static org.hamcrest.MatcherAssert.assertThat;
12+
13+
public class UriPrefixerTest {
14+
15+
@Test
16+
public void testMergeUrisWithSlash() throws Exception {
17+
final UriPrefixer prefixer = new UriPrefixer("http://localhost:1/uploads");
18+
final URI result = prefixer.mergeUris("/test");
19+
assertThat(result.toString(), is("http://localhost:1/uploads/test"));
20+
}
21+
22+
@Test
23+
public void testMergeUrisWithoutSlash() throws Exception {
24+
final UriPrefixer prefixer = new UriPrefixer("http://localhost:1/uploads");
25+
final URI result = prefixer.mergeUris("test");
26+
assertThat(result.toString(), is("http://localhost:1/uploads/test"));
27+
}
28+
}

src/test/java/com/gooddata/gdc/DataStoreServiceIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void shouldUploadAbsolute() throws Exception {
3636
gd.getDataStoreService().upload("/test", content);
3737
}
3838

39-
@Test(enabled = false) // todo #91
39+
@Test
4040
public void shouldUploadRelative() throws Exception {
4141
gd.getDataStoreService().upload("test", content);
4242
}

0 commit comments

Comments
 (0)