public Map<String, String> toMap() { HashMap<String, String> m = new HashMap<>(); m.put("data", data); m.put("view_path", getFullViewPath()); return m; }
@Test void shouldAllowViewPathWithQueryParametersForWindowsOperatingSystem() { String assetRoot = "\\assets\\root"; viewPath = "agents\\agents.html?msg=Hello%20World&msg2=AnotherOne"; analyticsData = new AnalyticsData("{}", viewPath); analyticsData.setAssetRoot(assetRoot); assertThat(analyticsData.getFullViewPath(), is("/assets/root/agents/agents.html?msg=Hello%20World&msg2=AnotherOne")); } }
@Test void shouldGetFullViewPathForWindowsOperatingSystem() { String assetRoot = "\\assets\\root"; viewPath = "agents\\agents.html"; analyticsData = new AnalyticsData("{}", viewPath); analyticsData.setAssetRoot(assetRoot); assertThat(analyticsData.getFullViewPath(), is("/assets/root/agents/agents.html")); }
@Test void shouldGetFullViewPathForLinuxOperatingSystem() { String assetRoot = "/assets/root"; viewPath = "agents/agents.html"; analyticsData = new AnalyticsData("{}", viewPath); analyticsData.setAssetRoot(assetRoot); assertThat(analyticsData.getFullViewPath(), is(assetRoot + '/' + viewPath)); }
@Test void shouldAllowViewPathWithQueryParametersForNonWindowsOperatingSystem() { String assetRoot = "/assets/root"; viewPath = "agents/agents.html?msg=Hello%20World&msg2=AnotherOne"; analyticsData = new AnalyticsData("{}", viewPath); analyticsData.setAssetRoot(assetRoot); assertThat(analyticsData.getFullViewPath(), is(assetRoot + '/' + viewPath)); }
@Test public void shouldGetAnalytics() throws Exception { String responseBody = "{ \"view_path\": \"path/to/view\", \"data\": \"{}\" }"; AnalyticsPluginInfo pluginInfo = new AnalyticsPluginInfo( new GoPluginDescriptor(PLUGIN_ID, null, null, null, null, false), null, null, null); pluginInfo.setStaticAssetsPath("/assets/root"); metadataStore.setPluginInfo(pluginInfo); when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ANALYTICS_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody)); AnalyticsData pipelineAnalytics = analyticsExtension.getAnalytics(PLUGIN_ID, "pipeline", "pipeline_with_highest_wait_time", Collections.singletonMap("pipeline_name", "test_pipeline")); String expectedRequestBody = "{" + "\"type\": \"pipeline\"," + "\"id\": \"pipeline_with_highest_wait_time\"," + " \"params\": {\"pipeline_name\": \"test_pipeline\"}}"; assertRequest(requestArgumentCaptor.getValue(), PluginConstants.ANALYTICS_EXTENSION, "1.0", REQUEST_GET_ANALYTICS, expectedRequestBody); assertThat(pipelineAnalytics.getData(), is("{}")); assertThat(pipelineAnalytics.getViewPath(), is("path/to/view")); assertThat(pipelineAnalytics.getFullViewPath(), is("/assets/root/path/to/view")); }