@Before public void prepare() { Mockito.when(systemStatus.isNexusStarted()).thenReturn(true); Mockito.when(applicationStatusSource.getSystemStatus()).thenReturn(systemStatus); Mockito.when(mavenProxyRepository.getId()).thenReturn("central"); Mockito.when(mavenProxyRepository.getName()).thenReturn("Central Repository"); }
protected void makeCentralPointTo(String url) throws Exception { MavenProxyRepository central = repositoryRegistry.getRepositoryWithFacet("central", MavenProxyRepository.class); // redirect it to our "sppof" jetty (see ReindexTest.xml in src/test/resources.... central.setRemoteUrl(url); // make the central download the remote indexes is found central.setDownloadRemoteIndexes(true); nexusConfiguration.saveConfiguration(); waitForTasksToStop(); }
protected void buildPathMatcherFor(final MavenProxyRepository mavenProxyRepository) { try { final PrefixSource prefixSource = manager.getPrefixSourceFor(mavenProxyRepository); if (prefixSource.supported()) { final PathMatcher pathMatcher = new PathMatcher(prefixSource.readEntries(), Integer.MAX_VALUE); pathMatchers.put(mavenProxyRepository.getId(), pathMatcher); } else { dropPathMatcherFor(mavenProxyRepository); } } catch (IOException e) { getLogger().warn("Could not build PathMatcher for {}!", mavenProxyRepository, e); dropPathMatcherFor(mavenProxyRepository); } }
protected boolean dropPathMatcherFor(final MavenProxyRepository mavenProxyRepository) { return pathMatchers.remove(mavenProxyRepository.getId()) != null; }
protected PathMatcher getPathMatcherFor(final MavenProxyRepository mavenProxyRepository) { return pathMatchers.get(mavenProxyRepository.getId()); }
@Test public void flippingProxyModeUpdatesWL() throws Exception { // at this point, NexusStartedEvent was fired, and hence, WL's should be inited final Manager wm = lookup(Manager.class); final MavenProxyRepository proxy1 = getRepositoryRegistry().getRepositoryWithFacet(PROXY1_REPO_ID, MavenProxyRepository.class); assertThat(proxy1.getProxyMode(), equalTo(ProxyMode.BLOCKED_MANUAL)); waitForRoutingBackgroundUpdates(); // let's check states { // proxy1 final RoutingStatus proxy1status = wm.getStatusFor(proxy1); // this repo is Blocked assertThat(proxy1status.getPublishingStatus().getStatus(), equalTo(PStatus.NOT_PUBLISHED)); assertThat( proxy1status.getDiscoveryStatus().getStatus(), equalTo(DStatus.ENABLED_NOT_POSSIBLE)); assertThat(proxy1status.getDiscoveryStatus().getLastDiscoveryStrategy(), is("none")); // Remark: the combination of those three above simply means "discovery never tried against // it" // yet. } { // group final RoutingStatus groupStatus = wm.getStatusFor( getRepositoryRegistry() .getRepositoryWithFacet(GROUP_REPO_ID, MavenGroupRepository.class)); // not all members have WL, unpublished assertThat(groupStatus.getPublishingStatus().getStatus(), equalTo(PStatus.NOT_PUBLISHED)); // message should refer to proxy1 as reason of not publishing group WL assertThat( groupStatus.getPublishingStatus().getLastPublishedMessage(), containsString(proxy1.getName())); assertThat(groupStatus.getDiscoveryStatus().getStatus(), equalTo(DStatus.NOT_A_PROXY)); } { // let's flip proxy1 now proxy1.setProxyMode(ProxyMode.ALLOW); getApplicationConfiguration().saveConfiguration(); Thread.yield(); wairForAsyncEventsToCalmDown(); waitForRoutingBackgroundUpdates(); } // let's check states again, now with enabled proxy1 { // proxy1 final RoutingStatus proxy1status = wm.getStatusFor( getRepositoryRegistry() .getRepositoryWithFacet(PROXY1_REPO_ID, MavenProxyRepository.class)); // this repo is Out of Service assertThat(proxy1status.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED)); assertThat(proxy1status.getDiscoveryStatus().getStatus(), equalTo(DStatus.SUCCESSFUL)); assertThat( proxy1status.getDiscoveryStatus().getLastDiscoveryStrategy(), is(RemotePrefixFileStrategy.ID)); } { // group final RoutingStatus groupStatus = wm.getStatusFor( getRepositoryRegistry() .getRepositoryWithFacet(GROUP_REPO_ID, MavenGroupRepository.class)); assertThat(groupStatus.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED)); assertThat(groupStatus.getDiscoveryStatus().getStatus(), equalTo(DStatus.NOT_A_PROXY)); } { // let's flip proxy1 now back proxy1.setProxyMode(ProxyMode.BLOCKED_MANUAL); getApplicationConfiguration().saveConfiguration(); Thread.yield(); wairForAsyncEventsToCalmDown(); waitForRoutingBackgroundUpdates(); } // let's check states again, now with enabled proxy1 { // proxy1 final RoutingStatus proxy1status = wm.getStatusFor( getRepositoryRegistry() .getRepositoryWithFacet(PROXY1_REPO_ID, MavenProxyRepository.class)); // this repo is blocked assertThat(proxy1status.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED)); assertThat( proxy1status.getDiscoveryStatus().getStatus(), equalTo(DStatus.ENABLED_NOT_POSSIBLE)); assertThat(proxy1status.getDiscoveryStatus().getLastDiscoveryStrategy(), is("none")); } { // group final RoutingStatus groupStatus = wm.getStatusFor( getRepositoryRegistry() .getRepositoryWithFacet(GROUP_REPO_ID, MavenGroupRepository.class)); assertThat(groupStatus.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED)); assertThat(groupStatus.getDiscoveryStatus().getStatus(), equalTo(DStatus.NOT_A_PROXY)); } }
@Test public void manuallyBlockedRepositoryDoesNotAffectWLInitialization() throws Exception { // at this point, NexusStartedEvent was fired, and hence, WL's should be inited final Manager wm = lookup(Manager.class); final MavenProxyRepository proxy1 = getRepositoryRegistry().getRepositoryWithFacet(PROXY1_REPO_ID, MavenProxyRepository.class); assertThat(proxy1.getProxyMode(), equalTo(ProxyMode.BLOCKED_MANUAL)); waitForRoutingBackgroundUpdates(); // let's check states { // proxy1 final RoutingStatus proxy1status = wm.getStatusFor(proxy1); // this repo is Out of Service assertThat(proxy1status.getPublishingStatus().getStatus(), equalTo(PStatus.NOT_PUBLISHED)); assertThat( proxy1status.getDiscoveryStatus().getStatus(), equalTo(DStatus.ENABLED_NOT_POSSIBLE)); assertThat(proxy1status.getDiscoveryStatus().getLastDiscoveryStrategy(), is("none")); // Remark: the combination of those three above simply means "discovery never tried against // it" // yet. } { // proxy2 final RoutingStatus proxy2status = wm.getStatusFor( getRepositoryRegistry() .getRepositoryWithFacet(PROXY2_REPO_ID, MavenProxyRepository.class)); // this repo should be good assertThat(proxy2status.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED)); assertThat(proxy2status.getDiscoveryStatus().getStatus(), equalTo(DStatus.SUCCESSFUL)); } { // hosted final RoutingStatus hostedStatus = wm.getStatusFor( getRepositoryRegistry() .getRepositoryWithFacet(HOSTED_REPO_ID, MavenHostedRepository.class)); // this repo should be good assertThat(hostedStatus.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED)); assertThat(hostedStatus.getDiscoveryStatus().getStatus(), equalTo(DStatus.NOT_A_PROXY)); } { // group final RoutingStatus groupStatus = wm.getStatusFor( getRepositoryRegistry() .getRepositoryWithFacet(GROUP_REPO_ID, MavenGroupRepository.class)); // not all members have WL, unpublished assertThat(groupStatus.getPublishingStatus().getStatus(), equalTo(PStatus.NOT_PUBLISHED)); // message should refer to proxy1 as reason of not publishing group WL assertThat( groupStatus.getPublishingStatus().getLastPublishedMessage(), containsString(proxy1.getName())); assertThat(groupStatus.getDiscoveryStatus().getStatus(), equalTo(DStatus.NOT_A_PROXY)); } }