From f53c32dc2bef579a4d7b9e9f819db7dd6dbe2d65 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Wed, 27 Sep 2017 16:55:14 +0200 Subject: [PATCH 001/582] [maven-release-plugin] prepare release gooddata-java-2.16.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c606a168a..8805300fb 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 gooddata-java - 2.15.2-SNAPSHOT + 2.16.0 ${project.artifactId} GoodData Java SDK https://github.com/gooddata/gooddata-java @@ -24,7 +24,7 @@ git@github.com:gooddata/gooddata-java.git scm:git:git@github.com:gooddata/gooddata-java.git scm:git:${basedir} - HEAD + gooddata-java-2.16.0 From a6830a3ae592c592d435b2c81c99cc2356d81448 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Wed, 27 Sep 2017 16:55:14 +0200 Subject: [PATCH 002/582] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8805300fb..43822207f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 gooddata-java - 2.16.0 + 2.16.1-SNAPSHOT ${project.artifactId} GoodData Java SDK https://github.com/gooddata/gooddata-java @@ -24,7 +24,7 @@ git@github.com:gooddata/gooddata-java.git scm:git:git@github.com:gooddata/gooddata-java.git scm:git:${basedir} - gooddata-java-2.16.0 + HEAD From a0ddca28bbea22a201833aa1a046aed18db9c6cf Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Wed, 27 Sep 2017 17:05:32 +0200 Subject: [PATCH 003/582] bump version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c01da78f..5a821e6f9 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.15.1 + 2.16.0 ``` See [releases page](https://github.com/gooddata/gooddata-java/releases) for information about versions and notable changes, From 7a2dd5afe914fe31cbd5e47cc956f3a864375422 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Thu, 28 Sep 2017 23:39:10 +0200 Subject: [PATCH 004/582] pronounce test starting Spring container as integration test --- ...aBeansAsServicesTest.java => GoodDataBeansAsServicesIT.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/test/java/com/gooddata/spring/{GoodDataBeansAsServicesTest.java => GoodDataBeansAsServicesIT.java} (97%) diff --git a/src/test/java/com/gooddata/spring/GoodDataBeansAsServicesTest.java b/src/test/java/com/gooddata/spring/GoodDataBeansAsServicesIT.java similarity index 97% rename from src/test/java/com/gooddata/spring/GoodDataBeansAsServicesTest.java rename to src/test/java/com/gooddata/spring/GoodDataBeansAsServicesIT.java index 9355f06fc..0e7e84808 100644 --- a/src/test/java/com/gooddata/spring/GoodDataBeansAsServicesTest.java +++ b/src/test/java/com/gooddata/spring/GoodDataBeansAsServicesIT.java @@ -25,7 +25,7 @@ import static org.testng.Assert.*; -public class GoodDataBeansAsServicesTest { +public class GoodDataBeansAsServicesIT { @Test public void servicesRegisteredFromXmlUsingAnnotationConfig() throws Exception { From 44f7a4e31d6db3a41c9b6fe9c5a7c1484a2be0a2 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Thu, 28 Sep 2017 23:05:26 +0200 Subject: [PATCH 005/582] autoclose ZipInputStream --- src/main/java/com/gooddata/util/ZipHelper.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gooddata/util/ZipHelper.java b/src/main/java/com/gooddata/util/ZipHelper.java index 7d8411024..e85e557c4 100644 --- a/src/main/java/com/gooddata/util/ZipHelper.java +++ b/src/main/java/com/gooddata/util/ZipHelper.java @@ -85,8 +85,9 @@ private static void zipFile(Path rootPath, File file, ZipOutputStream zos) throw } private static boolean isZipped(File file) { - try (final InputStream stream = Files.newInputStream(file.toPath())) { - return new ZipInputStream(stream).getNextEntry() != null; + try (final InputStream stream = Files.newInputStream(file.toPath()); + final ZipInputStream zipStream = new ZipInputStream(stream)) { + return zipStream.getNextEntry() != null; } catch (IOException e) { return false; } From af1346eb9572a55b20cb8cc6ef8ab6ece3159f79 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Thu, 28 Sep 2017 23:21:26 +0200 Subject: [PATCH 006/582] remove wrongly implemented equals method without hashCode counterpart --- .../com/gooddata/warehouse/WarehouseS3Credentials.java | 10 ---------- .../gooddata/warehouse/WarehouseS3CredentialsTest.java | 5 ++++- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/gooddata/warehouse/WarehouseS3Credentials.java b/src/main/java/com/gooddata/warehouse/WarehouseS3Credentials.java index 872e9ca1f..bede8aa5e 100644 --- a/src/main/java/com/gooddata/warehouse/WarehouseS3Credentials.java +++ b/src/main/java/com/gooddata/warehouse/WarehouseS3Credentials.java @@ -177,16 +177,6 @@ public String getUpdatedBy() { return updatedBy; } - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (!(o instanceof Links)) return false; - - final Links links = (Links) o; - - return this.toString().equals(links.toString()); - } - @Override public String toString() { return GoodDataToStringBuilder.defaultToString(this); diff --git a/src/test/java/com/gooddata/warehouse/WarehouseS3CredentialsTest.java b/src/test/java/com/gooddata/warehouse/WarehouseS3CredentialsTest.java index 0741ff1b5..05326ef40 100644 --- a/src/test/java/com/gooddata/warehouse/WarehouseS3CredentialsTest.java +++ b/src/test/java/com/gooddata/warehouse/WarehouseS3CredentialsTest.java @@ -12,10 +12,12 @@ import org.testng.annotations.Test; import static com.gooddata.util.ResourceUtils.readObjectFromResource; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals; import static net.javacrumbs.jsonunit.core.util.ResourceUtils.resource; import static org.hamcrest.CoreMatchers.endsWith; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -69,7 +71,8 @@ public void deserializeGet() { assertThat(credentials.getAccessKey(), is(ACCESS_KEY)); assertThat(credentials.getSecretKey(), is(nullValue())); assertThat(credentials.getUpdated().toString(), is(UPDATED_AT.toString())); - assertThat(credentials.getLinks(), is(LINKS)); + assertThat(credentials.getLinks(), is(sameBeanAs(LINKS))); + assertThat(credentials.getLinks().toString(), is(notNullValue())); } @Test From 3c0fa2a32df345d6573c755fbe526a2dbbb5ccf2 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Thu, 28 Sep 2017 23:26:43 +0200 Subject: [PATCH 007/582] store/return deffensive copy --- src/main/java/com/gooddata/md/MaqlAst.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gooddata/md/MaqlAst.java b/src/main/java/com/gooddata/md/MaqlAst.java index 20d458340..b5658a5f8 100644 --- a/src/main/java/com/gooddata/md/MaqlAst.java +++ b/src/main/java/com/gooddata/md/MaqlAst.java @@ -10,6 +10,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.gooddata.util.GoodDataToStringBuilder; +import java.util.Arrays; + /** * MAQL AST representation */ @@ -43,11 +45,11 @@ public MaqlAstPosition getPosition() { } public MaqlAst[] getContent() { - return content; + return content == null ? null : Arrays.copyOf(content, content.length); } public void setContent(final MaqlAst[] content) { - this.content = content; + this.content = content == null ? null : Arrays.copyOf(content, content.length); } public String getValue() { From 474fa76fff062a2fea35728bdb74b29ef937dacd Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Thu, 28 Sep 2017 23:31:49 +0200 Subject: [PATCH 008/582] delegate equals/hashCode methods to delegate list --- .../java/com/gooddata/collections/MultiPageList.java | 10 ++++++++++ .../gooddata/dataload/processes/ProcessService.java | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gooddata/collections/MultiPageList.java b/src/main/java/com/gooddata/collections/MultiPageList.java index ab609623e..a535c71b1 100644 --- a/src/main/java/com/gooddata/collections/MultiPageList.java +++ b/src/main/java/com/gooddata/collections/MultiPageList.java @@ -241,6 +241,16 @@ public List subList(final int fromIndex, final int toIndex) { return delegate.subList(fromIndex, toIndex); } + @Override + public boolean equals(final Object o) { + return delegate.equals(o); + } + + @Override + public int hashCode() { + return delegate.hashCode(); + } + private static final class PageIterator implements Iterator { private PageableList currentPage; diff --git a/src/main/java/com/gooddata/dataload/processes/ProcessService.java b/src/main/java/com/gooddata/dataload/processes/ProcessService.java index 522bee74d..ba7b33a56 100644 --- a/src/main/java/com/gooddata/dataload/processes/ProcessService.java +++ b/src/main/java/com/gooddata/dataload/processes/ProcessService.java @@ -670,6 +670,8 @@ private File createTempFile(String prefix, String suffix) { private void deleteTempFile(File file) { notNull(file, "file"); - file.delete(); + if (!file.delete()) { + // ignored + } } } From e9ee61dfc213c6708aa8a8241a226957ba41c264 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Thu, 28 Sep 2017 23:35:41 +0200 Subject: [PATCH 009/582] run findbugs during test phase --- pom.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pom.xml b/pom.xml index 43822207f..a6ed3e538 100644 --- a/pom.xml +++ b/pom.xml @@ -92,6 +92,19 @@ + + org.codehaus.mojo + findbugs-maven-plugin + 3.0.5 + + + + check + + test + + + From a2def02868a07cde203998972ad7f4d93e063c1c Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Wed, 4 Oct 2017 17:14:55 +0200 Subject: [PATCH 010/582] add a test to keep the coverage --- .../collections/MultiPageListTest.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/gooddata/collections/MultiPageListTest.java b/src/test/java/com/gooddata/collections/MultiPageListTest.java index bc348b82b..3837d1527 100644 --- a/src/test/java/com/gooddata/collections/MultiPageListTest.java +++ b/src/test/java/com/gooddata/collections/MultiPageListTest.java @@ -20,6 +20,7 @@ import static org.hamcrest.core.Is.is; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.testng.Assert.fail; public class MultiPageListTest { @@ -119,7 +120,8 @@ public void streamWithPageProvider() { assertThat(list.stream().max(Integer::compareTo).orElse(0), is(3)); } - @Test(expectedExceptions = IllegalStateException.class) + @Test(expectedExceptions = IllegalStateException.class, + expectedExceptionsMessageRegExp = ".*page provider does not iterate properly, returns the same page.*") public void infiniteLoopShouldBePrevented() { final PageableList pageableList = new PageableList<>(asList(1, 2), new Paging("next")); final PageableList list = new MultiPageList<>( @@ -127,7 +129,22 @@ public void infiniteLoopShouldBePrevented() { page -> pageableList ); - list.stream().anyMatch(it -> it == 5); + list.forEach((i) -> {}); + } + + @Test(expectedExceptions = IllegalStateException.class, + expectedExceptionsMessageRegExp = ".*page has no results, yet claims there is next page.*") + public void shouldFailOnMisbehavingNextPage() throws Exception { + final PageableList pageableList = new PageableList<>(asList(1, 2), new Paging("next")); + final PageableList misbehaving = mock(PageableList.class); + when(misbehaving.isEmpty()).thenReturn(true); + when(misbehaving.getNextPage()).thenReturn(new PageRequest()); + + final PageableList list = new MultiPageList<>( + pageableList, + page -> misbehaving + ); + list.forEach((i) -> {}); } @Test From 1122bf626202f4d7d6de8b1c5ae81ba55cd5520e Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Wed, 4 Oct 2017 16:10:32 +0200 Subject: [PATCH 011/582] make poll sleep interval configurable Set poll sleep interval to 0 in tests which makes tests invoked by mvn verify 4 times faster! --- .../java/com/gooddata/AbstractService.java | 22 +++++++-- src/main/java/com/gooddata/GoodData.java | 34 +++++++------- .../java/com/gooddata/GoodDataSettings.java | 47 +++++++++++++++---- .../com/gooddata/account/AccountService.java | 6 ++- .../auditevent/AuditEventService.java | 6 ++- .../gooddata/connector/ConnectorService.java | 5 +- .../gooddata/dataload/OutputStageService.java | 6 ++- .../dataload/processes/ProcessService.java | 7 ++- .../com/gooddata/dataset/DatasetService.java | 6 ++- .../com/gooddata/export/ExportService.java | 6 ++- .../featureflag/FeatureFlagService.java | 6 ++- .../java/com/gooddata/gdc/GdcService.java | 5 +- .../java/com/gooddata/md/MetadataService.java | 5 +- .../md/maintenance/ExportImportService.java | 5 +- .../java/com/gooddata/model/ModelService.java | 5 +- .../notification/NotificationService.java | 5 +- .../com/gooddata/project/ProjectService.java | 8 ++-- .../ProjectTemplateService.java | 6 ++- .../com/gooddata/report/ReportService.java | 5 +- .../gooddata/warehouse/WarehouseService.java | 6 ++- .../java/com/gooddata/AbstractGoodDataIT.java | 4 +- .../com/gooddata/AbstractServiceTest.java | 2 +- .../com/gooddata/GoodDataSettingsTest.java | 18 +++++++ .../auditevent/AuditEventServiceTest.java | 3 +- .../dataload/OutputStageServiceTest.java | 3 +- .../processes/ProcessServiceTest.java | 3 +- .../gooddata/dataset/DatasetServiceTest.java | 3 +- .../gooddata/export/ExportServiceTest.java | 7 +-- .../featureflag/FeatureFlagServiceTest.java | 3 +- .../com/gooddata/md/MetadataServiceTest.java | 3 +- .../maintenance/ExportImportServiceTest.java | 3 +- .../notification/NotificationServiceTest.java | 3 +- .../gooddata/project/ProjectServiceTest.java | 3 +- .../ProjectTemplateServiceTest.java | 3 +- .../gooddata/report/ReportServiceTest.java | 5 +- .../warehouse/WarehouseServiceTest.java | 3 +- 36 files changed, 186 insertions(+), 84 deletions(-) diff --git a/src/main/java/com/gooddata/AbstractService.java b/src/main/java/com/gooddata/AbstractService.java index 07f24fb14..76d31bb80 100644 --- a/src/main/java/com/gooddata/AbstractService.java +++ b/src/main/java/com/gooddata/AbstractService.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.net.URI; import java.util.concurrent.TimeUnit; /** @@ -30,23 +29,36 @@ */ public abstract class AbstractService { - public static final Integer WAIT_BEFORE_RETRY_IN_MILLIS = 5 * 1000; - protected final RestTemplate restTemplate; + private final GoodDataSettings settings; + protected final ObjectMapper mapper = new ObjectMapper(); private final ResponseExtractor reusableResponseExtractor = ReusableClientHttpResponse::new; + /** + * Sets RESTful HTTP Spring template. Should be called from constructor of concrete service extending + * this abstract one. + * + * @param restTemplate RESTful HTTP Spring template + * @param settings settings + */ + public AbstractService(final RestTemplate restTemplate, final GoodDataSettings settings) { + this.restTemplate = notNull(restTemplate, "restTemplate"); + this.settings = notNull(settings, "settings"); + } /** * Sets RESTful HTTP Spring template. Should be called from constructor of concrete service extending * this abstract one. * * @param restTemplate RESTful HTTP Spring template + * @deprecated use {@link #AbstractService(RestTemplate, GoodDataSettings)} */ + @Deprecated public AbstractService(RestTemplate restTemplate) { - this.restTemplate = notNull(restTemplate, "restTemplate"); + this(restTemplate, new GoodDataSettings()); } final R poll(final PollHandler handler, long timeout, final TimeUnit unit) { @@ -61,7 +73,7 @@ final R poll(final PollHandler handler, long timeout, final TimeUnit un } try { - Thread.sleep(WAIT_BEFORE_RETRY_IN_MILLIS); + Thread.sleep(settings.getPollSleep()); } catch (InterruptedException e) { throw new GoodDataException("interrupted"); } diff --git a/src/main/java/com/gooddata/GoodData.java b/src/main/java/com/gooddata/GoodData.java index 68baee3ac..3e5d28dc8 100644 --- a/src/main/java/com/gooddata/GoodData.java +++ b/src/main/java/com/gooddata/GoodData.java @@ -206,24 +206,24 @@ protected GoodData(GoodDataEndpoint endpoint, Authentication authentication, Goo restTemplate = createRestTemplate(endpoint, httpClient); - accountService = new AccountService(getRestTemplate()); - projectService = new ProjectService(getRestTemplate(), accountService); - metadataService = new MetadataService(getRestTemplate()); - modelService = new ModelService(getRestTemplate()); - gdcService = new GdcService(getRestTemplate()); + accountService = new AccountService(getRestTemplate(), settings); + projectService = new ProjectService(getRestTemplate(), accountService, settings); + metadataService = new MetadataService(getRestTemplate(), settings); + modelService = new ModelService(getRestTemplate(), settings); + gdcService = new GdcService(getRestTemplate(), settings); dataStoreService = new DataStoreService(getHttpClient(), getRestTemplate(), gdcService, endpoint.toUri()); - datasetService = new DatasetService(getRestTemplate(), dataStoreService); - exportService = new ExportService(getRestTemplate(), endpoint); - reportService = new ReportService(exportService, getRestTemplate()); - processService = new ProcessService(getRestTemplate(), accountService, dataStoreService); - warehouseService = new WarehouseService(getRestTemplate()); - connectorService = new ConnectorService(getRestTemplate(), projectService); - notificationService = new NotificationService(getRestTemplate()); - exportImportService = new ExportImportService(getRestTemplate()); - featureFlagService = new FeatureFlagService(getRestTemplate()); - outputStageService = new OutputStageService(getRestTemplate()); - projectTemplateService = new ProjectTemplateService(getRestTemplate()); - auditEventService = new AuditEventService(getRestTemplate(), accountService); + datasetService = new DatasetService(getRestTemplate(), dataStoreService, settings); + exportService = new ExportService(getRestTemplate(), endpoint, settings); + reportService = new ReportService(exportService, getRestTemplate(), settings); + processService = new ProcessService(getRestTemplate(), accountService, dataStoreService, settings); + warehouseService = new WarehouseService(getRestTemplate(), settings); + connectorService = new ConnectorService(getRestTemplate(), projectService, settings); + notificationService = new NotificationService(getRestTemplate(), settings); + exportImportService = new ExportImportService(getRestTemplate(), settings); + featureFlagService = new FeatureFlagService(getRestTemplate(), settings); + outputStageService = new OutputStageService(getRestTemplate(), settings); + projectTemplateService = new ProjectTemplateService(getRestTemplate(), settings); + auditEventService = new AuditEventService(getRestTemplate(), accountService, settings); } static RestTemplate createRestTemplate(GoodDataEndpoint endpoint, HttpClient httpClient) { diff --git a/src/main/java/com/gooddata/GoodDataSettings.java b/src/main/java/com/gooddata/GoodDataSettings.java index 44deaeea4..579fce6a0 100644 --- a/src/main/java/com/gooddata/GoodDataSettings.java +++ b/src/main/java/com/gooddata/GoodDataSettings.java @@ -5,7 +5,7 @@ */ package com.gooddata; -import org.apache.commons.lang.StringUtils; +import com.gooddata.util.GoodDataToStringBuilder; import java.util.concurrent.TimeUnit; @@ -24,6 +24,7 @@ public class GoodDataSettings { private int connectionTimeout = secondsToMillis(10); private int connectionRequestTimeout = secondsToMillis(10); private int socketTimeout = secondsToMillis(60); + private int pollSleep = secondsToMillis(5); private String userAgent; @@ -158,6 +159,36 @@ public int getSocketTimeout() { return socketTimeout; } + /** + * Get sleep time in milliseconds between poll retries + * + * @see AbstractService#poll(PollHandler, long, TimeUnit) + */ + public int getPollSleep() { + return pollSleep; + } + + /** + * Set sleep time between poll retries + * + * @param pollSleep sleep milliseconds + * @see AbstractService#poll(PollHandler, long, TimeUnit) + */ + public void setPollSleep(final int pollSleep) { + isTrue(pollSleep >= 0, "pollSleep must be not negative"); + this.pollSleep = pollSleep; + } + + /** + * Set sleep time between poll retries + * + * @param pollSleep sleep seconds + * @see AbstractService#poll(PollHandler, long, TimeUnit) + */ + public void setPollSleepSeconds(final int pollSleep) { + setPollSleep(secondsToMillis(pollSleep)); + } + /** * User agent * @return user agent string @@ -184,8 +215,9 @@ public boolean equals(final Object o) { if (maxConnections != that.maxConnections) return false; if (connectionTimeout != that.connectionTimeout) return false; if (connectionRequestTimeout != that.connectionRequestTimeout) return false; - return socketTimeout == that.socketTimeout; - + if (socketTimeout != that.socketTimeout) return false; + if (pollSleep != that.pollSleep) return false; + return userAgent != null ? userAgent.equals(that.userAgent) : that.userAgent == null; } @Override @@ -194,17 +226,14 @@ public int hashCode() { result = 31 * result + connectionTimeout; result = 31 * result + connectionRequestTimeout; result = 31 * result + socketTimeout; + result = 31 * result + pollSleep; + result = 31 * result + (userAgent != null ? userAgent.hashCode() : 0); return result; } @Override public String toString() { - return "GoodDataSettings{" + - "connectionRequestTimeout=" + connectionRequestTimeout + - ", maxConnections=" + maxConnections + - ", connectionTimeout=" + connectionTimeout + - ", socketTimeout=" + socketTimeout + - '}'; + return GoodDataToStringBuilder.defaultToString(this); } private static int secondsToMillis(int seconds) { diff --git a/src/main/java/com/gooddata/account/AccountService.java b/src/main/java/com/gooddata/account/AccountService.java index d25771082..0131b77fa 100644 --- a/src/main/java/com/gooddata/account/AccountService.java +++ b/src/main/java/com/gooddata/account/AccountService.java @@ -8,6 +8,7 @@ import com.gooddata.AbstractService; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.gdc.UriResponse; import org.springframework.http.HttpStatus; import org.springframework.http.converter.json.MappingJacksonValue; @@ -26,9 +27,10 @@ public class AccountService extends AbstractService { * Constructs service for GoodData account management. * * @param restTemplate RESTful HTTP Spring template + * @param settings settings */ - public AccountService(RestTemplate restTemplate) { - super(restTemplate); + public AccountService(final RestTemplate restTemplate, final GoodDataSettings settings) { + super(restTemplate, settings); } /** diff --git a/src/main/java/com/gooddata/auditevent/AuditEventService.java b/src/main/java/com/gooddata/auditevent/AuditEventService.java index 198def60c..d72a14e6b 100644 --- a/src/main/java/com/gooddata/auditevent/AuditEventService.java +++ b/src/main/java/com/gooddata/auditevent/AuditEventService.java @@ -6,6 +6,7 @@ import com.gooddata.AbstractService; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.account.Account; import com.gooddata.account.AccountService; import com.gooddata.collections.MultiPageList; @@ -30,9 +31,10 @@ public class AuditEventService extends AbstractService { * Service for audit events * @param restTemplate rest template * @param accountService account service + * @param settings settings */ - public AuditEventService(final RestTemplate restTemplate, final AccountService accountService) { - super(restTemplate); + public AuditEventService(final RestTemplate restTemplate, final AccountService accountService, final GoodDataSettings settings) { + super(restTemplate, settings); this.accountService = notNull(accountService, "account service"); } diff --git a/src/main/java/com/gooddata/connector/ConnectorService.java b/src/main/java/com/gooddata/connector/ConnectorService.java index 6e0160105..ea71a801e 100644 --- a/src/main/java/com/gooddata/connector/ConnectorService.java +++ b/src/main/java/com/gooddata/connector/ConnectorService.java @@ -7,6 +7,7 @@ import com.gooddata.AbstractService; import com.gooddata.FutureResult; +import com.gooddata.GoodDataSettings; import com.gooddata.PollResult; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; @@ -35,8 +36,8 @@ public class ConnectorService extends AbstractService { private final ProjectService projectService; - public ConnectorService(final RestTemplate restTemplate, final ProjectService projectService) { - super(restTemplate); + public ConnectorService(final RestTemplate restTemplate, final ProjectService projectService, final GoodDataSettings settings) { + super(restTemplate, settings); this.projectService = notNull(projectService, "projectService"); } diff --git a/src/main/java/com/gooddata/dataload/OutputStageService.java b/src/main/java/com/gooddata/dataload/OutputStageService.java index d990ddd73..98b934274 100644 --- a/src/main/java/com/gooddata/dataload/OutputStageService.java +++ b/src/main/java/com/gooddata/dataload/OutputStageService.java @@ -12,6 +12,7 @@ import com.gooddata.AbstractService; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.project.Project; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; @@ -28,9 +29,10 @@ public class OutputStageService 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 + * @param settings settings */ - public OutputStageService(final RestTemplate restTemplate) { - super(restTemplate); + public OutputStageService(final RestTemplate restTemplate, final GoodDataSettings settings) { + super(restTemplate, settings); } /** diff --git a/src/main/java/com/gooddata/dataload/processes/ProcessService.java b/src/main/java/com/gooddata/dataload/processes/ProcessService.java index 522bee74d..d29c946a2 100644 --- a/src/main/java/com/gooddata/dataload/processes/ProcessService.java +++ b/src/main/java/com/gooddata/dataload/processes/ProcessService.java @@ -8,6 +8,7 @@ import com.gooddata.AbstractPollHandler; import com.gooddata.AbstractService; import com.gooddata.FutureResult; +import com.gooddata.GoodDataSettings; import com.gooddata.PollResult; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; @@ -64,9 +65,11 @@ public class ProcessService extends AbstractService { * @param restTemplate RESTful HTTP Spring template * @param accountService service to access accounts * @param dataStoreService service for upload process data + * @param settings settings */ - public ProcessService(RestTemplate restTemplate, AccountService accountService, DataStoreService dataStoreService) { - super(restTemplate); + public ProcessService(final RestTemplate restTemplate, final AccountService accountService, + final DataStoreService dataStoreService, final GoodDataSettings settings) { + super(restTemplate, settings); this.dataStoreService = dataStoreService; this.accountService = notNull(accountService, "accountService"); } diff --git a/src/main/java/com/gooddata/dataset/DatasetService.java b/src/main/java/com/gooddata/dataset/DatasetService.java index b5596b641..bea214130 100644 --- a/src/main/java/com/gooddata/dataset/DatasetService.java +++ b/src/main/java/com/gooddata/dataset/DatasetService.java @@ -10,6 +10,7 @@ import com.gooddata.FutureResult; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.PollResult; import com.gooddata.gdc.AboutLinks.Link; import com.gooddata.gdc.DataStoreException; @@ -50,8 +51,9 @@ public class DatasetService extends AbstractService { private final DataStoreService dataStoreService; - public DatasetService(RestTemplate restTemplate, DataStoreService dataStoreService) { - super(restTemplate); + public DatasetService(final RestTemplate restTemplate, final DataStoreService dataStoreService, + final GoodDataSettings settings) { + super(restTemplate, settings); this.dataStoreService = notNull(dataStoreService, "dataStoreService"); } diff --git a/src/main/java/com/gooddata/export/ExportService.java b/src/main/java/com/gooddata/export/ExportService.java index 9015e2471..590277feb 100644 --- a/src/main/java/com/gooddata/export/ExportService.java +++ b/src/main/java/com/gooddata/export/ExportService.java @@ -12,6 +12,7 @@ import com.gooddata.GoodDataEndpoint; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.PollResult; import com.gooddata.SimplePollHandler; import com.gooddata.gdc.AsyncTask; @@ -55,9 +56,10 @@ public class ExportService extends AbstractService { * Service for data export * @param restTemplate REST template * @param endpoint GoodData Endpoint + * @param settings settings */ - public ExportService(final RestTemplate restTemplate, final GoodDataEndpoint endpoint) { - super(restTemplate); + public ExportService(final RestTemplate restTemplate, final GoodDataEndpoint endpoint, final GoodDataSettings settings) { + super(restTemplate, settings); this.endpoint = notNull(endpoint, "endpoint"); } diff --git a/src/main/java/com/gooddata/featureflag/FeatureFlagService.java b/src/main/java/com/gooddata/featureflag/FeatureFlagService.java index 93ab3a91c..77a888d07 100644 --- a/src/main/java/com/gooddata/featureflag/FeatureFlagService.java +++ b/src/main/java/com/gooddata/featureflag/FeatureFlagService.java @@ -7,6 +7,7 @@ import com.gooddata.AbstractService; import com.gooddata.GoodDataException; +import com.gooddata.GoodDataSettings; import com.gooddata.project.Project; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; @@ -29,9 +30,10 @@ public class FeatureFlagService extends AbstractService { * Constructs service for GoodData feature flags management. * * @param restTemplate RESTful HTTP Spring template + * @param settings settings */ - public FeatureFlagService(final RestTemplate restTemplate) { - super(restTemplate); + public FeatureFlagService(final RestTemplate restTemplate, final GoodDataSettings settings) { + super(restTemplate, settings); } /** diff --git a/src/main/java/com/gooddata/gdc/GdcService.java b/src/main/java/com/gooddata/gdc/GdcService.java index cbda1b06c..4f60348cf 100644 --- a/src/main/java/com/gooddata/gdc/GdcService.java +++ b/src/main/java/com/gooddata/gdc/GdcService.java @@ -7,6 +7,7 @@ import com.gooddata.AbstractService; import com.gooddata.GoodDataException; +import com.gooddata.GoodDataSettings; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; @@ -15,8 +16,8 @@ */ public class GdcService extends AbstractService { - public GdcService(RestTemplate restTemplate) { - super(restTemplate); + public GdcService(final RestTemplate restTemplate, final GoodDataSettings settings) { + super(restTemplate, settings); } /** diff --git a/src/main/java/com/gooddata/md/MetadataService.java b/src/main/java/com/gooddata/md/MetadataService.java index 419fdf317..f428bdf5c 100644 --- a/src/main/java/com/gooddata/md/MetadataService.java +++ b/src/main/java/com/gooddata/md/MetadataService.java @@ -8,6 +8,7 @@ import com.gooddata.AbstractService; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.md.report.ReportDefinition; import com.gooddata.project.Project; import org.springframework.http.HttpStatus; @@ -31,8 +32,8 @@ */ public class MetadataService extends AbstractService { - public MetadataService(RestTemplate restTemplate) { - super(restTemplate); + public MetadataService(final RestTemplate restTemplate, final GoodDataSettings settings) { + super(restTemplate, settings); } /** diff --git a/src/main/java/com/gooddata/md/maintenance/ExportImportService.java b/src/main/java/com/gooddata/md/maintenance/ExportImportService.java index 0bae95849..25feee03a 100644 --- a/src/main/java/com/gooddata/md/maintenance/ExportImportService.java +++ b/src/main/java/com/gooddata/md/maintenance/ExportImportService.java @@ -11,6 +11,7 @@ import com.gooddata.AbstractService; import com.gooddata.FutureResult; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.PollResult; import com.gooddata.gdc.TaskStatus; import com.gooddata.gdc.UriResponse; @@ -23,8 +24,8 @@ */ public class ExportImportService extends AbstractService { - public ExportImportService(RestTemplate restTemplate) { - super(restTemplate); + public ExportImportService(final RestTemplate restTemplate, final GoodDataSettings settings) { + super(restTemplate, settings); } diff --git a/src/main/java/com/gooddata/model/ModelService.java b/src/main/java/com/gooddata/model/ModelService.java index 66df630d3..0ef236c30 100644 --- a/src/main/java/com/gooddata/model/ModelService.java +++ b/src/main/java/com/gooddata/model/ModelService.java @@ -7,6 +7,7 @@ import com.gooddata.AbstractService; import com.gooddata.FutureResult; +import com.gooddata.GoodDataSettings; import com.gooddata.PollResult; import com.gooddata.GoodDataRestException; import com.gooddata.AbstractPollHandlerBase; @@ -34,8 +35,8 @@ */ public class ModelService extends AbstractService { - public ModelService(RestTemplate restTemplate) { - super(restTemplate); + public ModelService(final RestTemplate restTemplate, final GoodDataSettings settings) { + super(restTemplate, settings); } private FutureResult getProjectModelDiff(Project project, DiffRequest diffRequest) { diff --git a/src/main/java/com/gooddata/notification/NotificationService.java b/src/main/java/com/gooddata/notification/NotificationService.java index c4c6fe861..7cb8df269 100644 --- a/src/main/java/com/gooddata/notification/NotificationService.java +++ b/src/main/java/com/gooddata/notification/NotificationService.java @@ -10,6 +10,7 @@ import com.gooddata.AbstractService; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.project.Project; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; @@ -19,8 +20,8 @@ */ public class NotificationService extends AbstractService { - public NotificationService(final RestTemplate restTemplate) { - super(restTemplate); + public NotificationService(final RestTemplate restTemplate, final GoodDataSettings settings) { + super(restTemplate, settings); } /** diff --git a/src/main/java/com/gooddata/project/ProjectService.java b/src/main/java/com/gooddata/project/ProjectService.java index 62bec58e2..9a7458ba5 100644 --- a/src/main/java/com/gooddata/project/ProjectService.java +++ b/src/main/java/com/gooddata/project/ProjectService.java @@ -10,6 +10,7 @@ import com.gooddata.FutureResult; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.PollResult; import com.gooddata.SimplePollHandler; import com.gooddata.account.Account; @@ -55,12 +56,13 @@ public class ProjectService extends AbstractService { /** * Constructs service for GoodData project management (list projects, create a project, ...). - * * @param restTemplate RESTful HTTP Spring template * @param accountService GoodData account service + * @param settings settings */ - public ProjectService(RestTemplate restTemplate, AccountService accountService) { - super(restTemplate); + public ProjectService(final RestTemplate restTemplate, final AccountService accountService, + final GoodDataSettings settings) { + super(restTemplate, settings); this.accountService = notNull(accountService, "accountService"); } diff --git a/src/main/java/com/gooddata/projecttemplate/ProjectTemplateService.java b/src/main/java/com/gooddata/projecttemplate/ProjectTemplateService.java index 8def79977..ee7d36cf0 100644 --- a/src/main/java/com/gooddata/projecttemplate/ProjectTemplateService.java +++ b/src/main/java/com/gooddata/projecttemplate/ProjectTemplateService.java @@ -8,6 +8,7 @@ import com.gooddata.AbstractService; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.dataset.DatasetManifest; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; @@ -28,9 +29,10 @@ public class ProjectTemplateService extends AbstractService { * this abstract one. * * @param restTemplate RESTful HTTP Spring template + * @param settings settings */ - public ProjectTemplateService(RestTemplate restTemplate) { - super(restTemplate); + public ProjectTemplateService(final RestTemplate restTemplate, final GoodDataSettings settings) { + super(restTemplate, settings); } /** diff --git a/src/main/java/com/gooddata/report/ReportService.java b/src/main/java/com/gooddata/report/ReportService.java index efbae1b65..67ecbf2c6 100644 --- a/src/main/java/com/gooddata/report/ReportService.java +++ b/src/main/java/com/gooddata/report/ReportService.java @@ -7,6 +7,7 @@ import com.gooddata.AbstractService; import com.gooddata.FutureResult; +import com.gooddata.GoodDataSettings; import com.gooddata.export.ExportService; import com.gooddata.md.report.Report; import com.gooddata.md.report.ReportDefinition; @@ -32,8 +33,8 @@ public class ReportService extends AbstractService { private final ExportService service; - public ReportService(final ExportService service, final RestTemplate restTemplate) { - super(restTemplate); + public ReportService(final ExportService service, final RestTemplate restTemplate, final GoodDataSettings settings) { + super(restTemplate, settings); this.service = notNull(service, "service"); } diff --git a/src/main/java/com/gooddata/warehouse/WarehouseService.java b/src/main/java/com/gooddata/warehouse/WarehouseService.java index 9d89c5506..09a8089be 100644 --- a/src/main/java/com/gooddata/warehouse/WarehouseService.java +++ b/src/main/java/com/gooddata/warehouse/WarehouseService.java @@ -10,6 +10,7 @@ import com.gooddata.FutureResult; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.PollResult; import com.gooddata.collections.MultiPageList; import com.gooddata.collections.Page; @@ -45,9 +46,10 @@ public class WarehouseService extends AbstractService { * this abstract one. * * @param restTemplate RESTful HTTP Spring template + * @param settings settings */ - public WarehouseService(RestTemplate restTemplate) { - super(restTemplate); + public WarehouseService(final RestTemplate restTemplate, final GoodDataSettings settings) { + super(restTemplate, settings); } /** diff --git a/src/test/java/com/gooddata/AbstractGoodDataIT.java b/src/test/java/com/gooddata/AbstractGoodDataIT.java index f5c4b9e95..e408a3ef1 100644 --- a/src/test/java/com/gooddata/AbstractGoodDataIT.java +++ b/src/test/java/com/gooddata/AbstractGoodDataIT.java @@ -28,7 +28,9 @@ public void commonSetUp() { } protected GoodDataSettings createGoodDataSettings() { - return new GoodDataSettings(); + final GoodDataSettings settings = new GoodDataSettings(); + settings.setPollSleep(0); + return settings; } @AfterMethod diff --git a/src/test/java/com/gooddata/AbstractServiceTest.java b/src/test/java/com/gooddata/AbstractServiceTest.java index e389c0a62..23c8c10b2 100644 --- a/src/test/java/com/gooddata/AbstractServiceTest.java +++ b/src/test/java/com/gooddata/AbstractServiceTest.java @@ -33,7 +33,7 @@ public class AbstractServiceTest { @BeforeMethod public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - service = new AbstractService(restTemplate) {}; + service = new AbstractService(restTemplate, new GoodDataSettings()) {}; final ClientHttpResponse response = mock(ClientHttpResponse.class); when(response.getStatusCode()).thenReturn(HttpStatus.OK); when(restTemplate.execute(any(), any(HttpMethod.class), any(RequestCallback.class), any(ResponseExtractor.class))) diff --git a/src/test/java/com/gooddata/GoodDataSettingsTest.java b/src/test/java/com/gooddata/GoodDataSettingsTest.java index 651232816..d83e45011 100644 --- a/src/test/java/com/gooddata/GoodDataSettingsTest.java +++ b/src/test/java/com/gooddata/GoodDataSettingsTest.java @@ -5,6 +5,8 @@ */ package com.gooddata; +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -29,6 +31,7 @@ public void testHasDefaults() throws Exception { assertTrue(settings.getConnectionTimeout() >= 0); assertTrue(settings.getConnectionRequestTimeout() >= 0); assertTrue(settings.getSocketTimeout() >= 0); + assertTrue(settings.getPollSleep() >= 0); assertThat(settings.getUserAgent(), is(nullValue())); } @@ -37,10 +40,12 @@ public void testSetSeconds() throws Exception { settings.setConnectionTimeoutSeconds(53); settings.setConnectionRequestTimeoutSeconds(69); settings.setSocketTimeoutSeconds(71); + settings.setPollSleepSeconds(81); assertEquals(53000, settings.getConnectionTimeout()); assertEquals(69000, settings.getConnectionRequestTimeout()); assertEquals(71000, settings.getSocketTimeout()); + assertEquals(81000, settings.getPollSleep()); } @Test(expectedExceptions = IllegalArgumentException.class) @@ -58,6 +63,11 @@ public void setNegativeSocketTimeoutFails() throws Exception { settings.setSocketTimeout(-5); } + @Test(expectedExceptions = IllegalArgumentException.class) + public void setNegativePollSleepFails() throws Exception { + settings.setPollSleep(-5); + } + @Test(expectedExceptions = IllegalArgumentException.class) public void setZeroMaxConnectionsFails() throws Exception { settings.setMaxConnections(0); @@ -69,4 +79,12 @@ public void customUserAgentShouldBePrefixOfDefault() { goodDataSettings.setUserAgent("customAgent/X.Y"); assertThat(goodDataSettings.getUserAgent(), is("customAgent/X.Y")); } + + @Test + public void shouldVerifyEquals() throws Exception { + EqualsVerifier.forClass(GoodDataSettings.class) + .usingGetClass() + .suppress(Warning.NONFINAL_FIELDS) + .verify(); + } } \ No newline at end of file diff --git a/src/test/java/com/gooddata/auditevent/AuditEventServiceTest.java b/src/test/java/com/gooddata/auditevent/AuditEventServiceTest.java index 13fda9f44..984e9033a 100644 --- a/src/test/java/com/gooddata/auditevent/AuditEventServiceTest.java +++ b/src/test/java/com/gooddata/auditevent/AuditEventServiceTest.java @@ -3,6 +3,7 @@ */ package com.gooddata.auditevent; +import com.gooddata.GoodDataSettings; import com.gooddata.account.Account; import com.gooddata.account.AccountService; import com.gooddata.collections.PageRequest; @@ -19,7 +20,7 @@ public class AuditEventServiceTest { @BeforeMethod public void setUp() throws Exception { - service = new AuditEventService(new RestTemplate(), mock(AccountService.class)); + service = new AuditEventService(new RestTemplate(), mock(AccountService.class), new GoodDataSettings()); } @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".*account.*") diff --git a/src/test/java/com/gooddata/dataload/OutputStageServiceTest.java b/src/test/java/com/gooddata/dataload/OutputStageServiceTest.java index d7d03579f..89817e925 100644 --- a/src/test/java/com/gooddata/dataload/OutputStageServiceTest.java +++ b/src/test/java/com/gooddata/dataload/OutputStageServiceTest.java @@ -5,6 +5,7 @@ */ package com.gooddata.dataload; +import com.gooddata.GoodDataSettings; import com.gooddata.project.Project; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -41,7 +42,7 @@ public class OutputStageServiceTest { @BeforeMethod public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - outputStageService = new OutputStageService(restTemplate); + outputStageService = new OutputStageService(restTemplate, new GoodDataSettings()); outputStage = readObjectFromResource(OUTPUT_STAGE, OutputStage.class); } diff --git a/src/test/java/com/gooddata/dataload/processes/ProcessServiceTest.java b/src/test/java/com/gooddata/dataload/processes/ProcessServiceTest.java index 4a492d5a2..d4b5019a3 100644 --- a/src/test/java/com/gooddata/dataload/processes/ProcessServiceTest.java +++ b/src/test/java/com/gooddata/dataload/processes/ProcessServiceTest.java @@ -8,6 +8,7 @@ import com.gooddata.FutureResult; import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.account.Account; import com.gooddata.account.AccountService; import com.gooddata.gdc.DataStoreService; @@ -80,7 +81,7 @@ public class ProcessServiceTest { @BeforeMethod public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - processService = new ProcessService(restTemplate, accountService, dataStoreService); + processService = new ProcessService(restTemplate, accountService, dataStoreService, new GoodDataSettings()); when(process.getId()).thenReturn(PROCESS_ID); when(process.getUri()).thenReturn(DataloadProcess.TEMPLATE.expand(PROJECT_ID, PROCESS_ID).toString()); when(project.getId()).thenReturn(PROJECT_ID); diff --git a/src/test/java/com/gooddata/dataset/DatasetServiceTest.java b/src/test/java/com/gooddata/dataset/DatasetServiceTest.java index 4437fe453..cd2025878 100644 --- a/src/test/java/com/gooddata/dataset/DatasetServiceTest.java +++ b/src/test/java/com/gooddata/dataset/DatasetServiceTest.java @@ -7,6 +7,7 @@ import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.gdc.AboutLinks.Link; import com.gooddata.gdc.DataStoreException; import com.gooddata.gdc.DataStoreService; @@ -59,7 +60,7 @@ public class DatasetServiceTest { @BeforeMethod public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - service = new DatasetService(restTemplate, dataStoreService); + service = new DatasetService(restTemplate, dataStoreService, new GoodDataSettings()); when(project.getId()).thenReturn(PROJECT_ID); } diff --git a/src/test/java/com/gooddata/export/ExportServiceTest.java b/src/test/java/com/gooddata/export/ExportServiceTest.java index f627df7a2..5ca58d3ce 100644 --- a/src/test/java/com/gooddata/export/ExportServiceTest.java +++ b/src/test/java/com/gooddata/export/ExportServiceTest.java @@ -6,6 +6,7 @@ package com.gooddata.export; import com.gooddata.GoodDataEndpoint; +import com.gooddata.GoodDataSettings; import com.gooddata.md.ProjectDashboard; import com.gooddata.md.ProjectDashboard.Tab; import com.gooddata.md.report.Report; @@ -25,7 +26,7 @@ public class ExportServiceTest { - private final ExportService service = new ExportService(new RestTemplate(), new GoodDataEndpoint()); + private final ExportService service = new ExportService(new RestTemplate(), new GoodDataEndpoint(), new GoodDataSettings()); private ProjectDashboard dashboard; private Tab tab; private Report report; @@ -39,12 +40,12 @@ public void setUp() throws Exception { @Test(expectedExceptions = IllegalArgumentException.class) public void shouldFailOnNullArgument() throws Exception { - new ExportService(null, new GoodDataEndpoint()); + new ExportService(null, new GoodDataEndpoint(), new GoodDataSettings()); } @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".*endpoint.*") public void shouldFailOnNullEndpoint() throws Exception { - new ExportService(new RestTemplate(), null); + new ExportService(new RestTemplate(), null, new GoodDataSettings()); } @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".*dashboard.*") diff --git a/src/test/java/com/gooddata/featureflag/FeatureFlagServiceTest.java b/src/test/java/com/gooddata/featureflag/FeatureFlagServiceTest.java index 75352fdfc..3f9ffb71a 100644 --- a/src/test/java/com/gooddata/featureflag/FeatureFlagServiceTest.java +++ b/src/test/java/com/gooddata/featureflag/FeatureFlagServiceTest.java @@ -6,6 +6,7 @@ package com.gooddata.featureflag; import com.gooddata.GoodDataException; +import com.gooddata.GoodDataSettings; import com.gooddata.project.Project; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -48,7 +49,7 @@ public class FeatureFlagServiceTest { @BeforeMethod public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - service = new FeatureFlagService(restTemplate); + service = new FeatureFlagService(restTemplate, new GoodDataSettings()); when(project.getId()).thenReturn(PROJECT_ID); } diff --git a/src/test/java/com/gooddata/md/MetadataServiceTest.java b/src/test/java/com/gooddata/md/MetadataServiceTest.java index c3730b332..3cc9678a6 100644 --- a/src/test/java/com/gooddata/md/MetadataServiceTest.java +++ b/src/test/java/com/gooddata/md/MetadataServiceTest.java @@ -7,6 +7,7 @@ import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.gdc.UriResponse; import com.gooddata.md.report.ReportDefinition; import com.gooddata.project.Project; @@ -53,7 +54,7 @@ public class MetadataServiceTest { @BeforeMethod public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - service = new MetadataService(restTemplate); + service = new MetadataService(restTemplate, new GoodDataSettings()); when(project.getId()).thenReturn(PROJECT_ID); } diff --git a/src/test/java/com/gooddata/md/maintenance/ExportImportServiceTest.java b/src/test/java/com/gooddata/md/maintenance/ExportImportServiceTest.java index c7ab39bc1..933d17c7a 100644 --- a/src/test/java/com/gooddata/md/maintenance/ExportImportServiceTest.java +++ b/src/test/java/com/gooddata/md/maintenance/ExportImportServiceTest.java @@ -10,6 +10,7 @@ import static org.mockito.Mockito.when; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.gdc.UriResponse; import com.gooddata.project.Project; import org.mockito.Mock; @@ -32,7 +33,7 @@ public class ExportImportServiceTest { @BeforeMethod public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - service = new ExportImportService(restTemplate); + service = new ExportImportService(restTemplate, new GoodDataSettings()); when(project.getId()).thenReturn(PROJECT_ID); } diff --git a/src/test/java/com/gooddata/notification/NotificationServiceTest.java b/src/test/java/com/gooddata/notification/NotificationServiceTest.java index 81855ef32..241589246 100644 --- a/src/test/java/com/gooddata/notification/NotificationServiceTest.java +++ b/src/test/java/com/gooddata/notification/NotificationServiceTest.java @@ -8,6 +8,7 @@ import static java.util.Collections.singletonMap; import static org.mockito.Mockito.*; +import com.gooddata.GoodDataSettings; import com.gooddata.project.Project; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -30,7 +31,7 @@ public class NotificationServiceTest { @BeforeMethod public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - notificationService = new NotificationService(restTemplate); + notificationService = new NotificationService(restTemplate, new GoodDataSettings()); when(project.getId()).thenReturn(PROJECT_ID); } diff --git a/src/test/java/com/gooddata/project/ProjectServiceTest.java b/src/test/java/com/gooddata/project/ProjectServiceTest.java index 09862f89f..9ae66503f 100644 --- a/src/test/java/com/gooddata/project/ProjectServiceTest.java +++ b/src/test/java/com/gooddata/project/ProjectServiceTest.java @@ -7,6 +7,7 @@ import com.gooddata.GoodDataException; import com.gooddata.GoodDataRestException; +import com.gooddata.GoodDataSettings; import com.gooddata.account.Account; import com.gooddata.account.AccountService; import org.mockito.Mock; @@ -46,7 +47,7 @@ public class ProjectServiceTest { @BeforeMethod public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - service = new ProjectService(restTemplate, accountService); + service = new ProjectService(restTemplate, accountService, new GoodDataSettings()); when(accountService.getCurrent()).thenReturn(account); when(account.getId()).thenReturn(ACCOUNT_ID); when(project.getId()).thenReturn(ID); diff --git a/src/test/java/com/gooddata/projecttemplate/ProjectTemplateServiceTest.java b/src/test/java/com/gooddata/projecttemplate/ProjectTemplateServiceTest.java index 184dfe55d..6a59c693d 100644 --- a/src/test/java/com/gooddata/projecttemplate/ProjectTemplateServiceTest.java +++ b/src/test/java/com/gooddata/projecttemplate/ProjectTemplateServiceTest.java @@ -5,6 +5,7 @@ */ package com.gooddata.projecttemplate; +import com.gooddata.GoodDataSettings; import com.gooddata.dataset.DatasetManifest; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -38,7 +39,7 @@ public class ProjectTemplateServiceTest { @BeforeMethod public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - service = new ProjectTemplateService(restTemplate); + service = new ProjectTemplateService(restTemplate, new GoodDataSettings()); when(templates.getTemplates()).thenReturn(singletonList(template)); } diff --git a/src/test/java/com/gooddata/report/ReportServiceTest.java b/src/test/java/com/gooddata/report/ReportServiceTest.java index 7cda22e56..5cd7754e2 100644 --- a/src/test/java/com/gooddata/report/ReportServiceTest.java +++ b/src/test/java/com/gooddata/report/ReportServiceTest.java @@ -5,6 +5,7 @@ */ package com.gooddata.report; +import com.gooddata.GoodDataSettings; import com.gooddata.export.ExportFormat; import com.gooddata.export.ExportService; import com.gooddata.md.report.Report; @@ -27,12 +28,12 @@ public class ReportServiceTest { @BeforeMethod public void setUp() throws Exception { exportService = mock(ExportService.class); - reportService = new ReportService(exportService, mock(RestTemplate.class)); + reportService = new ReportService(exportService, mock(RestTemplate.class), new GoodDataSettings()); } @Test(expectedExceptions = IllegalArgumentException.class) public void shouldFailOnNullArgument() throws Exception { - new ReportService(null, mock(RestTemplate.class)); + new ReportService(null, mock(RestTemplate.class), new GoodDataSettings()); } @Test diff --git a/src/test/java/com/gooddata/warehouse/WarehouseServiceTest.java b/src/test/java/com/gooddata/warehouse/WarehouseServiceTest.java index 4fe84aca1..cccb7a78c 100644 --- a/src/test/java/com/gooddata/warehouse/WarehouseServiceTest.java +++ b/src/test/java/com/gooddata/warehouse/WarehouseServiceTest.java @@ -5,6 +5,7 @@ */ package com.gooddata.warehouse; +import com.gooddata.GoodDataSettings; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.http.HttpEntity; @@ -33,7 +34,7 @@ public class WarehouseServiceTest { @BeforeMethod public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - service = new WarehouseService(restTemplate); + service = new WarehouseService(restTemplate, new GoodDataSettings()); when(warehouse.getId()).thenReturn("instanceId"); final WarehouseTask warehouseTask = mock(WarehouseTask.class); From 426ae12f04f56a710e4cdb32967aca080d2a7870 Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Thu, 5 Oct 2017 22:09:52 +0200 Subject: [PATCH 012/582] enhance tests for error handler --- .../util/ResponseErrorHandlerTest.java | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java b/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java index d9c038988..8903e1636 100644 --- a/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java +++ b/src/test/java/com/gooddata/util/ResponseErrorHandlerTest.java @@ -42,7 +42,7 @@ public void testHandleGdcError() throws Exception { final GoodDataRestException exc = assertException(response); - assertThat("GoodDataRestException should have been thrown!", exc, is(notNullValue())); + assertThat(exc.getMessage(), is("500: [requestId=REQ] MSG")); assertThat(exc.getStatusCode(), is(500)); assertThat(exc.getRequestId(), is("REQ")); assertThat(exc.getComponent(), is("COMPONENT")); @@ -57,7 +57,7 @@ public void testHandleErrorStructure() throws Exception { final GoodDataRestException exc = assertException(response); - assertThat("GoodDataRestException should have been thrown!", exc, is(notNullValue())); + assertThat(exc.getMessage(), is("500: [requestId=REQ] MSG PARAM1 PARAM2 3")); assertThat(exc.getStatusCode(), is(500)); assertThat(exc.getRequestId(), is("REQ")); assertThat(exc.getComponent(), is("COMPONENT")); @@ -72,7 +72,7 @@ public void testHandleInvalidError() throws Exception { final GoodDataRestException exc = assertException(response); - assertThat("GoodDataRestException should have been thrown!", exc, is(notNullValue())); + assertThat(exc.getMessage(), is("500: [requestId=requestId] Unknown error")); assertThat(exc.getStatusCode(), is(500)); assertThat(exc.getRequestId(), is("requestId")); assertThat(exc.getComponent(), is(nullValue())); @@ -81,16 +81,39 @@ public void testHandleInvalidError() throws Exception { assertThat(exc.getText(), is(nullValue())); } + @Test + public void shouldName() throws Exception { + final ClientHttpResponse response = prepareResponse(); + final HttpHeaders headers = new HttpHeaders(); + when(response.getHeaders()).thenReturn(headers); + when(response.getStatusText()).thenThrow(IOException.class); + when(response.getRawStatusCode()).thenThrow(IOException.class); + + final GoodDataRestException exc = assertException(response); + + assertThat(exc.getMessage(), is("0: Unknown error")); + assertThat(exc.getStatusCode(), is(0)); + assertThat(exc.getRequestId(), is(nullValue())); + 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); - when(response.getRawStatusCode()).thenReturn(500); + final ClientHttpResponse response = prepareResponse(); final HttpHeaders headers = new HttpHeaders(); + when(response.getHeaders()).thenReturn(headers); headers.set(GoodData.GDC_REQUEST_ID_HEADER, "requestId"); headers.setContentType(MediaType.APPLICATION_JSON); - when(response.getHeaders()).thenReturn(headers); when(response.getBody()).thenReturn(readFromResource(resourcePath)); + return response; + } + private ClientHttpResponse prepareResponse() throws IOException { + final ClientHttpResponse response = mock(ClientHttpResponse.class); + when(response.getStatusCode()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR); + when(response.getRawStatusCode()).thenReturn(500); return response; } From c4e7e69aa11fdbd847f57be5176cfe0d1e02140d Mon Sep 17 00:00:00 2001 From: Martin Caslavsky Date: Wed, 4 Oct 2017 21:27:05 +0200 Subject: [PATCH 013/582] remove tests using mocked rest template --- CONTRIBUTING.md | 2 +- .../gooddata/notification/ProjectEvent.java | 16 ++-- .../dataload/OutputStageServiceTest.java | 60 +-------------- .../processes/ProcessServiceTest.java | 6 +- .../gooddata/dataset/DatasetServiceTest.java | 20 ----- .../featureflag/FeatureFlagServiceTest.java | 65 ---------------- .../featureflag/ProjectFeatureFlagTest.java | 11 +++ .../notification/NotificationServiceTest.java | 18 +---- .../notification/ProjectEventTest.java | 9 +++ .../ProjectTemplateServiceTest.java | 75 ------------------- .../gooddata/report/ReportServiceTest.java | 2 +- .../warehouse/WarehouseServiceTest.java | 13 ---- 12 files changed, 35 insertions(+), 262 deletions(-) delete mode 100644 src/test/java/com/gooddata/projecttemplate/ProjectTemplateServiceTest.java diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c61a4f09f..3c2fc1028 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,7 +65,7 @@ is specific enough. ## Best practices * **Test class naming**: - * `*Test` unit tests + * `*Test` unit tests, but avoid service tests using mocked `RestTemplate` - use integration test * `*IT` integration tests (see [`AbstractGoodDataIT`](src/test/java/com/gooddata/AbstractGoodDataIT.java)) * `*AT` acceptance tests * Everything public should be **documented** using _javadoc_. diff --git a/src/main/java/com/gooddata/notification/ProjectEvent.java b/src/main/java/com/gooddata/notification/ProjectEvent.java index 126a62bcf..cc2173a3e 100644 --- a/src/main/java/com/gooddata/notification/ProjectEvent.java +++ b/src/main/java/com/gooddata/notification/ProjectEvent.java @@ -66,18 +66,14 @@ public Map getParameters() { } @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof ProjectEvent)) - return false; + public boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; - ProjectEvent that = (ProjectEvent) o; - - if (type != null ? !type.equals(that.type) : that.type != null) - return false; - return !(parameters != null ? !parameters.equals(that.parameters) : that.parameters != null); + final ProjectEvent that = (ProjectEvent) o; + if (type != null ? !type.equals(that.type) : that.type != null) return false; + return parameters != null ? parameters.equals(that.parameters) : that.parameters == null; } @Override diff --git a/src/test/java/com/gooddata/dataload/OutputStageServiceTest.java b/src/test/java/com/gooddata/dataload/OutputStageServiceTest.java index 89817e925..ee4fdea27 100644 --- a/src/test/java/com/gooddata/dataload/OutputStageServiceTest.java +++ b/src/test/java/com/gooddata/dataload/OutputStageServiceTest.java @@ -6,44 +6,17 @@ package com.gooddata.dataload; import com.gooddata.GoodDataSettings; -import com.gooddata.project.Project; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.springframework.http.HttpMethod; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -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; - public class OutputStageServiceTest { - private static final String OUTPUT_STAGE = "/dataload/outputStage.json"; - - @Mock - private RestTemplate restTemplate; - private OutputStageService outputStageService; - private OutputStage outputStage; - @BeforeMethod public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - outputStageService = new OutputStageService(restTemplate, new GoodDataSettings()); - outputStage = readObjectFromResource(OUTPUT_STAGE, OutputStage.class); + outputStageService = new OutputStageService(new RestTemplate(), new GoodDataSettings()); } @Test(expectedExceptions = IllegalArgumentException.class) @@ -51,44 +24,13 @@ public void testGetOutputStageByNullUri() throws Exception { outputStageService.getOutputStageByUri(null); } - @Test - public void testGetOutputStageByUri() throws Exception { - when(restTemplate.getForObject(outputStage.getUri(), OutputStage.class)).thenReturn(outputStage); - - OutputStage outputStageByUri = outputStageService.getOutputStageByUri(outputStage.getUri()); - - assertThat(outputStageByUri, is(equalTo(outputStage))); - } - @Test(expectedExceptions = IllegalArgumentException.class) public void testGetOutputStageByNullProject() throws Exception { outputStageService.getOutputStage(null); } - @Test - public void testGetOutputStage() throws Exception { - Project project = mock(Project.class); - when(project.getId()).thenReturn("projectId"); - when(restTemplate.getForObject(outputStage.getUri(), OutputStage.class)).thenReturn(outputStage); - - OutputStage outputStageByProject = outputStageService.getOutputStage(project); - - assertThat(outputStageByProject, is(equalTo(outputStage))); - } - @Test(expectedExceptions = IllegalArgumentException.class) public void testUpdateOutputStageNullOutputStage() throws Exception { outputStageService.updateOutputStage(null); } - - @Test - public void testUpdateOutputStage() throws Exception { - ResponseEntity responseEntity = mock(ResponseEntity.class); - when(restTemplate.exchange(eq(outputStage.getUri()), eq(HttpMethod.PUT), any(RequestEntity.class), eq(OutputStage.class))).thenReturn(responseEntity); - doReturn(outputStage).when(responseEntity).getBody(); - - outputStageService.updateOutputStage(outputStage); - - verify(restTemplate, times(1)).exchange(eq(outputStage.getUri()), eq(HttpMethod.PUT), any(RequestEntity.class), eq(OutputStage.class)); - } } \ No newline at end of file diff --git a/src/test/java/com/gooddata/dataload/processes/ProcessServiceTest.java b/src/test/java/com/gooddata/dataload/processes/ProcessServiceTest.java index d4b5019a3..7842f9659 100644 --- a/src/test/java/com/gooddata/dataload/processes/ProcessServiceTest.java +++ b/src/test/java/com/gooddata/dataload/processes/ProcessServiceTest.java @@ -90,7 +90,7 @@ public void setUp() throws Exception { } @Test - public void testCreateProcess() throws Exception { + public void shouldDeploySmallProcessUsingAPI() throws Exception { final DataloadProcess process = new DataloadProcess("test", ProcessType.GRAPH); @@ -109,7 +109,7 @@ public void testCreateProcess() throws Exception { } @Test - public void testCreateProcessLargerThan1MB() throws Exception { + public void shouldDeployLargeProcessUsingWebDAV() throws Exception { final DataloadProcess process = new DataloadProcess("test", ProcessType.GRAPH); @@ -122,8 +122,6 @@ public void testCreateProcessLargerThan1MB() throws Exception { verify(dataStoreService).upload(anyString(), notNull(InputStream.class)); } - - private static File createProcessOfSize(int size) throws Exception { final Random r = new Random(); final File file = File.createTempFile("process", ".txt"); diff --git a/src/test/java/com/gooddata/dataset/DatasetServiceTest.java b/src/test/java/com/gooddata/dataset/DatasetServiceTest.java index cd2025878..502b6cf49 100644 --- a/src/test/java/com/gooddata/dataset/DatasetServiceTest.java +++ b/src/test/java/com/gooddata/dataset/DatasetServiceTest.java @@ -79,15 +79,6 @@ public void testGetDatasetManifestWithEmptyId() throws Exception { service.getDatasetManifest(project, ""); } - @Test - public void testGetDatasetManifest() throws Exception { - when(restTemplate.getForObject(DatasetManifest.URI, DatasetManifest.class, PROJECT_ID, DATASET_ID)) - .thenReturn(manifest); - final DatasetManifest result = service.getDatasetManifest(project, DATASET_ID); - - assertThat(result, is(manifest)); - } - @Test(expectedExceptions = DatasetNotFoundException.class) public void testGetDatasetManifestWhenNotFound() throws Exception { when(restTemplate.getForObject(DatasetManifest.URI, DatasetManifest.class, PROJECT_ID, DATASET_ID)) @@ -207,17 +198,6 @@ public void testListDatasetLinksWithRestClientError() throws Exception { service.listDatasetLinks(project); } - @Test - public void testListDatasetLinksWithEmptyResponse() throws Exception { - final DatasetLinks datasets = mock(DatasetLinks.class); - when(restTemplate.getForObject(DatasetLinks.URI, DatasetLinks.class, PROJECT_ID)).thenReturn(datasets); - when(datasets.getLinks()).thenReturn(singletonList(datasetLink)); - - final Collection result = service.listDatasetLinks(project); - assertThat(result, hasSize(1)); - assertThat(result, contains(datasetLink)); - } - @Test(expectedExceptions = GoodDataException.class) public void testGetDataSetInfoRestClientError() throws Exception { when(restTemplate.getForObject(UploadsInfo.URI, UploadsInfo.class, PROJECT_ID)) diff --git a/src/test/java/com/gooddata/featureflag/FeatureFlagServiceTest.java b/src/test/java/com/gooddata/featureflag/FeatureFlagServiceTest.java index 3f9ffb71a..9ffcbfaa7 100644 --- a/src/test/java/com/gooddata/featureflag/FeatureFlagServiceTest.java +++ b/src/test/java/com/gooddata/featureflag/FeatureFlagServiceTest.java @@ -71,17 +71,6 @@ public void whenClientErrorResponseThenGetFeatureFlagsShouldThrow() throws Excep service.listFeatureFlags(project); } - @Test - public void testGetFeatureFlags() throws Exception { - final FeatureFlag flag1 = new FeatureFlag(FLAG_NAME, true); - when(restTemplate.getForObject(new URI(FEATURE_FLAGS_URI), FeatureFlags.class)).thenReturn(featureFlags); - when(featureFlags.iterator()).thenReturn(singleton(flag1).iterator()); - - final FeatureFlags flags = service.listFeatureFlags(project); - - assertThat(flags, contains(flag1)); - } - @Test(expectedExceptions = IllegalArgumentException.class) public void whenNullArgThenGetProjectFeatureFlagsShouldThrow() throws Exception { service.listProjectFeatureFlags(null); @@ -100,18 +89,6 @@ public void whenClientErrorResponseThenGetProjectFeatureFlagsShouldThrow() throw service.listProjectFeatureFlags(project); } - @Test - public void testGetProjectFeatureFlags() throws Exception { - final ProjectFeatureFlag flag1 = new ProjectFeatureFlag(FLAG_NAME, true); - when(restTemplate.getForObject(new URI(PROJECT_FEATURE_FLAGS_URI), ProjectFeatureFlags.class)) - .thenReturn(projectFeatureFlags); - when(projectFeatureFlags.iterator()).thenReturn(singleton(flag1).iterator()); - - final ProjectFeatureFlags flags = service.listProjectFeatureFlags(project); - - assertThat(flags, contains(flag1)); - } - @Test(expectedExceptions = IllegalArgumentException.class) public void whenNullKeyThenCreateProjectFeatureFlagShouldThrow() throws Exception { service.createProjectFeatureFlag(project, null); @@ -135,18 +112,6 @@ public void whenClientErrorResponseThenCreateProjectFeatureFlagShouldThrow() thr service.createProjectFeatureFlag(project, projectFeatureFlag); } - @Test - public void testCreateProjectFeatureFlag() throws Exception { - final ProjectFeatureFlag flag = new ProjectFeatureFlag(FLAG_NAME, true); - when(restTemplate.postForLocation(PROJECT_FEATURE_FLAGS_URI, flag)) - .thenReturn(new URI(PROJECT_FEATURE_FLAG_URI)); - when(restTemplate.getForObject(PROJECT_FEATURE_FLAG_URI, ProjectFeatureFlag.class)).thenReturn(flag); - - final ProjectFeatureFlag result = service.createProjectFeatureFlag(project, flag); - - assertThat(result, is(flag)); - } - @Test(expectedExceptions = IllegalArgumentException.class) public void whenNullKeyThenGetProjectFeatureFlagShouldThrow() throws Exception { service.getProjectFeatureFlag(project, null); @@ -170,16 +135,6 @@ public void whenClientErrorResponseThenGetProjectFeatureFlagShouldThrow() throws service.getProjectFeatureFlag(project, FLAG_NAME); } - @Test - public void testGetProjectFeatureFlag() throws Exception { - final ProjectFeatureFlag flag = new ProjectFeatureFlag(FLAG_NAME, true); - when(restTemplate.getForObject(PROJECT_FEATURE_FLAG_URI, ProjectFeatureFlag.class)).thenReturn(flag); - - final ProjectFeatureFlag result = service.getProjectFeatureFlag(project, FLAG_NAME); - - assertThat(result, is(flag)); - } - @Test(expectedExceptions = IllegalArgumentException.class) public void whenNullFlagThenUpdateProjectFeatureFlagShouldThrow() throws Exception { service.updateProjectFeatureFlag(null); @@ -200,19 +155,6 @@ public void whenClientErrorResponseThenUpdateProjectFeatureFlagShouldThrow() thr service.updateProjectFeatureFlag(projectFeatureFlag); } - @Test - public void testUpdateProjectFeatureFlag() throws Exception { - final ProjectFeatureFlag newFlag = new ProjectFeatureFlag(FLAG_NAME, true); - when(projectFeatureFlag.getUri()).thenReturn(PROJECT_FEATURE_FLAG_URI); - when(restTemplate.getForObject(PROJECT_FEATURE_FLAG_URI, ProjectFeatureFlag.class)) - .thenReturn(newFlag); - - final ProjectFeatureFlag result = service.updateProjectFeatureFlag(projectFeatureFlag); - - verify(restTemplate).put(PROJECT_FEATURE_FLAG_URI, projectFeatureFlag); - assertThat(result, is(newFlag)); - } - @Test(expectedExceptions = IllegalArgumentException.class) public void whenNullFlagThenDeleteProjectFeatureFlagShouldThrow() throws Exception { service.deleteProjectFeatureFlag(null); @@ -225,11 +167,4 @@ public void whenClientErrorResponseThenDeleteProjectFeatureFlagShouldThrow() thr service.deleteProjectFeatureFlag(projectFeatureFlag); } - @Test - public void testDeleteProjectFeatureFlag() throws Exception { - when(projectFeatureFlag.getUri()).thenReturn(PROJECT_FEATURE_FLAG_URI); - service.deleteProjectFeatureFlag(projectFeatureFlag); - verify(restTemplate).delete(PROJECT_FEATURE_FLAG_URI); - } - } \ No newline at end of file diff --git a/src/test/java/com/gooddata/featureflag/ProjectFeatureFlagTest.java b/src/test/java/com/gooddata/featureflag/ProjectFeatureFlagTest.java index 6f1165d5b..a0b7c1aea 100644 --- a/src/test/java/com/gooddata/featureflag/ProjectFeatureFlagTest.java +++ b/src/test/java/com/gooddata/featureflag/ProjectFeatureFlagTest.java @@ -5,6 +5,8 @@ */ package com.gooddata.featureflag; +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; import org.testng.annotations.Test; import static org.hamcrest.CoreMatchers.is; @@ -41,4 +43,13 @@ public void testToStringFormat() { assertThat(flag.toString(), matchesPattern(ProjectFeatureFlag.class.getSimpleName() + "\\[.*\\]")); } + + @Test + public void shouldVerifyEquals() throws Exception { + EqualsVerifier.forClass(ProjectFeatureFlag.class) + .usingGetClass() + .suppress(Warning.NONFINAL_FIELDS) + .withIgnoredFields("links") + .verify(); + } } \ No newline at end of file diff --git a/src/test/java/com/gooddata/notification/NotificationServiceTest.java b/src/test/java/com/gooddata/notification/NotificationServiceTest.java index 241589246..fc232cc1c 100644 --- a/src/test/java/com/gooddata/notification/NotificationServiceTest.java +++ b/src/test/java/com/gooddata/notification/NotificationServiceTest.java @@ -5,9 +5,6 @@ */ package com.gooddata.notification; -import static java.util.Collections.singletonMap; -import static org.mockito.Mockito.*; - import com.gooddata.GoodDataSettings; import com.gooddata.project.Project; import org.mockito.Mock; @@ -16,6 +13,9 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class NotificationServiceTest { private static final String PROJECT_ID = "TEST_PROJ_ID"; @@ -23,25 +23,15 @@ public class NotificationServiceTest { @Mock private Project project; - @Mock - private RestTemplate restTemplate; - private NotificationService notificationService; @BeforeMethod public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - notificationService = new NotificationService(restTemplate, new GoodDataSettings()); + notificationService = new NotificationService(new RestTemplate(), new GoodDataSettings()); when(project.getId()).thenReturn(PROJECT_ID); } - @Test - public void testTriggerEvent() throws Exception { - final ProjectEvent projectEvent = new ProjectEvent("type", singletonMap("key", "value")); - notificationService.triggerEvent(project, projectEvent); - verify(restTemplate).postForEntity(eq(ProjectEvent.URI), eq(projectEvent), eq(Void.class), eq(PROJECT_ID)); - } - @Test(expectedExceptions = IllegalArgumentException.class) public void testTriggerNullEvent() throws Exception { notificationService.triggerEvent(project, null); diff --git a/src/test/java/com/gooddata/notification/ProjectEventTest.java b/src/test/java/com/gooddata/notification/ProjectEventTest.java index aec1f24a7..089c8643d 100644 --- a/src/test/java/com/gooddata/notification/ProjectEventTest.java +++ b/src/test/java/com/gooddata/notification/ProjectEventTest.java @@ -10,6 +10,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.text.MatchesPattern.matchesPattern; +import nl.jqno.equalsverifier.EqualsVerifier; import org.testng.annotations.Test; public class ProjectEventTest { @@ -27,4 +28,12 @@ public void testToStringFormat() { assertThat(projectEvent.toString(), matchesPattern(ProjectEvent.class.getSimpleName() + "\\[.*\\]")); } + + @Test + public void shouldVerifyEquals() throws Exception { + EqualsVerifier.forClass(ProjectEvent.class) + .usingGetClass() + .verify(); + } + } \ No newline at end of file diff --git a/src/test/java/com/gooddata/projecttemplate/ProjectTemplateServiceTest.java b/src/test/java/com/gooddata/projecttemplate/ProjectTemplateServiceTest.java deleted file mode 100644 index 6a59c693d..000000000 --- a/src/test/java/com/gooddata/projecttemplate/ProjectTemplateServiceTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.GoodDataSettings; -import com.gooddata.dataset.DatasetManifest; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.springframework.web.client.RestTemplate; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.Collection; - -import static java.util.Collections.singletonList; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.mockito.Mockito.when; - -public class ProjectTemplateServiceTest { - - private static final String TEMPLATE_URI = "/projectTemplates/ZendeskAnalytics/20"; - - @Mock - private RestTemplate restTemplate; - @Mock - private Template template; - @Mock - private Templates templates; - @Mock - private DatasetManifest manifest; - - private ProjectTemplateService service; - - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - service = new ProjectTemplateService(restTemplate, new GoodDataSettings()); - when(templates.getTemplates()).thenReturn(singletonList(template)); - } - - @Test - public void testGetTemplate() throws Exception { - when(restTemplate.getForObject(TEMPLATE_URI, Template.class)) - .thenReturn(template); - final Template template = service.getTemplateByUri(TEMPLATE_URI); - assertThat(template, is(template)); - } - - @Test - public void testGetTemplates() throws Exception { - when(restTemplate.getForObject("/projectTemplates", Templates.class)) - .thenReturn(templates); - - final Collection