Search in sources :

Example 6 with ServerStatusResponse

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");
}
Also used : ConfigFileType(com.thoughtworks.go.addon.businesscontinuity.ConfigFileType) FileDetails(com.thoughtworks.go.addon.businesscontinuity.FileDetails) ServerStatusResponse(com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse) Test(org.junit.jupiter.api.Test)

Example 7 with ServerStatusResponse

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"));
}
Also used : ConfigFileType(com.thoughtworks.go.addon.businesscontinuity.ConfigFileType) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) ServerStatusResponse(com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse) Test(org.junit.jupiter.api.Test)

Example 8 with ServerStatusResponse

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));
}
Also used : ConfigFileType(com.thoughtworks.go.addon.businesscontinuity.ConfigFileType) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) ServerStatusResponse(com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse) Test(org.junit.jupiter.api.Test)

Example 9 with ServerStatusResponse

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)) + "\"}");
}
Also used : HashMap(java.util.HashMap) ServerStatusResponse(com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

ServerStatusResponse (com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse)9 Test (org.junit.jupiter.api.Test)7 ConfigFileType (com.thoughtworks.go.addon.businesscontinuity.ConfigFileType)4 HashMap (java.util.HashMap)4 Gson (com.google.gson.Gson)3 FileDetails (com.thoughtworks.go.addon.businesscontinuity.FileDetails)2 File (java.io.File)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1