37
37
import com .azure .identity .ChainedTokenCredentialBuilder ;
38
38
import com .azure .identity .DefaultAzureCredentialBuilder ;
39
39
import com .azure .identity .EnvironmentCredentialBuilder ;
40
- import com .azure .json .JsonProviders ;
41
40
import com .azure .json .JsonSerializable ;
42
41
import com .azure .json .JsonWriter ;
43
42
import com .azure .storage .blob .models .BlobContainerItem ;
68
67
import reactor .core .publisher .Mono ;
69
68
import reactor .test .StepVerifier ;
70
69
71
- import java .io .ByteArrayOutputStream ;
72
70
import java .io .File ;
73
71
import java .io .IOException ;
74
72
import java .io .InputStream ;
@@ -165,6 +163,10 @@ public class BlobTestBase extends TestProxyTestBase {
165
163
166
164
protected String prefix ;
167
165
166
+ // used to support cross package tests without taking a dependency on the package
167
+ protected HttpPipeline dataPlanePipeline ;
168
+ protected HttpHeaders genericHeaders ;
169
+
168
170
// used to build pipeline to management plane
169
171
protected static final String RESOURCE_GROUP_NAME = ENVIRONMENT .getResourceGroupName ();
170
172
protected static final String SUBSCRIPTION_ID = ENVIRONMENT .getSubscriptionId ();
@@ -875,22 +877,15 @@ protected Mono<?> setAccessPolicySleepAsync(BlobContainerAsyncClient cc, PublicA
875
877
return setPolicyMono ;
876
878
}
877
879
878
- protected String generateShareName () {
879
- return generateResourceName (entityNo ++);
880
- }
881
-
882
880
protected String createFileAndDirectoryWithoutFileShareDependency (byte [] data , String shareName )
883
881
throws IOException {
884
882
String accountName = ENVIRONMENT .getPrimaryAccount ().getName ();
885
883
//authenticate
886
884
BearerTokenAuthenticationPolicy credentialPolicyDataPlane = new BearerTokenAuthenticationPolicy (
887
885
getTokenCredential (ENVIRONMENT .getTestMode ()), Constants .STORAGE_SCOPE );
888
886
889
- //create share through management plane
890
- createFileShareWithoutDependency (shareName );
891
-
892
887
//setup headers that will be used in every request
893
- HttpHeaders genericHeaders = new HttpHeaders ().set (X_MS_VERSION , "2025-07-05" )
888
+ genericHeaders = new HttpHeaders ().set (X_MS_VERSION , "2025-07-05" )
894
889
.set (HttpHeaderName .ACCEPT , "application/xml" )
895
890
.set (HttpHeaderName .HOST , accountName + ".file.core.windows.net" )
896
891
.set (HttpHeaderName .CONTENT_LENGTH , "0" )
@@ -904,8 +899,15 @@ protected String createFileAndDirectoryWithoutFileShareDependency(byte[] data, S
904
899
policies .add (new RequestIdPolicy ());
905
900
906
901
// create data plane pipeline
907
- HttpPipeline dataPlanePipeline
908
- = new HttpPipelineBuilder ().policies (policies .toArray (new HttpPipelinePolicy [0 ])).build ();
902
+ dataPlanePipeline = new HttpPipelineBuilder ().policies (policies .toArray (new HttpPipelinePolicy [0 ])).build ();
903
+
904
+ // create share through data plane pipeline
905
+ String shareUrl = String .format ("https://%s.file.core.windows.net/%s?restype=share" , accountName , shareName );
906
+
907
+ HttpResponse shareCreateResponse
908
+ = dataPlanePipeline .send (new HttpRequest (HttpMethod .PUT , new URL (shareUrl ), genericHeaders )).block ();
909
+ assertNotNull (shareCreateResponse );
910
+ assertEquals (201 , shareCreateResponse .getStatusCode ());
909
911
910
912
// create directory
911
913
String directoryName = generateBlobName ();
@@ -945,48 +947,14 @@ protected String createFileAndDirectoryWithoutFileShareDependency(byte[] data, S
945
947
return fileUrl ;
946
948
}
947
949
948
- protected void createFileShareWithoutDependency (String shareName ) throws IOException {
949
- String shareID = getFileShareID (shareName );
950
- Body shareBody = new Body ();
951
- shareBody .setId (shareID );
952
- shareBody .setName (shareName );
953
- shareBody .setType ("Microsoft.Storage/storageAccounts/fileServices/shares" );
954
-
955
- ByteArrayOutputStream shareJson = new ByteArrayOutputStream ();
956
- try (JsonWriter jsonWriter = JsonProviders .createWriter (shareJson )) {
957
- shareBody .toJson (jsonWriter );
958
- }
959
- HttpResponse response
960
- = getManagementPlanePipeline ().send (new HttpRequest (HttpMethod .PUT , new URL (getFileShareUri (shareID )),
961
- new HttpHeaders (), Flux .just (ByteBuffer .wrap (shareJson .toByteArray ())))).block ();
962
- assertNotNull (response );
963
- assertEquals (201 , response .getStatusCode ());
964
- }
965
-
966
950
protected void deleteFileShareWithoutDependency (String shareName ) throws IOException {
967
- String shareID = getFileShareID (shareName );
968
- HttpResponse response = getManagementPlanePipeline ()
969
- .send (new HttpRequest (HttpMethod .DELETE , new URL (getFileShareUri (shareID )), new HttpHeaders ()))
970
- .block ();
971
- assertNotNull (response );
972
- assertEquals (200 , response .getStatusCode ());
973
- }
974
-
975
- protected HttpPipeline getManagementPlanePipeline () {
976
- BearerTokenAuthenticationPolicy credentialPolicyManagementPlane = new BearerTokenAuthenticationPolicy (
977
- getTokenCredential (ENVIRONMENT .getTestMode ()), "https://management.azure.com/.default" );
978
- return new HttpPipelineBuilder ().policies (credentialPolicyManagementPlane ).build ();
979
- }
951
+ String shareUrl = String .format ("https://%s.file.core.windows.net/%s?restype=share" ,
952
+ ENVIRONMENT .getPrimaryAccount ().getName (), shareName );
980
953
981
- protected String getFileShareID (String shareName ) {
982
- return String .format (
983
- "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Storage/storageAccounts/"
984
- + "%s/fileServices/default/shares/%s" ,
985
- SUBSCRIPTION_ID , RESOURCE_GROUP_NAME , ENVIRONMENT .getPrimaryAccount ().getName (), shareName );
986
- }
987
-
988
- protected String getFileShareUri (String fileShareID ) {
989
- return "https://management.azure.com" + fileShareID + "?api-version=2024-01-01" ;
954
+ HttpResponse shareDeleteResponse
955
+ = dataPlanePipeline .send (new HttpRequest (HttpMethod .DELETE , new URL (shareUrl ), genericHeaders )).block ();
956
+ assertNotNull (shareDeleteResponse );
957
+ assertEquals (202 , shareDeleteResponse .getStatusCode ());
990
958
}
991
959
992
960
public static final class Body implements JsonSerializable <Body > {
@@ -1058,10 +1026,6 @@ public static final class ImmutableStorageWithVersioning
1058
1026
implements JsonSerializable <ImmutableStorageWithVersioning > {
1059
1027
private boolean enabled ;
1060
1028
1061
- public boolean isEnabled () {
1062
- return enabled ;
1063
- }
1064
-
1065
1029
public void setEnabled (boolean enabled ) {
1066
1030
this .enabled = enabled ;
1067
1031
}
@@ -1073,7 +1037,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
1073
1037
}
1074
1038
}
1075
1039
1076
- //todo: change the copy of this method in StorageCommonTestUtils to take in TestMode instead of interception manager
1040
+ //todo isbr : change the copy of this method in StorageCommonTestUtils to take in TestMode instead of interception manager
1077
1041
protected static TokenCredential getTokenCredential (TestMode testMode ) {
1078
1042
if (testMode == TestMode .RECORD ) {
1079
1043
return new DefaultAzureCredentialBuilder ().build ();
0 commit comments