|
| 1 | +package org.commonjava.indy.koji.util; |
| 2 | + |
| 3 | +import org.commonjava.indy.core.content.PathMaskChecker; |
| 4 | +import org.commonjava.indy.model.core.HostedRepository; |
| 5 | +import org.commonjava.indy.model.core.RemoteRepository; |
| 6 | +import org.junit.Test; |
| 7 | + |
| 8 | +import java.util.List; |
| 9 | +import java.util.Map; |
| 10 | +import java.util.Set; |
| 11 | + |
| 12 | +import static org.junit.Assert.*; |
| 13 | + |
| 14 | +public class PathMaskCheckerTest |
| 15 | +{ |
| 16 | + |
| 17 | + @Test |
| 18 | + public void extractGroupIdPath() throws Exception |
| 19 | + { |
| 20 | + List<Map.Entry<String, String>> metadataFiles = List.of( |
| 21 | + Map.entry("com/github/fge/msg-simple/maven-metadata.xml", "com/github/fge/"), |
| 22 | + Map.entry("org/jboss/eap/jboss-eap-parent/maven-metadata.xml", "org/jboss/eap/"), |
| 23 | + Map.entry("org/apache/lucene/lucene-core/maven-metadata.xml", "org/apache/lucene/"), |
| 24 | + Map.entry("org/wildfly/security/wildfly-elytron/maven-metadata.xml", "org/wildfly/security/"), |
| 25 | + Map.entry("io/dropwizard/metrics/metrics-core/maven-metadata.xml", "io/dropwizard/metrics/"), |
| 26 | + Map.entry("org/jboss/spec/javax/el/jboss-el-api_3.0_spec/maven-metadata.xml", "org/jboss/spec/javax/el/") |
| 27 | + ); |
| 28 | + |
| 29 | + for (var entry : metadataFiles) |
| 30 | + { |
| 31 | + assertEquals( entry.getValue(), PathMaskChecker.extractGroupIdPath(entry.getKey()) ); |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void checkListingMask() throws Exception |
| 37 | + { |
| 38 | + HostedRepository hostedRepository = new HostedRepository( |
| 39 | + "mvn-hosted" |
| 40 | + ); |
| 41 | + |
| 42 | + RemoteRepository mrrcRepo = new RemoteRepository( |
| 43 | + "mrrc-ga", |
| 44 | + "http://example.url" |
| 45 | + ); |
| 46 | + mrrcRepo.setPathMaskPatterns( |
| 47 | + Set.of("r|.+[-.]redhat[-_]\\d+.*|") |
| 48 | + ); |
| 49 | + |
| 50 | + RemoteRepository repositoryMatched = new RemoteRepository( |
| 51 | + "koji-org.infinispan-infinispan-parent-9.4.2.Final_redhat_00001-2", |
| 52 | + "http://example.url" |
| 53 | + ); |
| 54 | + repositoryMatched.setPathMaskPatterns( |
| 55 | + Set.of("r|org\\/infinispan\\/.+\\/9.4.2.Final-redhat-00001\\/.+|", |
| 56 | + "org/infinispan/infinispan-query-dsl/maven-metadata.xml", |
| 57 | + "r|org\\/infinispan\\/server\\/.+\\/9.4.2.Final-redhat-00001\\/.+|")); |
| 58 | + |
| 59 | + RemoteRepository repositoryUnMatched = new RemoteRepository( |
| 60 | + "koji-org.jboss.eap-jboss-eap-parent-7.2.0.GA_redhat_00002-2", |
| 61 | + "http://example.url" |
| 62 | + ); |
| 63 | + repositoryUnMatched.setPathMaskPatterns( |
| 64 | + Set.of("r|org\\/jboss\\/eap\\/.+\\/7.2.0.GA-redhat-00002\\/.+|", |
| 65 | + "org/jboss/eap/jboss-eap-parent/maven-metadata.xml")); |
| 66 | + |
| 67 | + RemoteRepository repositoryWithMultipleGroupIds = new RemoteRepository( |
| 68 | + "koji-com.sun.mail-all-1.6.1.redhat_1-1", |
| 69 | + "http://example.url" |
| 70 | + ); |
| 71 | + repositoryWithMultipleGroupIds.setPathMaskPatterns( |
| 72 | + Set.of("javax/mail/javax.mail-api/maven-metadata.xml", |
| 73 | + "com/sun/mail/javax.mail-api/maven-metadata.xml", |
| 74 | + "r|javax\\/mail\\/.+\\/1.6.1.redhat-1\\/.+|", |
| 75 | + "r|com\\/sun\\/mail\\/.+\\/1.6.1.redhat-1\\/.+|")); |
| 76 | + |
| 77 | + assertTrue(PathMaskChecker.checkListingMask(repositoryMatched, "org/")); |
| 78 | + assertTrue(PathMaskChecker.checkListingMask(repositoryMatched, "org/infinispan/")); |
| 79 | + assertTrue(PathMaskChecker.checkListingMask(repositoryMatched, "org/infinispan/infinispan-component-annotations/")); |
| 80 | + assertTrue(PathMaskChecker.checkListingMask(repositoryWithMultipleGroupIds, "com/sun/mail/")); |
| 81 | + assertTrue(PathMaskChecker.checkListingMask(repositoryWithMultipleGroupIds, "javax/mail/")); |
| 82 | + assertFalse(PathMaskChecker.checkListingMask(repositoryUnMatched, "org/infinispan/")); |
| 83 | + |
| 84 | + assertTrue(PathMaskChecker.checkListingMask(hostedRepository, "org/infinispan/")); |
| 85 | + assertTrue(PathMaskChecker.checkListingMask(mrrcRepo, "org/infinispan/")); |
| 86 | + } |
| 87 | + |
| 88 | +} |
0 commit comments