@@ -43,6 +43,7 @@ abstract class BaseRepositoryTests extends ArtifactoryTestsBase {
4343 protected Repository federatedRepo
4444 protected Repository remoteRepo
4545 protected Repository virtualRepo
46+ protected Repository repoForVirtual // Dedicated repo for virtual repo child
4647
4748 protected XraySettings xraySettings
4849 protected Map<String , Object > customProperties
@@ -155,14 +156,15 @@ abstract class BaseRepositoryTests extends ArtifactoryTestsBase {
155156 if (prepareVirtualRepo) {
156157 RepositorySettings virtualSettings = getRepositorySettings(RepositoryTypeImpl . VIRTUAL )
157158 def repos = new ArrayList<String > ()
158- Repository repoForVirtual = null
159159
160- // Determine which repository to use for the virtual repo
161- // For package types that don't support local repos (like P2), use remote repo
162- // Otherwise, create a dedicated local repo with matching package type
160+ // Create a dedicated child repo for the virtual repo
161+ // Use LOCAL settings if available, otherwise use VIRTUAL settings for package type compatibility
163162 if (prepareLocalRepo) {
164- // Create a dedicated local repo for virtual repo with matching package type
165163 RepositorySettings localSettingsForVirtual = getRepositorySettings(RepositoryTypeImpl . LOCAL )
164+ // If LOCAL settings are null, use VIRTUAL settings to ensure correct package type
165+ if (localSettingsForVirtual == null ) {
166+ localSettingsForVirtual = virtualSettings
167+ }
166168 XraySettings virtualXraySettings = new XraySettingsImpl ()
167169 repoForVirtual = artifactory. repositories(). builders(). localRepositoryBuilder()
168170 .key(" $REPO_NAME_PREFIX -for-virtual-$id " )
@@ -179,9 +181,39 @@ abstract class BaseRepositoryTests extends ArtifactoryTestsBase {
179181 .build()
180182 artifactory. repositories(). create(0 , repoForVirtual)
181183 repos. add(repoForVirtual. getKey())
182- } else if (prepareRemoteRepo && remoteRepo != null ) {
183- // Use remote repo for package types that don't support local repos (e.g., P2)
184- repoForVirtual = remoteRepo
184+ } else if (prepareRemoteRepo) {
185+ // For package types that don't support local repos (e.g., P2), create a SEPARATE remote repo
186+ RepositorySettings remoteSettingsForVirtual = getRepositorySettings(RepositoryTypeImpl . REMOTE )
187+ ContentSync contentSync = new ContentSyncImpl ()
188+ repoForVirtual = artifactory. repositories(). builders(). remoteRepositoryBuilder()
189+ .key(" $REPO_NAME_PREFIX -remote-for-virtual-$id " )
190+ .description(" remote-for-virtual-$id " )
191+ .notes(" notes-${ rnd.nextInt()} " )
192+ .allowAnyHostAuth(rnd. nextBoolean())
193+ .archiveBrowsingEnabled(rnd. nextBoolean())
194+ .assumedOfflinePeriodSecs(rnd. nextLong())
195+ .enableCookieManagement(rnd. nextBoolean())
196+ .excludesPattern(" org/${ rnd.nextInt()} /**" )
197+ .failedRetrievalCachePeriodSecs(rnd. nextInt())
198+ .hardFail(rnd. nextBoolean())
199+ .includesPattern(" org/${ rnd.nextInt()} /**" )
200+ .missedRetrievalCachePeriodSecs(rnd. nextInt())
201+ .offline(rnd. nextBoolean())
202+ .password(" password_${ rnd.nextInt()} " )
203+ .propertySets(Collections . emptyList())
204+ .retrievalCachePeriodSecs(rnd. nextInt())
205+ .shareConfiguration(rnd. nextBoolean())
206+ .socketTimeoutMillis(rnd. nextInt())
207+ .storeArtifactsLocally(ObjectUtils . defaultIfNull(storeArtifactsLocallyInRemoteRepo, rnd. nextBoolean()))
208+ .synchronizeProperties(rnd. nextBoolean())
209+ .unusedArtifactsCleanupPeriodHours(Math . abs(rnd. nextInt()))
210+ .url(remoteRepoUrl)
211+ .username(" user_${ rnd.nextInt()} " )
212+ .repositorySettings(remoteSettingsForVirtual)
213+ .xraySettings(xraySettings)
214+ .contentSync(contentSync)
215+ .customProperties(customProperties)
216+ .build()
185217 artifactory. repositories(). create(0 , repoForVirtual)
186218 repos. add(repoForVirtual. getKey())
187219 } else if (prepareGenericRepo && genericRepo != null ) {
@@ -203,18 +235,14 @@ abstract class BaseRepositoryTests extends ArtifactoryTestsBase {
203235 .customProperties(customProperties)
204236 .defaultDeploymentRepo(repos. isEmpty() ? null : repos. last())
205237 .build()
206-
207- // Store reference to the repo created for virtual for cleanup
208- if (! prepareGenericRepo && repoForVirtual != null ) {
209- genericRepo = repoForVirtual
210- }
211238 }
212239 }
213240
214241 @AfterMethod
215242 protected void tearDown () {
216243 // Invoking sequence is important! Delete in reverse dependency order
217- deleteRepoWithRetry(virtualRepo?. getKey()) // Delete virtual repo first (depends on generic)
244+ deleteRepoWithRetry(virtualRepo?. getKey()) // Delete virtual repo first (depends on others)
245+ deleteRepoWithRetry(repoForVirtual?. getKey()) // Delete the dedicated repo for virtual
218246 deleteRepoWithRetry(federatedRepo?. getKey())
219247 deleteRepoWithRetry(remoteRepo?. getKey())
220248 deleteRepoWithRetry(localRepo?. getKey())
0 commit comments