Skip to content

Commit 88e38ce

Browse files
committed
use ResourceUtils in tests
1 parent b7a6415 commit 88e38ce

117 files changed

Lines changed: 509 additions & 715 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/test/java/com/gooddata/AbstractGoodDataIT.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package com.gooddata;
77

88
import com.gooddata.authentication.LoginPasswordAuthentication;
9-
import com.fasterxml.jackson.databind.ObjectMapper;
109
import org.testng.annotations.AfterMethod;
1110
import org.testng.annotations.BeforeMethod;
1211

@@ -16,7 +15,6 @@
1615

1716
public abstract class AbstractGoodDataIT {
1817

19-
protected static final ObjectMapper MAPPER = new ObjectMapper();
2018
protected GoodData gd;
2119

2220
@BeforeMethod

src/test/java/com/gooddata/GoodDataRestExceptionTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
package com.gooddata;
77

88
import com.gooddata.gdc.GdcError;
9-
import com.fasterxml.jackson.databind.ObjectMapper;
109
import org.testng.annotations.Test;
1110

12-
import java.io.InputStream;
13-
11+
import static com.gooddata.util.ResourceUtils.readObjectFromResource;
1412
import static org.hamcrest.CoreMatchers.is;
1513
import static org.hamcrest.CoreMatchers.nullValue;
16-
import static org.hamcrest.MatcherAssert.*;
14+
import static org.hamcrest.MatcherAssert.assertThat;
1715

1816
public class GoodDataRestExceptionTest {
1917
@Test
@@ -69,8 +67,7 @@ public void shouldCreateInstanceWithNullStatusAndGdcError() throws Exception {
6967

7068
@Test
7169
public void shouldCreateInstanceWithGdcError() throws Exception {
72-
final InputStream inputStream = getClass().getResourceAsStream("/gdc/gdcError.json");
73-
final GdcError err = new ObjectMapper().readValue(inputStream, GdcError.class);
70+
final GdcError err = readObjectFromResource("/gdc/gdcError.json", GdcError.class);
7471

7572
final GoodDataRestException e = new GoodDataRestException(500, "a123", "message", err);
7673
assertThat(e.getMessage(), is("500: [requestId=REQ] MSG"));

src/test/java/com/gooddata/account/AccountServiceIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.IOException;
1414

1515
import static com.gooddata.util.ResourceUtils.readFromResource;
16+
import static com.gooddata.util.ResourceUtils.readObjectFromResource;
1617
import static net.jadler.Jadler.onRequest;
1718
import static org.hamcrest.MatcherAssert.assertThat;
1819
import static org.hamcrest.Matchers.notNullValue;
@@ -33,8 +34,8 @@ public class AccountServiceIT extends AbstractGoodDataIT {
3334

3435
@BeforeClass
3536
public void init() throws IOException {
36-
account = MAPPER.readValue(readFromResource(ACCOUNT), Account.class);
37-
createAccount = MAPPER.readValue(readFromResource(CREATE_ACCOUNT), Account.class);
37+
account = readObjectFromResource(ACCOUNT, Account.class);
38+
createAccount = readObjectFromResource(CREATE_ACCOUNT, Account.class);
3839
}
3940

4041
@Test

src/test/java/com/gooddata/account/AccountTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66
package com.gooddata.account;
77

8-
import com.fasterxml.jackson.databind.ObjectMapper;
98
import org.testng.annotations.Test;
109

1110
import static com.gooddata.JsonMatchers.serializesToJson;
11+
import static com.gooddata.util.ResourceUtils.readObjectFromResource;
1212
import static org.hamcrest.CoreMatchers.is;
1313
import static org.hamcrest.CoreMatchers.notNullValue;
1414
import static org.hamcrest.MatcherAssert.assertThat;
@@ -23,8 +23,7 @@ public class AccountTest {
2323
@SuppressWarnings("deprecation")
2424
@Test
2525
public void testDeserialize() throws Exception {
26-
final Account account = new ObjectMapper()
27-
.readValue(getClass().getResourceAsStream("/account/account.json"), Account.class);
26+
final Account account = readObjectFromResource("/account/account.json", Account.class);
2827
assertThat(account, is(notNullValue()));
2928

3029
assertThat(account.getFirstName(), is(FIRST_NAME));

src/test/java/com/gooddata/collections/PagingTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.io.InputStream;
1212

1313
import static com.gooddata.JsonMatchers.serializesToJson;
14+
import static com.gooddata.util.ResourceUtils.readObjectFromResource;
1415
import static org.hamcrest.CoreMatchers.notNullValue;
1516
import static org.hamcrest.CoreMatchers.nullValue;
1617
import static org.hamcrest.MatcherAssert.assertThat;
@@ -20,8 +21,7 @@ public class PagingTest {
2021

2122
@Test
2223
public void testDeserialization() throws Exception {
23-
final InputStream stream = getClass().getResourceAsStream("/collections/paging.json");
24-
final Paging paging = new ObjectMapper().readValue(stream, Paging.class);
24+
final Paging paging = readObjectFromResource("/collections/paging.json", Paging.class);
2525

2626
assertThat(paging.getOffset(), is("0"));
2727
assertThat(paging.getNext(), notNullValue());
@@ -30,17 +30,15 @@ public void testDeserialization() throws Exception {
3030

3131
@Test
3232
public void testDeserializationNullNext() throws Exception {
33-
final InputStream stream = getClass().getResourceAsStream("/collections/paging_no_next.json");
34-
final Paging paging = new ObjectMapper().readValue(stream, Paging.class);
33+
final Paging paging = readObjectFromResource("/collections/paging_no_next.json", Paging.class);
3534

3635
assertThat(paging.getOffset(), is("0"));
3736
assertThat(paging.getNext(), nullValue());
3837
}
3938

4039
@Test
4140
public void testDeserializationWithNextOnly() throws Exception {
42-
final InputStream stream = getClass().getResourceAsStream("/collections/paging_only_next.json");
43-
final Paging paging = new ObjectMapper().readValue(stream, Paging.class);
41+
final Paging paging = readObjectFromResource("/collections/paging_only_next.json", Paging.class);
4442

4543
assertThat(paging.getOffset(), is(nullValue()));
4644
assertThat(paging.getNext(), notNullValue());

src/test/java/com/gooddata/connector/ConnectorServiceIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ConnectorServiceIT extends AbstractGoodDataIT {
2828

2929
@BeforeMethod
3030
public void setUp() throws Exception {
31-
project = MAPPER.readValue(readFromResource("/project/project.json"), Project.class);
31+
project = readObjectFromResource("/project/project.json", Project.class);
3232
connectors = gd.getConnectorService();
3333
}
3434

@@ -109,7 +109,7 @@ public void shouldExecuteProcess() throws Exception {
109109
.havingMethodEqualTo("POST")
110110
.havingPathEqualTo("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes")
111111
.respond()
112-
.withBody(MAPPER.writeValueAsString(new UriResponse("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS")));
112+
.withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS")));
113113
onRequest()
114114
.havingPathEqualTo("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS")
115115
.respond()
@@ -128,7 +128,7 @@ public void shouldFailExecuteProcessPolling() throws Exception {
128128
.havingMethodEqualTo("POST")
129129
.havingPathEqualTo("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes")
130130
.respond()
131-
.withBody(MAPPER.writeValueAsString(new UriResponse("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS")));
131+
.withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS")));
132132
onRequest()
133133
.havingPathEqualTo("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS")
134134
.respond()
@@ -143,7 +143,7 @@ public void shouldFailExecuteProcess() throws Exception {
143143
.havingMethodEqualTo("POST")
144144
.havingPathEqualTo("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes")
145145
.respond()
146-
.withBody(MAPPER.writeValueAsString(new UriResponse("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS")));
146+
.withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS")));
147147
onRequest()
148148
.havingPathEqualTo("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS")
149149
.respond()

src/test/java/com/gooddata/connector/IntegrationProcessStatusTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
package com.gooddata.connector;
77

8-
import com.fasterxml.jackson.databind.ObjectMapper;
98
import org.joda.time.DateTime;
109
import org.joda.time.DateTimeZone;
1110
import org.testng.annotations.Test;
@@ -16,6 +15,7 @@
1615
import static com.gooddata.connector.Status.Code.SYNCHRONIZED;
1716
import static com.gooddata.connector.Status.Code.UPLOADING;
1817
import static com.gooddata.connector.Status.Code.USER_ERROR;
18+
import static com.gooddata.util.ResourceUtils.readObjectFromResource;
1919
import static org.hamcrest.CoreMatchers.is;
2020
import static org.hamcrest.CoreMatchers.notNullValue;
2121
import static org.hamcrest.CoreMatchers.nullValue;
@@ -27,8 +27,7 @@ public class IntegrationProcessStatusTest {
2727

2828
@Test
2929
public void testShouldDeserialize() throws Exception {
30-
final IntegrationProcessStatus process = new ObjectMapper()
31-
.readValue(getClass().getResource("/connector/process-status-embedded.json"), IntegrationProcessStatus.class);
30+
final IntegrationProcessStatus process = readObjectFromResource("/connector/process-status-embedded.json", IntegrationProcessStatus.class);
3231

3332
assertThat(process, is(notNullValue()));
3433
assertThat(process.getStarted(), is(new DateTime(2014, 5, 30, 7, 50, 15, DateTimeZone.UTC)));

src/test/java/com/gooddata/connector/IntegrationTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66
package com.gooddata.connector;
77

8-
import com.fasterxml.jackson.databind.ObjectMapper;
98
import org.testng.annotations.Test;
109

1110
import static com.gooddata.JsonMatchers.serializesToJson;
11+
import static com.gooddata.util.ResourceUtils.readObjectFromResource;
1212
import static org.hamcrest.MatcherAssert.assertThat;
1313
import static org.hamcrest.Matchers.is;
1414
import static org.hamcrest.Matchers.notNullValue;
@@ -19,8 +19,7 @@ public class IntegrationTest {
1919

2020
@Test
2121
public void shouldDeserialize() throws Exception {
22-
final Integration integration = new ObjectMapper()
23-
.readValue(getClass().getResourceAsStream("/connector/integration.json"), Integration.class);
22+
final Integration integration = readObjectFromResource("/connector/integration.json", Integration.class);
2423

2524
assertThat(integration, is(notNullValue()));
2625
assertThat(integration.isActive(), is(true));

src/test/java/com/gooddata/connector/ProcessStatusTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66
package com.gooddata.connector;
77

8-
import com.fasterxml.jackson.databind.ObjectMapper;
98
import org.testng.annotations.Test;
109

1110
import static com.gooddata.connector.Status.Code.ERROR;
11+
import static com.gooddata.util.ResourceUtils.readObjectFromResource;
1212
import static org.hamcrest.MatcherAssert.assertThat;
1313
import static org.hamcrest.Matchers.is;
1414
import static org.hamcrest.Matchers.notNullValue;
@@ -17,8 +17,7 @@ public class ProcessStatusTest {
1717

1818
@Test
1919
public void shouldDeserialize() throws Exception {
20-
final ProcessStatus process = new ObjectMapper()
21-
.readValue(getClass().getResourceAsStream("/connector/process-status-error.json"), ProcessStatus.class);
20+
final ProcessStatus process = readObjectFromResource("/connector/process-status-error.json", ProcessStatus.class);
2221

2322
assertThat(process, is(notNullValue()));
2423
assertThat(process.getFinished(), is(notNullValue()));

src/test/java/com/gooddata/connector/Zendesk4SettingsTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
*/
66
package com.gooddata.connector;
77

8-
import com.fasterxml.jackson.databind.ObjectMapper;
98
import org.testng.annotations.Test;
109

1110
import static com.gooddata.JsonMatchers.serializesToJson;
1211
import static com.gooddata.connector.ConnectorType.ZENDESK4;
1312
import static com.gooddata.connector.Zendesk4Settings.Zendesk4Type.plus;
13+
import static com.gooddata.util.ResourceUtils.readObjectFromResource;
1414
import static org.hamcrest.CoreMatchers.is;
1515
import static org.hamcrest.CoreMatchers.notNullValue;
1616
import static org.hamcrest.MatcherAssert.assertThat;
@@ -26,8 +26,7 @@ public void shouldSerialize() throws Exception {
2626

2727
@Test
2828
public void shouldDeserialize() throws Exception {
29-
final Zendesk4Settings settings = new ObjectMapper()
30-
.readValue(getClass().getResource("/connector/settings-zendesk4.json"), Zendesk4Settings.class);
29+
final Zendesk4Settings settings = readObjectFromResource("/connector/settings-zendesk4.json", Zendesk4Settings.class);
3130

3231
assertThat(settings, is(notNullValue()));
3332
assertThat(settings.getApiUrl(), is("https://foo.com"));

0 commit comments

Comments
 (0)