Skip to content

Commit 5a83d8a

Browse files
author
TanyaEf
committed
Updated BundlesService, InputControlsService
1 parent 1a2bf7c commit 5a83d8a

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

src/main/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/bundles/BundlesService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public BundlesService forLocale(String locale) {
4949
}
5050

5151
public BundlesService forLocale(Locale locale) {
52-
this.locale = locale;
52+
if (locale != null) {
53+
this.locale = locale;
54+
}
5355
return this;
5456
}
5557

@@ -65,7 +67,10 @@ private JerseyRequest<Map<String, String>> buildBundleRequest(String bundleName)
6567
JerseyRequest<Map<String, String>> request =
6668
JerseyRequest.buildRequest(sessionStorage, new GenericType<Map<String, String>>() {
6769
}, new String[]{"/bundles", bundleName}, new DefaultErrorHandler());
68-
request.setAccept(MediaType.APPLICATION_JSON).addHeader("Accept-Language", locale.toString().replace('_', '-'));
70+
request.setAccept(MediaType.APPLICATION_JSON);
71+
if (!"".equals(this.locale.getLanguage())) {
72+
request.addHeader("Accept-Language", locale.toString().replace('_', '-'));
73+
}
6974
return request;
7075
}
7176

@@ -80,5 +85,4 @@ private JerseyRequest<Map<String, Map<String, String>>> buildBundlesRequest() {
8085
}
8186
return request;
8287
}
83-
8488
}

src/main/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/inputControls/InputControlsAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ public class InputControlsAdapter extends AbstractAdapter{
2020

2121
public InputControlsAdapter container(String uri) {
2222
this.containerUri = uri;
23-
if (containerUri == null) {
24-
throw new MandatoryParameterNotFoundException("Uri of container should be specified");
25-
}
2623
return this;
2724
}
2825

@@ -49,6 +46,9 @@ public OperationResult<ReportInputControlsListWrapper> reorder(List<ReportInputC
4946
}
5047

5148
private JerseyRequest<ReportInputControlsListWrapper> buildRequest(){
49+
if (containerUri == null) {
50+
throw new MandatoryParameterNotFoundException("Uri of container should be specified");
51+
}
5252
JerseyRequest<ReportInputControlsListWrapper> request = JerseyRequest.buildRequest(sessionStorage,
5353
ReportInputControlsListWrapper.class,
5454
new String[]{"/reports", containerUri, "/inputControls"},

src/test/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/bundles/BundlesServiceTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,22 @@ public void should_not_invoke_adding_language_by_empty_locale() throws Exception
214214
}), eq(new String[]{"/bundles", "jasperserver_messages"}), any(DefaultErrorHandler.class));
215215
}
216216

217+
@Test
218+
public void should_set_default_locale_if_string_locale_is_null() throws Exception {
219+
//given
220+
Locale defaultLocale = Locale.getDefault();
221+
//when
222+
service.forLocale((String) null);
223+
//then
224+
assertEquals(defaultLocale, Whitebox.getInternalState(service, "locale"));
225+
}
217226

218227
@Test
219-
public void should_set_default_locale() throws Exception {
228+
public void should_set_default_locale_if_instance_locale_is_null() throws Exception {
220229
//given
221230
Locale defaultLocale = Locale.getDefault();
222231
//when
223-
service.forLocale((String)null);
232+
service.forLocale((Locale)null);
224233
//then
225234
assertEquals(defaultLocale, Whitebox.getInternalState(service, "locale"));
226235
}

src/test/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/inputControls/InputControlsAdapterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void before() {
5959
@Test(expectedExceptions = MandatoryParameterNotFoundException.class)
6060
public void should_throw_an_exception_when_uri_is_null() {
6161
// When
62-
new InputControlsAdapter(sessionStorageMock).container(null);
62+
new InputControlsAdapter(sessionStorageMock).container(null).get();
6363
// Then
6464
// should be thrown an exception
6565
}

0 commit comments

Comments
 (0)