Skip to content

Commit 73c1e2c

Browse files
Simply007IvanKiral
authored andcommitted
add renditions json bingind tests
1 parent 8978ee5 commit 73c1e2c

File tree

5 files changed

+251
-1
lines changed

5 files changed

+251
-1
lines changed

delivery-sdk/src/main/java/kontent/ai/delivery/Asset.java

Lines changed: 5 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
*/
@@ -59,4 +61,7 @@ public class Asset {
5961

6062
@JsonProperty("height")
6163
String height;
64+
65+
@JsonProperty("renditions")
66+
Map<String, AssetRendition> renditions;
6267
}
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 kontent.ai.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+
}

delivery-sdk/src/test/java/kontent/ai/delivery/JacksonBindingsTest.java

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

3737
import java.io.IOException;
38+
import java.util.HashMap;
3839
import java.util.List;
3940

4041
public class JacksonBindingsTest {
@@ -330,7 +331,7 @@ public void testDateTimeElementDeserialization() throws IOException {
330331
}
331332

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

366450
@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)