DeploymentConfigurationDao { @SneakyThrows public <T extends AbstractDeploymentConfig> T findById(Class<T> clazz, String id) { Path path = localGitRepositoryPathResolver.resolve(clazz, id); T config = null; if (Files.exists(path)) { byte[] bytes = Files.readAllBytes(path); if (ArrayUtils.isNotEmpty(bytes)) { config = YamlParserUtil.parse(new String(bytes, StandardCharsets.UTF_8), clazz); } } else { config = alienDao.findById(clazz, id); if (config != null) { save(config); alienDao.delete(clazz, id); } } return config; } @Inject  DeploymentConfigurationDao(LocalGitRepositoryPathResolver localGitRepositoryPathResolver, @Named("alien-es-dao") IGenericSearchDAO alienDao); @SneakyThrows T findById(Class<T> clazz, String id); @SneakyThrows void save(T deploymentInputs); void deleteAllByTopologyVersionId(String applicationId, String versionId); void deleteAllByEnvironmentId(String applicationId, String environmentId);  }
@Test public void migrate_data_previously_store_in_elastic_search() throws Exception { String existingId = AbstractDeploymentConfig.generateId("versionOK", "envId"); when(alienDao.findById(DeploymentMatchingConfiguration.class, existingId)).thenReturn(new DeploymentMatchingConfiguration("versionOK", "envId")); Path configLocalPath = Paths.get("target/deployment_config_dao_test/config"); Files.deleteIfExists(configLocalPath); when(localGitRepositoryPathResolver.resolve(eq(DeploymentMatchingConfiguration.class), eq(existingId))).thenReturn(configLocalPath); DeploymentMatchingConfiguration config = dao.findById(DeploymentMatchingConfiguration.class, existingId); assertThat(config).isNotNull(); assertThat(config.getId()).isEqualTo(existingId); verify(alienDao).delete(DeploymentMatchingConfiguration.class, existingId); assertThat(Files.exists(configLocalPath)).isTrue(); }
@Test public void when_no_data_in_elastic_search_and_git() throws Exception { assertThat(dao.findById(DeploymentInputs.class, "unknown")).isNull(); }