private Map<Path, Collection<ResourceChange>> getResourceChanges(Map<String, String> input) { Map<Path, Collection<ResourceChange>> resourceChanges = new HashMap<>(); input.entrySet() .stream() .filter(entry -> entry.getKey().startsWith(LocalBuildConfig.RESOURCE_CHANGE)) .forEach(entry -> { resourceChanges.put(decodePath(entry.getKey(), LocalBuildConfig.RESOURCE_CHANGE), decodeChanges(entry.getValue())); }); return resourceChanges; }
public Optional<BuildConfig> apply(LocalModule localModule, LocalBuildConfig localBuildConfig) { Optional<BuildConfig> result = Optional.empty(); LocalBuildConfig.BuildType buildType = decodeBuildType(localBuildConfig.getBuildType()); switch (buildType) { case FULL_BUILD: case INCREMENTAL_UPDATE_RESOURCE: result = Optional.of(new LocalBuildConfigInternal(localModule.getModule(), buildType, decodePath(localBuildConfig.getResource()))); break; case INCREMENTAL_BATCH_CHANGES: result = Optional.of(new LocalBuildConfigInternal(localModule.getModule(), getResourceChanges(localBuildConfig.getResourceChanges()))); break; case FULL_BUILD_AND_DEPLOY: result = Optional.of(new LocalBuildConfigInternal(localModule.getModule(), decodeDeploymentType(localBuildConfig.getDeploymentType()), decodeSuppressHandlers(localBuildConfig.getSuppressHandlers())));
private void verifyLocalBuildConfigExecutorWasInvoked(KieModule module, String buildType) { verify(localBuildConfigExecutor, times(1)).apply(localModuleCaptor.capture(), localBuildConfigCaptor.capture()); assertEquals(module, localModuleCaptor.getValue().getModule()); assertEquals(buildType, localBuildConfigCaptor.getValue().getBuildType()); }
@Before public void setup() { executor = new LocalBuildConfigExecutor(); }
private Path decodePath(String uri) { return decodePath(uri, ""); }
private void verifyLocalBuildConfigExecutorWasInvoked(KieModule module, String resourceUri, String buildType) { verify(localBuildConfigExecutor, times(1)).apply(localModuleCaptor.capture(), localBuildConfigCaptor.capture()); assertEquals(module, localModuleCaptor.getValue().getModule()); assertEquals(resourceUri, localBuildConfigCaptor.getValue().getResource()); assertEquals(buildType, localBuildConfigCaptor.getValue().getBuildType()); }
localSourceConfigExecutor = spy(new LocalSourceConfigExecutor()); localModuleConfigExecutor = spy(new LocalModuleConfigExecutor(moduleService)); localBuildConfigExecutor = spy(new LocalBuildConfigExecutor()); localBuildExecConfigExecutor = spy(new LocalBuildExecConfigExecutor(buildHelper));
@Test public void testApplyForModuleFullBuild() { when(localModule.getModule()).thenReturn(project); when(buildConfig.getBuildType()).thenReturn(LocalBuildConfig.BuildType.FULL_BUILD.name()); Optional<BuildConfig> result = executor.apply(localModule, buildConfig); assertTrue(result.isPresent()); assertEquals(LocalBuildConfig.BuildType.FULL_BUILD, ((LocalBuildConfigInternal) result.get()).getBuildType()); assertEquals(project, ((LocalBuildConfigInternal) result.get()).getModule()); }
private void verifyLocalBuildConfigExecutorWasInvoked(KieModule module, String buildType, String deploymentType, String suppressHandlers) { verify(localBuildConfigExecutor, times(1)).apply(localModuleCaptor.capture(), localBuildConfigCaptor.capture()); assertEquals(module, localModuleCaptor.getValue().getModule()); assertEquals(buildType, localBuildConfigCaptor.getValue().getBuildType()); assertEquals(deploymentType, localBuildConfigCaptor.getValue().getDeploymentType()); assertEquals(suppressHandlers, localBuildConfigCaptor.getValue().getSuppressHandlers()); }
private void verifyLocalBuildConfigExecutorWasInvoked(KieModule module, ResourceChangeRequest... changes) { verify(localBuildConfigExecutor, times(1)).apply(localModuleCaptor.capture(), localBuildConfigCaptor.capture()); assertEquals(module, localModuleCaptor.getValue().getModule()); assertEquals(LocalBuildConfig.BuildType.INCREMENTAL_BATCH_CHANGES.name(), localBuildConfigCaptor.getValue().getBuildType()); for (ResourceChangeRequest change : changes) { assertNotNull(localBuildConfigCaptor.getValue().getResourceChanges().get(LocalBuildConfig.RESOURCE_CHANGE + change.getUri())); assertEquals(change.getChanges(), localBuildConfigCaptor.getValue().getResourceChanges().get(LocalBuildConfig.RESOURCE_CHANGE + change.getUri())); } }
private void testApplyForIncrementalResourceBuild(LocalBuildConfig.BuildType buildType, String resourceURI) { when(localModule.getModule()).thenReturn(project); when(buildConfig.getBuildType()).thenReturn(buildType.name()); when(buildConfig.getResource()).thenReturn(resourceURI); Optional<BuildConfig> result = executor.apply(localModule, buildConfig); assertTrue(result.isPresent()); assertEquals(buildType, ((LocalBuildConfigInternal) result.get()).getBuildType()); assertEquals(project, ((LocalBuildConfigInternal) result.get()).getModule()); assertEquals(RESOURCE_URI_1, ((LocalBuildConfigInternal) result.get()).getResource().toURI()); }
@Test public void testApplyForIncrementalBatchChangesBuild() { when(localModule.getModule()).thenReturn(project); when(buildConfig.getBuildType()).thenReturn(LocalBuildConfig.BuildType.INCREMENTAL_BATCH_CHANGES.name()); Map<String, String> resourceChanges = new HashMap<>(); resourceChanges.put(LocalBuildConfig.RESOURCE_CHANGE + RESOURCE_URI_1, "ADD"); resourceChanges.put(LocalBuildConfig.RESOURCE_CHANGE + RESOURCE_URI_2, "ADD,UPDATE"); resourceChanges.put(LocalBuildConfig.RESOURCE_CHANGE + RESOURCE_URI_3, "ADD,UPDATE,DELETE"); when(buildConfig.getResourceChanges()).thenReturn(resourceChanges); Optional<BuildConfig> result = executor.apply(localModule, buildConfig); assertTrue(result.isPresent()); assertEquals(LocalBuildConfig.BuildType.INCREMENTAL_BATCH_CHANGES, ((LocalBuildConfigInternal) result.get()).getBuildType()); assertHasAllChanges(((LocalBuildConfigInternal) result.get()).getResourceChanges().get(resource1VFSPath), ResourceChangeType.ADD); assertHasAllChanges(((LocalBuildConfigInternal) result.get()).getResourceChanges().get(resource2VFSPath), ResourceChangeType.ADD, ResourceChangeType.UPDATE); assertHasAllChanges(((LocalBuildConfigInternal) result.get()).getResourceChanges().get(resource3VFSPath), ResourceChangeType.ADD, ResourceChangeType.UPDATE, ResourceChangeType.DELETE); }
private void testApplyForModuleFullBuildAndDeploy(LocalBuildConfig.DeploymentType deploymentType, boolean suppressHandlers) { when(localModule.getModule()).thenReturn(project); when(buildConfig.getBuildType()).thenReturn(LocalBuildConfig.BuildType.FULL_BUILD_AND_DEPLOY.name()); when(buildConfig.getDeploymentType()).thenReturn(deploymentType.name()); when(buildConfig.getSuppressHandlers()).thenReturn(Boolean.toString(suppressHandlers)); Optional<BuildConfig> result = executor.apply(localModule, buildConfig); assertTrue(result.isPresent()); assertEquals(project, ((LocalBuildConfigInternal) result.get()).getModule()); assertEquals(LocalBuildConfig.BuildType.FULL_BUILD_AND_DEPLOY, ((LocalBuildConfigInternal) result.get()).getBuildType()); assertEquals(deploymentType, ((LocalBuildConfigInternal) result.get()).getDeploymentType()); assertEquals(suppressHandlers, ((LocalBuildConfigInternal) result.get()).isSuppressHandlers()); } }