From dcdc0ee7f6fdef14d1d7555de924fb07aadf508d Mon Sep 17 00:00:00 2001 From: Jiri Mikulasek Date: Thu, 2 Mar 2017 21:50:31 +0100 Subject: [PATCH 001/702] fix: enable ResponseErrorHandler to read both known gdc error json structures Resolves #395. Custom deserializer for ErrorStructure and descendant GdcError created. Unfortunately it's not possible to deserialize exactly the ErrorStructure instance - the on purpose descendant is returned instead. The ErrorStructure descendants must use JsonDeserializer.None in order to work correctly. --- .../com/gooddata/GoodDataRestException.java | 6 +- .../java/com/gooddata/gdc/ErrorStructure.java | 4 +- .../gdc/ErrorStructureDeserializer.java | 68 ++++++++++++++ src/main/java/com/gooddata/gdc/GdcError.java | 3 + .../gooddata/util/ResponseErrorHandler.java | 10 +- .../util/ResponseErrorHandlerTest.java | 92 +++++++++++++++++++ 6 files changed, 174 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/gooddata/gdc/ErrorStructureDeserializer.java create mode 100644 src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java diff --git a/src/main/java/com/gooddata/GoodDataRestException.java b/src/main/java/com/gooddata/GoodDataRestException.java index 8d5fffdcd..804e72e4f 100644 --- a/src/main/java/com/gooddata/GoodDataRestException.java +++ b/src/main/java/com/gooddata/GoodDataRestException.java @@ -1,11 +1,11 @@ /** - * Copyright (C) 2004-2016, GoodData(R) Corporation. All rights reserved. + * Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved. * This source code is licensed under the BSD-style license found in the * LICENSE.txt file in the root directory of this source tree. */ package com.gooddata; -import com.gooddata.gdc.GdcError; +import com.gooddata.gdc.ErrorStructure; /** * Signals client or server error during communication with GoodData REST API. @@ -66,7 +66,7 @@ public GoodDataRestException(int statusCode, String requestId, String message, S * @param statusText the HTTP status text of the response * @param error the GoodData REST API error structure */ - public GoodDataRestException(int statusCode, String requestId, String statusText, GdcError error) { + public GoodDataRestException(int statusCode, String requestId, String statusText, ErrorStructure error) { this(statusCode, error != null && error.getRequestId() != null ? error.getRequestId() : requestId, error != null && error.getMessage() != null ? error.getFormattedMessage() : statusText, diff --git a/src/main/java/com/gooddata/gdc/ErrorStructure.java b/src/main/java/com/gooddata/gdc/ErrorStructure.java index 1f10f2a77..7147fb1b5 100644 --- a/src/main/java/com/gooddata/gdc/ErrorStructure.java +++ b/src/main/java/com/gooddata/gdc/ErrorStructure.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2004-2016, GoodData(R) Corporation. All rights reserved. + * Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved. * This source code is licensed under the BSD-style license found in the * LICENSE.txt file in the root directory of this source tree. */ @@ -9,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import static com.gooddata.util.Validate.notNull; import static java.util.Arrays.copyOf; @@ -18,6 +19,7 @@ * Deserialization only. */ @JsonIgnoreProperties(ignoreUnknown = true) +@JsonDeserialize(using = ErrorStructureDeserializer.class) public class ErrorStructure { protected final String message; protected final Object[] parameters; diff --git a/src/main/java/com/gooddata/gdc/ErrorStructureDeserializer.java b/src/main/java/com/gooddata/gdc/ErrorStructureDeserializer.java new file mode 100644 index 000000000..b5dd73d40 --- /dev/null +++ b/src/main/java/com/gooddata/gdc/ErrorStructureDeserializer.java @@ -0,0 +1,68 @@ +/** + * Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved. + * This source code is licensed under the BSD-style license found in the + * LICENSE.txt file in the root directory of this source tree. + */ +package com.gooddata.gdc; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.TreeNode; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.util.TokenBuffer; + +import java.io.IOException; + +/** + * Common deserializer for {@link ErrorStructure} and {@link GdcError}. + */ +class ErrorStructureDeserializer extends JsonDeserializer { + + private static final String GDC_ERROR_TYPE_NAME = "error"; + + @Override + public ErrorStructure deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { + final TokenBuffer tokenBuffer = new TokenBuffer(jp); + tokenBuffer.copyCurrentStructure(jp); + + final TreeNode treeNode = tokenBuffer.asParser().readValueAsTree(); + + Class clazz; + if (treeNode.isObject()) { + if (((ObjectNode) treeNode).has(GDC_ERROR_TYPE_NAME)) { + clazz = GdcError.class; + } else { + clazz = DefaultDeserializerErrorStructure.class; + } + } else { + throw ctxt.mappingException("Unknown type of ErrorStructure"); + } + + final JsonParser nextParser = tokenBuffer.asParser(); + nextParser.nextToken(); // just created parser points before the first token + + return ctxt.readValue(nextParser, clazz); + } + + /** + * This class actually represents deserialized {@link ErrorStructure}. + * We need to override deserializer to break the cycle while deserialize. + */ + @JsonDeserialize(using = None.class) + private static class DefaultDeserializerErrorStructure extends ErrorStructure { + + protected DefaultDeserializerErrorStructure(@JsonProperty("errorClass") String errorClass, + @JsonProperty("component") String component, + @JsonProperty("parameters") Object[] parameters, + @JsonProperty("message") String message, + @JsonProperty("errorCode") String errorCode, + @JsonProperty("errorId") String errorId, + @JsonProperty("trace") String trace, + @JsonProperty("requestId") String requestId) { + super(errorClass, component, parameters, message, errorCode, errorId, trace, requestId); + } + } +} diff --git a/src/main/java/com/gooddata/gdc/GdcError.java b/src/main/java/com/gooddata/gdc/GdcError.java index d524ce845..2a7693392 100644 --- a/src/main/java/com/gooddata/gdc/GdcError.java +++ b/src/main/java/com/gooddata/gdc/GdcError.java @@ -11,6 +11,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; /** * GoodData REST API error structure. @@ -20,6 +22,7 @@ @JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME) @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_NULL) +@JsonDeserialize(using = JsonDeserializer.None.class) public class GdcError extends ErrorStructure { @JsonCreator diff --git a/src/main/java/com/gooddata/util/ResponseErrorHandler.java b/src/main/java/com/gooddata/util/ResponseErrorHandler.java index c9d0a3f72..1abeb2de2 100644 --- a/src/main/java/com/gooddata/util/ResponseErrorHandler.java +++ b/src/main/java/com/gooddata/util/ResponseErrorHandler.java @@ -1,12 +1,12 @@ /** - * Copyright (C) 2004-2016, GoodData(R) Corporation. All rights reserved. + * Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved. * This source code is licensed under the BSD-style license found in the * LICENSE.txt file in the root directory of this source tree. */ package com.gooddata.util; import com.gooddata.GoodDataRestException; -import com.gooddata.gdc.GdcError; +import com.gooddata.gdc.ErrorStructure; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.client.DefaultResponseErrorHandler; @@ -24,16 +24,16 @@ */ public class ResponseErrorHandler extends DefaultResponseErrorHandler { - private final HttpMessageConverterExtractor gdcErrorExtractor; + private final HttpMessageConverterExtractor gdcErrorExtractor; public ResponseErrorHandler(List> messageConverters) { - gdcErrorExtractor = new HttpMessageConverterExtractor<>(GdcError.class, + gdcErrorExtractor = new HttpMessageConverterExtractor<>(ErrorStructure.class, noNullElements(messageConverters, "messageConverters")); } @Override public void handleError(ClientHttpResponse response) { - GdcError error = null; + ErrorStructure error = null; try { error = gdcErrorExtractor.extractData(response); } catch (RestClientException | IOException ignored) { diff --git a/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java b/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java new file mode 100644 index 000000000..34d58644e --- /dev/null +++ b/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java @@ -0,0 +1,92 @@ +/** + * Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved. + * This source code is licensed under the BSD-style license found in the + * LICENSE.txt file in the root directory of this source tree. + */ +package com.gooddata.util; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.gooddata.GoodData; +import com.gooddata.GoodDataRestException; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.client.ClientHttpResponse; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.io.IOException; + +import static java.util.Collections.singletonList; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.testng.Assert.assertEquals; + +public class ResponseErrorHandlerTest { + + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + private ResponseErrorHandler responseErrorHandler; + + @BeforeMethod + public void setUp() throws Exception { + responseErrorHandler = new ResponseErrorHandler(singletonList(new MappingJackson2HttpMessageConverter(OBJECT_MAPPER))); + } + + @Test + public void testHandleGdcError() throws Exception { + final ClientHttpResponse response = prepareResponse("/gdc/gdcError.json"); + + final GoodDataRestException exc = assertException(() -> responseErrorHandler.handleError(response)); + + assertThat("GoodDataRestException should have been thrown!", exc, is(notNullValue())); + assertEquals(exc.getStatusCode(), 500); + assertEquals(exc.getRequestId(), "REQ"); + assertEquals(exc.getComponent(), "COMPONENT"); + assertEquals(exc.getErrorClass(), "CLASS"); + assertEquals(exc.getErrorCode(), "CODE"); + assertEquals(exc.getText(), "MSG"); + } + + @Test + public void testHandleErrorStructure() throws Exception { + final ClientHttpResponse response = prepareResponse("/gdc/errorStructure.json"); + + final GoodDataRestException exc = assertException(() -> responseErrorHandler.handleError(response)); + + assertThat("GoodDataRestException should have been thrown!", exc, is(notNullValue())); + assertEquals(exc.getStatusCode(), 500); + assertEquals(exc.getRequestId(), "REQ"); + assertEquals(exc.getComponent(), "COMPONENT"); + assertEquals(exc.getErrorClass(), "CLASS"); + assertEquals(exc.getErrorCode(), "CODE"); + assertEquals(exc.getText(), "MSG PARAM1 PARAM2 3"); + } + + private ClientHttpResponse prepareResponse(String resourcePath) throws IOException { + final ClientHttpResponse response = mock(ClientHttpResponse.class); + when(response.getStatusCode()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR); + when(response.getRawStatusCode()).thenReturn(500); + final HttpHeaders headers = new HttpHeaders(); + headers.set(GoodData.GDC_REQUEST_ID_HEADER, "requestId"); + headers.setContentType(MediaType.APPLICATION_JSON); + when(response.getHeaders()).thenReturn(headers); + when(response.getBody()).thenReturn(getClass().getResourceAsStream(resourcePath)); + + return response; + } + + private static GoodDataRestException assertException(Runnable runnable) { + try { + runnable.run(); + return null; + } catch (GoodDataRestException e) { + return e; + } + } + +} \ No newline at end of file From fe95cf589f3189a02db4c4555135dca57620217b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C5=A0tumpf?= Date: Tue, 14 Mar 2017 13:00:26 +0100 Subject: [PATCH 002/702] eliminate double escaping in UriPage (fixes #428) --- src/main/java/com/gooddata/collections/UriPage.java | 8 +++++++- src/test/java/com/gooddata/collections/UriPageTest.java | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gooddata/collections/UriPage.java b/src/main/java/com/gooddata/collections/UriPage.java index 139b75bbd..7078caa19 100644 --- a/src/main/java/com/gooddata/collections/UriPage.java +++ b/src/main/java/com/gooddata/collections/UriPage.java @@ -7,7 +7,9 @@ import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; +import org.springframework.web.util.UriUtils; +import java.io.UnsupportedEncodingException; import java.net.URI; import java.util.List; import java.util.Map.Entry; @@ -27,7 +29,11 @@ class UriPage implements Page { * @param pageUri page URI */ public UriPage(final String pageUri) { - this.pageUri = UriComponentsBuilder.fromUriString(notNull(pageUri, "pageUri")).build(); + try { + this.pageUri = UriComponentsBuilder.fromUriString(UriUtils.decode(notNull(pageUri, "pageUri"), "UTF-8")).build(); + } catch (final UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } } /** diff --git a/src/test/java/com/gooddata/collections/UriPageTest.java b/src/test/java/com/gooddata/collections/UriPageTest.java index b0080510a..bb65557eb 100644 --- a/src/test/java/com/gooddata/collections/UriPageTest.java +++ b/src/test/java/com/gooddata/collections/UriPageTest.java @@ -63,4 +63,10 @@ public void testIdempotency() throws Exception { assertThat(components.getQueryParams(), hasEntry("offset", singletonList("god"))); assertThat(components.getQueryParams(), hasEntry("limit", singletonList("10"))); } + + @Test + public void testEncoding() throws Exception { + final UriPage uri = new UriPage("uri?test=foo%20bar"); + assertThat(uri.getPageUri(null).toString(), is("uri?test=foo%20bar")); + } } From 06feb5474d282e89a4b987f0c71e6af43c75e138 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Tue, 14 Mar 2017 13:32:47 +0100 Subject: [PATCH 003/702] update contributing guide --- CONTRIBUTING.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 97095c70e..df24c472b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,9 +3,16 @@ Below are few **rules, recommendations and best practices** we try to follow when developing the _GoodData Java SDK_. ## Paperwork -* Every pull request with non-trivial change must be **associated with an issue**. -* Every closed non-rejected pull request and issue must be marked with exactly **one milestone version**. -* Issue must be **properly labeled** (bug/enhancement/backward incompatible/...). +* The **commit message**: + * must be written in the **imperative mood** + * must clearly **explain rationale** behind this change (describe _why_ you are doing the change rather than _what_ you are changing) +* The **pull request**: + * must be **properly labeled** (trivial/bug/enhancement/backward incompatible/...) + * with non-trivial change must be **[associated with an issue](https://help.github.com/articles/closing-issues-via-commit-messages/)** + * must be marked with exactly one **milestone version** +* The **issue** + * must be **properly labeled** (bug/enhancement/backward incompatible/...). + * must be marked with exactly one **milestone version** * Add usage examples of new high level functionality to [documentation](https://github.com/gooddata/gooddata-java/wiki/Code-Examples). From f6d4043a2006e078cd203ff4a08da5da86466091 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Thu, 16 Mar 2017 10:57:26 +0100 Subject: [PATCH 004/702] [maven-release-plugin] prepare release gooddata-java-2.4.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3e7907c7e..ba1d57705 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.gooddata gooddata-java - 2.4.1-SNAPSHOT + 2.4.1 ${project.artifactId} GoodData Java SDK https://github.com/gooddata/gooddata-java From 5cef5f93295ae3d06c29849910c8603a64f6480d Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Thu, 16 Mar 2017 10:57:27 +0100 Subject: [PATCH 005/702] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ba1d57705..036deea6a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.gooddata gooddata-java - 2.4.1 + 2.4.2-SNAPSHOT ${project.artifactId} GoodData Java SDK https://github.com/gooddata/gooddata-java From 8235d5408c5e64d668d24c7450cf6a2d94e06b0a Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Thu, 16 Mar 2017 11:03:45 +0100 Subject: [PATCH 006/702] bump version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6621f77e1..743664849 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The *GoodData Java SDK* is available in Maven Central Repository, to use it from com.gooddata gooddata-java - 2.4.0 + 2.4.1 ``` See [releases page](https://github.com/gooddata/gooddata-java/releases) for information about versions and notable changes, From ed211a07ef02a3bba99d96e958026878fd2d8fd2 Mon Sep 17 00:00:00 2001 From: Libor Rysavy Date: Thu, 23 Mar 2017 11:42:02 +0100 Subject: [PATCH 007/702] Remove extra string from Implementation-Title --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 036deea6a..082ae922f 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ ${project.description} ${project.version} GoodData - HttpComponents ${project.description} + ${project.description} ${project.version} GoodData com.gooddata From 7401bb38017ea44f5811382a15caa9e0bf7675b4 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Mon, 3 Apr 2017 13:08:36 +0200 Subject: [PATCH 008/702] remove file input/output stream usage, close streams in try block https://www.cloudbees.com/blog/fileinputstream-fileoutputstream-considered-harmful --- .../gooddata/dataload/processes/ProcessService.java | 13 ++++++------- src/main/java/com/gooddata/util/ZipHelper.java | 11 ++++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/gooddata/dataload/processes/ProcessService.java b/src/main/java/com/gooddata/dataload/processes/ProcessService.java index 6cb3e2575..59bb3e8ce 100644 --- a/src/main/java/com/gooddata/dataload/processes/ProcessService.java +++ b/src/main/java/com/gooddata/dataload/processes/ProcessService.java @@ -33,12 +33,11 @@ import org.springframework.web.util.UriComponentsBuilder; import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import java.net.URI; +import java.nio.file.Files; import java.util.Collection; import static com.gooddata.util.Validate.notEmpty; @@ -524,7 +523,7 @@ private static URI getProcessesUri(Project project) { private DataloadProcess postProcess(DataloadProcess process, File processData, URI postUri) { File tempFile = createTempFile("process", ".zip"); - try (FileOutputStream output = new FileOutputStream(tempFile)) { + try (OutputStream output = Files.newOutputStream(tempFile.toPath())) { ZipHelper.zip(processData, output); } catch (IOException e) { throw new GoodDataException("Unable to zip process data", e); @@ -533,14 +532,14 @@ private DataloadProcess postProcess(DataloadProcess process, File processData, U Object processToSend; HttpMethod method = HttpMethod.POST; if (tempFile.length() > MAX_MULTIPART_SIZE) { - try { + try (final InputStream input = Files.newInputStream(tempFile.toPath())) { process.setPath(dataStoreService.getUri(tempFile.getName()).getPath()); - dataStoreService.upload(tempFile.getName(), new FileInputStream(tempFile)); + dataStoreService.upload(tempFile.getName(), input); processToSend = process; if (DataloadProcess.TEMPLATE.matches(postUri.toString())) { method = HttpMethod.PUT; } - } catch (FileNotFoundException e) { + } catch (IOException e) { throw new GoodDataException("Unable to access zipped process data at " + tempFile.getAbsolutePath(), e); } diff --git a/src/main/java/com/gooddata/util/ZipHelper.java b/src/main/java/com/gooddata/util/ZipHelper.java index 397bab6d2..86196a4e4 100644 --- a/src/main/java/com/gooddata/util/ZipHelper.java +++ b/src/main/java/com/gooddata/util/ZipHelper.java @@ -10,9 +10,10 @@ import org.springframework.util.StreamUtils; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; +import java.nio.file.Files; import java.nio.file.Path; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -50,7 +51,7 @@ public static void zip(File file, OutputStream output, boolean includeRoot) thro notNull(output, "output"); if (isZipped(file)) { - try (FileInputStream fis = new FileInputStream(file)) { + try (InputStream fis = Files.newInputStream(file.toPath())) { StreamUtils.copy(fis, output); } } else { @@ -77,15 +78,15 @@ private static void zipDir(Path rootPath, File dir, ZipOutputStream zos) throws private static void zipFile(Path rootPath, File file, ZipOutputStream zos) throws IOException { ZipEntry ze = new ZipEntry(rootPath.relativize(file.toPath()).toString()); zos.putNextEntry(ze); - try (FileInputStream fis = new FileInputStream(file)) { + try (InputStream fis = Files.newInputStream(file.toPath())) { StreamUtils.copy(fis, zos); } zos.closeEntry(); } private static boolean isZipped(File file) { - try { - return new ZipInputStream(new FileInputStream(file)).getNextEntry() != null; + try (final InputStream stream = Files.newInputStream(file.toPath())) { + return new ZipInputStream(stream).getNextEntry() != null; } catch (IOException e) { return false; } From b3d31c2a536a53b3db63c310fbe699e088fa9f59 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Wed, 19 Apr 2017 16:45:49 +0200 Subject: [PATCH 009/702] change test - use hamcrest, simplify exception extraction --- .../util/ResponseErrorHandlerTest.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java b/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java index 34d58644e..ae0f9e24b 100644 --- a/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java +++ b/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java @@ -24,7 +24,6 @@ import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.testng.Assert.assertEquals; public class ResponseErrorHandlerTest { @@ -41,30 +40,30 @@ public void setUp() throws Exception { public void testHandleGdcError() throws Exception { final ClientHttpResponse response = prepareResponse("/gdc/gdcError.json"); - final GoodDataRestException exc = assertException(() -> responseErrorHandler.handleError(response)); + final GoodDataRestException exc = assertException(response); assertThat("GoodDataRestException should have been thrown!", exc, is(notNullValue())); - assertEquals(exc.getStatusCode(), 500); - assertEquals(exc.getRequestId(), "REQ"); - assertEquals(exc.getComponent(), "COMPONENT"); - assertEquals(exc.getErrorClass(), "CLASS"); - assertEquals(exc.getErrorCode(), "CODE"); - assertEquals(exc.getText(), "MSG"); + assertThat(exc.getStatusCode(), is(500)); + assertThat(exc.getRequestId(), is("REQ")); + assertThat(exc.getComponent(), is("COMPONENT")); + assertThat(exc.getErrorClass(), is("CLASS")); + assertThat(exc.getErrorCode(), is("CODE")); + assertThat(exc.getText(), is("MSG")); } @Test public void testHandleErrorStructure() throws Exception { final ClientHttpResponse response = prepareResponse("/gdc/errorStructure.json"); - final GoodDataRestException exc = assertException(() -> responseErrorHandler.handleError(response)); + final GoodDataRestException exc = assertException(response); assertThat("GoodDataRestException should have been thrown!", exc, is(notNullValue())); - assertEquals(exc.getStatusCode(), 500); - assertEquals(exc.getRequestId(), "REQ"); - assertEquals(exc.getComponent(), "COMPONENT"); - assertEquals(exc.getErrorClass(), "CLASS"); - assertEquals(exc.getErrorCode(), "CODE"); - assertEquals(exc.getText(), "MSG PARAM1 PARAM2 3"); + assertThat(exc.getStatusCode(), is(500)); + assertThat(exc.getRequestId(), is("REQ")); + assertThat(exc.getComponent(), is("COMPONENT")); + assertThat(exc.getErrorClass(), is("CLASS")); + assertThat(exc.getErrorCode(), is("CODE")); + assertThat(exc.getText(), is("MSG PARAM1 PARAM2 3")); } private ClientHttpResponse prepareResponse(String resourcePath) throws IOException { @@ -80,10 +79,10 @@ private ClientHttpResponse prepareResponse(String resourcePath) throws IOExcepti return response; } - private static GoodDataRestException assertException(Runnable runnable) { + private GoodDataRestException assertException(ClientHttpResponse response) { try { - runnable.run(); - return null; + responseErrorHandler.handleError(response); + throw new AssertionError("Expected GoodDataRestException"); } catch (GoodDataRestException e) { return e; } From abf072930f0b5988acf496968550070cb96ef5d6 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Wed, 19 Apr 2017 17:08:32 +0200 Subject: [PATCH 010/702] fix: handle invalid error response --- .../java/com/gooddata/GoodDataRestException.java | 4 +++- .../com/gooddata/util/ResponseErrorHandler.java | 3 ++- .../com/gooddata/GoodDataRestExceptionTest.java | 10 ++++++++++ .../gooddata/util/ResponseErrorHandlerTest.java | 16 ++++++++++++++++ src/test/resources/gdc/invalidError.json | 8 ++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/gdc/invalidError.json diff --git a/src/main/java/com/gooddata/GoodDataRestException.java b/src/main/java/com/gooddata/GoodDataRestException.java index 804e72e4f..3d2ac2985 100644 --- a/src/main/java/com/gooddata/GoodDataRestException.java +++ b/src/main/java/com/gooddata/GoodDataRestException.java @@ -35,7 +35,9 @@ public class GoodDataRestException extends GoodDataException { */ public GoodDataRestException(int statusCode, String requestId, String message, String component, String errorClass, String errorCode) { - super(statusCode + (requestId != null ? ": [requestId=" + requestId + "] " : ": ") + message); + super(statusCode + + (requestId != null ? ": [requestId=" + requestId + "] " : ": ") + + (message != null ? message : "Unknown error")); this.statusCode = statusCode; this.requestId = requestId; this.component = component; diff --git a/src/main/java/com/gooddata/util/ResponseErrorHandler.java b/src/main/java/com/gooddata/util/ResponseErrorHandler.java index 1abeb2de2..a2245c48b 100644 --- a/src/main/java/com/gooddata/util/ResponseErrorHandler.java +++ b/src/main/java/com/gooddata/util/ResponseErrorHandler.java @@ -8,6 +8,7 @@ import com.gooddata.GoodDataRestException; import com.gooddata.gdc.ErrorStructure; import org.springframework.http.client.ClientHttpResponse; +import org.springframework.http.converter.HttpMessageConversionException; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.HttpMessageConverterExtractor; @@ -36,7 +37,7 @@ public void handleError(ClientHttpResponse response) { ErrorStructure error = null; try { error = gdcErrorExtractor.extractData(response); - } catch (RestClientException | IOException ignored) { + } catch (RestClientException | IOException | HttpMessageConversionException ignored) { } final String requestId = response.getHeaders().getFirst(GDC_REQUEST_ID_HEADER); int statusCode; diff --git a/src/test/java/com/gooddata/GoodDataRestExceptionTest.java b/src/test/java/com/gooddata/GoodDataRestExceptionTest.java index 22c133197..c69afe096 100644 --- a/src/test/java/com/gooddata/GoodDataRestExceptionTest.java +++ b/src/test/java/com/gooddata/GoodDataRestExceptionTest.java @@ -12,6 +12,7 @@ import java.io.InputStream; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.*; public class GoodDataRestExceptionTest { @@ -57,6 +58,15 @@ public void shouldCreateInstanceWithNullGdcError() throws Exception { assertThat(e.getText(), is("message")); } + @Test + public void shouldCreateInstanceWithNullStatusAndGdcError() throws Exception { + final GoodDataRestException e = new GoodDataRestException(500, "a123", null, null); + assertThat(e.getMessage(), is("500: [requestId=a123] Unknown error")); + assertThat(e.getStatusCode(), is(500)); + assertThat(e.getRequestId(), is("a123")); + assertThat(e.getText(), is(nullValue())); + } + @Test public void shouldCreateInstanceWithGdcError() throws Exception { final InputStream inputStream = getClass().getResourceAsStream("/gdc/gdcError.json"); diff --git a/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java b/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java index ae0f9e24b..3d4addcc1 100644 --- a/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java +++ b/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java @@ -20,6 +20,7 @@ import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.mock; @@ -66,6 +67,21 @@ public void testHandleErrorStructure() throws Exception { assertThat(exc.getText(), is("MSG PARAM1 PARAM2 3")); } + @Test + public void testHandleInvalidError() throws Exception { + final ClientHttpResponse response = prepareResponse("/gdc/invalidError.json"); + + final GoodDataRestException exc = assertException(response); + + assertThat("GoodDataRestException should have been thrown!", exc, is(notNullValue())); + assertThat(exc.getStatusCode(), is(500)); + assertThat(exc.getRequestId(), is("requestId")); + assertThat(exc.getComponent(), is(nullValue())); + assertThat(exc.getErrorClass(), is(nullValue())); + assertThat(exc.getErrorCode(), is(nullValue())); + assertThat(exc.getText(), is(nullValue())); + } + private ClientHttpResponse prepareResponse(String resourcePath) throws IOException { final ClientHttpResponse response = mock(ClientHttpResponse.class); when(response.getStatusCode()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR); diff --git a/src/test/resources/gdc/invalidError.json b/src/test/resources/gdc/invalidError.json new file mode 100644 index 000000000..e3ba3752c --- /dev/null +++ b/src/test/resources/gdc/invalidError.json @@ -0,0 +1,8 @@ +{ + "timestamp": 1492609090612, + "status": 500, + "error": "Internal Server Error", + "exception": "java.lang.NoSuchFieldError", + "message": "fail", + "path": "/foo" +} From d72fb15d19c551f58f8c99cee56584abf2736724 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Fri, 21 Apr 2017 08:16:31 +0200 Subject: [PATCH 011/702] fix: upgrading link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 743664849..d0ad3201b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The *GoodData Java SDK* is available in Maven Central Repository, to use it from ``` See [releases page](https://github.com/gooddata/gooddata-java/releases) for information about versions and notable changes, -the [Upgrading Guide](https://github.com/gooddata/gooddata-java/wiki/Upgrading-GoodData-Java-SDK) will navigate you +the [Upgrading Guide](https://github.com/gooddata/gooddata-java/wiki/Upgrading) will navigate you through changes between major versions. See [Javadocs](http://javadoc.io/doc/com.gooddata/gooddata-java) From 096c7e8bbf98c189e373a91879f64289ebcbd0f3 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Wed, 26 Apr 2017 13:59:34 +0200 Subject: [PATCH 012/702] fix: double uri encoding close: #436 --- src/main/java/com/gooddata/UriPrefixer.java | 16 +++++++++-- .../java/com/gooddata/UriPrefixerTest.java | 28 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gooddata/UriPrefixer.java b/src/main/java/com/gooddata/UriPrefixer.java index 9b8a82148..9ae63f7ff 100644 --- a/src/main/java/com/gooddata/UriPrefixer.java +++ b/src/main/java/com/gooddata/UriPrefixer.java @@ -8,6 +8,7 @@ import org.springframework.web.util.UriComponentsBuilder; import java.net.URI; +import java.util.List; import static com.gooddata.util.Validate.notEmpty; import static com.gooddata.util.Validate.notNull; @@ -55,12 +56,21 @@ public URI getUriPrefix() { */ public URI mergeUris(URI uri) { notNull(uri, "uri"); - final String path = trimLeadingCharacter(uri.getRawPath(), '/'); + return UriComponentsBuilder.fromUri(uriPrefix) - .pathSegment(path) + .pathSegment(getPathSegments(uri)) .query(uri.getRawQuery()) .fragment(uri.getRawFragment()) - .build().toUri(); + .build(true) // we have an URI as the input, so it is already encoded + .toUri(); + } + + private static String[] getPathSegments(final URI uri) { + final List pathSegments = UriComponentsBuilder + .fromPath(uri.getRawPath()) + .build(true) + .getPathSegments(); + return pathSegments.toArray(new String[pathSegments.size()]); } /** diff --git a/src/test/java/com/gooddata/UriPrefixerTest.java b/src/test/java/com/gooddata/UriPrefixerTest.java index 719b4e646..93b995238 100644 --- a/src/test/java/com/gooddata/UriPrefixerTest.java +++ b/src/test/java/com/gooddata/UriPrefixerTest.java @@ -5,6 +5,7 @@ */ package com.gooddata; +import org.springframework.web.util.UriComponentsBuilder; import org.testng.annotations.Test; import java.net.URI; @@ -21,10 +22,37 @@ public void testMergeUrisWithSlash() throws Exception { assertThat(result.toString(), is("http://localhost:1/uploads/test")); } + @Test + public void testMergeUrisWithSlashes() throws Exception { + final UriPrefixer prefixer = new UriPrefixer("http://localhost:1/uploads/"); + final URI result = prefixer.mergeUris("/test"); + assertThat(result.toString(), is("http://localhost:1/uploads/test")); + } + @Test public void testMergeUrisWithoutSlash() throws Exception { + final UriPrefixer prefixer = new UriPrefixer("http://localhost:1/uploads/"); + final URI result = prefixer.mergeUris("test"); + assertThat(result.toString(), is("http://localhost:1/uploads/test")); + } + + @Test + public void testMergeUrisWithoutSlashes() throws Exception { final UriPrefixer prefixer = new UriPrefixer("http://localhost:1/uploads"); final URI result = prefixer.mergeUris("test"); assertThat(result.toString(), is("http://localhost:1/uploads/test")); } + + @Test + public void shouldNotDoubleEncodeQueryParam() throws Exception { + final UriPrefixer prefixer = new UriPrefixer("http://localhost:1/uploads"); + + final URI uri = UriComponentsBuilder.fromPath("/foo") + .queryParam("bar", "\n") // some crazy value which needs encoding + .build() + .toUri(); + + final URI result = prefixer.mergeUris(uri); + assertThat(result.toString(), is("http://localhost:1/uploads/foo?bar=%0A")); + } } \ No newline at end of file From 31cae73fdee79918c6e11391302301c5d8c38752 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Wed, 26 Apr 2017 14:23:58 +0200 Subject: [PATCH 013/702] [maven-release-plugin] prepare release gooddata-java-2.4.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 082ae922f..2054c927d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.gooddata gooddata-java - 2.4.2-SNAPSHOT + 2.4.2 ${project.artifactId} GoodData Java SDK https://github.com/gooddata/gooddata-java From 89b40061eb362229d1823231cdfb96ede5fb037a Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Wed, 26 Apr 2017 14:23:58 +0200 Subject: [PATCH 014/702] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2054c927d..8b3e89a90 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.gooddata gooddata-java - 2.4.2 + 2.4.3-SNAPSHOT ${project.artifactId} GoodData Java SDK https://github.com/gooddata/gooddata-java From 63f4ade03e4a70690e8f2b1eaf2775283cc4a607 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Wed, 26 Apr 2017 14:33:03 +0200 Subject: [PATCH 015/702] bump version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d0ad3201b..cd895dcb8 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The *GoodData Java SDK* is available in Maven Central Repository, to use it from com.gooddata gooddata-java - 2.4.1 + 2.4.2 ``` See [releases page](https://github.com/gooddata/gooddata-java/releases) for information about versions and notable changes, From 284151918a7cf6528388a1155e6389150d872dd0 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Thu, 27 Apr 2017 15:25:47 +0200 Subject: [PATCH 016/702] fix: don't let uriprefixer to strip trailing slash close: #438 --- src/main/java/com/gooddata/UriPrefixer.java | 20 +++++++++++++------ .../UriPrefixingClientHttpRequestFactory.java | 3 ++- .../java/com/gooddata/UriPrefixerTest.java | 14 +++++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/gooddata/UriPrefixer.java b/src/main/java/com/gooddata/UriPrefixer.java index 9ae63f7ff..618b3bfc7 100644 --- a/src/main/java/com/gooddata/UriPrefixer.java +++ b/src/main/java/com/gooddata/UriPrefixer.java @@ -5,6 +5,7 @@ */ package com.gooddata; +import org.apache.commons.lang3.StringUtils; import org.springframework.web.util.UriComponentsBuilder; import java.net.URI; @@ -12,7 +13,6 @@ import static com.gooddata.util.Validate.notEmpty; import static com.gooddata.util.Validate.notNull; -import static org.springframework.util.StringUtils.trimLeadingCharacter; /** * Used internally by GoodData SDK to hold and set URI prefix (hostname and port) of all requests. @@ -57,17 +57,25 @@ public URI getUriPrefix() { public URI mergeUris(URI uri) { notNull(uri, "uri"); - return UriComponentsBuilder.fromUri(uriPrefix) - .pathSegment(getPathSegments(uri)) + final String path = uri.getRawPath(); + final String[] pathSegments = getPathSegments(path); + + final UriComponentsBuilder builder = UriComponentsBuilder.fromUri(uriPrefix) + .pathSegment(pathSegments) .query(uri.getRawQuery()) - .fragment(uri.getRawFragment()) + .fragment(uri.getRawFragment()); + if (StringUtils.endsWith(path, "/")) { + builder.path("/"); + } + + return builder .build(true) // we have an URI as the input, so it is already encoded .toUri(); } - private static String[] getPathSegments(final URI uri) { + private static String[] getPathSegments(final String path) { final List pathSegments = UriComponentsBuilder - .fromPath(uri.getRawPath()) + .fromPath(path) .build(true) .getPathSegments(); return pathSegments.toArray(new String[pathSegments.size()]); diff --git a/src/main/java/com/gooddata/UriPrefixingClientHttpRequestFactory.java b/src/main/java/com/gooddata/UriPrefixingClientHttpRequestFactory.java index a5f17d4e2..fd7cb7015 100644 --- a/src/main/java/com/gooddata/UriPrefixingClientHttpRequestFactory.java +++ b/src/main/java/com/gooddata/UriPrefixingClientHttpRequestFactory.java @@ -53,7 +53,8 @@ private UriPrefixingClientHttpRequestFactory(final ClientHttpRequestFactory fact @Override public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { - return wrapped.createRequest(prefixer.mergeUris(uri), httpMethod); + final URI merged = prefixer.mergeUris(uri); + return wrapped.createRequest(merged, httpMethod); } } \ No newline at end of file diff --git a/src/test/java/com/gooddata/UriPrefixerTest.java b/src/test/java/com/gooddata/UriPrefixerTest.java index 93b995238..65c564ee1 100644 --- a/src/test/java/com/gooddata/UriPrefixerTest.java +++ b/src/test/java/com/gooddata/UriPrefixerTest.java @@ -29,6 +29,13 @@ public void testMergeUrisWithSlashes() throws Exception { assertThat(result.toString(), is("http://localhost:1/uploads/test")); } + @Test + public void testMergeUrisWithAllSlashes() throws Exception { + final UriPrefixer prefixer = new UriPrefixer("http://localhost:1/uploads/"); + final URI result = prefixer.mergeUris("/test/"); + assertThat(result.toString(), is("http://localhost:1/uploads/test/")); + } + @Test public void testMergeUrisWithoutSlash() throws Exception { final UriPrefixer prefixer = new UriPrefixer("http://localhost:1/uploads/"); @@ -55,4 +62,11 @@ public void shouldNotDoubleEncodeQueryParam() throws Exception { final URI result = prefixer.mergeUris(uri); assertThat(result.toString(), is("http://localhost:1/uploads/foo?bar=%0A")); } + + @Test + public void shouldName() throws Exception { + final UriPrefixer prefixer = new UriPrefixer("https://localhost:1"); + final URI result = prefixer.mergeUris("http://localhost:1/uploads/test/"); + assertThat(result.toString(), is("https://localhost:1/uploads/test/")); + } } \ No newline at end of file From f70ddb2219e80cd5f61f72575a05a228972aef98 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 28 Apr 2017 15:12:18 +0200 Subject: [PATCH 017/702] include ADS license to the Warehouse object --- .../com/gooddata/warehouse/Warehouse.java | 30 +++++++++++++------ .../com/gooddata/warehouse/WarehouseTest.java | 26 ++++++++++++++++ .../warehouse/warehouse-withLicense.json | 21 +++++++++++++ 3 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 src/test/resources/warehouse/warehouse-withLicense.json diff --git a/src/main/java/com/gooddata/warehouse/Warehouse.java b/src/main/java/com/gooddata/warehouse/Warehouse.java index 443b46b3c..261582d27 100644 --- a/src/main/java/com/gooddata/warehouse/Warehouse.java +++ b/src/main/java/com/gooddata/warehouse/Warehouse.java @@ -56,6 +56,7 @@ public class Warehouse { private String environment; private Map links; private String connectionUrl; + private String license; public Warehouse(String title, String authToken) { this(title, authToken, null); @@ -67,15 +68,9 @@ public Warehouse(String title, String authToken, String description) { this.description = description; } - @JsonCreator - public Warehouse(@JsonProperty("title") String title, @JsonProperty("authorizationToken") String authToken, - @JsonProperty("description") String description, - @JsonProperty("created") @JsonDeserialize(using = ISODateTimeDeserializer.class) DateTime created, - @JsonProperty("updated") @JsonDeserialize(using = ISODateTimeDeserializer.class) DateTime updated, - @JsonProperty("createdBy") String createdBy, @JsonProperty("updatedBy") String updatedBy, - @JsonProperty("status") String status, @JsonProperty("environment") String environment, - @JsonProperty("connectionUrl") String connectionUrl, - @JsonProperty("links") Map links) { + public Warehouse(String title, String authToken, String description, DateTime created, DateTime updated, + String createdBy, String updatedBy, String status, String environment, String connectionUrl, + Map links) { this(title, authToken, description); this.created = created; this.updated = updated; @@ -87,6 +82,21 @@ public Warehouse(@JsonProperty("title") String title, @JsonProperty("authorizati this.links = links; } + @JsonCreator + public Warehouse(@JsonProperty("title") String title, @JsonProperty("authorizationToken") String authToken, + @JsonProperty("description") String description, + @JsonProperty("created") @JsonDeserialize(using = ISODateTimeDeserializer.class) DateTime created, + @JsonProperty("updated") @JsonDeserialize(using = ISODateTimeDeserializer.class) DateTime updated, + @JsonProperty("createdBy") String createdBy, @JsonProperty("updatedBy") String updatedBy, + @JsonProperty("status") String status, @JsonProperty("environment") String environment, + @JsonProperty("connectionUrl") String connectionUrl, + @JsonProperty("links") Map links, + @JsonProperty("license") String license) { + this(title, authToken, description, created, updated, createdBy, updatedBy, status, environment, connectionUrl, + links); + this.license = license; + } + public String getTitle() { return title; } @@ -144,6 +154,8 @@ public void setEnvironment(final String environment) { this.environment = environment; } + public String getLicense() { return license; } + @JsonIgnore public void setEnvironment(final Environment environment) { notNull(environment, "environment"); diff --git a/src/test/java/com/gooddata/warehouse/WarehouseTest.java b/src/test/java/com/gooddata/warehouse/WarehouseTest.java index 62007685e..f16042035 100644 --- a/src/test/java/com/gooddata/warehouse/WarehouseTest.java +++ b/src/test/java/com/gooddata/warehouse/WarehouseTest.java @@ -33,6 +33,7 @@ public class WarehouseTest { public static final String UPDATED_BY = "/gdc/account/profile/updatedBy"; public static final String STATUS = "ENABLED"; public static final String CONNECTION_URL = "CONNECTION_URL"; + public static final String PREMIUM_LICENSE = "PREMIUM"; public static final Map LINKS = new LinkedHashMap() {{ put("self", "/gdc/datawarehouse/instances/instanceId"); put("parent", "/gdc/datawarehouse/instances"); @@ -59,6 +60,12 @@ public void testSerializationWithNullToken() throws Exception { assertThat(warehouse, serializesToJson("/warehouse/warehouse-null-token.json")); } + @Test + public void testSerializationWithLicense() throws Exception { + final Warehouse warehouse = new Warehouse(TITLE, TOKEN, DESCRIPTION, CREATED, UPDATED, CREATED_BY, UPDATED_BY, STATUS, ENVIRONMENT, CONNECTION_URL, LINKS, PREMIUM_LICENSE); + assertThat(warehouse, serializesToJson("/warehouse/warehouse-withLicense.json")); + } + @Test public void testDeserialization() throws Exception { final InputStream stream = getClass().getResourceAsStream("/warehouse/warehouse.json"); @@ -77,6 +84,25 @@ public void testDeserialization() throws Exception { assertThat(warehouse.getConnectionUrl(), is(CONNECTION_URL)); } + @Test + public void testDeserializationWithLicense() throws Exception { + final InputStream stream = getClass().getResourceAsStream("/warehouse/warehouse-withLicense.json"); + final Warehouse warehouse = new ObjectMapper().readValue(stream, Warehouse.class); + + assertThat(warehouse.getTitle(), is(TITLE)); + assertThat(warehouse.getDescription(), is(DESCRIPTION)); + assertThat(warehouse.getAuthorizationToken(), is(TOKEN)); + assertThat(warehouse.getEnvironment(), is(ENVIRONMENT)); + assertThat(warehouse.getCreatedBy(), is(CREATED_BY)); + assertThat(warehouse.getUpdatedBy(), is(UPDATED_BY)); + assertThat(warehouse.getCreated(), is(CREATED)); + assertThat(warehouse.getUpdated(), is(UPDATED)); + assertThat(warehouse.getStatus(), is(STATUS)); + assertThat(warehouse.getLinks(), is(LINKS)); + assertThat(warehouse.getConnectionUrl(), is(CONNECTION_URL)); + assertThat(warehouse.getLicense(), is(PREMIUM_LICENSE)); + } + @Test public void testDeserializationWithNullToken() throws Exception { final InputStream stream = getClass().getResourceAsStream("/warehouse/warehouse-null-token.json"); diff --git a/src/test/resources/warehouse/warehouse-withLicense.json b/src/test/resources/warehouse/warehouse-withLicense.json new file mode 100644 index 000000000..1e2fe9746 --- /dev/null +++ b/src/test/resources/warehouse/warehouse-withLicense.json @@ -0,0 +1,21 @@ +{ + "instance" : { + "title" : "Test", + "description" : "Storage", + "status" : "ENABLED", + "authorizationToken" : "{Token}", + "created" : "2014-05-05T08:27:33.000Z", + "updated" : "2014-05-05T08:27:34.000Z", + "createdBy" : "/gdc/account/profile/createdBy", + "updatedBy" : "/gdc/account/profile/updatedBy", + "environment" : "TESTING", + "connectionUrl" : "CONNECTION_URL", + "license": "PREMIUM", + "links" : { + "self" : "/gdc/datawarehouse/instances/instanceId", + "parent" : "/gdc/datawarehouse/instances", + "users" : "/gdc/datawarehouse/instances/instanceId/users", + "jdbc" : "/gdc/datawarehouse/instances/instanceId/jdbc" + } + } +} From 2bc251d7f4a406eeeb4b374c25378d4bd339b680 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Tue, 2 May 2017 14:57:40 +0200 Subject: [PATCH 018/702] [maven-release-plugin] prepare release gooddata-java-2.5.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8b3e89a90..6a19b9b8b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.gooddata gooddata-java - 2.4.3-SNAPSHOT + 2.5.0 ${project.artifactId} GoodData Java SDK https://github.com/gooddata/gooddata-java From c81238f10bf8d672d1d8e7e36d6a5ad12c287473 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Tue, 2 May 2017 14:57:40 +0200 Subject: [PATCH 019/702] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6a19b9b8b..667ebad1e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.gooddata gooddata-java - 2.5.0 + 2.5.1-SNAPSHOT ${project.artifactId} GoodData Java SDK https://github.com/gooddata/gooddata-java From fa6919f84902f308fa373b13a59917ec7f30cb85 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Tue, 2 May 2017 16:07:49 +0200 Subject: [PATCH 020/702] bump version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cd895dcb8..f1dc8c023 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The *GoodData Java SDK* is available in Maven Central Repository, to use it from com.gooddata gooddata-java - 2.4.2 + 2.5.0 ``` See [releases page](https://github.com/gooddata/gooddata-java/releases) for information about versions and notable changes, From 62f267695b40610797ac8016846bf92954118f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Benkovsk=C3=BD?= Date: Wed, 10 May 2017 00:59:22 +0200 Subject: [PATCH 021/702] Add feature to execute schedule manually --- .../dataload/processes/ProcessService.java | 34 +++++++ .../gooddata/dataload/processes/Schedule.java | 6 ++ .../dataload/processes/ScheduleExecution.java | 95 +++++++++++++++++++ .../processes/ScheduleExecutionException.java | 23 +++++ .../dataload/processes/ProcessServiceAT.java | 9 ++ .../dataload/processes/ProcessServiceIT.java | 34 +++++++ .../processes/ProcessServiceTest.java | 35 +++++++ .../processes/ScheduleExecutionTest.java | 46 +++++++++ .../processes/emptyScheduleExecution.json | 4 + .../dataload/processes/scheduleExecution.json | 11 +++ 10 files changed, 297 insertions(+) create mode 100644 src/main/java/com/gooddata/dataload/processes/ScheduleExecution.java create mode 100644 src/main/java/com/gooddata/dataload/processes/ScheduleExecutionException.java create mode 100644 src/test/java/com/gooddata/dataload/processes/ScheduleExecutionTest.java create mode 100644 src/test/resources/dataload/processes/emptyScheduleExecution.json create mode 100644 src/test/resources/dataload/processes/scheduleExecution.json diff --git a/src/main/java/com/gooddata/dataload/processes/ProcessService.java b/src/main/java/com/gooddata/dataload/processes/ProcessService.java index 59bb3e8ce..39e450e8b 100644 --- a/src/main/java/com/gooddata/dataload/processes/ProcessService.java +++ b/src/main/java/com/gooddata/dataload/processes/ProcessService.java @@ -470,6 +470,40 @@ public void removeSchedule(Schedule schedule) { } } + /** + * Executes given schedule + * + * @param schedule to execute + * @return schedule execution + */ + public FutureResult executeSchedule(final Schedule schedule) { + notNull(schedule, "schedule"); + ScheduleExecution scheduleExecution; + try { + scheduleExecution = restTemplate.postForObject(schedule.getExecutionsUri(), new ScheduleExecution(), ScheduleExecution.class); + } catch (GoodDataException | RestClientException e) { + throw new ScheduleExecutionException("Cannot execute schedule", e); + } + + return new PollResult<>(this, new AbstractPollHandler(scheduleExecution.getUri(), ScheduleExecution.class, ScheduleExecution.class) { + @Override + public boolean isFinished(ClientHttpResponse response) throws IOException { + final ScheduleExecution pollResult = extractData(response, ScheduleExecution.class); + return pollResult.isFinished(); + } + + @Override + public void handlePollResult(final ScheduleExecution pollResult) { + setResult(pollResult); + } + + @Override + public void handlePollException(final GoodDataRestException e) { + throw new ScheduleExecutionException("Cannot execute schedule", e); + } + }); + } + private PageableList listSchedules(URI uri) { try { final Schedules schedules = restTemplate.getForObject(uri, Schedules.class); diff --git a/src/main/java/com/gooddata/dataload/processes/Schedule.java b/src/main/java/com/gooddata/dataload/processes/Schedule.java index 4fe94cb93..bbd7586ff 100644 --- a/src/main/java/com/gooddata/dataload/processes/Schedule.java +++ b/src/main/java/com/gooddata/dataload/processes/Schedule.java @@ -41,6 +41,7 @@ public class Schedule { public static final UriTemplate TEMPLATE = new UriTemplate(URI); private static final String SELF_LINK = "self"; + private static final String EXECUTIONS_LINK = "executions"; private static final String MSETL_TYPE = "MSETL"; private static final String PROCESS_ID = "PROCESS_ID"; @@ -254,6 +255,11 @@ public String getId() { return TEMPLATE.match(getUri()).get("scheduleId"); } + @JsonIgnore + public String getExecutionsUri() { + return notNullState(links, "links").get(EXECUTIONS_LINK); + } + @Override public String toString() { return GoodDataToStringBuilder.defaultToString(this); diff --git a/src/main/java/com/gooddata/dataload/processes/ScheduleExecution.java b/src/main/java/com/gooddata/dataload/processes/ScheduleExecution.java new file mode 100644 index 000000000..255989ea5 --- /dev/null +++ b/src/main/java/com/gooddata/dataload/processes/ScheduleExecution.java @@ -0,0 +1,95 @@ +/** + * Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved. + * This source code is licensed under the BSD-style license found in the + * LICENSE.txt file in the root directory of this source tree. + */ +package com.gooddata.dataload.processes; + +import static com.gooddata.util.Validate.notNullState; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.gooddata.util.ISODateTimeDeserializer; +import org.joda.time.DateTime; +import org.springframework.web.util.UriTemplate; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Schedule execution + */ +@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME) +@JsonTypeName("execution") +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ScheduleExecution { + + public static final String URI = "/gdc/projects/{projectId}/schedules/{scheduleId}/executions/{executionId}"; + public static final UriTemplate TEMPLATE = new UriTemplate(URI); + private static final Set FINISHED_STATUSES = new HashSet<>(Arrays.asList("OK", "ERROR", "CANCELED", "TIMEOUT")); + + private DateTime created; + private String status; + private String trigger; + private String processLastDeployedBy; + + private Map links; + + ScheduleExecution() {} + + @JsonCreator + private ScheduleExecution(@JsonProperty("createdTime") @JsonDeserialize(using = ISODateTimeDeserializer.class) DateTime created, + @JsonProperty("status") String executionStatus, + @JsonProperty("trigger") String trigger, + @JsonProperty("processLastDeployedBy") String processLastDeployedBy, + @JsonProperty("links") Map links) { + this.created = created; + this.status = executionStatus; + this.trigger = trigger; + this.processLastDeployedBy = processLastDeployedBy; + this.links = links; + } + + public String getStatus() { + return status; + } + + public Map getLinks() { + return links; + } + + public DateTime getCreated() { + return created; + } + + public String getTrigger() { + return trigger; + } + + public String getProcessLastDeployedBy() { + return processLastDeployedBy; + } + + @JsonIgnore + public String getUri() { + return notNullState(links, "links").get("self"); + } + + /** + * + * @return whether schedule execution is finished + */ + @JsonIgnore + public boolean isFinished() { + return FINISHED_STATUSES.contains(getStatus()); + } +} diff --git a/src/main/java/com/gooddata/dataload/processes/ScheduleExecutionException.java b/src/main/java/com/gooddata/dataload/processes/ScheduleExecutionException.java new file mode 100644 index 000000000..0a4dcc476 --- /dev/null +++ b/src/main/java/com/gooddata/dataload/processes/ScheduleExecutionException.java @@ -0,0 +1,23 @@ +/** + * Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved. + * This source code is licensed under the BSD-style license found in the + * LICENSE.txt file in the root directory of this source tree. + */ +package com.gooddata.dataload.processes; + +import com.gooddata.GoodDataException; + +/** + * Represents error during schedule execution + */ +public class ScheduleExecutionException extends GoodDataException { + + public ScheduleExecutionException(String message) { + super(message); + } + + public ScheduleExecutionException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/src/test/java/com/gooddata/dataload/processes/ProcessServiceAT.java b/src/test/java/com/gooddata/dataload/processes/ProcessServiceAT.java index 07af74d45..cbbd8d5e1 100644 --- a/src/test/java/com/gooddata/dataload/processes/ProcessServiceAT.java +++ b/src/test/java/com/gooddata/dataload/processes/ProcessServiceAT.java @@ -6,6 +6,7 @@ package com.gooddata.dataload.processes; import com.gooddata.AbstractGoodDataAT; +import com.gooddata.FutureResult; import com.gooddata.collections.PageableList; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -68,6 +69,14 @@ public void createSchedule() { assertThat(schedule.getRescheduleInMinutes(), is(15)); } + @Test(groups = "process", dependsOnMethods = "createSchedule") + public void executeSchedule() { + final FutureResult future = gd.getProcessService().executeSchedule(schedule); + final ScheduleExecution scheduleExecution = future.get(); + + assertThat(scheduleExecution.getStatus(), is("OK")); + } + @Test(groups = "process", dependsOnMethods = "createSchedule") public void createTriggeredSchedule() { triggeredSchedule = gd.getProcessService().createSchedule(project, new Schedule(process, "sdktest.grf", schedule)); diff --git a/src/test/java/com/gooddata/dataload/processes/ProcessServiceIT.java b/src/test/java/com/gooddata/dataload/processes/ProcessServiceIT.java index 948ad6b4b..68b09fc4b 100644 --- a/src/test/java/com/gooddata/dataload/processes/ProcessServiceIT.java +++ b/src/test/java/com/gooddata/dataload/processes/ProcessServiceIT.java @@ -44,6 +44,7 @@ public class ProcessServiceIT extends AbstractGoodDataIT { private static final String SCHEDULE_PATH = Schedule.TEMPLATE.expand(PROJECT_ID, SCHEDULE_ID).toString(); private static final String EXECUTABLE = "test.groovy"; private static final String PROCESS_DEPLOYMENT_POLLING_URI = "/gdc/projects/PROJECT_ID/dataload/processesDeploy/uri"; + private static final String EXECUTION_ID = "EXECUTION_ID"; private Project project; @@ -369,4 +370,37 @@ public void shouldUpdateProcessFromAppstore() { assertThat(updatedProcess.getType(), is(equalTo(ProcessType.RUBY.toString()))); assertThat(updatedProcess.getExecutables(), contains("hello.rb") ); } + + @Test + public void shouldExecuteSchedule() { + onRequest() + .havingMethodEqualTo("POST") + .havingPathEqualTo(schedule.getExecutionsUri()) + .respond() + .withBody(readFromResource("/dataload/processes/scheduleExecution.json")) + .withStatus(200); + + onRequest() + .havingMethodEqualTo("GET") + .havingPathEqualTo(ScheduleExecution.TEMPLATE.expand(PROJECT_ID, SCHEDULE_ID, EXECUTION_ID).toString()) + .respond() + .withBody(readFromResource("/dataload/processes/scheduleExecution.json")) + .withStatus(200); + + FutureResult futureResult = gd.getProcessService().executeSchedule(schedule); + ScheduleExecution scheduleExecution = futureResult.get(); + + assertThat(scheduleExecution.getStatus(), is("OK")); + } + + @Test(expectedExceptions = ScheduleExecutionException.class) + public void shouldNotExecuteSchedule() { + onRequest() + .havingMethodEqualTo("POST") + .havingPathEqualTo(schedule.getExecutionsUri()) + .respond() + .withStatus(409); + + gd.getProcessService().executeSchedule(schedule); + } } diff --git a/src/test/java/com/gooddata/dataload/processes/ProcessServiceTest.java b/src/test/java/com/gooddata/dataload/processes/ProcessServiceTest.java index 39092b899..418ed6469 100644 --- a/src/test/java/com/gooddata/dataload/processes/ProcessServiceTest.java +++ b/src/test/java/com/gooddata/dataload/processes/ProcessServiceTest.java @@ -5,6 +5,7 @@ */ package com.gooddata.dataload.processes; +import com.gooddata.FutureResult; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; import com.gooddata.account.Account; @@ -43,9 +44,11 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.notNull; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import static org.springframework.http.HttpMethod.GET; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; @@ -54,6 +57,8 @@ public class ProcessServiceTest { private static final String PROCESS_ID = "PROCESS_ID"; private static final String PROJECT_ID = "PROJECT_ID"; private static final String ACCOUNT_ID = "ACCOUNT_ID"; + private static final String SCHEDULE_EXECUTIONS_URI = "/gdc/projects/PROJECT_ID/schedules/SCHEDULE_ID/executions"; + private static final String SCHEDULE_EXECUTION_URI = "/gdc/projects/PROJECT_ID/schedules/SCHEDULE_ID/executions/EXECUTION_ID"; private static final String PROCESS_URI = "/gdc/projects/PROJECT_ID/dataload/processes/PROCESS_ID"; private static final String USER_PROCESS_URI = "/gdc/account/profile/ACCOUNT_ID/dataload/processes"; @@ -224,4 +229,34 @@ public void testListUserProcessesWithOneProcesses() throws Exception { assertThat(result, hasSize(1)); assertThat(result, contains(process)); } + + @Test(expectedExceptions = ScheduleExecutionException.class) + public void testExecuteScheduleException() throws Exception { + when(restTemplate.postForObject(eq(SCHEDULE_EXECUTIONS_URI), any(ScheduleExecution.class), eq(ScheduleExecution.class))) + .thenThrow(new RestClientException("")); + + final Schedule schedule = mock(Schedule.class); + + when(schedule.getExecutionsUri()).thenReturn(SCHEDULE_EXECUTIONS_URI); + + processService.executeSchedule(schedule); + } + + @Test(expectedExceptions = ScheduleExecutionException.class) + public void testExecuteScheduleExceptionDuringPolling() throws Exception { + final ScheduleExecution execution = mock(ScheduleExecution.class); + when(execution.getUri()).thenReturn(SCHEDULE_EXECUTION_URI); + + final Schedule schedule = mock(Schedule.class); + when(schedule.getExecutionsUri()).thenReturn(SCHEDULE_EXECUTIONS_URI); + + when(restTemplate.postForObject(eq(SCHEDULE_EXECUTIONS_URI), any(ScheduleExecution.class), eq(ScheduleExecution.class))) + .thenReturn(execution); + + when(restTemplate.execute(eq(SCHEDULE_EXECUTION_URI), eq(GET), any(), any())) + .thenThrow(mock(GoodDataRestException.class)); + + FutureResult futureResult = processService.executeSchedule(schedule); + futureResult.get(); + } } diff --git a/src/test/java/com/gooddata/dataload/processes/ScheduleExecutionTest.java b/src/test/java/com/gooddata/dataload/processes/ScheduleExecutionTest.java new file mode 100644 index 000000000..0f935a7c9 --- /dev/null +++ b/src/test/java/com/gooddata/dataload/processes/ScheduleExecutionTest.java @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved. + * This source code is licensed under the BSD-style license found in the + * LICENSE.txt file in the root directory of this source tree. + */ +package com.gooddata.dataload.processes; + + +import static com.gooddata.JsonMatchers.serializesToJson; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.core.Is.is; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.testng.annotations.Test; + +import java.io.InputStream; +import java.util.HashMap; + +public class ScheduleExecutionTest { + + @Test + public void testEmptyScheduleExecutionSerialization() throws Exception { + final ScheduleExecution scheduleExecution = new ScheduleExecution(); + + assertThat(scheduleExecution, serializesToJson("/dataload/processes/emptyScheduleExecution.json")); + } + + @Test + public void testDeserialization() throws Exception { + final InputStream stream = getClass().getResourceAsStream("/dataload/processes/scheduleExecution.json"); + final ScheduleExecution scheduleExecution = new ObjectMapper().readValue(stream, ScheduleExecution.class); + + assertThat(scheduleExecution, notNullValue()); + assertThat(scheduleExecution.getLinks(), is(equalTo(new HashMap() {{ + put("self", "/gdc/projects/PROJECT_ID/schedules/SCHEDULE_ID/executions/EXECUTION_ID"); + }}))); + assertThat(scheduleExecution.getStatus(), is("OK")); + assertThat(scheduleExecution.getTrigger(), is("MANUAL")); + assertThat(scheduleExecution.getProcessLastDeployedBy(), is("bear@gooddata.com")); + assertThat(scheduleExecution.getCreated(), is(new DateTime(2017, 5, 9, 21, 54, 50, 924, DateTimeZone.UTC))); + } +} diff --git a/src/test/resources/dataload/processes/emptyScheduleExecution.json b/src/test/resources/dataload/processes/emptyScheduleExecution.json new file mode 100644 index 000000000..dcbad84f1 --- /dev/null +++ b/src/test/resources/dataload/processes/emptyScheduleExecution.json @@ -0,0 +1,4 @@ +{ + "execution" : { + } +} diff --git a/src/test/resources/dataload/processes/scheduleExecution.json b/src/test/resources/dataload/processes/scheduleExecution.json new file mode 100644 index 000000000..89fd13e2e --- /dev/null +++ b/src/test/resources/dataload/processes/scheduleExecution.json @@ -0,0 +1,11 @@ +{ + "execution" : { + "createdTime" : "2017-05-09T21:54:50.924Z", + "status" : "OK", + "trigger" : "MANUAL", + "processLastDeployedBy" : "bear@gooddata.com", + "links" : { + "self" : "/gdc/projects/PROJECT_ID/schedules/SCHEDULE_ID/executions/EXECUTION_ID" + } + } +} From ed6e5b66d8360953cb3817dcd4523353545b7ccd Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Mon, 15 May 2017 15:37:40 +0200 Subject: [PATCH 022/702] chg: split duties of reviewer and committer --- CONTRIBUTING.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index df24c472b..c61a4f09f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,19 +3,21 @@ Below are few **rules, recommendations and best practices** we try to follow when developing the _GoodData Java SDK_. ## Paperwork + +### Committer * The **commit message**: * must be written in the **imperative mood** * must clearly **explain rationale** behind this change (describe _why_ you are doing the change rather than _what_ you are changing) * The **pull request**: - * must be **properly labeled** (trivial/bug/enhancement/backward incompatible/...) * with non-trivial change must be **[associated with an issue](https://help.github.com/articles/closing-issues-via-commit-messages/)** - * must be marked with exactly one **milestone version** -* The **issue** - * must be **properly labeled** (bug/enhancement/backward incompatible/...). - * must be marked with exactly one **milestone version** * Add usage examples of new high level functionality to [documentation](https://github.com/gooddata/gooddata-java/wiki/Code-Examples). +### Reviewer +Ensure pull request and issues are + * **properly labeled** (trivial/bug/enhancement/backward incompatible/...) + * marked with exactly one **milestone version** + ## Design ### Structure From 71aae8d9213ceb036bc064f23cc09f2de27a9d20 Mon Sep 17 00:00:00 2001 From: Matej Plch Date: Fri, 12 May 2017 17:06:17 +0200 Subject: [PATCH 023/702] FEATURE: Enable to customize user-agent --- src/main/java/com/gooddata/GoodData.java | 3 ++- .../java/com/gooddata/GoodDataSettings.java | 19 +++++++++++++++++++ .../com/gooddata/GoodDataSettingsTest.java | 11 +++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gooddata/GoodData.java b/src/main/java/com/gooddata/GoodData.java index 7a575c319..7d872bbbe 100644 --- a/src/main/java/com/gooddata/GoodData.java +++ b/src/main/java/com/gooddata/GoodData.java @@ -22,6 +22,7 @@ import com.gooddata.model.ModelService; import com.gooddata.project.ProjectService; import com.gooddata.report.ReportService; +import org.apache.commons.lang3.StringUtils; import org.apache.http.client.HttpClient; import org.apache.http.client.config.RequestConfig; import org.apache.http.config.SocketConfig; @@ -246,7 +247,7 @@ private HttpClientBuilder createHttpClientBuilder(final GoodDataSettings setting requestConfig.setSocketTimeout(settings.getSocketTimeout()); return HttpClientBuilder.create() - .setUserAgent(getUserAgent()) + .setUserAgent(StringUtils.isNotBlank(settings.getUserAgent()) ? String.format("%s %s", settings.getUserAgent(), getUserAgent()) : getUserAgent()) .setConnectionManager(connectionManager) .setDefaultRequestConfig(requestConfig.build()); } diff --git a/src/main/java/com/gooddata/GoodDataSettings.java b/src/main/java/com/gooddata/GoodDataSettings.java index 46ccd30ff..f35a09145 100644 --- a/src/main/java/com/gooddata/GoodDataSettings.java +++ b/src/main/java/com/gooddata/GoodDataSettings.java @@ -5,6 +5,8 @@ */ package com.gooddata; +import org.apache.commons.lang.StringUtils; + import java.util.concurrent.TimeUnit; import static org.springframework.util.Assert.isTrue; @@ -22,6 +24,7 @@ public class GoodDataSettings { private int connectionTimeout = secondsToMillis(10); private int connectionRequestTimeout = secondsToMillis(10); private int socketTimeout = secondsToMillis(60); + private String userAgent; /** @@ -155,6 +158,22 @@ public int getSocketTimeout() { return socketTimeout; } + /** + * User agent + * @return user agent string + */ + public String getUserAgent() { + return userAgent; + } + + /** + * Set custom user agent as prefix for default user agent + * @param userAgent user agent string + */ + public void setUserAgent(String userAgent) { + this.userAgent = userAgent; + } + @Override public boolean equals(final Object o) { if (this == o) return true; diff --git a/src/test/java/com/gooddata/GoodDataSettingsTest.java b/src/test/java/com/gooddata/GoodDataSettingsTest.java index 42bffade7..d4d6a7c45 100644 --- a/src/test/java/com/gooddata/GoodDataSettingsTest.java +++ b/src/test/java/com/gooddata/GoodDataSettingsTest.java @@ -8,6 +8,9 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; @@ -26,6 +29,7 @@ public void testHasDefaults() throws Exception { assertTrue(settings.getConnectionTimeout() >= 0); assertTrue(settings.getConnectionRequestTimeout() >= 0); assertTrue(settings.getSocketTimeout() >= 0); + assertThat(settings.getUserAgent(), is(nullValue())); } @Test @@ -58,4 +62,11 @@ public void setNegativeSocketTimeoutFails() throws Exception { public void setZeroMaxConnectionsFails() throws Exception { settings.setMaxConnections(0); } + + @Test + public void customUserAgentShouldBePrefixOfDefault() { + GoodDataSettings goodDataSettings = new GoodDataSettings(); + goodDataSettings.setUserAgent("customAgent/X.Y"); + assertThat(goodDataSettings.getUserAgent(), is("customAgent/X.Y")); + } } \ No newline at end of file From a4c70d90dbf10c7d469a3151aedc868fefe8d75c Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Tue, 16 May 2017 11:23:44 +0200 Subject: [PATCH 024/702] [maven-release-plugin] prepare release gooddata-java-2.6.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 667ebad1e..a5d020cf0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.gooddata gooddata-java - 2.5.1-SNAPSHOT + 2.6.0 ${project.artifactId} GoodData Java SDK https://github.com/gooddata/gooddata-java From 5c8da9d636d32cd17f783bbf30ac519fc09b1fd4 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Tue, 16 May 2017 11:23:44 +0200 Subject: [PATCH 025/702] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a5d020cf0..a95081d36 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.gooddata gooddata-java - 2.6.0 + 2.6.1-SNAPSHOT ${project.artifactId} GoodData Java SDK https://github.com/gooddata/gooddata-java From 8cd98172e820624403297ff1a57a939910f5afb1 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Tue, 16 May 2017 11:30:36 +0200 Subject: [PATCH 026/702] bump version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f1dc8c023..218d669cc 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The *GoodData Java SDK* is available in Maven Central Repository, to use it from com.gooddata gooddata-java - 2.5.0 + 2.6.0 ``` See [releases page](https://github.com/gooddata/gooddata-java/releases) for information about versions and notable changes, From 926b0eedb28929bf468c5759ad0c9923b76b9eb4 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Wed, 17 May 2017 09:36:18 +0200 Subject: [PATCH 027/702] handle a new type of exception WebDAV throws with R136 --- src/main/java/com/gooddata/gdc/DataStoreService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/gooddata/gdc/DataStoreService.java b/src/main/java/com/gooddata/gdc/DataStoreService.java index bfd75ff57..eb6b7bbe9 100644 --- a/src/main/java/com/gooddata/gdc/DataStoreService.java +++ b/src/main/java/com/gooddata/gdc/DataStoreService.java @@ -14,6 +14,7 @@ import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; +import org.apache.http.NoHttpResponseException; import org.apache.http.ProtocolVersion; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; @@ -111,6 +112,11 @@ private void upload(URI url, InputStream stream) { } else { throw new DataStoreException("Unable to upload to " + url + " got status " + e.getStatusCode(), e); } + } catch (NoHttpResponseException e) { + // this error may occur when user issues request to WebDAV before SST and TT were obtained + // and WebDAV is deployed on a separate hostname since R136 + // see https://github.com/gooddata/gooddata-java/wiki/Known-limitations + throw new DataStoreException(createUnAuthRequestWarningMessage(url), e); } catch (IOException e) { // this error may occur when user issues request to WebDAV before SST and TT were obtained // and WebDAV deployed on the same hostname From 28101f6f6e94a627b75291bd983a05ffa4c7795f Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Tue, 23 May 2017 10:36:55 +0200 Subject: [PATCH 028/702] fix: skip test as the fix on server side is scheduled for R136 --- src/test/java/com/gooddata/gdc/DatastoreServiceAT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/gooddata/gdc/DatastoreServiceAT.java b/src/test/java/com/gooddata/gdc/DatastoreServiceAT.java index 274fbf506..c1e3e6b64 100644 --- a/src/test/java/com/gooddata/gdc/DatastoreServiceAT.java +++ b/src/test/java/com/gooddata/gdc/DatastoreServiceAT.java @@ -92,8 +92,8 @@ public void datastoreConnectionClosedAfterSingleConnection() throws Exception { assertThat(connManager.getTotalStats().getLeased(), is(equalTo(0))); } - @Test(groups = "datastore", expectedExceptions = DataStoreException.class, - expectedExceptionsMessageRegExp = "(?s).* 500 .*https://github.com/.*/Known-limitations") + @Test(groups = "datastore", expectedExceptions = DataStoreException.class, enabled = false, + expectedExceptionsMessageRegExp = "(?s).* 500 .*https://github.com/.Known-limitations") public void shouldThrowExceptionWithMessageOnUnAuthRequest() throws Exception { final GoodData datastoreGd = new GoodData(getProperty("host"), getProperty("login"), getProperty("pass")); DataStoreService dataStoreService = datastoreGd.getDataStoreService(); From 722be536809ef2139c2591dccc24ad912faa3f07 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Tue, 23 May 2017 11:29:13 +0200 Subject: [PATCH 029/702] add windows CI build close #235 --- .appveyor.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .appveyor.yml diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 000000000..7468fa0c5 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,17 @@ +version: "{branch} {build}" + +branches: + only: + - master + +cache: + - C:\Users\appveyor\.m2 + +install: + - SET JAVA_HOME=C:\Program Files\Java\jdk1.8.0 + +build_script: + - mvn clean test-compile + +test_script: + - mvn verify From 88e38ceb3c1704e6af6c3a6bbdcc3dafde87891c Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Tue, 23 May 2017 22:04:09 +0200 Subject: [PATCH 030/702] use ResourceUtils in tests --- .../java/com/gooddata/AbstractGoodDataIT.java | 2 - .../gooddata/GoodDataRestExceptionTest.java | 9 ++-- .../gooddata/account/AccountServiceIT.java | 5 +- .../com/gooddata/account/AccountTest.java | 5 +- .../com/gooddata/collections/PagingTest.java | 10 ++-- .../connector/ConnectorServiceIT.java | 8 ++-- .../IntegrationProcessStatusTest.java | 5 +- .../gooddata/connector/IntegrationTest.java | 5 +- .../gooddata/connector/ProcessStatusTest.java | 5 +- .../connector/Zendesk4SettingsTest.java | 5 +- .../dataload/OutputStageServiceIT.java | 20 ++++---- .../dataload/OutputStageServiceTest.java | 29 +++++------- .../gooddata/dataload/OutputStageTest.java | 25 ++++------ .../processes/DataloadProcessTest.java | 11 ++--- .../processes/DataloadProcessesTest.java | 8 ++-- .../processes/ProcessExecutionDetailTest.java | 8 ++-- .../processes/ProcessExecutionTaskTest.java | 11 ++--- .../processes/ProcessExecutionTest.java | 14 +++--- .../dataload/processes/ProcessServiceIT.java | 13 +++-- .../processes/ScheduleExecutionTest.java | 18 ++++--- .../dataload/processes/ScheduleTest.java | 8 ++-- .../dataload/processes/SchedulesTest.java | 10 ++-- .../gooddata/dataset/DatasetLinksTest.java | 6 +-- .../gooddata/dataset/DatasetManifestTest.java | 9 ++-- .../gooddata/dataset/DatasetServiceIT.java | 28 ++++++----- .../com/gooddata/dataset/DatasetTest.java | 7 +-- .../com/gooddata/dataset/DatasetsTest.java | 6 +-- .../com/gooddata/dataset/MaqlDmlTest.java | 3 +- .../com/gooddata/dataset/PullTaskTest.java | 7 +-- .../com/gooddata/dataset/TaskStateTest.java | 9 ++-- .../dataset/UploadStatisticsTest.java | 7 ++- .../java/com/gooddata/dataset/UploadTest.java | 18 +++---- .../com/gooddata/dataset/UploadsInfoTest.java | 17 +++---- .../com/gooddata/dataset/UploadsTest.java | 16 +++---- .../featureflag/FeatureFlagServiceIT.java | 10 ++-- .../java/com/gooddata/gdc/AboutLinksTest.java | 6 +-- .../java/com/gooddata/gdc/AsyncTaskTest.java | 14 ++---- .../com/gooddata/gdc/ErrorStructureTest.java | 7 +-- .../java/com/gooddata/gdc/GdcErrorTest.java | 7 +-- src/test/java/com/gooddata/gdc/GdcTest.java | 7 +-- .../com/gooddata/gdc/LinkEntriesTest.java | 12 ++--- .../java/com/gooddata/gdc/RootLinksTest.java | 7 +-- .../java/com/gooddata/gdc/TaskStatusTest.java | 13 +++-- .../com/gooddata/gdc/UriResponseTest.java | 7 +-- .../gooddata/md/AttributeDisplayFormTest.java | 10 ++-- .../com/gooddata/md/AttributeElementTest.java | 14 ++---- .../gooddata/md/AttributeElementsTest.java | 16 +++---- .../com/gooddata/md/AttributeSortTest.java | 18 +++---- .../java/com/gooddata/md/AttributeTest.java | 14 ++---- src/test/java/com/gooddata/md/ColumnTest.java | 14 ++---- .../gooddata/md/DataLoadingColumnTest.java | 14 ++---- .../java/com/gooddata/md/DatasetTest.java | 14 +++--- .../java/com/gooddata/md/DimensionTest.java | 16 +++---- .../java/com/gooddata/md/DisplayFormTest.java | 7 +-- src/test/java/com/gooddata/md/EntryTest.java | 4 +- .../java/com/gooddata/md/ExpressionTest.java | 7 ++- src/test/java/com/gooddata/md/FactTest.java | 4 +- src/test/java/com/gooddata/md/KeyTest.java | 7 ++- src/test/java/com/gooddata/md/MetaTest.java | 4 +- .../com/gooddata/md/MetadataServiceIT.java | 15 +++--- src/test/java/com/gooddata/md/MetricTest.java | 22 ++++----- .../com/gooddata/md/NestedAttributeTest.java | 19 ++++---- src/test/java/com/gooddata/md/ObjTest.java | 6 +-- .../com/gooddata/md/ProjectDashboardTest.java | 11 ++--- src/test/java/com/gooddata/md/QueryTest.java | 6 +-- .../com/gooddata/md/ScheduledMailTest.java | 10 ++-- .../com/gooddata/md/TableDataLoadTest.java | 14 ++---- src/test/java/com/gooddata/md/TableTest.java | 14 ++---- .../md/maintenance/ExportImportServiceIT.java | 3 +- .../md/maintenance/PartialMdArtifactTest.java | 15 +++--- .../md/report/AttributeInGridTest.java | 11 ++--- .../report/GridElementDeserializerTest.java | 5 +- .../GridReportDefinitionContentTest.java | 7 ++- .../java/com/gooddata/md/report/GridTest.java | 13 +++-- .../gooddata/md/report/MetricElementTest.java | 7 +-- .../OneNumberReportDefinitionContentTest.java | 8 ++-- .../report/ReportDefinitionContentTest.java | 6 +-- .../md/report/ReportDefinitionTest.java | 9 ++-- .../com/gooddata/md/report/ReportTest.java | 8 ++-- .../com/gooddata/model/DiffRequestTest.java | 6 +-- .../com/gooddata/model/MaqlDdlLinksTest.java | 7 +-- .../java/com/gooddata/model/MaqlDdlTest.java | 4 +- .../com/gooddata/model/ModelDiffTest.java | 6 +-- .../com/gooddata/model/ModelServiceIT.java | 14 +++--- .../notification/NotificationServiceIT.java | 3 +- .../gooddata/project/ProjectServiceIT.java | 47 +++++++++---------- .../gooddata/project/ProjectTemplateTest.java | 8 ++-- .../project/ProjectTemplatesTest.java | 5 +- .../com/gooddata/project/ProjectTest.java | 17 +++---- .../ProjectValidationResultItemTest.java | 5 +- .../ProjectValidationResultParamTest.java | 3 +- .../project/ProjectValidationResultTest.java | 8 ++-- .../project/ProjectValidationResultsTest.java | 5 +- .../project/ProjectValidationTypeTest.java | 6 +-- .../project/ProjectValidationsTest.java | 5 +- .../java/com/gooddata/project/RoleTest.java | 6 +-- .../java/com/gooddata/project/RolesTest.java | 10 ++-- .../java/com/gooddata/project/UserTest.java | 10 ++-- .../java/com/gooddata/project/UsersTest.java | 7 +-- .../com/gooddata/report/ReportServiceIT.java | 12 +++-- .../util/BooleanDeserializerTest.java | 27 +++++------ .../util/BooleanIntegerSerializerTest.java | 12 ++--- .../util/BooleanStringSerializerTest.java | 12 ++--- .../gooddata/util/GDDateDeserializerTest.java | 9 ++-- .../gooddata/util/GDDateSerializerTest.java | 8 ++-- .../util/GDDateTimeDeserializerTest.java | 10 ++-- .../util/GDDateTimeSerializerTest.java | 8 ++-- .../util/ISODateTimeDeserializerTest.java | 10 ++-- .../util/ISODateTimeSerializerTest.java | 8 ++-- .../util/ResponseErrorHandlerTest.java | 4 +- .../gooddata/util/TagsDeserializerTest.java | 14 +++--- .../com/gooddata/util/TagsSerializerTest.java | 10 ++-- .../warehouse/WarehouseSchemaTest.java | 19 ++++---- .../warehouse/WarehouseServiceIT.java | 16 ++++--- .../gooddata/warehouse/WarehouseTaskTest.java | 16 ++----- .../com/gooddata/warehouse/WarehouseTest.java | 10 ++-- .../gooddata/warehouse/WarehouseUserTest.java | 8 ++-- 117 files changed, 509 insertions(+), 715 deletions(-) diff --git a/src/test/java/com/gooddata/AbstractGoodDataIT.java b/src/test/java/com/gooddata/AbstractGoodDataIT.java index 86e04563d..ed958d9a9 100644 --- a/src/test/java/com/gooddata/AbstractGoodDataIT.java +++ b/src/test/java/com/gooddata/AbstractGoodDataIT.java @@ -6,7 +6,6 @@ package com.gooddata; import com.gooddata.authentication.LoginPasswordAuthentication; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -16,7 +15,6 @@ public abstract class AbstractGoodDataIT { - protected static final ObjectMapper MAPPER = new ObjectMapper(); protected GoodData gd; @BeforeMethod diff --git a/src/test/java/com/gooddata/GoodDataRestExceptionTest.java b/src/test/java/com/gooddata/GoodDataRestExceptionTest.java index c69afe096..c2f9fef3c 100644 --- a/src/test/java/com/gooddata/GoodDataRestExceptionTest.java +++ b/src/test/java/com/gooddata/GoodDataRestExceptionTest.java @@ -6,14 +6,12 @@ package com.gooddata; import com.gooddata.gdc.GdcError; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.MatcherAssert.assertThat; public class GoodDataRestExceptionTest { @Test @@ -69,8 +67,7 @@ public void shouldCreateInstanceWithNullStatusAndGdcError() throws Exception { @Test public void shouldCreateInstanceWithGdcError() throws Exception { - final InputStream inputStream = getClass().getResourceAsStream("/gdc/gdcError.json"); - final GdcError err = new ObjectMapper().readValue(inputStream, GdcError.class); + final GdcError err = readObjectFromResource("/gdc/gdcError.json", GdcError.class); final GoodDataRestException e = new GoodDataRestException(500, "a123", "message", err); assertThat(e.getMessage(), is("500: [requestId=REQ] MSG")); diff --git a/src/test/java/com/gooddata/account/AccountServiceIT.java b/src/test/java/com/gooddata/account/AccountServiceIT.java index af2912354..4caaee149 100644 --- a/src/test/java/com/gooddata/account/AccountServiceIT.java +++ b/src/test/java/com/gooddata/account/AccountServiceIT.java @@ -13,6 +13,7 @@ import java.io.IOException; import static com.gooddata.util.ResourceUtils.readFromResource; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static net.jadler.Jadler.onRequest; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; @@ -33,8 +34,8 @@ public class AccountServiceIT extends AbstractGoodDataIT { @BeforeClass public void init() throws IOException { - account = MAPPER.readValue(readFromResource(ACCOUNT), Account.class); - createAccount = MAPPER.readValue(readFromResource(CREATE_ACCOUNT), Account.class); + account = readObjectFromResource(ACCOUNT, Account.class); + createAccount = readObjectFromResource(CREATE_ACCOUNT, Account.class); } @Test diff --git a/src/test/java/com/gooddata/account/AccountTest.java b/src/test/java/com/gooddata/account/AccountTest.java index d428990bb..a6439efd7 100644 --- a/src/test/java/com/gooddata/account/AccountTest.java +++ b/src/test/java/com/gooddata/account/AccountTest.java @@ -5,10 +5,10 @@ */ package com.gooddata.account; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -23,8 +23,7 @@ public class AccountTest { @SuppressWarnings("deprecation") @Test public void testDeserialize() throws Exception { - final Account account = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/account/account.json"), Account.class); + final Account account = readObjectFromResource("/account/account.json", Account.class); assertThat(account, is(notNullValue())); assertThat(account.getFirstName(), is(FIRST_NAME)); diff --git a/src/test/java/com/gooddata/collections/PagingTest.java b/src/test/java/com/gooddata/collections/PagingTest.java index 67bf1f0fd..888debed8 100644 --- a/src/test/java/com/gooddata/collections/PagingTest.java +++ b/src/test/java/com/gooddata/collections/PagingTest.java @@ -11,6 +11,7 @@ import java.io.InputStream; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -20,8 +21,7 @@ public class PagingTest { @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/collections/paging.json"); - final Paging paging = new ObjectMapper().readValue(stream, Paging.class); + final Paging paging = readObjectFromResource("/collections/paging.json", Paging.class); assertThat(paging.getOffset(), is("0")); assertThat(paging.getNext(), notNullValue()); @@ -30,8 +30,7 @@ public void testDeserialization() throws Exception { @Test public void testDeserializationNullNext() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/collections/paging_no_next.json"); - final Paging paging = new ObjectMapper().readValue(stream, Paging.class); + final Paging paging = readObjectFromResource("/collections/paging_no_next.json", Paging.class); assertThat(paging.getOffset(), is("0")); assertThat(paging.getNext(), nullValue()); @@ -39,8 +38,7 @@ public void testDeserializationNullNext() throws Exception { @Test public void testDeserializationWithNextOnly() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/collections/paging_only_next.json"); - final Paging paging = new ObjectMapper().readValue(stream, Paging.class); + final Paging paging = readObjectFromResource("/collections/paging_only_next.json", Paging.class); assertThat(paging.getOffset(), is(nullValue())); assertThat(paging.getNext(), notNullValue()); diff --git a/src/test/java/com/gooddata/connector/ConnectorServiceIT.java b/src/test/java/com/gooddata/connector/ConnectorServiceIT.java index 117f75e33..1356ee806 100644 --- a/src/test/java/com/gooddata/connector/ConnectorServiceIT.java +++ b/src/test/java/com/gooddata/connector/ConnectorServiceIT.java @@ -28,7 +28,7 @@ public class ConnectorServiceIT extends AbstractGoodDataIT { @BeforeMethod public void setUp() throws Exception { - project = MAPPER.readValue(readFromResource("/project/project.json"), Project.class); + project = readObjectFromResource("/project/project.json", Project.class); connectors = gd.getConnectorService(); } @@ -109,7 +109,7 @@ public void shouldExecuteProcess() throws Exception { .havingMethodEqualTo("POST") .havingPathEqualTo("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes") .respond() - .withBody(MAPPER.writeValueAsString(new UriResponse("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS"))); + .withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS"))); onRequest() .havingPathEqualTo("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS") .respond() @@ -128,7 +128,7 @@ public void shouldFailExecuteProcessPolling() throws Exception { .havingMethodEqualTo("POST") .havingPathEqualTo("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes") .respond() - .withBody(MAPPER.writeValueAsString(new UriResponse("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS"))); + .withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS"))); onRequest() .havingPathEqualTo("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS") .respond() @@ -143,7 +143,7 @@ public void shouldFailExecuteProcess() throws Exception { .havingMethodEqualTo("POST") .havingPathEqualTo("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes") .respond() - .withBody(MAPPER.writeValueAsString(new UriResponse("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS"))); + .withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS"))); onRequest() .havingPathEqualTo("/gdc/projects/PROJECT_ID/connectors/zendesk4/integration/processes/PROCESS") .respond() diff --git a/src/test/java/com/gooddata/connector/IntegrationProcessStatusTest.java b/src/test/java/com/gooddata/connector/IntegrationProcessStatusTest.java index 95efece28..812c965b7 100644 --- a/src/test/java/com/gooddata/connector/IntegrationProcessStatusTest.java +++ b/src/test/java/com/gooddata/connector/IntegrationProcessStatusTest.java @@ -5,7 +5,6 @@ */ package com.gooddata.connector; -import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.testng.annotations.Test; @@ -16,6 +15,7 @@ import static com.gooddata.connector.Status.Code.SYNCHRONIZED; import static com.gooddata.connector.Status.Code.UPLOADING; import static com.gooddata.connector.Status.Code.USER_ERROR; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; @@ -27,8 +27,7 @@ public class IntegrationProcessStatusTest { @Test public void testShouldDeserialize() throws Exception { - final IntegrationProcessStatus process = new ObjectMapper() - .readValue(getClass().getResource("/connector/process-status-embedded.json"), IntegrationProcessStatus.class); + final IntegrationProcessStatus process = readObjectFromResource("/connector/process-status-embedded.json", IntegrationProcessStatus.class); assertThat(process, is(notNullValue())); assertThat(process.getStarted(), is(new DateTime(2014, 5, 30, 7, 50, 15, DateTimeZone.UTC))); diff --git a/src/test/java/com/gooddata/connector/IntegrationTest.java b/src/test/java/com/gooddata/connector/IntegrationTest.java index 0fee2cfb9..198b06db4 100644 --- a/src/test/java/com/gooddata/connector/IntegrationTest.java +++ b/src/test/java/com/gooddata/connector/IntegrationTest.java @@ -5,10 +5,10 @@ */ package com.gooddata.connector; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @@ -19,8 +19,7 @@ public class IntegrationTest { @Test public void shouldDeserialize() throws Exception { - final Integration integration = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/connector/integration.json"), Integration.class); + final Integration integration = readObjectFromResource("/connector/integration.json", Integration.class); assertThat(integration, is(notNullValue())); assertThat(integration.isActive(), is(true)); diff --git a/src/test/java/com/gooddata/connector/ProcessStatusTest.java b/src/test/java/com/gooddata/connector/ProcessStatusTest.java index 861d5495e..f68ed8e83 100644 --- a/src/test/java/com/gooddata/connector/ProcessStatusTest.java +++ b/src/test/java/com/gooddata/connector/ProcessStatusTest.java @@ -5,10 +5,10 @@ */ package com.gooddata.connector; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; import static com.gooddata.connector.Status.Code.ERROR; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @@ -17,8 +17,7 @@ public class ProcessStatusTest { @Test public void shouldDeserialize() throws Exception { - final ProcessStatus process = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/connector/process-status-error.json"), ProcessStatus.class); + final ProcessStatus process = readObjectFromResource("/connector/process-status-error.json", ProcessStatus.class); assertThat(process, is(notNullValue())); assertThat(process.getFinished(), is(notNullValue())); diff --git a/src/test/java/com/gooddata/connector/Zendesk4SettingsTest.java b/src/test/java/com/gooddata/connector/Zendesk4SettingsTest.java index 83cf5aef3..2ba04dbbd 100644 --- a/src/test/java/com/gooddata/connector/Zendesk4SettingsTest.java +++ b/src/test/java/com/gooddata/connector/Zendesk4SettingsTest.java @@ -5,12 +5,12 @@ */ package com.gooddata.connector; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; import static com.gooddata.JsonMatchers.serializesToJson; import static com.gooddata.connector.ConnectorType.ZENDESK4; import static com.gooddata.connector.Zendesk4Settings.Zendesk4Type.plus; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -26,8 +26,7 @@ public void shouldSerialize() throws Exception { @Test public void shouldDeserialize() throws Exception { - final Zendesk4Settings settings = new ObjectMapper() - .readValue(getClass().getResource("/connector/settings-zendesk4.json"), Zendesk4Settings.class); + final Zendesk4Settings settings = readObjectFromResource("/connector/settings-zendesk4.json", Zendesk4Settings.class); assertThat(settings, is(notNullValue())); assertThat(settings.getApiUrl(), is("https://foo.com")); diff --git a/src/test/java/com/gooddata/dataload/OutputStageServiceIT.java b/src/test/java/com/gooddata/dataload/OutputStageServiceIT.java index a6e593d31..52d63cc56 100644 --- a/src/test/java/com/gooddata/dataload/OutputStageServiceIT.java +++ b/src/test/java/com/gooddata/dataload/OutputStageServiceIT.java @@ -5,7 +5,13 @@ */ package com.gooddata.dataload; +import com.gooddata.AbstractGoodDataIT; +import com.gooddata.project.Project; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + import static com.gooddata.util.ResourceUtils.readFromResource; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static com.gooddata.util.ResourceUtils.readStringFromResource; import static net.jadler.Jadler.onRequest; import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals; @@ -16,15 +22,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.gooddata.AbstractGoodDataIT; - -import com.gooddata.project.Project; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.io.InputStream; - public class OutputStageServiceIT extends AbstractGoodDataIT { private static final String OUTPUT_STAGE_ALL_FIELDS = "/dataload/outputStageAllFields.json"; @@ -41,7 +38,7 @@ public class OutputStageServiceIT extends AbstractGoodDataIT { @BeforeClass public void setUp() throws Exception { - outputStage = MAPPER.readValue(readFromResource(OUTPUT_STAGE_ALL_FIELDS), OutputStage.class); + outputStage = readObjectFromResource(OUTPUT_STAGE_ALL_FIELDS, OutputStage.class); project = mock(Project.class); when(project.getId()).thenReturn(PROJECT_ID); } @@ -78,8 +75,7 @@ public void shouldGetOutputStage() throws Exception { @Test public void shouldUpdateOutputStage() throws Exception { - final InputStream stream = getClass().getResourceAsStream(OUTPUT_STAGE); - final OutputStage outputStage = new ObjectMapper().readValue(stream, OutputStage.class); + final OutputStage outputStage = readObjectFromResource(OUTPUT_STAGE, OutputStage.class); onRequest() .havingMethodEqualTo("PUT") diff --git a/src/test/java/com/gooddata/dataload/OutputStageServiceTest.java b/src/test/java/com/gooddata/dataload/OutputStageServiceTest.java index 64961660c..c5de8c24a 100644 --- a/src/test/java/com/gooddata/dataload/OutputStageServiceTest.java +++ b/src/test/java/com/gooddata/dataload/OutputStageServiceTest.java @@ -5,19 +5,6 @@ */ package com.gooddata.dataload; -import static com.gooddata.util.ResourceUtils.readFromResource; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.core.Is.is; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.mockito.Matchers.any; -import static org.hamcrest.MatcherAssert.assertThat; - -import com.fasterxml.jackson.databind.ObjectMapper; import com.gooddata.project.Project; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -28,9 +15,19 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -public class OutputStageServiceTest { +import static com.gooddata.util.ResourceUtils.readObjectFromResource; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; - private final ObjectMapper MAPPER = new ObjectMapper(); +public class OutputStageServiceTest { private static final String OUTPUT_STAGE = "/dataload/outputStage.json"; @@ -45,7 +42,7 @@ public class OutputStageServiceTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); outputStageService = new OutputStageService(restTemplate); - outputStage = MAPPER.readValue(readFromResource(OUTPUT_STAGE), OutputStage.class); + outputStage = readObjectFromResource(OUTPUT_STAGE, OutputStage.class); } @Test(expectedExceptions = IllegalArgumentException.class) diff --git a/src/test/java/com/gooddata/dataload/OutputStageTest.java b/src/test/java/com/gooddata/dataload/OutputStageTest.java index 6d9cf1cd8..bcdf938ad 100644 --- a/src/test/java/com/gooddata/dataload/OutputStageTest.java +++ b/src/test/java/com/gooddata/dataload/OutputStageTest.java @@ -5,20 +5,19 @@ */ package com.gooddata.dataload; +import org.testng.annotations.Test; + +import java.util.LinkedHashMap; +import java.util.Map; + import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.text.MatchesPattern.matchesPattern; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.testng.annotations.Test; - -import java.io.InputStream; -import java.util.LinkedHashMap; -import java.util.Map; - public class OutputStageTest { private static final String SCHEMA_URI = "/gdc/datawarehouse/instances/instanceId/schemas/default"; @@ -36,8 +35,7 @@ public class OutputStageTest { @Test public void testDeserializationAllFields() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/dataload/outputStageAllFields.json"); - final OutputStage outputStage = new ObjectMapper().readValue(stream, OutputStage.class); + final OutputStage outputStage = readObjectFromResource("/dataload/outputStageAllFields.json", OutputStage.class); assertThat(outputStage.getSchemaUri(), is(equalTo(SCHEMA_URI))); assertThat(outputStage.getClientId(), is(equalTo(CLIENT_ID))); @@ -53,8 +51,7 @@ public void testDeserializationAllFields() throws Exception { @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/dataload/outputStage.json"); - final OutputStage outputStage = new ObjectMapper().readValue(stream, OutputStage.class); + final OutputStage outputStage = readObjectFromResource("/dataload/outputStage.json", OutputStage.class); assertThat(outputStage.getSchemaUri(), is(nullValue())); assertThat(outputStage.getClientId(), is(nullValue())); @@ -69,8 +66,7 @@ public void testDeserialization() throws Exception { @Test public void testSerializationAfterDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/dataload/outputStage.json"); - final OutputStage outputStage = new ObjectMapper().readValue(stream, OutputStage.class); + final OutputStage outputStage = readObjectFromResource("/dataload/outputStage.json", OutputStage.class); outputStage.setSchemaUri(SCHEMA_URI); outputStage.setClientId(CLIENT_ID); @@ -80,8 +76,7 @@ public void testSerializationAfterDeserialization() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/dataload/outputStage.json"); - final OutputStage outputStage = new ObjectMapper().readValue(stream, OutputStage.class); + final OutputStage outputStage = readObjectFromResource("/dataload/outputStage.json", OutputStage.class); assertThat(outputStage.toString(), matchesPattern(OutputStage.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/dataload/processes/DataloadProcessTest.java b/src/test/java/com/gooddata/dataload/processes/DataloadProcessTest.java index cac3617dc..b633379e5 100644 --- a/src/test/java/com/gooddata/dataload/processes/DataloadProcessTest.java +++ b/src/test/java/com/gooddata/dataload/processes/DataloadProcessTest.java @@ -5,24 +5,23 @@ */ package com.gooddata.dataload.processes; +import org.testng.annotations.Test; + import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.text.MatchesPattern.matchesPattern; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.testng.annotations.Test; - public class DataloadProcessTest { @SuppressWarnings("deprecation") @Test public void testDeserialization() throws Exception { - final DataloadProcess process = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/dataload/processes/process.json"), DataloadProcess.class); + final DataloadProcess process = readObjectFromResource("/dataload/processes/process.json", DataloadProcess.class); assertThat(process, is(notNullValue())); assertThat(process.getName(), is("testProcess")); diff --git a/src/test/java/com/gooddata/dataload/processes/DataloadProcessesTest.java b/src/test/java/com/gooddata/dataload/processes/DataloadProcessesTest.java index 0aabe61c4..3fd5dccad 100644 --- a/src/test/java/com/gooddata/dataload/processes/DataloadProcessesTest.java +++ b/src/test/java/com/gooddata/dataload/processes/DataloadProcessesTest.java @@ -5,9 +5,9 @@ */ package com.gooddata.dataload.processes; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -18,8 +18,7 @@ public class DataloadProcessesTest { @Test public void testDeserialization() throws Exception { - final DataloadProcesses processes = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/dataload/processes/processes.json"), DataloadProcesses.class); + final DataloadProcesses processes = readObjectFromResource("/dataload/processes/processes.json", DataloadProcesses.class); assertThat(processes, is(notNullValue())); assertThat(processes.getItems(), hasSize(1)); @@ -27,8 +26,7 @@ public void testDeserialization() throws Exception { @Test public void testToStringFormat() throws Exception { - final DataloadProcesses processes = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/dataload/processes/processes.json"), DataloadProcesses.class); + final DataloadProcesses processes = readObjectFromResource("/dataload/processes/processes.json", DataloadProcesses.class); assertThat(processes.toString(), matchesPattern(DataloadProcesses.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/dataload/processes/ProcessExecutionDetailTest.java b/src/test/java/com/gooddata/dataload/processes/ProcessExecutionDetailTest.java index 467ff2782..9d0635567 100644 --- a/src/test/java/com/gooddata/dataload/processes/ProcessExecutionDetailTest.java +++ b/src/test/java/com/gooddata/dataload/processes/ProcessExecutionDetailTest.java @@ -5,11 +5,11 @@ */ package com.gooddata.dataload.processes; -import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.core.Is.is; @@ -17,11 +17,9 @@ public class ProcessExecutionDetailTest { - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Test public void testDeserialization() throws Exception { - final ProcessExecutionDetail executionDetail = MAPPER.readValue(getClass().getResourceAsStream("/dataload/processes/executionDetail.json"), + final ProcessExecutionDetail executionDetail = readObjectFromResource("/dataload/processes/executionDetail.json", ProcessExecutionDetail.class); assertThat(executionDetail, notNullValue()); assertThat(executionDetail.getStatus(), is("ERROR")); @@ -40,7 +38,7 @@ public void testDeserialization() throws Exception { @Test public void testToStringFormat() throws Exception { - final ProcessExecutionDetail executionDetail = MAPPER.readValue(getClass().getResourceAsStream("/dataload/processes/executionDetail.json"), + final ProcessExecutionDetail executionDetail = readObjectFromResource("/dataload/processes/executionDetail.json", ProcessExecutionDetail.class); assertThat(executionDetail.toString(), matchesPattern(ProcessExecutionDetail.class.getSimpleName() + "\\[.*\\]")); diff --git a/src/test/java/com/gooddata/dataload/processes/ProcessExecutionTaskTest.java b/src/test/java/com/gooddata/dataload/processes/ProcessExecutionTaskTest.java index 9f4a38576..24221f8e9 100644 --- a/src/test/java/com/gooddata/dataload/processes/ProcessExecutionTaskTest.java +++ b/src/test/java/com/gooddata/dataload/processes/ProcessExecutionTaskTest.java @@ -5,19 +5,18 @@ */ package com.gooddata.dataload.processes; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.MatcherAssert.*; - -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + public class ProcessExecutionTaskTest { @SuppressWarnings("deprecation") @Test public void testDeserialize() throws Exception { - final ProcessExecutionTask task = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/dataload/processes/executionTask.json"), ProcessExecutionTask.class); + final ProcessExecutionTask task = readObjectFromResource("/dataload/processes/executionTask.json", ProcessExecutionTask.class); assertThat(task.getPollLink(), is("/gdc/projects/PROJECT_ID/dataload/processes/processId/executions/executionId")); assertThat(task.getPollUri(), is("/gdc/projects/PROJECT_ID/dataload/processes/processId/executions/executionId")); assertThat(task.getDetailLink(), is("/gdc/projects/PROJECT_ID/dataload/processes/processId/executions/executionId/detail")); diff --git a/src/test/java/com/gooddata/dataload/processes/ProcessExecutionTest.java b/src/test/java/com/gooddata/dataload/processes/ProcessExecutionTest.java index c26bc28fd..091df03a5 100644 --- a/src/test/java/com/gooddata/dataload/processes/ProcessExecutionTest.java +++ b/src/test/java/com/gooddata/dataload/processes/ProcessExecutionTest.java @@ -5,16 +5,16 @@ */ package com.gooddata.dataload.processes; -import static com.gooddata.JsonMatchers.serializesToJson; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.text.MatchesPattern.matchesPattern; - -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; import java.util.HashMap; import java.util.Map; +import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.text.MatchesPattern.matchesPattern; + public class ProcessExecutionTest { @Test @@ -26,7 +26,7 @@ public void testSerialization() throws Exception { hidden.put("HIDDEN_PARAM1", "SENSITIVE_VALUE1"); hidden.put("HIDDEN_PARAM2", "SENSITIVE_VALUE2"); - final DataloadProcess process = new ObjectMapper().readValue(getClass().getResourceAsStream("/dataload/processes/process.json"), DataloadProcess.class); + final DataloadProcess process = readObjectFromResource("/dataload/processes/process.json", DataloadProcess.class); final ProcessExecution execution = new ProcessExecution(process, "test.groovy", params, hidden); assertThat(execution, serializesToJson("/dataload/processes/execution.json")); @@ -34,7 +34,7 @@ public void testSerialization() throws Exception { @Test public void testToStringFormat() throws Exception { - final DataloadProcess process = new ObjectMapper().readValue(getClass().getResourceAsStream("/dataload/processes/process.json"), DataloadProcess.class); + final DataloadProcess process = readObjectFromResource("/dataload/processes/process.json", DataloadProcess.class); final ProcessExecution execution = new ProcessExecution(process, "test.groovy"); assertThat(execution.toString(), matchesPattern(ProcessExecution.class.getSimpleName() + "\\[.*\\]")); diff --git a/src/test/java/com/gooddata/dataload/processes/ProcessServiceIT.java b/src/test/java/com/gooddata/dataload/processes/ProcessServiceIT.java index 68b09fc4b..97be55ff6 100644 --- a/src/test/java/com/gooddata/dataload/processes/ProcessServiceIT.java +++ b/src/test/java/com/gooddata/dataload/processes/ProcessServiceIT.java @@ -9,7 +9,6 @@ import com.gooddata.FutureResult; import com.gooddata.collections.PageableList; import com.gooddata.project.Project; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -18,6 +17,7 @@ import java.util.Collection; import static com.gooddata.util.ResourceUtils.readFromResource; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static net.jadler.Jadler.onRequest; import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,7 +30,6 @@ public class ProcessServiceIT extends AbstractGoodDataIT { - private static final ObjectMapper MAPPER = new ObjectMapper(); private static final String PROCESSES_PATH = DataloadProcesses.TEMPLATE.expand("PROJECT_ID").toString(); private static final String PROCESS_ID = "processId"; private static final String PROCESS_PATH = DataloadProcess.TEMPLATE.expand("PROJECT_ID", PROCESS_ID).toString(); @@ -56,9 +55,9 @@ public class ProcessServiceIT extends AbstractGoodDataIT { @BeforeClass public void setUp() throws Exception { - project = MAPPER.readValue(readFromResource("/project/project.json"), Project.class); - process = MAPPER.readValue(readFromResource("/dataload/processes/process.json"), DataloadProcess.class); - schedule = MAPPER.readValue(readFromResource("/dataload/processes/schedule.json"), Schedule.class); + project = readObjectFromResource("/project/project.json", Project.class); + process = readObjectFromResource("/dataload/processes/process.json", DataloadProcess.class); + schedule = readObjectFromResource("/dataload/processes/schedule.json", Schedule.class); file = File.createTempFile("test", ".groovy"); } @@ -169,7 +168,7 @@ public void shouldGetExecutionLog() throws Exception { .withStatus(200); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - final ProcessExecutionDetail executionDetail = MAPPER.readValue(readFromResource("/dataload/processes/executionDetail.json"), ProcessExecutionDetail.class); + final ProcessExecutionDetail executionDetail = readObjectFromResource("/dataload/processes/executionDetail.json", ProcessExecutionDetail.class); gd.getProcessService().getExecutionLog(executionDetail, outputStream); assertThat(outputStream.toString(), is(log)); } @@ -200,7 +199,7 @@ public void shouldExecuteProcess() throws Exception { final FutureResult result = gd.getProcessService().executeProcess(new ProcessExecution(process, "test.groovy")); final ProcessExecutionDetail executionDetail = result.get(); - assertJsonEquals(MAPPER.readValue(readFromResource("/dataload/processes/executionDetail-success.json"), ProcessExecutionDetail.class), executionDetail); + assertJsonEquals(readObjectFromResource("/dataload/processes/executionDetail-success.json", ProcessExecutionDetail.class), executionDetail); } @Test(expectedExceptions = ProcessExecutionException.class) diff --git a/src/test/java/com/gooddata/dataload/processes/ScheduleExecutionTest.java b/src/test/java/com/gooddata/dataload/processes/ScheduleExecutionTest.java index 0f935a7c9..7b449cddb 100644 --- a/src/test/java/com/gooddata/dataload/processes/ScheduleExecutionTest.java +++ b/src/test/java/com/gooddata/dataload/processes/ScheduleExecutionTest.java @@ -6,20 +6,19 @@ package com.gooddata.dataload.processes; -import static com.gooddata.JsonMatchers.serializesToJson; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.core.Is.is; - -import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.testng.annotations.Test; -import java.io.InputStream; import java.util.HashMap; +import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.core.Is.is; + public class ScheduleExecutionTest { @Test @@ -31,8 +30,7 @@ public void testEmptyScheduleExecutionSerialization() throws Exception { @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/dataload/processes/scheduleExecution.json"); - final ScheduleExecution scheduleExecution = new ObjectMapper().readValue(stream, ScheduleExecution.class); + final ScheduleExecution scheduleExecution = readObjectFromResource("/dataload/processes/scheduleExecution.json", ScheduleExecution.class); assertThat(scheduleExecution, notNullValue()); assertThat(scheduleExecution.getLinks(), is(equalTo(new HashMap() {{ diff --git a/src/test/java/com/gooddata/dataload/processes/ScheduleTest.java b/src/test/java/com/gooddata/dataload/processes/ScheduleTest.java index 00e885592..46825a957 100644 --- a/src/test/java/com/gooddata/dataload/processes/ScheduleTest.java +++ b/src/test/java/com/gooddata/dataload/processes/ScheduleTest.java @@ -5,7 +5,6 @@ */ package com.gooddata.dataload.processes; -import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.Duration; @@ -19,6 +18,7 @@ import java.util.Collections; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; @@ -53,8 +53,7 @@ public void setUp() throws Exception { @Test public void testDeserialization() throws Exception { - final Schedule schedule = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/dataload/processes/schedule.json"), Schedule.class); + final Schedule schedule = readObjectFromResource("/dataload/processes/schedule.json", Schedule.class); assertThat(schedule, is(notNullValue())); assertThat(schedule.getId(), is("SCHEDULE_ID")); @@ -74,8 +73,7 @@ public void testDeserialization() throws Exception { @Test public void testTriggeredScheduleDeserialization() throws Exception { - final Schedule schedule = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/dataload/processes/schedule-triggered.json"), Schedule.class); + final Schedule schedule = readObjectFromResource("/dataload/processes/schedule-triggered.json", Schedule.class); assertThat(schedule, is(notNullValue())); assertThat(schedule.getId(), is("SCHEDULE_ID")); diff --git a/src/test/java/com/gooddata/dataload/processes/SchedulesTest.java b/src/test/java/com/gooddata/dataload/processes/SchedulesTest.java index 376973542..cc11af24a 100644 --- a/src/test/java/com/gooddata/dataload/processes/SchedulesTest.java +++ b/src/test/java/com/gooddata/dataload/processes/SchedulesTest.java @@ -5,11 +5,9 @@ */ package com.gooddata.dataload.processes; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; @@ -20,8 +18,7 @@ public class SchedulesTest { @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/dataload/processes/schedules.json"); - final Schedules schedules = new ObjectMapper().readValue(stream, Schedules.class); + final Schedules schedules = readObjectFromResource("/dataload/processes/schedules.json", Schedules.class); assertThat(schedules, notNullValue()); assertThat(schedules, hasSize(1)); @@ -32,8 +29,7 @@ public void testDeserialization() throws Exception { @Test public void testDeserializationPaging() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/dataload/processes/schedules_page1.json"); - final Schedules schedules = new ObjectMapper().readValue(stream, Schedules.class); + final Schedules schedules = readObjectFromResource("/dataload/processes/schedules_page1.json", Schedules.class); assertThat(schedules, notNullValue()); assertThat(schedules, hasSize(1)); diff --git a/src/test/java/com/gooddata/dataset/DatasetLinksTest.java b/src/test/java/com/gooddata/dataset/DatasetLinksTest.java index a7124ee1b..67d543796 100644 --- a/src/test/java/com/gooddata/dataset/DatasetLinksTest.java +++ b/src/test/java/com/gooddata/dataset/DatasetLinksTest.java @@ -5,13 +5,12 @@ */ package com.gooddata.dataset; -import com.fasterxml.jackson.databind.ObjectMapper; import com.gooddata.gdc.AboutLinks; import org.testng.annotations.Test; -import java.io.InputStream; import java.util.Collection; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -21,8 +20,7 @@ public class DatasetLinksTest { @Test public void deserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/dataset/datasetLinks.json"); - final DatasetLinks datasetLinks = new ObjectMapper().readValue(stream, DatasetLinks.class); + final DatasetLinks datasetLinks = readObjectFromResource("/dataset/datasetLinks.json", DatasetLinks.class); assertThat(datasetLinks, is(notNullValue())); assertThat(datasetLinks.getCategory(), is("singleloadinterface")); assertThat(datasetLinks.getInstance(), is("MD::LDM::SingleLoadInterface")); diff --git a/src/test/java/com/gooddata/dataset/DatasetManifestTest.java b/src/test/java/com/gooddata/dataset/DatasetManifestTest.java index c95012832..05e93240b 100644 --- a/src/test/java/com/gooddata/dataset/DatasetManifestTest.java +++ b/src/test/java/com/gooddata/dataset/DatasetManifestTest.java @@ -5,26 +5,23 @@ */ package com.gooddata.dataset; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.text.MatchesPattern.matchesPattern; public class DatasetManifestTest { @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/dataset/datasetManifest.json"); - final DatasetManifest manifest = new ObjectMapper().readValue(stream, DatasetManifest.class); + final DatasetManifest manifest = readObjectFromResource("/dataset/datasetManifest.json", DatasetManifest.class); assertThat(manifest.getDataSet(), is("dataset.person")); assertThat(manifest.getFile(), is("dataset.person.csv")); diff --git a/src/test/java/com/gooddata/dataset/DatasetServiceIT.java b/src/test/java/com/gooddata/dataset/DatasetServiceIT.java index cf5f5edb5..471cb9434 100644 --- a/src/test/java/com/gooddata/dataset/DatasetServiceIT.java +++ b/src/test/java/com/gooddata/dataset/DatasetServiceIT.java @@ -19,7 +19,9 @@ import java.io.InputStream; import java.util.Collection; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static com.gooddata.util.ResourceUtils.readFromResource; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static net.jadler.Jadler.onRequest; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; @@ -35,7 +37,7 @@ public class DatasetServiceIT extends AbstractGoodDataIT { @BeforeClass public void setUpClass() throws Exception { - project = MAPPER.readValue(readFromResource("/project/project.json"), Project.class); + project = readObjectFromResource("/project/project.json", Project.class); } @BeforeMethod @@ -74,7 +76,7 @@ public void shouldLoadDataset() throws Exception { .withStatus(200) .withBody(readFromResource("/dataset/pullTaskStatusOk.json")); - final DatasetManifest manifest = MAPPER.readValue(readFromResource("/dataset/datasetManifest.json"), DatasetManifest.class); + final DatasetManifest manifest = readObjectFromResource("/dataset/datasetManifest.json", DatasetManifest.class); gd.getDatasetService().loadDataset(project, manifest, new ByteArrayInputStream(new byte[]{})).get(); } @@ -89,7 +91,7 @@ public void shouldLoadDatasets() throws Exception { .withStatus(200) .withBody(readFromResource("/dataset/pullTaskStatusOk.json")); - final DatasetManifest manifest = MAPPER.readValue(readFromResource("/dataset/datasetManifest.json"), DatasetManifest.class); + final DatasetManifest manifest = readObjectFromResource("/dataset/datasetManifest.json", DatasetManifest.class); final InputStream source = new ByteArrayInputStream(new byte[]{}); manifest.setSource(source); @@ -104,7 +106,7 @@ public void shouldFailPolling() throws Exception { .respond() .withStatus(400); - final DatasetManifest manifest = MAPPER.readValue(readFromResource("/dataset/datasetManifest.json"), DatasetManifest.class); + final DatasetManifest manifest = readObjectFromResource("/dataset/datasetManifest.json", DatasetManifest.class); gd.getDatasetService().loadDataset(project, manifest, new ByteArrayInputStream(new byte[]{})).get(); } @@ -115,7 +117,7 @@ public void shouldFailLoading() throws Exception { .respond() .withStatus(200) .withBody(readFromResource("/dataset/pullTaskStatusError.json")); - final DatasetManifest manifest = MAPPER.readValue(readFromResource("/dataset/datasetManifest.json"), DatasetManifest.class); + final DatasetManifest manifest = readObjectFromResource("/dataset/datasetManifest.json", DatasetManifest.class); try { gd.getDatasetService().loadDataset(project, manifest, new ByteArrayInputStream(new byte[]{})).get(); fail("Exception should be thrown"); @@ -181,10 +183,10 @@ public void shouldOptimizeSliHash() throws Exception { .havingPathEqualTo(STATUS_URI) .respond() .withStatus(202) - .withBody(MAPPER.writeValueAsString(new TaskStatus("RUNNING", STATUS_URI))) + .withBody(OBJECT_MAPPER.writeValueAsString(new TaskStatus("RUNNING", STATUS_URI))) .thenRespond() .withStatus(200) - .withBody(MAPPER.writeValueAsString(new TaskStatus("OK", STATUS_URI))); + .withBody(OBJECT_MAPPER.writeValueAsString(new TaskStatus("OK", STATUS_URI))); gd.getDatasetService().optimizeSliHash(project).get(); } @@ -202,10 +204,10 @@ public void shouldFailOptimizeSliHash() throws Exception { .havingPathEqualTo(STATUS_URI) .respond() .withStatus(202) - .withBody(MAPPER.writeValueAsString(new TaskStatus("RUNNING", STATUS_URI))) + .withBody(OBJECT_MAPPER.writeValueAsString(new TaskStatus("RUNNING", STATUS_URI))) .thenRespond() .withStatus(200) - .withBody(MAPPER.writeValueAsString(new TaskStatus("ERROR", STATUS_URI))); + .withBody(OBJECT_MAPPER.writeValueAsString(new TaskStatus("ERROR", STATUS_URI))); gd.getDatasetService().optimizeSliHash(project).get(); } @@ -223,10 +225,10 @@ public void shouldUpdateProjectData() throws IOException { .havingPathEqualTo(STATUS_URI) .respond() .withStatus(200) // REST API returns HTTP 200 when task is in RUNNING state :( - .withBody(MAPPER.writeValueAsString(new TaskState("RUNNING", STATUS_URI))) + .withBody(OBJECT_MAPPER.writeValueAsString(new TaskState("RUNNING", STATUS_URI))) .thenRespond() .withStatus(200) - .withBody(MAPPER.writeValueAsString(new TaskState("OK", STATUS_URI))) + .withBody(OBJECT_MAPPER.writeValueAsString(new TaskState("OK", STATUS_URI))) ; gd.getDatasetService().updateProjectData(project, DML_MAQL).get(); @@ -263,10 +265,10 @@ public void shouldFailUpdateProjectData() throws IOException { .havingPathEqualTo(STATUS_URI) .respond() .withStatus(202) - .withBody(MAPPER.writeValueAsString(new TaskState("RUNNING", STATUS_URI))) + .withBody(OBJECT_MAPPER.writeValueAsString(new TaskState("RUNNING", STATUS_URI))) .thenRespond() .withStatus(200) - .withBody(MAPPER.writeValueAsString(new TaskState("ERROR", STATUS_URI))) + .withBody(OBJECT_MAPPER.writeValueAsString(new TaskState("ERROR", STATUS_URI))) ; gd.getDatasetService().updateProjectData(project, DML_MAQL).get(); diff --git a/src/test/java/com/gooddata/dataset/DatasetTest.java b/src/test/java/com/gooddata/dataset/DatasetTest.java index 53e132a2e..e5279cdff 100644 --- a/src/test/java/com/gooddata/dataset/DatasetTest.java +++ b/src/test/java/com/gooddata/dataset/DatasetTest.java @@ -5,11 +5,9 @@ */ package com.gooddata.dataset; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -19,8 +17,7 @@ public class DatasetTest { @SuppressWarnings("deprecation") @Test public void deserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/dataset/dataset.json"); - final Dataset dataset = new ObjectMapper().readValue(stream, Dataset.class); + final Dataset dataset = readObjectFromResource("/dataset/dataset.json", Dataset.class); assertThat(dataset, is(notNullValue())); assertThat(dataset.getIdentifier(), is("dataset.person")); diff --git a/src/test/java/com/gooddata/dataset/DatasetsTest.java b/src/test/java/com/gooddata/dataset/DatasetsTest.java index 1e5a916f4..1e88dc817 100644 --- a/src/test/java/com/gooddata/dataset/DatasetsTest.java +++ b/src/test/java/com/gooddata/dataset/DatasetsTest.java @@ -5,13 +5,12 @@ */ package com.gooddata.dataset; -import com.fasterxml.jackson.databind.ObjectMapper; import com.gooddata.gdc.AboutLinks.Link; import org.testng.annotations.Test; -import java.io.InputStream; import java.util.Collection; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -22,8 +21,7 @@ public class DatasetsTest { @SuppressWarnings("deprecation") @Test public void deserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/dataset/datasetLinks.json"); - final Datasets datasets = new ObjectMapper().readValue(stream, Datasets.class); + final Datasets datasets = readObjectFromResource("/dataset/datasetLinks.json", Datasets.class); assertThat(datasets, is(notNullValue())); assertThat(datasets.getCategory(), is("singleloadinterface")); assertThat(datasets.getInstance(), is("MD::LDM::SingleLoadInterface")); diff --git a/src/test/java/com/gooddata/dataset/MaqlDmlTest.java b/src/test/java/com/gooddata/dataset/MaqlDmlTest.java index b9a2c1f10..52eb18b07 100644 --- a/src/test/java/com/gooddata/dataset/MaqlDmlTest.java +++ b/src/test/java/com/gooddata/dataset/MaqlDmlTest.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -17,7 +18,7 @@ public class MaqlDmlTest { @Test public void testSerialization() throws Exception { final String json = IOUtils.toString(getClass().getResourceAsStream("/dataset/maqlDml.json"), "UTF-8"); - assertThat(new ObjectMapper().writeValueAsString(new MaqlDml("maqlddl")), + assertThat(OBJECT_MAPPER.writeValueAsString(new MaqlDml("maqlddl")), is(json)); } } diff --git a/src/test/java/com/gooddata/dataset/PullTaskTest.java b/src/test/java/com/gooddata/dataset/PullTaskTest.java index 7412daf9a..b952f1cc3 100644 --- a/src/test/java/com/gooddata/dataset/PullTaskTest.java +++ b/src/test/java/com/gooddata/dataset/PullTaskTest.java @@ -5,11 +5,9 @@ */ package com.gooddata.dataset; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -17,8 +15,7 @@ public class PullTaskTest { @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/dataset/pullTask.json"); - final PullTask task = new ObjectMapper().readValue(stream, PullTask.class); + final PullTask task = readObjectFromResource("/dataset/pullTask.json", PullTask.class); assertThat(task.getPollUri(), is("/gdc/md/PROJECT/tasks/task/ID/status")); } diff --git a/src/test/java/com/gooddata/dataset/TaskStateTest.java b/src/test/java/com/gooddata/dataset/TaskStateTest.java index 1927c9344..ada3b06ea 100644 --- a/src/test/java/com/gooddata/dataset/TaskStateTest.java +++ b/src/test/java/com/gooddata/dataset/TaskStateTest.java @@ -5,12 +5,11 @@ */ package com.gooddata.dataset; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; import java.io.IOException; -import java.io.InputStream; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.text.MatchesPattern.matchesPattern; @@ -19,16 +18,14 @@ public class TaskStateTest { @Test public void testDeserialize() throws IOException { - final InputStream stream = getClass().getResourceAsStream("/dataset/taskStateOK.json"); - TaskState taskState = new ObjectMapper().readValue(stream, TaskState.class); + TaskState taskState = readObjectFromResource("/dataset/taskStateOK.json", TaskState.class); assertThat(taskState.getStatus(), is("OK")); assertThat(taskState.getMessage(), is("ok message")); } @Test public void testToStringFormat() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/dataset/taskStateOK.json"); - TaskState taskState = new ObjectMapper().readValue(stream, TaskState.class); + TaskState taskState = readObjectFromResource("/dataset/taskStateOK.json", TaskState.class); assertThat(taskState.toString(), matchesPattern(TaskState.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/dataset/UploadStatisticsTest.java b/src/test/java/com/gooddata/dataset/UploadStatisticsTest.java index f3a2fedfa..9249af785 100644 --- a/src/test/java/com/gooddata/dataset/UploadStatisticsTest.java +++ b/src/test/java/com/gooddata/dataset/UploadStatisticsTest.java @@ -5,6 +5,7 @@ */ package com.gooddata.dataset; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @@ -19,8 +20,7 @@ public class UploadStatisticsTest { @Test public void shouldDeserialize() throws Exception { - final InputStream input = getClass().getResourceAsStream("/dataset/uploads/data-uploads-info.json"); - final UploadStatistics uploadStatistics = new ObjectMapper().readValue(input, UploadStatistics.class); + final UploadStatistics uploadStatistics = readObjectFromResource("/dataset/uploads/data-uploads-info.json", UploadStatistics.class); assertThat(uploadStatistics, notNullValue()); @@ -32,8 +32,7 @@ public void shouldDeserialize() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream input = getClass().getResourceAsStream("/dataset/uploads/data-uploads-info.json"); - final UploadStatistics uploadStatistics = new ObjectMapper().readValue(input, UploadStatistics.class); + final UploadStatistics uploadStatistics = readObjectFromResource("/dataset/uploads/data-uploads-info.json", UploadStatistics.class); assertThat(uploadStatistics.toString(), matchesPattern(UploadStatistics.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/dataset/UploadTest.java b/src/test/java/com/gooddata/dataset/UploadTest.java index 1273b803a..4c2aa7b0a 100644 --- a/src/test/java/com/gooddata/dataset/UploadTest.java +++ b/src/test/java/com/gooddata/dataset/UploadTest.java @@ -5,25 +5,22 @@ */ package com.gooddata.dataset; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.testng.annotations.Test; + +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.closeTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.text.MatchesPattern.matchesPattern; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.testng.annotations.Test; - -import java.io.InputStream; - public class UploadTest { @Test public void shouldDeserialize() throws Exception { - final InputStream input = getClass().getResourceAsStream("/dataset/uploads/upload.json"); - final Upload upload = new ObjectMapper().readValue(input, Upload.class); + final Upload upload = readObjectFromResource("/dataset/uploads/upload.json", Upload.class); assertThat(upload, notNullValue()); assertThat(upload.getMessage(), is("some upload message")); @@ -38,8 +35,7 @@ public void shouldDeserialize() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream input = getClass().getResourceAsStream("/dataset/uploads/upload.json"); - final Upload upload = new ObjectMapper().readValue(input, Upload.class); + final Upload upload = readObjectFromResource("/dataset/uploads/upload.json", Upload.class); assertThat(upload.toString(), matchesPattern(Upload.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/dataset/UploadsInfoTest.java b/src/test/java/com/gooddata/dataset/UploadsInfoTest.java index ca7c2fead..a84c9d0e8 100644 --- a/src/test/java/com/gooddata/dataset/UploadsInfoTest.java +++ b/src/test/java/com/gooddata/dataset/UploadsInfoTest.java @@ -5,23 +5,21 @@ */ package com.gooddata.dataset; +import org.testng.annotations.Test; + +import java.util.Collections; + +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.text.MatchesPattern.matchesPattern; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.testng.annotations.Test; - -import java.io.InputStream; -import java.util.Collections; - public class UploadsInfoTest { @Test public void shouldDeserialize() throws Exception { - final InputStream input = getClass().getResourceAsStream("/dataset/uploads/data-sets.json"); - final UploadsInfo uploadsInfo = new ObjectMapper().readValue(input, UploadsInfo.class); + final UploadsInfo uploadsInfo = readObjectFromResource("/dataset/uploads/data-sets.json", UploadsInfo.class); assertThat(uploadsInfo, notNullValue()); @@ -40,8 +38,7 @@ public void getDatasetUploadInfoFails() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream input = getClass().getResourceAsStream("/dataset/uploads/data-sets.json"); - final UploadsInfo uploadsInfo = new ObjectMapper().readValue(input, UploadsInfo.class); + final UploadsInfo uploadsInfo = readObjectFromResource("/dataset/uploads/data-sets.json", UploadsInfo.class); assertThat(uploadsInfo.toString(), matchesPattern(UploadsInfo.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/dataset/UploadsTest.java b/src/test/java/com/gooddata/dataset/UploadsTest.java index 0b1044b8f..e2ad69db5 100644 --- a/src/test/java/com/gooddata/dataset/UploadsTest.java +++ b/src/test/java/com/gooddata/dataset/UploadsTest.java @@ -5,24 +5,21 @@ */ package com.gooddata.dataset; +import org.hamcrest.Matchers; +import org.testng.annotations.Test; + +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.text.MatchesPattern.matchesPattern; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.hamcrest.Matchers; -import org.testng.annotations.Test; - -import java.io.InputStream; - public class UploadsTest { @Test public void shouldDeserialize() throws Exception { - final InputStream input = getClass().getResourceAsStream("/dataset/uploads/uploads.json"); - final Uploads uploads = new ObjectMapper().readValue(input, Uploads.class); + final Uploads uploads = readObjectFromResource("/dataset/uploads/uploads.json", Uploads.class); assertThat(uploads, notNullValue()); assertThat(uploads.items(), not(Matchers.empty())); @@ -31,8 +28,7 @@ public void shouldDeserialize() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream input = getClass().getResourceAsStream("/dataset/uploads/uploads.json"); - final Uploads uploads = new ObjectMapper().readValue(input, Uploads.class); + final Uploads uploads = readObjectFromResource("/dataset/uploads/uploads.json", Uploads.class); assertThat(uploads.toString(), matchesPattern(Uploads.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/featureflag/FeatureFlagServiceIT.java b/src/test/java/com/gooddata/featureflag/FeatureFlagServiceIT.java index 4574f943b..a1486f7cf 100644 --- a/src/test/java/com/gooddata/featureflag/FeatureFlagServiceIT.java +++ b/src/test/java/com/gooddata/featureflag/FeatureFlagServiceIT.java @@ -12,7 +12,7 @@ import static com.gooddata.featureflag.ProjectFeatureFlag.PROJECT_FEATURE_FLAG_TEMPLATE; import static com.gooddata.featureflag.ProjectFeatureFlags.PROJECT_FEATURE_FLAGS_TEMPLATE; -import static com.gooddata.util.ResourceUtils.readFromResource; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static com.gooddata.util.ResourceUtils.readStringFromResource; import static net.jadler.Jadler.onRequest; import static org.hamcrest.MatcherAssert.assertThat; @@ -35,7 +35,7 @@ public class FeatureFlagServiceIT extends AbstractGoodDataIT { @BeforeMethod public void setUp() throws Exception { service = gd.getFeatureFlagService(); - project = MAPPER.readValue(readFromResource("/project/project.json"), Project.class); + project = readObjectFromResource("/project/project.json", Project.class); } @Test @@ -126,8 +126,7 @@ public void updateProjectFeatureFlagShouldUpdateAndReturnUpdatedProjectFeatureFl .withBody(readStringFromResource("/featureflag/projectFeatureFlag.json")) .withStatus(200); - final ProjectFeatureFlag flag = MAPPER - .readValue(readFromResource("/featureflag/projectFeatureFlag.json"), ProjectFeatureFlag.class); + final ProjectFeatureFlag flag = readObjectFromResource("/featureflag/projectFeatureFlag.json", ProjectFeatureFlag.class); final ProjectFeatureFlag featureFlag = service.updateProjectFeatureFlag(flag); assertThat(featureFlag, is(notNullValue())); @@ -143,8 +142,7 @@ public void deleteProjectFeatureFlagShouldRemoveIt() throws Exception { .respond() .withStatus(200); - final ProjectFeatureFlag flag = MAPPER - .readValue(readFromResource("/featureflag/projectFeatureFlag.json"), ProjectFeatureFlag.class); + final ProjectFeatureFlag flag = readObjectFromResource("/featureflag/projectFeatureFlag.json", ProjectFeatureFlag.class); service.deleteProjectFeatureFlag(flag); } diff --git a/src/test/java/com/gooddata/gdc/AboutLinksTest.java b/src/test/java/com/gooddata/gdc/AboutLinksTest.java index efe9a0955..fa28f0415 100644 --- a/src/test/java/com/gooddata/gdc/AboutLinksTest.java +++ b/src/test/java/com/gooddata/gdc/AboutLinksTest.java @@ -5,12 +5,11 @@ */ package com.gooddata.gdc; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; import java.util.Collection; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -20,8 +19,7 @@ public class AboutLinksTest { @Test public void deserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/dataset/datasetLinks.json"); - final AboutLinks aboutLinks = new ObjectMapper().readValue(stream, AboutLinks.class); + final AboutLinks aboutLinks = readObjectFromResource("/dataset/datasetLinks.json", AboutLinks.class); assertThat(aboutLinks, is(notNullValue())); assertThat(aboutLinks.getCategory(), is("singleloadinterface")); assertThat(aboutLinks.getInstance(), is("MD::LDM::SingleLoadInterface")); diff --git a/src/test/java/com/gooddata/gdc/AsyncTaskTest.java b/src/test/java/com/gooddata/gdc/AsyncTaskTest.java index 2e6275357..ae6fcd46f 100644 --- a/src/test/java/com/gooddata/gdc/AsyncTaskTest.java +++ b/src/test/java/com/gooddata/gdc/AsyncTaskTest.java @@ -5,30 +5,26 @@ */ package com.gooddata.gdc; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class AsyncTaskTest { - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Test public void testDeserialization() throws Exception { - final InputStream is = getClass().getResourceAsStream("/gdc/asyncTask.json"); - final AsyncTask asyncTask = MAPPER.readValue(is, AsyncTask.class); + final AsyncTask asyncTask = readObjectFromResource("/gdc/asyncTask.json", AsyncTask.class); assertThat(asyncTask.getUri(), is("POLL-URI")); } @Test public void testSerialization() throws Exception { - final String json = MAPPER.writeValueAsString(new AsyncTask("foo")); - final AsyncTask asyncTask = MAPPER.readValue(json, AsyncTask.class); + final String json = OBJECT_MAPPER.writeValueAsString(new AsyncTask("foo")); + final AsyncTask asyncTask = OBJECT_MAPPER.readValue(json, AsyncTask.class); assertThat(asyncTask.getUri(), is("foo")); } diff --git a/src/test/java/com/gooddata/gdc/ErrorStructureTest.java b/src/test/java/com/gooddata/gdc/ErrorStructureTest.java index 857b6c607..825ac8df0 100644 --- a/src/test/java/com/gooddata/gdc/ErrorStructureTest.java +++ b/src/test/java/com/gooddata/gdc/ErrorStructureTest.java @@ -5,11 +5,9 @@ */ package com.gooddata.gdc; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -18,8 +16,7 @@ public class ErrorStructureTest { @Test public void testDeserialization() throws Exception { - final InputStream inputStream = getClass().getResourceAsStream("/gdc/errorStructure.json"); - final ErrorStructure errStructure = new ObjectMapper().readValue(inputStream, ErrorStructure.class); + final ErrorStructure errStructure = readObjectFromResource("/gdc/errorStructure.json", ErrorStructure.class); assertThat(errStructure, is(notNullValue())); assertThat(errStructure.getErrorClass(), is("CLASS")); diff --git a/src/test/java/com/gooddata/gdc/GdcErrorTest.java b/src/test/java/com/gooddata/gdc/GdcErrorTest.java index fed25c0e4..4da0420ca 100644 --- a/src/test/java/com/gooddata/gdc/GdcErrorTest.java +++ b/src/test/java/com/gooddata/gdc/GdcErrorTest.java @@ -5,11 +5,9 @@ */ package com.gooddata.gdc; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -18,8 +16,7 @@ public class GdcErrorTest { @Test public void testDeserialization() throws Exception { - final InputStream inputStream = getClass().getResourceAsStream("/gdc/gdcError.json"); - final GdcError err = new ObjectMapper().readValue(inputStream, GdcError.class); + final GdcError err = readObjectFromResource("/gdc/gdcError.json", GdcError.class); assertThat(err, is(notNullValue())); assertThat(err.getErrorClass(), is("CLASS")); diff --git a/src/test/java/com/gooddata/gdc/GdcTest.java b/src/test/java/com/gooddata/gdc/GdcTest.java index 27283571e..70cc59f35 100644 --- a/src/test/java/com/gooddata/gdc/GdcTest.java +++ b/src/test/java/com/gooddata/gdc/GdcTest.java @@ -5,11 +5,9 @@ */ package com.gooddata.gdc; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -19,8 +17,7 @@ public class GdcTest { @SuppressWarnings("deprecation") @Test public void deserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/gdc/gdc.json"); - final Gdc gdc = new ObjectMapper().readValue(stream, Gdc.class); + final Gdc gdc = readObjectFromResource("/gdc/gdc.json", Gdc.class); assertThat(gdc, is(notNullValue())); assertThat(gdc.getHomeLink(), is("/gdc/")); diff --git a/src/test/java/com/gooddata/gdc/LinkEntriesTest.java b/src/test/java/com/gooddata/gdc/LinkEntriesTest.java index b7724377c..8218e8b7b 100644 --- a/src/test/java/com/gooddata/gdc/LinkEntriesTest.java +++ b/src/test/java/com/gooddata/gdc/LinkEntriesTest.java @@ -5,15 +5,13 @@ */ package com.gooddata.gdc; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.text.MatchesPattern.matchesPattern; public class LinkEntriesTest { @@ -21,8 +19,7 @@ public class LinkEntriesTest { @SuppressWarnings("deprecation") @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/gdc/linkEntries.json"); - final LinkEntries linkEntries = new ObjectMapper().readValue(stream, LinkEntries.class); + final LinkEntries linkEntries = readObjectFromResource("/gdc/linkEntries.json", LinkEntries.class); assertThat(linkEntries, is(notNullValue())); assertThat(linkEntries.getEntries(), hasSize(1)); @@ -34,8 +31,7 @@ public void testDeserialization() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/gdc/linkEntries.json"); - final LinkEntries linkEntries = new ObjectMapper().readValue(stream, LinkEntries.class); + final LinkEntries linkEntries = readObjectFromResource("/gdc/linkEntries.json", LinkEntries.class); assertThat(linkEntries.toString(), matchesPattern(LinkEntries.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/gdc/RootLinksTest.java b/src/test/java/com/gooddata/gdc/RootLinksTest.java index 0e26fb683..2f145dd4f 100644 --- a/src/test/java/com/gooddata/gdc/RootLinksTest.java +++ b/src/test/java/com/gooddata/gdc/RootLinksTest.java @@ -5,11 +5,9 @@ */ package com.gooddata.gdc; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -19,8 +17,7 @@ public class RootLinksTest { @SuppressWarnings("deprecation") @Test public void deserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/gdc/gdc.json"); - final RootLinks rootLinks = new ObjectMapper().readValue(stream, RootLinks.class); + final RootLinks rootLinks = readObjectFromResource("/gdc/gdc.json", RootLinks.class); assertThat(rootLinks, is(notNullValue())); assertThat(rootLinks.getHomeLink(), is("/gdc/")); diff --git a/src/test/java/com/gooddata/gdc/TaskStatusTest.java b/src/test/java/com/gooddata/gdc/TaskStatusTest.java index e2d1da35e..9c093a771 100644 --- a/src/test/java/com/gooddata/gdc/TaskStatusTest.java +++ b/src/test/java/com/gooddata/gdc/TaskStatusTest.java @@ -5,26 +5,25 @@ */ package com.gooddata.gdc; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.Matchers.*; import static org.hamcrest.MatcherAssert.*; public class TaskStatusTest { - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Test public void testDeser() throws Exception { - final TaskStatus status = MAPPER.readValue(getClass().getResourceAsStream("/gdc/task-status.json"), TaskStatus.class); + final TaskStatus status = readObjectFromResource("/gdc/task-status.json", TaskStatus.class); assertThat(status.getStatus(), is("OK")); assertThat(status.getPollUri(), is("/gdc/md/PROJECT_ID/tasks/TASK_ID/status")); } @Test public void testDeserMessages() throws Exception { - final TaskStatus status = MAPPER.readValue(getClass().getResourceAsStream("/model/maql-ddl-task-status-fail.json"), TaskStatus.class); + final TaskStatus status = readObjectFromResource("/model/maql-ddl-task-status-fail.json", TaskStatus.class); assertThat(status.getStatus(), is("ERROR")); assertThat(status.getPollUri(), is("/gdc/md/PROJECT_ID/tasks/TASK_ID/status")); assertThat(status.getMessages(), hasSize(1)); @@ -34,8 +33,8 @@ public void testDeserMessages() throws Exception { @Test public void testSerialize() throws Exception { - final String json = MAPPER.writeValueAsString(new TaskStatus("OK", "foo")); - final TaskStatus status = MAPPER.readValue(json, TaskStatus.class); + final String json = OBJECT_MAPPER.writeValueAsString(new TaskStatus("OK", "foo")); + final TaskStatus status = OBJECT_MAPPER.readValue(json, TaskStatus.class); assertThat(status.getStatus(), is("OK")); assertThat(status.getPollUri(), is("foo")); } diff --git a/src/test/java/com/gooddata/gdc/UriResponseTest.java b/src/test/java/com/gooddata/gdc/UriResponseTest.java index 4743ead86..1ef618f1a 100644 --- a/src/test/java/com/gooddata/gdc/UriResponseTest.java +++ b/src/test/java/com/gooddata/gdc/UriResponseTest.java @@ -5,12 +5,10 @@ */ package com.gooddata.gdc; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -19,8 +17,7 @@ public class UriResponseTest { @Test public void testDeserialization() throws Exception { - final InputStream inputStream = getClass().getResourceAsStream("/gdc/uriResponse.json"); - final UriResponse uriResponse = new ObjectMapper().readValue(inputStream, UriResponse.class); + final UriResponse uriResponse = readObjectFromResource("/gdc/uriResponse.json", UriResponse.class); assertThat(uriResponse, is(notNullValue())); assertThat(uriResponse.getUri(), is("URI")); diff --git a/src/test/java/com/gooddata/md/AttributeDisplayFormTest.java b/src/test/java/com/gooddata/md/AttributeDisplayFormTest.java index 4324f7b40..72d17f9ba 100644 --- a/src/test/java/com/gooddata/md/AttributeDisplayFormTest.java +++ b/src/test/java/com/gooddata/md/AttributeDisplayFormTest.java @@ -5,12 +5,10 @@ */ package com.gooddata.md; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -29,8 +27,7 @@ public class AttributeDisplayFormTest { @SuppressWarnings("deprecation") @Test public void shouldDeserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/attributeDisplayForm.json"); - final AttributeDisplayForm attrDF = new ObjectMapper().readValue(stream, AttributeDisplayForm.class); + final AttributeDisplayForm attrDF = readObjectFromResource("/md/attributeDisplayForm.json", AttributeDisplayForm.class); assertThat(attrDF, is(notNullValue())); assertThat(attrDF.getFormOf(), is(FORM_OF)); @@ -52,8 +49,7 @@ public void testSerialization() throws Exception { @Test public void shouldSerializeSameAsDeserializationInput() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/attributeDisplayForm.json"); - final AttributeDisplayForm attrDF = new ObjectMapper().readValue(stream, AttributeDisplayForm.class); + final AttributeDisplayForm attrDF = readObjectFromResource("/md/attributeDisplayForm.json", AttributeDisplayForm.class); assertThat(attrDF, serializesToJson("/md/attributeDisplayForm-inputOrig.json")); } diff --git a/src/test/java/com/gooddata/md/AttributeElementTest.java b/src/test/java/com/gooddata/md/AttributeElementTest.java index 4fa6b4b6b..81940e353 100644 --- a/src/test/java/com/gooddata/md/AttributeElementTest.java +++ b/src/test/java/com/gooddata/md/AttributeElementTest.java @@ -5,16 +5,14 @@ */ package com.gooddata.md; +import org.testng.annotations.Test; + +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.text.MatchesPattern.matchesPattern; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.testng.annotations.Test; - -import java.io.InputStream; - public class AttributeElementTest { private static final String URI = "/gdc/md/PROJECT_ID/obj/1333/elements?id=6959"; @@ -22,8 +20,7 @@ public class AttributeElementTest { @Test public void shouldDeserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/attributeElement.json"); - final AttributeElement element = new ObjectMapper().readValue(stream, AttributeElement.class); + final AttributeElement element = readObjectFromResource("/md/attributeElement.json", AttributeElement.class); assertThat(element, is(notNullValue())); assertThat(element.getUri(), is(URI)); @@ -32,8 +29,7 @@ public void shouldDeserialize() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/attributeElement.json"); - final AttributeElement element = new ObjectMapper().readValue(stream, AttributeElement.class); + final AttributeElement element = readObjectFromResource("/md/attributeElement.json", AttributeElement.class); assertThat(element.toString(), matchesPattern(AttributeElement.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/md/AttributeElementsTest.java b/src/test/java/com/gooddata/md/AttributeElementsTest.java index 3da82955d..7fbdea22a 100644 --- a/src/test/java/com/gooddata/md/AttributeElementsTest.java +++ b/src/test/java/com/gooddata/md/AttributeElementsTest.java @@ -5,24 +5,22 @@ */ package com.gooddata.md; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; - -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; import java.util.List; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; + public class AttributeElementsTest { @Test public void shouldDeserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/attributeElements.json"); - final AttributeElements elements = new ObjectMapper().readValue(stream, AttributeElements.class); + final AttributeElements elements = readObjectFromResource("/md/attributeElements.json", AttributeElements.class); assertThat(elements, is(notNullValue())); final List elementsList = elements.getElements(); diff --git a/src/test/java/com/gooddata/md/AttributeSortTest.java b/src/test/java/com/gooddata/md/AttributeSortTest.java index a52c86126..fe6c8c498 100644 --- a/src/test/java/com/gooddata/md/AttributeSortTest.java +++ b/src/test/java/com/gooddata/md/AttributeSortTest.java @@ -5,17 +5,17 @@ */ package com.gooddata.md; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; -import static org.hamcrest.text.MatchesPattern.matchesPattern; - -import com.fasterxml.jackson.databind.ObjectMapper; import com.gooddata.JsonMatchers; import org.testng.annotations.Test; -public class AttributeSortTest { +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.text.MatchesPattern.matchesPattern; - private static final ObjectMapper MAPPER = new ObjectMapper(); +public class AttributeSortTest { @Test public void testSerializePlain() throws Exception { @@ -25,7 +25,7 @@ public void testSerializePlain() throws Exception { @Test public void testDeserializePlain() throws Exception { - final AttributeSort attributeSort = MAPPER.readValue("\"pk\"", AttributeSort.class); + final AttributeSort attributeSort = OBJECT_MAPPER.readValue("\"pk\"", AttributeSort.class); assertThat(attributeSort, is(notNullValue())); assertThat(attributeSort.getValue(), is("pk")); } @@ -38,7 +38,7 @@ public void testSerializeLink() throws Exception { @Test public void testDeserializeLink() throws Exception { - final AttributeSort attributeSort = MAPPER.readValue(getClass().getResourceAsStream("/md/attributeSort.json"), AttributeSort.class); + final AttributeSort attributeSort = readObjectFromResource("/md/attributeSort.json", AttributeSort.class); assertThat(attributeSort, is(notNullValue())); assertThat(attributeSort.getValue(), is("/gdc/md/PROJECT_ID/obj/1806")); } diff --git a/src/test/java/com/gooddata/md/AttributeTest.java b/src/test/java/com/gooddata/md/AttributeTest.java index 9689fed34..db29d3ca1 100644 --- a/src/test/java/com/gooddata/md/AttributeTest.java +++ b/src/test/java/com/gooddata/md/AttributeTest.java @@ -5,18 +5,17 @@ */ package com.gooddata.md; -import com.fasterxml.jackson.databind.ObjectMapper; import org.hamcrest.Matchers; import org.testng.annotations.Test; -import java.io.InputStream; import java.util.Collection; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; public class AttributeTest { @@ -25,8 +24,7 @@ public class AttributeTest { @SuppressWarnings("deprecation") @Test public void shouldDeserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/attribute.json"); - final Attribute attribute = new ObjectMapper().readValue(stream, Attribute.class); + final Attribute attribute = readObjectFromResource("/md/attribute.json", Attribute.class); assertThat(attribute, is(notNullValue())); final Collection displayForms = attribute.getDisplayForms(); @@ -86,15 +84,13 @@ public void testSerialization() throws Exception { @Test public void shouldSerializeSameAsDeserializationInput() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/attribute.json"); - final Attribute attribute = new ObjectMapper().readValue(stream, Attribute.class); + final Attribute attribute = readObjectFromResource("/md/attribute.json", Attribute.class); assertThat(attribute, serializesToJson("/md/attribute-inputOrig.json")); } @Test public void shouldDeserializeAttributeWithSort() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/attribute-sortDf.json"); - final Attribute attribute = new ObjectMapper().readValue(stream, Attribute.class); + final Attribute attribute = readObjectFromResource("/md/attribute-sortDf.json", Attribute.class); assertThat(attribute.getSort(), is("/gdc/md/PROJECT_ID/obj/1806")); assertThat(attribute.isSortedByLinkedDf(), is(true)); diff --git a/src/test/java/com/gooddata/md/ColumnTest.java b/src/test/java/com/gooddata/md/ColumnTest.java index 5d0b9872d..4e7156598 100644 --- a/src/test/java/com/gooddata/md/ColumnTest.java +++ b/src/test/java/com/gooddata/md/ColumnTest.java @@ -5,22 +5,19 @@ */ package com.gooddata.md; +import org.testng.annotations.Test; + +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.text.MatchesPattern.matchesPattern; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.testng.annotations.Test; - -import java.io.InputStream; - public class ColumnTest { @Test public void shouldDeserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/column.json"); - final Column column = new ObjectMapper().readValue(stream, Column.class); + final Column column = readObjectFromResource("/md/column.json", Column.class); assertThat(column, is(notNullValue())); assertThat(column.getTableUri(), is("/gdc/md/PROJECT_ID/obj/9538")); @@ -35,8 +32,7 @@ public void shouldDeserialize() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/column.json"); - final Column column = new ObjectMapper().readValue(stream, Column.class); + final Column column = readObjectFromResource("/md/column.json", Column.class); assertThat(column.toString(), matchesPattern(Column.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/md/DataLoadingColumnTest.java b/src/test/java/com/gooddata/md/DataLoadingColumnTest.java index 933ec30e0..baa744821 100644 --- a/src/test/java/com/gooddata/md/DataLoadingColumnTest.java +++ b/src/test/java/com/gooddata/md/DataLoadingColumnTest.java @@ -5,23 +5,20 @@ */ package com.gooddata.md; +import org.testng.annotations.Test; + +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.text.MatchesPattern.matchesPattern; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.testng.annotations.Test; - -import java.io.InputStream; - public class DataLoadingColumnTest { @Test public void shouldDeserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/dataLoadingColumn.json"); - final DataLoadingColumn column = new ObjectMapper().readValue(stream, DataLoadingColumn.class); + final DataLoadingColumn column = readObjectFromResource("/md/dataLoadingColumn.json", DataLoadingColumn.class); assertThat(column, is(notNullValue())); assertThat(column.getColumnUri(), is("/gdc/md/PROJECT_ID/obj/COLUMN_ID")); @@ -43,8 +40,7 @@ public void shouldDeserialize() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/dataLoadingColumn.json"); - final DataLoadingColumn column = new ObjectMapper().readValue(stream, DataLoadingColumn.class); + final DataLoadingColumn column = readObjectFromResource("/md/dataLoadingColumn.json", DataLoadingColumn.class); assertThat(column.toString(), matchesPattern(DataLoadingColumn.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/md/DatasetTest.java b/src/test/java/com/gooddata/md/DatasetTest.java index b85e52743..b41f0e8ad 100644 --- a/src/test/java/com/gooddata/md/DatasetTest.java +++ b/src/test/java/com/gooddata/md/DatasetTest.java @@ -5,7 +5,12 @@ */ package com.gooddata.md; +import org.testng.annotations.Test; + +import java.util.List; + import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; @@ -13,19 +18,12 @@ import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.text.MatchesPattern.matchesPattern; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.testng.annotations.Test; - -import java.io.InputStream; -import java.util.List; - public class DatasetTest { @SuppressWarnings("deprecation") @Test public void shouldDeserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/dataset.json"); - final Dataset dataset = new ObjectMapper().readValue(stream, Dataset.class); + final Dataset dataset = readObjectFromResource("/md/dataset.json", Dataset.class); assertThat(dataset, is(notNullValue())); diff --git a/src/test/java/com/gooddata/md/DimensionTest.java b/src/test/java/com/gooddata/md/DimensionTest.java index 769afbb5a..c3f3cb207 100644 --- a/src/test/java/com/gooddata/md/DimensionTest.java +++ b/src/test/java/com/gooddata/md/DimensionTest.java @@ -5,25 +5,23 @@ */ package com.gooddata.md; +import org.testng.annotations.Test; + +import java.util.Collection; + import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.text.MatchesPattern.matchesPattern; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.testng.annotations.Test; - -import java.io.InputStream; -import java.util.Collection; - public class DimensionTest { @Test public void shouldDeserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/dimension.json"); - final Dimension dimension = new ObjectMapper().readValue(stream, Dimension.class); + final Dimension dimension = readObjectFromResource("/md/dimension.json", Dimension.class); assertThat(dimension, is(notNullValue())); final Collection attributes = dimension.getAttributes(); diff --git a/src/test/java/com/gooddata/md/DisplayFormTest.java b/src/test/java/com/gooddata/md/DisplayFormTest.java index bf8979d32..e4b5d77d4 100644 --- a/src/test/java/com/gooddata/md/DisplayFormTest.java +++ b/src/test/java/com/gooddata/md/DisplayFormTest.java @@ -5,12 +5,10 @@ */ package com.gooddata.md; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; @@ -27,8 +25,7 @@ public class DisplayFormTest { @SuppressWarnings("deprecation") @Test public void shouldDeserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/displayForm.json"); - final DisplayForm displayForm = new ObjectMapper().readValue(stream, DisplayForm.class); + final DisplayForm displayForm = readObjectFromResource("/md/displayForm.json", DisplayForm.class); assertThat(displayForm, is(notNullValue())); assertThat(displayForm.getFormOf(), is(FORM_OF)); diff --git a/src/test/java/com/gooddata/md/EntryTest.java b/src/test/java/com/gooddata/md/EntryTest.java index 1174d274c..894ba0e2a 100644 --- a/src/test/java/com/gooddata/md/EntryTest.java +++ b/src/test/java/com/gooddata/md/EntryTest.java @@ -5,7 +5,6 @@ */ package com.gooddata.md; -import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.testng.annotations.Test; @@ -13,6 +12,7 @@ import java.util.Set; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static java.util.Collections.singleton; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -38,7 +38,7 @@ public class EntryTest { @SuppressWarnings("deprecation") @Test public void testDeserialize() throws Exception { - final Entry entry = new ObjectMapper().readValue(getClass().getResourceAsStream("/md/entry.json"), Entry.class); + final Entry entry = readObjectFromResource("/md/entry.json", Entry.class); assertThat(entry, is(notNullValue())); assertThat(entry.getLink(), is(URI)); assertThat(entry.getUri(), is(URI)); diff --git a/src/test/java/com/gooddata/md/ExpressionTest.java b/src/test/java/com/gooddata/md/ExpressionTest.java index 786b2e047..28a080c24 100644 --- a/src/test/java/com/gooddata/md/ExpressionTest.java +++ b/src/test/java/com/gooddata/md/ExpressionTest.java @@ -5,9 +5,9 @@ */ package com.gooddata.md; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -18,11 +18,10 @@ public class ExpressionTest { public static final String DATA = "/gdc/md/PROJECT_ID/obj/EXPR_ID"; public static final String TYPE = "expr"; public static final String JSON = "{\"data\":\"/gdc/md/PROJECT_ID/obj/EXPR_ID\",\"type\":\"expr\"}"; - public static final ObjectMapper MAPPER = new ObjectMapper(); @Test public void testDeserialize() throws Exception { - final Expression expression = MAPPER.readValue(JSON, Expression.class); + final Expression expression = OBJECT_MAPPER.readValue(JSON, Expression.class); assertThat(expression, is(notNullValue())); assertThat(expression.getData(), is(DATA)); assertThat(expression.getType(), is(TYPE)); @@ -31,7 +30,7 @@ public void testDeserialize() throws Exception { @Test public void testSerialize() throws Exception { final Expression expression = new Expression(DATA, TYPE); - assertThat(MAPPER.writeValueAsString(expression), is(JSON)); + assertThat(OBJECT_MAPPER.writeValueAsString(expression), is(JSON)); } @Test diff --git a/src/test/java/com/gooddata/md/FactTest.java b/src/test/java/com/gooddata/md/FactTest.java index 4decd7e40..ce4b2b8c1 100644 --- a/src/test/java/com/gooddata/md/FactTest.java +++ b/src/test/java/com/gooddata/md/FactTest.java @@ -5,10 +5,10 @@ */ package com.gooddata.md; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -19,7 +19,7 @@ public class FactTest { @Test public void testDeserialization() throws Exception { - final Fact fact = new ObjectMapper().readValue(getClass().getResourceAsStream("/md/fact.json"), Fact.class); + final Fact fact = readObjectFromResource("/md/fact.json", Fact.class); assertThat(fact, is(notNullValue())); assertThat(fact.getExpressions(), is(notNullValue())); assertThat(fact.getExpressions(), hasSize(1)); diff --git a/src/test/java/com/gooddata/md/KeyTest.java b/src/test/java/com/gooddata/md/KeyTest.java index 24be70932..fc79bc57d 100644 --- a/src/test/java/com/gooddata/md/KeyTest.java +++ b/src/test/java/com/gooddata/md/KeyTest.java @@ -5,9 +5,9 @@ */ package com.gooddata.md; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -15,14 +15,13 @@ public class KeyTest { - public static final ObjectMapper MAPPER = new ObjectMapper(); public static final String DATA = "/gdc/md/PROJECT_ID/obj/PK_ID"; public static final String TYPE = "col"; public static final String JSON = "{\"data\":\"/gdc/md/PROJECT_ID/obj/PK_ID\",\"type\":\"col\"}"; @Test public void testDeserialize() throws Exception { - final Key key = MAPPER.readValue(JSON, Key.class); + final Key key = OBJECT_MAPPER.readValue(JSON, Key.class); assertThat(key, is(notNullValue())); assertThat(key.getData(), is(DATA)); assertThat(key.getType(), is(TYPE)); @@ -31,7 +30,7 @@ public void testDeserialize() throws Exception { @Test public void testSerialize() throws Exception { final Key key = new Key(DATA, TYPE); - final String json = MAPPER.writeValueAsString(key); + final String json = OBJECT_MAPPER.writeValueAsString(key); assertThat(json, is(JSON)); } diff --git a/src/test/java/com/gooddata/md/MetaTest.java b/src/test/java/com/gooddata/md/MetaTest.java index c91271be6..c13310491 100644 --- a/src/test/java/com/gooddata/md/MetaTest.java +++ b/src/test/java/com/gooddata/md/MetaTest.java @@ -5,7 +5,6 @@ */ package com.gooddata.md; -import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.testng.annotations.Test; @@ -14,6 +13,7 @@ import java.util.Set; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -40,7 +40,7 @@ public class MetaTest { @Test public void testDeserialization() throws Exception { - final Meta meta = new ObjectMapper().readValue(getClass().getResourceAsStream("/md/meta.json"), Meta.class); + final Meta meta = readObjectFromResource("/md/meta.json", Meta.class); assertThat(meta, is(notNullValue())); assertThat(meta.getAuthor(), is(AUTHOR)); assertThat(meta.getContributor(), is(CONTRIBUTOR)); diff --git a/src/test/java/com/gooddata/md/MetadataServiceIT.java b/src/test/java/com/gooddata/md/MetadataServiceIT.java index e6a0e552b..8b3919714 100644 --- a/src/test/java/com/gooddata/md/MetadataServiceIT.java +++ b/src/test/java/com/gooddata/md/MetadataServiceIT.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.util.*; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static com.gooddata.util.ResourceUtils.readFromResource; import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static com.gooddata.util.ResourceUtils.readStringFromResource; @@ -47,9 +48,9 @@ public class MetadataServiceIT extends AbstractGoodDataIT { @BeforeClass public void setUp() throws Exception { - project = MAPPER.readValue(readFromResource("/project/project.json"), Project.class); - metricInput = MAPPER.readValue(readFromResource("/md/metric-input.json"), Metric.class); - scheduledMailInput = MAPPER.readValue(readFromResource("/md/scheduledMail.json"), ScheduledMail.class); + project = readObjectFromResource("/project/project.json", Project.class); + metricInput = readObjectFromResource("/md/metric-input.json", Metric.class); + scheduledMailInput = readObjectFromResource("/md/scheduledMail.json", ScheduledMail.class); } @Test @@ -64,7 +65,7 @@ public void testUsedBy() throws Exception { .havingPathEqualTo(USEDBY_URI) .respond() .withStatus(200) - .withBody(MAPPER.writeValueAsString(useMany)); + .withBody(OBJECT_MAPPER.writeValueAsString(useMany)); final Collection result = gd.getMetadataService().usedBy(project, OBJ_URI, false, ReportDefinition.class); @@ -86,7 +87,7 @@ public void testUsedByBatch() throws Exception { .havingPathEqualTo(USEDBY_URI) .respond() .withStatus(200) - .withBody(MAPPER.writeValueAsString(useMany)); + .withBody(OBJECT_MAPPER.writeValueAsString(useMany)); final Collection result = gd.getMetadataService().usedBy(project, new HashSet<>(asList(OBJ_URI, OBJ_URI2)), false, ReportDefinition.class); @@ -156,11 +157,11 @@ public void shouldCreateObj() throws Exception { public void shouldUpdateObj() throws Exception { onRequest() .havingMethodEqualTo("PUT") - .havingBodyEqualTo(MAPPER.writeValueAsString(metricInput)) + .havingBodyEqualTo(OBJECT_MAPPER.writeValueAsString(metricInput)) .havingPathEqualTo(SPECIFIC_OBJ_URI) .respond() .withStatus(200) - .withBody(MAPPER.writeValueAsString(new UriResponse(SPECIFIC_OBJ_URI))); + .withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse(SPECIFIC_OBJ_URI))); onRequest() .havingMethodEqualTo("GET") .havingPathEqualTo(SPECIFIC_OBJ_URI) diff --git a/src/test/java/com/gooddata/md/MetricTest.java b/src/test/java/com/gooddata/md/MetricTest.java index 7e16e70b5..99435d63e 100644 --- a/src/test/java/com/gooddata/md/MetricTest.java +++ b/src/test/java/com/gooddata/md/MetricTest.java @@ -5,7 +5,10 @@ */ package com.gooddata.md; +import org.testng.annotations.Test; + import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static net.javacrumbs.jsonunit.JsonMatchers.jsonNodeAbsent; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -14,16 +17,11 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.text.MatchesPattern.matchesPattern; -import org.testng.annotations.Test; - -import com.fasterxml.jackson.databind.ObjectMapper; - public class MetricTest { @Test public void testDeserialization() throws Exception { - final Metric metric = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/md/metric-out.json"), Metric.class); + final Metric metric = readObjectFromResource("/md/metric-out.json", Metric.class); assertThat(metric, is(notNullValue())); assertThat(metric.getExpression(), is("SELECT AVG([/gdc/md/PROJECT_ID/obj/EXPR_ID])")); assertThat(metric.getFormat(), is("#,##0")); @@ -41,8 +39,7 @@ public void testDeserialization() throws Exception { @Test public void shouldDeserializeFolder() throws Exception { - final Metric metric = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/md/metric-folder.json"), Metric.class); + final Metric metric = readObjectFromResource("/md/metric-folder.json", Metric.class); assertThat(metric.getFolders(), contains("/gdc/md/ge06jy0jr6h1hzaxei6d53evw276p3xc/obj/51430")); } @@ -54,8 +51,7 @@ public void testSerialization() throws Exception { @Test public void fullJsonShouldStayTheSameAfterDeserializationAndSerializationBack() throws Exception { - final Metric metric = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/md/metric-out.json"), Metric.class); + final Metric metric = readObjectFromResource("/md/metric-out.json", Metric.class); assertThat(metric, jsonNodeAbsent("metric.content.tree.content[0].content[0].content[0].content")); assertThat(metric, serializesToJson("/md/metric-out.json")); @@ -63,15 +59,13 @@ public void fullJsonShouldStayTheSameAfterDeserializationAndSerializationBack() @Test public void shouldIgnoreLinksProperty() throws Exception { - final Metric metric = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/md/metric-links.json"), Metric.class); + final Metric metric = readObjectFromResource("/md/metric-links.json", Metric.class); assertThat(metric, serializesToJson("/md/metric-out.json")); } @Test public void testToStringFormat() throws Exception { - final Metric metric = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/md/metric-out.json"), Metric.class); + final Metric metric = readObjectFromResource("/md/metric-out.json", Metric.class); assertThat(metric.toString(), matchesPattern(Metric.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/md/NestedAttributeTest.java b/src/test/java/com/gooddata/md/NestedAttributeTest.java index 302a70c9b..2424ee40e 100644 --- a/src/test/java/com/gooddata/md/NestedAttributeTest.java +++ b/src/test/java/com/gooddata/md/NestedAttributeTest.java @@ -5,24 +5,25 @@ */ package com.gooddata.md; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; -import static org.hamcrest.text.MatchesPattern.matchesPattern; - -import com.fasterxml.jackson.databind.ObjectMapper; import org.hamcrest.Matchers; import org.testng.annotations.Test; import java.util.Collection; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.isEmptyString; +import static org.hamcrest.text.MatchesPattern.matchesPattern; + public class NestedAttributeTest { @SuppressWarnings("deprecation") @Test public void testDeserialization() throws Exception { - final NestedAttribute attribute = new ObjectMapper().readValue(getClass().getResourceAsStream("/md/dimensionAttribute.json"), NestedAttribute.class); + final NestedAttribute attribute = readObjectFromResource("/md/dimensionAttribute.json", NestedAttribute.class); assertThat(attribute, is(notNullValue())); final Collection displayForms = attribute.getDisplayForms(); @@ -60,7 +61,7 @@ public void testDeserialization() throws Exception { @Test public void testToStringFormat() throws Exception { - final NestedAttribute attribute = new ObjectMapper().readValue(getClass().getResourceAsStream("/md/dimensionAttribute.json"), NestedAttribute.class); + final NestedAttribute attribute = readObjectFromResource("/md/dimensionAttribute.json", NestedAttribute.class); assertThat(attribute.toString(), matchesPattern(NestedAttribute.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/md/ObjTest.java b/src/test/java/com/gooddata/md/ObjTest.java index 7cbccf448..175d7c51c 100644 --- a/src/test/java/com/gooddata/md/ObjTest.java +++ b/src/test/java/com/gooddata/md/ObjTest.java @@ -6,16 +6,15 @@ package com.gooddata.md; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.testng.annotations.Test; -import java.io.InputStream; import java.util.LinkedHashSet; import java.util.Set; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -39,8 +38,7 @@ public class ObjTest { @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/objCommon.json"); - final AbstractObj obj = new ObjectMapper().readValue(stream, ConcreteObj.class); + final AbstractObj obj = readObjectFromResource("/md/objCommon.json", ConcreteObj.class); assertThat(obj, is(notNullValue())); assertThat(obj.getAuthor(), is(AUTHOR)); diff --git a/src/test/java/com/gooddata/md/ProjectDashboardTest.java b/src/test/java/com/gooddata/md/ProjectDashboardTest.java index 166d15558..8bc4e5e42 100644 --- a/src/test/java/com/gooddata/md/ProjectDashboardTest.java +++ b/src/test/java/com/gooddata/md/ProjectDashboardTest.java @@ -5,21 +5,20 @@ */ package com.gooddata.md; +import org.testng.annotations.Test; + +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.text.MatchesPattern.matchesPattern; -import com.fasterxml.jackson.databind.ObjectMapper; - -import org.testng.annotations.Test; - public class ProjectDashboardTest { @Test public void testDeserialization() throws Exception { - final ProjectDashboard dashboard = new ObjectMapper().readValue(getClass().getResourceAsStream("/md/projectDashboard.json"), ProjectDashboard.class); + final ProjectDashboard dashboard = readObjectFromResource("/md/projectDashboard.json", ProjectDashboard.class); assertThat(dashboard.getUri(), is("/gdc/md/PROJECT_ID/obj/12345")); @@ -35,7 +34,7 @@ public void testDeserialization() throws Exception { @Test public void testToStringFormat() throws Exception { - final ProjectDashboard dashboard = new ObjectMapper().readValue(getClass().getResourceAsStream("/md/projectDashboard.json"), ProjectDashboard.class); + final ProjectDashboard dashboard = readObjectFromResource("/md/projectDashboard.json", ProjectDashboard.class); assertThat(dashboard.toString(), matchesPattern(ProjectDashboard.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/md/QueryTest.java b/src/test/java/com/gooddata/md/QueryTest.java index b4963d67f..87d8dc565 100644 --- a/src/test/java/com/gooddata/md/QueryTest.java +++ b/src/test/java/com/gooddata/md/QueryTest.java @@ -5,9 +5,9 @@ */ package com.gooddata.md; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -17,7 +17,7 @@ public class QueryTest { @Test public void testDeserialization() throws Exception { - final Query query = new ObjectMapper().readValue(getClass().getResourceAsStream("/md/query.json"), Query.class); + final Query query = readObjectFromResource("/md/query.json", Query.class); assertThat(query, is(notNullValue())); assertThat(query.getCategory(), is("MD::Query::Object")); assertThat(query.getTitle(), is("List of allTypes")); @@ -26,7 +26,7 @@ public void testDeserialization() throws Exception { @Test public void testToStringFormat() throws Exception { - final Query query = new ObjectMapper().readValue(getClass().getResourceAsStream("/md/query.json"), Query.class); + final Query query = readObjectFromResource("/md/query.json", Query.class); assertThat(query.toString(), matchesPattern(Query.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/md/ScheduledMailTest.java b/src/test/java/com/gooddata/md/ScheduledMailTest.java index 5d845e0d5..991933c34 100644 --- a/src/test/java/com/gooddata/md/ScheduledMailTest.java +++ b/src/test/java/com/gooddata/md/ScheduledMailTest.java @@ -7,14 +7,16 @@ import com.gooddata.JsonMatchers; import com.gooddata.report.ReportExportFormat; -import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.LocalDate; import org.testng.annotations.Test; import java.util.Arrays; import java.util.Collections; -import static org.hamcrest.CoreMatchers.*; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.text.MatchesPattern.matchesPattern; @@ -40,7 +42,7 @@ public class ScheduledMailTest { @Test public void testDeserialization() throws Exception { - final ScheduledMail scheduledMail = new ObjectMapper().readValue(getClass().getResourceAsStream("/md/scheduledMail.json"), ScheduledMail.class); + final ScheduledMail scheduledMail = readObjectFromResource("/md/scheduledMail.json", ScheduledMail.class); assertThat(scheduledMail, is(notNullValue())); assertThat(scheduledMail.getToAddresses(), hasItems("email@example.com")); assertThat(scheduledMail.getBccAddresses(), hasItems("secret-email@example.com")); @@ -67,7 +69,7 @@ public void testSerialization() throws Exception { @Test public void testToStringFormat() throws Exception { - final ScheduledMail scheduledMail = new ObjectMapper().readValue(getClass().getResourceAsStream("/md/scheduledMail.json"), ScheduledMail.class); + final ScheduledMail scheduledMail = readObjectFromResource("/md/scheduledMail.json", ScheduledMail.class); assertThat(scheduledMail.toString(), matchesPattern(ScheduledMail.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/md/TableDataLoadTest.java b/src/test/java/com/gooddata/md/TableDataLoadTest.java index b00bf22d8..d38deb28c 100644 --- a/src/test/java/com/gooddata/md/TableDataLoadTest.java +++ b/src/test/java/com/gooddata/md/TableDataLoadTest.java @@ -5,22 +5,19 @@ */ package com.gooddata.md; +import org.testng.annotations.Test; + +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.text.MatchesPattern.matchesPattern; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.testng.annotations.Test; - -import java.io.InputStream; - public class TableDataLoadTest { @Test public void shouldDeserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/tableDataLoad.json"); - final TableDataLoad load = new ObjectMapper().readValue(stream, TableDataLoad.class); + final TableDataLoad load = readObjectFromResource("/md/tableDataLoad.json", TableDataLoad.class); assertThat(load, is(notNullValue())); assertThat(load.getDataSourceLocation(), is("d_zendesktickets_vehicleview_aaavxfdfgqamowg")); @@ -31,8 +28,7 @@ public void shouldDeserialize() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/tableDataLoad.json"); - final TableDataLoad load = new ObjectMapper().readValue(stream, TableDataLoad.class); + final TableDataLoad load = readObjectFromResource("/md/tableDataLoad.json", TableDataLoad.class); assertThat(load.toString(), matchesPattern(TableDataLoad.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/md/TableTest.java b/src/test/java/com/gooddata/md/TableTest.java index 783cbbf65..2f683f86a 100644 --- a/src/test/java/com/gooddata/md/TableTest.java +++ b/src/test/java/com/gooddata/md/TableTest.java @@ -5,23 +5,20 @@ */ package com.gooddata.md; +import org.testng.annotations.Test; + +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.text.MatchesPattern.matchesPattern; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.testng.annotations.Test; - -import java.io.InputStream; - public class TableTest { @Test public void shouldDeserialize() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/table.json"); - final Table table = new ObjectMapper().readValue(stream, Table.class); + final Table table = readObjectFromResource("/md/table.json", Table.class); assertThat(table, is(notNullValue())); assertThat(table.getDBName(), is("d_zendesktickets_vehicleview")); @@ -33,8 +30,7 @@ public void shouldDeserialize() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/md/table.json"); - final Table table = new ObjectMapper().readValue(stream, Table.class); + final Table table = readObjectFromResource("/md/table.json", Table.class); assertThat(table.toString(), matchesPattern(Table.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/md/maintenance/ExportImportServiceIT.java b/src/test/java/com/gooddata/md/maintenance/ExportImportServiceIT.java index 03bd15331..a526ca825 100644 --- a/src/test/java/com/gooddata/md/maintenance/ExportImportServiceIT.java +++ b/src/test/java/com/gooddata/md/maintenance/ExportImportServiceIT.java @@ -6,6 +6,7 @@ package com.gooddata.md.maintenance; import static com.gooddata.util.ResourceUtils.readFromResource; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static net.jadler.Jadler.onRequest; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -23,7 +24,7 @@ public class ExportImportServiceIT extends AbstractGoodDataIT { @BeforeClass public void setUp() throws Exception { - project = MAPPER.readValue(readFromResource("/project/project.json"), Project.class); + project = readObjectFromResource("/project/project.json", Project.class); } @Test diff --git a/src/test/java/com/gooddata/md/maintenance/PartialMdArtifactTest.java b/src/test/java/com/gooddata/md/maintenance/PartialMdArtifactTest.java index 0da3e56be..30731bde5 100644 --- a/src/test/java/com/gooddata/md/maintenance/PartialMdArtifactTest.java +++ b/src/test/java/com/gooddata/md/maintenance/PartialMdArtifactTest.java @@ -5,23 +5,20 @@ */ package com.gooddata.md.maintenance; -import static com.gooddata.JsonMatchers.serializesToJson; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; -import static org.hamcrest.text.MatchesPattern.matchesPattern; - -import com.fasterxml.jackson.databind.ObjectMapper; import com.gooddata.gdc.UriResponse; import org.testng.annotations.Test; -import java.io.InputStream; +import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.text.MatchesPattern.matchesPattern; public class PartialMdArtifactTest { @Test public void shouldDeserialize() throws Exception { - final InputStream input = getClass().getResourceAsStream("/md/maintenance/partialMDArtifact.json"); - final PartialMdArtifact partialMdArtifact = new ObjectMapper().readValue(input, PartialMdArtifact.class); + final PartialMdArtifact partialMdArtifact = readObjectFromResource("/md/maintenance/partialMDArtifact.json", PartialMdArtifact.class); assertThat(partialMdArtifact.getStatusUri(), is("/gdc/md/projectId/tasks/taskId/status")); assertThat(partialMdArtifact.getToken(), is("TOKEN123")); diff --git a/src/test/java/com/gooddata/md/report/AttributeInGridTest.java b/src/test/java/com/gooddata/md/report/AttributeInGridTest.java index c4a581ec9..910d24676 100644 --- a/src/test/java/com/gooddata/md/report/AttributeInGridTest.java +++ b/src/test/java/com/gooddata/md/report/AttributeInGridTest.java @@ -5,21 +5,20 @@ */ package com.gooddata.md.report; -import com.fasterxml.jackson.databind.ObjectMapper; import com.gooddata.md.Attribute; import com.gooddata.md.DisplayForm; import org.testng.annotations.Test; -import java.io.InputStream; import java.util.Iterator; import java.util.List; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.text.MatchesPattern.matchesPattern; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -32,8 +31,7 @@ public class AttributeInGridTest { @Test public void testDeserialization() throws Exception { - final InputStream is = getClass().getResourceAsStream("/md/report/attributeInGrid.json"); - final AttributeInGrid attr = new ObjectMapper().readValue(is, AttributeInGrid.class); + final AttributeInGrid attr = readObjectFromResource("/md/report/attributeInGrid.json", AttributeInGrid.class); assertThat(attr, is(notNullValue())); assertThat(attr.getUri(), is(URI)); @@ -85,8 +83,7 @@ public void testCreateFromDisplayForm() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream is = getClass().getResourceAsStream("/md/report/attributeInGrid.json"); - final AttributeInGrid attr = new ObjectMapper().readValue(is, AttributeInGrid.class); + final AttributeInGrid attr = readObjectFromResource("/md/report/attributeInGrid.json", AttributeInGrid.class); assertThat(attr.toString(), matchesPattern(AttributeInGrid.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/md/report/GridElementDeserializerTest.java b/src/test/java/com/gooddata/md/report/GridElementDeserializerTest.java index bd0b27ddd..2d3a88e06 100644 --- a/src/test/java/com/gooddata/md/report/GridElementDeserializerTest.java +++ b/src/test/java/com/gooddata/md/report/GridElementDeserializerTest.java @@ -5,12 +5,12 @@ */ package com.gooddata.md.report; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.testng.annotations.Test; import java.util.ArrayList; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -21,8 +21,7 @@ public class GridElementDeserializerTest { @Test public void testDeserializer() throws Exception { - final GridElements elems = new ObjectMapper().readValue( - getClass().getResourceAsStream("/md/report/gridElements.json"), GridElements.class); + final GridElements elems = readObjectFromResource("/md/report/gridElements.json", GridElements.class); assertThat(elems, is(notNullValue())); assertThat(elems, hasSize(2)); diff --git a/src/test/java/com/gooddata/md/report/GridReportDefinitionContentTest.java b/src/test/java/com/gooddata/md/report/GridReportDefinitionContentTest.java index cfea902dc..8c42c85e0 100644 --- a/src/test/java/com/gooddata/md/report/GridReportDefinitionContentTest.java +++ b/src/test/java/com/gooddata/md/report/GridReportDefinitionContentTest.java @@ -5,13 +5,12 @@ */ package com.gooddata.md.report; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; import java.util.Collections; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -20,8 +19,8 @@ public class GridReportDefinitionContentTest { @Test public void testDeserialization() throws Exception { - final InputStream is = getClass().getResourceAsStream("/md/report/gridReportDefinitionContent.json"); - final GridReportDefinitionContent def = (GridReportDefinitionContent) new ObjectMapper().readValue(is, ReportDefinitionContent.class); + final GridReportDefinitionContent def = (GridReportDefinitionContent) + readObjectFromResource("/md/report/gridReportDefinitionContent.json", ReportDefinitionContent.class); assertThat(def, is(notNullValue())); assertThat(def.getFormat(), is("grid")); assertThat(def.getGrid(), is(notNullValue())); diff --git a/src/test/java/com/gooddata/md/report/GridTest.java b/src/test/java/com/gooddata/md/report/GridTest.java index 525c84b9e..b7ce8cd8a 100644 --- a/src/test/java/com/gooddata/md/report/GridTest.java +++ b/src/test/java/com/gooddata/md/report/GridTest.java @@ -5,7 +5,6 @@ */ package com.gooddata.md.report; -import com.fasterxml.jackson.databind.ObjectMapper; import org.hamcrest.CoreMatchers; import org.testng.annotations.Test; @@ -16,19 +15,20 @@ import static com.gooddata.JsonMatchers.serializesToJson; import static com.gooddata.md.report.MetricGroup.METRIC_GROUP; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.text.MatchesPattern.matchesPattern; public class GridTest { @Test public void testDeserialization() throws Exception { - final Grid grid = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/md/report/grid.json"), Grid.class); + final Grid grid = readObjectFromResource("/md/report/grid.json", Grid.class); assertThat(grid, is(notNullValue())); assertThat(grid.getColumns(), is(notNullValue())); @@ -63,15 +63,14 @@ public void testSerialization() throws Exception { asList(new AttributeInGrid("/gdc/md/PROJECT_ID/obj/ATTR_ID", "attr")), asList(new MetricElement("/gdc/md/PROJECT_ID/obj/METR_ID", "metr")), sort, asList(colWidths)); - new ObjectMapper().writeValueAsString(grid); + OBJECT_MAPPER.writeValueAsString(grid); assertThat(grid, serializesToJson("/md/report/grid-input.json")); } @Test public void testToStringFormat() throws Exception { - final Grid grid = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/md/report/grid.json"), Grid.class); + final Grid grid = readObjectFromResource("/md/report/grid.json", Grid.class); assertThat(grid.toString(), matchesPattern(Grid.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/md/report/MetricElementTest.java b/src/test/java/com/gooddata/md/report/MetricElementTest.java index 6b337f556..ce34e837f 100644 --- a/src/test/java/com/gooddata/md/report/MetricElementTest.java +++ b/src/test/java/com/gooddata/md/report/MetricElementTest.java @@ -5,13 +5,11 @@ */ package com.gooddata.md.report; -import com.fasterxml.jackson.databind.ObjectMapper; import com.gooddata.md.Metric; import org.testng.annotations.Test; -import java.io.InputStream; - import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -28,8 +26,7 @@ public class MetricElementTest { @Test public void testDeserialization() throws Exception { - final InputStream is = getClass().getResourceAsStream("/md/report/metricElement.json"); - final MetricElement element = new ObjectMapper().readValue(is, MetricElement.class); + final MetricElement element = readObjectFromResource("/md/report/metricElement.json", MetricElement.class); assertThat(element, is(notNullValue())); assertThat(element.getUri(), is(URI)); assertThat(element.getAlias(), is(ALIAS)); diff --git a/src/test/java/com/gooddata/md/report/OneNumberReportDefinitionContentTest.java b/src/test/java/com/gooddata/md/report/OneNumberReportDefinitionContentTest.java index 8d212477f..f3ecb401b 100644 --- a/src/test/java/com/gooddata/md/report/OneNumberReportDefinitionContentTest.java +++ b/src/test/java/com/gooddata/md/report/OneNumberReportDefinitionContentTest.java @@ -5,13 +5,12 @@ */ package com.gooddata.md.report; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; import java.util.Collections; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -20,9 +19,8 @@ public class OneNumberReportDefinitionContentTest { @Test public void testDeserialization() throws Exception { - final InputStream is = getClass().getResourceAsStream("/md/report/oneNumberReportDefinitionContent.json"); - final OneNumberReportDefinitionContent def = (OneNumberReportDefinitionContent) new ObjectMapper() - .readValue(is, ReportDefinitionContent.class); + final OneNumberReportDefinitionContent def = (OneNumberReportDefinitionContent) + readObjectFromResource("/md/report/oneNumberReportDefinitionContent.json", ReportDefinitionContent.class); assertThat(def, is(notNullValue())); assertThat(def.getFormat(), is("oneNumber")); assertThat(def.getGrid(), is(notNullValue())); diff --git a/src/test/java/com/gooddata/md/report/ReportDefinitionContentTest.java b/src/test/java/com/gooddata/md/report/ReportDefinitionContentTest.java index a33690ac4..b3fe0e08f 100644 --- a/src/test/java/com/gooddata/md/report/ReportDefinitionContentTest.java +++ b/src/test/java/com/gooddata/md/report/ReportDefinitionContentTest.java @@ -5,13 +5,12 @@ */ package com.gooddata.md.report; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; import java.util.Collections; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -21,8 +20,7 @@ public class ReportDefinitionContentTest { @Test public void testDeserialization() throws Exception { - final InputStream is = getClass().getResourceAsStream("/md/report/gridReportDefinitionContent.json"); - final ReportDefinitionContent def = new ObjectMapper().readValue(is, ReportDefinitionContent.class); + final ReportDefinitionContent def = readObjectFromResource("/md/report/gridReportDefinitionContent.json", ReportDefinitionContent.class); assertThat(def, is(notNullValue())); assertThat(def.getFormat(), is("grid")); assertThat(def.getGrid(), is(notNullValue())); diff --git a/src/test/java/com/gooddata/md/report/ReportDefinitionTest.java b/src/test/java/com/gooddata/md/report/ReportDefinitionTest.java index b9e61cb89..7ed37b1b2 100644 --- a/src/test/java/com/gooddata/md/report/ReportDefinitionTest.java +++ b/src/test/java/com/gooddata/md/report/ReportDefinitionTest.java @@ -5,13 +5,12 @@ */ package com.gooddata.md.report; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; import java.util.Collections; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -24,8 +23,7 @@ public class ReportDefinitionTest { @Test public void testDeserialization() throws Exception { - final InputStream is = getClass().getResourceAsStream("/md/report/oneNumberReportDefinition.json"); - final ReportDefinition def = new ObjectMapper().readValue(is, ReportDefinition.class); + final ReportDefinition def = readObjectFromResource("/md/report/oneNumberReportDefinition.json", ReportDefinition.class); assertThat(def, is(notNullValue())); assertThat(def.getFormat(), is(FORMAT)); assertThat(def.getGrid(), is(notNullValue())); @@ -44,8 +42,7 @@ public void testSerialization() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream is = getClass().getResourceAsStream("/md/report/oneNumberReportDefinition.json"); - final ReportDefinition def = new ObjectMapper().readValue(is, ReportDefinition.class); + final ReportDefinition def = readObjectFromResource("/md/report/oneNumberReportDefinition.json", ReportDefinition.class); assertThat(def.toString(), matchesPattern(ReportDefinition.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/md/report/ReportTest.java b/src/test/java/com/gooddata/md/report/ReportTest.java index 847d09b29..2383c4aa5 100644 --- a/src/test/java/com/gooddata/md/report/ReportTest.java +++ b/src/test/java/com/gooddata/md/report/ReportTest.java @@ -5,14 +5,14 @@ */ package com.gooddata.md.report; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.text.MatchesPattern.matchesPattern; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -24,7 +24,7 @@ public class ReportTest { @Test public void testDeserialization() throws Exception { - final Report report = new ObjectMapper().readValue(getClass().getResourceAsStream("/md/report/report.json"), Report.class); + final Report report = readObjectFromResource("/md/report/report.json", Report.class); assertThat(report, is(notNullValue())); assertThat(report.getDefinitions(), is(notNullValue())); assertThat(report.getDefinitions(), hasSize(1)); @@ -46,7 +46,7 @@ public void testSerialization() throws Exception { @Test public void testToStringFormat() throws Exception { - final Report report = new ObjectMapper().readValue(getClass().getResourceAsStream("/md/report/report.json"), Report.class); + final Report report = readObjectFromResource("/md/report/report.json", Report.class); assertThat(report.toString(), matchesPattern(Report.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/model/DiffRequestTest.java b/src/test/java/com/gooddata/model/DiffRequestTest.java index 6d15c45c0..e532761db 100644 --- a/src/test/java/com/gooddata/model/DiffRequestTest.java +++ b/src/test/java/com/gooddata/model/DiffRequestTest.java @@ -5,19 +5,17 @@ */ package com.gooddata.model; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class DiffRequestTest { - private static final ObjectMapper mapper = new ObjectMapper(); - @Test public void testSerialization() throws Exception { - String valueAsString = mapper.writeValueAsString(new DiffRequest("{\"projectModel\":\"xxx\"}")); + String valueAsString = OBJECT_MAPPER.writeValueAsString(new DiffRequest("{\"projectModel\":\"xxx\"}")); assertThat(valueAsString, is("{\"diffRequest\":{\"targetModel\":{\"projectModel\":\"xxx\"}}}")); } } diff --git a/src/test/java/com/gooddata/model/MaqlDdlLinksTest.java b/src/test/java/com/gooddata/model/MaqlDdlLinksTest.java index d9687eaa1..2b7533c1e 100644 --- a/src/test/java/com/gooddata/model/MaqlDdlLinksTest.java +++ b/src/test/java/com/gooddata/model/MaqlDdlLinksTest.java @@ -5,11 +5,9 @@ */ package com.gooddata.model; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -19,8 +17,7 @@ public class MaqlDdlLinksTest { @SuppressWarnings("deprecation") @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/model/maqlDdlLinks.json"); - final MaqlDdlLinks maqlDdlLinks = new ObjectMapper().readValue(stream, MaqlDdlLinks.class); + final MaqlDdlLinks maqlDdlLinks = readObjectFromResource("/model/maqlDdlLinks.json", MaqlDdlLinks.class); assertThat(maqlDdlLinks, is(notNullValue())); assertThat(maqlDdlLinks.getStatusLink(), is("/gdc/md/PROJECT_ID/tasks/123/status")); diff --git a/src/test/java/com/gooddata/model/MaqlDdlTest.java b/src/test/java/com/gooddata/model/MaqlDdlTest.java index 59c368991..d70267204 100644 --- a/src/test/java/com/gooddata/model/MaqlDdlTest.java +++ b/src/test/java/com/gooddata/model/MaqlDdlTest.java @@ -5,9 +5,9 @@ */ package com.gooddata.model; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; @@ -15,7 +15,7 @@ public class MaqlDdlTest { @Test public void testSerialization() throws Exception { - assertThat(new ObjectMapper().writeValueAsString(new MaqlDdl("maqlddl")), + assertThat(OBJECT_MAPPER.writeValueAsString(new MaqlDdl("maqlddl")), is("{\"manage\":{\"maql\":\"maqlddl\"}}")); } diff --git a/src/test/java/com/gooddata/model/ModelDiffTest.java b/src/test/java/com/gooddata/model/ModelDiffTest.java index 2a1758b56..8ec6f81c5 100644 --- a/src/test/java/com/gooddata/model/ModelDiffTest.java +++ b/src/test/java/com/gooddata/model/ModelDiffTest.java @@ -5,13 +5,12 @@ */ package com.gooddata.model; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; import java.util.Collections; import static com.gooddata.model.ModelDiff.UpdateScript; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; @@ -76,8 +75,7 @@ public void testGetUpdateMaqlsNoMaqlInUpdateScript() throws Exception { @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/model/modelDiff.json"); - final ModelDiff diff = new ObjectMapper().readValue(stream, ModelDiff.class); + final ModelDiff diff = readObjectFromResource("/model/modelDiff.json", ModelDiff.class); assertThat(diff, is(notNullValue())); assertThat(diff.getUpdateScripts(), hasSize(2)); diff --git a/src/test/java/com/gooddata/model/ModelServiceIT.java b/src/test/java/com/gooddata/model/ModelServiceIT.java index bfce9a281..a661daa26 100644 --- a/src/test/java/com/gooddata/model/ModelServiceIT.java +++ b/src/test/java/com/gooddata/model/ModelServiceIT.java @@ -13,7 +13,9 @@ import org.testng.annotations.Test; import static com.gooddata.model.ModelDiff.UpdateScript; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static com.gooddata.util.ResourceUtils.readFromResource; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static net.jadler.Jadler.onRequest; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -30,7 +32,7 @@ public class ModelServiceIT extends AbstractGoodDataIT { @BeforeClass public void setUp() throws Exception { - project = MAPPER.readValue(readFromResource("/project/project.json"), Project.class); + project = readObjectFromResource("/project/project.json", Project.class); } @Test @@ -40,13 +42,13 @@ public void shouldCreateDiff() throws Exception { .havingPathEqualTo(DIFF_URI) .respond() .withStatus(202) - .withBody(MAPPER.writeValueAsString(new AsyncTask(DIFF_POLL_URI))); + .withBody(OBJECT_MAPPER.writeValueAsString(new AsyncTask(DIFF_POLL_URI))); onRequest() .havingMethodEqualTo("GET") .havingPathEqualTo(DIFF_POLL_URI) .respond() .withStatus(202) - .withBody(MAPPER.writeValueAsString(new AsyncTask(DIFF_POLL_URI))) + .withBody(OBJECT_MAPPER.writeValueAsString(new AsyncTask(DIFF_POLL_URI))) .thenRespond() .withStatus(200) .withBody(readFromResource("/model/modelDiff.json")) @@ -65,7 +67,7 @@ public void shouldFailCreateDiff() throws Exception { .havingPathEqualTo(DIFF_URI) .respond() .withStatus(202) - .withBody(MAPPER.writeValueAsString(new AsyncTask(DIFF_POLL_URI))); + .withBody(OBJECT_MAPPER.writeValueAsString(new AsyncTask(DIFF_POLL_URI))); onRequest() .havingMethodEqualTo("GET") .havingPathEqualTo(DIFF_POLL_URI) @@ -89,10 +91,10 @@ public void shouldUpdateModel() throws Exception { .havingPathEqualTo(STATUS_URI) .respond() .withStatus(202) - .withBody(MAPPER.writeValueAsString(new TaskStatus("RUNNING", STATUS_URI))) + .withBody(OBJECT_MAPPER.writeValueAsString(new TaskStatus("RUNNING", STATUS_URI))) .thenRespond() .withStatus(200) - .withBody(MAPPER.writeValueAsString(new TaskStatus("OK", STATUS_URI))) + .withBody(OBJECT_MAPPER.writeValueAsString(new TaskStatus("OK", STATUS_URI))) ; final ModelDiff diff = new ModelDiff(new UpdateScript(true, false, diff --git a/src/test/java/com/gooddata/notification/NotificationServiceIT.java b/src/test/java/com/gooddata/notification/NotificationServiceIT.java index b79a4ab4a..c80c6d58c 100644 --- a/src/test/java/com/gooddata/notification/NotificationServiceIT.java +++ b/src/test/java/com/gooddata/notification/NotificationServiceIT.java @@ -6,6 +6,7 @@ package com.gooddata.notification; import static com.gooddata.util.ResourceUtils.readFromResource; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static java.util.Collections.singletonMap; import static net.jadler.Jadler.onRequest; @@ -23,7 +24,7 @@ public class NotificationServiceIT extends AbstractGoodDataIT { @BeforeClass public void setUp() throws Exception { - project = MAPPER.readValue(readFromResource("/project/project.json"), Project.class); + project = readObjectFromResource("/project/project.json", Project.class); } @Test diff --git a/src/test/java/com/gooddata/project/ProjectServiceIT.java b/src/test/java/com/gooddata/project/ProjectServiceIT.java index e67ad1f50..e09400f81 100644 --- a/src/test/java/com/gooddata/project/ProjectServiceIT.java +++ b/src/test/java/com/gooddata/project/ProjectServiceIT.java @@ -11,12 +11,17 @@ import com.gooddata.gdc.AsyncTask; import com.gooddata.gdc.TaskStatus; import com.gooddata.gdc.UriResponse; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.util.Collection; +import java.util.List; +import java.util.Set; + import static com.gooddata.JsonMatchers.isJsonString; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static com.gooddata.util.ResourceUtils.readFromResource; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static net.jadler.Jadler.onRequest; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; @@ -24,14 +29,8 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; -import java.util.Collection; -import java.util.List; -import java.util.Set; - public class ProjectServiceIT extends AbstractGoodDataIT { - private static final ObjectMapper MAPPER = new ObjectMapper(); - private static final String PROJECT_ID = "PROJECT_ID"; private static final String PROJECT_URI = "/gdc/projects/" + PROJECT_ID; @@ -41,9 +40,9 @@ public class ProjectServiceIT extends AbstractGoodDataIT { @BeforeClass public void setUp() throws Exception { - loading = MAPPER.readValue(readFromResource("/project/project-loading.json"), Project.class); - enabled = MAPPER.readValue(readFromResource("/project/project.json"), Project.class); - deleted = MAPPER.readValue(readFromResource("/project/project-deleted.json"), Project.class); + loading = readObjectFromResource("/project/project-loading.json", Project.class); + enabled = readObjectFromResource("/project/project.json", Project.class); + deleted = readObjectFromResource("/project/project-deleted.json", Project.class); } @Test @@ -52,17 +51,17 @@ public void shouldCreateProject() throws Exception { .havingMethodEqualTo("POST") .havingPathEqualTo(Projects.URI) .respond() - .withBody(MAPPER.writeValueAsString(new UriResponse(PROJECT_URI))) + .withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse(PROJECT_URI))) .withStatus(202) ; onRequest() .havingMethodEqualTo("GET") .havingPathEqualTo(PROJECT_URI) .respond() - .withBody(MAPPER.writeValueAsString(loading)) + .withBody(OBJECT_MAPPER.writeValueAsString(loading)) .withStatus(202) .thenRespond() - .withBody(MAPPER.writeValueAsString(enabled)) + .withBody(OBJECT_MAPPER.writeValueAsString(enabled)) .withStatus(200) ; @@ -88,7 +87,7 @@ public void shouldFailWhenPollFails() throws Exception { .havingMethodEqualTo("POST") .havingPathEqualTo(Projects.URI) .respond() - .withBody(MAPPER.writeValueAsString(new UriResponse(PROJECT_URI))) + .withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse(PROJECT_URI))) .withStatus(202) ; onRequest() @@ -108,14 +107,14 @@ public void shouldFailWhenCantCreateProject() throws Exception { .havingMethodEqualTo("POST") .havingPathEqualTo(Projects.URI) .respond() - .withBody(MAPPER.writeValueAsString(new UriResponse(PROJECT_URI))) + .withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse(PROJECT_URI))) .withStatus(202) ; onRequest() .havingMethodEqualTo("GET") .havingPathEqualTo(PROJECT_URI) .respond() - .withBody(MAPPER.writeValueAsString(deleted)) + .withBody(OBJECT_MAPPER.writeValueAsString(deleted)) .withStatus(200) ; @@ -175,23 +174,23 @@ public void shouldValidateProject() throws Exception { .havingMethodEqualTo("POST") .havingBody(isJsonString("/project/project-validate.json")) .respond() - .withBody(MAPPER.writeValueAsString(new AsyncTask(task1Uri))) + .withBody(OBJECT_MAPPER.writeValueAsString(new AsyncTask(task1Uri))) .withStatus(201); onRequest() .havingPathEqualTo(task1Uri) .respond() - .withBody(MAPPER.writeValueAsString(new UriResponse(task2Uri))) + .withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse(task2Uri))) .withHeader("Location", task2Uri) .withStatus(303); onRequest() .havingPathEqualTo(task2Uri) .respond() - .withBody(MAPPER.writeValueAsString(new AsyncTask(task2Uri))) + .withBody(OBJECT_MAPPER.writeValueAsString(new AsyncTask(task2Uri))) .withStatus(202) .thenRespond() - .withBody(MAPPER.writeValueAsString(new UriResponse(resultUri))) + .withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse(resultUri))) .withHeader("Location", resultUri) .withStatus(303); @@ -223,21 +222,21 @@ public void shouldValidateProject2() throws Exception { .havingMethodEqualTo("POST") .havingBody(isJsonString("/project/project-validate.json")) .respond() - .withBody(MAPPER.writeValueAsString(new AsyncTask(task1Uri))) + .withBody(OBJECT_MAPPER.writeValueAsString(new AsyncTask(task1Uri))) .withStatus(201); onRequest() .havingPathEqualTo(task1Uri) .respond() - .withBody(MAPPER.writeValueAsString(new UriResponse(task2Uri))) + .withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse(task2Uri))) .withHeader("Location", task1Uri) .withStatus(303) .thenRespond() - .withBody(MAPPER.writeValueAsString(new TaskStatus("RUNNING", task2Uri))) + .withBody(OBJECT_MAPPER.writeValueAsString(new TaskStatus("RUNNING", task2Uri))) .withHeader("Location", task1Uri) .withStatus(202) .thenRespond() - .withBody(MAPPER.writeValueAsString(new UriResponse(resultUri))) + .withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse(resultUri))) .withHeader("Location", resultUri) .withStatus(303) ; diff --git a/src/test/java/com/gooddata/project/ProjectTemplateTest.java b/src/test/java/com/gooddata/project/ProjectTemplateTest.java index a770eec07..39495e1d4 100644 --- a/src/test/java/com/gooddata/project/ProjectTemplateTest.java +++ b/src/test/java/com/gooddata/project/ProjectTemplateTest.java @@ -5,9 +5,9 @@ */ package com.gooddata.project; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -17,8 +17,7 @@ public class ProjectTemplateTest { @Test public void shouldDeserialize() throws Exception { - final ProjectTemplate template = new ObjectMapper() - .readValue(getClass().getResource("/project/project-template.json"), ProjectTemplate.class); + final ProjectTemplate template = readObjectFromResource("/project/project-template.json", ProjectTemplate.class); assertThat(template, is(notNullValue())); assertThat(template.getUrl(), is("/projectTemplates/ZendeskAnalytics/11")); @@ -28,8 +27,7 @@ public void shouldDeserialize() throws Exception { @Test public void testToStringFormat() throws Exception { - final ProjectTemplate template = new ObjectMapper() - .readValue(getClass().getResource("/project/project-template.json"), ProjectTemplate.class); + final ProjectTemplate template = readObjectFromResource("/project/project-template.json", ProjectTemplate.class); assertThat(template.toString(), matchesPattern(ProjectTemplate.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/project/ProjectTemplatesTest.java b/src/test/java/com/gooddata/project/ProjectTemplatesTest.java index abd90ea41..9a8a34acc 100644 --- a/src/test/java/com/gooddata/project/ProjectTemplatesTest.java +++ b/src/test/java/com/gooddata/project/ProjectTemplatesTest.java @@ -5,9 +5,9 @@ */ package com.gooddata.project; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -17,8 +17,7 @@ public class ProjectTemplatesTest { @Test public void shouldDeserialize() throws Exception { - final ProjectTemplates templates = new ObjectMapper() - .readValue(getClass().getResource("/project/project-templates.json"), ProjectTemplates.class); + final ProjectTemplates templates = readObjectFromResource("/project/project-templates.json", ProjectTemplates.class); assertThat(templates, is(notNullValue())); assertThat(templates.getTemplatesInfo(), is(notNullValue())); diff --git a/src/test/java/com/gooddata/project/ProjectTest.java b/src/test/java/com/gooddata/project/ProjectTest.java index 7b57e6c8b..fc488c44a 100644 --- a/src/test/java/com/gooddata/project/ProjectTest.java +++ b/src/test/java/com/gooddata/project/ProjectTest.java @@ -5,12 +5,15 @@ */ package com.gooddata.project; -import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.testng.annotations.Test; -import static org.hamcrest.CoreMatchers.*; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.StringContains.containsString; import static org.hamcrest.core.StringStartsWith.startsWith; @@ -21,8 +24,7 @@ public class ProjectTest { @SuppressWarnings("deprecation") @Test public void testDeserialize() throws Exception { - final Project project = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/project/project.json"), Project.class); + final Project project = readObjectFromResource("/project/project.json", Project.class); assertThat(project, is(notNullValue())); assertThat(project.getAuthorizationToken(), is("AUTH_TOKEN")); @@ -79,7 +81,7 @@ public void testSerialize() throws Exception { final Project project = new Project("TITLE", "SUMMARY", "TOKEN"); project.setProjectTemplate("/projectTemplates/TEMPLATE"); project.setEnvironment(ProjectEnvironment.TESTING); - final String serializedProject = new ObjectMapper().writeValueAsString(project); + final String serializedProject = OBJECT_MAPPER.writeValueAsString(project); assertThat(serializedProject, startsWith("{\"project\"")); @@ -107,8 +109,7 @@ public void testSerialize() throws Exception { @Test public void testDeserializeVerticaProject() throws Exception { - final Project project = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/project/project-vertica.json"), Project.class); + final Project project = readObjectFromResource("/project/project-vertica.json", Project.class); assertThat(project, is(notNullValue())); assertThat(project.getDriver(), is("vertica")); @@ -121,7 +122,7 @@ public void testSerializeVerticaProject() throws Exception { final Project project = new Project("TITLE", "SUMMARY", "TOKEN"); project.setDriver(ProjectDriver.VERTICA); project.setProjectTemplate("/projectTemplates/TEMPLATE"); - final String serializedProject = new ObjectMapper().writeValueAsString(project); + final String serializedProject = OBJECT_MAPPER.writeValueAsString(project); assertThat(serializedProject, startsWith("{\"project\"")); assertThat(serializedProject, containsString("\"driver\":\"vertica\"")); diff --git a/src/test/java/com/gooddata/project/ProjectValidationResultItemTest.java b/src/test/java/com/gooddata/project/ProjectValidationResultItemTest.java index 301c00d7c..13451c5e0 100644 --- a/src/test/java/com/gooddata/project/ProjectValidationResultItemTest.java +++ b/src/test/java/com/gooddata/project/ProjectValidationResultItemTest.java @@ -5,9 +5,9 @@ */ package com.gooddata.project; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; @@ -16,8 +16,7 @@ public class ProjectValidationResultItemTest { @Test public void testDeserialize() throws Exception { - final ProjectValidationResultItem item = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/project/project-validationResultItem.json"), ProjectValidationResultItem.class); + final ProjectValidationResultItem item = readObjectFromResource("/project/project-validationResultItem.json", ProjectValidationResultItem.class); assertThat(item.getValidation(), is(ProjectValidationType.PDM_TRANSITIVITY)); assertThat(item.getLogs(), hasSize(3)); diff --git a/src/test/java/com/gooddata/project/ProjectValidationResultParamTest.java b/src/test/java/com/gooddata/project/ProjectValidationResultParamTest.java index 0a2480896..a64ae2f2f 100644 --- a/src/test/java/com/gooddata/project/ProjectValidationResultParamTest.java +++ b/src/test/java/com/gooddata/project/ProjectValidationResultParamTest.java @@ -11,6 +11,7 @@ import java.util.List; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; @@ -20,7 +21,7 @@ public class ProjectValidationResultParamTest { @Test public void testDeser() throws Exception { - final List result = new ObjectMapper() + final List result = OBJECT_MAPPER .readValue(getClass().getResourceAsStream("/project/project-validationResultParam.json"), new TypeReference>() { }); diff --git a/src/test/java/com/gooddata/project/ProjectValidationResultTest.java b/src/test/java/com/gooddata/project/ProjectValidationResultTest.java index 143f5ec99..ec80813cf 100644 --- a/src/test/java/com/gooddata/project/ProjectValidationResultTest.java +++ b/src/test/java/com/gooddata/project/ProjectValidationResultTest.java @@ -5,9 +5,9 @@ */ package com.gooddata.project; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; @@ -17,8 +17,7 @@ public class ProjectValidationResultTest { @Test public void testDeserialize() throws Exception { - final ProjectValidationResult log = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/project/project-validationResultLog.json"), ProjectValidationResult.class); + final ProjectValidationResult log = readObjectFromResource("/project/project-validationResultLog.json", ProjectValidationResult.class); assertThat(log.getCategory(), is("TRANSITIVITY")); assertThat(log.getLevel(), is("WARN")); @@ -29,8 +28,7 @@ public void testDeserialize() throws Exception { @Test public void testToStringFormat() throws Exception { - final ProjectValidationResult log = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/project/project-validationResultLog.json"), ProjectValidationResult.class); + final ProjectValidationResult log = readObjectFromResource("/project/project-validationResultLog.json", ProjectValidationResult.class); assertThat(log.toString(), matchesPattern(ProjectValidationResult.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/project/ProjectValidationResultsTest.java b/src/test/java/com/gooddata/project/ProjectValidationResultsTest.java index 44b3c0971..aff7ebb9d 100644 --- a/src/test/java/com/gooddata/project/ProjectValidationResultsTest.java +++ b/src/test/java/com/gooddata/project/ProjectValidationResultsTest.java @@ -5,9 +5,9 @@ */ package com.gooddata.project; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @@ -16,8 +16,7 @@ public class ProjectValidationResultsTest { @Test public void testDeserialize() throws Exception { - final ProjectValidationResults result = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/project/project-validationResults.json"), ProjectValidationResults.class); + final ProjectValidationResults result = readObjectFromResource("/project/project-validationResults.json", ProjectValidationResults.class); assertThat(result.isError(), is(true)); assertThat(result.isFatalError(), is(true)); diff --git a/src/test/java/com/gooddata/project/ProjectValidationTypeTest.java b/src/test/java/com/gooddata/project/ProjectValidationTypeTest.java index 1489a1fc8..08968de9a 100644 --- a/src/test/java/com/gooddata/project/ProjectValidationTypeTest.java +++ b/src/test/java/com/gooddata/project/ProjectValidationTypeTest.java @@ -5,9 +5,9 @@ */ package com.gooddata.project; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @@ -16,13 +16,13 @@ public class ProjectValidationTypeTest { @Test public void testSerialize() throws Exception { - final String myValidationType = new ObjectMapper().writeValueAsString(new ProjectValidationType("myValidationType")); + final String myValidationType = OBJECT_MAPPER.writeValueAsString(new ProjectValidationType("myValidationType")); assertThat(myValidationType, is("\"myValidationType\"")); } @Test public void testDeserialize() throws Exception { - final ProjectValidationType myValidationType = new ObjectMapper().readValue("\"myValidationType\"", ProjectValidationType.class); + final ProjectValidationType myValidationType = OBJECT_MAPPER.readValue("\"myValidationType\"", ProjectValidationType.class); assertThat(myValidationType, notNullValue()); assertThat(myValidationType.getValue(), is("myValidationType")); } diff --git a/src/test/java/com/gooddata/project/ProjectValidationsTest.java b/src/test/java/com/gooddata/project/ProjectValidationsTest.java index b30c09211..59edcb881 100644 --- a/src/test/java/com/gooddata/project/ProjectValidationsTest.java +++ b/src/test/java/com/gooddata/project/ProjectValidationsTest.java @@ -5,7 +5,6 @@ */ package com.gooddata.project; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; import static com.gooddata.JsonMatchers.serializesToJson; @@ -16,6 +15,7 @@ import static com.gooddata.project.ProjectValidationType.PDM_PK_FK_CONSISTENCY; import static com.gooddata.project.ProjectValidationType.PDM_TRANSITIVITY; import static com.gooddata.project.ProjectValidationType.PDM_VS_DWH; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.is; @@ -32,8 +32,7 @@ public void testSerialize() throws Exception { @Test public void testDeserialize() throws Exception { - final ProjectValidations validations = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/project/project-validationAvail.json"), ProjectValidations.class); + final ProjectValidations validations = readObjectFromResource("/project/project-validationAvail.json", ProjectValidations.class); assertThat(validations, is(notNullValue())); assertThat(validations.getValidations(), hasItems(PDM_VS_DWH, METRIC_FILTER, PDM_TRANSITIVITY, LDM, diff --git a/src/test/java/com/gooddata/project/RoleTest.java b/src/test/java/com/gooddata/project/RoleTest.java index 727ea63d8..ab57782a5 100644 --- a/src/test/java/com/gooddata/project/RoleTest.java +++ b/src/test/java/com/gooddata/project/RoleTest.java @@ -5,12 +5,11 @@ */ package com.gooddata.project; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; import java.io.IOException; -import java.io.InputStream; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; @@ -44,7 +43,6 @@ public void testEquals() throws IOException { } private Role readRole(final String suffix) throws java.io.IOException { - final InputStream stream = getClass().getResourceAsStream("/project/project-role" + suffix + ".json"); - return new ObjectMapper().readValue(stream, Role.class); + return readObjectFromResource("/project/project-role" + suffix + ".json", Role.class); } } \ No newline at end of file diff --git a/src/test/java/com/gooddata/project/RolesTest.java b/src/test/java/com/gooddata/project/RolesTest.java index 4d878869c..d63574f0f 100644 --- a/src/test/java/com/gooddata/project/RolesTest.java +++ b/src/test/java/com/gooddata/project/RolesTest.java @@ -5,11 +5,9 @@ */ package com.gooddata.project; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.notNullValue; @@ -20,8 +18,7 @@ public class RolesTest { @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/project/project-roles.json"); - final Roles roles = new ObjectMapper().readValue(stream, Roles.class); + final Roles roles = readObjectFromResource("/project/project-roles.json", Roles.class); assertThat(roles, notNullValue()); assertThat(roles.getRoles(), hasSize(2)); @@ -31,8 +28,7 @@ public void testDeserialization() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/project/project-roles.json"); - final Roles roles = new ObjectMapper().readValue(stream, Roles.class); + final Roles roles = readObjectFromResource("/project/project-roles.json", Roles.class); assertThat(roles.toString(), matchesPattern(Roles.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/project/UserTest.java b/src/test/java/com/gooddata/project/UserTest.java index 46f48beed..5edb8b6b6 100644 --- a/src/test/java/com/gooddata/project/UserTest.java +++ b/src/test/java/com/gooddata/project/UserTest.java @@ -5,11 +5,9 @@ */ package com.gooddata.project; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; @@ -20,8 +18,7 @@ public class UserTest { @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/project/project-user.json"); - final User user = new ObjectMapper().readValue(stream, User.class); + final User user = readObjectFromResource("/project/project-user.json", User.class); assertThat(user, notNullValue()); assertThat(user.getEmail(), is("ateam+ads-testing@gooddata.com")); @@ -35,8 +32,7 @@ public void testDeserialization() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/project/project-user.json"); - final User user = new ObjectMapper().readValue(stream, User.class); + final User user = readObjectFromResource("/project/project-user.json", User.class); assertThat(user.toString(), matchesPattern(User.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/project/UsersTest.java b/src/test/java/com/gooddata/project/UsersTest.java index fbd820df8..dcf74a6c3 100644 --- a/src/test/java/com/gooddata/project/UsersTest.java +++ b/src/test/java/com/gooddata/project/UsersTest.java @@ -5,11 +5,9 @@ */ package com.gooddata.project; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; - +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; @@ -21,8 +19,7 @@ public class UsersTest { @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/project/project-users.json"); - final Users users = new ObjectMapper().readValue(stream, Users.class); + final Users users = readObjectFromResource("/project/project-users.json", Users.class); assertThat(users, notNullValue()); assertThat(users, hasSize(1)); diff --git a/src/test/java/com/gooddata/report/ReportServiceIT.java b/src/test/java/com/gooddata/report/ReportServiceIT.java index 1498176c0..1b2b8768d 100644 --- a/src/test/java/com/gooddata/report/ReportServiceIT.java +++ b/src/test/java/com/gooddata/report/ReportServiceIT.java @@ -16,7 +16,9 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static com.gooddata.util.ResourceUtils.readFromResource; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static net.jadler.Jadler.onRequest; import static net.jadler.Jadler.port; import static org.hamcrest.Matchers.is; @@ -39,7 +41,7 @@ public void setUp() throws IOException { .havingMethodEqualTo("POST") .respond() .withStatus(202) - .withBody(MAPPER.writeValueAsString(new UriResponse("http://localhost:" + port() + URI))); + .withBody(OBJECT_MAPPER.writeValueAsString(new UriResponse("http://localhost:" + port() + URI))); onRequest() .havingPathEqualTo(URI) .havingMethodEqualTo("GET") @@ -53,7 +55,7 @@ public void setUp() throws IOException { @Test public void shouldExportReportDefinition() throws Exception { - final ReportDefinition rd = MAPPER.readValue(readFromResource("/md/report/gridReportDefinition.json"), ReportDefinition.class); + final ReportDefinition rd = readObjectFromResource("/md/report/gridReportDefinition.json", ReportDefinition.class); final ByteArrayOutputStream output = new ByteArrayOutputStream(); gd.getReportService().exportReport(rd, ReportExportFormat.CSV, output).get(); assertThat(output.toString(StandardCharsets.US_ASCII.name()), is(RESPONSE)); @@ -61,7 +63,7 @@ public void shouldExportReportDefinition() throws Exception { @Test public void shouldExportReport() throws Exception { - final Report rd = MAPPER.readValue(readFromResource("/md/report/report.json"), Report.class); + final Report rd = readObjectFromResource("/md/report/report.json", Report.class); final ByteArrayOutputStream output = new ByteArrayOutputStream(); gd.getReportService().exportReport(rd, ReportExportFormat.CSV, output).get(); assertThat(output.toString(StandardCharsets.US_ASCII.name()), is(RESPONSE)); @@ -75,7 +77,7 @@ public void shouldFail() throws Exception { .respond() .withStatus(400); - final Report rd = MAPPER.readValue(readFromResource("/md/report/report.json"), Report.class); + final Report rd = readObjectFromResource("/md/report/report.json", Report.class); final ByteArrayOutputStream output = new ByteArrayOutputStream(); gd.getReportService().exportReport(rd, ReportExportFormat.CSV, output).get(); } @@ -88,7 +90,7 @@ public void shouldFailNoData() throws Exception { .respond() .withStatus(204); - final Report rd = MAPPER.readValue(readFromResource("/md/report/report.json"), Report.class); + final Report rd = readObjectFromResource("/md/report/report.json", Report.class); final ByteArrayOutputStream output = new ByteArrayOutputStream(); gd.getReportService().exportReport(rd, ReportExportFormat.CSV, output).get(); } diff --git a/src/test/java/com/gooddata/util/BooleanDeserializerTest.java b/src/test/java/com/gooddata/util/BooleanDeserializerTest.java index f723e2345..4680a237d 100644 --- a/src/test/java/com/gooddata/util/BooleanDeserializerTest.java +++ b/src/test/java/com/gooddata/util/BooleanDeserializerTest.java @@ -9,54 +9,53 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class BooleanDeserializerTest { - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Test public void shouldDeserializeIntegerTrue() throws Exception { - final String json = MAPPER.writeValueAsString(new BooleanIntegerClass(true)); + final String json = OBJECT_MAPPER.writeValueAsString(new BooleanIntegerClass(true)); - final JsonNode node = MAPPER.readTree(json); + final JsonNode node = OBJECT_MAPPER.readTree(json); assertThat(node.path("foo").numberValue().intValue(), is(1)); - final BooleanIntegerClass moo = MAPPER.readValue(json, BooleanIntegerClass.class); + final BooleanIntegerClass moo = OBJECT_MAPPER.readValue(json, BooleanIntegerClass.class); assertThat(moo.isFoo(), is(true)); } @Test public void shouldDeserializeIntegerFalse() throws Exception { - final String json = MAPPER.writeValueAsString(new BooleanIntegerClass(false)); + final String json = OBJECT_MAPPER.writeValueAsString(new BooleanIntegerClass(false)); - final JsonNode node = MAPPER.readTree(json); + final JsonNode node = OBJECT_MAPPER.readTree(json); assertThat(node.path("foo").numberValue().intValue(), is(0)); - final BooleanIntegerClass moo = MAPPER.readValue(json, BooleanIntegerClass.class); + final BooleanIntegerClass moo = OBJECT_MAPPER.readValue(json, BooleanIntegerClass.class); assertThat(moo.isFoo(), is(false)); } @Test public void shouldDeserializeStringTrue() throws Exception { - final String json = MAPPER.writeValueAsString(new BooleanStringClass(true)); + final String json = OBJECT_MAPPER.writeValueAsString(new BooleanStringClass(true)); - final JsonNode node = MAPPER.readTree(json); + final JsonNode node = OBJECT_MAPPER.readTree(json); assertThat(node.path("foo").textValue(), is("1")); - final BooleanStringClass moo = MAPPER.readValue(json, BooleanStringClass.class); + final BooleanStringClass moo = OBJECT_MAPPER.readValue(json, BooleanStringClass.class); assertThat(moo.isFoo(), is(true)); } @Test public void shouldDeserializeStringFalse() throws Exception { - final String json = MAPPER.writeValueAsString(new BooleanStringClass(false)); + final String json = OBJECT_MAPPER.writeValueAsString(new BooleanStringClass(false)); - final JsonNode node = MAPPER.readTree(json); + final JsonNode node = OBJECT_MAPPER.readTree(json); assertThat(node.path("foo").textValue(), is("0")); - final BooleanStringClass moo = MAPPER.readValue(json, BooleanStringClass.class); + final BooleanStringClass moo = OBJECT_MAPPER.readValue(json, BooleanStringClass.class); assertThat(moo.isFoo(), is(false)); } diff --git a/src/test/java/com/gooddata/util/BooleanIntegerSerializerTest.java b/src/test/java/com/gooddata/util/BooleanIntegerSerializerTest.java index 7db295878..796f4a002 100644 --- a/src/test/java/com/gooddata/util/BooleanIntegerSerializerTest.java +++ b/src/test/java/com/gooddata/util/BooleanIntegerSerializerTest.java @@ -6,29 +6,27 @@ package com.gooddata.util; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class BooleanIntegerSerializerTest { - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Test public void shouldSerializeTrue() throws Exception { - final String json = MAPPER.writeValueAsString(new BooleanIntegerClass(true)); + final String json = OBJECT_MAPPER.writeValueAsString(new BooleanIntegerClass(true)); - final JsonNode node = MAPPER.readTree(json); + final JsonNode node = OBJECT_MAPPER.readTree(json); assertThat(node.path("foo").numberValue().intValue(), is(1)); } @Test public void shouldSerializeFalse() throws Exception { - final String json = MAPPER.writeValueAsString(new BooleanIntegerClass(false)); + final String json = OBJECT_MAPPER.writeValueAsString(new BooleanIntegerClass(false)); - final JsonNode node = MAPPER.readTree(json); + final JsonNode node = OBJECT_MAPPER.readTree(json); assertThat(node.path("foo").numberValue().intValue(), is(0)); } } \ No newline at end of file diff --git a/src/test/java/com/gooddata/util/BooleanStringSerializerTest.java b/src/test/java/com/gooddata/util/BooleanStringSerializerTest.java index c4a2ce598..32db34423 100644 --- a/src/test/java/com/gooddata/util/BooleanStringSerializerTest.java +++ b/src/test/java/com/gooddata/util/BooleanStringSerializerTest.java @@ -6,29 +6,27 @@ package com.gooddata.util; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class BooleanStringSerializerTest { - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Test public void shouldSerializeTrue() throws Exception { - final String json = MAPPER.writeValueAsString(new BooleanStringClass(true)); + final String json = OBJECT_MAPPER.writeValueAsString(new BooleanStringClass(true)); - final JsonNode node = MAPPER.readTree(json); + final JsonNode node = OBJECT_MAPPER.readTree(json); assertThat(node.path("foo").textValue(), is("1")); } @Test public void shouldSerializeFalse() throws Exception { - final String json = MAPPER.writeValueAsString(new BooleanStringClass(false)); + final String json = OBJECT_MAPPER.writeValueAsString(new BooleanStringClass(false)); - final JsonNode node = MAPPER.readTree(json); + final JsonNode node = OBJECT_MAPPER.readTree(json); assertThat(node.path("foo").textValue(), is("0")); } } \ No newline at end of file diff --git a/src/test/java/com/gooddata/util/GDDateDeserializerTest.java b/src/test/java/com/gooddata/util/GDDateDeserializerTest.java index 2119896f9..3a232cd06 100644 --- a/src/test/java/com/gooddata/util/GDDateDeserializerTest.java +++ b/src/test/java/com/gooddata/util/GDDateDeserializerTest.java @@ -10,21 +10,20 @@ import org.joda.time.LocalDate; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class GDDateDeserializerTest { - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Test public void testDeserialize() throws Exception { - final String json = MAPPER.writeValueAsString(new GDDateClass(new LocalDate(2012, 3, 20))); + final String json = OBJECT_MAPPER.writeValueAsString(new GDDateClass(new LocalDate(2012, 3, 20))); - final JsonNode node = MAPPER.readTree(json); + final JsonNode node = OBJECT_MAPPER.readTree(json); assertThat(node.path("date").textValue(), is("2012-03-20")); - final GDDateClass date = MAPPER.readValue(json, GDDateClass.class); + final GDDateClass date = OBJECT_MAPPER.readValue(json, GDDateClass.class); assertThat(date.getDate(), is(new LocalDate(2012, 3, 20))); } diff --git a/src/test/java/com/gooddata/util/GDDateSerializerTest.java b/src/test/java/com/gooddata/util/GDDateSerializerTest.java index 6abd62593..4a47c9b60 100644 --- a/src/test/java/com/gooddata/util/GDDateSerializerTest.java +++ b/src/test/java/com/gooddata/util/GDDateSerializerTest.java @@ -6,22 +6,20 @@ package com.gooddata.util; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.LocalDate; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class GDDateSerializerTest { - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Test public void testSerialize() throws Exception { final GDDateClass foo = new GDDateClass(new LocalDate(2012, 3, 20)); - final String json = MAPPER.writeValueAsString(foo); - final JsonNode node = MAPPER.readTree(json); + final String json = OBJECT_MAPPER.writeValueAsString(foo); + final JsonNode node = OBJECT_MAPPER.readTree(json); assertThat(node.path("date").textValue(), is("2012-03-20")); } diff --git a/src/test/java/com/gooddata/util/GDDateTimeDeserializerTest.java b/src/test/java/com/gooddata/util/GDDateTimeDeserializerTest.java index 4f57321e0..a5511d9a9 100644 --- a/src/test/java/com/gooddata/util/GDDateTimeDeserializerTest.java +++ b/src/test/java/com/gooddata/util/GDDateTimeDeserializerTest.java @@ -6,26 +6,24 @@ package com.gooddata.util; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class GDDateTimeDeserializerTest { - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Test public void testDeserialize() throws Exception { - final String json = MAPPER.writeValueAsString(new GDDateTimeClass(new DateTime(2012, 3, 20, 14, 31, 5, 3, DateTimeZone.UTC))); + final String json = OBJECT_MAPPER.writeValueAsString(new GDDateTimeClass(new DateTime(2012, 3, 20, 14, 31, 5, 3, DateTimeZone.UTC))); - final JsonNode node = MAPPER.readTree(json); + final JsonNode node = OBJECT_MAPPER.readTree(json); assertThat(node.path("date").textValue(), is("2012-03-20 14:31:05")); - final GDDateTimeClass date = MAPPER.readValue(json, GDDateTimeClass.class); + final GDDateTimeClass date = OBJECT_MAPPER.readValue(json, GDDateTimeClass.class); assertThat(date.getDate(), is(new DateTime(2012, 3, 20, 14, 31, 5, DateTimeZone.UTC))); } } diff --git a/src/test/java/com/gooddata/util/GDDateTimeSerializerTest.java b/src/test/java/com/gooddata/util/GDDateTimeSerializerTest.java index 6321c0689..0f90d2a60 100644 --- a/src/test/java/com/gooddata/util/GDDateTimeSerializerTest.java +++ b/src/test/java/com/gooddata/util/GDDateTimeSerializerTest.java @@ -6,23 +6,21 @@ package com.gooddata.util; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class GDDateTimeSerializerTest { - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Test public void testSerialize() throws Exception { final GDDateTimeClass foo = new GDDateTimeClass(new DateTime(2012, 3, 20, 14, 31, 5, 3, DateTimeZone.UTC)); - final String json = MAPPER.writeValueAsString(foo); - final JsonNode node = MAPPER.readTree(json); + final String json = OBJECT_MAPPER.writeValueAsString(foo); + final JsonNode node = OBJECT_MAPPER.readTree(json); assertThat(node.path("date").textValue(), is("2012-03-20 14:31:05")); } diff --git a/src/test/java/com/gooddata/util/ISODateTimeDeserializerTest.java b/src/test/java/com/gooddata/util/ISODateTimeDeserializerTest.java index 34af7035b..ac284909e 100644 --- a/src/test/java/com/gooddata/util/ISODateTimeDeserializerTest.java +++ b/src/test/java/com/gooddata/util/ISODateTimeDeserializerTest.java @@ -6,27 +6,25 @@ package com.gooddata.util; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class ISODateTimeDeserializerTest { - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Test public void testDeserialize() throws Exception { final DateTime expected = new DateTime(2012, 3, 20, 14, 31, 5, 3, DateTimeZone.UTC); - final String json = MAPPER.writeValueAsString(new ISODateClass(expected)); + final String json = OBJECT_MAPPER.writeValueAsString(new ISODateClass(expected)); - final JsonNode node = MAPPER.readTree(json); + final JsonNode node = OBJECT_MAPPER.readTree(json); assertThat(node.path("date").textValue(), is("2012-03-20T14:31:05.003Z")); - final ISODateClass moo = MAPPER.readValue(json, ISODateClass.class); + final ISODateClass moo = OBJECT_MAPPER.readValue(json, ISODateClass.class); assertThat(moo.getDate(), is(expected)); } } \ No newline at end of file diff --git a/src/test/java/com/gooddata/util/ISODateTimeSerializerTest.java b/src/test/java/com/gooddata/util/ISODateTimeSerializerTest.java index eb6ef0c72..58d055fc2 100644 --- a/src/test/java/com/gooddata/util/ISODateTimeSerializerTest.java +++ b/src/test/java/com/gooddata/util/ISODateTimeSerializerTest.java @@ -6,23 +6,21 @@ package com.gooddata.util; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class ISODateTimeSerializerTest { - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Test public void testSerialize() throws Exception { final ISODateClass foo = new ISODateClass(new DateTime(2012, 3, 20, 14, 31, 5, 3, DateTimeZone.UTC)); - final String json = MAPPER.writeValueAsString(foo); - final JsonNode node = MAPPER.readTree(json); + final String json = OBJECT_MAPPER.writeValueAsString(foo); + final JsonNode node = OBJECT_MAPPER.readTree(json); assertThat(node.path("date").textValue(), is("2012-03-20T14:31:05.003Z")); } diff --git a/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java b/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java index 3d4addcc1..f4450491a 100644 --- a/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java +++ b/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java @@ -5,7 +5,6 @@ */ package com.gooddata.util; -import com.fasterxml.jackson.databind.ObjectMapper; import com.gooddata.GoodData; import com.gooddata.GoodDataRestException; import org.springframework.http.HttpHeaders; @@ -18,6 +17,7 @@ import java.io.IOException; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; @@ -28,8 +28,6 @@ public class ResponseErrorHandlerTest { - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - private ResponseErrorHandler responseErrorHandler; @BeforeMethod diff --git a/src/test/java/com/gooddata/util/TagsDeserializerTest.java b/src/test/java/com/gooddata/util/TagsDeserializerTest.java index b18b4e78c..d797ff2e9 100644 --- a/src/test/java/com/gooddata/util/TagsDeserializerTest.java +++ b/src/test/java/com/gooddata/util/TagsDeserializerTest.java @@ -5,33 +5,33 @@ */ package com.gooddata.util; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; public class TagsDeserializerTest { - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Test public void shouldDeserializeOneToken() throws Exception { - final TagsTestClass tags = MAPPER.readValue("{\"tags\":\"TAG\"}", TagsTestClass.class); + final TagsTestClass tags = OBJECT_MAPPER.readValue("{\"tags\":\"TAG\"}", TagsTestClass.class); assertThat(tags.getTags(), hasSize(1)); assertThat(tags.getTags().iterator().next(), is("TAG")); } @Test public void shouldDeserializeTwoTokens() throws Exception { - final TagsTestClass tags = MAPPER.readValue("{\"tags\":\"TAG TAG2\"}", TagsTestClass.class); + final TagsTestClass tags = OBJECT_MAPPER.readValue("{\"tags\":\"TAG TAG2\"}", TagsTestClass.class); assertThat(tags.getTags(), hasSize(2)); assertThat(tags.getTags(), hasItems("TAG", "TAG2")); } @Test public void shouldDeserializeMultipleWhitespaceSeparatedTokens() throws Exception { - final TagsTestClass tags = MAPPER.readValue("{\"tags\":\"TAG TAG2\"}", TagsTestClass.class); + final TagsTestClass tags = OBJECT_MAPPER.readValue("{\"tags\":\"TAG TAG2\"}", TagsTestClass.class); assertThat(tags.getTags(), hasSize(2)); assertThat(tags.getTags(), hasItems("TAG", "TAG2")); } diff --git a/src/test/java/com/gooddata/util/TagsSerializerTest.java b/src/test/java/com/gooddata/util/TagsSerializerTest.java index 24e42f15d..047955bf5 100644 --- a/src/test/java/com/gooddata/util/TagsSerializerTest.java +++ b/src/test/java/com/gooddata/util/TagsSerializerTest.java @@ -5,12 +5,12 @@ */ package com.gooddata.util; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; import java.util.Collections; import java.util.LinkedHashSet; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static java.util.Arrays.asList; import static java.util.Collections.singleton; import static org.hamcrest.MatcherAssert.assertThat; @@ -18,26 +18,24 @@ public class TagsSerializerTest { - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Test public void shouldSerializeOneTag() throws Exception { final TagsTestClass tags = new TagsTestClass(singleton("TAG")); - final String jsonString = MAPPER.writeValueAsString(tags); + final String jsonString = OBJECT_MAPPER.writeValueAsString(tags); assertThat(jsonString, is("{\"tags\":\"TAG\"}")); } @Test public void shouldSerializeZeroTags() throws Exception { final TagsTestClass tags = new TagsTestClass(Collections.emptySet()); - final String jsonString = MAPPER.writeValueAsString(tags); + final String jsonString = OBJECT_MAPPER.writeValueAsString(tags); assertThat(jsonString, is("{\"tags\":\"\"}")); } @Test public void shouldSerializeTwoTags() throws Exception { final TagsTestClass tags = new TagsTestClass(new LinkedHashSet<>(asList("TAG", "TAG2"))); - final String jsonString = MAPPER.writeValueAsString(tags); + final String jsonString = OBJECT_MAPPER.writeValueAsString(tags); assertThat(jsonString, is("{\"tags\":\"TAG TAG2\"}")); } } \ No newline at end of file diff --git a/src/test/java/com/gooddata/warehouse/WarehouseSchemaTest.java b/src/test/java/com/gooddata/warehouse/WarehouseSchemaTest.java index e8ea543ad..4e76f6d4d 100644 --- a/src/test/java/com/gooddata/warehouse/WarehouseSchemaTest.java +++ b/src/test/java/com/gooddata/warehouse/WarehouseSchemaTest.java @@ -5,18 +5,17 @@ */ package com.gooddata.warehouse; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.text.MatchesPattern.matchesPattern; - -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; import java.util.LinkedHashMap; import java.util.Map; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.text.MatchesPattern.matchesPattern; + public class WarehouseSchemaTest { private static final String NAME = "default"; @@ -32,8 +31,7 @@ public class WarehouseSchemaTest { @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/warehouse/schema.json"); - final WarehouseSchema warehouseSchema = new ObjectMapper().readValue(stream, WarehouseSchema.class); + final WarehouseSchema warehouseSchema = readObjectFromResource("/warehouse/schema.json", WarehouseSchema.class); assertThat(warehouseSchema.getName(), is(NAME)); assertThat(warehouseSchema.getDescription(), is(DESCRIPTION)); @@ -42,8 +40,7 @@ public void testDeserialization() throws Exception { @Test public void testToStringFormat() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/warehouse/schema.json"); - final WarehouseSchema warehouseSchema = new ObjectMapper().readValue(stream, WarehouseSchema.class); + final WarehouseSchema warehouseSchema = readObjectFromResource("/warehouse/schema.json", WarehouseSchema.class); assertThat(warehouseSchema.toString(), matchesPattern(WarehouseSchema.class.getSimpleName() + "\\[.*\\]")); } diff --git a/src/test/java/com/gooddata/warehouse/WarehouseServiceIT.java b/src/test/java/com/gooddata/warehouse/WarehouseServiceIT.java index a7fb6dd4c..b6e3286cc 100644 --- a/src/test/java/com/gooddata/warehouse/WarehouseServiceIT.java +++ b/src/test/java/com/gooddata/warehouse/WarehouseServiceIT.java @@ -18,7 +18,9 @@ import java.io.IOException; import java.util.Collections; +import static com.gooddata.util.ResourceUtils.OBJECT_MAPPER; import static com.gooddata.util.ResourceUtils.readFromResource; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static net.jadler.Jadler.onRequest; import static net.jadler.Jadler.verifyThatRequest; import static org.hamcrest.MatcherAssert.assertThat; @@ -52,10 +54,10 @@ public class WarehouseServiceIT extends AbstractGoodDataIT { @BeforeClass public void setUp() throws Exception { - pollingTask = MAPPER.readValue(readFromResource(TASK_POLL), WarehouseTask.class); - finishedTask = MAPPER.readValue(readFromResource(TASK_DONE), WarehouseTask.class); - warehouse = MAPPER.readValue(readFromResource(WAREHOUSE), Warehouse.class); - warehouseSchema = MAPPER.readValue(readFromResource(WAREHOUSE_SCHEMA), WarehouseSchema.class); + pollingTask = readObjectFromResource(TASK_POLL, WarehouseTask.class); + finishedTask = readObjectFromResource(TASK_DONE, WarehouseTask.class); + warehouse = readObjectFromResource(WAREHOUSE, Warehouse.class); + warehouseSchema = readObjectFromResource(WAREHOUSE_SCHEMA, WarehouseSchema.class); } @Test @@ -151,7 +153,7 @@ public void shouldUpdateWarehouse() throws Exception { final String updatedTitle = "UPDATED_TITLE"; - final Warehouse toUpdate = MAPPER.readValue(readFromResource(WAREHOUSE), Warehouse.class); + final Warehouse toUpdate = readObjectFromResource(WAREHOUSE, Warehouse.class); toUpdate.setTitle(updatedTitle); onRequest() @@ -163,7 +165,7 @@ public void shouldUpdateWarehouse() throws Exception { .havingMethodEqualTo("GET") .havingPathEqualTo(warehouse.getUri()) .respond() - .withBody(MAPPER.writeValueAsString(toUpdate)) + .withBody(OBJECT_MAPPER.writeValueAsString(toUpdate)) .withStatus(200); final Warehouse updated = gd.getWarehouseService().updateWarehouse(toUpdate); @@ -177,7 +179,7 @@ public void shouldUpdateWarehouse() throws Exception { @Override public boolean matches(Object o) { try { - Warehouse instance = MAPPER.readValue((String) o, Warehouse.class); + Warehouse instance = OBJECT_MAPPER.readValue((String) o, Warehouse.class); return updatedTitle.equals(instance.getTitle()); } catch (IOException e) { return false; diff --git a/src/test/java/com/gooddata/warehouse/WarehouseTaskTest.java b/src/test/java/com/gooddata/warehouse/WarehouseTaskTest.java index 5bdfdf3b4..7e321e307 100644 --- a/src/test/java/com/gooddata/warehouse/WarehouseTaskTest.java +++ b/src/test/java/com/gooddata/warehouse/WarehouseTaskTest.java @@ -5,20 +5,18 @@ */ package com.gooddata.warehouse; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.MatcherAssert.*; - -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; -import java.io.InputStream; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; public class WarehouseTaskTest { @SuppressWarnings("deprecation") @Test public void testDeserializePoll() throws Exception { - final WarehouseTask warehouseTask = deserialize("/warehouse/warehouseTask-poll.json"); + final WarehouseTask warehouseTask = readObjectFromResource("/warehouse/warehouseTask-poll.json", WarehouseTask.class); assertThat(warehouseTask.getPollLink(), is("/gdc/datawarehouse/executions/executionId")); assertThat(warehouseTask.getPollUri(), is("/gdc/datawarehouse/executions/executionId")); } @@ -26,13 +24,9 @@ public void testDeserializePoll() throws Exception { @SuppressWarnings("deprecation") @Test public void testDeserializeInstance() throws Exception { - final WarehouseTask warehouseTask = deserialize("/warehouse/warehouseTask-finished.json"); + final WarehouseTask warehouseTask = readObjectFromResource("/warehouse/warehouseTask-finished.json", WarehouseTask.class); assertThat(warehouseTask.getWarehouseLink(), is("/gdc/datawarehouse/instances/instanceId")); assertThat(warehouseTask.getWarehouseUri(), is("/gdc/datawarehouse/instances/instanceId")); } - private WarehouseTask deserialize(String path) throws Exception { - final InputStream stream = getClass().getResourceAsStream(path); - return new ObjectMapper().readValue(stream, WarehouseTask.class); - } } \ No newline at end of file diff --git a/src/test/java/com/gooddata/warehouse/WarehouseTest.java b/src/test/java/com/gooddata/warehouse/WarehouseTest.java index f16042035..8e1b3a770 100644 --- a/src/test/java/com/gooddata/warehouse/WarehouseTest.java +++ b/src/test/java/com/gooddata/warehouse/WarehouseTest.java @@ -6,6 +6,7 @@ package com.gooddata.warehouse; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.core.Is.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -68,8 +69,7 @@ public void testSerializationWithLicense() throws Exception { @Test public void testDeserialization() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/warehouse/warehouse.json"); - final Warehouse warehouse = new ObjectMapper().readValue(stream, Warehouse.class); + final Warehouse warehouse = readObjectFromResource("/warehouse/warehouse.json", Warehouse.class); assertThat(warehouse.getTitle(), is(TITLE)); assertThat(warehouse.getDescription(), is(DESCRIPTION)); @@ -86,8 +86,7 @@ public void testDeserialization() throws Exception { @Test public void testDeserializationWithLicense() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/warehouse/warehouse-withLicense.json"); - final Warehouse warehouse = new ObjectMapper().readValue(stream, Warehouse.class); + final Warehouse warehouse = readObjectFromResource("/warehouse/warehouse-withLicense.json", Warehouse.class); assertThat(warehouse.getTitle(), is(TITLE)); assertThat(warehouse.getDescription(), is(DESCRIPTION)); @@ -105,8 +104,7 @@ public void testDeserializationWithLicense() throws Exception { @Test public void testDeserializationWithNullToken() throws Exception { - final InputStream stream = getClass().getResourceAsStream("/warehouse/warehouse-null-token.json"); - final Warehouse warehouse = new ObjectMapper().readValue(stream, Warehouse.class); + final Warehouse warehouse = readObjectFromResource("/warehouse/warehouse-null-token.json", Warehouse.class); assertThat(warehouse.getTitle(), is(TITLE)); assertThat(warehouse.getDescription(), is(DESCRIPTION)); diff --git a/src/test/java/com/gooddata/warehouse/WarehouseUserTest.java b/src/test/java/com/gooddata/warehouse/WarehouseUserTest.java index a4555edd3..536fdbf32 100644 --- a/src/test/java/com/gooddata/warehouse/WarehouseUserTest.java +++ b/src/test/java/com/gooddata/warehouse/WarehouseUserTest.java @@ -5,13 +5,13 @@ */ package com.gooddata.warehouse; -import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.annotations.Test; import java.util.LinkedHashMap; import java.util.Map; import static com.gooddata.JsonMatchers.serializesToJson; +import static com.gooddata.util.ResourceUtils.readObjectFromResource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.text.MatchesPattern.matchesPattern; @@ -47,8 +47,7 @@ public void testCompleteSerialization() throws Exception { @Test public void testDeserialization() throws Exception { - final WarehouseUser user = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/warehouse/user.json"), WarehouseUser.class); + final WarehouseUser user = readObjectFromResource("/warehouse/user.json", WarehouseUser.class); assertThat(user.getRole(), is(ROLE)); assertThat(user.getProfile(), is(PROFILE)); @@ -65,8 +64,7 @@ public void testGetId() throws Exception { @Test public void testToStringFormat() throws Exception { - final WarehouseUser user = new ObjectMapper() - .readValue(getClass().getResourceAsStream("/warehouse/user.json"), WarehouseUser.class); + final WarehouseUser user = readObjectFromResource("/warehouse/user.json", WarehouseUser.class); assertThat(user.toString(), matchesPattern(WarehouseUser.class.getSimpleName() + "\\[.*\\]")); } From b0224182dfcdb827d61b4153fccf168adbb3df7f Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Thu, 25 May 2017 15:53:37 +0200 Subject: [PATCH 031/702] add: getSanitizedLimit(max) --- .../java/com/gooddata/collections/PageRequest.java | 14 ++++++++++++++ .../com/gooddata/collections/PageRequestTest.java | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/com/gooddata/collections/PageRequest.java b/src/main/java/com/gooddata/collections/PageRequest.java index 64cf2fd80..e97743dbd 100644 --- a/src/main/java/com/gooddata/collections/PageRequest.java +++ b/src/main/java/com/gooddata/collections/PageRequest.java @@ -70,10 +70,24 @@ public int getLimit() { return limit; } + /** + * Return the limit value or the {@link #DEFAULT_LIMIT} if the limit is lower than or equal to zero + * @return sanitized limit + */ public int getSanitizedLimit() { return limit > 0 ? limit : DEFAULT_LIMIT; } + /** + * Return the {@link #getSanitizedLimit()} if lower than the given maximum or the maximum value + * @param max maximum value + * @return sanitized limit + */ + public int getSanitizedLimit(final int max) { + final int limit = getSanitizedLimit(); + return limit < max ? limit : max; + } + public void setLimit(final int limit) { this.limit = limit; } diff --git a/src/test/java/com/gooddata/collections/PageRequestTest.java b/src/test/java/com/gooddata/collections/PageRequestTest.java index 4d59a2139..564485d47 100644 --- a/src/test/java/com/gooddata/collections/PageRequestTest.java +++ b/src/test/java/com/gooddata/collections/PageRequestTest.java @@ -76,4 +76,16 @@ public void testGetSanitizedLimit() throws Exception { pageRequest.setLimit(-2); assertThat(pageRequest.getSanitizedLimit(), is(DEFAULT_LIMIT)); } + + @Test + public void shouldReturnDefaultForZero() throws Exception { + final PageRequest pageRequest = new PageRequest(0); + assertThat(pageRequest.getSanitizedLimit(), is(DEFAULT_LIMIT)); + } + + @Test + public void shouldReturnMaxForSanitizedLimit() throws Exception { + final PageRequest pageRequest = new PageRequest(100); + assertThat(pageRequest.getSanitizedLimit(10), is(10)); + } } From a72ee494dfd4fdacf0625a94782fb6a5959d7d85 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Thu, 25 May 2017 16:43:50 +0200 Subject: [PATCH 032/702] refactor and remove duplicated code --- .../com/gooddata/dataset/DatasetService.java | 38 ++++++++----------- .../gooddata/dataset/DatasetServiceTest.java | 4 +- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/gooddata/dataset/DatasetService.java b/src/main/java/com/gooddata/dataset/DatasetService.java index eef92c864..1ee248e10 100644 --- a/src/main/java/com/gooddata/dataset/DatasetService.java +++ b/src/main/java/com/gooddata/dataset/DatasetService.java @@ -8,11 +8,14 @@ import com.gooddata.AbstractPollHandler; import com.gooddata.AbstractService; import com.gooddata.FutureResult; -import com.gooddata.PollResult; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; -import com.gooddata.gdc.*; +import com.gooddata.PollResult; import com.gooddata.gdc.AboutLinks.Link; +import com.gooddata.gdc.DataStoreException; +import com.gooddata.gdc.DataStoreService; +import com.gooddata.gdc.TaskStatus; +import com.gooddata.gdc.UriResponse; import com.gooddata.project.Project; import org.apache.commons.lang3.RandomStringUtils; import org.springframework.http.client.ClientHttpResponse; @@ -25,7 +28,10 @@ import java.net.URI; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; import java.util.stream.Collectors; import static com.gooddata.util.Validate.notEmpty; @@ -94,19 +100,9 @@ public FutureResult loadDataset(final Project project, final DatasetManife notNull(project, "project"); notNull(dataset, "dataset"); notNull(manifest, "manifest"); - final Path dirPath = Paths.get("/", project.getId() + "_" + RandomStringUtils.randomAlphabetic(3), "/"); - try { - dataStoreService.upload(dirPath.resolve(manifest.getFile()).toString(), dataset); - final String manifestJson = mapper.writeValueAsString(manifest); - final ByteArrayInputStream inputStream = new ByteArrayInputStream(manifestJson.getBytes(UTF_8)); - dataStoreService.upload(dirPath.resolve(MANIFEST_FILE_NAME).toString(), inputStream); + manifest.setSource(dataset); - return pullLoad(project, dirPath, manifest.getDataSet()); - } catch (IOException e) { - throw new DatasetException("Unable to serialize manifest", manifest.getDataSet(), e); - } catch (DataStoreException | GoodDataRestException | RestClientException e) { - throw new DatasetException("Unable to load", manifest.getDataSet(), e); - } + return loadDatasets(project, manifest); } /** @@ -156,7 +152,7 @@ public FutureResult loadDatasets(final Project project, final Collection datasets) } } - private FutureResult pullLoad(Project project, final Path dirPath, final String dataset) { - return pullLoad(project, dirPath, singletonList(dataset)); - } - - private FutureResult pullLoad(Project project, final Path dirPath, final Collection datasets) { + private FutureResult pullLoad(Project project, final String dirPath, final Collection datasets) { final PullTask pullTask = restTemplate - .postForObject(Pull.URI, new Pull(dirPath.toString()), PullTask.class, project.getId()); + .postForObject(Pull.URI, new Pull(dirPath), PullTask.class, project.getId()); return new PollResult<>(this, new AbstractPollHandler(pullTask.getPollUri(), TaskStatus.class, Void.class) { @Override @@ -207,7 +199,7 @@ public void handlePollException(final GoodDataRestException e) { @Override protected void onFinish() { try { - dataStoreService.delete(dirPath.toString()); + dataStoreService.delete(dirPath); } catch (DataStoreException ignored) { // todo log? } diff --git a/src/test/java/com/gooddata/dataset/DatasetServiceTest.java b/src/test/java/com/gooddata/dataset/DatasetServiceTest.java index 65b032bbd..006f0dca6 100644 --- a/src/test/java/com/gooddata/dataset/DatasetServiceTest.java +++ b/src/test/java/com/gooddata/dataset/DatasetServiceTest.java @@ -128,7 +128,9 @@ public void testLoadDatasetWithNullDataset() throws Exception { public void testLoadDatasetWhenUploadFails() throws Exception { doThrow(DataStoreException.class).when(dataStoreService).upload(anyString(), eq(stream)); when(manifest.getFile()).thenReturn(""); - service.loadDataset(project, manifest, stream); + when(manifest.getSource()).thenReturn(stream); + when(manifest.getDataSet()).thenReturn(DATASET_ID); + service.loadDatasets(project, manifest); } @Test(expectedExceptions = IllegalArgumentException.class) From ad71485b81d696986737eeda8f097b0673224a8b Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Thu, 25 May 2017 17:13:34 +0200 Subject: [PATCH 033/702] use simple string to resolve windows issue #456 --- .../java/com/gooddata/dataset/DatasetService.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/gooddata/dataset/DatasetService.java b/src/main/java/com/gooddata/dataset/DatasetService.java index 1ee248e10..357a1e19a 100644 --- a/src/main/java/com/gooddata/dataset/DatasetService.java +++ b/src/main/java/com/gooddata/dataset/DatasetService.java @@ -26,8 +26,6 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -40,7 +38,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.springframework.util.StringUtils.isEmpty; /** @@ -142,17 +139,17 @@ public FutureResult loadDatasets(final Project project, final Collection datasetsNames = new ArrayList<>(datasets.size()); try { - final Path dirPath = Paths.get("/", project.getId() + "_" + RandomStringUtils.randomAlphabetic(3), "/"); + final String dirPath = "/" + project.getId() + "_" + RandomStringUtils.randomAlphabetic(3) + "/"; for (DatasetManifest datasetManifest : datasets) { datasetsNames.add(datasetManifest.getDataSet()); - dataStoreService.upload(dirPath.resolve(datasetManifest.getFile()).toString(), datasetManifest.getSource()); + dataStoreService.upload(dirPath + datasetManifest.getFile(), datasetManifest.getSource()); } final String manifestJson = mapper.writeValueAsString(new DatasetManifests(datasets)); final ByteArrayInputStream inputStream = new ByteArrayInputStream(manifestJson.getBytes(UTF_8)); - dataStoreService.upload(dirPath.resolve(MANIFEST_FILE_NAME).toString(), inputStream); + dataStoreService.upload(dirPath + MANIFEST_FILE_NAME, inputStream); - return pullLoad(project, dirPath.toString(), datasetsNames); + return pullLoad(project, dirPath, datasetsNames); } catch (IOException e) { throw new DatasetException("Unable to serialize manifest", datasetsNames, e); } catch (DataStoreException | GoodDataRestException | RestClientException e) { From 7dcd2fa99fb55f90601ea579b4fcfde5a93a7d20 Mon Sep 17 00:00:00 2001 From: Jiri Mikulasek Date: Tue, 23 May 2017 19:33:23 +0200 Subject: [PATCH 034/702] introduce support for projectTemplates ProjectTemplateService enables to get for list of templates or particular template by URI. --- src/main/java/com/gooddata/GoodData.java | 17 +- .../ProjectTemplateService.java | 75 +++++++ .../gooddata/projecttemplate/Template.java | 189 ++++++++++++++++++ .../gooddata/projecttemplate/Templates.java | 32 +++ .../ProjectTemplateServiceIT.java | 79 ++++++++ .../ProjectTemplateServiceTest.java | 74 +++++++ .../projecttemplate/TemplateTest.java | 44 ++++ .../resources/projecttemplate/template.json | 26 +++ .../resources/projecttemplate/templates.json | 47 +++++ 9 files changed, 581 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/gooddata/projecttemplate/ProjectTemplateService.java create mode 100644 src/main/java/com/gooddata/projecttemplate/Template.java create mode 100644 src/main/java/com/gooddata/projecttemplate/Templates.java create mode 100644 src/test/java/com/gooddata/projecttemplate/ProjectTemplateServiceIT.java create mode 100644 src/test/java/com/gooddata/projecttemplate/ProjectTemplateServiceTest.java create mode 100644 src/test/java/com/gooddata/projecttemplate/TemplateTest.java create mode 100644 src/test/resources/projecttemplate/template.json create mode 100644 src/test/resources/projecttemplate/templates.json diff --git a/src/main/java/com/gooddata/GoodData.java b/src/main/java/com/gooddata/GoodData.java index 7d872bbbe..46828d62e 100644 --- a/src/main/java/com/gooddata/GoodData.java +++ b/src/main/java/com/gooddata/GoodData.java @@ -12,6 +12,7 @@ import com.gooddata.featureflag.FeatureFlagService; import com.gooddata.md.maintenance.ExportImportService; import com.gooddata.notification.NotificationService; +import com.gooddata.projecttemplate.ProjectTemplateService; import com.gooddata.util.ResponseErrorHandler; import com.gooddata.authentication.LoginPasswordAuthentication; import com.gooddata.warehouse.WarehouseService; @@ -81,6 +82,7 @@ public class GoodData { private final ExportImportService exportImportService; private final FeatureFlagService featureFlagService; private final OutputStageService outputStageService; + private final ProjectTemplateService projectTemplateService; /** * Create instance configured to communicate with GoodData Platform under user with given credentials. @@ -211,8 +213,9 @@ protected GoodData(GoodDataEndpoint endpoint, Authentication authentication, Goo connectorService = new ConnectorService(getRestTemplate(), projectService); notificationService = new NotificationService(getRestTemplate()); exportImportService = new ExportImportService(getRestTemplate()); - featureFlagService = new FeatureFlagService(restTemplate); - outputStageService = new OutputStageService(restTemplate); + featureFlagService = new FeatureFlagService(getRestTemplate()); + outputStageService = new OutputStageService(getRestTemplate()); + projectTemplateService = new ProjectTemplateService(getRestTemplate()); } static RestTemplate createRestTemplate(GoodDataEndpoint endpoint, HttpClient httpClient) { @@ -448,4 +451,14 @@ public FeatureFlagService getFeatureFlagService() { public OutputStageService getOutputStageService() { return outputStageService; } + + /** + * Get initialized service for project templates + * + * @return initialized service for project templates + */ + @Bean + public ProjectTemplateService getProjectTemplateService() { + return projectTemplateService; + } } diff --git a/src/main/java/com/gooddata/projecttemplate/ProjectTemplateService.java b/src/main/java/com/gooddata/projecttemplate/ProjectTemplateService.java new file mode 100644 index 000000000..53c59a622 --- /dev/null +++ b/src/main/java/com/gooddata/projecttemplate/ProjectTemplateService.java @@ -0,0 +1,75 @@ +/** + * Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved. + * This source code is licensed under the BSD-style license found in the + * LICENSE.txt file in the root directory of this source tree. + */ +package com.gooddata.projecttemplate; + +import com.gooddata.AbstractService; +import com.gooddata.GoodDataException; +import com.gooddata.GoodDataRestException; +import com.gooddata.dataset.DatasetManifest; +import com.gooddata.util.Validate; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; + +import java.util.Collection; +import java.util.stream.Collectors; + +/** + * Service enabling access to project templates, under /projectTemplates/... + */ +public class ProjectTemplateService extends AbstractService { + + /** + * Sets RESTful HTTP Spring template. Should be called from constructor of concrete service extending + * this abstract one. + * + * @param restTemplate RESTful HTTP Spring template + */ + public ProjectTemplateService(RestTemplate restTemplate) { + super(restTemplate); + } + + /** + * List of all projects' templates + * @return list of templates + */ + public Collection