use of com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse in project gocd by gocd.
the class PrimaryServerCommunicationServiceTest method shouldRespondWithLatestStatus.
@Test
void shouldRespondWithLatestStatus() {
String responseBody = "{\"configFilesUpdateInterval\":10,\"fileDetailsMap\":{\"CRUISE_CONFIG_XML\":{\"md5\":\"a\"}}}";
httpClientMock.onGet("https://localhost:1234/go/add-on/business-continuity/api/config_files_status").withHeader("Authorization", AUTHORIZATION_HEADER_VALUE).doReturn(200, responseBody);
ServerStatusResponse serverStatusResponse = primaryServerCommunicationService.getLatestFileStatus();
assertThat(serverStatusResponse.getConfigFilesUpdateInterval()).isEqualTo(10L);
Map<ConfigFileType, FileDetails> fileDetailsMap = serverStatusResponse.getFileDetailsMap();
assertThat(fileDetailsMap.size()).isEqualTo(1);
assertThat(fileDetailsMap.get(ConfigFileType.CRUISE_CONFIG_XML).getMd5()).isEqualTo("a");
}
use of com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse in project gocd by gocd.
the class PrimaryStatusProviderControllerTest method shouldRespondWithLatestStatus.
@Test
void shouldRespondWithLatestStatus() throws IOException {
Map<ConfigFileType, String> latestStatus = new HashMap<>();
latestStatus.put(ConfigFileType.CRUISE_CONFIG_XML, "a");
latestStatus.put(ConfigFileType.AES_CIPHER, "AES-CIPHER");
latestStatus.put(ConfigFileType.JETTY_XML, "c");
when(goFilesStatusProvider.getLatestStatusMap()).thenReturn(latestStatus);
primaryStatusProviderController.latestStatus(httpServletResponse);
ServerStatusResponse serverStatusResponse = new Gson().fromJson(httpServletResponse.getContentAsString(), ServerStatusResponse.class);
assertThat(serverStatusResponse.getFileDetailsMap().size(), is(3));
assertThat(serverStatusResponse.getFileDetailsMap().get(ConfigFileType.CRUISE_CONFIG_XML).getMd5(), is("a"));
assertThat(serverStatusResponse.getFileDetailsMap().get(ConfigFileType.AES_CIPHER).getMd5(), is("AES-CIPHER"));
assertThat(serverStatusResponse.getFileDetailsMap().get(ConfigFileType.JETTY_XML).getMd5(), is("c"));
}
use of com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse in project gocd by gocd.
the class PrimaryStatusProviderControllerTest method shouldNotIncludeFileWithEmptyMd5InLatestStatus.
@Test
void shouldNotIncludeFileWithEmptyMd5InLatestStatus() throws Exception {
Map<ConfigFileType, String> latestStatus = new HashMap<>();
latestStatus.put(ConfigFileType.CRUISE_CONFIG_XML, "a");
latestStatus.put(ConfigFileType.USER_FEATURE_TOGGLE, "");
when(goFilesStatusProvider.getLatestStatusMap()).thenReturn(latestStatus);
primaryStatusProviderController.latestStatus(httpServletResponse);
ServerStatusResponse serverStatusResponse = new Gson().fromJson(httpServletResponse.getContentAsString(), ServerStatusResponse.class);
assertThat(serverStatusResponse.getFileDetailsMap().containsKey(ConfigFileType.USER_FEATURE_TOGGLE), is(false));
}
use of com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse in project gocd by gocd.
the class DashBoardControllerTest method shouldGetPrimaryServerDetails.
@Test
void shouldGetPrimaryServerDetails() {
HashMap<ConfigFileType, FileDetails> fileDetailsMap = new HashMap<>();
fileDetailsMap.put(ConfigFileType.CRUISE_CONFIG_XML, new FileDetails("md51"));
fileDetailsMap.put(ConfigFileType.AES_CIPHER, new FileDetails("md53"));
Map<String, String> pluginOne = new HashMap<>();
pluginOne.put("name", "plugin-one");
pluginOne.put("md5", "md51");
Map<String, String> pluginTwo = new HashMap<>();
pluginTwo.put("name", "plugin-two");
pluginTwo.put("md5", "md52");
Map<String, Object> plugins = new HashMap<>();
plugins.put("external", asList(pluginOne, pluginTwo));
long time = 1428051875504L;
doReturn(new ServerStatusResponse(60000, time, fileDetailsMap)).when(primaryServerCommunicationService).getLatestFileStatus();
doReturn("https://localhost:8154").when(primaryServerCommunicationService).primaryServerUrl();
doReturn("12345").when(primaryServerCommunicationService).latestDatabaseWalLocation();
doReturn(plugins).when(primaryServerCommunicationService).getLatestPluginsStatus();
Map<String, Object> primaryServerDetails = controller.primaryServerDetails();
JsonFluentAssert.assertThatJson(gson.toJson(primaryServerDetails)).isEqualTo("{\"CRUISE_CONFIG_XML\":{\"md5\":\"md51\"},\"configFilesUpdateInterval\":60000,\"latestDatabaseWalLocation\":\"12345\",\"pluginStatus\":\"plugin-one=md51, plugin-two=md52\",\"AES_CIPHER\":{\"md5\":\"md53\"},\"url\":\"https://localhost:8154\",\"lastConfigUpdateTime\":\"" + new SimpleDateFormat("MMM d, YYYY HH:mm:ss").format(new Date(time)) + "\"}");
}
Aggregations