Skip to content

Commit 36d411f

Browse files
author
TanyaEf
committed
Updated RestClientConfigurationTest
1 parent 43b0ca4 commit 36d411f

File tree

5 files changed

+255
-69
lines changed

5 files changed

+255
-69
lines changed

src/integration-test/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/reporting/ReportingServiceIT.java

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import org.testng.annotations.AfterMethod;
88
import org.testng.annotations.BeforeMethod;
99
import org.testng.annotations.Test;
10-
import sun.org.mozilla.javascript.internal.ast.WhileLoop;
1110

12-
import java.io.*;
11+
import java.io.FileOutputStream;
12+
import java.io.IOException;
13+
import java.io.InputStream;
14+
import java.io.OutputStream;
1315

1416
public class ReportingServiceIT {
1517

@@ -40,34 +42,55 @@ public void should_return_proper_entity_if_pass_jrprint_report_output_format() {
4042
InputStream entity = result.getEntity();
4143
/** Then **/
4244
Assert.assertNotNull(entity);
45+
}
4346

44-
// OutputStream output = null;
45-
// try {
46-
// output = new FileOutputStream("file.pdf");
47-
// int i = 0;
48-
// while (i != -1) {
49-
// i = entity.read();
50-
// output.write(i);
51-
// output.flush();
52-
//
53-
// }
54-
// } catch (IOException e) {
55-
// e.printStackTrace();
56-
// } finally {
57-
//
58-
// try {
59-
// entity.close();
60-
// output.close();
61-
// } catch (IOException e) {
62-
// e.printStackTrace();
63-
// }
64-
// }
47+
@Test
48+
public void should_return_proper_entity_() {
6549

50+
/** When **/
51+
OperationResult<InputStream> result = client
52+
.authenticate("superuser", "superuser")
53+
.reportingService()
54+
.report("/organizations/organization_1/adhoc/topics/Cascading_multi_select_topic")
55+
.prepareForRun(ReportOutputFormat.PDF, 1)
56+
.parameter("Cascading_state_multi_select", "CA")
57+
.parameter("Cascading_state_multi_select", "OR", "WA")
58+
.parameter("Cascading_name_single_select", "Adams-Steen Transportation Holdings")
59+
.parameter("Country_multi_select", "USA")
60+
.run();
61+
62+
InputStream entity = result.getEntity();
63+
/** Then **/
64+
Assert.assertNotNull(entity);
6665
}
6766

6867
@AfterMethod
6968
public void after() {
7069
client = null;
7170
configuration = null;
7271
}
72+
73+
private void reportToPdf(InputStream entity) {
74+
OutputStream output = null;
75+
try {
76+
output = new FileOutputStream("file.pdf");
77+
int i = 0;
78+
while (i != -1) {
79+
i = entity.read();
80+
output.write(i);
81+
output.flush();
82+
83+
}
84+
} catch (IOException e) {
85+
e.printStackTrace();
86+
} finally {
87+
88+
try {
89+
entity.close();
90+
output.close();
91+
} catch (IOException e) {
92+
e.printStackTrace();
93+
}
94+
}
95+
}
7396
}

src/integration-test/java/com/jaspersoft/jasperserver/jaxrs/client/core/RestClientConfigurationIT.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,24 @@ public void should_load_configuration_from_file() {
2929
assertNotNull(config.getAcceptMimeType());
3030
assertNotNull(config.getContentMimeType());
3131
assertTrue(config.getLogHttp());
32-
assertFalse(config.getLogHttpEntity());
33-
assertFalse(config.getLogHttpEntity());
32+
assertTrue(config.getLogHttpEntity());
3433
assertFalse(config.getRestrictedHttpMethods());
3534
assertEquals(config.getJrsVersion(), JRSVersion.v6_0_0);
3635
assertEquals(config.getAuthenticationType(), AuthenticationType.REST);
3736
}
3837

39-
@AfterMethod
38+
39+
@Test
40+
public void should_throw_nullPointerException() {
41+
try {
42+
config = RestClientConfiguration.loadConfiguration("wrong_path");
43+
} catch (NullPointerException ex) {
44+
assertNotNull(ex);
45+
assertSame(ex, new NullPointerException());
46+
}
47+
}
48+
49+
@AfterMethod
4050
public void afterTest() {
4151
config = null;
4252
}

src/main/java/com/jaspersoft/jasperserver/jaxrs/client/core/RestClientConfiguration.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@
3030
import java.security.cert.CertificateException;
3131
import java.security.cert.X509Certificate;
3232
import java.util.Properties;
33-
import java.util.regex.Matcher;
3433
import java.util.regex.Pattern;
3534

3635
public class RestClientConfiguration {
3736

3837
private static final Log log = LogFactory.getLog(RestClientConfiguration.class);
3938
private static final Pattern URL_PATTERN = Pattern.compile("\\b(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");
4039
private static final Pattern VERSION_PATTERN = Pattern.compile("^[v]\\d[_]\\d[_]\\d$");
41-
private static final Pattern BOOLEAN_PATTERN = Pattern.compile("^[true|false]$");
40+
private static final Pattern BOOLEAN_PATTERN = Pattern.compile("^(true|false)$", Pattern.CASE_INSENSITIVE);
4241
private static final Pattern NUMBER_PATTERN = Pattern.compile("^\\d+$");
4342

4443
private String jasperReportsServerUrl;
@@ -57,7 +56,7 @@ public class RestClientConfiguration {
5756

5857
public RestClientConfiguration(String jasperReportsServerUrl) {
5958
this();
60-
setJasperReportsServerUrl(jasperReportsServerUrl);
59+
setJasperReportsServerUrl(jasperReportsServerUrl);
6160
}
6261

6362
public RestClientConfiguration() {
@@ -83,8 +82,7 @@ public String getJasperReportsServerUrl() {
8382
}
8483

8584
public void setJasperReportsServerUrl(String jasperReportsServerUrl) {
86-
Matcher matcher = URL_PATTERN.matcher(jasperReportsServerUrl);
87-
if (!matcher.matches())
85+
if (!isStringValid(jasperReportsServerUrl) || !URL_PATTERN.matcher(jasperReportsServerUrl).matches())
8886
throw new IllegalArgumentException("Given parameter is not a URL");
8987
this.jasperReportsServerUrl = jasperReportsServerUrl;
9088
}
@@ -176,7 +174,7 @@ public static RestClientConfiguration loadConfiguration(String path) {
176174
}
177175
if (properties == null) {
178176
log.info("The properties file was not loaded");
179-
return null;
177+
return new RestClientConfiguration();
180178
}
181179

182180
RestClientConfiguration configuration = new RestClientConfiguration();
@@ -213,17 +211,17 @@ public static RestClientConfiguration loadConfiguration(String path) {
213211
}
214212

215213
String logHttp = properties.getProperty("logHttp");
216-
if (isStringValid(logHttp)) {
214+
if (isStringValid(logHttp) && BOOLEAN_PATTERN.matcher(logHttp).matches()) {
217215
configuration.setLogHttp(Boolean.valueOf(logHttp));
218216
}
219217

220218
String logHttpEntity = properties.getProperty("logHttpEntity");
221-
if (isStringValid(logHttpEntity)) {
219+
if (isStringValid(logHttpEntity) && BOOLEAN_PATTERN.matcher(logHttpEntity).matches()) {
222220
configuration.setLogHttpEntity(Boolean.valueOf(logHttpEntity));
223221
}
224222

225223
String restrictedHttpMethods = properties.getProperty("restrictedHttpMethods");
226-
if (isStringValid(restrictedHttpMethods)) {
224+
if (isStringValid(restrictedHttpMethods) && BOOLEAN_PATTERN.matcher(restrictedHttpMethods).matches()) {
227225
configuration.setRestrictedHttpMethods(Boolean.valueOf(restrictedHttpMethods));
228226
}
229227

src/main/resources/config.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ url=http://localhost:4444/jasperserver-pro
55
jasperserverVersion=v6_0_0
66
authenticationType=REST
77
logHttp=true
8-
logHttpEntity=false
8+
logHttpEntity=true
99
restrictedHttpMethods=false
1010
contentMimeType=JSON
1111
acceptMimeType=JSON

0 commit comments

Comments
 (0)