RPackagesBuilderFacetImpl extends FacetSupport implements RPackagesBuilderFacet, Asynchronous { @Subscribe @Guarded(by = STARTED) @AllowConcurrentEvents public void on(final AssetEvent event) { if (shouldInvalidate(event)) { invalidateMetadata(getBasePath(event.getAsset().name())); } } @Inject  RPackagesBuilderFacetImpl(
      final EventManager eventManager,
      @Named("${nexus.r.packagesBuilder.interval:-1000}") final long interval); @Subscribe @Guarded(by = STARTED) @AllowConcurrentEvents void on(final AssetEvent event); @Override void invalidateMetadata(final String basePath); @Subscribe void on(final RMetadataInvalidationEvent event);  }
@Test public void testAssetDeletedEventHandledCorrectly() { when(assetDeletedEvent.isLocal()).thenReturn(true); when(assetDeletedEvent.getRepositoryName()).thenReturn(REPOSITORY_NAME); when(assetDeletedEvent.getAsset()).thenReturn(asset); when(asset.name()).thenReturn(ASSET_PATH); when(formatAttributes.get(P_ASSET_KIND, String.class)).thenReturn(ARCHIVE.name()); underTest.on(assetDeletedEvent); ArgumentCaptor<RMetadataInvalidationEvent> eventCaptor = ArgumentCaptor.forClass(RMetadataInvalidationEvent.class); verify(eventManager).post(eventCaptor.capture()); RMetadataInvalidationEvent event = eventCaptor.getValue(); assertThat(event.getRepositoryName(), is(REPOSITORY_NAME)); assertThat(event.getBasePath(), is(BASE_PATH)); }
@Test public void testAssetDeletedEventIgnoredForDifferentNode() { when(assetDeletedEvent.isLocal()).thenReturn(false); when(assetDeletedEvent.getRepositoryName()).thenReturn(REPOSITORY_NAME); when(assetDeletedEvent.getAsset()).thenReturn(asset); when(asset.name()).thenReturn(ASSET_PATH); when(formatAttributes.get(P_ASSET_KIND, String.class)).thenReturn(ARCHIVE.name()); underTest.on(assetDeletedEvent); verifyNoMoreInteractions(eventManager); }
@Test public void testAssetDeletedEventIgnoredForDifferentRepository() { when(assetDeletedEvent.isLocal()).thenReturn(true); when(assetDeletedEvent.getRepositoryName()).thenReturn("foo"); when(assetDeletedEvent.getAsset()).thenReturn(asset); when(asset.name()).thenReturn(ASSET_PATH); when(formatAttributes.get(P_ASSET_KIND, String.class)).thenReturn(ARCHIVE.name()); underTest.on(assetDeletedEvent); verifyNoMoreInteractions(eventManager); }
@Test public void testAssetDeletedEventIgnoredForPackagesGzAsset() { when(assetDeletedEvent.isLocal()).thenReturn(true); when(assetDeletedEvent.getRepositoryName()).thenReturn(REPOSITORY_NAME); when(assetDeletedEvent.getAsset()).thenReturn(asset); when(asset.name()).thenReturn(PACKAGES_GZ_PATH); when(formatAttributes.get(P_ASSET_KIND, String.class)).thenReturn(PACKAGES.name()); underTest.on(assetDeletedEvent); verifyNoMoreInteractions(eventManager); }
@Test public void testAssetCreatedEventHandledCorrectly() { when(assetCreatedEvent.isLocal()).thenReturn(true); when(assetCreatedEvent.getRepositoryName()).thenReturn(REPOSITORY_NAME); when(assetCreatedEvent.getAsset()).thenReturn(asset); when(asset.name()).thenReturn(ASSET_PATH); when(formatAttributes.get(P_ASSET_KIND, String.class)).thenReturn(ARCHIVE.name()); underTest.on(assetCreatedEvent); ArgumentCaptor<RMetadataInvalidationEvent> eventCaptor = ArgumentCaptor.forClass(RMetadataInvalidationEvent.class); verify(eventManager).post(eventCaptor.capture()); RMetadataInvalidationEvent event = eventCaptor.getValue(); assertThat(event.getRepositoryName(), is(REPOSITORY_NAME)); assertThat(event.getBasePath(), is(BASE_PATH)); }
@Test public void testAssetCreatedEventIgnoredForDifferentNode() { when(assetCreatedEvent.isLocal()).thenReturn(false); when(assetCreatedEvent.getRepositoryName()).thenReturn(REPOSITORY_NAME); when(assetCreatedEvent.getAsset()).thenReturn(asset); when(asset.name()).thenReturn(ASSET_PATH); when(formatAttributes.get(P_ASSET_KIND, String.class)).thenReturn(ARCHIVE.name()); underTest.on(assetCreatedEvent); verifyNoMoreInteractions(eventManager); }
@Test public void testAssetCreatedEventIgnoredForDifferentRepository() { when(assetCreatedEvent.isLocal()).thenReturn(true); when(assetCreatedEvent.getRepositoryName()).thenReturn("foo"); when(assetCreatedEvent.getAsset()).thenReturn(asset); when(asset.name()).thenReturn(ASSET_PATH); when(formatAttributes.get(P_ASSET_KIND, String.class)).thenReturn(ARCHIVE.name()); underTest.on(assetCreatedEvent); verifyNoMoreInteractions(eventManager); }
@Test public void testAssetCreatedEventIgnoredForPackagesGzAsset() { when(assetCreatedEvent.isLocal()).thenReturn(true); when(assetCreatedEvent.getRepositoryName()).thenReturn(REPOSITORY_NAME); when(assetCreatedEvent.getAsset()).thenReturn(asset); when(asset.name()).thenReturn(PACKAGES_GZ_PATH); when(formatAttributes.get(P_ASSET_KIND, String.class)).thenReturn(PACKAGES.name()); underTest.on(assetCreatedEvent); verifyNoMoreInteractions(eventManager); }
@Test public void testAssetUpdatedEventHandledCorrectly() { when(assetUpdatedEvent.isLocal()).thenReturn(true); when(assetUpdatedEvent.getRepositoryName()).thenReturn(REPOSITORY_NAME); when(assetUpdatedEvent.getAsset()).thenReturn(asset); when(asset.name()).thenReturn(ASSET_PATH); when(formatAttributes.get(P_ASSET_KIND, String.class)).thenReturn(ARCHIVE.name()); underTest.on(assetUpdatedEvent); ArgumentCaptor<RMetadataInvalidationEvent> eventCaptor = ArgumentCaptor.forClass(RMetadataInvalidationEvent.class); verify(eventManager).post(eventCaptor.capture()); RMetadataInvalidationEvent event = eventCaptor.getValue(); assertThat(event.getRepositoryName(), is(REPOSITORY_NAME)); assertThat(event.getBasePath(), is(BASE_PATH)); }
@Test public void testAssetUpdatedEventIgnoredForDifferentNode() { when(assetUpdatedEvent.isLocal()).thenReturn(false); when(assetUpdatedEvent.getRepositoryName()).thenReturn(REPOSITORY_NAME); when(assetUpdatedEvent.getAsset()).thenReturn(asset); when(asset.name()).thenReturn(ASSET_PATH); when(formatAttributes.get(P_ASSET_KIND, String.class)).thenReturn(ARCHIVE.name()); underTest.on(assetUpdatedEvent); verifyNoMoreInteractions(eventManager); }
@Test public void testAssetUpdatedEventIgnoredForDifferentRepository() { when(assetUpdatedEvent.isLocal()).thenReturn(true); when(assetUpdatedEvent.getRepositoryName()).thenReturn("foo"); when(assetUpdatedEvent.getAsset()).thenReturn(asset); when(asset.name()).thenReturn(ASSET_PATH); when(formatAttributes.get(P_ASSET_KIND, String.class)).thenReturn(ARCHIVE.name()); underTest.on(assetUpdatedEvent); verifyNoMoreInteractions(eventManager); }
@Test public void testAssetUpdatedEventIgnoredForPackagesGzAsset() { when(assetUpdatedEvent.isLocal()).thenReturn(true); when(assetUpdatedEvent.getRepositoryName()).thenReturn(REPOSITORY_NAME); when(assetUpdatedEvent.getAsset()).thenReturn(asset); when(asset.name()).thenReturn(PACKAGES_GZ_PATH); when(formatAttributes.get(P_ASSET_KIND, String.class)).thenReturn(PACKAGES.name()); underTest.on(assetUpdatedEvent); verifyNoMoreInteractions(eventManager); }
@Test public void testRebuildMetadataOnEvent() throws Exception { when(invalidationEvent.getBasePath()).thenReturn(BASE_PATH); when(invalidationEvent.getRepositoryName()).thenReturn(REPOSITORY_NAME); underTest.on(invalidationEvent); verify(hostedFacet).buildAndPutPackagesGz(BASE_PATH); }