2323import com .microsoft .azure .storage .TestRunners .CloudTests ;
2424import com .microsoft .azure .storage .TestRunners .DevFabricTests ;
2525import com .microsoft .azure .storage .TestRunners .DevStoreTests ;
26- import com .microsoft .azure .storage .TestRunners .SlowTests ;
2726
2827import org .junit .Test ;
2928import org .junit .experimental .categories .Category ;
@@ -49,6 +48,7 @@ public void testAnalyticsDisable() throws StorageException, InterruptedException
4948 ServiceClient client = TestHelper .createCloudBlobClient ();
5049 ServiceProperties props = new ServiceProperties ();
5150 props .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
51+ props .setStaticWebsiteProperties (new StaticWebsiteProperties ());
5252 props .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
5353 testAnalyticsDisable (client , props );
5454
@@ -93,6 +93,7 @@ public void testAnalyticsDefaultServiceVersion() throws StorageException, Interr
9393 ServiceClient client = TestHelper .createCloudBlobClient ();
9494 ServiceProperties props = new ServiceProperties ();
9595 props .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
96+ props .setStaticWebsiteProperties (new StaticWebsiteProperties ());
9697 props .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
9798 testAnalyticsDefaultServiceVersion (client , props );
9899
@@ -154,6 +155,7 @@ public void testAnalyticsLoggingOperations() throws StorageException, Interrupte
154155 ServiceClient client = TestHelper .createCloudBlobClient ();
155156 ServiceProperties props = new ServiceProperties ();
156157 props .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
158+ props .setStaticWebsiteProperties (new StaticWebsiteProperties ());
157159 props .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
158160 testAnalyticsLoggingOperations (client , props );
159161
@@ -196,6 +198,7 @@ public void testAnalyticsHourMetricsLevel() throws StorageException, Interrupted
196198 ServiceProperties props = new ServiceProperties ();
197199 props .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
198200 props .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
201+ props .setStaticWebsiteProperties (new StaticWebsiteProperties ());
199202 testAnalyticsHourMetricsLevel (client , props , null );
200203
201204 client = TestHelper .createCloudQueueClient ();
@@ -264,6 +267,7 @@ public void testAnalyticsMinuteMetricsLevel() throws StorageException, Interrupt
264267 ServiceClient client = TestHelper .createCloudBlobClient ();
265268 ServiceProperties props = new ServiceProperties ();
266269 props .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
270+ props .setStaticWebsiteProperties (new StaticWebsiteProperties ());
267271 props .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
268272 testAnalyticsMinuteMetricsLevel (client , props , null );
269273
@@ -333,6 +337,7 @@ public void testAnalyticsRetentionPolicies() throws StorageException, Interrupte
333337 ServiceClient client = TestHelper .createCloudBlobClient ();
334338 ServiceProperties props = new ServiceProperties ();
335339 props .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
340+ props .setStaticWebsiteProperties (new StaticWebsiteProperties ());
336341 props .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
337342 testAnalyticsRetentionPolicies (client , props );
338343
@@ -434,6 +439,7 @@ private void testValidDeleteRetentionPolicy(ServiceClient client, boolean enable
434439 ServiceProperties expectedServiceProperties = new ServiceProperties ();
435440 expectedServiceProperties .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
436441 expectedServiceProperties .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
442+ expectedServiceProperties .setStaticWebsiteProperties (new StaticWebsiteProperties ());
437443
438444 if (enabled ) {
439445 expectedServiceProperties .getDeleteRetentionPolicy ().setEnabled (true );
@@ -532,6 +538,7 @@ public void testEmptyDeleteRetentionPolicy() throws StorageException, Interrupte
532538 ServiceProperties currentServiceProperties = new ServiceProperties ();
533539 currentServiceProperties .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
534540 currentServiceProperties .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
541+ currentServiceProperties .setStaticWebsiteProperties (new StaticWebsiteProperties ());
535542 currentServiceProperties .getDeleteRetentionPolicy ().setEnabled (true );
536543 currentServiceProperties .getDeleteRetentionPolicy ().setRetentionIntervalInDays (5 );
537544 callUploadServiceProps (client , currentServiceProperties , null );
@@ -554,6 +561,79 @@ public void testEmptyDeleteRetentionPolicy() throws StorageException, Interrupte
554561 }
555562 }
556563
564+ @ Test
565+ public void testValidStaticWebsiteProperties () throws StorageException , InterruptedException {
566+ ServiceClient client = TestHelper .createCloudBlobClient ();
567+ // average setting
568+ testValidStaticWebsiteProperties (client , true , "index.html" , "errors/error/404error.html" );
569+
570+ // disabled setting
571+ testValidStaticWebsiteProperties (client , false , "index.html" , "errors/error/404error.html" );
572+ }
573+
574+ private void testValidStaticWebsiteProperties (ServiceClient client , boolean enabled , String index , String pathTo404 ) throws InterruptedException , StorageException {
575+ try {
576+ ServiceProperties expectedServiceProperties = new ServiceProperties ();
577+ expectedServiceProperties .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
578+ expectedServiceProperties .setStaticWebsiteProperties (new StaticWebsiteProperties ());
579+ expectedServiceProperties .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
580+
581+ if (enabled ) {
582+ expectedServiceProperties .getStaticWebsiteProperties ().setEnabled (true );
583+ expectedServiceProperties .getStaticWebsiteProperties ().setIndexDocument (index );
584+ expectedServiceProperties .getStaticWebsiteProperties ().setErrorDocument404Path (pathTo404 );
585+ callUploadServiceProps (client , expectedServiceProperties , null );
586+ } else {
587+ // index document and error document path will be ignored by the service when the properties are not enabled.
588+ ServiceProperties propertiesToUpload = new ServiceProperties ();
589+ propertiesToUpload .setStaticWebsiteProperties (new StaticWebsiteProperties ());
590+ propertiesToUpload .getStaticWebsiteProperties ().setIndexDocument (index );
591+ propertiesToUpload .getStaticWebsiteProperties ().setErrorDocument404Path (pathTo404 );
592+
593+ expectedServiceProperties .getStaticWebsiteProperties ().setEnabled (false );
594+ callUploadServiceProps (client , propertiesToUpload , null );
595+ }
596+
597+ // verify
598+ assertServicePropertiesAreEqual (expectedServiceProperties , callDownloadServiceProperties (client ));
599+ }
600+ finally {
601+ // disable the static websites
602+ ServiceProperties disabledStaticWebsiteProperties = new ServiceProperties ();
603+ disabledStaticWebsiteProperties .setStaticWebsiteProperties (new StaticWebsiteProperties ());
604+ callUploadServiceProps (client , disabledStaticWebsiteProperties , null );
605+ }
606+ }
607+
608+ @ Test
609+ public void testEmptyStaticWebsiteProperties () throws StorageException , InterruptedException {
610+ ServiceClient client = TestHelper .createCloudBlobClient ();
611+
612+ // set up initial static website properties
613+ ServiceProperties currentServiceProperties = new ServiceProperties ();
614+ StaticWebsiteProperties properties = new StaticWebsiteProperties ();
615+ properties .setEnabled (true );
616+ properties .setIndexDocument ("index.html" );
617+ properties .setErrorDocument404Path ("path/to/404" );
618+ currentServiceProperties .setStaticWebsiteProperties (properties );
619+ currentServiceProperties .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
620+ currentServiceProperties .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
621+ callUploadServiceProps (client , currentServiceProperties , null );
622+
623+ // verify
624+ assertServicePropertiesAreEqual (currentServiceProperties , callDownloadServiceProperties (client ));
625+
626+ // try to upload empty properties
627+ ServiceProperties emptyServiceProperties = new ServiceProperties ();
628+ emptyServiceProperties .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
629+ emptyServiceProperties .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
630+ emptyServiceProperties .setStaticWebsiteProperties (new StaticWebsiteProperties ());
631+ callUploadServiceProps (client , emptyServiceProperties , null );
632+
633+ // verify
634+ assertServicePropertiesAreEqual (emptyServiceProperties , callDownloadServiceProperties (client ));
635+ }
636+
557637 /**
558638 * Test CORS with different rules.
559639 *
@@ -565,6 +645,7 @@ public void testCloudValidCorsRules() throws StorageException, InterruptedExcept
565645 ServiceClient client = TestHelper .createCloudBlobClient ();
566646 ServiceProperties props = new ServiceProperties ();
567647 props .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
648+ props .setStaticWebsiteProperties (new StaticWebsiteProperties ());
568649 props .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
569650 testCloudValidCorsRules (client , props , null );
570651
@@ -689,6 +770,7 @@ public void testCorsExpectedExceptions() throws StorageException {
689770 ServiceClient client = TestHelper .createCloudBlobClient ();
690771 ServiceProperties props = new ServiceProperties ();
691772 props .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
773+ props .setStaticWebsiteProperties (new StaticWebsiteProperties ());
692774 props .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
693775 testCorsExpectedExceptions (client , props , null );
694776
@@ -753,6 +835,7 @@ public void testCorsMaxOrigins() throws StorageException, InterruptedException {
753835 ServiceClient client = TestHelper .createCloudBlobClient ();
754836 ServiceProperties props = new ServiceProperties ();
755837 props .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
838+ props .setStaticWebsiteProperties (new StaticWebsiteProperties ());
756839 props .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
757840 testCorsMaxOrigins (client , props , null );
758841
@@ -805,6 +888,7 @@ public void testCorsMaxHeaders() throws StorageException, InterruptedException {
805888 ServiceClient client = TestHelper .createCloudBlobClient ();
806889 ServiceProperties props = new ServiceProperties ();
807890 props .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
891+ props .setStaticWebsiteProperties (new StaticWebsiteProperties ());
808892 props .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
809893 testCorsMaxHeaders (client , props , null );
810894
@@ -909,6 +993,7 @@ public void testOptionalServiceProperties() throws StorageException, Interrupted
909993 ServiceClient client = TestHelper .createCloudBlobClient ();
910994 ServiceProperties props = new ServiceProperties ();
911995 props .setDeleteRetentionPolicy (new DeleteRetentionPolicy ());
996+ props .setStaticWebsiteProperties (new StaticWebsiteProperties ());
912997 props .setDefaultServiceVersion (Constants .HeaderConstants .TARGET_STORAGE_VERSION );
913998 testOptionalServiceProperties (client , props );
914999
@@ -991,7 +1076,7 @@ else if (client.getClass().equals(CloudFileClient.class)) {
9911076 else {
9921077 fail ();
9931078 }
994-
1079+
9951080 // It may take up to 30 seconds for the settings to take effect, but the new properties are immediately
9961081 // visible when querying service properties.
9971082 }
@@ -1144,6 +1229,16 @@ private static void assertServicePropertiesAreEqual(ServiceProperties propsA, Se
11441229 assertNull (propsA .getDeleteRetentionPolicy ());
11451230 assertNull (propsB .getDeleteRetentionPolicy ());
11461231 }
1232+
1233+ if (propsA .getStaticWebsiteProperties () != null && propsB .getStaticWebsiteProperties () != null ) {
1234+ assertEquals (propsA .getStaticWebsiteProperties ().getEnabled (), propsB .getStaticWebsiteProperties ().getEnabled ());
1235+ assertEquals (propsA .getStaticWebsiteProperties ().getIndexDocument (), propsB .getStaticWebsiteProperties ().getIndexDocument ());
1236+ assertEquals (propsA .getStaticWebsiteProperties ().getErrorDocument404Path (), propsB .getStaticWebsiteProperties ().getErrorDocument404Path ());
1237+ }
1238+ else {
1239+ assertNull (propsA .getStaticWebsiteProperties ());
1240+ assertNull (propsB .getStaticWebsiteProperties ());
1241+ }
11471242 }
11481243
11491244 /**
0 commit comments