Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ default byte priority() {
* <p>Transports must be able to be instantiated without any arguments for use in dynamic clients.
*/
default ClientTransport<RequestT, ResponseT> createTransport() {
return createTransport(Document.createStringMap(Collections.emptyMap()));
return createTransport(Document.of(Collections.emptyMap()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public Builder toBuilder() {
})
.build();

var response = client.call("GetSprocket", Document.createFromObject(Map.of("id", "1")));
var response = client.call("GetSprocket", Document.ofObject(Map.of("id", "1")));

assertThat(mockQueue.remaining(), is(0));
assertThat(response.getMember("id").asString(), equalTo("1"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class InjectIdempotencyTokenPluginTest {

@Test
public void injectsToken() {
var token = callAndGetToken("CreateSprocket", Document.createFromObject(Map.of("id", "1")));
var token = callAndGetToken("CreateSprocket", Document.ofObject(Map.of("id", "1")));

assertThat(token, not(nullValue()));
assertThat(token.length(), greaterThan(0));
Expand Down Expand Up @@ -101,28 +101,28 @@ private String callAndGetToken(String operation, Document input) {
.addPlugin(mock)
.build();

client.call(operation, Document.createFromObject(input));
client.call(operation, Document.of(input));
assertThat(mock.getRequests(), not(empty()));
return mock.getRequests().get(0).request().headers().firstValue("x-token");
}

@Test
public void doesNotInjectToken() {
var token = callAndGetToken("CreateSprocketNoToken", Document.createFromObject(Map.of("id", "1")));
var token = callAndGetToken("CreateSprocketNoToken", Document.ofObject(Map.of("id", "1")));

assertThat(token, nullValue());
}

@Test
public void usesProvidedToken() {
var token = callAndGetToken("CreateSprocket", Document.createFromObject(Map.of("id", "1", "token", "xyz")));
var token = callAndGetToken("CreateSprocket", Document.ofObject(Map.of("id", "1", "token", "xyz")));

assertThat(token, equalTo("xyz"));
}

@Test
public void ignoresEmptyStringToken() {
var token = callAndGetToken("CreateSprocket", Document.createFromObject(Map.of("id", "1", "token", "")));
var token = callAndGetToken("CreateSprocket", Document.ofObject(Map.of("id", "1", "token", "")));

assertThat(token, notNullValue());
assertThat(token, not(equalTo("")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ void setsCorrectDefault() {
defaults.streamingBlob()
.asByteBuffer()
.thenAccept(b -> assertEquals(b, ByteBuffer.wrap(Base64.getDecoder().decode("c3RyZWFtaW5n"))));
assertEquals(defaults.boolDoc(), Document.createBoolean(true));
assertEquals(defaults.stringDoc(), Document.createString("string"));
assertEquals(defaults.numberDoc(), Document.createInteger(1));
assertEquals(defaults.floatingPointnumberDoc(), Document.createDouble(1.2));
assertEquals(defaults.listDoc(), Document.createList(Collections.emptyList()));
assertEquals(defaults.mapDoc(), Document.createStringMap(Collections.emptyMap()));
assertEquals(defaults.boolDoc(), Document.of(true));
assertEquals(defaults.stringDoc(), Document.of("string"));
assertEquals(defaults.numberDoc(), Document.of(1));
assertEquals(defaults.floatingPointnumberDoc(), Document.of(1.2));
assertEquals(defaults.listDoc(), Document.of(Collections.emptyList()));
assertEquals(defaults.mapDoc(), Document.of(Collections.emptyMap()));
assertEquals(defaults.list(), List.of());
assertEquals(defaults.map(), Map.of());
assertEquals(defaults.timestamp(), Instant.parse("1985-04-12T23:20:50.52Z"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static Stream<SerializableShape> listTypes() {
.build(),
ListAllTypesInput.builder()
.listOfDocuments(
List.of(Document.createDouble(2.0), Document.createString("string"))
List.of(Document.of(2.0), Document.of("string"))
)
.build()
);
Expand Down Expand Up @@ -240,7 +240,7 @@ static Stream<SerializableShape> sparseLists() {
.build(),
SparseListsInput.builder()
.listOfDocuments(
ListUtils.of(Document.createDouble(2.0), null, Document.createString("string"))
ListUtils.of(Document.of(2.0), null, Document.of("string"))
)
.build()
);
Expand All @@ -264,8 +264,8 @@ void nullDistinctFromEmpty() {
// Collections should return empty collections for access
assertEquals(emptyInput.listOfBoolean(), Collections.emptyList());
assertEquals(emptyInput.listOfBoolean(), nullInput.listOfBoolean());
var emptyDocument = Document.createTyped(emptyInput);
var nullDocument = Document.createTyped(nullInput);
var emptyDocument = Document.of(emptyInput);
var nullDocument = Document.of(nullInput);
assertNotNull(emptyDocument.getMember("listOfBoolean"));
assertNull(nullDocument.getMember("listOfBoolean"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ void nullDistinctFromEmpty() {
assertEquals(emptyInput.stringBooleanMap(), Collections.emptyMap());
assertEquals(emptyInput.stringBooleanMap(), nullInput.stringBooleanMap());

var emptyDocument = Document.createTyped(emptyInput);
var nullDocument = Document.createTyped(nullInput);
var emptyDocument = Document.of(emptyInput);
var nullDocument = Document.of(nullInput);
assertNotNull(emptyDocument.getMember("stringBooleanMap"));
assertNull(nullDocument.getMember("stringBooleanMap"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void multiplyRecursiveUnionWorks() {
)
)
);
var document = Document.createTyped(recursive);
var document = Document.of(recursive);
var builder = AttributeValue.builder();
document.deserializeInto(builder);
var output = builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class StructuresTest {
static Stream<SerializableShape> memberTypes() {
return Stream.of(
BooleanMembersInput.builder().requiredBoolean(true).build(),
DocumentMembersInput.builder().requiredDoc(Document.createString("str")).build(),
DocumentMembersInput.builder().requiredDoc(Document.of("str")).build(),
ListMembersInput.builder().requiredList(List.of("a", "b", "c")).build(),
MapMembersInput.builder().requiredMap(Map.of("a", "b")).build(),
BigDecimalMembersInput.builder().requiredBigDecimal(BigDecimal.valueOf(1.0)).build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static Stream<SerializableShape> unionTypes() {
@ParameterizedTest
@MethodSource("unionTypes")
void pojoToDocumentRoundTrip(UnionType pojo) {
var document = Document.createTyped(pojo);
var document = Document.of(pojo);
var builder = UnionType.builder();
document.deserializeInto(builder);
var output = builder.build();
Expand All @@ -70,7 +70,7 @@ void pojoToDocumentRoundTrip(UnionType pojo) {

record UnknownDocument() implements Document {

private static final Map<String, Document> members = Map.of("UNKNOWN!!!", Document.createDouble(3.2));
private static final Map<String, Document> members = Map.of("UNKNOWN!!!", Document.of(3.2));

@Override
public ShapeType type() {
Expand Down Expand Up @@ -112,6 +112,6 @@ void unknownUnionDeser() {
@Test
void unknownUnionSerFails() {
var union = UnionType.builder().$unknownMember("foo").build();
assertThrows(SerializationException.class, () -> Document.createTyped(union));
assertThrows(SerializationException.class, () -> Document.of(union));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class Utils {
private Utils() {}

static <T extends SerializableStruct> T pojoToDocumentRoundTrip(T pojo) {
var document = Document.createTyped(pojo);
var document = Document.of(pojo);
ShapeBuilder<T> builder = getBuilder(pojo);
document.deserializeInto(builder);
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1054,13 +1054,13 @@ private record DocumentDefaultNodeVisitor(JavaWriter writer) implements NodeVisi
@Override
public Void arrayNode(ArrayNode node) {
// List defaults must always be empty
writer.write("${document:T}.createList($T.emptyList())", Collections.class);
writer.write("${document:T}.of($T.emptyList())", Collections.class);
return null;
}

@Override
public Void booleanNode(BooleanNode node) {
writer.write("${document:T}.createBoolean($L)", node.getValue());
writer.write("${document:T}.of($L)", node.getValue());
return null;
}

Expand All @@ -1072,23 +1072,23 @@ public Void nullNode(NullNode node) {
@Override
public Void numberNode(NumberNode node) {
if (node.isFloatingPointNumber()) {
writer.write("${document:T}.createDouble($L)", node.getValue().doubleValue());
writer.write("${document:T}.of($L)", node.getValue().doubleValue());
} else {
writer.write("${document:T}.createInteger($L)", node.getValue().intValue());
writer.write("${document:T}.of($L)", node.getValue().intValue());
}
return null;
}

@Override
public Void objectNode(ObjectNode node) {
// Map defaults must always be empty
writer.write("${document:T}.createStringMap($T.emptyMap())", Collections.class);
writer.write("${document:T}.of($T.emptyMap())", Collections.class);
return null;
}

@Override
public Void stringNode(StringNode node) {
writer.write("${document:T}.createString($S)", node.getValue());
writer.write("${document:T}.of($S)", node.getValue());
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public Void arrayNode(ArrayNode arrayNode) {
writer.putContext("nodes", consumers);
writer.putContext("list", List.class);
writer.write(
"${document:T}.createList(${list:T}.of(${#nodes}${value:C}${^key.last}, ${/key.last}${/nodes}))"
"${document:T}.of(${list:T}.of(${#nodes}${value:C}${^key.last}, ${/key.last}${/nodes}))"
);
writer.popState();
return null;
Expand All @@ -250,7 +250,7 @@ public Void arrayNode(ArrayNode arrayNode) {
public Void objectNode(ObjectNode objectNode) {
writer.pushState();
writer.putContext("map", Map.class);
writer.openBlock("${document:T}.createStringMap(${map:T}.of(", "))", () -> {
writer.openBlock("${document:T}.of(${map:T}.of(", "))", () -> {
var iter = objectNode.getMembers().entrySet().iterator();
while (iter.hasNext()) {
var entry = iter.next();
Expand All @@ -271,19 +271,19 @@ public Void objectNode(ObjectNode objectNode) {

@Override
public Void booleanNode(BooleanNode booleanNode) {
writer.writeInline("${document:T}.createBoolean($L)", booleanNode.getValue());
writer.writeInline("${document:T}.of($L)", booleanNode.getValue());
return null;
}

@Override
public Void numberNode(NumberNode numberNode) {
writer.writeInline("${document:T}.createNumber($L)", numberNode.getValue());
writer.writeInline("${document:T}.ofNumber($L)", numberNode.getValue());
return null;
}

@Override
public Void stringNode(StringNode stringNode) {
writer.writeInline("${document:T}.createString($S)", stringNode.getValue());
writer.writeInline("${document:T}.of($S)", stringNode.getValue());
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static Stream<Arguments> types() {
@ParameterizedTest
@MethodSource("types")
<T extends SerializableShape> void serdeTest(T pojo, ShapeBuilder<T> builder) {
var document = Document.createTyped(pojo);
var document = Document.of(pojo);
document.deserializeInto(builder);
var output = builder.build();
assertEquals(pojo.hashCode(), output.hashCode());
Expand Down
Loading
Loading