70
70
import static org .apache .hadoop .fs .s3a .test .PublicDatasetTestUtils .getExternalData ;
71
71
import static org .apache .hadoop .test .LambdaTestUtils .intercept ;
72
72
import static org .apache .hadoop .test .LambdaTestUtils .interceptFuture ;
73
+ import static org .apache .hadoop .util .StringUtils .STRING_COLLECTION_SPLIT_EQUALS_INVALID_ARG ;
73
74
74
75
/**
75
76
* Unit tests for {@link Constants#AWS_CREDENTIALS_PROVIDER} logic.
@@ -722,8 +723,8 @@ public void testV2ClassNotFound() throws Throwable {
722
723
* Tests for the string utility that will be used by S3A credentials provider.
723
724
*/
724
725
@ Test
725
- public void testStringCollectionSplitByEquals () {
726
- final Configuration configuration = new Configuration ();
726
+ public void testStringCollectionSplitByEqualsSuccess () {
727
+ final Configuration configuration = new Configuration (false );
727
728
configuration .set ("custom_key" , "" );
728
729
Map <String , String > splitMap =
729
730
S3AUtils .getTrimmedStringCollectionSplitByEquals (
@@ -775,8 +776,7 @@ public void testStringCollectionSplitByEquals() {
775
776
+ "element.abc.val5 ,\n \n \n "
776
777
+ " element.xyz.key6 = element.abc.val6 \n , \n "
777
778
+ "element.xyz.key7=element.abc.val7,\n " );
778
- splitMap = S3AUtils .getTrimmedStringCollectionSplitByEquals (
779
- configuration , "custom_key" );
779
+ splitMap = S3AUtils .getTrimmedStringCollectionSplitByEquals (configuration , "custom_key" );
780
780
781
781
Assertions
782
782
.assertThat (splitMap )
@@ -790,6 +790,75 @@ public void testStringCollectionSplitByEquals() {
790
790
.containsEntry ("element.xyz.key5" , "element.abc.val5" )
791
791
.containsEntry ("element.xyz.key6" , "element.abc.val6" )
792
792
.containsEntry ("element.xyz.key7" , "element.abc.val7" );
793
+
794
+ configuration .set ("custom_key" ,
795
+ "element.first.key1 = element.first.val2 ,element.first.key1 =element.first.val1" );
796
+ splitMap =
797
+ S3AUtils .getTrimmedStringCollectionSplitByEquals (
798
+ configuration , "custom_key" );
799
+ Assertions
800
+ .assertThat (splitMap )
801
+ .describedAs ("Map of key value pairs split by equals(=) and comma(,)" )
802
+ .hasSize (1 )
803
+ .containsEntry ("element.first.key1" , "element.first.val1" );
804
+
805
+ configuration .set ("custom_key" ,
806
+ ",,, , ,, ,element.first.key1 = element.first.val2 ,"
807
+ + "element.first.key1 = element.first.val1 , ,,, ," );
808
+ splitMap = S3AUtils .getTrimmedStringCollectionSplitByEquals (
809
+ configuration , "custom_key" );
810
+ Assertions
811
+ .assertThat (splitMap )
812
+ .describedAs ("Map of key value pairs split by equals(=) and comma(,)" )
813
+ .hasSize (1 )
814
+ .containsEntry ("element.first.key1" , "element.first.val1" );
815
+
816
+ configuration .set ("custom_key" , ",, , , ,, ," );
817
+ splitMap = S3AUtils .getTrimmedStringCollectionSplitByEquals (
818
+ configuration , "custom_key" );
819
+ Assertions
820
+ .assertThat (splitMap )
821
+ .describedAs ("Map of key value pairs split by equals(=) and comma(,)" )
822
+ .hasSize (0 );
823
+ }
824
+
825
+ /**
826
+ * Validates that the argument provided is invalid by intercepting the expected
827
+ * Exception.
828
+ *
829
+ * @param propKey The property key to validate.
830
+ * @throws Exception If any error occurs.
831
+ */
832
+ private static void expectInvalidArgument (final String propKey ) throws Exception {
833
+ final Configuration configuration = new Configuration (false );
834
+ configuration .set ("custom_key" , propKey );
835
+
836
+ intercept (
837
+ IllegalArgumentException .class ,
838
+ STRING_COLLECTION_SPLIT_EQUALS_INVALID_ARG ,
839
+ () -> S3AUtils .getTrimmedStringCollectionSplitByEquals (
840
+ configuration , "custom_key" ));
841
+ }
842
+
843
+ /**
844
+ * Tests for the string utility that will be used by S3A credentials provider.
845
+ */
846
+ @ Test
847
+ public void testStringCollectionSplitByEqualsFailure () throws Exception {
848
+ expectInvalidArgument (" = element.abc.val1" );
849
+ expectInvalidArgument ("=element.abc.val1" );
850
+ expectInvalidArgument ("= element.abc.val1" );
851
+ expectInvalidArgument (" =element.abc.val1" );
852
+ expectInvalidArgument ("element.abc.key1=" );
853
+ expectInvalidArgument ("element.abc.key1= " );
854
+ expectInvalidArgument ("element.abc.key1 =" );
855
+ expectInvalidArgument ("element.abc.key1 = " );
856
+ expectInvalidArgument ("=" );
857
+ expectInvalidArgument (" =" );
858
+ expectInvalidArgument ("= " );
859
+ expectInvalidArgument (" = " );
860
+ expectInvalidArgument ("== = = =" );
861
+ expectInvalidArgument (", = " );
793
862
}
794
863
795
864
/**
0 commit comments