Skip to content

Commit

Permalink
unit test per-property naming
Browse files Browse the repository at this point in the history
  • Loading branch information
hammettj committed Oct 4, 2022
1 parent 755f6da commit 303aedd
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.vertx.test.codegen.converter;

import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.impl.JsonUtil;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Base64;

/**
* Converter and mapper for {@link io.vertx.test.codegen.converter.DataObjectPropertyFormattedDataObject}.
* NOTE: This class has been automatically generated from the {@link io.vertx.test.codegen.converter.DataObjectPropertyFormattedDataObject} original class using Vert.x codegen.
*/
public class DataObjectPropertyFormattedDataObjectConverter {


private static final Base64.Decoder BASE64_DECODER = JsonUtil.BASE64_DECODER;
private static final Base64.Encoder BASE64_ENCODER = JsonUtil.BASE64_ENCODER;

public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, DataObjectPropertyFormattedDataObject obj) {
for (java.util.Map.Entry<String, Object> member : json) {
switch (member.getKey()) {
case "id":
if (member.getValue() instanceof String) {
obj.setId((String)member.getValue());
}
break;
case ":ref":
if (member.getValue() instanceof String) {
obj.setRef((String)member.getValue());
}
break;
}
}
}

public static void toJson(DataObjectPropertyFormattedDataObject obj, JsonObject json) {
toJson(obj, json.getMap());
}

public static void toJson(DataObjectPropertyFormattedDataObject obj, java.util.Map<String, Object> json) {
if (obj.getId() != null) {
json.put("id", obj.getId());
}
if (obj.getRef() != null) {
json.put(":ref", obj.getRef());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2011-2017 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*/

package io.vertx.test.codegen.converter;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;

@DataObject(generateConverter = true)
public class DataObjectPropertyFormattedDataObject {

private String id;
private String ref;

public DataObjectPropertyFormattedDataObject() {
}

public DataObjectPropertyFormattedDataObject(JsonObject json) {
}

public String getId() {
return id;
}

public DataObjectPropertyFormattedDataObject setId(String id) {
this.id = id;
return this;
}

@DataObject.Property(":ref")
public String getRef() {
return ref;
}

public DataObjectPropertyFormattedDataObject setRef(String ref) {
this.ref = ref;
return this;
}
}
15 changes: 15 additions & 0 deletions src/test/java/io/vertx/test/codegen/converter/DataObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,21 @@ public void testSnakeFormatted() {
Assert.assertEquals(expected, test);
}

@Test
public void testDataObjectPropertyFormatted() {
DataObjectPropertyFormattedDataObject obj = new DataObjectPropertyFormattedDataObject();
JsonObject expected = new JsonObject()
.put("id", "val1")
.put(":ref", "self");
DataObjectPropertyFormattedDataObjectConverter.fromJson(expected
, obj);
Assert.assertEquals("val1", obj.getId());
Assert.assertEquals("self", obj.getRef());
JsonObject test = new JsonObject();
DataObjectPropertyFormattedDataObjectConverter.toJson(obj, test);
Assert.assertEquals(expected, test);
}

@Test
public void testBase64Basic() {
TestDataObjectBase64Basic obj = new TestDataObjectBase64Basic();
Expand Down

0 comments on commit 303aedd

Please sign in to comment.