@Test public void verify_properties_displayed_in_json_per_installing_plugin() throws Exception { when(pluginDownloader.getDownloadedPlugins()).thenReturn(of(gitPluginInfo())); UpdateCenter updateCenter = mock(UpdateCenter.class); when(updateCenterMatrixFactory.getUpdateCenter(false)).thenReturn(Optional.of(updateCenter)); when(updateCenter.findAllCompatiblePlugins()) .thenReturn(Arrays.asList(new Plugin("scmgit").setCategory("cat_1"))); underTest.handle(request, response); assertJson(response.outputAsString()) .isSimilarTo( "{" + " \"installing\": " + " [" + " {" + " \"key\": \"scmgit\"," + " \"name\": \"Git\"," + " \"description\": \"Git SCM Provider.\"," + " \"version\": \"1.0\"," + " \"license\": \"GNU LGPL 3\"," + " \"category\":\"cat_1\"," + " \"organizationName\": \"SonarSource\"," + " \"organizationUrl\": \"http://www.sonarsource.com\"," + " \"homepageUrl\": \"http://redirect.sonarsource.com/plugins/scmgit.html\"," + " \"issueTrackerUrl\": \"http://jira.sonarsource.com/browse/SONARSCGIT\"," + " \"implementationBuild\": \"9ce9d330c313c296fab051317cc5ad4b26319e07\"" + " }" + " ]," + " \"removing\": []" + "}"); }
@Test public void IAE_is_raised_when_update_center_is_unavailable() throws Exception { when(updateCenterFactory.getUpdateCenter(anyBoolean())) .thenReturn(Optional.<UpdateCenter>absent()); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("No plugin with key 'pluginKey'"); underTest.handle(validRequest, response); }
@Test public void empty_arrays_are_returned_when_update_center_is_unavailable() throws Exception { when(updateCenterMatrixFactory.getUpdateCenter(false)) .thenReturn(Optional.<UpdateCenter>absent()); underTest.handle(request, response); assertJson(response.outputAsString()) .withStrictArrayOrder() .isSimilarTo("{" + " \"installing\": []," + " \"removing\": []" + "}"); }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkPermission(SYSTEM_ADMIN); JsonWriter jsonWriter = response.newJsonWriter(); jsonWriter.beginObject(); Optional<UpdateCenter> updateCenter = updateCenterMatrixFactory.getUpdateCenter(DO_NOT_FORCE_REFRESH); writePlugins(jsonWriter, updateCenter); pluginWSCommons.writeUpdateCenterProperties(jsonWriter, updateCenter); jsonWriter.endObject(); jsonWriter.close(); }
@Before public void setUp() { when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.of(updateCenter)); userSessionRule.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); }