Skip to content

Commit 8df90e8

Browse files
committed
add renditions json bingind tests
1 parent 527a4d8 commit 8df90e8

File tree

5 files changed

+250
-1
lines changed

5 files changed

+250
-1
lines changed

kontent-delivery/src/main/java/kentico/kontent/delivery/Asset.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import com.fasterxml.jackson.annotation.JsonProperty;
2828

29+
import java.util.Map;
30+
2931
/**
3032
* Object model for Asset elements
3133
*/
@@ -56,6 +58,8 @@ public class Asset {
5658
@JsonProperty("height")
5759
String height;
5860

61+
@JsonProperty("renditions")
62+
Map<String, AssetRendition> renditions;
5963

6064
/**
6165
* File name of the asset
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2019
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package kentico.kontent.delivery;
26+
27+
import com.fasterxml.jackson.annotation.JsonProperty;
28+
29+
/**
30+
* Object model for asset rendition
31+
*/
32+
@lombok.Data
33+
@lombok.NoArgsConstructor
34+
@lombok.AllArgsConstructor
35+
@lombok.Builder
36+
public class AssetRendition {
37+
38+
@JsonProperty("rendition_id")
39+
String renditionId;
40+
41+
@JsonProperty("preset_id")
42+
String presetId;
43+
44+
@JsonProperty("width")
45+
String width;
46+
47+
@JsonProperty("height")
48+
String height;
49+
50+
@JsonProperty("query")
51+
String query;
52+
53+
/**
54+
* Asset rendition ID
55+
*
56+
* @return rendition ID
57+
*/
58+
public String getRenditionId() {
59+
return renditionId;
60+
}
61+
62+
void setRenditionId(String renditionId) {
63+
this.renditionId = renditionId;
64+
}
65+
66+
/**
67+
* Asset rendition preset ID
68+
*
69+
* @return rendition preset ID
70+
*/
71+
public String getPresetId() {
72+
return presetId;
73+
}
74+
75+
void setPresetId(String presetId) {
76+
this.presetId = presetId;
77+
}
78+
79+
/**
80+
* Width of the asset rendition
81+
*
82+
* @return Width of the asset rendition
83+
*/
84+
85+
public String getWidth() {
86+
return width;
87+
}
88+
89+
public void setWidth(String width) {
90+
this.width = width;
91+
}
92+
93+
/**
94+
* Height of the asset rendition
95+
*
96+
* @return Height of the asset rendition
97+
*/
98+
99+
public String getHeight() {
100+
return height;
101+
}
102+
103+
public void setHeight(String height) {
104+
this.height = height;
105+
}
106+
107+
/**
108+
* Asset rendition query
109+
*
110+
* @return rendition query
111+
*/
112+
public String getQuery() {
113+
return query;
114+
}
115+
116+
void setQuery(String query) {
117+
this.query = query;
118+
}
119+
}

kontent-delivery/src/test/java/kentico/kontent/delivery/JacksonBindingsTest.java

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.junit.Test;
3434

3535
import java.io.IOException;
36+
import java.util.HashMap;
3637
import java.util.List;
3738

3839
public class JacksonBindingsTest {
@@ -321,7 +322,7 @@ public void testDateTimeElementDeserialization() throws IOException {
321322
}
322323

323324
@Test
324-
public void testAssetElementDeserialization() throws IOException {
325+
public void testAssetElementWithoutRenditionsDeserialization() throws IOException {
325326
AssetsElement assetsElement = objectMapper.readValue(
326327
this.getClass().getResource("SampleAssetElement.json"), AssetsElement.class);
327328
AssetsElement assetsElement2 = objectMapper.readValue(
@@ -352,6 +353,89 @@ public void testAssetElementDeserialization() throws IOException {
352353
Assert.assertEquals(
353354
"https://assets-us-01.kc-usercontent.com:443/38af179c-40ba-42e7-a5ca-33b8cdcc0d45/e700596b-03b0-4cee-ac5c-9212762c027a/coffee-beverages-explained-1080px.jpg",
354355
asset.getUrl());
356+
Assert.assertNull(asset.renditions);
357+
}
358+
359+
@Test
360+
public void testAssetElementWithEmptyRenditionsDeserialization() throws IOException {
361+
AssetsElement assetsElement = objectMapper.readValue(
362+
this.getClass().getResource("SampleAssetElementWithEmptyRendition.json"), AssetsElement.class);
363+
AssetsElement assetsElement2 = objectMapper.readValue(
364+
this.getClass().getResource("SampleAssetElementWithEmptyRendition.json"), AssetsElement.class);
365+
Assert.assertNotNull("object failed deserialization", assetsElement);
366+
Assert.assertNotNull(assetsElement.toString());
367+
Assert.assertEquals(assetsElement, assetsElement2);
368+
Assert.assertEquals(assetsElement.hashCode(), assetsElement2.hashCode());
369+
Assert.assertEquals("Teaser image", assetsElement.getName());
370+
Assert.assertEquals(1, assetsElement.getValue().size());
371+
Asset asset = assetsElement.getValue().get(0);
372+
Assert.assertNotNull(asset);
373+
Asset asset2 = Asset.builder()
374+
.name(asset.getName())
375+
.description(asset.getDescription())
376+
.size(asset.getSize())
377+
.url(asset.getUrl())
378+
.type(asset.getType())
379+
.height(asset.getHeight())
380+
.width(asset.getWidth())
381+
.renditions(asset.getRenditions())
382+
.build();
383+
Assert.assertEquals(asset, asset2);
384+
Assert.assertEquals(asset.hashCode(), asset2.hashCode());
385+
Assert.assertEquals("coffee-beverages-explained-1080px.jpg", asset.getName());
386+
Assert.assertEquals("image/jpeg", asset.getType());
387+
Assert.assertEquals(90895, asset.getSize().longValue());
388+
Assert.assertNull(asset.getDescription());
389+
Assert.assertEquals(
390+
"https://assets-us-01.kc-usercontent.com:443/38af179c-40ba-42e7-a5ca-33b8cdcc0d45/e700596b-03b0-4cee-ac5c-9212762c027a/coffee-beverages-explained-1080px.jpg",
391+
asset.getUrl());
392+
Assert.assertNotNull(asset.getRenditions());
393+
Assert.assertTrue(asset.getRenditions().isEmpty());
394+
}
395+
396+
@Test
397+
public void testAssetElementWithRenditionsDeserialization() throws IOException {
398+
AssetsElement assetsElement = objectMapper.readValue(
399+
this.getClass().getResource("SampleAssetElementWithRendition.json"), AssetsElement.class);
400+
AssetsElement assetsElement2 = objectMapper.readValue(
401+
this.getClass().getResource("SampleAssetElementWithRendition.json"), AssetsElement.class);
402+
Assert.assertNotNull("object failed deserialization", assetsElement);
403+
Assert.assertNotNull(assetsElement.toString());
404+
Assert.assertEquals(assetsElement, assetsElement2);
405+
Assert.assertEquals(assetsElement.hashCode(), assetsElement2.hashCode());
406+
Assert.assertEquals("Teaser image", assetsElement.getName());
407+
Assert.assertEquals(1, assetsElement.getValue().size());
408+
Asset asset = assetsElement.getValue().get(0);
409+
Assert.assertNotNull(asset);
410+
Asset asset2 = Asset.builder()
411+
.name(asset.getName())
412+
.description(asset.getDescription())
413+
.size(asset.getSize())
414+
.url(asset.getUrl())
415+
.type(asset.getType())
416+
.height(asset.getHeight())
417+
.width(asset.getWidth())
418+
.renditions(asset.getRenditions())
419+
.build();
420+
Assert.assertEquals(asset, asset2);
421+
Assert.assertEquals(asset.hashCode(), asset2.hashCode());
422+
Assert.assertEquals("coffee-beverages-explained-1080px.jpg", asset.getName());
423+
Assert.assertEquals("image/jpeg", asset.getType());
424+
Assert.assertEquals(90895, asset.getSize().longValue());
425+
Assert.assertNull(asset.getDescription());
426+
Assert.assertEquals(
427+
"https://assets-us-01.kc-usercontent.com:443/38af179c-40ba-42e7-a5ca-33b8cdcc0d45/e700596b-03b0-4cee-ac5c-9212762c027a/coffee-beverages-explained-1080px.jpg",
428+
asset.getUrl());
429+
Assert.assertNotNull(asset.getRenditions());
430+
Assert.assertEquals(1, asset.getRenditions().size());
431+
AssetRendition expectedRendition = new AssetRendition(
432+
"dc448f45-161e-4268-8155-b9d9e33497c8",
433+
"a6d98cd5-8b2c-4e50-99c9-15192bce2490",
434+
"640",
435+
"480",
436+
"w=640&h=480&fit=clip&rect=146,425,788,590"
437+
);
438+
Assert.assertEquals(expectedRendition, asset.getRenditions().get("default"));
355439
}
356440

357441
@Test
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"type": "asset",
3+
"name": "Teaser image",
4+
"value": [
5+
{
6+
"name": "coffee-beverages-explained-1080px.jpg",
7+
"type": "image/jpeg",
8+
"size": "90895",
9+
"description": null,
10+
"url": "https://assets-us-01.kc-usercontent.com:443/38af179c-40ba-42e7-a5ca-33b8cdcc0d45/e700596b-03b0-4cee-ac5c-9212762c027a/coffee-beverages-explained-1080px.jpg",
11+
"width": "1600",
12+
"height": "800",
13+
"renditions": {}
14+
}
15+
],
16+
"testing_unknown_field_does_not_break_jackson": true
17+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"type": "asset",
3+
"name": "Teaser image",
4+
"value": [
5+
{
6+
"name": "coffee-beverages-explained-1080px.jpg",
7+
"type": "image/jpeg",
8+
"size": "90895",
9+
"description": null,
10+
"url": "https://assets-us-01.kc-usercontent.com:443/38af179c-40ba-42e7-a5ca-33b8cdcc0d45/e700596b-03b0-4cee-ac5c-9212762c027a/coffee-beverages-explained-1080px.jpg",
11+
"width": "1600",
12+
"height": "800",
13+
"renditions": {
14+
"default": {
15+
"rendition_id": "dc448f45-161e-4268-8155-b9d9e33497c8",
16+
"preset_id": "a6d98cd5-8b2c-4e50-99c9-15192bce2490",
17+
"width": 640,
18+
"height": 480,
19+
"query": "w=640&h=480&fit=clip&rect=146,425,788,590"
20+
}
21+
}
22+
}
23+
],
24+
"testing_unknown_field_does_not_break_jackson": true
25+
}

0 commit comments

Comments
 (0)