@Test public void shouldFindMigrationStepsForAllPossibleConfigVersions() { Integer currentConfigVersion = new MainConfig().getConfigVersion(); List<ConfigMigrationStep> steps = ConfigMigration.getMigrationSteps(); for (int i = 3; i < currentConfigVersion; i++) { int finalI = i; assertThat(steps.stream().anyMatch(x -> x.forVersion() == finalI)).isTrue(); } }
protected static List<ConfigMigrationStep> getMigrationSteps() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.addIncludeFilter(new AssignableTypeFilter(ConfigMigrationStep.class)); Set<BeanDefinition> candidates = provider.findCandidateComponents(ConfigMigrationStep.class.getPackage().getName()); List<ConfigMigrationStep> steps = new ArrayList<>(); for (BeanDefinition beanDefinition : candidates) { try { ConfigMigrationStep instance = (ConfigMigrationStep) Class.forName(beanDefinition.getBeanClassName()).getConstructor().newInstance(); steps.add(instance); } catch (Exception e) { logger.error("Unable to instantiate migration step from class " + beanDefinition.getBeanClassName(), e); } } Collections.sort(steps); return steps; }
ConfigMigration { protected static List<ConfigMigrationStep> getMigrationSteps() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.addIncludeFilter(new AssignableTypeFilter(ConfigMigrationStep.class)); Set<BeanDefinition> candidates = provider.findCandidateComponents(ConfigMigrationStep.class.getPackage().getName()); List<ConfigMigrationStep> steps = new ArrayList<>(); for (BeanDefinition beanDefinition : candidates) { try { ConfigMigrationStep instance = (ConfigMigrationStep) Class.forName(beanDefinition.getBeanClassName()).getConstructor().newInstance(); steps.add(instance); } catch (Exception e) { logger.error("Unable to instantiate migration step from class " + beanDefinition.getBeanClassName(), e); } } Collections.sort(steps); return steps; } }
ConfigMigration { protected static List<ConfigMigrationStep> getMigrationSteps() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.addIncludeFilter(new AssignableTypeFilter(ConfigMigrationStep.class)); Set<BeanDefinition> candidates = provider.findCandidateComponents(ConfigMigrationStep.class.getPackage().getName()); List<ConfigMigrationStep> steps = new ArrayList<>(); for (BeanDefinition beanDefinition : candidates) { try { ConfigMigrationStep instance = (ConfigMigrationStep) Class.forName(beanDefinition.getBeanClassName()).getConstructor().newInstance(); steps.add(instance); } catch (Exception e) { logger.error("Unable to instantiate migration step from class " + beanDefinition.getBeanClassName(), e); } } Collections.sort(steps); return steps; } ConfigMigration(); }
ConfigMigration { protected static List<ConfigMigrationStep> getMigrationSteps() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.addIncludeFilter(new AssignableTypeFilter(ConfigMigrationStep.class)); Set<BeanDefinition> candidates = provider.findCandidateComponents(ConfigMigrationStep.class.getPackage().getName()); List<ConfigMigrationStep> steps = new ArrayList<>(); for (BeanDefinition beanDefinition : candidates) { try { ConfigMigrationStep instance = (ConfigMigrationStep) Class.forName(beanDefinition.getBeanClassName()).getConstructor().newInstance(); steps.add(instance); } catch (Exception e) { logger.error("Unable to instantiate migration step from class " + beanDefinition.getBeanClassName(), e); } } Collections.sort(steps); return steps; } ConfigMigration(); Map<String, Object> migrate(Map<String, Object> map); }
ConfigMigration { protected static List<ConfigMigrationStep> getMigrationSteps() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.addIncludeFilter(new AssignableTypeFilter(ConfigMigrationStep.class)); Set<BeanDefinition> candidates = provider.findCandidateComponents(ConfigMigrationStep.class.getPackage().getName()); List<ConfigMigrationStep> steps = new ArrayList<>(); for (BeanDefinition beanDefinition : candidates) { try { ConfigMigrationStep instance = (ConfigMigrationStep) Class.forName(beanDefinition.getBeanClassName()).getConstructor().newInstance(); steps.add(instance); } catch (Exception e) { logger.error("Unable to instantiate migration step from class " + beanDefinition.getBeanClassName(), e); } } Collections.sort(steps); return steps; } ConfigMigration(); Map<String, Object> migrate(Map<String, Object> map);  }