-
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.
- Loading branch information
Showing
10 changed files
with
382 additions
and
11 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
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,5 @@ | ||
param( | ||
[Parameter()] | ||
[string] $fileName = "test-resources.json.env" | ||
) | ||
([System.Text.Encoding]::UTF8).GetString([Security.Cryptography.ProtectedData]::Unprotect([IO.File]::ReadAllBytes((Resolve-path $fileName)), $null, [Security.Cryptography.DataProtectionScope]::CurrentUser)) |
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
110 changes: 110 additions & 0 deletions
110
...ure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/DigitalTwinsTestBase.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,110 @@ | ||
package com.azure.digitaltwins.core; | ||
|
||
import com.azure.core.credential.AccessToken; | ||
import com.azure.core.credential.TokenCredential; | ||
import com.azure.core.credential.TokenRequestContext; | ||
import com.azure.core.http.policy.HttpLogDetailLevel; | ||
import com.azure.core.http.policy.HttpLogOptions; | ||
import com.azure.core.http.policy.HttpPipelinePolicy; | ||
import com.azure.core.test.TestBase; | ||
import com.azure.core.test.TestMode; | ||
import com.azure.core.util.Configuration; | ||
import com.azure.core.util.logging.ClientLogger; | ||
import com.azure.identity.ClientSecretCredentialBuilder; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.Locale; | ||
|
||
public class DigitalTwinsTestBase extends TestBase | ||
{ | ||
protected static final String TENANT_ID = Configuration.getGlobalConfiguration() | ||
.get("TENANT_ID", "tenantId"); | ||
|
||
protected static final String CLIENT_SECRET = Configuration.getGlobalConfiguration() | ||
.get("CLIENT_SECRET", "clientSecret"); | ||
|
||
protected static final String CLIENT_ID = Configuration.getGlobalConfiguration() | ||
.get("CLIENT_ID", "clientId"); | ||
|
||
protected static final String DIGITALTWINS_URL = Configuration.getGlobalConfiguration() | ||
.get("DIGITALTWINS_URL", "https://playback.api.wus2.digitaltwins.azure.net"); | ||
|
||
protected DigitalTwinsClientBuilder getDigitalTwinsClientBuilder() { | ||
DigitalTwinsClientBuilder builder = new DigitalTwinsClientBuilder() | ||
.endpoint(DIGITALTWINS_URL); | ||
|
||
if (interceptorManager.isPlaybackMode()){ | ||
builder.httpClient(interceptorManager.getPlaybackClient()); | ||
// Use fake credentials for playback mode. | ||
builder.tokenCredential(new FakeCredentials()); | ||
return builder; | ||
} | ||
|
||
// TODO: investigate whether or not we need to add a retry policy. | ||
|
||
// If it is record mode, we add record mode policies to the builder. | ||
// There is no isRecordMode method on interceptorManger. | ||
if (!interceptorManager.isLiveMode()){ | ||
builder.addPolicy(interceptorManager.getRecordPolicy()); | ||
} | ||
|
||
// Only get valid live token when running live tests. | ||
builder.tokenCredential(new ClientSecretCredentialBuilder() | ||
.tenantId(TENANT_ID) | ||
.clientId(CLIENT_ID) | ||
.clientSecret(CLIENT_SECRET) | ||
.build()); | ||
|
||
return builder; | ||
} | ||
|
||
protected DigitalTwinsClientBuilder getDigitalTwinsClientBuilder(HttpPipelinePolicy... policies) { | ||
DigitalTwinsClientBuilder builder = new DigitalTwinsClientBuilder() | ||
.endpoint(DIGITALTWINS_URL); | ||
|
||
if (interceptorManager.isPlaybackMode()){ | ||
builder.httpClient(interceptorManager.getPlaybackClient()); | ||
// Use fake credentials for playback mode. | ||
builder.tokenCredential(new FakeCredentials()); | ||
addPolicies(builder, policies); | ||
return builder; | ||
} | ||
|
||
addPolicies(builder, policies); | ||
|
||
// TODO: investigate whether or not we need to add a retry policy. | ||
|
||
// If it is record mode, we add record mode policies to the builder. | ||
// There is no isRecordMode method on interceptorManger. | ||
if (!interceptorManager.isLiveMode()) { | ||
builder.addPolicy(interceptorManager.getRecordPolicy()); | ||
} | ||
|
||
// Only get valid live token when running live tests. | ||
builder.tokenCredential(new ClientSecretCredentialBuilder() | ||
.tenantId(TENANT_ID) | ||
.clientId(CLIENT_ID) | ||
.clientSecret(CLIENT_SECRET) | ||
.build()); | ||
|
||
return builder; | ||
} | ||
|
||
private static void addPolicies(DigitalTwinsClientBuilder builder, HttpPipelinePolicy... policies) { | ||
if (policies == null) { | ||
return; | ||
} | ||
|
||
for (HttpPipelinePolicy policy : policies) { | ||
builder.addPolicy(policy); | ||
} | ||
} | ||
|
||
static class FakeCredentials implements TokenCredential | ||
{ | ||
@Override | ||
public Mono<AccessToken> getToken(TokenRequestContext tokenRequestContext) { | ||
return Mono.empty(); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...altwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/SampleTest.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,41 @@ | ||
package com.azure.digitaltwins.core; | ||
|
||
import com.azure.core.http.rest.PagedIterable; | ||
import com.azure.digitaltwins.core.models.ModelData; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class SampleTest extends DigitalTwinsTestBase { | ||
|
||
private static DigitalTwinsClient client; | ||
|
||
@Override | ||
protected void beforeTest(){ | ||
super.beforeTest(); | ||
client = setupClient(); | ||
} | ||
|
||
@Override | ||
protected void afterTest() | ||
{ | ||
super.afterTest(); | ||
} | ||
|
||
private DigitalTwinsClient setupClient(){ | ||
return getDigitalTwinsClientBuilder() | ||
.buildClient(); | ||
} | ||
|
||
@Test | ||
public void ListTest(){ | ||
PagedIterable<ModelData> models = client.listModels(); | ||
|
||
// Process using the Stream interface by iterating over each page | ||
models | ||
// You can also subscribe to pages by specifying the preferred page size or the associated continuation token to start the processing from. | ||
.streamByPage() | ||
.forEach(page -> { | ||
System.out.println("Response headers status code is " + page.getStatusCode()); | ||
page.getValue().forEach(item -> System.out.println("Model retrieved: " + item.getId())); | ||
}); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
.../azure-digitaltwins-core/src/test/resources/prerequisite/prerequisite readme.md
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,26 @@ | ||
# Prerequisites | ||
|
||
## Install | ||
|
||
### Install the latest Powershell 7 | ||
|
||
- Make sure you run the script using the latest stable version of [powershell 7](https://github.com/PowerShell/PowerShell/releases) | ||
|
||
### Install the latest Azure CLI package | ||
|
||
- If already installed, check latest version: | ||
- Run `az --version` to make sure `azure-cli` is at least **version 2.3.1** | ||
- If it isn't, update it | ||
- Use this link to install [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest]) | ||
|
||
## Delete | ||
|
||
To delete the digital twins instance, you need to first delete the endpoint added by the script (the service doesn't yet support cascading delete). | ||
|
||
1. To do this, run the command `az dt endpoint delete -n <dt name> -g <rg name> --en someEventHubEndpoint`. | ||
1. If you have other endpoints that have been added outside this script, you can discover them with the command `az dt endpoint list -n <dt name> -g <rg name>`. | ||
1. Then delete them with the same command in step 1. | ||
|
||
## Maintenance | ||
|
||
In order to maintain the functionality of the Setup.ps1 file, make sure this document stays updated with all the required changes if you run/alter this script. |
Oops, something went wrong.