From e7a0c412b94c97ff49e4cfac539c243f46821f11 Mon Sep 17 00:00:00 2001 From: Mario Bodemann Date: Mon, 12 Nov 2018 14:25:05 +0100 Subject: [PATCH] Add rich text (#178) map out all rich text types (https://www.contentful.com/developers/docs/concepts/rich-text/) --- .buildscript/deploy_snapshot.sh | 2 +- .travis.yml | 2 +- CHANGELOG.md | 8 +- README.md | 2 +- checkstyle.xml | 18 +- pom.xml | 15 +- .../com/contentful/java/cda/AbsQuery.java | 4 +- .../contentful/java/cda/ArrayResource.java | 3 +- .../com/contentful/java/cda/CDAArray.java | 1 + .../com/contentful/java/cda/CDAAsset.java | 4 +- .../com/contentful/java/cda/CDAClient.java | 87 ++-- .../contentful/java/cda/CDAContentType.java | 1 + .../cda/CDAContentTypeNotFoundException.java | 2 + .../com/contentful/java/cda/CDAEntry.java | 1 + .../com/contentful/java/cda/CDAField.java | 1 + .../contentful/java/cda/CDAHttpException.java | 1 + .../com/contentful/java/cda/CDALocale.java | 1 + .../com/contentful/java/cda/CDAResource.java | 1 + .../cda/CDAResourceNotFoundException.java | 2 + .../com/contentful/java/cda/CDASpace.java | 1 + .../com/contentful/java/cda/Callbacks.java | 4 +- .../contentful/java/cda/DeletedResource.java | 1 + .../java/cda/LocalizedResource.java | 18 + .../com/contentful/java/cda/ObserveQuery.java | 61 ++- .../contentful/java/cda/QueryOperation.java | 37 +- .../contentful/java/cda/ResourceFactory.java | 18 +- .../contentful/java/cda/ResourceUtils.java | 53 +-- .../com/contentful/java/cda/SyncQuery.java | 25 +- .../com/contentful/java/cda/SyncType.java | 4 +- .../java/cda/SynchronizedSpace.java | 1 + .../contentful/java/cda/TlsSocketFactory.java | 2 +- .../ContentfulUserAgentHeaderInterceptor.java | 2 +- .../java/cda/rich/CDARichBlock.java | 18 + .../java/cda/rich/CDARichDocument.java | 7 + .../java/cda/rich/CDARichEmbeddedLink.java | 17 + .../java/cda/rich/CDARichHeading.java | 26 ++ .../java/cda/rich/CDARichHorizontalRule.java | 12 + .../java/cda/rich/CDARichHyperLink.java | 24 + .../contentful/java/cda/rich/CDARichList.java | 28 ++ .../java/cda/rich/CDARichListItem.java | 7 + .../contentful/java/cda/rich/CDARichMark.java | 55 +++ .../contentful/java/cda/rich/CDARichNode.java | 7 + .../java/cda/rich/CDARichOrderedList.java | 13 + .../java/cda/rich/CDARichParagraph.java | 7 + .../java/cda/rich/CDARichQuote.java | 7 + .../contentful/java/cda/rich/CDARichText.java | 43 ++ .../java/cda/rich/CDARichUnorderedList.java | 13 + .../java/cda/rich/RichTextFactory.java | 344 +++++++++++++++ src/test/bash/create_folders.sh | 3 + src/test/bash/create_recordings.sh | 10 + src/test/bash/rich_text-all.sh | 27 ++ src/test/bash/rich_text-content_types.sh | 15 + src/test/bash/rich_text-locales.sh | 15 + .../com/contentful/java/cda/AbsQueryTest.java | 140 +++--- .../com/contentful/java/cda/AssetTest.java | 42 +- .../com/contentful/java/cda/BaseTest.java | 4 +- .../com/contentful/java/cda/CallbackTest.java | 10 +- .../com/contentful/java/cda/ClientTest.java | 41 +- .../contentful/java/cda/ContentTypeTest.java | 12 +- .../com/contentful/java/cda/EntryTest.java | 72 ++- .../contentful/java/cda/EnvironmentTest.java | 4 +- .../com/contentful/java/cda/LinkTest.java | 12 +- .../java/cda/LocaleFallbackTest.java | 36 +- .../com/contentful/java/cda/LocaleTest.java | 8 +- .../java/cda/ResourceFactoryUnitTest.java | 10 +- .../com/contentful/java/cda/RichTextTest.java | 411 ++++++++++++++++++ .../com/contentful/java/cda/SpaceTest.java | 2 +- .../com/contentful/java/cda/SyncTest.java | 48 +- .../java/cda/integration/Integration.java | 101 ++--- .../IntegrationWithMasterEnvironment.java | 28 +- .../IntegrationWithStagingEnvironment.java | 31 +- .../java/cda/lib/EnqueueResponseRule.java | 5 +- .../resources/rich_text/content_types.json | 56 +++ src/test/resources/rich_text/locales.json | 21 + .../rich_text/simple_blockquote.json | 80 ++++ .../rich_text/simple_headline_1.json | 71 +++ .../rich_text/simple_headline_2.json | 71 +++ .../rich_text/simple_headline_3.json | 71 +++ .../rich_text/simple_headline_4.json | 71 +++ .../rich_text/simple_headline_5.json | 71 +++ .../rich_text/simple_headline_6.json | 71 +++ .../rich_text/simple_horizontal_rule.json | 71 +++ .../rich_text/simple_ordered_list.json | 151 +++++++ .../rich_text/simple_ordered_nested_list.json | 198 +++++++++ src/test/resources/rich_text/simple_text.json | 60 +++ .../resources/rich_text/simple_text_bold.json | 66 +++ .../resources/rich_text/simple_text_code.json | 66 +++ .../rich_text/simple_text_embedded.json | 133 ++++++ .../rich_text/simple_text_italic.json | 66 +++ ..._mixed_bold_italic_underline_code_all.json | 145 ++++++ .../rich_text/simple_text_underline.json | 66 +++ .../rich_text/simple_text_with_link.json | 78 ++++ .../rich_text/simple_unordered_list.json | 168 +++++++ 93 files changed, 3464 insertions(+), 485 deletions(-) create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichBlock.java create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichDocument.java create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichEmbeddedLink.java create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichHeading.java create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichHorizontalRule.java create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichHyperLink.java create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichList.java create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichListItem.java create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichMark.java create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichNode.java create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichOrderedList.java create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichParagraph.java create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichQuote.java create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichText.java create mode 100644 src/main/java/com/contentful/java/cda/rich/CDARichUnorderedList.java create mode 100644 src/main/java/com/contentful/java/cda/rich/RichTextFactory.java create mode 100755 src/test/bash/create_folders.sh create mode 100755 src/test/bash/create_recordings.sh create mode 100755 src/test/bash/rich_text-all.sh create mode 100755 src/test/bash/rich_text-content_types.sh create mode 100755 src/test/bash/rich_text-locales.sh create mode 100644 src/test/java/com/contentful/java/cda/RichTextTest.java create mode 100644 src/test/resources/rich_text/content_types.json create mode 100644 src/test/resources/rich_text/locales.json create mode 100644 src/test/resources/rich_text/simple_blockquote.json create mode 100644 src/test/resources/rich_text/simple_headline_1.json create mode 100644 src/test/resources/rich_text/simple_headline_2.json create mode 100644 src/test/resources/rich_text/simple_headline_3.json create mode 100644 src/test/resources/rich_text/simple_headline_4.json create mode 100644 src/test/resources/rich_text/simple_headline_5.json create mode 100644 src/test/resources/rich_text/simple_headline_6.json create mode 100644 src/test/resources/rich_text/simple_horizontal_rule.json create mode 100644 src/test/resources/rich_text/simple_ordered_list.json create mode 100644 src/test/resources/rich_text/simple_ordered_nested_list.json create mode 100644 src/test/resources/rich_text/simple_text.json create mode 100644 src/test/resources/rich_text/simple_text_bold.json create mode 100644 src/test/resources/rich_text/simple_text_code.json create mode 100644 src/test/resources/rich_text/simple_text_embedded.json create mode 100644 src/test/resources/rich_text/simple_text_italic.json create mode 100644 src/test/resources/rich_text/simple_text_mixed_bold_italic_underline_code_all.json create mode 100644 src/test/resources/rich_text/simple_text_underline.json create mode 100644 src/test/resources/rich_text/simple_text_with_link.json create mode 100644 src/test/resources/rich_text/simple_unordered_list.json diff --git a/.buildscript/deploy_snapshot.sh b/.buildscript/deploy_snapshot.sh index f178bdab..26c9dbcf 100755 --- a/.buildscript/deploy_snapshot.sh +++ b/.buildscript/deploy_snapshot.sh @@ -26,6 +26,6 @@ else fi echo "Deploying snapshot to jitpack ..." -curl https://jitpack.io/com/github/contentful/contentful.java/${TRAVIS_BRANCH}-SNAPSHOT +curl --verbose --location "https://jitpack.io/com/github/contentful/contentful.java/${TRAVIS_BRANCH}-SNAPSHOT/" echo "Snapshot deployed to jitpack!" diff --git a/.travis.yml b/.travis.yml index 91aaa20c..47a4dcc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,9 @@ language: java sudo: false jdk: - - openjdk7 - openjdk8 - oraclejdk8 + - oraclejdk9 script: - mvn jacoco:prepare-agent test jacoco:report diff --git a/CHANGELOG.md b/CHANGELOG.md index e37e5038..3c937b2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## Version [10.2.0] - (2018-11-12) +- Add [rich text](https://www.contentful.com/developers/docs/concepts/rich-text/) to entry types. + ## Version [10.1.0] - (2018-05-22) - Add `png8` image option for returning images in png with up to 256 colours. - Make `sync` environment aware. @@ -221,8 +224,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## Version 1.0.0 - 2014-08-13 Initial release. -[unreleased]: https://github.com/contentful/contentful.java/compare/java-sdk-10.1.0...HEAD -[10.0.0]: https://github.com/contentful/contentful.java/compare/java-sdk-10.0.0...java-sdk-10.1.0 +[unreleased]: https://github.com/contentful/contentful.java/compare/java-sdk-10.2.0...HEAD +[10.2.0]: https://github.com/contentful/contentful.java/compare/java-sdk-10.1.0...java-sdk-10.2.0 +[10.1.0]: https://github.com/contentful/contentful.java/compare/java-sdk-10.0.0...java-sdk-10.1.0 [10.0.0]: https://github.com/contentful/contentful.java/compare/java-sdk-9.1.1...java-sdk-10.0.0 [9.1.1]: https://github.com/contentful/contentful.java/compare/java-sdk-9.1.0...java-sdk-9.1.1 [9.1.0]: https://github.com/contentful/contentful.java/compare/java-sdk-9.0.1...java-sdk-9.1.0 diff --git a/README.md b/README.md index 00edadbc..acba5fd8 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Install the Contentful dependency: compile 'com.contentful.java:java-sdk:10.0.0' ``` -This SDK requires Java 7 (or higher version) or Android 5. +This SDK requires Java 8 (or higher version) or Android 5. Client Creation --------------- diff --git a/checkstyle.xml b/checkstyle.xml index e6f2b7bf..f861132e 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -97,7 +97,6 @@ - @@ -107,10 +106,6 @@ - - - - @@ -126,13 +121,12 @@ - - - - - - - + + + + + + diff --git a/pom.xml b/pom.xml index 19e06692..85e99207 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.contentful.java java-sdk - 10.1.1-SNAPSHOT + 10.2.0-SNAPSHOT jar ${project.groupId}:${project.artifactId} @@ -45,7 +45,7 @@ UTF-8 - 1.6 + 1.8 2.3.0 @@ -220,8 +220,15 @@ org.apache.maven.plugins maven-checkstyle-plugin - 2.9.1 - + 3.0.0 + + + com.puppycrawl.tools + checkstyle + 8.12 + + + true checkstyle.xml true diff --git a/src/main/java/com/contentful/java/cda/AbsQuery.java b/src/main/java/com/contentful/java/cda/AbsQuery.java index b6335dd3..33a9ca16 100644 --- a/src/main/java/com/contentful/java/cda/AbsQuery.java +++ b/src/main/java/com/contentful/java/cda/AbsQuery.java @@ -35,7 +35,7 @@ public abstract class AbsQuery< final CDAClient client; - final Map params = new HashMap(); + final Map params = new HashMap<>(); AbsQuery(Class type, CDAClient client) { this.type = type; @@ -357,7 +357,7 @@ public Query reverseOrderBy(String key) { * Limits the amount of elements to a given number. *

* If more then the number given elements are present, you can use {@link #skip(int)} and - * {@link #limit(int)} for pagination. + * {@see #limit(int)} for pagination. * * @param limit a non negative number less than 1001 to include elements. * @return the calling query for chaining. diff --git a/src/main/java/com/contentful/java/cda/ArrayResource.java b/src/main/java/com/contentful/java/cda/ArrayResource.java index 75221d26..99901b10 100644 --- a/src/main/java/com/contentful/java/cda/ArrayResource.java +++ b/src/main/java/com/contentful/java/cda/ArrayResource.java @@ -8,7 +8,8 @@ * * @see CDAResource */ -abstract class ArrayResource extends CDAResource { +public abstract class ArrayResource extends CDAResource { + private static final long serialVersionUID = -2702554830040250962L; List items; Map assets; diff --git a/src/main/java/com/contentful/java/cda/CDAArray.java b/src/main/java/com/contentful/java/cda/CDAArray.java index be2b770d..2aad79a9 100644 --- a/src/main/java/com/contentful/java/cda/CDAArray.java +++ b/src/main/java/com/contentful/java/cda/CDAArray.java @@ -8,6 +8,7 @@ * Collection of CDA resources. */ public class CDAArray extends ArrayResource { + private static final long serialVersionUID = 6596224363025698245L; int total; int skip; diff --git a/src/main/java/com/contentful/java/cda/CDAAsset.java b/src/main/java/com/contentful/java/cda/CDAAsset.java index 592289cc..b304124b 100644 --- a/src/main/java/com/contentful/java/cda/CDAAsset.java +++ b/src/main/java/com/contentful/java/cda/CDAAsset.java @@ -10,6 +10,8 @@ */ public class CDAAsset extends LocalizedResource { + private static final long serialVersionUID = -4645571481643616657L; + /** * @return title of this asset. */ @@ -53,7 +55,7 @@ public String urlForImageWith(ImageOption... options) { } final Map mappedOptions - = new LinkedHashMap(options.length); + = new LinkedHashMap<>(options.length); for (final ImageOption option : options) { mappedOptions.put(option.getOperation(), option); diff --git a/src/main/java/com/contentful/java/cda/CDAClient.java b/src/main/java/com/contentful/java/cda/CDAClient.java index d7ef80ba..79e35943 100644 --- a/src/main/java/com/contentful/java/cda/CDAClient.java +++ b/src/main/java/com/contentful/java/cda/CDAClient.java @@ -31,7 +31,6 @@ import io.reactivex.functions.Function; import okhttp3.Call; import okhttp3.OkHttpClient; -import retrofit2.Response; import retrofit2.Retrofit; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; @@ -126,7 +125,7 @@ private static CDAService createService(Builder clientBuilder) { * @see #fetchSpace() */ public FetchQuery fetch(Class type) { - return new FetchQuery(type, this); + return new FetchQuery<>(type, this); } /** @@ -140,7 +139,7 @@ public FetchQuery fetch(Class type) { * @see #observeSpace() */ public ObserveQuery observe(Class type) { - return new ObserveQuery(type, this); + return new ObserveQuery<>(type, this); } /** @@ -223,7 +222,7 @@ public Flowable observeContentTypeCachePopulation(final int limit) { .all() .map( new Function() { - @Override public CDAArray apply(CDAArray array) throws Exception { + @Override public CDAArray apply(CDAArray array) { if (array.skip() + array.limit() < array.total()) { return nextPage(array); } else { @@ -250,20 +249,18 @@ private CDAArray nextPage(CDAArray array) { } ) .map( - new Function() { - @Override public Integer apply(CDAArray array) throws Exception { - for (CDAResource resource : array.items) { - if (resource instanceof CDAContentType) { - cache.types().put(resource.id(), (CDAContentType) resource); - } else { - throw new IllegalStateException( - "Requesting a list of content types should not return " - + "any other type."); - } + array -> { + for (CDAResource resource : array.items) { + if (resource instanceof CDAContentType) { + cache.types().put(resource.id(), (CDAContentType) resource); + } else { + throw new IllegalStateException( + "Requesting a list of content types should not return " + + "any other type."); } - - return array.total; } + + return array.total; } ); } @@ -363,11 +360,7 @@ public > C fetchSpace(C callback) { * @return an {@link Flowable} that fetches the space for this client. */ public Flowable observeSpace() { - return service.space(spaceId).map(new Function, CDASpace>() { - @Override public CDASpace apply(Response response) throws Exception { - return fromResponse(response); - } - }); + return service.space(spaceId).map(ResourceFactory::fromResponse); } /** @@ -375,28 +368,18 @@ public Flowable observeSpace() { */ Flowable cacheAll(final boolean invalidate) { return cacheLocales(invalidate) - .flatMap(new Function, Flowable>>() { - @Override public Flowable> apply(List locales) { - return cacheTypes(invalidate); - } - }) - .map(new Function, Cache>() { - @Override public Cache apply(Map stringCDAContentTypeMap) { - return cache; - } - }); + .flatMap(locales -> cacheTypes(invalidate)) + .map(stringCDAContentTypeMap -> cache); } Flowable> cacheLocales(boolean invalidate) { List locales = invalidate ? null : cache.locales(); if (locales == null) { - return service.array(spaceId, environmentId, PATH_LOCALES, new HashMap()) - .map(new Function, List>() { - @Override public List apply(Response localesResponse) { - final List locales = fromArrayToItems(fromResponse(localesResponse)); - cache.setLocales(locales); - return locales; - } + return service.array(spaceId, environmentId, PATH_LOCALES, new HashMap<>()) + .map(localesResponse -> { + final List locales1 = fromArrayToItems(fromResponse(localesResponse)); + cache.setLocales(locales1); + return locales1; }); } return Flowable.just(locales); @@ -409,18 +392,16 @@ Flowable> cacheTypes(boolean invalidate) { spaceId, environmentId, PATH_CONTENT_TYPES, - new HashMap() + new HashMap<>() ).map( - new Function, Map>() { - @Override public Map apply(Response arrayResponse) { - CDAArray array = ResourceFactory.array(arrayResponse, CDAClient.this); - Map tmp = new ConcurrentHashMap(); - for (CDAResource resource : array.items()) { - tmp.put(resource.id(), (CDAContentType) resource); - } - cache.setTypes(tmp); - return tmp; + arrayResponse -> { + CDAArray array = ResourceFactory.array(arrayResponse, CDAClient.this); + Map tmp = new ConcurrentHashMap<>(); + for (CDAResource resource : array.items()) { + tmp.put(resource.id(), (CDAContentType) resource); } + cache.setTypes(tmp); + return tmp; }); } return Flowable.just(types); @@ -432,13 +413,11 @@ Flowable cacheTypeWithId(String id) { return observe(CDAContentType.class) .one(id) .map( - new Function() { - @Override public CDAContentType apply(CDAContentType resource) { - if (resource != null) { - cache.types().put(resource.id(), resource); - } - return resource; + resource -> { + if (resource != null) { + cache.types().put(resource.id(), resource); } + return resource; } ); } diff --git a/src/main/java/com/contentful/java/cda/CDAContentType.java b/src/main/java/com/contentful/java/cda/CDAContentType.java index e195c0f4..0391e436 100644 --- a/src/main/java/com/contentful/java/cda/CDAContentType.java +++ b/src/main/java/com/contentful/java/cda/CDAContentType.java @@ -6,6 +6,7 @@ * Represents a single content type. */ public class CDAContentType extends CDAResource { + private static final long serialVersionUID = 7901798878659781364L; List fields; String name; diff --git a/src/main/java/com/contentful/java/cda/CDAContentTypeNotFoundException.java b/src/main/java/com/contentful/java/cda/CDAContentTypeNotFoundException.java index 6801e055..9b33a3c7 100644 --- a/src/main/java/com/contentful/java/cda/CDAContentTypeNotFoundException.java +++ b/src/main/java/com/contentful/java/cda/CDAContentTypeNotFoundException.java @@ -10,6 +10,8 @@ */ public class CDAContentTypeNotFoundException extends RuntimeException { + private static final long serialVersionUID = -5839900656195732862L; + /** * Create a new exception. * diff --git a/src/main/java/com/contentful/java/cda/CDAEntry.java b/src/main/java/com/contentful/java/cda/CDAEntry.java index d3b9e955..df860368 100644 --- a/src/main/java/com/contentful/java/cda/CDAEntry.java +++ b/src/main/java/com/contentful/java/cda/CDAEntry.java @@ -4,6 +4,7 @@ * The class represents a basic entry in the space. */ public class CDAEntry extends LocalizedResource { + private static final long serialVersionUID = 5902790363045498307L; private CDAContentType contentType; /** diff --git a/src/main/java/com/contentful/java/cda/CDAField.java b/src/main/java/com/contentful/java/cda/CDAField.java index 82c70dfc..018052d7 100644 --- a/src/main/java/com/contentful/java/cda/CDAField.java +++ b/src/main/java/com/contentful/java/cda/CDAField.java @@ -6,6 +6,7 @@ /** Represents a single content type field. */ public class CDAField implements Serializable { + private static final long serialVersionUID = -2852530837647669035L; String name; String id; diff --git a/src/main/java/com/contentful/java/cda/CDAHttpException.java b/src/main/java/com/contentful/java/cda/CDAHttpException.java index 2d980a05..a29718df 100644 --- a/src/main/java/com/contentful/java/cda/CDAHttpException.java +++ b/src/main/java/com/contentful/java/cda/CDAHttpException.java @@ -16,6 +16,7 @@ * This class will represent known Contentful exceptions */ public class CDAHttpException extends RuntimeException { + private static final long serialVersionUID = 637581021148308658L; private final Request request; private final Response response; private final String responseBody; diff --git a/src/main/java/com/contentful/java/cda/CDALocale.java b/src/main/java/com/contentful/java/cda/CDALocale.java index 677bc9a9..bf1fea1c 100644 --- a/src/main/java/com/contentful/java/cda/CDALocale.java +++ b/src/main/java/com/contentful/java/cda/CDALocale.java @@ -6,6 +6,7 @@ * Represents a single locale. */ public class CDALocale extends CDAResource { + private static final long serialVersionUID = -5710267672379169621L; String code; String name; diff --git a/src/main/java/com/contentful/java/cda/CDAResource.java b/src/main/java/com/contentful/java/cda/CDAResource.java index 3b205080..d17a7afc 100644 --- a/src/main/java/com/contentful/java/cda/CDAResource.java +++ b/src/main/java/com/contentful/java/cda/CDAResource.java @@ -12,6 +12,7 @@ * for CDAContentType, CDASpace and, indirectly, for CDAEntry. */ public abstract class CDAResource implements Serializable { + private static final long serialVersionUID = -160701290783423915L; @SerializedName("sys") Map attrs; diff --git a/src/main/java/com/contentful/java/cda/CDAResourceNotFoundException.java b/src/main/java/com/contentful/java/cda/CDAResourceNotFoundException.java index 57afb1d8..275ad990 100644 --- a/src/main/java/com/contentful/java/cda/CDAResourceNotFoundException.java +++ b/src/main/java/com/contentful/java/cda/CDAResourceNotFoundException.java @@ -7,6 +7,8 @@ */ public class CDAResourceNotFoundException extends RuntimeException { + private static final long serialVersionUID = -7419778969492055048L; + /** * Create a new exception * diff --git a/src/main/java/com/contentful/java/cda/CDASpace.java b/src/main/java/com/contentful/java/cda/CDASpace.java index 2844656d..9e9d8a3c 100644 --- a/src/main/java/com/contentful/java/cda/CDASpace.java +++ b/src/main/java/com/contentful/java/cda/CDASpace.java @@ -4,6 +4,7 @@ * Represents a single space. */ public class CDASpace extends CDAResource { + private static final long serialVersionUID = 8920494351623297673L; String name; /** diff --git a/src/main/java/com/contentful/java/cda/Callbacks.java b/src/main/java/com/contentful/java/cda/Callbacks.java index b89707a0..0fa5ff68 100644 --- a/src/main/java/com/contentful/java/cda/Callbacks.java +++ b/src/main/java/com/contentful/java/cda/Callbacks.java @@ -15,7 +15,7 @@ static CDACallback subscribeAs ConnectableFlowable connectable = flowable.observeOn(Schedulers.io()).publish(); callback.setSubscription(connectable.subscribe( - new SuccessAction(callback, client), + new SuccessAction<>(callback, client), new FailureAction(callback, client))); connectable.connect(); @@ -55,7 +55,7 @@ static class SuccessAction extends BaseAction { @SuppressWarnings("unchecked") @Override protected void doCall(E e) { - execute(new SuccessRunnable(e, (CDACallback) callback)); + execute(new SuccessRunnable<>(e, (CDACallback) callback)); } } diff --git a/src/main/java/com/contentful/java/cda/DeletedResource.java b/src/main/java/com/contentful/java/cda/DeletedResource.java index 4bd0b6fa..e0c60206 100644 --- a/src/main/java/com/contentful/java/cda/DeletedResource.java +++ b/src/main/java/com/contentful/java/cda/DeletedResource.java @@ -2,4 +2,5 @@ /** Represents a deleted resource (via the Sync API). */ public class DeletedResource extends CDAResource { + private static final long serialVersionUID = 5881271494348347577L; } diff --git a/src/main/java/com/contentful/java/cda/LocalizedResource.java b/src/main/java/com/contentful/java/cda/LocalizedResource.java index d453bc51..2e989b2b 100644 --- a/src/main/java/com/contentful/java/cda/LocalizedResource.java +++ b/src/main/java/com/contentful/java/cda/LocalizedResource.java @@ -6,6 +6,8 @@ * Represents a resource which may contain field values for multiple locales. */ public abstract class LocalizedResource extends CDAResource { + private static final long serialVersionUID = 5713028146014748949L; + public class Localizer { private final String locale; @@ -85,6 +87,22 @@ public T getField(String locale, String key) { return localize(locale).getField(key); } + /** + * Internal method for updating contents of a field. + *

+ * This method is used by the SDK to generate objects based on raw fields. + * + * Do not use this field to update data on Contentful. Take a look at the CMA-SDK for that. + * + * @param locale locale to be updated. + * @param key the key of the field to be updated. + * @param value the value of the field to be used. + */ + @SuppressWarnings("unchecked") + public void setField(String locale, String key, Object value) { + ((Map) fields.get(key)).put(locale, value); + } + /** * @return raw unprocessed fields. */ diff --git a/src/main/java/com/contentful/java/cda/ObserveQuery.java b/src/main/java/com/contentful/java/cda/ObserveQuery.java index 250ca13b..c1c245a7 100644 --- a/src/main/java/com/contentful/java/cda/ObserveQuery.java +++ b/src/main/java/com/contentful/java/cda/ObserveQuery.java @@ -1,8 +1,6 @@ package com.contentful.java.cda; import io.reactivex.Flowable; -import io.reactivex.functions.Function; -import retrofit2.Response; import static com.contentful.java.cda.CDAType.ASSET; import static com.contentful.java.cda.CDAType.CONTENTTYPE; @@ -30,39 +28,36 @@ public class ObserveQuery extends AbsQuery one(final String id) { - Flowable flowable = where("sys.id", id).all().map(new Function() { - @Override @SuppressWarnings("unchecked") public T apply(CDAArray array) { - if (array.items().size() == 0) { + Flowable flowable = where("sys.id", id).all().map(array -> { + if (array.items().size() == 0) { + throw new CDAResourceNotFoundException(type, id); + } + CDAType resourceType = typeForClass(type); + if (ASSET.equals(resourceType)) { + return (T) array.assets().get(id); + } else if (ENTRY.equals(resourceType)) { + return (T) array.entries().get(id); + } else if (CONTENTTYPE.equals(resourceType)) { + return (T) array.items().get(0); + } else if (LOCALE.equals(resourceType)) { + T found = findById(array, id); + if (found == null) { throw new CDAResourceNotFoundException(type, id); } - CDAType resourceType = typeForClass(type); - if (ASSET.equals(resourceType)) { - return (T) array.assets().get(id); - } else if (ENTRY.equals(resourceType)) { - return (T) array.entries().get(id); - } else if (CONTENTTYPE.equals(resourceType)) { - return (T) array.items().get(0); - } else if (LOCALE.equals(resourceType)) { - T found = findById(array, id); - if (found == null) { - throw new CDAResourceNotFoundException(type, id); - } - return found; - } else { - throw new IllegalArgumentException("Cannot invoke query for type: " + type.getName()); - } + return found; + } else { + throw new IllegalArgumentException("Cannot invoke query for type: " + type.getName()); } }); if (CONTENTTYPE.equals(typeForClass(type))) { - flowable = flowable.map(new Function() { - @Override public T apply(T t) { - if (t != null) { - client.cache.types().put(t.id(), (CDAContentType) t); - } - return t; + flowable = flowable.map(t -> { + if (t != null) { + client.cache.types().put(t.id(), (CDAContentType) t); } + return t; }); } return flowable; @@ -86,14 +81,8 @@ T findById(CDAArray array, String id) { */ public Flowable all() { return client.cacheAll(false) - .flatMap(new Function>>() { - @Override public Flowable> apply(Cache cache) { - return client.service.array(client.spaceId, client.environmentId, path(), params); - } - }).map(new Function, CDAArray>() { - @Override public CDAArray apply(Response response) { - return ResourceFactory.array(response, client); - } - }); + .flatMap( + cache -> client.service.array(client.spaceId, client.environmentId, path(), params) + ).map(response -> ResourceFactory.array(response, client)); } } diff --git a/src/main/java/com/contentful/java/cda/QueryOperation.java b/src/main/java/com/contentful/java/cda/QueryOperation.java index 8c1b50d6..6350ead6 100644 --- a/src/main/java/com/contentful/java/cda/QueryOperation.java +++ b/src/main/java/com/contentful/java/cda/QueryOperation.java @@ -7,34 +7,33 @@ */ public class QueryOperation { - public static final QueryOperation IsEqualTo = new QueryOperation(""); - public static final QueryOperation IsNotEqualTo = new QueryOperation("[ne]"); - public static final QueryOperation HasOneOf = new QueryOperation("[in]"); - public static final QueryOperation HasNoneOf = new QueryOperation("[nin]"); - public static final QueryOperation HasAllOf = new QueryOperation("[all]"); + public static final QueryOperation IsEqualTo = new QueryOperation<>(""); + public static final QueryOperation IsNotEqualTo = new QueryOperation<>("[ne]"); + public static final QueryOperation HasOneOf = new QueryOperation<>("[in]"); + public static final QueryOperation HasNoneOf = new QueryOperation<>("[nin]"); + public static final QueryOperation HasAllOf = new QueryOperation<>("[all]"); - public static final QueryOperation IsLessThan = new QueryOperation("[lt]"); + public static final QueryOperation IsLessThan = new QueryOperation<>("[lt]"); public static final QueryOperation IsLessThanOrEqualTo - = new QueryOperation("[lte]"); - public static final QueryOperation IsGreaterThan = new QueryOperation("[gt]"); + = new QueryOperation<>("[lte]"); + public static final QueryOperation IsGreaterThan = new QueryOperation<>("[gt]"); public static final QueryOperation IsGreaterThanOrEqualTo - = new QueryOperation("[gte]"); + = new QueryOperation<>("[gte]"); - public static final QueryOperation Exists = new QueryOperation("[exists]" - , true); + public static final QueryOperation Exists = new QueryOperation<>("[exists]", true); - public static final QueryOperation IsEarlierThan = new QueryOperation("[lt]"); - public static final QueryOperation IsEarlierOrAt = new QueryOperation("[lte]"); - public static final QueryOperation IsLaterThan = new QueryOperation("[gt]"); - public static final QueryOperation IsLaterOrAt = new QueryOperation("[gte]"); + public static final QueryOperation IsEarlierThan = new QueryOperation<>("[lt]"); + public static final QueryOperation IsEarlierOrAt = new QueryOperation<>("[lte]"); + public static final QueryOperation IsLaterThan = new QueryOperation<>("[gt]"); + public static final QueryOperation IsLaterOrAt = new QueryOperation<>("[gte]"); - public static final QueryOperation Matches = new QueryOperation("[match]"); + public static final QueryOperation Matches = new QueryOperation<>("[match]"); - public static final QueryOperation IsCloseTo = new QueryOperation("[near]"); + public static final QueryOperation IsCloseTo = new QueryOperation<>("[near]"); public static final QueryOperation IsWithinBoundingBoxOf - = new QueryOperation("[within]"); + = new QueryOperation<>("[within]"); public static final QueryOperation IsWithinCircleOf - = new QueryOperation("[within]"); + = new QueryOperation<>("[within]"); final String operator; final T defaultValue; diff --git a/src/main/java/com/contentful/java/cda/ResourceFactory.java b/src/main/java/com/contentful/java/cda/ResourceFactory.java index 747404e2..6aced5af 100644 --- a/src/main/java/com/contentful/java/cda/ResourceFactory.java +++ b/src/main/java/com/contentful/java/cda/ResourceFactory.java @@ -13,6 +13,8 @@ import retrofit2.Response; +import static com.contentful.java.cda.rich.RichTextFactory.resolveRichTextField; + final class ResourceFactory { private ResourceFactory() { throw new AssertionError(); @@ -22,19 +24,20 @@ private ResourceFactory() { static CDAArray array(Response arrayResponse, CDAClient client) { CDAArray array = arrayResponse.body(); - array.assets = new LinkedHashMap(); - array.entries = new LinkedHashMap(); + array.assets = new LinkedHashMap<>(); + array.entries = new LinkedHashMap<>(); Set resources = collectResources(array); ResourceUtils.localizeResources(resources, client.cache); ResourceUtils.mapResources(resources, array.assets, array.entries); ResourceUtils.setRawFields(array); + resolveRichTextField(array, client); ResourceUtils.resolveLinks(array, client); return array; } private static Set collectResources(CDAArray array) { - Set resources = new LinkedHashSet(array.items()); + Set resources = new LinkedHashSet<>(array.items()); if (array.includes != null) { if (array.includes.assets != null) { resources.addAll(array.includes.assets); @@ -50,8 +53,8 @@ static SynchronizedSpace sync( Response newSpace, SynchronizedSpace oldSpace, CDAClient client) { - Map assets = new HashMap(); - Map entries = new HashMap(); + Map assets = new HashMap<>(); + Map entries = new HashMap<>(); // Map resources from existing space if (oldSpace != null) { @@ -62,7 +65,7 @@ static SynchronizedSpace sync( ResourceUtils.mapResources(result.items(), assets, entries); ResourceUtils.mapDeletedResources(result); - List items = new ArrayList(); + List items = new ArrayList<>(); items.addAll(assets.values()); items.addAll(entries.values()); result.items = items; @@ -70,6 +73,7 @@ static SynchronizedSpace sync( result.entries = entries; ResourceUtils.setRawFields(result); + resolveRichTextField(result, client); ResourceUtils.resolveLinks(result, client); return result; @@ -81,7 +85,7 @@ static T fromResponse(Response response) { @SuppressWarnings("unchecked") static List fromArrayToItems(CDAArray array) { - final List result = new ArrayList(array.items.size()); + final List result = new ArrayList<>(array.items.size()); for (CDAResource resource : array.items) { result.add((T) resource); diff --git a/src/main/java/com/contentful/java/cda/ResourceUtils.java b/src/main/java/com/contentful/java/cda/ResourceUtils.java index 3a88dc02..99781348 100644 --- a/src/main/java/com/contentful/java/cda/ResourceUtils.java +++ b/src/main/java/com/contentful/java/cda/ResourceUtils.java @@ -9,8 +9,6 @@ import java.util.Set; import io.reactivex.Flowable; -import io.reactivex.functions.Consumer; -import io.reactivex.functions.Predicate; import retrofit2.Response; import static com.contentful.java.cda.CDAType.ASSET; @@ -21,7 +19,7 @@ import static com.contentful.java.cda.Util.extractNested; import static com.contentful.java.cda.Util.queryParam; -final class ResourceUtils { +public final class ResourceUtils { private ResourceUtils() { throw new AssertionError(); } @@ -74,7 +72,7 @@ static void resolveLinks(ArrayResource array, CDAClient client) { } } - static void ensureContentType(CDAEntry entry, CDAClient client) { + public static void ensureContentType(CDAEntry entry, CDAClient client) { CDAContentType contentType = entry.contentType(); if (contentType != null) { return; @@ -103,9 +101,9 @@ static void resolveArrayOfLinks(CDAEntry entry, CDAField field, ArrayResource ar if (links == null) { continue; } - List resolved = new ArrayList(); - for (int i = 0; i < links.size(); i++) { - String linkId = getLinkId(links.get(i)); + List resolved = new ArrayList<>(); + for (final Object link : links) { + String linkId = getLinkId(link); if (linkId == null) { continue; } @@ -125,7 +123,7 @@ static void resolveSingleLink(CDAEntry entry, CDAField field, ArrayResource arra if (value == null) { return; } - Set toRemove = new HashSet(); + Set toRemove = new HashSet<>(); for (String locale : value.keySet()) { String linkId = getLinkId(value.get(locale)); if (linkId == null) { @@ -184,32 +182,28 @@ static void mapResources(Collection resources, static void mapDeletedResources(SynchronizedSpace space) { final Set assets; if (space.deletedAssets == null) { - assets = new HashSet(); + assets = new HashSet<>(); } else { - assets = new HashSet(space.deletedAssets); + assets = new HashSet<>(space.deletedAssets); } final Set entries; if (space.deletedEntries == null) { - entries = new HashSet(); + entries = new HashSet<>(); } else { - entries = new HashSet(space.deletedEntries); + entries = new HashSet<>(space.deletedEntries); } Flowable.fromIterable(space.items()) - .filter(new Predicate() { - @Override public boolean test(CDAResource resource) { - CDAType type = resource.type(); - return DELETEDASSET.equals(type) || DELETEDENTRY.equals(type); - } + .filter(resource -> { + CDAType type = resource.type(); + return DELETEDASSET.equals(type) || DELETEDENTRY.equals(type); }) - .subscribe(new Consumer() { - @Override public void accept(CDAResource resource) { - if (DELETEDASSET.equals(resource.type())) { - assets.add(resource.id()); - } else { - entries.add(resource.id()); - } + .subscribe(resource -> { + if (DELETEDASSET.equals(resource.type())) { + assets.add(resource.id()); + } else { + entries.add(resource.id()); } }); space.deletedAssets = assets; @@ -239,7 +233,7 @@ static void localize(LocalizedResource resource, Cache cache) { } private static Map getFallbackLocaleMap(Cache cache) { - final Map fallbackLocales = new HashMap(cache.locales().size()); + final Map fallbackLocales = new HashMap<>(cache.locales().size()); for (final CDALocale locale : cache.locales()) { final String fallback = locale.fallbackLocaleCode(); @@ -252,7 +246,7 @@ private static Map getFallbackLocaleMap(Cache cache) { } static void normalizeFields(LocalizedResource resource) { - Map fields = new HashMap(); + Map fields = new HashMap<>(); for (String key : resource.fields.keySet()) { Object value = resource.fields.get(key); if (value == null) { @@ -260,7 +254,7 @@ static void normalizeFields(LocalizedResource resource) { } else if (resourceContainsLocaleMap(resource, value)) { fields.put(key, value); } else { - Map map = new HashMap(); + Map map = new HashMap<>(); map.put(resource.defaultLocale, value); fields.put(key, map); } @@ -284,10 +278,9 @@ static void setRawFields(ArrayResource array) { @SuppressWarnings("unchecked") private static void setRawFields(LocalizedResource resource) { - Map rawFields = new HashMap(); + Map rawFields = new HashMap<>(); for (String key : resource.fields.keySet()) { - Map map = new HashMap(); - map.putAll((Map) resource.fields.get(key)); + Map map = new HashMap<>((Map) resource.fields.get(key)); rawFields.put(key, map); } resource.rawFields = rawFields; diff --git a/src/main/java/com/contentful/java/cda/SyncQuery.java b/src/main/java/com/contentful/java/cda/SyncQuery.java index e81c71e2..91af8bba 100644 --- a/src/main/java/com/contentful/java/cda/SyncQuery.java +++ b/src/main/java/com/contentful/java/cda/SyncQuery.java @@ -1,8 +1,6 @@ package com.contentful.java.cda; import io.reactivex.Flowable; -import io.reactivex.functions.Function; -import retrofit2.Response; import static com.contentful.java.cda.Util.checkNotNull; @@ -46,20 +44,15 @@ public Flowable observe() { token = syncToken; } return client.cacheAll(true) - .flatMap(new Function>>() { - @Override public Flowable> apply(Cache cache) { - return client.service.sync( - client.spaceId, - client.environmentId, - initial ? initial : null, token, - initial && type != null ? type.getName() : null, - initial && type != null ? type.getContentType() : null); - } - }).map(new Function, SynchronizedSpace>() { - @Override public SynchronizedSpace apply(Response synchronizedSpace) { - return ResourceFactory.sync(synchronizedSpace, space, client); - } - }); + .flatMap(cache -> client.service.sync( + client.spaceId, + client.environmentId, + initial ? initial : null, + token, + initial && type != null ? type.getName() : null, + initial && type != null ? type.getContentType() : null)).map( + synchronizedSpace -> ResourceFactory.sync(synchronizedSpace, space, client) + ); } /** diff --git a/src/main/java/com/contentful/java/cda/SyncType.java b/src/main/java/com/contentful/java/cda/SyncType.java index 09553aeb..06f96154 100644 --- a/src/main/java/com/contentful/java/cda/SyncType.java +++ b/src/main/java/com/contentful/java/cda/SyncType.java @@ -39,8 +39,8 @@ public enum Type { DeletedEntry } - Type type; - String contentType; + final Type type; + final String contentType; SyncType(Type type, String contentType) { this.type = type; diff --git a/src/main/java/com/contentful/java/cda/SynchronizedSpace.java b/src/main/java/com/contentful/java/cda/SynchronizedSpace.java index 25d39af6..ee03031c 100644 --- a/src/main/java/com/contentful/java/cda/SynchronizedSpace.java +++ b/src/main/java/com/contentful/java/cda/SynchronizedSpace.java @@ -6,6 +6,7 @@ * Represents results for synchronization via the Sync API. */ public class SynchronizedSpace extends ArrayResource { + private static final long serialVersionUID = 8618757744312417604L; String nextPageUrl; String nextSyncUrl; diff --git a/src/main/java/com/contentful/java/cda/TlsSocketFactory.java b/src/main/java/com/contentful/java/cda/TlsSocketFactory.java index fbbeb346..bd6809d6 100644 --- a/src/main/java/com/contentful/java/cda/TlsSocketFactory.java +++ b/src/main/java/com/contentful/java/cda/TlsSocketFactory.java @@ -66,7 +66,7 @@ public Socket createSocket(InetAddress address, int port, InetAddress localAddre } private Socket enableTlsOnSocket(Socket socket) { - if (socket != null && (socket instanceof SSLSocket)) { + if (socket instanceof SSLSocket) { ((SSLSocket) socket).setEnabledProtocols(PROTOCOLS_TLS_1_2_ONLY); } return socket; diff --git a/src/main/java/com/contentful/java/cda/interceptor/ContentfulUserAgentHeaderInterceptor.java b/src/main/java/com/contentful/java/cda/interceptor/ContentfulUserAgentHeaderInterceptor.java index 97134299..7a13282d 100644 --- a/src/main/java/com/contentful/java/cda/interceptor/ContentfulUserAgentHeaderInterceptor.java +++ b/src/main/java/com/contentful/java/cda/interceptor/ContentfulUserAgentHeaderInterceptor.java @@ -362,7 +362,7 @@ private static Section[] checkSections(Section[] sections) { private static String sectionsToString(Section[] sections) { // take last section of same identifier - final LinkedHashMap mappedSections = new LinkedHashMap(); + final LinkedHashMap mappedSections = new LinkedHashMap<>(); for (final Section section : sections) { if (section != null) { final String identifier = section.getIdentifier(); diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichBlock.java b/src/main/java/com/contentful/java/cda/rich/CDARichBlock.java new file mode 100644 index 00000000..a449caae --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichBlock.java @@ -0,0 +1,18 @@ +package com.contentful.java.cda.rich; + +import java.util.LinkedList; +import java.util.List; + +/** + * A collection of several nodes. + */ +public class CDARichBlock extends CDARichNode { + final List content = new LinkedList<>(); + + /** + * @return a changeable list of contents of this block + */ + public List getContent() { + return content; + } +} diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichDocument.java b/src/main/java/com/contentful/java/cda/rich/CDARichDocument.java new file mode 100644 index 00000000..d87fbf28 --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichDocument.java @@ -0,0 +1,7 @@ +package com.contentful.java.cda.rich; + +/** + * The base of a rich text field, containing all the other nodes. + */ +public class CDARichDocument extends CDARichBlock { +} diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichEmbeddedLink.java b/src/main/java/com/contentful/java/cda/rich/CDARichEmbeddedLink.java new file mode 100644 index 00000000..d29b7e83 --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichEmbeddedLink.java @@ -0,0 +1,17 @@ +package com.contentful.java.cda.rich; + +/** + * This node is an inline link to a CDAEntry + * + * @see com.contentful.java.cda.CDAEntry + */ +public class CDARichEmbeddedLink extends CDARichHyperLink { + /** + * Create a link pointing to a CDAEntry. + * + * @param target an entry to be pointed to. + */ + public CDARichEmbeddedLink(Object target) { + super(target); + } +} diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichHeading.java b/src/main/java/com/contentful/java/cda/rich/CDARichHeading.java new file mode 100644 index 00000000..ba99e9c1 --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichHeading.java @@ -0,0 +1,26 @@ +package com.contentful.java.cda.rich; + +/** + * Defines a headline of the text. + *

+ * Can have an arbitrary level assigned, but useful probably between 1 and 6. + */ +public class CDARichHeading extends CDARichBlock { + private final int level; + + /** + * Create a heading block, describing a level elements deep nested heading. + * + * @param level a number indicating the level of this heading. + */ + public CDARichHeading(int level) { + this.level = level; + } + + /** + * @return the current nesting level of this heading. + */ + public int getLevel() { + return level; + } +} diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichHorizontalRule.java b/src/main/java/com/contentful/java/cda/rich/CDARichHorizontalRule.java new file mode 100644 index 00000000..c788cf60 --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichHorizontalRule.java @@ -0,0 +1,12 @@ +package com.contentful.java.cda.rich; + +/** + * A node representing a division, called a horizontal rule. + */ +public class CDARichHorizontalRule extends CDARichNode { + /** + * Construct this node. + */ + public CDARichHorizontalRule() { + } +} diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichHyperLink.java b/src/main/java/com/contentful/java/cda/rich/CDARichHyperLink.java new file mode 100644 index 00000000..5b012da4 --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichHyperLink.java @@ -0,0 +1,24 @@ +package com.contentful.java.cda.rich; + +/** + * This block represents a link to a website. + */ +public class CDARichHyperLink extends CDARichBlock { + Object data; + + /** + * Create a new hyper link. + * + * @param target point to the target. + */ + public CDARichHyperLink(Object target) { + this.data = target; + } + + /** + * @return the target this link points to. + */ + public Object getData() { + return data; + } +} diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichList.java b/src/main/java/com/contentful/java/cda/rich/CDARichList.java new file mode 100644 index 00000000..022524bd --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichList.java @@ -0,0 +1,28 @@ +package com.contentful.java.cda.rich; + +/** + * Parent class for all list classes + */ +public class CDARichList extends CDARichBlock { + final CharSequence decoration; + + /** + * Create a list of the given symbols per nesting level + * + * @param decoration a symbol to be added for differentiation. Can be [1,A,a,I,i] for + * prefixing each node with an arabic number (1., 2., …), a capitalized letter + * (A., B., …), a lowercase letter (a., b., …) or roman numerals in capital + * (I, II, …) or non capitalized form (i, ii, …). Alternatively unordered + * symbols can be used: `*` for bullets, `-` for dashes and `⭐` for stars etc. + */ + public CDARichList(CharSequence decoration) { + this.decoration = decoration; + } + + /** + * @return decoration for this list. + */ + public CharSequence getDecoration() { + return decoration; + } +} diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichListItem.java b/src/main/java/com/contentful/java/cda/rich/CDARichListItem.java new file mode 100644 index 00000000..4818321b --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichListItem.java @@ -0,0 +1,7 @@ +package com.contentful.java.cda.rich; + +/** + * A block representing an item inside a list. + */ +public class CDARichListItem extends CDARichBlock { +} diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichMark.java b/src/main/java/com/contentful/java/cda/rich/CDARichMark.java new file mode 100644 index 00000000..9ffc26f1 --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichMark.java @@ -0,0 +1,55 @@ +package com.contentful.java.cda.rich; + +/** + * How to draw a given text. + *

+ * Subclasses are used for further differentiation. + */ +public class CDARichMark { + /** + * A bold mark of a rich text. + */ + public static class CDARichMarkBold extends CDARichMark { + } + + /** + * Declares the text as being displayed in italics. + */ + public static class CDARichMarkItalic extends CDARichMark { + } + + /** + * Marker for making the rich text displayed as underline. + */ + public static class CDARichMarkUnderline extends CDARichMark { + } + + /** + * The text marked by this marker should be represented by Code. + */ + public static class CDARichMarkCode extends CDARichMark { + } + + /** + * Any custom marker for a given rich text. + */ + public static class CDARichMarkCustom extends CDARichMark { + private final String type; + + /** + * Create a custom marker using the given type. + * + * @param type which type should this marker have? + */ + public CDARichMarkCustom(String type) { + this.type = type; + } + + /** + * @return the custom type of the marker. + */ + public String getType() { + return type; + } + } +} diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichNode.java b/src/main/java/com/contentful/java/cda/rich/CDARichNode.java new file mode 100644 index 00000000..22a30c76 --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichNode.java @@ -0,0 +1,7 @@ +package com.contentful.java.cda.rich; + +/** + * A leaf node of the rich text hierarchy. + */ +public class CDARichNode { +} diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichOrderedList.java b/src/main/java/com/contentful/java/cda/rich/CDARichOrderedList.java new file mode 100644 index 00000000..931b44b3 --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichOrderedList.java @@ -0,0 +1,13 @@ +package com.contentful.java.cda.rich; + +/** + * A list of elements, ordered by number. + */ +public class CDARichOrderedList extends CDARichList { + /** + * Create a list with numbers. + */ + public CDARichOrderedList() { + super("1"); + } +} diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichParagraph.java b/src/main/java/com/contentful/java/cda/rich/CDARichParagraph.java new file mode 100644 index 00000000..f56b1238 --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichParagraph.java @@ -0,0 +1,7 @@ +package com.contentful.java.cda.rich; + +/** + * A paragraph of nodes, usually rendered together. + */ +public class CDARichParagraph extends CDARichBlock { +} diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichQuote.java b/src/main/java/com/contentful/java/cda/rich/CDARichQuote.java new file mode 100644 index 00000000..3a9bec84 --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichQuote.java @@ -0,0 +1,7 @@ +package com.contentful.java.cda.rich; + +/** + * A block of nodes rendered as a direct quote. + */ +public class CDARichQuote extends CDARichBlock { +} diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichText.java b/src/main/java/com/contentful/java/cda/rich/CDARichText.java new file mode 100644 index 00000000..b98a81a2 --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichText.java @@ -0,0 +1,43 @@ +package com.contentful.java.cda.rich; + +import java.util.ArrayList; +import java.util.List; + +/** + * A leaf element of the rich text node graph: Render a given text with the given markings. + */ +public class CDARichText extends CDARichNode { + private final List marks = new ArrayList<>(); + private final CharSequence text; + + /** + * Create a text with the given marks + * + * @param text the text to be displayed + * @param marks the marks to be used if any + */ + public CDARichText(CharSequence text, List marks) { + if (text == null) { + text = ""; + } + + this.marks.addAll(marks); + this.text = text; + } + + /** + * @return the text of this node. + */ + public CharSequence getText() { + return text; + } + + /** + * @return the marks of this text. + * + * @see CDARichMark.CDARichMarkBold + */ + public List getMarks() { + return marks; + } +} diff --git a/src/main/java/com/contentful/java/cda/rich/CDARichUnorderedList.java b/src/main/java/com/contentful/java/cda/rich/CDARichUnorderedList.java new file mode 100644 index 00000000..8838e4c2 --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/CDARichUnorderedList.java @@ -0,0 +1,13 @@ +package com.contentful.java.cda.rich; + +/** + * Representation of a block of unordered items. + */ +public class CDARichUnorderedList extends CDARichList { + /** + * Create a list with bullet points. + */ + public CDARichUnorderedList() { + super("*"); + } +} diff --git a/src/main/java/com/contentful/java/cda/rich/RichTextFactory.java b/src/main/java/com/contentful/java/cda/rich/RichTextFactory.java new file mode 100644 index 00000000..dbec1932 --- /dev/null +++ b/src/main/java/com/contentful/java/cda/rich/RichTextFactory.java @@ -0,0 +1,344 @@ +package com.contentful.java.cda.rich; + +import com.contentful.java.cda.ArrayResource; +import com.contentful.java.cda.CDAClient; +import com.contentful.java.cda.CDAEntry; +import com.contentful.java.cda.CDAField; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + +import static com.contentful.java.cda.ResourceUtils.ensureContentType; + +/** + * This factory will be used in order to create the {@link CDARichNode}-graph representation of + * the Contentful data returned by a rich text - field. + */ +@SuppressWarnings("unchecked") +public class RichTextFactory { + private static final int HEADING_LEVEL_1 = 1; + private static final int HEADING_LEVEL_2 = 2; + private static final int HEADING_LEVEL_3 = 3; + private static final int HEADING_LEVEL_4 = 4; + private static final int HEADING_LEVEL_5 = 5; + private static final int HEADING_LEVEL_6 = 6; + + /** + * Interface for resolving the type of a node by its raw representation. + */ + private interface Resolver { + CDARichNode resolve(Map raw); + } + + /** + * Resolves a block of rich text + * + * @param a block to be resolved. + */ + private static class BlockResolver implements Resolver { + final Supplier supplier; + + /** + * Create a block resolver based on its given supplier. + * + * @param supplier an object to create more objects of type T. + */ + BlockResolver(Supplier supplier) { + this.supplier = supplier; + } + + /** + * This method is called in order to try to create rich text block node from a raw map + * representation. + * + * @param raw representation of the block node coming from Contentful. + * @return the rich node if resolving was successful. + */ + @Override public CDARichNode resolve(Map raw) { + final T resolved = getCDAType(raw); + + final List> contents = (List>) raw.get("content"); + for (final Map rawNode : contents) { + final CDARichNode resolvedNode = resolveRichNode(rawNode); + if (resolvedNode != null) { + resolved.content.add(resolvedNode); + } + } + return resolved; + } + + /** + * Convenience method to try and find out the type of the given raw map representation. + * + * @param raw a map coming from Contentful, parsed from the json response. + * @return a new node based on the type of T. + */ + T getCDAType(Map raw) { + return supplier.get(); + } + } + + /** + * Resolve only headings from Contentful. + */ + private static class HeadingResolver extends BlockResolver { + final int level; + + /** + * Create resolver using the given heading. + * + * @param level the level of the headings nesting. Should be positive and less then 7. + */ + HeadingResolver(int level) { + super(() -> new CDARichHeading(level)); + this.level = level; + } + } + + /** + * Simple interface for providing an instance based on a type. + * + * @param the type an instance should be created for. + */ + private interface SupplierWithData { + /** + * Create an object of type T. + * + * @param data the initialization data needed. + * @return An instance of type T. + */ + T get(Object data); + } + + /** + * Resolves a block containing more data. + * + * @param Which type should the block be? + */ + private static class BlockAndDataResolver + extends BlockResolver { + final SupplierWithData supplier; + final String dataFieldKey; + + /** + * Create the resolver. + * + * @param supplier how to generate an object of type T? + * @param dataFieldKey what other keys to be filtered? + */ + BlockAndDataResolver(SupplierWithData supplier, String dataFieldKey) { + super(null); + this.supplier = supplier; + this.dataFieldKey = dataFieldKey; + } + + /** + * Create an object of T + * + * @param raw a map coming from Contentful, parsed from the json response. + * @return an object of Type T. + */ + @Override + T getCDAType(Map raw) { + return supplier.get(raw.get(dataFieldKey)); + } + } + + private static final Map RESOLVER_MAP = new HashMap<>(); + + static { + // add leafs + RESOLVER_MAP.put("text", raw -> new CDARichText( + (CharSequence) raw.get("value"), + resolveMarks((List>) raw.get("marks")) + )); + RESOLVER_MAP.put("hr", raw -> new CDARichHorizontalRule()); + + // add blocks + RESOLVER_MAP.put("blockquote", new BlockResolver<>(CDARichQuote::new)); + RESOLVER_MAP.put("paragraph", new BlockResolver<>(CDARichParagraph::new)); + RESOLVER_MAP.put("document", new BlockResolver<>(CDARichDocument::new)); + RESOLVER_MAP.put("list-item", new BlockResolver<>(CDARichListItem::new)); + RESOLVER_MAP.put("ordered-list", new BlockResolver<>(CDARichOrderedList::new)); + RESOLVER_MAP.put("unordered-list", new BlockResolver<>(CDARichUnorderedList::new)); + RESOLVER_MAP.put("hyperlink", new BlockAndDataResolver<>(CDARichHyperLink::new, "data")); + RESOLVER_MAP.put("embedded-entry-block", + new BlockAndDataResolver<>(CDARichEmbeddedLink::new, "data")); + RESOLVER_MAP.put("heading-1", new HeadingResolver(HEADING_LEVEL_1)); + RESOLVER_MAP.put("heading-2", new HeadingResolver(HEADING_LEVEL_2)); + RESOLVER_MAP.put("heading-3", new HeadingResolver(HEADING_LEVEL_3)); + RESOLVER_MAP.put("heading-4", new HeadingResolver(HEADING_LEVEL_4)); + RESOLVER_MAP.put("heading-5", new HeadingResolver(HEADING_LEVEL_5)); + RESOLVER_MAP.put("heading-6", new HeadingResolver(HEADING_LEVEL_6)); + } + + /** + * Walk through the given array and resolve all rich text fields. + * + * @param array the array to be walked. + * @param client the client to be used if updating of types is needed. + */ + public static void resolveRichTextField(ArrayResource array, CDAClient client) { + for (CDAEntry entry : array.entries().values()) { + ensureContentType(entry, client); + for (CDAField field : entry.contentType().fields()) { + if ("RichText".equals(field.type())) { + resolveRichDocument(entry, field); + resolveRichLink(array, entry, field); + } + } + } + } + + /** + * Resolve all children of the top most document block. + * + * @param entry the entry to contain the field to be walked + * @param field the id of the field to be walked. + */ + @SuppressWarnings("unchecked") + private static void resolveRichDocument(CDAEntry entry, CDAField field) { + final Map rawValue = (Map) entry.rawFields().get(field.id()); + if (rawValue == null) { + return; + } + + for (final String locale : rawValue.keySet()) { + final Map raw = (Map) rawValue.get(locale); + if (raw == null) { + continue; + } + + entry.setField(locale, field.id(), RESOLVER_MAP.get("document").resolve(raw)); + } + } + + /** + * Specific method for resolving rich text marks. + * + * @param rawMarks the json responded map from Contentful + * @return objectified and parsed objects. + */ + static List resolveMarks(List> rawMarks) { + final List marks = new ArrayList<>(rawMarks.size()); + for (final Map rawMark : rawMarks) { + final String type = (String) rawMark.get("type"); + if ("bold".equals(type)) { + marks.add(new CDARichMark.CDARichMarkBold()); + } else if ("italic".equals(type)) { + marks.add(new CDARichMark.CDARichMarkItalic()); + } else if ("underline".equals(type)) { + marks.add(new CDARichMark.CDARichMarkUnderline()); + } else if ("code".equals(type)) { + marks.add(new CDARichMark.CDARichMarkCode()); + } else { + marks.add(new CDARichMark.CDARichMarkCustom(type)); + } + } + return marks; + } + + /** + * Resolve one node. + * + * @param rawNode the map response from Contentful + * @return a CDARichNode from this SDK. + */ + static CDARichNode resolveRichNode(Map rawNode) { + final String type = (String) rawNode.get("nodeType"); + if (RESOLVER_MAP.containsKey(type)) { + return RESOLVER_MAP.get(type).resolve(rawNode); + } else { + return null; + } + } + + /** + * Resolve all links if possible. If linked to entry is not found, null it's field. + * + * @param array the array containing the complete response + * @param entry the entry to be completed. + * @param field the field pointing to a link. + */ + private static void resolveRichLink(ArrayResource array, CDAEntry entry, CDAField field) { + final Map rawValue = (Map) entry.rawFields().get(field.id()); + if (rawValue == null) { + return; + } + + for (final String locale : rawValue.keySet()) { + final CDARichDocument document = entry.getField(locale, field.id()); + for (final CDARichNode node : document.getContent()) { + resolveOneLink(array, field, locale, node); + } + } + } + + /** + * Link found, resolve it. + * + * @param array the complete response from Contentful. + * @param field the field containing a link. + * @param locale the locale of the link to be updated. + * @param node the node build from the response. + */ + private static void resolveOneLink(ArrayResource array, CDAField field, String locale, + CDARichNode node) { + if (node instanceof CDARichHyperLink) { + final CDARichHyperLink link = (CDARichHyperLink) node; + final Map data = (Map) link.data; + final Object target = data.get("target"); + + if (target instanceof Map) { + if (isLink(target)) { + final Map map = (Map) target; + final Map sys = (Map) map.get("sys"); + final String linkType = (String) sys.get("linkType"); + final String id = (String) sys.get("id"); + + if ("Asset".equals(linkType)) { + link.data = array.assets().get(id); + } else if ("Entry".equals(linkType)) { + link.data = array.entries().get(id); + } + + } else { + throw new IllegalStateException("Could not parse content of data field '" + + field.id() + "' for locale '" + locale + "' at node '" + node + + "'. Please check your content type model."); + } + } else if (target == null && data.containsKey("uri")) { + link.data = data.get("uri"); + } + } else if (node instanceof CDARichParagraph) { + for (final CDARichNode child : ((CDARichParagraph) node).getContent()) { + resolveOneLink(array, field, locale, child); + } + } + } + + /** + * Is the give object a link of any kind? + */ + private static boolean isLink(Object data) { + try { + final Map map = (Map) data; + final Map sys = (Map) map.get("sys"); + final String type = (String) sys.get("type"); + final String linkType = (String) sys.get("linkType"); + final String id = (String) sys.get("id"); + + if ("Link".equals(type) + && ("Entry".equals(linkType) || "Asset".equals(linkType) + && id != null)) { + return true; + } + } catch (ClassCastException cast) { + return false; + } + return false; + } +} \ No newline at end of file diff --git a/src/test/bash/create_folders.sh b/src/test/bash/create_folders.sh new file mode 100755 index 00000000..ca85f6b7 --- /dev/null +++ b/src/test/bash/create_folders.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +mkdir --parents ../resources/rich_text diff --git a/src/test/bash/create_recordings.sh b/src/test/bash/create_recordings.sh new file mode 100755 index 00000000..69545a65 --- /dev/null +++ b/src/test/bash/create_recordings.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +echo $0 + + +for i in *.sh; do + if [ "$(basename $0)" != "$i" ]; then + echo "Executing $i" + ./${i} + fi +done diff --git a/src/test/bash/rich_text-all.sh b/src/test/bash/rich_text-all.sh new file mode 100755 index 00000000..6dc257b4 --- /dev/null +++ b/src/test/bash/rich_text-all.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +folder="../resources/$(basename $(echo $0) | cut -d'-' -f1)" +file="$(basename $0 | cut -d'-' -f2)" + +mkdir --parent ${folder} + +for id in $(curl \ + --silent \ + -H "Authorization: Bearer ${RICH_TEXT_DELIVERY_TOKEN}" \ + "https://cdn.contentful.com/spaces/${RICH_TEXT_SPACE_ID}/entries?content_type=rich&select=sys.id" \ + | grep id | cut -d'"' -f4); do + name="$(curl \ + --silent \ + -H "Authorization: Bearer ${RICH_TEXT_DELIVERY_TOKEN}" \ + "https://cdn.contentful.com/spaces/${RICH_TEXT_SPACE_ID}/entries?content_type=rich&sys.id=${id}&select=fields.name" \ + | grep name | cut -d'"' -f4)" + output="$(echo ${folder}/${name}.json)" + echo ${name} + + curl --silent \ + -H "Authorization: Bearer ${RICH_TEXT_DELIVERY_TOKEN}" \ + "https://cdn.contentful.com/spaces/${RICH_TEXT_SPACE_ID}/entries?sys.id=${id}" \ + | sed 's/'${RICH_TEXT_SPACE_ID}'//g' \ + | sed 's/'${RICH_TEXT_DELIVERY_TOKEN}'//g' \ + | tee ${output} +done diff --git a/src/test/bash/rich_text-content_types.sh b/src/test/bash/rich_text-content_types.sh new file mode 100755 index 00000000..a786b05c --- /dev/null +++ b/src/test/bash/rich_text-content_types.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +folder="../resources/$(basename $(echo $0) | cut -d'-' -f1)" +file="$(basename $0 | cut -d'-' -f2)" +output="$(echo ${folder}/${file} | sed 's#sh#json#g')" + +mkdir --parent ${folder} +touch ${output} + +curl --verbose \ + -H 'Authorization: Bearer '${RICH_TEXT_DELIVERY_TOKEN} \ + 'https://cdn.contentful.com/spaces/'${RICH_TEXT_SPACE_ID}'/content_types' \ + | sed 's/'${RICH_TEXT_SPACE_ID}'//g' \ + | sed 's/'${RICH_TEXT_DELIVERY_TOKEN}'//g' \ + | tee ${output} diff --git a/src/test/bash/rich_text-locales.sh b/src/test/bash/rich_text-locales.sh new file mode 100755 index 00000000..2a92f7d5 --- /dev/null +++ b/src/test/bash/rich_text-locales.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +folder="../resources/$(basename $(echo $0) | cut -d'-' -f1)" +file="$(basename $0 | cut -d'-' -f2)" +output="$(echo ${folder}/${file} | sed 's#sh#json#g')" + +mkdir --parent ${folder} +touch ${output} + +curl --verbose \ + -H 'Authorization: Bearer '${RICH_TEXT_DELIVERY_TOKEN} \ + 'https://cdn.contentful.com/spaces/'${RICH_TEXT_SPACE_ID}'/locales' \ + | sed 's/'${RICH_TEXT_SPACE_ID}'//g' \ + | sed 's/'${RICH_TEXT_DELIVERY_TOKEN}'//g' \ + | tee ${output} diff --git a/src/test/java/com/contentful/java/cda/AbsQueryTest.java b/src/test/java/com/contentful/java/cda/AbsQueryTest.java index 91114ed0..8468c6a0 100644 --- a/src/test/java/com/contentful/java/cda/AbsQueryTest.java +++ b/src/test/java/com/contentful/java/cda/AbsQueryTest.java @@ -43,24 +43,24 @@ public class AbsQueryTest { @Before public void setup() { - query = new FetchQuery(CDAResource.class, client); + query = new FetchQuery<>(CDAResource.class, client); } @Test - public void contentType() throws Exception { + public void contentType() { query.withContentType("foo"); assertThat(query.params).containsEntry("content_type", "foo"); } @Test(expected = IllegalStateException.class) - public void settingContentTypeTwiceThrows() throws Exception { + public void settingContentTypeTwiceThrows() { query.withContentType("foo"); query.withContentType("bar"); } @Test - public void select() throws Exception { + public void select() { query.withContentType("foo"); query.select("fields.bar"); @@ -68,19 +68,19 @@ public void select() throws Exception { } @Test(expected = IllegalStateException.class) - public void selectWithoutContentTypeThrows() throws Exception { + public void selectWithoutContentTypeThrows() { query.select("fields.bar"); } @Test - public void selectWithSys() throws Exception { + public void selectWithSys() { query.select("sys"); assertThat(query.params).containsEntry("select", "sys"); } @Test - public void selectWithSysAndFields() throws Exception { + public void selectWithSysAndFields() { query.withContentType("foo"); query.select("sys"); query.select("fields.bar"); @@ -89,18 +89,18 @@ public void selectWithSysAndFields() throws Exception { } @Test(expected = IllegalArgumentException.class) - public void emptySelectThrows() throws Exception { + public void emptySelectThrows() { query.withContentType("foo"); query.select(); } @Test(expected = IllegalArgumentException.class) - public void selectWithEmptyNameThrows() throws Exception { + public void selectWithEmptyNameThrows() { query.select(""); } @Test - public void selectDifferentFieldNames() throws Exception { + public void selectDifferentFieldNames() { query.withContentType("foo"); query.select("fields.bar"); query.select("fields.bar2"); @@ -109,13 +109,13 @@ public void selectDifferentFieldNames() throws Exception { } @Test(expected = IllegalArgumentException.class) - public void selectWithToManyLevelsThrows() throws Exception { + public void selectWithToManyLevelsThrows() { query.withContentType("foo"); query.select("fields.baz.bar"); } @Test - public void selects() throws Exception { + public void selects() { query.withContentType("foo"); query.select("fields.bar", "fields.bar2"); @@ -123,32 +123,32 @@ public void selects() throws Exception { } @Test - public void linksToEntryId() throws Exception { + public void linksToEntryId() { query.linksToEntryId("nyancat"); assertThat(query.params).containsEntry("links_to_entry", "nyancat"); } @Test - public void linksToAssetId() throws Exception { + public void linksToAssetId() { query.linksToAssetId("nyancat"); assertThat(query.params).containsEntry("links_to_asset", "nyancat"); } @Test(expected = IllegalStateException.class) - public void selectsWithoutTypeThrows() throws Exception { + public void selectsWithoutTypeThrows() { query.select("fields.bar", "fields.bar2"); } @Test(expected = IllegalArgumentException.class) - public void selectsWithoutFieldNames() throws Exception { + public void selectsWithoutFieldNames() { query.withContentType("foo"); query.select(); } @Test(expected = IllegalArgumentException.class) - public void selectsWithoutNullEntry() throws Exception { + public void selectsWithoutNullEntry() { query.withContentType("foo"); query.select("bar", null); } @@ -197,7 +197,7 @@ public void equalsWithNoValuesThrows() { } @Test - public void notEqual() throws Exception { + public void notEqual() { query.withContentType("foo"); query.where("fields.bar", IsNotEqualTo, "baz"); @@ -205,7 +205,7 @@ public void notEqual() throws Exception { } @Test - public void all() throws Exception { + public void all() { query.withContentType("foo"); query.where("fields.bar", HasAllOf, "a,b,c,d"); @@ -213,7 +213,7 @@ public void all() throws Exception { } @Test - public void allSeparated() throws Exception { + public void allSeparated() { query.withContentType("foo"); query.where("fields.bar", HasAllOf, "a", "b", "c", "d"); @@ -221,7 +221,7 @@ public void allSeparated() throws Exception { } @Test - public void atLeasOnOf() throws Exception { + public void atLeasOnOf() { query.withContentType("foo"); query.where("fields.bar", HasOneOf, "a", "b", "c", "d"); @@ -229,7 +229,7 @@ public void atLeasOnOf() throws Exception { } @Test - public void noneOf() throws Exception { + public void noneOf() { query.withContentType("foo"); query.where("fields.bar", HasNoneOf, "a", "b", "c", "d"); @@ -237,7 +237,7 @@ public void noneOf() throws Exception { } @Test - public void fieldExists() throws Exception { + public void fieldExists() { query.withContentType("foo"); query.where("fields.bar", Exists); @@ -245,7 +245,7 @@ public void fieldExists() throws Exception { } @Test - public void fieldDoesNotExists() throws Exception { + public void fieldDoesNotExists() { query.withContentType("foo"); query.where("fields.bar", Exists, false); @@ -253,7 +253,7 @@ public void fieldDoesNotExists() throws Exception { } @Test - public void isLessThan() throws Exception { + public void isLessThan() { query.withContentType("foo"); query.where("fields.bar", IsLessThan, 1); @@ -261,7 +261,7 @@ public void isLessThan() throws Exception { } @Test - public void isLessOrEqualTo() throws Exception { + public void isLessOrEqualTo() { query.withContentType("foo"); query.where("fields.bar", IsLessThanOrEqualTo, 1); @@ -269,7 +269,7 @@ public void isLessOrEqualTo() throws Exception { } @Test - public void isGreaterThan() throws Exception { + public void isGreaterThan() { query.withContentType("foo"); query.where("fields.bar", IsGreaterThan, 1); @@ -277,7 +277,7 @@ public void isGreaterThan() throws Exception { } @Test - public void isGreaterThanOrEqualTo() throws Exception { + public void isGreaterThanOrEqualTo() { query.withContentType("foo"); query.where("fields.bar", IsGreaterThanOrEqualTo, 1); @@ -285,7 +285,7 @@ public void isGreaterThanOrEqualTo() throws Exception { } @Test - public void isEarlierThan() throws Exception { + public void isEarlierThan() { query.withContentType("foo"); query.where("fields.bar", IsEarlierThan, "2013-02-02T14:34+01:00"); @@ -293,7 +293,7 @@ public void isEarlierThan() throws Exception { } @Test - public void isEarlierThanOrAt() throws Exception { + public void isEarlierThanOrAt() { query.withContentType("foo"); query.where("fields.bar", IsEarlierOrAt, "2013-02-02T14:34+01:00"); @@ -302,7 +302,7 @@ public void isEarlierThanOrAt() throws Exception { @Test - public void isLaterThan() throws Exception { + public void isLaterThan() { query.withContentType("foo"); query.where("fields.bar", IsLaterThan, "2013-02-02T14:34+01:00"); @@ -310,7 +310,7 @@ public void isLaterThan() throws Exception { } @Test - public void isLaterThanOrEqualTo() throws Exception { + public void isLaterThanOrEqualTo() { query.withContentType("foo"); query.where("fields.bar", IsLaterOrAt, "2013-02-02T14:34+01:00"); @@ -318,7 +318,7 @@ public void isLaterThanOrEqualTo() throws Exception { } @Test - public void matchQuery() throws Exception { + public void matchQuery() { query.withContentType("foo"); query.where("fields.bar", Matches, "bar"); @@ -327,18 +327,18 @@ public void matchQuery() throws Exception { } @Test(expected = IllegalArgumentException.class) - public void matchQueryWithEmptyValueThrows() throws Exception { + public void matchQueryWithEmptyValueThrows() { query.withContentType("foo"); query.where("fields.bar", Matches); } @Test(expected = IllegalStateException.class) - public void matchQueryWithNoContentTypeButFieldsThrows() throws Exception { + public void matchQueryWithNoContentTypeButFieldsThrows() { query.where("fields.foo", Matches, "b"); } @Test - public void matchQueryWithSys() throws Exception { + public void matchQueryWithSys() { query.where("sys.id", Matches, "foo"); assertThat(query.params).containsEntry("sys.id[match]", "foo"); @@ -346,7 +346,7 @@ public void matchQueryWithSys() throws Exception { } @Test - public void near() throws Exception { + public void near() { query.withContentType("foo"); query.where("fields.bar", IsCloseTo, new Location(52d, 14d)); @@ -359,12 +359,12 @@ public void near() throws Exception { } @Test(expected = IllegalStateException.class) - public void nearThrowsIfNotUsedWithContentType() throws Exception { + public void nearThrowsIfNotUsedWithContentType() { query.where("fields.bar", IsCloseTo, new Location(52, 14)); } @Test - public void withinBoundingBox() throws Exception { + public void withinBoundingBox() { query.withContentType("foo"); query.where("fields.bar", IsWithinBoundingBoxOf, new BoundingBox(new Location(0, 1), new Location(2, 3))); @@ -380,7 +380,7 @@ public void withinBoundingBox() throws Exception { } @Test - public void withinBoundingBoxOfDoubles() throws Exception { + public void withinBoundingBoxOfDoubles() { query.withContentType("foo"); query.where("fields.bar", IsWithinBoundingBoxOf, new BoundingBox(0, 1, 2, 3)); @@ -395,7 +395,7 @@ public void withinBoundingBoxOfDoubles() throws Exception { } @Test - public void withinBoundingCircle() throws Exception { + public void withinBoundingCircle() { query.withContentType("foo"); query.where("fields.bar", IsWithinCircleOf, new BoundingCircle(52d, 14d, 10d)); @@ -409,7 +409,7 @@ public void withinBoundingCircle() throws Exception { } @Test - public void withinTypeSaveBoundingCircle() throws Exception { + public void withinTypeSaveBoundingCircle() { query.withContentType("foo"); query.where("fields.bar", IsWithinCircleOf, new BoundingCircle(new Location(52d, 14d), 10d)); @@ -423,7 +423,7 @@ public void withinTypeSaveBoundingCircle() throws Exception { } @Test - public void orderByField() throws Exception { + public void orderByField() { query.withContentType("foo"); query.orderBy("fields.bar"); @@ -432,7 +432,7 @@ public void orderByField() throws Exception { } @Test - public void orderBySysWithoutField() throws Exception { + public void orderBySysWithoutField() { query.orderBy("sys.foo"); assertThat(query.params).doesNotContainKey("content_type"); @@ -440,22 +440,22 @@ public void orderBySysWithoutField() throws Exception { } @Test(expected = IllegalStateException.class) - public void orderByThrowsOnFieldWithoutContentType() throws Exception { + public void orderByThrowsOnFieldWithoutContentType() { query.orderBy("fields.foo"); } @Test(expected = IllegalArgumentException.class) - public void orderByThrowsOnEmptyKey() throws Exception { + public void orderByThrowsOnEmptyKey() { query.orderBy(""); } @Test(expected = IllegalArgumentException.class) - public void orderByThrowsOnNullKey() throws Exception { + public void orderByThrowsOnNullKey() { query.orderBy((String) null); } @Test - public void orderByMultipleFields() throws Exception { + public void orderByMultipleFields() { query.withContentType("foo"); query.orderBy("fields.bar", "fields.baz"); @@ -464,7 +464,7 @@ public void orderByMultipleFields() throws Exception { } @Test - public void orderByMultipleFieldsWithSys() throws Exception { + public void orderByMultipleFieldsWithSys() { query.withContentType("foo"); query.orderBy("fields.bar", "sys.id"); @@ -473,7 +473,7 @@ public void orderByMultipleFieldsWithSys() throws Exception { } @Test - public void orderByMultipleOnlySysAndNoContentType() throws Exception { + public void orderByMultipleOnlySysAndNoContentType() { query.orderBy("sys.foo", "sys.bar"); assertThat(query.params).doesNotContainKey("content_type"); @@ -481,26 +481,26 @@ public void orderByMultipleOnlySysAndNoContentType() throws Exception { } @Test - public void orderByMultipleOneReverse() throws Exception { + public void orderByMultipleOneReverse() { query.orderBy("sys.foo", "-sys.bar"); assertThat(query.params).containsEntry("order", "sys.foo,-sys.bar"); } @Test(expected = IllegalArgumentException.class) - public void orderByOneNullThrows() throws Exception { + public void orderByOneNullThrows() { query.withContentType("foo"); query.orderBy("fields.bar", null); } @Test(expected = IllegalArgumentException.class) - public void orderByOneEmptyThrows() throws Exception { + public void orderByOneEmptyThrows() { query.withContentType("foo"); query.orderBy("fields.bar", "", "fields.baz"); } @Test - public void reverseOrderByField() throws Exception { + public void reverseOrderByField() { query.withContentType("foo"); query.reverseOrderBy("fields.bar"); @@ -509,7 +509,7 @@ public void reverseOrderByField() throws Exception { } @Test - public void reverseOrderBySysWithoutField() throws Exception { + public void reverseOrderBySysWithoutField() { query.reverseOrderBy("sys.foo"); assertThat(query.params).doesNotContainKey("content_type"); @@ -517,87 +517,87 @@ public void reverseOrderBySysWithoutField() throws Exception { } @Test(expected = IllegalStateException.class) - public void reverseOrderByThrowsOnFieldWithoutContentType() throws Exception { + public void reverseOrderByThrowsOnFieldWithoutContentType() { query.reverseOrderBy("fields.foo"); } @Test(expected = IllegalArgumentException.class) - public void reverseOrderByThrowsOnEmptyKey() throws Exception { + public void reverseOrderByThrowsOnEmptyKey() { query.reverseOrderBy(""); } @Test(expected = IllegalArgumentException.class) - public void reverseOrderByThrowsOnNullKey() throws Exception { + public void reverseOrderByThrowsOnNullKey() { query.reverseOrderBy(null); } @Test - public void limit() throws Exception { + public void limit() { query.limit(3); assertThat(query.params).containsEntry("limit", "3"); } @Test(expected = IllegalArgumentException.class) - public void limitWithNegativeThrows() throws Exception { + public void limitWithNegativeThrows() { query.limit(-1); } @Test(expected = IllegalArgumentException.class) - public void limitWithMoreThen1kThrows() throws Exception { + public void limitWithMoreThen1kThrows() { query.limit(1001); } @Test - public void skip() throws Exception { + public void skip() { query.skip(3); assertThat(query.params).containsEntry("skip", "3"); } @Test(expected = IllegalArgumentException.class) - public void skipWithNegativeThrows() throws Exception { + public void skipWithNegativeThrows() { query.skip(-1); } @Test(expected = IllegalArgumentException.class) - public void skipWithNegInfThrows() throws Exception { + public void skipWithNegInfThrows() { query.skip(Integer.MIN_VALUE); } @Test - public void includeZero() throws Exception { + public void includeZero() { query.include(0); assertThat(query.params).containsEntry("include", "0"); } @Test - public void includeTen() throws Exception { + public void includeTen() { query.include(10); assertThat(query.params).containsEntry("include", "10"); } @Test(expected = IllegalArgumentException.class) - public void includeToManyLevelThrows() throws Exception { + public void includeToManyLevelThrows() { query.include(11); } @Test(expected = IllegalArgumentException.class) - public void includeNegative() throws Exception { + public void includeNegative() { query.include(-1); } @Test public void queryingAssetTitlesDoesNotThrowWithoutTypeSet() { - final FetchQuery assetQuery = new FetchQuery(CDAAsset.class, client); + final FetchQuery assetQuery = new FetchQuery<>(CDAAsset.class, client); assetQuery.where("fields.title", IsEqualTo, "bar"); } @Test public void queryForAContentTypesNameDoesNotThrow() { - final FetchQuery typeQuery = new FetchQuery(CDAContentType.class, client); + final FetchQuery typeQuery = new FetchQuery<>(CDAContentType.class, client); typeQuery.where("name", Matches, "Auth"); } } \ No newline at end of file diff --git a/src/test/java/com/contentful/java/cda/AssetTest.java b/src/test/java/com/contentful/java/cda/AssetTest.java index 079dbab7..83321710 100644 --- a/src/test/java/com/contentful/java/cda/AssetTest.java +++ b/src/test/java/com/contentful/java/cda/AssetTest.java @@ -24,7 +24,7 @@ public class AssetTest extends BaseTest { @Test @Enqueue("demo/assets_jake.json") - public void fetchAsset() throws Exception { + public void fetchAsset() { final CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); assertThat(asset.id()).isEqualTo("jake"); @@ -39,7 +39,7 @@ public void fetchAsset() throws Exception { @Test @Enqueue("demo/assets_jake.json") - public void augmentUrlSimple() throws Exception { + public void augmentUrlSimple() { final CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); assertThat(asset.urlForImageWith(http(), widthOf(10))) @@ -52,7 +52,7 @@ public void augmentUrlSimple() throws Exception { @Test @Enqueue("demo/assets_jake.json") - public void augmentUrlWithSameOperationUsesLastOption() throws Exception { + public void augmentUrlWithSameOperationUsesLastOption() { final CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); assertThat( @@ -68,7 +68,7 @@ public void augmentUrlWithSameOperationUsesLastOption() throws Exception { @Test @Enqueue("demo/assets_jake.json") - public void augmentUrlComplete() throws Exception { + public void augmentUrlComplete() { final CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); assertThat( @@ -105,7 +105,7 @@ public void augmentUrlComplete() throws Exception { @Test @Enqueue("demo/assets_jake.json") - public void augmentPng8() throws Exception { + public void augmentPng8() { final CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); assertThat( @@ -126,7 +126,7 @@ public void augmentPng8() throws Exception { @Test(expected = IllegalStateException.class) @Enqueue("demo/assets_no_image.json") - public void expectThrowIfNotImageAsset() throws Exception { + public void expectThrowIfNotImageAsset() { CDAAsset asset = client.fetch(CDAAsset.class).one("6OpsQmtnl6uYyeUmkOiYYq"); asset.urlForImageWith(http()); @@ -134,7 +134,7 @@ public void expectThrowIfNotImageAsset() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue("demo/assets_jake.json") - public void expectThrowIfWidthIsNegative() throws Exception { + public void expectThrowIfWidthIsNegative() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); asset.urlForImageWith(widthOf(-1)); @@ -142,7 +142,7 @@ public void expectThrowIfWidthIsNegative() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue("demo/assets_jake.json") - public void expectThrowIfHeightIsNegative() throws Exception { + public void expectThrowIfHeightIsNegative() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); asset.urlForImageWith(heightOf(-1)); @@ -150,7 +150,7 @@ public void expectThrowIfHeightIsNegative() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue("demo/assets_jake.json") - public void expectThrowIfRadiusIsNegative() throws Exception { + public void expectThrowIfRadiusIsNegative() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); asset.urlForImageWith(roundedCornerRadiusOf(-1)); @@ -158,7 +158,7 @@ public void expectThrowIfRadiusIsNegative() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue("demo/assets_jake.json") - public void expectThrowIfColorIsNegative() throws Exception { + public void expectThrowIfColorIsNegative() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); asset.urlForImageWith(backgroundColorOf(-1)); @@ -166,7 +166,7 @@ public void expectThrowIfColorIsNegative() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue("demo/assets_jake.json") - public void expectThrowIfColorIsToLarge() throws Exception { + public void expectThrowIfColorIsToLarge() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); asset.urlForImageWith(backgroundColorOf(0xFFFFFF + 1)); @@ -174,7 +174,7 @@ public void expectThrowIfColorIsToLarge() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue("demo/assets_jake.json") - public void expectThrowIfRedColorComponentIsNegative() throws Exception { + public void expectThrowIfRedColorComponentIsNegative() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); asset.urlForImageWith(backgroundColorOf(-1, 0, 0)); @@ -182,7 +182,7 @@ public void expectThrowIfRedColorComponentIsNegative() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue("demo/assets_jake.json") - public void expectThrowIfRedColorComponentIsToLarge() throws Exception { + public void expectThrowIfRedColorComponentIsToLarge() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); asset.urlForImageWith(backgroundColorOf(0xFF + 1, 0, 0)); @@ -190,7 +190,7 @@ public void expectThrowIfRedColorComponentIsToLarge() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue("demo/assets_jake.json") - public void expectThrowIfGreenColorComponentIsNegative() throws Exception { + public void expectThrowIfGreenColorComponentIsNegative() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); asset.urlForImageWith(backgroundColorOf(0, -1, 0)); @@ -198,7 +198,7 @@ public void expectThrowIfGreenColorComponentIsNegative() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue("demo/assets_jake.json") - public void expectThrowIfGreenColorComponentIsToLarge() throws Exception { + public void expectThrowIfGreenColorComponentIsToLarge() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); asset.urlForImageWith(backgroundColorOf(0, 0xFF + 1, 0)); @@ -206,7 +206,7 @@ public void expectThrowIfGreenColorComponentIsToLarge() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue("demo/assets_jake.json") - public void expectThrowIfBlueColorComponentIsNegative() throws Exception { + public void expectThrowIfBlueColorComponentIsNegative() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); asset.urlForImageWith(backgroundColorOf(0, 0, -1)); @@ -214,7 +214,7 @@ public void expectThrowIfBlueColorComponentIsNegative() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue("demo/assets_jake.json") - public void expectThrowIfBlueColorComponentIsToLarge() throws Exception { + public void expectThrowIfBlueColorComponentIsToLarge() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); asset.urlForImageWith(backgroundColorOf(0, 0, 0xFF + 1)); @@ -222,7 +222,7 @@ public void expectThrowIfBlueColorComponentIsToLarge() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue("demo/assets_jake.json") - public void expectThrowIfQualityIsToSmall() throws Exception { + public void expectThrowIfQualityIsToSmall() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); asset.urlForImageWith(jpegQualityOf(-1)); @@ -230,7 +230,7 @@ public void expectThrowIfQualityIsToSmall() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue("demo/assets_jake.json") - public void expectThrowIfQualityIsToHigh() throws Exception { + public void expectThrowIfQualityIsToHigh() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); asset.urlForImageWith(jpegQualityOf(0xFFFFFF + 1)); @@ -238,7 +238,7 @@ public void expectThrowIfQualityIsToHigh() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue("demo/assets_jake.json") - public void expectThrowIfEmptyOption() throws Exception { + public void expectThrowIfEmptyOption() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); asset.urlForImageWith(); @@ -246,7 +246,7 @@ public void expectThrowIfEmptyOption() throws Exception { @Test @Enqueue("demo/assets_jake.json") - public void firstHttpOptionSurvives() throws Exception { + public void firstHttpOptionSurvives() { CDAAsset asset = client.fetch(CDAAsset.class).one("jake"); assertThat(asset.urlForImageWith(http(), https())).startsWith("http:"); diff --git a/src/test/java/com/contentful/java/cda/BaseTest.java b/src/test/java/com/contentful/java/cda/BaseTest.java index 2326af04..f19fb6ae 100644 --- a/src/test/java/com/contentful/java/cda/BaseTest.java +++ b/src/test/java/com/contentful/java/cda/BaseTest.java @@ -35,7 +35,7 @@ public class BaseTest { @Rule public EnqueueResponseRule enqueueResponse = new EnqueueResponseRule(); - @Before public void setUp() throws Exception { + @Before public void setUp() throws IOException { LogManager.getLogManager().reset(); server = createServer(); server.start(); @@ -49,7 +49,7 @@ public class BaseTest { } } - @After public void tearDown() throws Exception { + @After public void tearDown() throws IOException { server.shutdown(); } diff --git a/src/test/java/com/contentful/java/cda/CallbackTest.java b/src/test/java/com/contentful/java/cda/CallbackTest.java index 9b5c9147..baf63f31 100644 --- a/src/test/java/com/contentful/java/cda/CallbackTest.java +++ b/src/test/java/com/contentful/java/cda/CallbackTest.java @@ -16,17 +16,17 @@ public class CallbackTest extends BaseTest { @Test @Enqueue("demo/entries_nyancat.json") - public void fetchEntryAsync() throws Exception { + public void fetchEntryAsync() throws InterruptedException { assertCallback( - client.fetch(CDAEntry.class).one("nyancat", new TestCallback()) + client.fetch(CDAEntry.class).one("nyancat", new TestCallback<>()) .await()); } @Test - public void onFailure() throws Exception { + public void onFailure() throws InterruptedException { server.enqueue(new MockResponse().setStatus("404")); try { - client.fetchSpace(new TestCallback()).await(); + client.fetchSpace(new TestCallback<>()).await(); } catch (Exception e) { assertThat(e.getMessage()).isEqualTo("Cannot log to a null logger. Please set either logLevel to None, or do set a Logger"); throw e; @@ -35,7 +35,7 @@ public void onFailure() throws Exception { @Test @Enqueue("array_empty.json") - public void cancel() throws Exception { + public void cancel() throws InterruptedException { CDACallback callback = new CDACallback() { @Override protected void onSuccess(CDAArray result) { fail("Callback should not be invoked."); diff --git a/src/test/java/com/contentful/java/cda/ClientTest.java b/src/test/java/com/contentful/java/cda/ClientTest.java index eff68cd3..5016e12d 100644 --- a/src/test/java/com/contentful/java/cda/ClientTest.java +++ b/src/test/java/com/contentful/java/cda/ClientTest.java @@ -34,7 +34,7 @@ public class ClientTest extends BaseTest { public static final String ERROR_MESSAGE = "This is an expected error!"; @Test @Enqueue - public void notUsingCustomCallFactoryDoesCreateCallFactoryWithAuthAndUserAgentInterceptors() throws Exception { + public void notUsingCustomCallFactoryDoesCreateCallFactoryWithAuthAndUserAgentInterceptors() throws InterruptedException { createClient().fetchSpace(); @@ -48,7 +48,7 @@ public void notUsingCustomCallFactoryDoesCreateCallFactoryWithAuthAndUserAgentIn } @Test @Enqueue - public void usingCustomCallFactoryDoesNotAddDefaultHeaders() throws Exception { + public void usingCustomCallFactoryDoesNotAddDefaultHeaders() throws InterruptedException { final Call.Factory callFactory = new OkHttpClient.Builder().build(); createBuilder() @@ -69,7 +69,7 @@ public void usingCustomCallFactoryDoesNotAddDefaultHeaders() throws Exception { } @Test @Enqueue - public void customCallFactoryCanAddInterceptors() throws Exception { + public void customCallFactoryCanAddInterceptors() throws IOException { final Interceptor interceptor = spy(new AuthorizationHeaderInterceptor(DEFAULT_TOKEN)); Call.Factory callFactory = new OkHttpClient.Builder() @@ -86,11 +86,9 @@ public void customCallFactoryCanAddInterceptors() throws Exception { } @Test(expected = RuntimeException.class) @Enqueue - public void throwingAnExceptionInAnInterceptorResultsInRuntimeException() throws Exception { - final Interceptor interceptor = new Interceptor() { - @Override public Response intercept(Chain chain) throws IOException { - throw new IOException(ERROR_MESSAGE); - } + public void throwingAnExceptionInAnInterceptorResultsInRuntimeException() { + final Interceptor interceptor = chain -> { + throw new IOException(ERROR_MESSAGE); }; Call.Factory callFactory = new OkHttpClient.Builder() @@ -113,7 +111,7 @@ public void throwingAnExceptionInAnInterceptorResultsInRuntimeException() throws } @Test(expected = NullPointerException.class) - public void clientWithNoSpaceAndNoCallFactoryThrows() throws Exception { + public void clientWithNoSpaceAndNoCallFactoryThrows() { try { CDAClient.builder().setToken("token").build(); } catch (NullPointerException e) { @@ -123,7 +121,7 @@ public void clientWithNoSpaceAndNoCallFactoryThrows() throws Exception { } @Test - public void clientWithNoSpaceButCallFactoryBuilds() throws Exception { + public void clientWithNoSpaceButCallFactoryBuilds() { CDAClient.builder() .setCallFactory(mock(Call.Factory.class)) .setSpace(DEFAULT_SPACE) @@ -131,7 +129,7 @@ public void clientWithNoSpaceButCallFactoryBuilds() throws Exception { } @Test(expected = NullPointerException.class) - public void clientWithNoTokenThrows() throws Exception { + public void clientWithNoTokenThrows() { try { CDAClient.builder().setSpace("space").build(); } catch (NullPointerException e) { @@ -142,7 +140,7 @@ public void clientWithNoTokenThrows() throws Exception { @Test @Enqueue - public void authHeader() throws Exception { + public void authHeader() throws InterruptedException { client.fetchSpace(); RecordedRequest request = server.takeRequest(); assertThat(request.getHeader("authorization")).isEqualTo("Bearer " + DEFAULT_TOKEN); @@ -150,7 +148,7 @@ public void authHeader() throws Exception { @Test @Enqueue - public void userAgentHeader() throws Exception { + public void userAgentHeader() throws InterruptedException { String versionName = GeneratedBuildParameters.PROJECT_VERSION; assertThat(versionName).matches("^\\d+\\.\\d+\\.\\d+(-\\w+)?$"); @@ -163,7 +161,7 @@ public void userAgentHeader() throws Exception { @Test(expected = IllegalArgumentException.class) @Enqueue - public void fetchInvalidTypeThrows() throws Exception { + public void fetchInvalidTypeThrows() { try { client.fetch(CDAResource.class).all(); } catch (IllegalArgumentException e) { @@ -309,7 +307,7 @@ public void javaUsesSystemsTLSFactoryIfNotForcedToCustom() { defaults = {}, complex = {@EnqueueResponse(fileName = "errors/invalid_query.json", code = 404)} ) - public void sendingInvalidQueriesThrowsMeaningfulException() throws Throwable { + public void sendingInvalidQueriesThrowsMeaningfulException() { final CDAClient client = createClient(); @@ -337,7 +335,7 @@ public void sendingInvalidQueriesThrowsMeaningfulException() throws Throwable { } )} ) - public void requestingWhileRateLimitedThrows() throws Throwable { + public void requestingWhileRateLimitedThrows() { final CDAClient client = createClient(); @@ -404,7 +402,7 @@ static class InterceptingInterceptor implements Interceptor { } @Test @Enqueue - public void customCallFactoryCanUseDefault() throws Exception { + public void customCallFactoryCanUseDefault() { final CDAClient.Builder builder = createBuilder(); @@ -422,7 +420,7 @@ public void customCallFactoryCanUseDefault() throws Exception { @Test @Enqueue - public void contentfulCustomHeaderUsed() throws Exception { + public void contentfulCustomHeaderUsed() throws InterruptedException { final CDAClient client = createBuilder().build(); client.fetchSpace(); @@ -436,7 +434,7 @@ public void contentfulCustomHeaderUsed() throws Exception { @Test @Enqueue - public void addingApplicationToCustomHeaderWorks() throws Exception { + public void addingApplicationToCustomHeaderWorks() throws InterruptedException { final CDAClient client = createBuilder() .setApplication("Contentful Java Unit Test", "0.0.1-beta4") .build(); @@ -451,7 +449,7 @@ public void addingApplicationToCustomHeaderWorks() throws Exception { @Test @Enqueue - public void addingIntegrationToCustomHeaderWorks() throws Exception { + public void addingIntegrationToCustomHeaderWorks() throws InterruptedException { // use this features if you are using creating a library on top of the sdk. final CDAClient client = createBuilder() .setIntegration("contentful.awesomelib.java", "0.0.1-beta9") @@ -467,7 +465,7 @@ public void addingIntegrationToCustomHeaderWorks() throws Exception { @Test @Enqueue({"demo/locales.json", "demo/content_types.json", "demo/sync_initial_p1.json"}) - public void syncTypeIsAddedToRequest() throws Exception { + public void syncTypeIsAddedToRequest() throws InterruptedException { final CDAClient client = createPreviewClient(); final CountDownLatch latch = new CountDownLatch(1); @@ -492,5 +490,4 @@ protected void onFailure(Throwable error) { assertThat(request.getPath()).contains("type=Entry"); assertThat(request.getPath()).contains("content_type=CustomType"); } - } diff --git a/src/test/java/com/contentful/java/cda/ContentTypeTest.java b/src/test/java/com/contentful/java/cda/ContentTypeTest.java index b7dba385..1dbed42a 100644 --- a/src/test/java/com/contentful/java/cda/ContentTypeTest.java +++ b/src/test/java/com/contentful/java/cda/ContentTypeTest.java @@ -13,7 +13,7 @@ public class ContentTypeTest extends BaseTest { @Test @Enqueue("demo/content_types_cat.json") - public void fetchContentType() throws Exception { + public void fetchContentType() { CDAContentType cat = client.fetch(CDAContentType.class).one("cat"); assertThat(cat.name()).isEqualTo("Cat"); assertThat(cat.displayField()).isEqualTo("name"); @@ -23,7 +23,7 @@ public void fetchContentType() throws Exception { @Test @Enqueue({"demo/content_types_cat.json", "demo/content_types_fake.json"}) - public void manuallyFetchedContentTypeIsCached() throws Exception { + public void manuallyFetchedContentTypeIsCached() { client.fetch(CDAContentType.class).one("cat"); assertThat(client.cache.types()).hasSize(5); assertThat(client.cache.types()).doesNotContainKey("fake"); @@ -41,7 +41,7 @@ public void manuallyFetchedContentTypeIsCached() throws Exception { "cda/entries.json", "cda/content_types_bar.json" }) - public void missingContentTypeIsFetchedAndCached() throws Exception { + public void missingContentTypeIsFetchedAndCached() { assertThat(client.cache.types()).isNull(); CDAArray array = client.fetch(CDAEntry.class).all(); CDAEntry foo = array.entries().get("3UpazZmO8g8iI0iWAMmGMS"); @@ -49,7 +49,7 @@ public void missingContentTypeIsFetchedAndCached() throws Exception { CDAEntry bar = foo.getField("link"); assertThat(bar).isNotNull(); - assertThat(bar.getField("name")).isEqualTo("bar"); + assertThat(bar.getField("name")).isEqualTo("bar"); assertThat(client.cache.types()).containsKey("3lYaFZKDgQCUwWy6uEoQYi"); } @@ -59,7 +59,7 @@ public void missingContentTypeIsFetchedAndCached() throws Exception { "demo/entries_fake.json", "array_empty.json" }) - public void badTypeMappingThrows() throws Exception { + public void badTypeMappingThrows() { try { client.fetch(CDAEntry.class).all(); } catch (CDAContentTypeNotFoundException e) { @@ -72,7 +72,7 @@ public void badTypeMappingThrows() throws Exception { @Test @Enqueue("demo/content_types_cat.json") - public void fetchFieldValidations() throws Exception { + public void fetchFieldValidations() { CDAContentType catContentType = client.fetch(CDAContentType.class).one("cat"); assertThat(catContentType).isNotNull(); CDAField colorField = findFieldById(catContentType.fields(), "color"); diff --git a/src/test/java/com/contentful/java/cda/EntryTest.java b/src/test/java/com/contentful/java/cda/EntryTest.java index 15075ea8..af09adf7 100644 --- a/src/test/java/com/contentful/java/cda/EntryTest.java +++ b/src/test/java/com/contentful/java/cda/EntryTest.java @@ -10,14 +10,12 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import io.reactivex.functions.Consumer; - import static com.google.common.truth.Truth.assertThat; public class EntryTest extends BaseTest { @Test(expected = CDAResourceNotFoundException.class) @Enqueue("array_empty.json") - public void fetchNonExistingReturnsNull() throws Exception { + public void fetchNonExistingReturnsNull() { try { client.fetch(CDAEntry.class).one("foo"); } catch (NullPointerException e) { @@ -28,7 +26,7 @@ public void fetchNonExistingReturnsNull() throws Exception { @Test @Enqueue("array_empty.json") - public void fetchNonExistingEntryThrowsError() throws Exception { + public void fetchNonExistingEntryThrowsError() throws InterruptedException { final Object result[] = new Object[]{new Object()}; final Object error[] = new Object[]{new Object()}; final CountDownLatch latch = new CountDownLatch(1); @@ -36,20 +34,16 @@ public void fetchNonExistingEntryThrowsError() throws Exception { client.observe(CDAEntry.class) .one("foo") .subscribe( - new Consumer() { - @Override public void accept(CDAEntry entry) { - result[0] = entry; - error[0] = null; - - latch.countDown(); - } - }, new Consumer() { - @Override public void accept(Throwable throwable) { - result[0] = null; - error[0] = throwable; - - latch.countDown(); - } + entry -> { + result[0] = entry; + error[0] = null; + + latch.countDown(); + }, throwable -> { + result[0] = null; + error[0] = throwable; + + latch.countDown(); } ); @@ -65,9 +59,9 @@ public void fetchNonExistingEntryThrowsError() throws Exception { @Test @Enqueue("array_empty.json") - public void fetchNonExistingEntryInvokesSuccessWithNull() throws Exception { + public void fetchNonExistingEntryInvokesSuccessWithNull() throws InterruptedException { TestCallback callback = client.fetch(CDAEntry.class) - .one("foo", new TestCallback()) + .one("foo", new TestCallback<>()) .await(); assertThat(callback.error()).isNotNull(); @@ -79,7 +73,7 @@ public void fetchNonExistingEntryInvokesSuccessWithNull() throws Exception { @Test @Enqueue("demo/entries_nofields.json") - public void entryNoFields() throws Exception { + public void entryNoFields() { CDAEntry foo = client.fetch(CDAEntry.class).one("foo"); assertThat(foo).isNotNull(); assertThat(foo.fields).isEmpty(); @@ -87,20 +81,20 @@ public void entryNoFields() throws Exception { @Test @Enqueue("demo/entries_nyancat.json") - public void entryContentType() throws Exception { + public void entryContentType() { CDAEntry entry = client.fetch(CDAEntry.class).one("nyancat"); assertThat(entry.contentType()).isNotNull(); } @Test @Enqueue("demo/entries_nyancat.json") - public void fetchEntry() throws Exception { + public void fetchEntry() { assertNyanCat(client.fetch(CDAEntry.class).one("nyancat")); } @Test @Enqueue("demo/entries_nyancat.json") - public void fetchEntryAsync() throws Exception { + public void fetchEntryAsync() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final CDAEntry[] result = {null}; @@ -121,22 +115,22 @@ public void fetchEntryAsync() throws Exception { } @Test(expected = IllegalArgumentException.class) - public void populationThrowsOnZeroLimit() throws Exception { + public void populationThrowsOnZeroLimit() { client.populateContentTypeCache(0); } @Test(expected = IllegalArgumentException.class) - public void populationThrowsOnThought() throws Exception { + public void populationThrowsOnThought() { client.populateContentTypeCache(1001); } @Test(expected = IllegalArgumentException.class) - public void observePopulationThrowsOnZeroLimit() throws Exception { + public void observePopulationThrowsOnZeroLimit() { client.observeContentTypeCachePopulation(0); } @Test(expected = IllegalArgumentException.class) - public void observePopulationThrowsOnThought() throws Exception { + public void observePopulationThrowsOnThought() { client.observeContentTypeCachePopulation(1001); } @@ -150,7 +144,7 @@ public void observePopulationThrowsOnThought() throws Exception { "content_types/populate_cache_simple.json" } ) - public void populateAllContentTypesSinglePage() throws Exception { + public void populateAllContentTypesSinglePage() { final int contentTypesCached = client.populateContentTypeCache(); assertThat(contentTypesCached).isEqualTo(3); @@ -186,7 +180,7 @@ public void populateAllContentTypesSinglePage() throws Exception { "content_types/populate_cache_complex_p3.json" } ) - public void populateAllContentTypesMultiplePages() throws Exception { + public void populateAllContentTypesMultiplePages() { int numberOfContentTypes = client.populateContentTypeCache(60); assertThat(numberOfContentTypes).isEqualTo(151); @@ -222,7 +216,7 @@ public void populateAllContentTypesMultiplePages() throws Exception { "content_types/populate_cache_last_entry.json" } ) - public void aPopulatedContentTypeCacheDoesNotToFetchContentTypes() throws Exception { + public void aPopulatedContentTypeCacheDoesNotToFetchContentTypes() { client.populateContentTypeCache(60); assertThat(client.cache.types().size()).isEqualTo(151); @@ -240,7 +234,7 @@ public void aPopulatedContentTypeCacheDoesNotToFetchContentTypes() throws Except @Test @Enqueue("demo/entries.json") - public void fetchAllEntries() throws Exception { + public void fetchAllEntries() { CDAArray array = client.fetch(CDAEntry.class).all(); assertThat(array.items()).hasSize(11); assertThat(array.assets()).hasSize(4); @@ -261,10 +255,10 @@ public void fetchAllEntries() throws Exception { private void assertNyanCat(CDAEntry entry) { assertThat(entry.id()).isEqualTo("nyancat"); - assertThat(entry.getField("name")).isEqualTo("Nyan Cat"); - assertThat(entry.getField("color")).isEqualTo("rainbow"); - assertThat(entry.getField("birthday")).isEqualTo("2011-04-04T22:00:00+00:00"); - assertThat(entry.getField("lives")).isEqualTo(1337.0); + assertThat(entry.getField("name")).isEqualTo("Nyan Cat"); + assertThat(entry.getField("color")).isEqualTo("rainbow"); + assertThat(entry.getField("birthday")).isEqualTo("2011-04-04T22:00:00+00:00"); + assertThat(entry.getField("lives")).isEqualTo(1337.0); List likes = entry.getField("likes"); assertThat(likes).containsExactly("rainbows", "fish"); @@ -275,8 +269,8 @@ private void assertNyanCat(CDAEntry entry) { // Localization assertThat(entry.defaultLocale).isEqualTo("en-US"); - assertThat(entry.getField("color")).isEqualTo("rainbow"); - assertThat(entry.getField("non-existing-does-not-throw")).isNull(); + assertThat(entry.getField("color")).isEqualTo("rainbow"); + assertThat(entry.getField("non-existing-does-not-throw")).isNull(); } @Test @@ -284,7 +278,7 @@ private void assertNyanCat(CDAEntry entry) { defaults = {"arrays/locales.json", "arrays/content_types.json"}, value = "arrays/entries.json" ) - public void arrayItemsContainOnlyTopLevelEntries() throws Exception { + public void arrayItemsContainOnlyTopLevelEntries() { CDAArray array = client.fetch(CDAEntry.class).where("content_type", "Jm9AuzgH8OyocaMQSMwKC").all(); diff --git a/src/test/java/com/contentful/java/cda/EnvironmentTest.java b/src/test/java/com/contentful/java/cda/EnvironmentTest.java index be97166a..c3bb2801 100644 --- a/src/test/java/com/contentful/java/cda/EnvironmentTest.java +++ b/src/test/java/com/contentful/java/cda/EnvironmentTest.java @@ -11,7 +11,7 @@ public class EnvironmentTest extends BaseTest { @Test @Enqueue("demo/entries.json") - public void creatingDefaultClientTalksToMaster() throws Exception { + public void creatingDefaultClientTalksToMaster() throws InterruptedException { createBuilder() .setSpace(DEFAULT_SPACE) @@ -26,7 +26,7 @@ public void creatingDefaultClientTalksToMaster() throws Exception { } @Test @Enqueue("demo/entries.json") - public void settingEnvironmentUpdatesRequestURI() throws Exception { + public void settingEnvironmentUpdatesRequestURI() throws InterruptedException { createBuilder() .setSpace(DEFAULT_SPACE) .setEnvironment(STAGING_ENVIRONMENT) diff --git a/src/test/java/com/contentful/java/cda/LinkTest.java b/src/test/java/com/contentful/java/cda/LinkTest.java index 537f131c..9727a5f8 100644 --- a/src/test/java/com/contentful/java/cda/LinkTest.java +++ b/src/test/java/com/contentful/java/cda/LinkTest.java @@ -9,14 +9,14 @@ import static com.google.common.truth.Truth.assertThat; public class LinkTest extends BaseTest { - @Test @Enqueue("demo/links_unresolved.json") public void unresolvedLinkIsNull() throws Exception { + @Test @Enqueue("demo/links_unresolved.json") public void unresolvedLinkIsNull() { CDAArray array = client.fetch(CDAEntry.class).all(); assertThat(array.items()).hasSize(1); assertThat(array.entries()).hasSize(1); CDAEntry entry = array.entries().get("happycat"); assertThat(entry).isNotNull(); - assertThat(entry.getField("bestFriend")).isNull(); + assertThat(entry.getField("bestFriend")).isNull(); } @SuppressWarnings("unchecked") @@ -25,7 +25,7 @@ public class LinkTest extends BaseTest { "links/content_types.json" }, value = { "links/entries.json" - }) public void arrays() throws Exception { + }) public void arrays() { CDAArray array = client.fetch(CDAEntry.class).all(); assertThat(array.total()).isEqualTo(4); assertThat(array.items()).hasSize(4); @@ -34,8 +34,8 @@ public class LinkTest extends BaseTest { CDAEntry container = array.entries().get("3vyEoAvlkk8yE4a8gCCkiu"); assertThat(container).isNotNull(); - assertThat(container.getField("asset")).isInstanceOf(CDAAsset.class); - assertThat(container.getField("entry")).isInstanceOf(CDAEntry.class); + assertThat(container.getField("asset")).isInstanceOf(CDAAsset.class); + assertThat(container.getField("entry")).isInstanceOf(CDAEntry.class); List assets = container.getField("assets"); assertThat(assets).isNotNull(); @@ -58,7 +58,7 @@ public class LinkTest extends BaseTest { "links/content_types.json" }, value = { "links/sync_empty_links.json" - }) public void testEmptyLinks() throws Exception { + }) public void testEmptyLinks() { client.sync().fetch(); } } diff --git a/src/test/java/com/contentful/java/cda/LocaleFallbackTest.java b/src/test/java/com/contentful/java/cda/LocaleFallbackTest.java index 4876e45c..b2542bc9 100644 --- a/src/test/java/com/contentful/java/cda/LocaleFallbackTest.java +++ b/src/test/java/com/contentful/java/cda/LocaleFallbackTest.java @@ -17,7 +17,7 @@ public class LocaleFallbackTest extends BaseTest { defaults = {"locales_fallback/fetch_all_locales.json", "locales_fallback/content_types.json"}, value = "locales_fallback/fetch_all_locales.json" ) - public void fetchLocales() throws Exception { + public void fetchLocales() { final List locales = fromArrayToItems(client.fetch(CDALocale.class).all()); Map localesByCodeMap = listToMapByNamer(locales, localeNamer); @@ -37,18 +37,18 @@ public void fetchLocales() throws Exception { defaults = {"locales_fallback/fetch_all_locales.json", "locales_fallback/content_types.json"}, value = "locales_fallback/entries.json" ) - public void testFallbackLocaleQueueToDefaultOneHop() throws Exception { + public void testFallbackLocaleQueueToDefaultOneHop() { final CDAArray all = client.fetch(CDAEntry.class).all(); final Map entries = all.entries(); final CDAEntry nofirst = entries.get("no-first"); - assertThat(nofirst.getField("title")).isEqualTo("no-first"); + assertThat(nofirst.getField("title")).isEqualTo("no-first"); - assertThat(nofirst.getField("first", "title")).isEqualTo("inbetween"); + assertThat(nofirst.getField("first", "title")).isEqualTo("inbetween"); - assertThat(nofirst.getField("inbetween", "title")).isEqualTo("inbetween"); + assertThat(nofirst.getField("inbetween", "title")).isEqualTo("inbetween"); - assertThat(nofirst.getField("default", "title")).isEqualTo("no-first"); + assertThat(nofirst.getField("default", "title")).isEqualTo("no-first"); } @Test @@ -56,18 +56,18 @@ public void testFallbackLocaleQueueToDefaultOneHop() throws Exception { defaults = {"locales_fallback/fetch_all_locales.json", "locales_fallback/content_types.json"}, value = "locales_fallback/entries.json" ) - public void testFallbackLocaleQueueToDefaultTwoHops() throws Exception { + public void testFallbackLocaleQueueToDefaultTwoHops() { final CDAArray all = client.fetch(CDAEntry.class).all(); final Map entries = all.entries(); final CDAEntry subject = entries.get("no-first-and-no-inbetween"); - assertThat(subject.getField("title")).isEqualTo("no-first-and-no-inbetween"); + assertThat(subject.getField("title")).isEqualTo("no-first-and-no-inbetween"); - assertThat(subject.getField("first", "title")).isEqualTo("no-first-and-no-inbetween"); + assertThat(subject.getField("first", "title")).isEqualTo("no-first-and-no-inbetween"); - assertThat(subject.getField("inbetween", "title")).isEqualTo("no-first-and-no-inbetween"); + assertThat(subject.getField("inbetween", "title")).isEqualTo("no-first-and-no-inbetween"); - assertThat(subject.getField("default", "title")).isEqualTo("no-first-and-no-inbetween"); + assertThat(subject.getField("default", "title")).isEqualTo("no-first-and-no-inbetween"); } @Test @@ -75,29 +75,25 @@ public void testFallbackLocaleQueueToDefaultTwoHops() throws Exception { defaults = {"locales_fallback/fetch_all_locales.json", "locales_fallback/content_types.json"}, value = "locales_fallback/entries.json" ) - public void testFallbackLocaleQueueToNull() throws Exception { + public void testFallbackLocaleQueueToNull() { final CDAArray all = client.fetch(CDAEntry.class).all(); final Map entries = all.entries(); final CDAEntry toNull = entries.get("no-null"); - assertThat(toNull.getField("title")).isEqualTo("no-null"); + assertThat(toNull.getField("title")).isEqualTo("no-null"); - assertThat(toNull.getField("null", "title")).isNull(); + assertThat(toNull.getField("null", "title")).isNull(); } - private static Namer localeNamer = new Namer() { - @Override public String name(CDALocale cdaLocale) { - return cdaLocale.code(); - } - }; + private static final Namer localeNamer = CDALocale::code; private interface Namer { String name(T t); } private Map listToMapByNamer(List list, Namer namer) { - final HashMap map = new HashMap(); + final HashMap map = new HashMap<>(); for (T item : list) { final String key = namer.name(item); diff --git a/src/test/java/com/contentful/java/cda/LocaleTest.java b/src/test/java/com/contentful/java/cda/LocaleTest.java index 20f5473b..5661b5bf 100644 --- a/src/test/java/com/contentful/java/cda/LocaleTest.java +++ b/src/test/java/com/contentful/java/cda/LocaleTest.java @@ -9,7 +9,7 @@ public class LocaleTest extends BaseTest { @Test @Enqueue("locales/array_empty.json") - public void fetchEmptyLocales() throws Exception { + public void fetchEmptyLocales() { final CDAArray all = client.fetch(CDALocale.class).all(); assertThat(all.total).isEqualTo(0); @@ -18,13 +18,13 @@ public void fetchEmptyLocales() throws Exception { @Test(expected = CDAResourceNotFoundException.class) @Enqueue("errors/not_found.json") - public void fetchOneNonExistingThrows() throws Exception { + public void fetchOneNonExistingThrows() { client.fetch(CDALocale.class).one("foo"); } @Test @Enqueue("locales/fetch_all_locales.json") - public void fetchOne() throws Exception { + public void fetchOne() { final CDALocale one = client.fetch(CDALocale.class).one("2oQPjMCL9bQkylziydLh57"); assertThat(one.toString()).isEqualTo("CDALocale { CDAResource { attrs = {" + "id=2oQPjMCL9bQkylziydLh57, type=Locale, version=1.0}, id = 2oQPjMCL9bQkylziydLh57, " + @@ -34,7 +34,7 @@ public void fetchOne() throws Exception { @Test @Enqueue("locales/fetch_all_locales.json") - public void fetchAllLocales() throws Exception { + public void fetchAllLocales() { final CDAArray found = client.fetch(CDALocale.class).all(); assertThat(found.items().size()).isEqualTo(2); diff --git a/src/test/java/com/contentful/java/cda/ResourceFactoryUnitTest.java b/src/test/java/com/contentful/java/cda/ResourceFactoryUnitTest.java index 454dfc56..cc9e0af8 100644 --- a/src/test/java/com/contentful/java/cda/ResourceFactoryUnitTest.java +++ b/src/test/java/com/contentful/java/cda/ResourceFactoryUnitTest.java @@ -35,9 +35,9 @@ public class ResourceFactoryUnitTest { } @Test - public void testPreserveOrderOfElements() throws Exception { + public void testPreserveOrderOfElements() { final CDAArray inputArray = new CDAArray(); - inputArray.items = new ArrayList(); + inputArray.items = new ArrayList<>(); for (int i = 0; i < 23; ++i) { inputArray.items().add(createCdaEntry(String.format("%03d", i))); } @@ -50,12 +50,12 @@ public void testPreserveOrderOfElements() throws Exception { private CDAEntry createCdaEntry(String id) { final CDAEntry entry = new CDAEntry(); - entry.fields = new HashMap(); - entry.attrs = new HashMap(); + entry.fields = new HashMap<>(); + entry.attrs = new HashMap<>(); entry.attrs.put("type", CDAType.ENTRY.name()); entry.attrs.put("id", id); entry.setContentType(new CDAContentType()); - entry.contentType().fields = new ArrayList(); + entry.contentType().fields = new ArrayList<>(); return entry; } } \ No newline at end of file diff --git a/src/test/java/com/contentful/java/cda/RichTextTest.java b/src/test/java/com/contentful/java/cda/RichTextTest.java new file mode 100644 index 00000000..f9490c41 --- /dev/null +++ b/src/test/java/com/contentful/java/cda/RichTextTest.java @@ -0,0 +1,411 @@ +package com.contentful.java.cda; + +import com.contentful.java.cda.lib.Enqueue; +import com.contentful.java.cda.rich.CDARichBlock; +import com.contentful.java.cda.rich.CDARichDocument; +import com.contentful.java.cda.rich.CDARichEmbeddedLink; +import com.contentful.java.cda.rich.CDARichHeading; +import com.contentful.java.cda.rich.CDARichHorizontalRule; +import com.contentful.java.cda.rich.CDARichHyperLink; +import com.contentful.java.cda.rich.CDARichMark.CDARichMarkBold; +import com.contentful.java.cda.rich.CDARichMark.CDARichMarkCode; +import com.contentful.java.cda.rich.CDARichMark.CDARichMarkItalic; +import com.contentful.java.cda.rich.CDARichMark.CDARichMarkUnderline; +import com.contentful.java.cda.rich.CDARichOrderedList; +import com.contentful.java.cda.rich.CDARichParagraph; +import com.contentful.java.cda.rich.CDARichQuote; +import com.contentful.java.cda.rich.CDARichText; +import com.contentful.java.cda.rich.CDARichUnorderedList; + +import org.junit.Test; + +import static com.google.common.truth.Truth.assertThat; + +public class RichTextTest extends BaseTest { + @Test + @Enqueue(value = "rich_text/simple_headline_1.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_headline_1_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(2); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichHeading.class); + final CDARichHeading heading = (CDARichHeading) rich.getContent().get(0); + + assertThat(heading.getLevel()).isEqualTo(1); + assertThat(heading.getContent()).hasSize(1); + assertThat(heading.getContent().get(0)).isInstanceOf(CDARichText.class); + final CDARichText text = (CDARichText) heading.getContent().get(0); + assertThat(text.getText()).isEqualTo("This is some simple text"); + } + + @Test + @Enqueue(value = "rich_text/simple_headline_2.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_headline_2_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(2); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichHeading.class); + final CDARichHeading heading = (CDARichHeading) rich.getContent().get(0); + + assertThat(heading.getLevel()).isEqualTo(2); + assertThat(heading.getContent()).hasSize(1); + assertThat(heading.getContent().get(0)).isInstanceOf(CDARichText.class); + final CDARichText text = (CDARichText) heading.getContent().get(0); + assertThat(text.getText()).isEqualTo("This is some simple text"); + } + + @Test + @Enqueue(value = "rich_text/simple_headline_3.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_headline_3_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(2); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichHeading.class); + final CDARichHeading heading = (CDARichHeading) rich.getContent().get(0); + + assertThat(heading.getLevel()).isEqualTo(3); + assertThat(heading.getContent()).hasSize(1); + assertThat(heading.getContent().get(0)).isInstanceOf(CDARichText.class); + final CDARichText text = (CDARichText) heading.getContent().get(0); + assertThat(text.getText()).isEqualTo("This is some simple text"); + } + + @Test + @Enqueue(value = "rich_text/simple_headline_4.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_headline_4_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(2); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichHeading.class); + final CDARichHeading heading = (CDARichHeading) rich.getContent().get(0); + + assertThat(heading.getLevel()).isEqualTo(4); + assertThat(heading.getContent()).hasSize(1); + assertThat(heading.getContent().get(0)).isInstanceOf(CDARichText.class); + final CDARichText text = (CDARichText) heading.getContent().get(0); + assertThat(text.getText()).isEqualTo("This is some simple text"); + } + + @Test + @Enqueue(value = "rich_text/simple_headline_5.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_headline_5_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(2); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichHeading.class); + final CDARichHeading heading = (CDARichHeading) rich.getContent().get(0); + + assertThat(heading.getLevel()).isEqualTo(5); + assertThat(heading.getContent()).hasSize(1); + assertThat(heading.getContent().get(0)).isInstanceOf(CDARichText.class); + final CDARichText text = (CDARichText) heading.getContent().get(0); + assertThat(text.getText()).isEqualTo("This is some simple text"); + } + + @Test + @Enqueue(value = "rich_text/simple_headline_6.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_headline_6_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(2); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichHeading.class); + final CDARichHeading heading = (CDARichHeading) rich.getContent().get(0); + + assertThat(heading.getLevel()).isEqualTo(6); + assertThat(heading.getContent()).hasSize(1); + assertThat(heading.getContent().get(0)).isInstanceOf(CDARichText.class); + final CDARichText text = (CDARichText) heading.getContent().get(0); + assertThat(text.getText()).isEqualTo("This is some simple text"); + } + + @Test + @Enqueue(value = "rich_text/simple_horizontal_rule.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_horizontal_rule_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(2); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichHorizontalRule.class); + } + + @Test + @Enqueue(value = "rich_text/simple_ordered_list.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_ordered_list_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(2); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichOrderedList.class); + + final CDARichOrderedList list = (CDARichOrderedList) rich.getContent().get(0); + assertThat(list.getContent()).hasSize(5); + + final CDARichBlock item = (CDARichBlock) list.getContent().get(0); + assertThat(item.getContent()).hasSize(1); + + final CDARichBlock block = (CDARichBlock) item.getContent().get(0); + assertThat(block.getContent().get(0)).isInstanceOf(CDARichText.class); + + final CDARichText text = (CDARichText) block.getContent().get(0); + assertThat(text.getText()).isEqualTo("This "); + } + + @Test + @Enqueue(value = "rich_text/simple_blockquote.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_quote_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(2); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichQuote.class); + final CDARichQuote quote = (CDARichQuote) rich.getContent().get(0); + + assertThat(quote.getContent()).hasSize(1); + assertThat(quote.getContent().get(0)).isInstanceOf(CDARichBlock.class); + + final CDARichBlock block = (CDARichBlock) quote.getContent().get(0); + assertThat(block.getContent()).hasSize(1); + + final CDARichText text = (CDARichText) block.getContent().get(0); + assertThat(text.getText()).isEqualTo("This is some simple blockquote"); + } + + @Test + @Enqueue(value = "rich_text/simple_text.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_text_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(1); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichBlock.class); + final CDARichBlock block = (CDARichBlock) rich.getContent().get(0); + + assertThat(block.getContent()).hasSize(1); + assertThat(block.getContent().get(0)).isInstanceOf(CDARichText.class); + final CDARichText text = (CDARichText) block.getContent().get(0); + assertThat(text.getText()).isEqualTo("This is some simple text"); + } + + @Test + @Enqueue(value = "rich_text/simple_text_bold.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_text_bold_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(1); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichBlock.class); + final CDARichBlock block = (CDARichBlock) rich.getContent().get(0); + + assertThat(block.getContent()).hasSize(1); + assertThat(block.getContent().get(0)).isInstanceOf(CDARichText.class); + + final CDARichText text = (CDARichText) block.getContent().get(0); + assertThat(text.getMarks()).hasSize(1); + assertThat(text.getMarks().get(0)).isInstanceOf(CDARichMarkBold.class); + assertThat(text.getText()).isEqualTo("This is some simple text"); + } + + @Test + @Enqueue(value = "rich_text/simple_text_code.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_text_code_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(1); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichBlock.class); + final CDARichBlock block = (CDARichBlock) rich.getContent().get(0); + + assertThat(block.getContent()).hasSize(1); + assertThat(block.getContent().get(0)).isInstanceOf(CDARichText.class); + + final CDARichText text = (CDARichText) block.getContent().get(0); + assertThat(text.getMarks()).hasSize(1); + assertThat(text.getMarks().get(0)).isInstanceOf(CDARichMarkCode.class); + assertThat(text.getText()).isEqualTo("This is some simple text"); + } + + @Test + @Enqueue(value = "rich_text/simple_text_italic.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_text_italic_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(1); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichBlock.class); + final CDARichBlock block = (CDARichBlock) rich.getContent().get(0); + + assertThat(block.getContent()).hasSize(1); + assertThat(block.getContent().get(0)).isInstanceOf(CDARichText.class); + + final CDARichText text = (CDARichText) block.getContent().get(0); + assertThat(text.getMarks()).hasSize(1); + assertThat(text.getMarks().get(0)).isInstanceOf(CDARichMarkItalic.class); + assertThat(text.getText()).isEqualTo("This is some simple text"); + } + + @Test + @Enqueue(value = "rich_text/simple_text_underline.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_text_underline_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(1); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichBlock.class); + final CDARichBlock block = (CDARichBlock) rich.getContent().get(0); + + assertThat(block.getContent()).hasSize(1); + assertThat(block.getContent().get(0)).isInstanceOf(CDARichText.class); + + final CDARichText text = (CDARichText) block.getContent().get(0); + assertThat(text.getMarks()).hasSize(1); + assertThat(text.getMarks().get(0)).isInstanceOf(CDARichMarkUnderline.class); + assertThat(text.getText()).isEqualTo("This is some simple text"); + } + + @Test + @Enqueue(value = "rich_text/simple_text_mixed_bold_italic_underline_code_all.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_text_mixed_bold_italic_underline_code_all_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(1); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichBlock.class); + final CDARichBlock block = (CDARichBlock) rich.getContent().get(0); + + assertThat(block.getContent()).hasSize(9); + + final CDARichText first = (CDARichText) block.getContent().get(0); + assertThat(first.getText()).isEqualTo("This"); + assertThat(first.getMarks()).hasSize(1); + assertThat(first.getMarks().get(0)).isInstanceOf(CDARichMarkBold.class); + + final CDARichText second = (CDARichText) block.getContent().get(1); + assertThat(second.getText()).isEqualTo(" "); + assertThat(second.getMarks()).hasSize(0); + + final CDARichText third = (CDARichText) block.getContent().get(2); + assertThat(third.getText()).isEqualTo("is"); + assertThat(third.getMarks()).hasSize(1); + assertThat(third.getMarks().get(0)).isInstanceOf(CDARichMarkItalic.class); + + final CDARichText fourth = (CDARichText) block.getContent().get(3); + assertThat(fourth.getText()).isEqualTo(" "); + assertThat(fourth.getMarks()).hasSize(0); + + final CDARichText fifth = (CDARichText) block.getContent().get(4); + assertThat(fifth.getText()).isEqualTo("some"); + assertThat(fifth.getMarks()).hasSize(1); + assertThat(fifth.getMarks().get(0)).isInstanceOf(CDARichMarkUnderline.class); + + final CDARichText sixth = (CDARichText) block.getContent().get(5); + assertThat(sixth.getText()).isEqualTo(" "); + assertThat(sixth.getMarks()).hasSize(0); + + final CDARichText senventh = (CDARichText) block.getContent().get(6); + assertThat(senventh.getText()).isEqualTo("simple"); + assertThat(senventh.getMarks()).hasSize(1); + assertThat(senventh.getMarks().get(0)).isInstanceOf(CDARichMarkCode.class); + + final CDARichText eights = (CDARichText) block.getContent().get(7); + assertThat(eights.getText()).isEqualTo(" "); + assertThat(eights.getMarks()).hasSize(0); + + final CDARichText ninth = (CDARichText) block.getContent().get(8); + assertThat(ninth.getText()).isEqualTo("text"); + assertThat(ninth.getMarks()).hasSize(4); + assertThat(ninth.getMarks().get(0)).isInstanceOf(CDARichMarkBold.class); + assertThat(ninth.getMarks().get(1)).isInstanceOf(CDARichMarkItalic.class); + assertThat(ninth.getMarks().get(2)).isInstanceOf(CDARichMarkUnderline.class); + assertThat(ninth.getMarks().get(3)).isInstanceOf(CDARichMarkCode.class); + } + + @Test + @Enqueue(value = "rich_text/simple_text_embedded.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_text_embedded_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(2); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichEmbeddedLink.class); + final CDARichEmbeddedLink embedded = (CDARichEmbeddedLink) rich.getContent().get(0); + + assertThat(embedded.getData()).isInstanceOf(CDAEntry.class); + final CDAEntry cdaEntry = (CDAEntry) embedded.getData(); + + assertThat(cdaEntry.getField("name")).isEqualTo("simple_text"); + + assertThat(embedded.getContent().get(0)).isInstanceOf(CDARichText.class); + final CDARichText text = (CDARichText) embedded.getContent().get(0); + assertThat(text.getText()).isEqualTo(""); + } + + @Test + @Enqueue(value = "rich_text/simple_text_with_link.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_text_with_link_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(1); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichBlock.class); + final CDARichBlock block = (CDARichBlock) rich.getContent().get(0); + + assertThat(block.getContent()).hasSize(3); + assertThat(block.getContent().get(0)).isInstanceOf(CDARichText.class); + assertThat(block.getContent().get(1)).isInstanceOf(CDARichHyperLink.class); + assertThat(block.getContent().get(2)).isInstanceOf(CDARichText.class); + + final CDARichHyperLink link = (CDARichHyperLink) block.getContent().get(1); + assertThat(link.getData()).isEqualTo("https://www.contentful.com"); + assertThat(link.getContent().get(0)).isInstanceOf(CDARichText.class); + + final CDARichText text = (CDARichText) link.getContent().get(0); + assertThat(text.getText()).isEqualTo("This is some simple text"); + } + + @Test + @Enqueue(value = "rich_text/simple_unordered_list.json", defaults = {"rich_text/locales.json", "rich_text/content_types.json"}) + public void simple_unordered_list_test() { + final CDAEntry entry = (CDAEntry) client.fetch(CDAEntry.class).all().items().get(0); + final CDARichDocument rich = entry.getField("rich"); + assertThat(rich).isNotNull(); + + assertThat(rich.getContent()).hasSize(2); + assertThat(rich.getContent().get(0)).isInstanceOf(CDARichUnorderedList.class); + + final CDARichUnorderedList list = (CDARichUnorderedList) rich.getContent().get(0); + assertThat(list.getDecoration()).isEqualTo("*"); + assertThat(list.getContent()).hasSize(6); + + final CDARichBlock item = (CDARichBlock) list.getContent().get(0); + assertThat(item.getContent()).hasSize(1); + + final CDARichBlock block = (CDARichBlock) item.getContent().get(0); + assertThat(block.getContent().get(0)).isInstanceOf(CDARichText.class); + + final CDARichText text = (CDARichText) block.getContent().get(0); + assertThat(text.getText()).isEqualTo("This"); + } +} diff --git a/src/test/java/com/contentful/java/cda/SpaceTest.java b/src/test/java/com/contentful/java/cda/SpaceTest.java index 3dc5b91e..11d47423 100644 --- a/src/test/java/com/contentful/java/cda/SpaceTest.java +++ b/src/test/java/com/contentful/java/cda/SpaceTest.java @@ -10,7 +10,7 @@ public class SpaceTest extends BaseTest { @Test @Enqueue(value = "demo/space.json", defaults = {}) - public void fetchSpace() throws Exception { + public void fetchSpace() { CDASpace space = client.fetchSpace(); assertThat(space.name()).isEqualTo("Contentful Example API"); assertThat(space.id()).isEqualTo("cfexampleapi"); diff --git a/src/test/java/com/contentful/java/cda/SyncTest.java b/src/test/java/com/contentful/java/cda/SyncTest.java index 095bd1a7..b087ca81 100644 --- a/src/test/java/com/contentful/java/cda/SyncTest.java +++ b/src/test/java/com/contentful/java/cda/SyncTest.java @@ -20,7 +20,7 @@ public class SyncTest extends BaseTest { "demo/locales.json", "demo/content_types.json", "demo/sync_update_p1.json", "demo/sync_update_p2.json" }) - public void sync() throws Exception { + public void sync() { SynchronizedSpace first = client.sync().observe().blockingFirst(); assertInitial(first); @@ -37,18 +37,18 @@ private void assertUpdate(SynchronizedSpace space) { CDAEntry superCat = space.entries().get("supercat"); assertThat(superCat).isNotNull(); - assertThat(superCat.getField("name")).isEqualTo("Super Cat"); - assertThat(superCat.getField("color")).isEqualTo("black"); + assertThat(superCat.getField("name")).isEqualTo("Super Cat"); + assertThat(superCat.getField("color")).isEqualTo("black"); List likes = superCat.getField("likes"); assertThat(likes).containsExactly("nothing"); CDAEntry nyanCat = space.entries().get("nyancat"); assertThat(nyanCat).isNotNull(); - assertThat(nyanCat.getField("name")).isEqualTo("foo"); - assertThat(nyanCat.getField("color")).isEqualTo("red"); + assertThat(nyanCat.getField("name")).isEqualTo("foo"); + assertThat(nyanCat.getField("color")).isEqualTo("red"); likes = nyanCat.getField("likes"); assertThat(likes).containsExactly("a", "b", "c"); - assertThat(nyanCat.getField("bestFriend")).isSameAs(superCat); + assertThat(nyanCat.getField("bestFriend")).isSameAs(superCat); } private void assertInitial(SynchronizedSpace space) { @@ -78,28 +78,28 @@ private void assertInitial(SynchronizedSpace space) { assertThat(space.entries()).hasSize(11); CDAEntry nyanCat = space.entries().get("nyancat"); assertThat(nyanCat).isNotNull(); - assertThat(nyanCat.getField("name")).isEqualTo("Nyan Cat"); - assertThat(nyanCat.getField("bestFriend")).isInstanceOf(CDAEntry.class); + assertThat(nyanCat.getField("name")).isEqualTo("Nyan Cat"); + assertThat(nyanCat.getField("bestFriend")).isInstanceOf(CDAEntry.class); CDAEntry happyCat = space.entries().get("happycat"); assertThat(happyCat).isNotNull(); - assertThat(happyCat.getField("name")).isEqualTo("Happy Cat"); + assertThat(happyCat.getField("name")).isEqualTo("Happy Cat"); // Localization assertThat(nyanCat.defaultLocale).isEqualTo("en-US"); - assertThat(nyanCat.getField("name")).isEqualTo("Nyan Cat"); - assertThat(nyanCat.getField("color")).isEqualTo("rainbow"); + assertThat(nyanCat.getField("name")).isEqualTo("Nyan Cat"); + assertThat(nyanCat.getField("color")).isEqualTo("rainbow"); final LocalizedResource.Localizer localizedNyanCat = nyanCat.localize("tlh"); - assertThat(localizedNyanCat.getField("name")).isEqualTo("Nyan vIghro'"); - assertThat(localizedNyanCat.getField("color")).isEqualTo("rainbow"); // fallback - assertThat(localizedNyanCat.getField("non-existing-does-not-throw")).isNull(); + assertThat(localizedNyanCat.getField("name")).isEqualTo("Nyan vIghro'"); + assertThat(localizedNyanCat.getField("color")).isEqualTo("rainbow"); // fallback + assertThat(localizedNyanCat.getField("non-existing-does-not-throw")).isNull(); } @SuppressWarnings("unchecked") @Test @Enqueue(defaults = {}, value = { "shallow/locales.json", "shallow/types.json", "shallow/initial.json", "shallow/locales.json", "shallow/types.json", "shallow/update.json" }) - public void testRawFields() throws Exception { + public void testRawFields() { SynchronizedSpace space = client.sync().fetch(); assertThat(space.items()).hasSize(2); assertThat(space.assets()).hasSize(1); @@ -107,7 +107,7 @@ public void testRawFields() throws Exception { CDAEntry foo = space.entries().get("2k5aHpfw7m0waMKYksC2Ww"); assertThat(foo).isNotNull(); - assertThat(foo.getField("image")).isNotNull(); + assertThat(foo.getField("image")).isNotNull(); // image Map> rawImage = (Map>) foo.rawFields().get("image"); @@ -123,7 +123,7 @@ public void testRawFields() throws Exception { space = client.sync(syncToken).fetch(); foo = space.entries().get("2k5aHpfw7m0waMKYksC2Ww"); assertThat(foo).isNotNull(); - assertThat(foo.getField("image")).isNull(); + assertThat(foo.getField("image")).isNull(); // image rawImage = (Map>) foo.rawFields().get("image"); @@ -145,7 +145,7 @@ public void testRawFields() throws Exception { "links_invalid/sync_initial.json" } ) - public void invalidLinkDoesNotThrow() throws Exception { + public void invalidLinkDoesNotThrow() { client.sync().fetch(); } @@ -153,7 +153,7 @@ public void invalidLinkDoesNotThrow() throws Exception { "demo/sync_initial_preview_p1.json", "demo/sync_initial_preview_p2.json", "demo/locales.json", "demo/content_types.json" }) - public void syncingInPreviewWithTokenSyncsInitial() throws Exception { + public void syncingInPreviewWithTokenSyncsInitial() { client = createPreviewClient(); final SynchronizedSpace space = client.sync("sometoken").fetch(); @@ -167,7 +167,7 @@ public void syncingInPreviewWithTokenSyncsInitial() throws Exception { "demo/sync_initial_preview_p1.json", "demo/sync_initial_preview_p2.json", "demo/locales.json", "demo/content_types.json" }) - public void syncingInPreviewWithPreviousSpaceSyncsInitial() throws Exception { + public void syncingInPreviewWithPreviousSpaceSyncsInitial() { client = createPreviewClient(); SynchronizedSpace space = client.sync().fetch(); @@ -182,7 +182,7 @@ public void syncingInPreviewWithPreviousSpaceSyncsInitial() throws Exception { "demo/sync_initial_preview_p1.json", "demo/sync_initial_preview_p2.json", "demo/locales.json"}) - public void syncingWithPreviewWorks() throws Exception { + public void syncingWithPreviewWorks() { client = createPreviewClient(); final SynchronizedSpace space = client.sync().fetch(); @@ -194,7 +194,7 @@ public void syncingWithPreviewWorks() throws Exception { "demo/sync_initial_staging_p1.json", "demo/sync_initial_staging_p2.json", "demo/locales.json"}) - public void syncingWithEnvironmentsWorks() throws Exception { + public void syncingWithEnvironmentsWorks() { client = createBuilder() .setEnvironment("staging") .build(); @@ -213,14 +213,14 @@ public void syncingWithEnvironmentsWorks() throws Exception { } @Test - public void syncUsesResourceType() throws Exception { + public void syncUsesResourceType() { final SyncQuery query = client.sync(onlyDeletedEntries()); assertThat(query.type.getName()).isEqualTo("DeletedEntry"); } @Test - public void syncUsesContentType() throws Exception { + public void syncUsesContentType() { final SyncQuery query = client.sync(onlyEntriesOfType("customType")); assertThat(query.type.getContentType()).isEqualTo("customType"); diff --git a/src/test/java/com/contentful/java/cda/integration/Integration.java b/src/test/java/com/contentful/java/cda/integration/Integration.java index a6052267..bc65860d 100644 --- a/src/test/java/com/contentful/java/cda/integration/Integration.java +++ b/src/test/java/com/contentful/java/cda/integration/Integration.java @@ -47,7 +47,7 @@ public class Integration { CDAClient client; - @Before public void setUp() throws Exception { + @Before public void setUp() { client = CDAClient.builder() .setSpace("cfexampleapi") .setToken("b4c0n73n7fu1") @@ -55,7 +55,7 @@ public class Integration { } @Test - public void fetchContentType() throws Exception { + public void fetchContentType() { CDAContentType cat = client.fetch(CDAContentType.class).one("cat"); assertThat(cat.name()).isEqualTo("Cat"); assertThat(cat.displayField()).isEqualTo("name"); @@ -64,7 +64,7 @@ public void fetchContentType() throws Exception { } @Test - public void fetchNyancatEntryAsync() throws Exception { + public void fetchNyancatEntryAsync() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final CDAEntry[] result = {null}; @@ -85,7 +85,7 @@ public void fetchNyancatEntryAsync() throws Exception { } @Test - public void fetchAllEntries() throws Exception { + public void fetchAllEntries() { CDAArray array = client.fetch(CDAEntry.class).all(); assertThat(array.items()).hasSize(10); assertThat(array.assets()).hasSize(4); @@ -105,22 +105,22 @@ public void fetchAllEntries() throws Exception { } @Test(expected = CDAResourceNotFoundException.class) - public void fetchOneNonExistingEntry() throws Exception { + public void fetchOneNonExistingEntry() { client.fetch(CDAEntry.class).one("fooooo"); } @Test(expected = CDAResourceNotFoundException.class) - public void fetchOneNonExistingAsset() throws Exception { + public void fetchOneNonExistingAsset() { client.fetch(CDAAsset.class).one("fooooo"); } @Test(expected = CDAResourceNotFoundException.class) - public void fetchOneNonExistingContentType() throws Exception { + public void fetchOneNonExistingContentType() { client.fetch(CDAContentType.class).one("fooooo"); } @Test - public void fetchSpace() throws Exception { + public void fetchSpace() { CDASpace space = client.fetchSpace(); assertThat(space.name()).isEqualTo("Contentful Example API"); assertThat(space.id()).isEqualTo("cfexampleapi"); @@ -129,7 +129,7 @@ public void fetchSpace() throws Exception { // "/spaces/{space_id}/sync?initial=true", @Test - public void sync() throws Exception { + public void sync() { SynchronizedSpace space = client.sync().observe().blockingFirst(); assertInitial(space); @@ -141,16 +141,16 @@ public void sync() throws Exception { CDAEntry nyanCat = space.entries().get("nyancat"); assertThat(nyanCat).isNotNull(); - assertThat(nyanCat.getField("tlh", "name")).isEqualTo("Nyan vIghro'"); - assertThat(nyanCat.getField("name")).isEqualTo("Nyan Cat"); - assertThat(nyanCat.getField("color")).isEqualTo("rainbow"); + assertThat(nyanCat.getField("tlh", "name")).isEqualTo("Nyan vIghro'"); + assertThat(nyanCat.getField("name")).isEqualTo("Nyan Cat"); + assertThat(nyanCat.getField("color")).isEqualTo("rainbow"); List likes = nyanCat.getField("likes"); assertThat(likes).containsExactly("rainbows", "fish"); } // "/spaces/{space_id}/sync?initial=true&type=Entry&content_type=cat", @Test - public void syncOnlyContentTypeCat() throws Exception { + public void syncOnlyContentTypeCat() { SynchronizedSpace space = client.sync(onlyEntriesOfType("cat")).observe().blockingFirst(); space = client.sync(space).observe().blockingFirst(); @@ -160,15 +160,15 @@ public void syncOnlyContentTypeCat() throws Exception { CDAEntry nyanCat = space.entries().get("nyancat"); assertThat(nyanCat).isNotNull(); - assertThat(nyanCat.getField("name")).isEqualTo("Nyan Cat"); - assertThat(nyanCat.getField("color")).isEqualTo("rainbow"); + assertThat(nyanCat.getField("name")).isEqualTo("Nyan Cat"); + assertThat(nyanCat.getField("color")).isEqualTo("rainbow"); List likes = nyanCat.getField("likes"); assertThat(likes).containsExactly("rainbows", "fish"); } // "/spaces/{space_id}/sync?initial=true&type=DELETEDASSETS", @Test - public void syncTypeOfDeletedAssets() throws Exception { + public void syncTypeOfDeletedAssets() { final SynchronizedSpace space = client.sync(onlyDeletedAssets()).fetch(); assertThat(space.nextSyncUrl()).isNotEmpty(); @@ -277,7 +277,7 @@ public void fetchEntriesWithQuery() { //"/spaces/{space_id}/entries?limit={value}", @Test - public void fetchEntriesWithLimit() throws Exception { + public void fetchEntriesWithLimit() { final CDAArray entries = client.fetch(CDAEntry.class).limit(5).all(); assertThat(entries.limit()).isEqualTo(5); @@ -286,7 +286,7 @@ public void fetchEntriesWithLimit() throws Exception { //"/spaces/{space_id}/entries?skip={value}", @Test - public void fetchEntriesWithSkip() throws Exception { + public void fetchEntriesWithSkip() { final CDAArray entries = client.fetch(CDAEntry.class).skip(4).all(); assertThat(entries.skip()).isEqualTo(4); @@ -390,7 +390,7 @@ public void fetchWithLimit() { assertThat(found.items().size()).isEqualTo(1); CDAEntry entry = (CDAEntry) found.items().get(0); - assertThat(entry.getField("name")).isEqualTo("Berlin"); + assertThat(entry.getField("name")).isEqualTo("Berlin"); } //"/spaces/{space_id}/entries?skip={value}", @@ -403,7 +403,7 @@ public void fetchWithSkip() { assertThat(found.items().size()).isEqualTo(9); CDAEntry entry = (CDAEntry) found.items().get(0); - assertThat(entry.getField("name")).isEqualTo("London"); + assertThat(entry.getField("name")).isEqualTo("London"); } //"/spaces/{space_id}/entries?include={value}", @@ -422,14 +422,15 @@ public void fetchWithoutIncluding() { public void fetchWithInQuery() { CDAArray found = client.fetch(CDAEntry.class) .where("sys.id", HasOneOf, "finn", "jake") + .orderBy("sys.id") .all(); assertThat(found.items().size()).isEqualTo(2); CDAEntry finn = (CDAEntry) found.items().get(0); - assertThat(finn.getField("name")).isEqualTo("Finn"); + assertThat(finn.getField("name")).isEqualTo("Finn"); CDAEntry jake = (CDAEntry) found.items().get(1); - assertThat(jake.getField("name")).isEqualTo("Jake"); + assertThat(jake.getField("name")).isEqualTo("Jake"); } //"/spaces/{space_id}/entries?{attribute}%5Ball%5D={value}", @@ -442,7 +443,7 @@ public void fetchWithAllQuery() { assertThat(found.items().size()).isEqualTo(1); CDAEntry finn = (CDAEntry) found.items().get(0); - assertThat(finn.getField("name")).isEqualTo("Nyan Cat"); + assertThat(finn.getField("name")).isEqualTo("Nyan Cat"); } //"/spaces/{space_id}/entries?content_type={content_type}&{attribute}%5Bnin%5D={value}", @@ -475,7 +476,7 @@ public void fetchWithExistsQueryOnFields() { .all(); assertThat(found.items()).hasSize(1); - assertThat(found.entries().get("garfield").getField("name")).isEqualTo("Garfield"); + assertThat(found.entries().get("garfield").getField("name")).isEqualTo("Garfield"); } //"/spaces/{space_id}/entries?content_type={content_type}&{attribute}%5Blte%5D={value}", @@ -488,7 +489,7 @@ public void fetchEntriesInRange() { assertThat(found.items().size()).isEqualTo(1); CDAEntry nyancat = (CDAEntry) found.items().get(0); - assertThat(nyancat.getField("name")).isEqualTo("Garfield"); + assertThat(nyancat.getField("name")).isEqualTo("Garfield"); } //"/spaces/{space_id}/entries?{attribute}%5Blte%5D={value}", @@ -512,7 +513,7 @@ public void fetchEntriesEarlierOrAt() { assertThat(found.items().size()).isEqualTo(1); CDAEntry cat = (CDAEntry) found.items().get(0); - assertThat(cat.getField("name")).isEqualTo("Garfield"); + assertThat(cat.getField("name")).isEqualTo("Garfield"); } //"/spaces/{space_id}/entries?content_type={content_type}&{attribute}%5Blte%5D={value}", @@ -525,7 +526,7 @@ public void fetchEntriesLaterOrAt() { assertThat(found.items().size()).isEqualTo(1); CDAEntry cat = (CDAEntry) found.items().get(0); - assertThat(cat.getField("name")).isEqualTo("Nyan Cat"); + assertThat(cat.getField("name")).isEqualTo("Nyan Cat"); } //"/spaces/{space_id}/entries?content_type={content_type}&fields.{field_id}%5Bmatch%5D={value}", @@ -538,7 +539,7 @@ public void fetchEntriesWithFieldMatching() { assertThat(found.items().size()).isEqualTo(1); CDAEntry nyancat = (CDAEntry) found.items().get(0); - assertThat(nyancat.getField("name")).isEqualTo("Happy Cat"); + assertThat(nyancat.getField("name")).isEqualTo("Happy Cat"); } //"/spaces/{space_id}/entries?fields.center%5Bnear%5D={coordinate}&content_type={content_type}", @@ -551,9 +552,9 @@ public void fetchEntriesNearby() { assertThat(found.items().size()).isEqualTo(4); CDAEntry sf = (CDAEntry) found.items().get(0); - assertThat(sf.getField("name")).isEqualTo("San Francisco"); + assertThat(sf.getField("name")).isEqualTo("San Francisco"); CDAEntry london = (CDAEntry) found.items().get(1); - assertThat(london.getField("name")).isEqualTo("London"); + assertThat(london.getField("name")).isEqualTo("London"); } //"/spaces/{space_id}/entries?fields.center%5Bnear%5D={coordinate}&content_type={content_type}", @@ -566,7 +567,7 @@ public void fetchEntriesNearbyCircle() { assertThat(found.items().size()).isEqualTo(1); CDAEntry sf = (CDAEntry) found.items().get(0); - assertThat(sf.getField("name")).isEqualTo("San Francisco"); + assertThat(sf.getField("name")).isEqualTo("San Francisco"); } //"/spaces/{space_id}/entries?fields.center%5Bwithin%5D={rectangle}&content_type={content_type}", @@ -579,7 +580,7 @@ public void fetchEntriesWithinBoundingBox() { assertThat(found.items().size()).isEqualTo(1); CDAEntry sf = (CDAEntry) found.items().get(0); - assertThat(sf.getField("name")).isEqualTo("San Francisco"); + assertThat(sf.getField("name")).isEqualTo("San Francisco"); } //"/spaces/{space_id}/entries?{attribute}%5Bne%5D={value}", @@ -637,7 +638,7 @@ public void fetchOneLocale() { } @SuppressWarnings("unchecked") @Test - public void testRawFields() throws Exception { + public void testRawFields() { SynchronizedSpace space = client.sync().fetch(); assertThat(space.items()).hasSize(14); assertThat(space.assets()).hasSize(4); @@ -645,8 +646,8 @@ public void testRawFields() throws Exception { CDAEntry happycat = space.entries().get("happycat"); assertThat(happycat).isNotNull(); - assertThat(happycat.getField("image")).isNotNull(); - assertThat(happycat.getField("bestFriend")).isNotNull(); + assertThat(happycat.getField("image")).isNotNull(); + assertThat(happycat.getField("bestFriend")).isNotNull(); // image Map> rawImage = (Map>) happycat.rawFields().get("image"); @@ -660,7 +661,7 @@ public void testRawFields() throws Exception { } @Test(expected = CDAHttpException.class) - public void testErrorResponse() throws Exception { + public void testErrorResponse() { try { client.fetch(CDAEntry.class).where("sys.asdf", "fas").one("nope"); } catch (CDAHttpException cdaException) { @@ -693,28 +694,28 @@ private void assertInitial(SynchronizedSpace space) { assertThat(space.entries()).hasSize(10); CDAEntry nyanCat = space.entries().get("nyancat"); assertThat(nyanCat).isNotNull(); - assertThat(nyanCat.getField("name")).isEqualTo("Nyan Cat"); - assertThat(nyanCat.getField("bestFriend")).isInstanceOf(CDAEntry.class); + assertThat(nyanCat.getField("name")).isEqualTo("Nyan Cat"); + assertThat(nyanCat.getField("bestFriend")).isInstanceOf(CDAEntry.class); CDAEntry happyCat = space.entries().get("happycat"); assertThat(happyCat).isNotNull(); - assertThat(happyCat.getField("name")).isEqualTo("Happy Cat"); + assertThat(happyCat.getField("name")).isEqualTo("Happy Cat"); // Localization - assertThat(nyanCat.getField("name")).isEqualTo("Nyan Cat"); - assertThat(nyanCat.getField("color")).isEqualTo("rainbow"); + assertThat(nyanCat.getField("name")).isEqualTo("Nyan Cat"); + assertThat(nyanCat.getField("color")).isEqualTo("rainbow"); final LocalizedResource.Localizer localizedCat = nyanCat.localize("tlh"); - assertThat(localizedCat.getField("name")).isEqualTo("Nyan vIghro'"); - assertThat(localizedCat.getField("color")).isEqualTo("rainbow"); // fallback - assertThat(localizedCat.getField("non-existing-does-not-throw")).isNull(); + assertThat(localizedCat.getField("name")).isEqualTo("Nyan vIghro'"); + assertThat(localizedCat.getField("color")).isEqualTo("rainbow"); // fallback + assertThat(localizedCat.getField("non-existing-does-not-throw")).isNull(); } void assertNyanCat(CDAEntry entry) { assertThat(entry.id()).isEqualTo("nyancat"); - assertThat(entry.getField("name")).isEqualTo("Nyan Cat"); - assertThat(entry.getField("color")).isEqualTo("rainbow"); - assertThat(entry.getField("birthday")).isEqualTo("2011-04-04T22:00:00+00:00"); - assertThat(entry.getField("lives")).isEqualTo(1337.0); + assertThat(entry.getField("name")).isEqualTo("Nyan Cat"); + assertThat(entry.getField("color")).isEqualTo("rainbow"); + assertThat(entry.getField("birthday")).isEqualTo("2011-04-04T22:00:00+00:00"); + assertThat(entry.getField("lives")).isEqualTo(1337.0); List likes = entry.getField("likes"); assertThat(likes).containsExactly("rainbows", "fish"); @@ -725,7 +726,7 @@ void assertNyanCat(CDAEntry entry) { // Localization final LocalizedResource.Localizer localizedCat = entry.localize("tlh"); - assertThat(localizedCat.getField("color")).isEqualTo("rainbow"); - assertThat(localizedCat.getField("non-existing-does-not-throw")).isNull(); + assertThat(localizedCat.getField("color")).isEqualTo("rainbow"); + assertThat(localizedCat.getField("non-existing-does-not-throw")).isNull(); } } diff --git a/src/test/java/com/contentful/java/cda/integration/IntegrationWithMasterEnvironment.java b/src/test/java/com/contentful/java/cda/integration/IntegrationWithMasterEnvironment.java index 2e9bfc4d..7df9882d 100644 --- a/src/test/java/com/contentful/java/cda/integration/IntegrationWithMasterEnvironment.java +++ b/src/test/java/com/contentful/java/cda/integration/IntegrationWithMasterEnvironment.java @@ -6,14 +6,16 @@ import com.contentful.java.cda.CDALocale; import com.contentful.java.cda.CDASpace; import com.contentful.java.cda.LocalizedResource; +import com.contentful.java.cda.SynchronizedSpace; import java.util.List; import static com.contentful.java.cda.CDAType.SPACE; +import static com.contentful.java.cda.SyncType.onlyDeletedAssets; import static com.google.common.truth.Truth.assertThat; public class IntegrationWithMasterEnvironment extends Integration { - @Override public void setUp() throws Exception { + @Override public void setUp() { client = CDAClient.builder() .setSpace("5s4tdjmyjfpl") .setToken("84017d3a5da6d3ae9c733c6c210c55eebc3da033730b4e5093a6e6aa099b4995") @@ -22,7 +24,7 @@ public class IntegrationWithMasterEnvironment extends Integration { } // space id and so on changed on master - @Override public void fetchSpace() throws Exception { + @Override public void fetchSpace() { CDASpace space = client.fetchSpace(); assertThat(space.name()).isEqualTo("Contentful Example API with En"); assertThat(space.id()).isEqualTo("5s4tdjmyjfpl"); @@ -50,10 +52,10 @@ public class IntegrationWithMasterEnvironment extends Integration { @Override void assertNyanCat(CDAEntry entry) { assertThat(entry.id()).isEqualTo("nyancat"); - assertThat(entry.getField("name")).isEqualTo("Nyan Cat"); - assertThat(entry.getField("color")).isEqualTo("rainbow"); - assertThat(entry.getField("birthday")).isEqualTo("2011-04-04T22:00+00:00"); - assertThat(entry.getField("lives")).isEqualTo(1337.0); + assertThat(entry.getField("name")).isEqualTo("Nyan Cat"); + assertThat(entry.getField("color")).isEqualTo("rainbow"); + assertThat(entry.getField("birthday")).isEqualTo("2011-04-04T22:00+00:00"); + assertThat(entry.getField("lives")).isEqualTo(1337.0); List likes = entry.getField("likes"); assertThat(likes).containsExactly("rainbows", "fish"); @@ -64,7 +66,17 @@ public class IntegrationWithMasterEnvironment extends Integration { // Localization final LocalizedResource.Localizer localized = entry.localize("tlh"); - assertThat(localized.getField("color")).isEqualTo("rainbow"); - assertThat(localized.getField("non-existing-does-not-throw")).isNull(); + assertThat(localized.getField("color")).isEqualTo("rainbow"); + assertThat(localized.getField("non-existing-does-not-throw")).isNull(); + } + + @Override public void syncTypeOfDeletedAssets() { + final SynchronizedSpace space = client.sync(onlyDeletedAssets()).fetch(); + + assertThat(space.nextSyncUrl()).isNotEmpty(); + assertThat(space.items()).hasSize(0); + assertThat(space.assets()).hasSize(0); + assertThat(space.deletedEntries()).hasSize(0); + assertThat(space.deletedAssets()).hasSize(0); } } diff --git a/src/test/java/com/contentful/java/cda/integration/IntegrationWithStagingEnvironment.java b/src/test/java/com/contentful/java/cda/integration/IntegrationWithStagingEnvironment.java index 03ea2ef4..b1405a17 100644 --- a/src/test/java/com/contentful/java/cda/integration/IntegrationWithStagingEnvironment.java +++ b/src/test/java/com/contentful/java/cda/integration/IntegrationWithStagingEnvironment.java @@ -4,15 +4,18 @@ import com.contentful.java.cda.CDAClient; import com.contentful.java.cda.CDAEntry; import com.contentful.java.cda.CDAHttpException; +import com.contentful.java.cda.SynchronizedSpace; import org.junit.Test; +import static com.contentful.java.cda.QueryOperation.Exists; import static com.contentful.java.cda.QueryOperation.IsEarlierOrAt; import static com.contentful.java.cda.QueryOperation.IsEarlierThan; +import static com.contentful.java.cda.SyncType.onlyDeletedAssets; import static com.google.common.truth.Truth.assertThat; public class IntegrationWithStagingEnvironment extends IntegrationWithMasterEnvironment { - public void setUp() throws Exception { + public void setUp() { client = CDAClient.builder() .setSpace("5s4tdjmyjfpl") .setToken("16bc99120b1e0b33cc16323324baab4dbe9350c0d7a2b222ed8d7d5328e95bf3") @@ -23,7 +26,7 @@ public void setUp() throws Exception { // cannot fetch space on non master token @Test(expected = CDAHttpException.class) - @Override public void fetchSpace() throws Exception { + @Override public void fetchSpace() { client.fetchSpace(); } @@ -36,7 +39,7 @@ public void fetchEntriesInRange() { assertThat(found.items().size()).isEqualTo(1); CDAEntry nyancat = (CDAEntry) found.items().get(0); - assertThat(nyancat.getField("name")).isEqualTo("Staged Garfield"); + assertThat(nyancat.getField("name")).isEqualTo("Staged Garfield"); } //"/spaces/{space_id}/entries?content_type={content_type}&{attribute}%5Blte%5D={value}", @@ -49,7 +52,27 @@ public void fetchEntriesEarlierOrAt() { assertThat(found.items().size()).isEqualTo(1); CDAEntry cat = (CDAEntry) found.items().get(0); - assertThat(cat.getField("name")).isEqualTo("Staged Garfield"); + assertThat(cat.getField("name")).isEqualTo("Staged Garfield"); } + @Override + public void fetchWithExistsQueryOnFields() { + CDAArray found = client.fetch(CDAEntry.class) + .withContentType("cat") + .where("fields.bestFriend", Exists, false) // entries without id + .all(); + + assertThat(found.items()).hasSize(1); + assertThat(found.entries().get("garfield").getField("name")).isEqualTo("Staged Garfield"); + } + + @Override public void syncTypeOfDeletedAssets() { + final SynchronizedSpace space = client.sync(onlyDeletedAssets()).fetch(); + + assertThat(space.nextSyncUrl()).isNotEmpty(); + assertThat(space.items()).hasSize(0); + assertThat(space.assets()).hasSize(0); + assertThat(space.deletedEntries()).hasSize(0); + assertThat(space.deletedAssets()).hasSize(0); + } } diff --git a/src/test/java/com/contentful/java/cda/lib/EnqueueResponseRule.java b/src/test/java/com/contentful/java/cda/lib/EnqueueResponseRule.java index 13b0cc50..cf2bbb8c 100644 --- a/src/test/java/com/contentful/java/cda/lib/EnqueueResponseRule.java +++ b/src/test/java/com/contentful/java/cda/lib/EnqueueResponseRule.java @@ -20,8 +20,7 @@ public class EnqueueResponseRule implements MethodRule { + "when using @" + Enqueue.class.getSimpleName()); } - List responses = new ArrayList(); - responses.addAll(enqueueToTestResponse(enqueue)); + List responses = new ArrayList<>(enqueueToTestResponse(enqueue)); ((BaseTest) o).setResponseQueue(responses); } return statement; @@ -29,7 +28,7 @@ public class EnqueueResponseRule implements MethodRule { private Collection enqueueToTestResponse(Enqueue enqueue) { final List responses - = new ArrayList( + = new ArrayList<>( enqueue.complex().length + enqueue.value().length); diff --git a/src/test/resources/rich_text/content_types.json b/src/test/resources/rich_text/content_types.json new file mode 100644 index 00000000..068a1e79 --- /dev/null +++ b/src/test/resources/rich_text/content_types.json @@ -0,0 +1,56 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "rich", + "type": "ContentType", + "createdAt": "2018-10-17T13:19:01.984Z", + "updatedAt": "2018-10-17T13:32:19.221Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 3 + }, + "displayField": "name", + "name": "Rich", + "description": "", + "fields": [ + { + "id": "name", + "name": "name", + "type": "Symbol", + "localized": false, + "required": false, + "disabled": false, + "omitted": false + }, + { + "id": "rich", + "name": "rich", + "type": "RichText", + "localized": false, + "required": false, + "disabled": false, + "omitted": false + } + ] + } + ] +} diff --git a/src/test/resources/rich_text/locales.json b/src/test/resources/rich_text/locales.json new file mode 100644 index 00000000..6837217d --- /dev/null +++ b/src/test/resources/rich_text/locales.json @@ -0,0 +1,21 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 1000, + "items": [ + { + "code": "en-US", + "name": "English (United States)", + "default": true, + "fallbackCode": null, + "sys": { + "id": "7fpOneSflazHm9rrNGxojE", + "type": "Locale", + "version": 1 + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_blockquote.json b/src/test/resources/rich_text/simple_blockquote.json new file mode 100644 index 00000000..f50c47a0 --- /dev/null +++ b/src/test/resources/rich_text/simple_blockquote.json @@ -0,0 +1,80 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "3f6f7Q6FhCIka0OqEuWoMc", + "type": "Entry", + "createdAt": "2018-10-17T13:32:33.981Z", + "updatedAt": "2018-10-17T13:33:43.652Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 2, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_blockquote", + "rich": { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "data": {}, + "marks": [], + "value": "This is some simple blockquote", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "blockquote" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "marks": [], + "value": "", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_headline_1.json b/src/test/resources/rich_text/simple_headline_1.json new file mode 100644 index 00000000..6ef0bc88 --- /dev/null +++ b/src/test/resources/rich_text/simple_headline_1.json @@ -0,0 +1,71 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "4vg1cRFHtKaAgWYaAEUu6K", + "type": "Entry", + "createdAt": "2018-10-17T13:32:30.252Z", + "updatedAt": "2018-10-17T13:32:30.252Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_headline_1", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "This is some simple text", + "nodeType": "text" + } + ], + "nodeType": "heading-1" + }, + { + "data": {}, + "content": [ + { + "marks": [], + "value": "asdfadfadf", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_headline_2.json b/src/test/resources/rich_text/simple_headline_2.json new file mode 100644 index 00000000..5406ae63 --- /dev/null +++ b/src/test/resources/rich_text/simple_headline_2.json @@ -0,0 +1,71 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "66zfk6zIgoGGOa6kGeWqoi", + "type": "Entry", + "createdAt": "2018-10-17T13:32:29.327Z", + "updatedAt": "2018-10-17T13:32:29.327Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_headline_2", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "This is some simple text", + "nodeType": "text" + } + ], + "nodeType": "heading-2" + }, + { + "data": {}, + "content": [ + { + "marks": [], + "value": "asdfadfadf", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_headline_3.json b/src/test/resources/rich_text/simple_headline_3.json new file mode 100644 index 00000000..aff851a5 --- /dev/null +++ b/src/test/resources/rich_text/simple_headline_3.json @@ -0,0 +1,71 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "2PuzK2bTpCIuQA6gc6a4sq", + "type": "Entry", + "createdAt": "2018-10-17T13:32:28.884Z", + "updatedAt": "2018-10-17T13:32:28.884Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_headline_3", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "This is some simple text", + "nodeType": "text" + } + ], + "nodeType": "heading-3" + }, + { + "data": {}, + "content": [ + { + "marks": [], + "value": "asdfadfadf", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_headline_4.json b/src/test/resources/rich_text/simple_headline_4.json new file mode 100644 index 00000000..fc6aaf8c --- /dev/null +++ b/src/test/resources/rich_text/simple_headline_4.json @@ -0,0 +1,71 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "4TDbGOxMCsikyccqyMUWAc", + "type": "Entry", + "createdAt": "2018-10-17T13:32:28.296Z", + "updatedAt": "2018-10-17T13:32:28.296Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_headline_4", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "This is some simple text", + "nodeType": "text" + } + ], + "nodeType": "heading-4" + }, + { + "data": {}, + "content": [ + { + "marks": [], + "value": "asdfadfadf", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_headline_5.json b/src/test/resources/rich_text/simple_headline_5.json new file mode 100644 index 00000000..68c085ba --- /dev/null +++ b/src/test/resources/rich_text/simple_headline_5.json @@ -0,0 +1,71 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "52TyxOtKLCQu6mu8aACYKa", + "type": "Entry", + "createdAt": "2018-10-17T13:32:27.618Z", + "updatedAt": "2018-10-17T13:32:27.618Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_headline_5", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "This is some simple text", + "nodeType": "text" + } + ], + "nodeType": "heading-5" + }, + { + "data": {}, + "content": [ + { + "marks": [], + "value": "asdfadfadf", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_headline_6.json b/src/test/resources/rich_text/simple_headline_6.json new file mode 100644 index 00000000..ee6cd793 --- /dev/null +++ b/src/test/resources/rich_text/simple_headline_6.json @@ -0,0 +1,71 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "2s3r0fFqosWGCSWIcWoyiU", + "type": "Entry", + "createdAt": "2018-10-17T13:32:30.025Z", + "updatedAt": "2018-10-17T13:32:30.025Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_headline_6", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "This is some simple text", + "nodeType": "text" + } + ], + "nodeType": "heading-6" + }, + { + "data": {}, + "content": [ + { + "marks": [], + "value": "", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_horizontal_rule.json b/src/test/resources/rich_text/simple_horizontal_rule.json new file mode 100644 index 00000000..235d3138 --- /dev/null +++ b/src/test/resources/rich_text/simple_horizontal_rule.json @@ -0,0 +1,71 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "2pcmZPg5HS4Ca0gme600IW", + "type": "Entry", + "createdAt": "2018-10-17T13:32:34.679Z", + "updatedAt": "2018-10-17T13:32:34.679Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_horizontal_rule", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "", + "nodeType": "text" + } + ], + "nodeType": "hr" + }, + { + "data": {}, + "content": [ + { + "marks": [], + "value": "", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_ordered_list.json b/src/test/resources/rich_text/simple_ordered_list.json new file mode 100644 index 00000000..1329283b --- /dev/null +++ b/src/test/resources/rich_text/simple_ordered_list.json @@ -0,0 +1,151 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "7Mlh48fMysQqmSwmWUeAU4", + "type": "Entry", + "createdAt": "2018-10-17T13:32:31.439Z", + "updatedAt": "2018-10-17T13:32:31.439Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_ordered_list", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "This ", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "list-item" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "is", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "list-item" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "some", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "list-item" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "simple", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "list-item" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "text", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "list-item" + } + ], + "nodeType": "ordered-list" + }, + { + "data": {}, + "content": [ + { + "marks": [], + "value": "", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_ordered_nested_list.json b/src/test/resources/rich_text/simple_ordered_nested_list.json new file mode 100644 index 00000000..7c53aeba --- /dev/null +++ b/src/test/resources/rich_text/simple_ordered_nested_list.json @@ -0,0 +1,198 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "4KEmdA0GpaYyMsEGiqOKgg", + "type": "Entry", + "createdAt": "2018-10-17T13:32:27.340Z", + "updatedAt": "2018-10-17T13:32:27.340Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_ordered_nested_list", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "This ", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "is", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "some", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "simple", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "nested", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "list", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "list-item" + } + ], + "nodeType": "ordered-list" + } + ], + "nodeType": "list-item" + } + ], + "nodeType": "ordered-list" + } + ], + "nodeType": "list-item" + } + ], + "nodeType": "ordered-list" + } + ], + "nodeType": "list-item" + } + ], + "nodeType": "ordered-list" + } + ], + "nodeType": "list-item" + } + ], + "nodeType": "ordered-list" + } + ], + "nodeType": "list-item" + } + ], + "nodeType": "ordered-list" + }, + { + "data": {}, + "content": [ + { + "marks": [], + "value": "", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_text.json b/src/test/resources/rich_text/simple_text.json new file mode 100644 index 00000000..02a77750 --- /dev/null +++ b/src/test/resources/rich_text/simple_text.json @@ -0,0 +1,60 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "ybxKk5Avzqam6KymAOgIG", + "type": "Entry", + "createdAt": "2018-10-17T13:32:26.926Z", + "updatedAt": "2018-10-17T13:32:26.926Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_text", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "This is some simple text", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_text_bold.json b/src/test/resources/rich_text/simple_text_bold.json new file mode 100644 index 00000000..3fb8076a --- /dev/null +++ b/src/test/resources/rich_text/simple_text_bold.json @@ -0,0 +1,66 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "6VTkaiufQck4wyMwCu4u4E", + "type": "Entry", + "createdAt": "2018-10-17T13:32:31.957Z", + "updatedAt": "2018-10-17T13:32:31.957Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_text_bold", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [ + { + "data": {}, + "type": "bold", + "object": "mark" + } + ], + "value": "This is some simple text", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_text_code.json b/src/test/resources/rich_text/simple_text_code.json new file mode 100644 index 00000000..4805522c --- /dev/null +++ b/src/test/resources/rich_text/simple_text_code.json @@ -0,0 +1,66 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "6VkkamQ5zO4qWIugKkWowK", + "type": "Entry", + "createdAt": "2018-10-17T13:32:33.090Z", + "updatedAt": "2018-10-17T13:32:33.090Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_text_code", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [ + { + "data": {}, + "type": "code", + "object": "mark" + } + ], + "value": "This is some simple text", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_text_embedded.json b/src/test/resources/rich_text/simple_text_embedded.json new file mode 100644 index 00000000..e71a861b --- /dev/null +++ b/src/test/resources/rich_text/simple_text_embedded.json @@ -0,0 +1,133 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "2oVOBFJuE0ym8Yqqi2CS4i", + "type": "Entry", + "createdAt": "2018-10-17T13:32:29.635Z", + "updatedAt": "2018-10-17T13:32:29.635Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_text_embedded", + "rich": { + "content": [ + { + "data": { + "target": { + "sys": { + "id": "ybxKk5Avzqam6KymAOgIG", + "type": "Link", + "linkType": "Entry" + } + } + }, + "content": [ + { + "marks": [], + "value": "", + "nodeType": "text" + } + ], + "nodeType": "embedded-entry-block" + }, + { + "data": {}, + "content": [ + { + "marks": [], + "value": "", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ], + "includes": { + "Entry": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "ybxKk5Avzqam6KymAOgIG", + "type": "Entry", + "createdAt": "2018-10-17T13:32:26.926Z", + "updatedAt": "2018-10-17T13:32:26.926Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_text", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "This is some simple text", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] + } +} diff --git a/src/test/resources/rich_text/simple_text_italic.json b/src/test/resources/rich_text/simple_text_italic.json new file mode 100644 index 00000000..b35f75de --- /dev/null +++ b/src/test/resources/rich_text/simple_text_italic.json @@ -0,0 +1,66 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "1eIWMi8RNEO0ii4OsAUeow", + "type": "Entry", + "createdAt": "2018-10-17T13:32:33.252Z", + "updatedAt": "2018-10-17T13:32:33.252Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_text_italic", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [ + { + "data": {}, + "type": "italic", + "object": "mark" + } + ], + "value": "This is some simple text", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_text_mixed_bold_italic_underline_code_all.json b/src/test/resources/rich_text/simple_text_mixed_bold_italic_underline_code_all.json new file mode 100644 index 00000000..f6f02b7c --- /dev/null +++ b/src/test/resources/rich_text/simple_text_mixed_bold_italic_underline_code_all.json @@ -0,0 +1,145 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "2D1cTTbKDCgY0UAKsCYAea", + "type": "Entry", + "createdAt": "2018-10-17T13:32:30.761Z", + "updatedAt": "2018-10-17T13:32:30.761Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_text_mixed_bold_italic_underline_code_all", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [ + { + "data": {}, + "type": "bold", + "object": "mark" + } + ], + "value": "This", + "nodeType": "text" + }, + { + "marks": [], + "value": " ", + "nodeType": "text" + }, + { + "marks": [ + { + "data": {}, + "type": "italic", + "object": "mark" + } + ], + "value": "is", + "nodeType": "text" + }, + { + "marks": [], + "value": " ", + "nodeType": "text" + }, + { + "marks": [ + { + "data": {}, + "type": "underline", + "object": "mark" + } + ], + "value": "some", + "nodeType": "text" + }, + { + "marks": [], + "value": " ", + "nodeType": "text" + }, + { + "marks": [ + { + "data": {}, + "type": "code", + "object": "mark" + } + ], + "value": "simple", + "nodeType": "text" + }, + { + "marks": [], + "value": " ", + "nodeType": "text" + }, + { + "marks": [ + { + "data": {}, + "type": "bold", + "object": "mark" + }, + { + "data": {}, + "type": "italic", + "object": "mark" + }, + { + "data": {}, + "type": "underline", + "object": "mark" + }, + { + "data": {}, + "type": "code", + "object": "mark" + } + ], + "value": "text", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_text_underline.json b/src/test/resources/rich_text/simple_text_underline.json new file mode 100644 index 00000000..ffd18980 --- /dev/null +++ b/src/test/resources/rich_text/simple_text_underline.json @@ -0,0 +1,66 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "42c9Fb0T0As26K0W0E48U2", + "type": "Entry", + "createdAt": "2018-10-17T13:32:32.829Z", + "updatedAt": "2018-10-17T13:32:32.829Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_text_underline", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [ + { + "data": {}, + "type": "underline", + "object": "mark" + } + ], + "value": "This is some simple text", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_text_with_link.json b/src/test/resources/rich_text/simple_text_with_link.json new file mode 100644 index 00000000..9f2f3b62 --- /dev/null +++ b/src/test/resources/rich_text/simple_text_with_link.json @@ -0,0 +1,78 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "104F4Lbe2gUKuo42yGygsQ", + "type": "Entry", + "createdAt": "2018-10-17T13:32:33.642Z", + "updatedAt": "2018-10-17T13:32:33.642Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_text_with_link", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "", + "nodeType": "text" + }, + { + "data": { + "uri": "https://www.contentful.com" + }, + "content": [ + { + "marks": [], + "value": "This is some simple text", + "nodeType": "text" + } + ], + "nodeType": "hyperlink" + }, + { + "marks": [], + "value": "", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +} diff --git a/src/test/resources/rich_text/simple_unordered_list.json b/src/test/resources/rich_text/simple_unordered_list.json new file mode 100644 index 00000000..dff632a1 --- /dev/null +++ b/src/test/resources/rich_text/simple_unordered_list.json @@ -0,0 +1,168 @@ +{ + "sys": { + "type": "Array" + }, + "total": 1, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "" + } + }, + "id": "5Z7FHGZYxqMuoCyWmwMuwm", + "type": "Entry", + "createdAt": "2018-10-17T13:32:31.110Z", + "updatedAt": "2018-10-17T13:32:31.110Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 1, + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "rich" + } + }, + "locale": "en-US" + }, + "fields": { + "name": "simple_unordered_list", + "rich": { + "content": [ + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "This", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "list-item" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "is", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "list-item" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "some", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "list-item" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "simple", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "list-item" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "unordered", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "list-item" + }, + { + "data": {}, + "content": [ + { + "data": {}, + "content": [ + { + "marks": [], + "value": "list", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "list-item" + } + ], + "nodeType": "unordered-list" + }, + { + "data": {}, + "content": [ + { + "marks": [], + "value": "", + "nodeType": "text" + } + ], + "nodeType": "paragraph" + } + ], + "nodeType": "document" + } + } + } + ] +}