Skip to content

Commit

Permalink
add renditions json bingind tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Simply007 authored and IvanKiral committed Dec 14, 2023
1 parent 8978ee5 commit 73c1e2c
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 1 deletion.
5 changes: 5 additions & 0 deletions delivery-sdk/src/main/java/kontent/ai/delivery/Asset.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Map;

/**
* Object model for Asset elements
*/
Expand Down Expand Up @@ -59,4 +61,7 @@ public class Asset {

@JsonProperty("height")
String height;

@JsonProperty("renditions")
Map<String, AssetRendition> renditions;
}
119 changes: 119 additions & 0 deletions delivery-sdk/src/main/java/kontent/ai/delivery/AssetRendition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* MIT License
*
* Copyright (c) 2019
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package kontent.ai.delivery;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Object model for asset rendition
*/
@lombok.Data
@lombok.NoArgsConstructor
@lombok.AllArgsConstructor
@lombok.Builder
public class AssetRendition {

@JsonProperty("rendition_id")
String renditionId;

@JsonProperty("preset_id")
String presetId;

@JsonProperty("width")
String width;

@JsonProperty("height")
String height;

@JsonProperty("query")
String query;

/**
* Asset rendition ID
*
* @return rendition ID
*/
public String getRenditionId() {
return renditionId;
}

void setRenditionId(String renditionId) {
this.renditionId = renditionId;
}

/**
* Asset rendition preset ID
*
* @return rendition preset ID
*/
public String getPresetId() {
return presetId;
}

void setPresetId(String presetId) {
this.presetId = presetId;
}

/**
* Width of the asset rendition
*
* @return Width of the asset rendition
*/

public String getWidth() {
return width;
}

public void setWidth(String width) {
this.width = width;
}

/**
* Height of the asset rendition
*
* @return Height of the asset rendition
*/

public String getHeight() {
return height;
}

public void setHeight(String height) {
this.height = height;
}

/**
* Asset rendition query
*
* @return rendition query
*/
public String getQuery() {
return query;
}

void setQuery(String query) {
this.query = query;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.junit.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

public class JacksonBindingsTest {
Expand Down Expand Up @@ -330,7 +331,7 @@ public void testDateTimeElementDeserialization() throws IOException {
}

@Test
public void testAssetElementDeserialization() throws IOException {
public void testAssetElementWithoutRenditionsDeserialization() throws IOException {
AssetsElement assetsElement = objectMapper.readValue(
this.getClass().getResource("SampleAssetElement.json"), AssetsElement.class);
AssetsElement assetsElement2 = objectMapper.readValue(
Expand Down Expand Up @@ -361,6 +362,89 @@ public void testAssetElementDeserialization() throws IOException {
Assert.assertEquals(
"https://assets-us-01.kc-usercontent.com:443/38af179c-40ba-42e7-a5ca-33b8cdcc0d45/e700596b-03b0-4cee-ac5c-9212762c027a/coffee-beverages-explained-1080px.jpg",
asset.getUrl());
Assert.assertNull(asset.renditions);
}

@Test
public void testAssetElementWithEmptyRenditionsDeserialization() throws IOException {
AssetsElement assetsElement = objectMapper.readValue(
this.getClass().getResource("SampleAssetElementWithEmptyRendition.json"), AssetsElement.class);
AssetsElement assetsElement2 = objectMapper.readValue(
this.getClass().getResource("SampleAssetElementWithEmptyRendition.json"), AssetsElement.class);
Assert.assertNotNull("object failed deserialization", assetsElement);
Assert.assertNotNull(assetsElement.toString());
Assert.assertEquals(assetsElement, assetsElement2);
Assert.assertEquals(assetsElement.hashCode(), assetsElement2.hashCode());
Assert.assertEquals("Teaser image", assetsElement.getName());
Assert.assertEquals(1, assetsElement.getValue().size());
Asset asset = assetsElement.getValue().get(0);
Assert.assertNotNull(asset);
Asset asset2 = Asset.builder()
.name(asset.getName())
.description(asset.getDescription())
.size(asset.getSize())
.url(asset.getUrl())
.type(asset.getType())
.height(asset.getHeight())
.width(asset.getWidth())
.renditions(asset.getRenditions())
.build();
Assert.assertEquals(asset, asset2);
Assert.assertEquals(asset.hashCode(), asset2.hashCode());
Assert.assertEquals("coffee-beverages-explained-1080px.jpg", asset.getName());
Assert.assertEquals("image/jpeg", asset.getType());
Assert.assertEquals(90895, asset.getSize().longValue());
Assert.assertNull(asset.getDescription());
Assert.assertEquals(
"https://assets-us-01.kc-usercontent.com:443/38af179c-40ba-42e7-a5ca-33b8cdcc0d45/e700596b-03b0-4cee-ac5c-9212762c027a/coffee-beverages-explained-1080px.jpg",
asset.getUrl());
Assert.assertNotNull(asset.getRenditions());
Assert.assertTrue(asset.getRenditions().isEmpty());
}

@Test
public void testAssetElementWithRenditionsDeserialization() throws IOException {
AssetsElement assetsElement = objectMapper.readValue(
this.getClass().getResource("SampleAssetElementWithRendition.json"), AssetsElement.class);
AssetsElement assetsElement2 = objectMapper.readValue(
this.getClass().getResource("SampleAssetElementWithRendition.json"), AssetsElement.class);
Assert.assertNotNull("object failed deserialization", assetsElement);
Assert.assertNotNull(assetsElement.toString());
Assert.assertEquals(assetsElement, assetsElement2);
Assert.assertEquals(assetsElement.hashCode(), assetsElement2.hashCode());
Assert.assertEquals("Teaser image", assetsElement.getName());
Assert.assertEquals(1, assetsElement.getValue().size());
Asset asset = assetsElement.getValue().get(0);
Assert.assertNotNull(asset);
Asset asset2 = Asset.builder()
.name(asset.getName())
.description(asset.getDescription())
.size(asset.getSize())
.url(asset.getUrl())
.type(asset.getType())
.height(asset.getHeight())
.width(asset.getWidth())
.renditions(asset.getRenditions())
.build();
Assert.assertEquals(asset, asset2);
Assert.assertEquals(asset.hashCode(), asset2.hashCode());
Assert.assertEquals("coffee-beverages-explained-1080px.jpg", asset.getName());
Assert.assertEquals("image/jpeg", asset.getType());
Assert.assertEquals(90895, asset.getSize().longValue());
Assert.assertNull(asset.getDescription());
Assert.assertEquals(
"https://assets-us-01.kc-usercontent.com:443/38af179c-40ba-42e7-a5ca-33b8cdcc0d45/e700596b-03b0-4cee-ac5c-9212762c027a/coffee-beverages-explained-1080px.jpg",
asset.getUrl());
Assert.assertNotNull(asset.getRenditions());
Assert.assertEquals(1, asset.getRenditions().size());
AssetRendition expectedRendition = new AssetRendition(
"dc448f45-161e-4268-8155-b9d9e33497c8",
"a6d98cd5-8b2c-4e50-99c9-15192bce2490",
"640",
"480",
"w=640&h=480&fit=clip&rect=146,425,788,590"
);
Assert.assertEquals(expectedRendition, asset.getRenditions().get("default"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"type": "asset",
"name": "Teaser image",
"value": [
{
"name": "coffee-beverages-explained-1080px.jpg",
"type": "image/jpeg",
"size": "90895",
"description": null,
"url": "https://assets-us-01.kc-usercontent.com:443/38af179c-40ba-42e7-a5ca-33b8cdcc0d45/e700596b-03b0-4cee-ac5c-9212762c027a/coffee-beverages-explained-1080px.jpg",
"width": "1600",
"height": "800",
"renditions": {}
}
],
"testing_unknown_field_does_not_break_jackson": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "asset",
"name": "Teaser image",
"value": [
{
"name": "coffee-beverages-explained-1080px.jpg",
"type": "image/jpeg",
"size": "90895",
"description": null,
"url": "https://assets-us-01.kc-usercontent.com:443/38af179c-40ba-42e7-a5ca-33b8cdcc0d45/e700596b-03b0-4cee-ac5c-9212762c027a/coffee-beverages-explained-1080px.jpg",
"width": "1600",
"height": "800",
"renditions": {
"default": {
"rendition_id": "dc448f45-161e-4268-8155-b9d9e33497c8",
"preset_id": "a6d98cd5-8b2c-4e50-99c9-15192bce2490",
"width": 640,
"height": 480,
"query": "w=640&h=480&fit=clip&rect=146,425,788,590"
}
}
}
],
"testing_unknown_field_does_not_break_jackson": true
}

0 comments on commit 73c1e2c

Please sign in to comment.