Skip to content

Commit 092420c

Browse files
authored
tsp, add test for cadl-ranch (#2866)
1 parent 8ee3658 commit 092420c

File tree

5 files changed

+171
-0
lines changed

5 files changed

+171
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com._specs_.azure.core.model;
5+
6+
import com._specs_.azure.core.model.models.AzureEmbeddingModel;
7+
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.Test;
9+
10+
import java.util.Arrays;
11+
12+
public class ModelClientTests {
13+
ModelClient client = new ModelClientBuilder().buildClient();
14+
15+
@Test
16+
public void get() {
17+
Assertions.assertIterableEquals(Arrays.asList(0, 1, 2, 3, 4), client.get());
18+
}
19+
20+
@Test
21+
public void post() {
22+
AzureEmbeddingModel model = client.post(new AzureEmbeddingModel(Arrays.asList(0, 1, 2, 3, 4)));
23+
Assertions.assertIterableEquals(Arrays.asList(5, 6, 7, 8, 9), model.getEmbedding());
24+
}
25+
26+
@Test
27+
public void put() {
28+
client.put(Arrays.asList(0, 1, 2, 3, 4));
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.resourcemanager.models.commontypes.managedidentity;
5+
6+
import com.azure.core.management.Region;
7+
import com.azure.resourcemanager.models.commontypes.managedidentity.models.ManagedIdentityTrackedResource;
8+
import com.azure.resourcemanager.models.commontypes.managedidentity.models.ManagedIdentityTrackedResourceProperties;
9+
import com.azure.resourcemanager.models.commontypes.managedidentity.models.ManagedServiceIdentity;
10+
import com.azure.resourcemanager.models.commontypes.managedidentity.models.ManagedServiceIdentityType;
11+
import com.azure.resourcemanager.models.commontypes.managedidentity.models.UserAssignedIdentity;
12+
import org.junit.jupiter.api.Assertions;
13+
import org.junit.jupiter.api.Test;
14+
import org.utils.ArmUtils;
15+
16+
import java.util.HashMap;
17+
import java.util.Map;
18+
19+
public class ManagedIdentityManagerTests {
20+
private static final String USER_ASSIGNED_IDENTITIES_KEY = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1";
21+
private final ManagedIdentityManager manager = ManagedIdentityManager.authenticate(
22+
ArmUtils.createTestHttpPipeline(),
23+
ArmUtils.getAzureProfile());
24+
25+
@Test
26+
public void testManagedIdentityManager() {
27+
Map<String, String> tagsMap = new HashMap<>();
28+
tagsMap.put("tagKey1", "tagValue1");
29+
ManagedIdentityTrackedResource resource = manager.managedIdentityTrackedResources()
30+
.define("identity")
31+
.withRegion(Region.US_EAST)
32+
.withExistingResourceGroup("test-rg")
33+
.withProperties(new ManagedIdentityTrackedResourceProperties())
34+
.withIdentity(new ManagedServiceIdentity().withType(ManagedServiceIdentityType.SYSTEM_ASSIGNED))
35+
.withTags(tagsMap)
36+
.create();
37+
Assertions.assertEquals(ManagedServiceIdentityType.SYSTEM_ASSIGNED, resource.identity().type());
38+
Assertions.assertNotNull(resource.identity().principalId());
39+
Assertions.assertNotNull(resource.identity().tenantId());
40+
41+
resource = manager.managedIdentityTrackedResources().getById(resource.id());
42+
Assertions.assertEquals(ManagedServiceIdentityType.SYSTEM_ASSIGNED, resource.identity().type());
43+
Assertions.assertNotNull(resource.identity().principalId());
44+
Assertions.assertNotNull(resource.identity().tenantId());
45+
46+
Map<String, UserAssignedIdentity> userAssignedIdentityMap = new HashMap<>();
47+
userAssignedIdentityMap.put(USER_ASSIGNED_IDENTITIES_KEY, new UserAssignedIdentity());
48+
resource.update().withIdentity(new ManagedServiceIdentity()
49+
.withType(ManagedServiceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED)
50+
.withUserAssignedIdentities(userAssignedIdentityMap))
51+
.apply();
52+
Assertions.assertEquals(ManagedServiceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED, resource.identity().type());
53+
Assertions.assertNotNull(resource.identity().principalId());
54+
Assertions.assertNotNull(resource.identity().tenantId());
55+
Assertions.assertNotNull(resource.identity().userAssignedIdentities());
56+
Assertions.assertEquals(1, resource.identity().userAssignedIdentities().size());
57+
UserAssignedIdentity userAssignedIdentity = resource.identity()
58+
.userAssignedIdentities().get(USER_ASSIGNED_IDENTITIES_KEY);
59+
Assertions.assertNotNull(userAssignedIdentity.principalId());
60+
Assertions.assertNotNull(userAssignedIdentity.clientId());
61+
62+
}
63+
}

typespec-tests/src/test/java/com/type/model/visibility/AutomaticClientTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
package com.type.model.visibility;
55

6+
import com.type.model.visibility.models.ReadOnlyModel;
67
import com.type.model.visibility.models.VisibilityModel;
8+
import org.junit.jupiter.api.Assertions;
79
import org.junit.jupiter.api.Test;
810

911
import java.util.Arrays;
@@ -48,4 +50,12 @@ void deleteModel() {
4850
// client.deleteModelWithResponse(BinaryData.fromString("{\"deleteProp\": true}"), null);
4951
client.deleteModel(new VisibilityModel(null, null, null, true));
5052
}
53+
54+
@Test
55+
void putReadOnlyModel() {
56+
ReadOnlyModel readOnlyModel = client.putReadOnlyModel(new ReadOnlyModel());
57+
Assertions.assertIterableEquals(Arrays.asList(1, 2, 3), readOnlyModel.getOptionalNullableIntList());
58+
Assertions.assertEquals("value1", readOnlyModel.getOptionalStringRecord().get("k1"));
59+
Assertions.assertEquals("value2", readOnlyModel.getOptionalStringRecord().get("k2"));
60+
}
5161
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.type.property.optional;
5+
6+
import com.type.property.optional.models.PlaindateProperty;
7+
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.Test;
9+
10+
import java.time.LocalDate;
11+
12+
public class PlaindateClientTests {
13+
private final PlaindateClient client = new OptionalClientBuilder().buildPlaindateClient();
14+
15+
@Test
16+
public void getAll() {
17+
PlaindateProperty plaindateProperty = client.getAll();
18+
Assertions.assertEquals(LocalDate.parse("2022-12-12"), plaindateProperty.getProperty());
19+
}
20+
21+
@Test
22+
public void getDefault() {
23+
PlaindateProperty plaindateProperty = client.getDefault();
24+
Assertions.assertNull(plaindateProperty.getProperty());
25+
}
26+
27+
@Test
28+
public void putAll() {
29+
client.putAll(new PlaindateProperty().setProperty(LocalDate.parse("2022-12-12")));
30+
}
31+
32+
@Test
33+
public void putDefault() {
34+
client.putDefault(new PlaindateProperty());
35+
}
36+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.type.property.optional;
5+
6+
import com.type.property.optional.models.PlainTimeProperty;
7+
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.Test;
9+
10+
public class PlaintimeClientTests {
11+
private final PlaintimeClient client = new OptionalClientBuilder().buildPlaintimeClient();
12+
13+
@Test
14+
public void getAll() {
15+
Assertions.assertEquals("13:06:12", client.getAll().getProperty());
16+
}
17+
18+
@Test
19+
public void getDefault() {
20+
Assertions.assertNull(client.getDefault().getProperty());
21+
}
22+
23+
@Test
24+
public void putAll() {
25+
client.putAll(new PlainTimeProperty().setProperty("13:06:12"));
26+
}
27+
28+
@Test
29+
public void putDefault() {
30+
client.putDefault(new PlainTimeProperty());
31+
}
32+
}

0 commit comments

Comments
 (0)