-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding MessageWithMetadata to azure-core-experimental. (#26810)
* Adding MessageWithMetadata. * Adding MessageWithMetadataTest. * Adding package-info.java. * Update CHANGELOG
- Loading branch information
Showing
5 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...re-experimental/src/main/java/com/azure/core/experimental/models/MessageWithMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.core.experimental.models; | ||
|
||
import com.azure.core.annotation.Fluent; | ||
import com.azure.core.util.BinaryData; | ||
|
||
/** | ||
* An abstraction for a message containing a content type along with its data. | ||
*/ | ||
@Fluent | ||
public class MessageWithMetadata { | ||
private BinaryData binaryData; | ||
private String contentType; | ||
|
||
/** | ||
* Gets the message body. | ||
* | ||
* @return The message body. | ||
*/ | ||
public BinaryData getBodyAsBinaryData() { | ||
return binaryData; | ||
} | ||
|
||
/** | ||
* Sets the message body. | ||
* | ||
* @param binaryData The message body. | ||
* | ||
* @return The updated {@link MessageWithMetadata} object. | ||
*/ | ||
public MessageWithMetadata setBodyAsBinaryData(BinaryData binaryData) { | ||
this.binaryData = binaryData; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets the content type. | ||
* | ||
* @return The content type. | ||
*/ | ||
public String getContentType() { | ||
return contentType; | ||
} | ||
|
||
/** | ||
* Sets the content type. | ||
* | ||
* @param contentType The content type. | ||
* | ||
* @return The updated {@link MessageWithMetadata} object. | ||
*/ | ||
public MessageWithMetadata setContentType(String contentType) { | ||
this.contentType = contentType; | ||
return this; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...zure-core-experimental/src/main/java/com/azure/core/experimental/models/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* Package containing experimental model classes. | ||
*/ | ||
package com.azure.core.experimental.models; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...xperimental/src/test/java/com/azure/core/experimental/models/MessageWithMetadataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.core.experimental.models; | ||
|
||
import com.azure.core.util.BinaryData; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
/** | ||
* Tests for {@link MessageWithMetadata} | ||
*/ | ||
public class MessageWithMetadataTest { | ||
/** | ||
* Verify default parameters. | ||
*/ | ||
@Test | ||
public void initialize() { | ||
// Act | ||
final MessageWithMetadata message = new MessageWithMetadata(); | ||
|
||
// Assert | ||
assertNull(message.getBodyAsBinaryData(), "'body' should initially be null."); | ||
assertNull(message.getContentType(), "'contentType' should initially be null."); | ||
} | ||
|
||
/** | ||
* Verify properties can be set. | ||
*/ | ||
@Test | ||
public void settingProperties() { | ||
// Arrange | ||
final BinaryData binaryData = BinaryData.fromString("foo.bar.baz"); | ||
final String contentType = "some-content"; | ||
final MessageWithMetadata message = new MessageWithMetadata(); | ||
|
||
// Act | ||
final MessageWithMetadata actual = message.setContentType(contentType) | ||
.setBodyAsBinaryData(binaryData); | ||
|
||
// Assert | ||
assertEquals(binaryData, actual.getBodyAsBinaryData()); | ||
assertEquals(contentType, actual.getContentType()); | ||
} | ||
} |