Skip to content

Commit f6be420

Browse files
committed
Improve handling when self link is not present
1 parent 7c24a09 commit f6be420

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

gooddata-java/src/main/java/com/gooddata/sdk/service/connector/ConnectorService.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2004-2019, GoodData(R) Corporation. All rights reserved.
2+
* Copyright (C) 2004-2021, GoodData(R) Corporation. All rights reserved.
33
* This source code is licensed under the BSD-style license found in the
44
* LICENSE.txt file in the root directory of this source tree.
55
*/
@@ -22,8 +22,8 @@
2222
import java.io.IOException;
2323
import java.util.Collection;
2424
import java.util.Map;
25+
import java.util.Optional;
2526

26-
import static com.gooddata.sdk.common.util.Validate.isTrue;
2727
import static com.gooddata.sdk.common.util.Validate.notNull;
2828
import static com.gooddata.sdk.common.util.Validate.notNullState;
2929
import static java.lang.String.format;
@@ -267,13 +267,17 @@ public FutureResult<ProcessStatus> getProcessStatus(final IntegrationProcessStat
267267
* You should use the result of {@link #scheduleZendesk4Reload} to see changes in {@link Reload#getStatus()} and
268268
* {@link Reload#getProcessId()} or retrieve process URI {@link Reload#getProcessUri()}.
269269
*
270-
* @param reload existing reload.
270+
* @param reload existing reload (self link must be present).
271271
* @return same reload with refreshed properties (status, processId, process URI)
272272
*/
273273
public Reload getZendesk4Reload(final Reload reload) {
274274
notNull(reload, "reload");
275-
isTrue(reload.getUri().isPresent(), "reload.uri");
276-
return getZendesk4ReloadByUri(reload.getUri().get());
275+
final Optional<String> reloadUri = reload.getUri();
276+
if (reloadUri.isPresent()) {
277+
return getZendesk4ReloadByUri(reloadUri.get());
278+
} else {
279+
throw new IllegalArgumentException("Self link in the Reload must be present!");
280+
}
277281
}
278282

279283
/**
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (C) 2004-2021, GoodData(R) Corporation. All rights reserved.
3+
* This source code is licensed under the BSD-style license found in the
4+
* LICENSE.txt file in the root directory of this source tree.
5+
*/
6+
7+
package com.gooddata.sdk.service.connector
8+
9+
import com.gooddata.sdk.model.connector.Reload
10+
import com.gooddata.sdk.service.GoodDataSettings
11+
import com.gooddata.sdk.service.project.ProjectService
12+
import org.springframework.web.client.RestTemplate
13+
import spock.lang.Specification
14+
import spock.lang.Subject
15+
16+
import static java.util.Collections.emptyMap
17+
18+
class ConnectorServiceTest extends Specification {
19+
20+
@Subject
21+
def service = new ConnectorService(Mock(RestTemplate), Mock(ProjectService), Mock(GoodDataSettings))
22+
23+
def "getZendesk4Reload should throw when Reload is null"() {
24+
when:
25+
service.getZendesk4Reload(null)
26+
27+
then:
28+
thrown(IllegalArgumentException)
29+
}
30+
31+
def "getZendesk4Reload should throw when Reload does not contain self URI"() {
32+
when:
33+
service.getZendesk4Reload(new Reload(emptyMap()))
34+
35+
then:
36+
thrown(IllegalArgumentException)
37+
}
38+
}

0 commit comments

Comments
 (0)