@@ -57,9 +57,7 @@ void shouldExecuteInitScript() {
5757 void shouldExecuteInitScriptWithEdgeCases () {
5858 try (
5959 MongoDBContainer mongoDB = new MongoDBContainer ("mongo:4.0.10" )
60- .withInitScript ("initEdgeCase.js" )
61- .withEnv ("LANG" , "C.UTF-8" )
62- .withEnv ("LC_ALL" , "C.UTF-8" )
60+ .withInitScript ("initEdgeCase!@#%^& *'().js" )
6361 .withStartupTimeout (Duration .ofSeconds (30 ))
6462 ) {
6563 mongoDB .start ();
@@ -70,31 +68,27 @@ void shouldExecuteInitScriptWithEdgeCases() {
7068 )
7169 ) {
7270 String expectedComplexName = "test_col_\" _with_specials_!@#%^&*()" ;
73- String expectedJapaneseName = "日本語 コレクション テスト " ;
71+ String expectedCollectionWithSpecialChars = "col with spaces & symbols !@# " ;
7472
7573 com .mongodb .client .MongoDatabase database = client .getDatabase ("test" );
7674
77- assertThat (database .listCollectionNames ()).contains (expectedComplexName , expectedJapaneseName );
75+ assertThat (database .listCollectionNames ())
76+ .contains (expectedComplexName , expectedCollectionWithSpecialChars );
7877
7978 com .mongodb .client .MongoCollection <org .bson .Document > collection = database .getCollection (
8079 expectedComplexName
8180 );
8281
8382 org .bson .Document doc = collection .find (new org .bson .Document ("_id" , 1 )).first ();
8483
85- assertThat (doc ).as ( "Document with _id=1 should exist" ). isNotNull ();
84+ assertThat (doc ).isNotNull ();
8685
87- assertThat (doc .getString ("key_with_quotes" ))
88- .as ("Double quotes should be preserved correctly" )
89- .isEqualTo ("This is a \" double quoted\" string" );
86+ assertThat (doc .getString ("key_with_quotes" )).isEqualTo ("This is a \" double quoted\" string" );
9087
91- assertThat (doc .getString ("key_with_json_chars" ))
92- .as ("JSON special chars should be treated as plain text" )
93- .isEqualTo ("{ } [ ] : ," );
88+ assertThat (doc .getString ("key_with_json_chars" )).isEqualTo ("{ } [ ] : ," );
9489
9590 assertThat (doc .getString ("description" ))
96- .as ("Japanese text should be preserved correctly" )
97- .isEqualTo ("特殊記号を含むコレクションへの挿入テスト" );
91+ .isEqualTo ("Insertion test for collection with special symbols" );
9892 }
9993 }
10094 }
@@ -107,14 +101,6 @@ void shouldExecuteInitScriptWithReplicaSet() {
107101 }
108102 }
109103
110- @ Test
111- void shouldExecuteInitScriptWithReplicaSetConfiguredFirst () {
112- try (MongoDBContainer mongo = new MongoDBContainer ("mongo:7.0.0" ).withReplicaSet ().withInitScript ("init.js" )) {
113- mongo .start ();
114- assertInitScriptExecuted (mongo );
115- }
116- }
117-
118104 @ Test
119105 void shouldExecuteInitScriptWithSharding () {
120106 try (MongoDBContainer mongo = new MongoDBContainer ("mongo:7.0.0" ).withInitScript ("init.js" ).withSharding ()) {
@@ -123,19 +109,9 @@ void shouldExecuteInitScriptWithSharding() {
123109 }
124110 }
125111
126- @ Test
127- void shouldExecuteInitScriptWithShardingConfiguredFirst () {
128- try (MongoDBContainer mongo = new MongoDBContainer ("mongo:7.0.0" ).withSharding ().withInitScript ("init.js" )) {
129- mongo .start ();
130- assertInitScriptExecuted (mongo );
131- }
132- }
133-
134112 private void assertInitScriptExecuted (MongoDBContainer mongo ) {
135113 try (com .mongodb .client .MongoClient client = com .mongodb .client .MongoClients .create (mongo .getReplicaSetUrl ())) {
136- assertThat (client .getDatabase ("test" ).listCollectionNames ())
137- .as ("Check if init.js created the collection" )
138- .contains ("test_collection" );
114+ assertThat (client .getDatabase ("test" ).listCollectionNames ()).contains ("test_collection" );
139115 }
140116 }
141117}
0 commit comments