@@ -84,8 +84,8 @@ public class MicrocksContainer extends GenericContainer<MicrocksContainer> {
8484 private Set <String > snapshotsToImport ;
8585 private Set <String > mainArtifactsToImport ;
8686 private Set <String > secondaryArtifactsToImport ;
87- private Set <String > mainRemoteArtifactsToImport ;
88- private Set <String > secondaryRemoteArtifactsToImport ;
87+ private Set <RemoteArtifact > mainRemoteArtifactsToImport ;
88+ private Set <RemoteArtifact > secondaryRemoteArtifactsToImport ;
8989 private Set <Secret > secrets ;
9090
9191 /**
@@ -149,7 +149,22 @@ public MicrocksContainer withMainRemoteArtifacts(String... remoteArtifactUrls) {
149149 if (mainRemoteArtifactsToImport == null ) {
150150 mainRemoteArtifactsToImport = new HashSet <>();
151151 }
152- mainRemoteArtifactsToImport .addAll (Arrays .stream (remoteArtifactUrls ).collect (Collectors .toList ()));
152+ mainRemoteArtifactsToImport .addAll (Arrays .stream (remoteArtifactUrls )
153+ .map (url -> RemoteArtifact .of (url , null )).collect (Collectors .toSet ()));
154+ return self ();
155+ }
156+
157+ /**
158+ * Provide remote artifacts (with secret name) that will be imported as primary or main ones within the Microcks
159+ * container once it will be started and healthy.
160+ * @param remoteArtifacts A set of remote artifacts that will be loaded
161+ * @return self
162+ */
163+ public MicrocksContainer withMainRemoteArtifacts (RemoteArtifact ... remoteArtifacts ) {
164+ if (mainRemoteArtifactsToImport == null ) {
165+ mainRemoteArtifactsToImport = new HashSet <>();
166+ }
167+ mainRemoteArtifactsToImport .addAll (Arrays .stream (remoteArtifacts ).collect (Collectors .toSet ()));
153168 return self ();
154169 }
155170
@@ -163,7 +178,22 @@ public MicrocksContainer withSecondaryRemoteArtifacts(String... remoteArtifactUr
163178 if (secondaryRemoteArtifactsToImport == null ) {
164179 secondaryRemoteArtifactsToImport = new HashSet <>();
165180 }
166- secondaryRemoteArtifactsToImport .addAll (Arrays .stream (remoteArtifactUrls ).collect (Collectors .toList ()));
181+ secondaryRemoteArtifactsToImport .addAll (Arrays .stream (remoteArtifactUrls )
182+ .map (url -> RemoteArtifact .of (url , null )).collect (Collectors .toSet ()));
183+ return self ();
184+ }
185+
186+ /**
187+ * Provide remote artifacts (with secret name) that will be imported as secondary ones within the Microcks
188+ * container once it will be started and healthy.
189+ * @param remoteArtifacts A set of remote artifacts that will be loaded
190+ * @return self
191+ */
192+ public MicrocksContainer withSecondaryRemoteArtifacts (RemoteArtifact ... remoteArtifacts ) {
193+ if (secondaryRemoteArtifactsToImport == null ) {
194+ secondaryRemoteArtifactsToImport = new HashSet <>();
195+ }
196+ secondaryRemoteArtifactsToImport .addAll (Arrays .stream (remoteArtifacts ).collect (Collectors .toSet ()));
167197 return self ();
168198 }
169199
@@ -200,12 +230,16 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) {
200230 if (snapshotsToImport != null && !snapshotsToImport .isEmpty ()) {
201231 snapshotsToImport .forEach (this ::importSnapshot );
202232 }
233+ // Load secrets before remote artifacts as they may be needed for authentication.
234+ if (secrets != null && !secrets .isEmpty ()) {
235+ secrets .forEach (this ::createSecret );
236+ }
203237 // Load remote artifacts before local ones.
204238 if (mainRemoteArtifactsToImport != null && !mainRemoteArtifactsToImport .isEmpty ()) {
205- mainRemoteArtifactsToImport .forEach (( String remoteArtifactUrl ) -> this .downloadArtifact (remoteArtifactUrl , true ));
239+ mainRemoteArtifactsToImport .forEach (remoteArtifact -> this .downloadArtifact (remoteArtifact , true ));
206240 }
207241 if (secondaryRemoteArtifactsToImport != null && !secondaryRemoteArtifactsToImport .isEmpty ()) {
208- secondaryRemoteArtifactsToImport .forEach (( String remoteArtifactUrl ) -> this .downloadArtifact (remoteArtifactUrl , false ));
242+ secondaryRemoteArtifactsToImport .forEach (remoteArtifact -> this .downloadArtifact (remoteArtifact , false ));
209243 }
210244 // Load local ones that may override remote ones.
211245 if (mainArtifactsToImport != null && !mainArtifactsToImport .isEmpty ()) {
@@ -214,10 +248,6 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) {
214248 if (secondaryArtifactsToImport != null && !secondaryArtifactsToImport .isEmpty ()) {
215249 secondaryArtifactsToImport .forEach ((String artifactPath ) -> this .importArtifact (artifactPath , false ));
216250 }
217- // Load secrets before remote artifacts as they may be needed for authentication.
218- if (secrets != null && !secrets .isEmpty ()) {
219- secrets .forEach (this ::createSecret );
220- }
221251 }
222252
223253 /**
@@ -625,7 +655,7 @@ public static List<UnidirectionalEvent> getEventMessagesForTestCase(String micro
625655 * @throws ArtifactLoadException If artifact cannot be correctly downloaded in container (probably not found)
626656 */
627657 public void downloadAsMainRemoteArtifact (String remoteArtifactUrl ) throws ArtifactLoadException {
628- downloadArtifact (remoteArtifactUrl , true );
658+ downloadArtifact (new RemoteArtifact ( remoteArtifactUrl , null ) , true );
629659 }
630660
631661 /**
@@ -634,7 +664,7 @@ public void downloadAsMainRemoteArtifact(String remoteArtifactUrl) throws Artifa
634664 * @throws ArtifactLoadException If artifact cannot be correctly downloaded in container (probably not found)
635665 */
636666 public void downloadAsSecondaryRemoteArtifact (String remoteArtifactUrl ) throws ArtifactLoadException {
637- downloadArtifact (remoteArtifactUrl , false );
667+ downloadArtifact (new RemoteArtifact ( remoteArtifactUrl , null ) , false );
638668 }
639669
640670 /**
@@ -803,7 +833,7 @@ private void importArtifact(String artifactPath, boolean mainArtifact) {
803833 }
804834 }
805835
806- private void downloadArtifact (String remoteArtifactUrl , boolean mainArtifact ) throws ArtifactLoadException {
836+ private void downloadArtifact (RemoteArtifact remoteArtifact , boolean mainArtifact ) throws ArtifactLoadException {
807837 try {
808838 // Use the artifact/download endpoint to download the artifact.
809839 URL url = new URL (getHttpEndpoint () + "/api/artifact/download" );
@@ -812,7 +842,11 @@ private void downloadArtifact(String remoteArtifactUrl, boolean mainArtifact) th
812842 httpConn .setRequestMethod ("POST" );
813843 httpConn .setDoOutput (true );
814844
815- String requestBody = "mainArtifact=" + mainArtifact + "&url=" + remoteArtifactUrl ;
845+ String requestBody = "mainArtifact=" + mainArtifact + "&url=" + remoteArtifact .getUrl ();
846+
847+ if (remoteArtifact .getSecretName () != null ) {
848+ requestBody += "&secretName=" + remoteArtifact .getSecretName ();
849+ }
816850
817851 // Write the request body to the output stream of the connection
818852 try (OutputStream os = httpConn .getOutputStream ();
@@ -832,8 +866,8 @@ private void downloadArtifact(String remoteArtifactUrl, boolean mainArtifact) th
832866 // Disconnect Http connection.
833867 httpConn .disconnect ();
834868 } catch (Exception e ) {
835- log .error ("Could not load remote artifact: {}" , remoteArtifactUrl );
836- throw new ArtifactLoadException ("Error while importing remote artifact: " + remoteArtifactUrl , e );
869+ log .error ("Could not load remote artifact: {}" , remoteArtifact . getUrl () );
870+ throw new ArtifactLoadException ("Error while importing remote artifact: " + remoteArtifact . getUrl () , e );
837871 }
838872 }
839873
@@ -843,7 +877,7 @@ private void importSnapshot(String snapshotPath) {
843877 resource = MicrocksContainer .class .getClassLoader ().getResource (snapshotPath );
844878 if (resource == null ) {
845879 log .warn ("Could not load classpath snapshot: {}" , snapshotPath );
846- throw new ArtifactLoadException ("Error while importing snasphot : " + snapshotPath );
880+ throw new ArtifactLoadException ("Error while importing snapshot : " + snapshotPath );
847881 }
848882 }
849883 try {
0 commit comments