Skip to content

Commit

Permalink
Fix deviceupdate build (#19626)
Browse files Browse the repository at this point in the history
* Fix readme format

* exclude swagger readme from docsettings

* fix links

* Fix playback tests

* Fix playback tests

* Fix relative link

* Suppress checkstyle for generated code

* Add missing links
  • Loading branch information
srnagar authored Mar 5, 2021
1 parent 1fb7ab7 commit 07574ab
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 63 deletions.
1 change: 1 addition & 0 deletions eng/.docsettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ known_content_issues:
- ['sdk/cosmos/azure-cosmos/README.md', '#3113']
- ['sdk/cosmos/azure-cosmos-encryption/README.md', '#3113']
- ['sdk/cosmos/README.md', '#3113']
- ['sdk/deviceupdate/azure-iot-deviceupdate/swagger/README.md', '#3113']
- ['sdk/e2e/README.md', '#3113']
- ['sdk/eventgrid/azure-messaging-eventgrid/swagger/README.md', '#3113']
- ['sdk/eventgrid/microsoft-azure-eventgrid/README.md', '#3113']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<suppress checks="Javadoc" files=".*CoverageReporter\.java"/>
<suppress checks="Javadoc" files=".*[/\\]implementation[/\\].*\.java"/>
<suppress checks="Header" files=".*package-info.java"/>

<!-- Suppress all checkstyle rules for Track 1/management libraries. -->
<suppress checks="[a-zA-Z0-9]*" files=".*[/\\]com[/\\]microsoft[/\\].*"/>

Expand Down Expand Up @@ -510,6 +510,7 @@ the main ServiceBusClientBuilder. -->
<suppress checks="[a-zA-Z0-9]*" files="[/\\]azure-digitaltwins-core[/\\]src[/\\]"/>
<suppress checks="[a-zA-Z0-9]*" files="[/\\]azure-messaging-eventgrid[/\\]src[/\\]"/>
<suppress checks="[a-zA-Z0-9]*" files="[/\\]azure-ai-anomalydetector[/\\]src[/\\]"/>
<suppress checks="[a-zA-Z0-9]*" files="[/\\]azure-iot-deviceupdate[/\\]src[/\\]"/>

<!-- Don't enforce non-static ClientLogger instances in com.azure.core.util.Option types-->
<suppress checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck"
Expand Down
21 changes: 13 additions & 8 deletions sdk/deviceupdate/azure-iot-deviceupdate/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Device Update for IoT Hub client library for Java
# Azure Device Update for IoT Hub client library for Java

The library provides access to the Device Update for IoT Hub service that enables customers to publish updates for their IoT devices to the cloud, and then deploy these updates to their devices (approve updates to groups of devices managed and provisioned in IoT Hub).

[Source code](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk) | [Product documentation](https://docs.microsoft.com/en-us/azure/iot-hub-device-update/understand-device-update)
[Source code](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk) | [Product documentation](https://docs.microsoft.com/azure/iot-hub-device-update/understand-device-update)

## Getting started

The complete Microsoft Azure SDK can be downloaded from the [Microsoft Azure Downloads](https://azure.microsoft.com/en-us/downloads/?sdk=java) page and ships with support for building deployment packages, integrating with tooling, rich command line tooling, and more.
The complete Microsoft Azure SDK can be downloaded from the [Microsoft Azure Downloads](https://azure.microsoft.com/downloads/?sdk=java) page and ships with support for building deployment packages, integrating with tooling, rich command line tooling, and more.

For the best development experience, developers should use the official Microsoft NuGet packages for libraries. NuGet packages are regularly updated with new functionality and hotfixes.

Expand All @@ -31,7 +31,7 @@ For the best development experience, developers should use the official Microsof

### Authenticate the client

In order to interact with the Device Update for IoT Hub service, you will need to create an instance of a [TokenCredential class](https://docs.microsoft.com/en-us/dotnet/api/azure.core.tokencredential?view=azure-dotnet) and pass it to the constructor of your AzureDeviceUpdateClientBuilder class.
In order to interact with the Device Update for IoT Hub service, you will need to create an instance of a [TokenCredential class](https://docs.microsoft.com/java/api/com.azure.core.credential.tokencredential?view=azure-java-stable) and pass it to the constructor of your AzureDeviceUpdateClientBuilder class.

## Key concepts

Expand All @@ -45,7 +45,7 @@ You can learn more about Device Update for IoT Hub by visiting [Device Update fo

## Examples

You can familiarize yourself with different APIs using [Samples](./src/samples).
You can familiarize yourself with different APIs using [Samples](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/deviceupdate/azure-iot-deviceupdate/src/samples).

## Troubleshooting

Expand All @@ -69,17 +69,22 @@ catch (HttpResponseException ex) {

## Next steps

Get started with our [Device Update for IoT Hub samples](./src/samples)
Get started with our [Device Update for IoT Hub samples](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/deviceupdate/azure-iot-deviceupdate/src/samples)

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit <https://cla.microsoft.com.>
This project welcomes contributions and suggestions. Most contributions require you to agree to a [Contributor License Agreement (CLA)][cla] declaring that you have the right to, and actually do, grant us the rights to use your contribution.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For more information see the [Code of Conduct FAQ][coc_faq] or contact [[email protected]][coc_contact] with any additional questions or comments.

<!-- LINKS -->
[azure_subscription]: https://azure.microsoft.com/free
[jdk_link]: https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable
[cla]: https://cla.microsoft.com
[coc]: https://opensource.microsoft.com/codeofconduct/
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
[coc_contact]: mailto:[email protected]

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fdeviceupdate%2Fazure-iot-deviceupdate%2FREADME.png)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.azure.core.test.TestBase;
import com.azure.core.test.TestMode;
import com.azure.identity.ClientSecretCredentialBuilder;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.iot.deviceupdate.models.*;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
Expand All @@ -29,6 +28,10 @@ private DeploymentsAsyncClient createClient() {
TokenCredential credentials;
HttpClient httpClient;
HttpPipelinePolicy recordingPolicy = null;
HttpPipeline httpPipeline;

HttpHeaders headers = new HttpHeaders().put("Accept", ContentType.APPLICATION_JSON);
AddHeadersPolicy addHeadersPolicy = new AddHeadersPolicy(headers);

if (getTestMode() != TestMode.PLAYBACK) {
// Record & Live
Expand All @@ -41,31 +44,19 @@ private DeploymentsAsyncClient createClient() {
if (getTestMode() == TestMode.RECORD) {
recordingPolicy = interceptorManager.getRecordPolicy();
}
}
else {
// Playback
credentials = new DefaultAzureCredentialBuilder().build();
httpClient = interceptorManager.getPlaybackClient();
}

BearerTokenAuthenticationPolicy bearerTokenAuthenticationPolicy = new BearerTokenAuthenticationPolicy(credentials, DEFAULT_SCOPE);

HttpHeaders headers = new HttpHeaders().put("Accept", ContentType.APPLICATION_JSON);
AddHeadersPolicy addHeadersPolicy = new AddHeadersPolicy(headers);

HttpPipeline httpPipeline;
if (getTestMode() == TestMode.RECORD) {
// Record & Live
BearerTokenAuthenticationPolicy bearerTokenAuthenticationPolicy =
new BearerTokenAuthenticationPolicy(credentials, DEFAULT_SCOPE);
httpPipeline = new HttpPipelineBuilder()
.httpClient(httpClient)
.policies(bearerTokenAuthenticationPolicy, addHeadersPolicy, recordingPolicy)
.build();
}
else {
// Playback
httpClient = interceptorManager.getPlaybackClient();
httpPipeline = new HttpPipelineBuilder()
.httpClient(httpClient)
.policies(bearerTokenAuthenticationPolicy, addHeadersPolicy)
.policies(addHeadersPolicy)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ private DevicesAsyncClient createClient() {
TokenCredential credentials;
HttpClient httpClient;
HttpPipelinePolicy recordingPolicy = null;
HttpPipeline httpPipeline;

HttpHeaders headers = new HttpHeaders().put("Accept", ContentType.APPLICATION_JSON);
AddHeadersPolicy addHeadersPolicy = new AddHeadersPolicy(headers);

if (getTestMode() != TestMode.PLAYBACK) {
// Record & Live
Expand All @@ -39,20 +43,10 @@ private DevicesAsyncClient createClient() {
if (getTestMode() == TestMode.RECORD) {
recordingPolicy = interceptorManager.getRecordPolicy();
}
}
else {
// Playback
credentials = new DefaultAzureCredentialBuilder().build();
httpClient = interceptorManager.getPlaybackClient();
}

BearerTokenAuthenticationPolicy bearerTokenAuthenticationPolicy = new BearerTokenAuthenticationPolicy(credentials, DEFAULT_SCOPE);

HttpHeaders headers = new HttpHeaders().put("Accept", ContentType.APPLICATION_JSON);
AddHeadersPolicy addHeadersPolicy = new AddHeadersPolicy(headers);
BearerTokenAuthenticationPolicy bearerTokenAuthenticationPolicy =
new BearerTokenAuthenticationPolicy(credentials, DEFAULT_SCOPE);

HttpPipeline httpPipeline;
if (getTestMode() == TestMode.RECORD) {
// Record & Live
httpPipeline = new HttpPipelineBuilder()
.httpClient(httpClient)
Expand All @@ -61,9 +55,12 @@ private DevicesAsyncClient createClient() {
}
else {
// Playback
credentials = new DefaultAzureCredentialBuilder().build();
httpClient = interceptorManager.getPlaybackClient();

httpPipeline = new HttpPipelineBuilder()
.httpClient(httpClient)
.policies(bearerTokenAuthenticationPolicy, addHeadersPolicy)
.policies(addHeadersPolicy)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import java.time.ZoneOffset;

public class TestData {
public static final String ACCOUNT_ENDPOINT = GetTestValue("ACCOUNT_ENDPOINT", "contosoprod.api.prod.adu.microsoft.com");
public static final String ACCOUNT_ENDPOINT = GetTestValue("ACCOUNT_ENDPOINT",
"contosoprod.api.prod.adu.microsoft.com");

public static final String TENANT_ID = GetTestValue("TENANT_ID", "tenantId");

Expand All @@ -19,17 +20,19 @@ public class TestData {

public static final String NAME = "Virtual-Machine";

public static final String VERSION = GetTestValue("UPDATE_VERSION", "");
public static final String VERSION = GetTestValue("UPDATE_VERSION", "2021.302.1202.48");

public static final String OPERATION_ID = GetTestValue("UPDATE_OPERATION", "");
public static final String OPERATION_ID = GetTestValue("UPDATE_OPERATION",
"e3a75d1b-e359-4bbd-a84c-68fbfa8b7b9f?api-version=2");

public static final String DEVICE_CLASS_ID = "b83e3c87fbf98063c20c3269f1c9e58d255906dd";

public static final String DEVICE_ID = GetTestValue("DEVICE_ID", "");
public static final String DEVICE_ID = GetTestValue("DEVICE_ID", "dpokluda-test");

public static final String DEPLOYMENT_ID = GetTestValue("DEPLOYMENT_ID", "");
public static final String DEPLOYMENT_ID = GetTestValue("DEPLOYMENT_ID", "dpokluda-test-2021-302-1202-48");

public static final OffsetDateTime CREATE_DEPLOYMENT_START = OffsetDateTime.of(2020, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
public static final OffsetDateTime CREATE_DEPLOYMENT_START = OffsetDateTime
.of(2020, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);

private static String GetTestValue(String name, String defaultValue) {
if (Configuration.getGlobalConfiguration().contains(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.azure.core.test.TestBase;
import com.azure.core.test.TestMode;
import com.azure.identity.ClientSecretCredentialBuilder;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.iot.deviceupdate.models.*;
import org.junit.jupiter.api.Test;

Expand All @@ -23,7 +22,6 @@

import static org.junit.jupiter.api.Assertions.*;


public class UpdatesClientTests extends TestBase {
private static final String FILE_NAME = "setup.exe";
private static final String DEFAULT_SCOPE = "6ee392c4-d339-4083-b04d-6b7947c6cf78/.default";
Expand All @@ -32,6 +30,10 @@ private UpdatesAsyncClient createClient() {
TokenCredential credentials;
HttpClient httpClient;
HttpPipelinePolicy recordingPolicy = null;
HttpPipeline httpPipeline;

HttpHeaders headers = new HttpHeaders().put("Accept", ContentType.APPLICATION_JSON);
AddHeadersPolicy addHeadersPolicy = new AddHeadersPolicy(headers);

if (getTestMode() != TestMode.PLAYBACK) {
// Record & Live
Expand All @@ -44,31 +46,19 @@ private UpdatesAsyncClient createClient() {
if (getTestMode() == TestMode.RECORD) {
recordingPolicy = interceptorManager.getRecordPolicy();
}
}
else {
// Playback
credentials = new DefaultAzureCredentialBuilder().build();
httpClient = interceptorManager.getPlaybackClient();
}

BearerTokenAuthenticationPolicy bearerTokenAuthenticationPolicy = new BearerTokenAuthenticationPolicy(credentials, DEFAULT_SCOPE);

HttpHeaders headers = new HttpHeaders().put("Accept", ContentType.APPLICATION_JSON);
AddHeadersPolicy addHeadersPolicy = new AddHeadersPolicy(headers);

HttpPipeline httpPipeline;
if (getTestMode() == TestMode.RECORD) {
// Record & Live
BearerTokenAuthenticationPolicy bearerTokenAuthenticationPolicy =
new BearerTokenAuthenticationPolicy(credentials, DEFAULT_SCOPE);
httpPipeline = new HttpPipelineBuilder()
.httpClient(httpClient)
.policies(bearerTokenAuthenticationPolicy, addHeadersPolicy, recordingPolicy)
.build();
}
else {
// Playback
httpClient = interceptorManager.getPlaybackClient();
httpPipeline = new HttpPipelineBuilder()
.httpClient(httpClient)
.policies(bearerTokenAuthenticationPolicy, addHeadersPolicy)
.policies(addHeadersPolicy)
.build();
}

Expand Down

0 comments on commit 07574ab

Please sign in to comment.