11package org .openmetadata .service .jdbi3 ;
22
3+ import static org .junit .jupiter .api .Assertions .assertEquals ;
34import static org .junit .jupiter .api .Assertions .assertFalse ;
5+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
6+ import static org .junit .jupiter .api .Assertions .assertNull ;
47import static org .junit .jupiter .api .Assertions .assertTrue ;
58import static org .mockito .Mockito .mock ;
69import static org .mockito .Mockito .when ;
710
811import java .util .Objects ;
12+ import java .util .UUID ;
913import org .junit .jupiter .api .BeforeAll ;
1014import org .junit .jupiter .api .DisplayName ;
1115import org .junit .jupiter .api .Test ;
1418import org .openmetadata .schema .metadataIngestion .DatabaseServiceMetadataPipeline ;
1519import org .openmetadata .schema .metadataIngestion .LogLevels ;
1620import org .openmetadata .schema .metadataIngestion .SourceConfig ;
21+ import org .openmetadata .schema .security .secrets .SecretsManagerConfiguration ;
22+ import org .openmetadata .schema .security .secrets .SecretsManagerProvider ;
1723import org .openmetadata .schema .type .EntityReference ;
24+ import org .openmetadata .service .secrets .SecretsManagerFactory ;
1825
1926class IngestionPipelineRepositoryTest {
2027
@@ -31,6 +38,10 @@ static void setup() {
3138 org .mockito .ArgumentMatchers .any (IngestionPipeline .class ),
3239 org .mockito .ArgumentMatchers .any (IngestionPipeline .class )))
3340 .thenCallRealMethod ();
41+
42+ SecretsManagerConfiguration smConfig = new SecretsManagerConfiguration ();
43+ smConfig .setSecretsManager (SecretsManagerProvider .DB );
44+ SecretsManagerFactory .createSecretsManager (smConfig , "test" );
3445 }
3546
3647 @ Test
@@ -219,6 +230,42 @@ void testHasSourceConfigChanged_OneNull_ShouldReturnTrue() {
219230 assertTrue (hasChanged , "Null to non-null sourceConfig should indicate a change" );
220231 }
221232
233+ @ Test
234+ @ DisplayName (
235+ "buildIngestionPipelineDecrypted with null service should produce decrypted pipeline without service" )
236+ void testBuildIngestionPipelineDecrypted_NullServicePreserved () {
237+ IngestionPipeline pipeline = createBasicPipeline ();
238+ pipeline .setService (null );
239+
240+ IngestionPipeline decrypted =
241+ IngestionPipelineRepository .buildIngestionPipelineDecrypted (pipeline );
242+
243+ assertNull (
244+ decrypted .getService (),
245+ "Decrypted pipeline should have null service when original has null service."
246+ + " This happens when the pipeline is loaded via findByName (service is a relationship"
247+ + " field stripped before DB storage). deployPipelineBeforeUpdate must restore it." );
248+ }
249+
250+ @ Test
251+ @ DisplayName ("buildIngestionPipelineDecrypted with service set should preserve it" )
252+ void testBuildIngestionPipelineDecrypted_ServicePreserved () {
253+ UUID serviceId = UUID .randomUUID ();
254+ EntityReference serviceRef = new EntityReference ();
255+ serviceRef .setId (serviceId );
256+ serviceRef .setName ("OpenMetadata" );
257+ serviceRef .setType ("metadataService" );
258+
259+ IngestionPipeline pipeline = createBasicPipeline ();
260+ pipeline .setService (serviceRef );
261+
262+ IngestionPipeline decrypted =
263+ IngestionPipelineRepository .buildIngestionPipelineDecrypted (pipeline );
264+
265+ assertNotNull (decrypted .getService ());
266+ assertEquals ("OpenMetadata" , decrypted .getService ().getName ());
267+ }
268+
222269 private static IngestionPipeline createPipelineWithSchedule (String schedule ) {
223270 IngestionPipeline pipeline = createBasicPipeline ();
224271 AirflowConfig airflowConfig = new AirflowConfig ();
0 commit comments