Skip to content

Commit 5b2ce9c

Browse files
author
Jeffrey Hammett
committed
unit test per-property naming
1 parent 6a78229 commit 5b2ce9c

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package io.vertx.test.codegen.converter;
2+
3+
import io.vertx.core.json.JsonObject;
4+
import io.vertx.core.json.JsonArray;
5+
import io.vertx.core.json.impl.JsonUtil;
6+
import java.time.Instant;
7+
import java.time.format.DateTimeFormatter;
8+
import java.util.Base64;
9+
10+
/**
11+
* Converter and mapper for {@link io.vertx.test.codegen.converter.DataObjectPropertyFormattedDataObject}.
12+
* NOTE: This class has been automatically generated from the {@link io.vertx.test.codegen.converter.DataObjectPropertyFormattedDataObject} original class using Vert.x codegen.
13+
*/
14+
public class DataObjectPropertyFormattedDataObjectConverter {
15+
16+
17+
private static final Base64.Decoder BASE64_DECODER = JsonUtil.BASE64_DECODER;
18+
private static final Base64.Encoder BASE64_ENCODER = JsonUtil.BASE64_ENCODER;
19+
20+
public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, DataObjectPropertyFormattedDataObject obj) {
21+
for (java.util.Map.Entry<String, Object> member : json) {
22+
switch (member.getKey()) {
23+
case "id":
24+
if (member.getValue() instanceof String) {
25+
obj.setId((String)member.getValue());
26+
}
27+
break;
28+
case ":ref":
29+
if (member.getValue() instanceof String) {
30+
obj.setRef((String)member.getValue());
31+
}
32+
break;
33+
}
34+
}
35+
}
36+
37+
public static void toJson(DataObjectPropertyFormattedDataObject obj, JsonObject json) {
38+
toJson(obj, json.getMap());
39+
}
40+
41+
public static void toJson(DataObjectPropertyFormattedDataObject obj, java.util.Map<String, Object> json) {
42+
if (obj.getId() != null) {
43+
json.put("id", obj.getId());
44+
}
45+
if (obj.getRef() != null) {
46+
json.put(":ref", obj.getRef());
47+
}
48+
}
49+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2011-2017 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*/
11+
12+
package io.vertx.test.codegen.converter;
13+
14+
import io.vertx.codegen.annotations.DataObject;
15+
import io.vertx.core.json.JsonObject;
16+
17+
@DataObject(generateConverter = true)
18+
public class DataObjectPropertyFormattedDataObject {
19+
20+
private String id;
21+
private String ref;
22+
23+
public DataObjectPropertyFormattedDataObject() {
24+
}
25+
26+
public DataObjectPropertyFormattedDataObject(JsonObject json) {
27+
}
28+
29+
public String getId() {
30+
return id;
31+
}
32+
33+
public DataObjectPropertyFormattedDataObject setId(String id) {
34+
this.id = id;
35+
return this;
36+
}
37+
38+
@DataObject.Property(":ref")
39+
public String getRef() {
40+
return ref;
41+
}
42+
43+
public DataObjectPropertyFormattedDataObject setRef(String ref) {
44+
this.ref = ref;
45+
return this;
46+
}
47+
}

src/test/java/io/vertx/test/codegen/converter/DataObjectTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,21 @@ public void testSnakeFormatted() {
849849
Assert.assertEquals(expected, test);
850850
}
851851

852+
@Test
853+
public void testDataObjectPropertyFormatted() {
854+
DataObjectPropertyFormattedDataObject obj = new DataObjectPropertyFormattedDataObject();
855+
JsonObject expected = new JsonObject()
856+
.put("id", "val1")
857+
.put(":ref", "self");
858+
DataObjectPropertyFormattedDataObjectConverter.fromJson(expected
859+
, obj);
860+
Assert.assertEquals("val1", obj.getId());
861+
Assert.assertEquals("self", obj.getRef());
862+
JsonObject test = new JsonObject();
863+
DataObjectPropertyFormattedDataObjectConverter.toJson(obj, test);
864+
Assert.assertEquals(expected, test);
865+
}
866+
852867
@Test
853868
public void testBase64Basic() {
854869
TestDataObjectBase64Basic obj = new TestDataObjectBase64Basic();

0 commit comments

Comments
 (0)