### Question:
MaintenanceModeValidationService { public List<Warning> validateStackRepository(Long clusterId, String stackRepo) { List<Warning> warnings = new ArrayList<>(); StackRepoDetails repoDetails = clusterComponentConfigProvider.getStackRepoDetails(clusterId); Map<String, String> stack = repoDetails.getStack(); if (Objects.nonNull(stackRepo)) { JsonNode stackRepoJson = jsonHelper.createJsonFromString(stackRepo).path("Repositories"); String baseUrl = stackRepoJson.path("base_url").asText(); String osType = stackRepoJson.path("os_type").asText(); String repoId = stackRepoJson.path("repo_id").asText(); String configuredRepoId = stack.get(StackRepoDetails.REPO_ID_TAG); if (!configuredRepoId.contentEquals(repoId)) { warnings.add(new Warning(WarningType.STACK_REPO_WARNING, String.format("Incorrect repo id! Configured '%s', but fetched '%s' from Ambari.", configuredRepoId, repoId))); } String configuredBaseUrl = stack.get(osType); if (configuredBaseUrl == null) { warnings.add(new Warning(WarningType.STACK_REPO_WARNING, String.format("Incorrect OS type configured, fetched '%s' from Ambari.", osType))); } else if (!configuredBaseUrl.contentEquals(baseUrl)) { warnings.add(new Warning(WarningType.STACK_REPO_WARNING, String.format("Incorrect repo URL. '%s' configured but '%s' fetched from Ambari.", configuredBaseUrl, baseUrl))); } } stack.remove(StackRepoDetails.REPO_ID_TAG); return warnings; }  String fetchStackRepository(Long stackId); void setUpValidationFlow(Long stackId); List<Warning> validateStackRepository(Long clusterId, String stackRepo); List<Warning> validateImageCatalog(Stack stack); void handleValidationSuccess(Long stackId, List<Warning> warnings); void handleValidationFailure(Long stackId, Exception error);  }### Answer:
@Test public void testValidateStackRepositoryOk() throws IOException { StackRepoDetails repoDetails = new StackRepoDetails(); repoDetails.setHdpVersion("2.6.5.0"); Map stackMap = new HashMap<>(); stackMap.put(StackRepoDetails.REPO_ID_TAG, "HDP-2.6"); stackMap.put(StackRepoDetails.REPOSITORY_VERSION, "2.6.5.0-292"); stackMap.put(StackRepoDetails.CUSTOM_VDF_REPO_KEY, "http: stackMap.put("redhat7", "http: repoDetails.setStack(stackMap); when(clusterComponentConfigProvider.getStackRepoDetails(eq(cluster.getId()))).thenReturn(repoDetails); when(jsonHelper.createJsonFromString(eq(stackRepo))).thenReturn(JsonUtil.readTree(stackRepo)); warnings.addAll(underTest.validateStackRepository(cluster.getId(), stackRepo)); assertEquals(0, warnings.size()); }
@Test public void testValidateStackRepositoryNok() throws IOException { StackRepoDetails repoDetails = new StackRepoDetails(); repoDetails.setHdpVersion("2.6.5.2"); Map stackMap = new HashMap<>(); stackMap.put(StackRepoDetails.REPO_ID_TAG, "HDP-2.5"); stackMap.put(StackRepoDetails.REPOSITORY_VERSION, "2.6.5.1-292"); stackMap.put(StackRepoDetails.CUSTOM_VDF_REPO_KEY, "http: stackMap.put("redhat7", "http: repoDetails.setStack(stackMap); when(clusterComponentConfigProvider.getStackRepoDetails(eq(cluster.getId()))).thenReturn(repoDetails); when(jsonHelper.createJsonFromString(eq(stackRepo))).thenReturn(JsonUtil.readTree(stackRepo)); warnings.addAll(underTest.validateStackRepository(cluster.getId(), stackRepo)); assertEquals(2, warnings.size()); }