public void invalidateProjectCache(@Observes final InvalidateDMOModuleCacheEvent event) { PortablePreconditions.checkNotNull("event", event); final Path resourcePath = event.getResourcePath(); final KieModule module = moduleService.resolveModule(resourcePath); if (module != null) { invalidateCache(module); } } }
@Test public void testCacheIsInvalidatedWhenResourceThatMapsToProject() { final InvalidateDMOModuleCacheEvent event = new InvalidateDMOModuleCacheEvent(sessionInfo, module, resourcePath); doReturn(module).when(moduleService).resolveModule(resourcePath); cache.invalidateProjectCache(event); verify(cache).invalidateCache(eq(module)); verify(cache, never()).invalidateCache(eq(otherModule)); } }
@Test public void checkPOMSaveInvalidatesPomModelCache() { // See https://issues.jboss.org/browse/RHBRMS-2822 // Saving the pom.xml (eventually) triggers an InvalidateDMOProjectCacheEvent once VFS's WatchService // has observed the file change after the batch has been committed. The InvalidateDMOProjectCacheEvent then // invalidates the PomModelCache. The PomModelCache is used to find the Project's GAV when the Project is // "Built (& Deployed)" and if it's content is stale can lead to the generated KJAR containing the // wrong GAV. Therefore invalidate the PomModelCache as soon as the save starts. final ProjectScreenModel model = new ProjectScreenModel(); final Metadata pomMetaData = new Metadata(); final POM pom = new POM(); model.setPOM(pom); model.setPOMMetaData(pomMetaData); KieModule module = mock(KieModule.class); when(moduleService.resolveModule(pathToPom)).thenReturn(module); saver.save(pathToPom, model, DeploymentMode.FORCED, "message"); verify(pomModelCache).invalidateCache(module); }