Skip to content

Commit

Permalink
Adding MessageWithMetadata to azure-core-experimental. (#26810)
Browse files Browse the repository at this point in the history
* Adding MessageWithMetadata.

* Adding MessageWithMetadataTest.

* Adding package-info.java.

* Update CHANGELOG
  • Loading branch information
conniey authored Feb 4, 2022
1 parent 9017150 commit ed1e0c0
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sdk/core/azure-core-experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

## 1.0.0-beta.24 (2022-02-03)

### Features Added

- Added `com.azure.core.experimental.models.MessageWithMetadata`.

### Other Changes

### Breaking Changes

#### Dependency Updates

- Upgraded `azure-core` from `1.24.1` to `1.25.0`.
Expand Down Expand Up @@ -62,7 +68,7 @@

### Breaking Changes

- Moved `HttpAuthorization` into `azure-core`.
- Moved `HttpAuthorization` into `azure-core`.

### Other Changes

Expand Down Expand Up @@ -174,7 +180,7 @@

- Added API `fromObject()` in `BinaryData` which uses `JsonSerializer` present in the classpath.
- Added APIs to `JsonPatchDocument` which accept pre-serialized JSON.
- Updated `azure-core` dependency to released version.
- Updated `azure-core` dependency to released version.

## 1.0.0-beta.6 (2020-10-06)

Expand Down
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;
}
}
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;
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
exports com.azure.core.experimental.http;
exports com.azure.core.experimental.http.policy;

exports com.azure.core.experimental.models;

uses com.azure.core.experimental.serializer.AvroSerializerProvider;
}
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());
}
}

0 comments on commit ed1e0c0

Please sign in to comment.