From 1df47931611991bcb4332c35a323fa93bf2dbf4d Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 30 Jan 2026 15:19:27 +0800 Subject: [PATCH 1/5] mock value for BinaryData --- .../http/client/generator/core/util/ModelTestCaseUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/ModelTestCaseUtil.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/ModelTestCaseUtil.java index 8307064003b..f38954434f8 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/ModelTestCaseUtil.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/ModelTestCaseUtil.java @@ -127,7 +127,7 @@ public static Object jsonFromType(int depth, IType type) { return UUID.randomUUID().toString(); } else if (type == ClassType.URL) { return "http://example.org/" + URLEncoder.encode(randomString(), StandardCharsets.UTF_8); - } else if (type == ClassType.OBJECT) { + } else if (type == ClassType.OBJECT || type == ClassType.BINARY_DATA) { // unknown type, use a simple string return "data" + randomString(); } else if (type instanceof EnumType) { From 74f6a311571a50dfafb6779b945edd27e47934f0 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 30 Jan 2026 15:19:47 +0800 Subject: [PATCH 2/5] test --- .../tsp/arm-stream-style-serialization.tsp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/http-client-java/generator/http-client-generator-test/tsp/arm-stream-style-serialization.tsp b/packages/http-client-java/generator/http-client-generator-test/tsp/arm-stream-style-serialization.tsp index 3d45287f072..4ae6f69c189 100644 --- a/packages/http-client-java/generator/http-client-generator-test/tsp/arm-stream-style-serialization.tsp +++ b/packages/http-client-java/generator/http-client-generator-test/tsp/arm-stream-style-serialization.tsp @@ -287,6 +287,8 @@ model ResultData { prop2: string; } +// test the serializaton of "unknown" +@usage(Usage.input | Usage.output) model Builtin { boolean: boolean; string: string; @@ -304,8 +306,9 @@ model Builtin { bytesDict: Record; url: url; nullableFloatDict: Record; - encoded: Encoded; + encoding: Encoded; uuid: Azure.Core.uuid; + `unknown`: unknown; } @encode(DurationKnownEncoding.seconds, float32) From 1c13b74920cb85ba0ba1d83e47d504d91472ac98 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 30 Jan 2026 15:34:40 +0800 Subject: [PATCH 3/5] regen --- .../models/Builtin.java | 263 +++++++++++++++++- .../models/Encoded.java | 181 +++++++++++- 2 files changed, 426 insertions(+), 18 deletions(-) diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armstreamstyleserialization/models/Builtin.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armstreamstyleserialization/models/Builtin.java index 6ed4912ec3f..4baa115a2f1 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armstreamstyleserialization/models/Builtin.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armstreamstyleserialization/models/Builtin.java @@ -4,7 +4,8 @@ package tsptest.armstreamstyleserialization.models; -import com.azure.core.annotation.Immutable; +import com.azure.core.annotation.Fluent; +import com.azure.core.util.BinaryData; import com.azure.core.util.CoreUtils; import com.azure.core.util.logging.ClientLogger; import com.azure.json.JsonReader; @@ -24,7 +25,7 @@ /** * The Builtin model. */ -@Immutable +@Fluent public final class Builtin implements JsonSerializable { /* * The boolean property. @@ -107,19 +108,24 @@ public final class Builtin implements JsonSerializable { private Map nullableFloatDict; /* - * The encoded property. + * The encoding property. */ - private Encoded encoded; + private Encoded encoding; /* * The uuid property. */ private String uuid; + /* + * The unknown property. + */ + private BinaryData unknown; + /** * Creates an instance of Builtin class. */ - private Builtin() { + public Builtin() { } /** @@ -131,6 +137,17 @@ public boolean booleanProperty() { return this.booleanProperty; } + /** + * Set the booleanProperty property: The boolean property. + * + * @param booleanProperty the booleanProperty value to set. + * @return the Builtin object itself. + */ + public Builtin withBooleanProperty(boolean booleanProperty) { + this.booleanProperty = booleanProperty; + return this; + } + /** * Get the string property: The string property. * @@ -140,6 +157,17 @@ public String string() { return this.string; } + /** + * Set the string property: The string property. + * + * @param string the string value to set. + * @return the Builtin object itself. + */ + public Builtin withString(String string) { + this.string = string; + return this; + } + /** * Get the bytes property: The bytes property. * @@ -149,6 +177,17 @@ public byte[] bytes() { return CoreUtils.clone(this.bytes); } + /** + * Set the bytes property: The bytes property. + * + * @param bytes the bytes value to set. + * @return the Builtin object itself. + */ + public Builtin withBytes(byte[] bytes) { + this.bytes = CoreUtils.clone(bytes); + return this; + } + /** * Get the intProperty property: The int property. * @@ -158,6 +197,17 @@ public int intProperty() { return this.intProperty; } + /** + * Set the intProperty property: The int property. + * + * @param intProperty the intProperty value to set. + * @return the Builtin object itself. + */ + public Builtin withIntProperty(int intProperty) { + this.intProperty = intProperty; + return this; + } + /** * Get the safeint property: The safeint property. * @@ -167,6 +217,17 @@ public long safeint() { return this.safeint; } + /** + * Set the safeint property: The safeint property. + * + * @param safeint the safeint value to set. + * @return the Builtin object itself. + */ + public Builtin withSafeint(long safeint) { + this.safeint = safeint; + return this; + } + /** * Get the decimal property: The decimal property. * @@ -176,6 +237,17 @@ public BigDecimal decimal() { return this.decimal; } + /** + * Set the decimal property: The decimal property. + * + * @param decimal the decimal value to set. + * @return the Builtin object itself. + */ + public Builtin withDecimal(BigDecimal decimal) { + this.decimal = decimal; + return this; + } + /** * Get the longProperty property: The long property. * @@ -185,6 +257,17 @@ public long longProperty() { return this.longProperty; } + /** + * Set the longProperty property: The long property. + * + * @param longProperty the longProperty value to set. + * @return the Builtin object itself. + */ + public Builtin withLongProperty(long longProperty) { + this.longProperty = longProperty; + return this; + } + /** * Get the floatProperty property: The float property. * @@ -194,6 +277,17 @@ public double floatProperty() { return this.floatProperty; } + /** + * Set the floatProperty property: The float property. + * + * @param floatProperty the floatProperty value to set. + * @return the Builtin object itself. + */ + public Builtin withFloatProperty(double floatProperty) { + this.floatProperty = floatProperty; + return this; + } + /** * Get the doubleProperty property: The double property. * @@ -203,6 +297,17 @@ public double doubleProperty() { return this.doubleProperty; } + /** + * Set the doubleProperty property: The double property. + * + * @param doubleProperty the doubleProperty value to set. + * @return the Builtin object itself. + */ + public Builtin withDoubleProperty(double doubleProperty) { + this.doubleProperty = doubleProperty; + return this; + } + /** * Get the duration property: The duration property. * @@ -212,6 +317,17 @@ public Duration duration() { return this.duration; } + /** + * Set the duration property: The duration property. + * + * @param duration the duration value to set. + * @return the Builtin object itself. + */ + public Builtin withDuration(Duration duration) { + this.duration = duration; + return this; + } + /** * Get the date property: The date property. * @@ -221,6 +337,17 @@ public LocalDate date() { return this.date; } + /** + * Set the date property: The date property. + * + * @param date the date value to set. + * @return the Builtin object itself. + */ + public Builtin withDate(LocalDate date) { + this.date = date; + return this; + } + /** * Get the dateTime property: The dateTime property. * @@ -230,6 +357,17 @@ public OffsetDateTime dateTime() { return this.dateTime; } + /** + * Set the dateTime property: The dateTime property. + * + * @param dateTime the dateTime value to set. + * @return the Builtin object itself. + */ + public Builtin withDateTime(OffsetDateTime dateTime) { + this.dateTime = dateTime; + return this; + } + /** * Get the stringList property: The stringList property. * @@ -239,6 +377,17 @@ public List stringList() { return this.stringList; } + /** + * Set the stringList property: The stringList property. + * + * @param stringList the stringList value to set. + * @return the Builtin object itself. + */ + public Builtin withStringList(List stringList) { + this.stringList = stringList; + return this; + } + /** * Get the bytesDict property: The bytesDict property. * @@ -248,6 +397,17 @@ public Map bytesDict() { return this.bytesDict; } + /** + * Set the bytesDict property: The bytesDict property. + * + * @param bytesDict the bytesDict value to set. + * @return the Builtin object itself. + */ + public Builtin withBytesDict(Map bytesDict) { + this.bytesDict = bytesDict; + return this; + } + /** * Get the url property: The url property. * @@ -257,6 +417,17 @@ public String url() { return this.url; } + /** + * Set the url property: The url property. + * + * @param url the url value to set. + * @return the Builtin object itself. + */ + public Builtin withUrl(String url) { + this.url = url; + return this; + } + /** * Get the nullableFloatDict property: The nullableFloatDict property. * @@ -267,12 +438,34 @@ public Map nullableFloatDict() { } /** - * Get the encoded property: The encoded property. + * Set the nullableFloatDict property: The nullableFloatDict property. + * + * @param nullableFloatDict the nullableFloatDict value to set. + * @return the Builtin object itself. + */ + public Builtin withNullableFloatDict(Map nullableFloatDict) { + this.nullableFloatDict = nullableFloatDict; + return this; + } + + /** + * Get the encoding property: The encoding property. * - * @return the encoded value. + * @return the encoding value. */ - public Encoded encoded() { - return this.encoded; + public Encoded encoding() { + return this.encoding; + } + + /** + * Set the encoding property: The encoding property. + * + * @param encoding the encoding value to set. + * @return the Builtin object itself. + */ + public Builtin withEncoding(Encoded encoding) { + this.encoding = encoding; + return this; } /** @@ -284,6 +477,37 @@ public String uuid() { return this.uuid; } + /** + * Set the uuid property: The uuid property. + * + * @param uuid the uuid value to set. + * @return the Builtin object itself. + */ + public Builtin withUuid(String uuid) { + this.uuid = uuid; + return this; + } + + /** + * Get the unknown property: The unknown property. + * + * @return the unknown value. + */ + public BinaryData unknown() { + return this.unknown; + } + + /** + * Set the unknown property: The unknown property. + * + * @param unknown the unknown value to set. + * @return the Builtin object itself. + */ + public Builtin withUnknown(BinaryData unknown) { + this.unknown = unknown; + return this; + } + /** * Validates the instance. * @@ -328,15 +552,19 @@ public void validate() { throw LOGGER.atError() .log(new IllegalArgumentException("Missing required property nullableFloatDict in model Builtin")); } - if (encoded() == null) { + if (encoding() == null) { throw LOGGER.atError() - .log(new IllegalArgumentException("Missing required property encoded in model Builtin")); + .log(new IllegalArgumentException("Missing required property encoding in model Builtin")); } else { - encoded().validate(); + encoding().validate(); } if (uuid() == null) { throw LOGGER.atError().log(new IllegalArgumentException("Missing required property uuid in model Builtin")); } + if (unknown() == null) { + throw LOGGER.atError() + .log(new IllegalArgumentException("Missing required property unknown in model Builtin")); + } } private static final ClientLogger LOGGER = new ClientLogger(Builtin.class); @@ -365,8 +593,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStringField("url", this.url); jsonWriter.writeMapField("nullableFloatDict", this.nullableFloatDict, (writer, element) -> writer.writeNumber(element)); - jsonWriter.writeJsonField("encoded", this.encoded); + jsonWriter.writeJsonField("encoding", this.encoding); jsonWriter.writeStringField("uuid", this.uuid); + jsonWriter.writeFieldName("unknown"); + this.unknown.writeTo(jsonWriter); return jsonWriter.writeEndObject(); } @@ -426,10 +656,13 @@ public static Builtin fromJson(JsonReader jsonReader) throws IOException { Map nullableFloatDict = reader.readMap(reader1 -> reader1.getNullable(JsonReader::getDouble)); deserializedBuiltin.nullableFloatDict = nullableFloatDict; - } else if ("encoded".equals(fieldName)) { - deserializedBuiltin.encoded = Encoded.fromJson(reader); + } else if ("encoding".equals(fieldName)) { + deserializedBuiltin.encoding = Encoded.fromJson(reader); } else if ("uuid".equals(fieldName)) { deserializedBuiltin.uuid = reader.getString(); + } else if ("unknown".equals(fieldName)) { + deserializedBuiltin.unknown + = reader.getNullable(nonNullReader -> BinaryData.fromObject(nonNullReader.readUntyped())); } else { reader.skipChildren(); } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armstreamstyleserialization/models/Encoded.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armstreamstyleserialization/models/Encoded.java index 9588c592228..6f6e1555fa0 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armstreamstyleserialization/models/Encoded.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armstreamstyleserialization/models/Encoded.java @@ -4,7 +4,7 @@ package tsptest.armstreamstyleserialization.models; -import com.azure.core.annotation.Immutable; +import com.azure.core.annotation.Fluent; import com.azure.core.util.Base64Url; import com.azure.core.util.CoreUtils; import com.azure.core.util.DateTimeRfc1123; @@ -24,7 +24,7 @@ /** * The Encoded model. */ -@Immutable +@Fluent public final class Encoded implements JsonSerializable { private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; @@ -96,7 +96,7 @@ public final class Encoded implements JsonSerializable { /** * Creates an instance of Encoded class. */ - private Encoded() { + public Encoded() { } /** @@ -111,6 +111,21 @@ public Duration timeInSeconds() { return Duration.ofSeconds(this.timeInSeconds); } + /** + * Set the timeInSeconds property: The timeInSeconds property. + * + * @param timeInSeconds the timeInSeconds value to set. + * @return the Encoded object itself. + */ + public Encoded withTimeInSeconds(Duration timeInSeconds) { + if (timeInSeconds == null) { + this.timeInSeconds = null; + } else { + this.timeInSeconds = timeInSeconds.getSeconds(); + } + return this; + } + /** * Get the timeInSecondsPrimitive property: The timeInSecondsPrimitive property. * @@ -120,6 +135,21 @@ public Duration timeInSecondsPrimitive() { return Duration.ofSeconds(this.timeInSecondsPrimitive); } + /** + * Set the timeInSecondsPrimitive property: The timeInSecondsPrimitive property. + * + * @param timeInSecondsPrimitive the timeInSecondsPrimitive value to set. + * @return the Encoded object itself. + */ + public Encoded withTimeInSecondsPrimitive(Duration timeInSecondsPrimitive) { + if (timeInSecondsPrimitive == null) { + this.timeInSecondsPrimitive = 0L; + } else { + this.timeInSecondsPrimitive = timeInSecondsPrimitive.getSeconds(); + } + return this; + } + /** * Get the timeInSecondsFraction property: The timeInSecondsFraction property. * @@ -132,6 +162,21 @@ public Duration timeInSecondsFraction() { return Duration.ofNanos((long) (this.timeInSecondsFraction * 1000_000_000L)); } + /** + * Set the timeInSecondsFraction property: The timeInSecondsFraction property. + * + * @param timeInSecondsFraction the timeInSecondsFraction value to set. + * @return the Encoded object itself. + */ + public Encoded withTimeInSecondsFraction(Duration timeInSecondsFraction) { + if (timeInSecondsFraction == null) { + this.timeInSecondsFraction = null; + } else { + this.timeInSecondsFraction = (double) timeInSecondsFraction.toNanos() / 1000_000_000L; + } + return this; + } + /** * Get the timeInSecondsFractionPrimitive property: The timeInSecondsFractionPrimitive property. * @@ -141,6 +186,21 @@ public Duration timeInSecondsFractionPrimitive() { return Duration.ofNanos((long) (this.timeInSecondsFractionPrimitive * 1000_000_000L)); } + /** + * Set the timeInSecondsFractionPrimitive property: The timeInSecondsFractionPrimitive property. + * + * @param timeInSecondsFractionPrimitive the timeInSecondsFractionPrimitive value to set. + * @return the Encoded object itself. + */ + public Encoded withTimeInSecondsFractionPrimitive(Duration timeInSecondsFractionPrimitive) { + if (timeInSecondsFractionPrimitive == null) { + this.timeInSecondsFractionPrimitive = 0.0; + } else { + this.timeInSecondsFractionPrimitive = (double) timeInSecondsFractionPrimitive.toNanos() / 1000_000_000L; + } + return this; + } + /** * Get the dateTime property: The dateTime property. * @@ -150,6 +210,17 @@ public OffsetDateTime dateTime() { return this.dateTime; } + /** + * Set the dateTime property: The dateTime property. + * + * @param dateTime the dateTime value to set. + * @return the Encoded object itself. + */ + public Encoded withDateTime(OffsetDateTime dateTime) { + this.dateTime = dateTime; + return this; + } + /** * Get the dateTimeRfc7231 property: The dateTimeRfc7231 property. * @@ -162,6 +233,21 @@ public OffsetDateTime dateTimeRfc7231() { return this.dateTimeRfc7231.getDateTime(); } + /** + * Set the dateTimeRfc7231 property: The dateTimeRfc7231 property. + * + * @param dateTimeRfc7231 the dateTimeRfc7231 value to set. + * @return the Encoded object itself. + */ + public Encoded withDateTimeRfc7231(OffsetDateTime dateTimeRfc7231) { + if (dateTimeRfc7231 == null) { + this.dateTimeRfc7231 = null; + } else { + this.dateTimeRfc7231 = new DateTimeRfc1123(dateTimeRfc7231); + } + return this; + } + /** * Get the unixTimestamp property: The unixTimestamp property. * @@ -174,6 +260,21 @@ public OffsetDateTime unixTimestamp() { return OffsetDateTime.ofInstant(Instant.ofEpochSecond(this.unixTimestamp), ZoneOffset.UTC); } + /** + * Set the unixTimestamp property: The unixTimestamp property. + * + * @param unixTimestamp the unixTimestamp value to set. + * @return the Encoded object itself. + */ + public Encoded withUnixTimestamp(OffsetDateTime unixTimestamp) { + if (unixTimestamp == null) { + this.unixTimestamp = null; + } else { + this.unixTimestamp = unixTimestamp.toEpochSecond(); + } + return this; + } + /** * Get the unixTimestampPrimitive property: The unixTimestampPrimitive property. * @@ -183,6 +284,21 @@ public OffsetDateTime unixTimestampPrimitive() { return OffsetDateTime.ofInstant(Instant.ofEpochSecond(this.unixTimestampPrimitive), ZoneOffset.UTC); } + /** + * Set the unixTimestampPrimitive property: The unixTimestampPrimitive property. + * + * @param unixTimestampPrimitive the unixTimestampPrimitive value to set. + * @return the Encoded object itself. + */ + public Encoded withUnixTimestampPrimitive(OffsetDateTime unixTimestampPrimitive) { + if (unixTimestampPrimitive == null) { + this.unixTimestampPrimitive = 0L; + } else { + this.unixTimestampPrimitive = unixTimestampPrimitive.toEpochSecond(); + } + return this; + } + /** * Get the base64 property: The base64 property. * @@ -192,6 +308,17 @@ public byte[] base64() { return CoreUtils.clone(this.base64); } + /** + * Set the base64 property: The base64 property. + * + * @param base64 the base64 value to set. + * @return the Encoded object itself. + */ + public Encoded withBase64(byte[] base64) { + this.base64 = CoreUtils.clone(base64); + return this; + } + /** * Get the base64url property: The base64url property. * @@ -204,6 +331,21 @@ public byte[] base64url() { return this.base64url.decodedBytes(); } + /** + * Set the base64url property: The base64url property. + * + * @param base64url the base64url value to set. + * @return the Encoded object itself. + */ + public Encoded withBase64url(byte[] base64url) { + if (base64url == null) { + this.base64url = null; + } else { + this.base64url = Base64Url.encode(CoreUtils.clone(base64url)); + } + return this; + } + /** * Get the unknownDurationFormat property: The unknownDurationFormat property. * @@ -213,6 +355,17 @@ public String unknownDurationFormat() { return this.unknownDurationFormat; } + /** + * Set the unknownDurationFormat property: The unknownDurationFormat property. + * + * @param unknownDurationFormat the unknownDurationFormat value to set. + * @return the Encoded object itself. + */ + public Encoded withUnknownDurationFormat(String unknownDurationFormat) { + this.unknownDurationFormat = unknownDurationFormat; + return this; + } + /** * Get the unknownDateTimeFormat property: The unknownDateTimeFormat property. * @@ -222,6 +375,17 @@ public String unknownDateTimeFormat() { return this.unknownDateTimeFormat; } + /** + * Set the unknownDateTimeFormat property: The unknownDateTimeFormat property. + * + * @param unknownDateTimeFormat the unknownDateTimeFormat value to set. + * @return the Encoded object itself. + */ + public Encoded withUnknownDateTimeFormat(String unknownDateTimeFormat) { + this.unknownDateTimeFormat = unknownDateTimeFormat; + return this; + } + /** * Get the unknownBytes property: The unknownBytes property. * @@ -231,6 +395,17 @@ public String unknownBytes() { return this.unknownBytes; } + /** + * Set the unknownBytes property: The unknownBytes property. + * + * @param unknownBytes the unknownBytes value to set. + * @return the Encoded object itself. + */ + public Encoded withUnknownBytes(String unknownBytes) { + this.unknownBytes = unknownBytes; + return this; + } + /** * Validates the instance. * From 6370720f4ea3d61e8d8d586f48f166be075e0759 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 30 Jan 2026 15:36:12 +0800 Subject: [PATCH 4/5] .gitignore already has src/test/java/tsptest/**/arm*/generated --- .../http-client-generator-test/Generate.ps1 | 4 -- .../TopLevelArmResourceInnerTests.java | 45 ------------------- .../TopLevelArmResourceListResultTests.java | 21 --------- .../TopLevelArmResourcePropertiesTests.java | 22 --------- 4 files changed, 92 deletions(-) delete mode 100644 packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourceInnerTests.java delete mode 100644 packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourceListResultTests.java delete mode 100644 packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourcePropertiesTests.java diff --git a/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 b/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 index 60040979a62..04565c86e76 100644 --- a/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 +++ b/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 @@ -82,8 +82,6 @@ $generateScript = { } elseif ($tspFile -match "azure[\\/]resource-manager[\\/]multi-service-shared-models[\\/]") { $tspOptions += " --option ""@typespec/http-client-java.metadata-suffix=shared-models""" } elseif ($tspFile -match "tsp[\\/]arm.tsp") { - # for mgmt, do not generate tests due to random mock values - $tspOptions += " --option ""@typespec/http-client-java.generate-tests=false""" # test service-name $tspOptions += " --option ""@typespec/http-client-java.service-name=Arm Resource Provider""" # also test generating from specific api-version @@ -105,8 +103,6 @@ $generateScript = { # enable client side validations $tspOptions += " --option ""@typespec/http-client-java.client-side-validations=true""" } elseif ($tspFile -match "tsp[\\/]arm-customization.tsp") { - # for mgmt, do not generate tests due to random mock values - $tspOptions += " --option ""@typespec/http-client-java.generate-tests=false""" # add customization code $tspOptions += " --option ""@typespec/http-client-java.customization-class=../../customization/src/main/java/KeyVaultCustomization.java""" } elseif ($tspFile -match "tsp[\\/]arm-versioned.tsp") { diff --git a/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourceInnerTests.java b/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourceInnerTests.java deleted file mode 100644 index c0f8f2fc1ee..00000000000 --- a/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourceInnerTests.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) TypeSpec Code Generator. - -package tsptest.armversioned.generated; - -import com.azure.core.util.BinaryData; -import java.util.HashMap; -import java.util.Map; -import org.junit.jupiter.api.Assertions; -import tsptest.armversioned.fluent.models.TopLevelArmResourceInner; -import tsptest.armversioned.models.TopLevelArmResourceProperties; - -public final class TopLevelArmResourceInnerTests { - @org.junit.jupiter.api.Test - public void testDeserialize() throws Exception { - TopLevelArmResourceInner model = BinaryData.fromString( - "{\"properties\":{\"provisioningState\":\"Succeeded\"},\"location\":\"uv\",\"tags\":{\"phrupidgsybbejhp\":\"pybczmehmtzopb\"},\"id\":\"oycmsxaobhdxbmt\",\"name\":\"ioq\",\"type\":\"zehtbmu\"}") - .toObject(TopLevelArmResourceInner.class); - Assertions.assertEquals("uv", model.location()); - Assertions.assertEquals("pybczmehmtzopb", model.tags().get("phrupidgsybbejhp")); - } - - @org.junit.jupiter.api.Test - public void testSerialize() throws Exception { - TopLevelArmResourceInner model = new TopLevelArmResourceInner().withLocation("uv") - .withTags(mapOf("phrupidgsybbejhp", "pybczmehmtzopb")) - .withProperties(new TopLevelArmResourceProperties()); - model = BinaryData.fromObject(model).toObject(TopLevelArmResourceInner.class); - Assertions.assertEquals("uv", model.location()); - Assertions.assertEquals("pybczmehmtzopb", model.tags().get("phrupidgsybbejhp")); - } - - // Use "Map.of" if available - @SuppressWarnings("unchecked") - private static Map mapOf(Object... inputs) { - Map map = new HashMap<>(); - for (int i = 0; i < inputs.length; i += 2) { - String key = (String) inputs[i]; - T value = (T) inputs[i + 1]; - map.put(key, value); - } - return map; - } -} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourceListResultTests.java b/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourceListResultTests.java deleted file mode 100644 index bc7524675a2..00000000000 --- a/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourceListResultTests.java +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) TypeSpec Code Generator. - -package tsptest.armversioned.generated; - -import com.azure.core.util.BinaryData; -import org.junit.jupiter.api.Assertions; -import tsptest.armversioned.implementation.models.TopLevelArmResourceListResult; - -public final class TopLevelArmResourceListResultTests { - @org.junit.jupiter.api.Test - public void testDeserialize() throws Exception { - TopLevelArmResourceListResult model = BinaryData.fromString( - "{\"value\":[{\"properties\":{\"provisioningState\":\"Failed\"},\"location\":\"hwlrx\",\"tags\":{\"dmbpazlobcufpdz\":\"soqijg\",\"qqjnqgl\":\"rbt\",\"foooj\":\"qgn\"},\"id\":\"wifsq\",\"name\":\"saagdf\",\"type\":\"glzlhjxrifkwmrv\"}],\"nextLink\":\"siznto\"}") - .toObject(TopLevelArmResourceListResult.class); - Assertions.assertEquals("hwlrx", model.value().get(0).location()); - Assertions.assertEquals("soqijg", model.value().get(0).tags().get("dmbpazlobcufpdz")); - Assertions.assertEquals("siznto", model.nextLink()); - } -} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourcePropertiesTests.java b/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourcePropertiesTests.java deleted file mode 100644 index fe3644035e9..00000000000 --- a/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourcePropertiesTests.java +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) TypeSpec Code Generator. - -package tsptest.armversioned.generated; - -import com.azure.core.util.BinaryData; -import tsptest.armversioned.models.TopLevelArmResourceProperties; - -public final class TopLevelArmResourcePropertiesTests { - @org.junit.jupiter.api.Test - public void testDeserialize() throws Exception { - TopLevelArmResourceProperties model = BinaryData.fromString("{\"provisioningState\":\"Canceled\"}") - .toObject(TopLevelArmResourceProperties.class); - } - - @org.junit.jupiter.api.Test - public void testSerialize() throws Exception { - TopLevelArmResourceProperties model = new TopLevelArmResourceProperties(); - model = BinaryData.fromObject(model).toObject(TopLevelArmResourceProperties.class); - } -} From 8937aacd3eafccf9ec6b55cbf23bcb8113b97849 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 30 Jan 2026 15:37:05 +0800 Subject: [PATCH 5/5] changelog --- ...fix-example-value-for-binary-data-2026-0-30-15-36-58.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/http-client-java_bug-fix-example-value-for-binary-data-2026-0-30-15-36-58.md diff --git a/.chronus/changes/http-client-java_bug-fix-example-value-for-binary-data-2026-0-30-15-36-58.md b/.chronus/changes/http-client-java_bug-fix-example-value-for-binary-data-2026-0-30-15-36-58.md new file mode 100644 index 00000000000..49f90ce015e --- /dev/null +++ b/.chronus/changes/http-client-java_bug-fix-example-value-for-binary-data-2026-0-30-15-36-58.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-java" +--- + +Missing example value for BinaryData type in mock test. \ No newline at end of file