@Test public void empty_arrays_are_returned_when_update_center_is_unavailable() throws Exception { logInAsSystemAdministrator(); when(updateCenterMatrixFactory.getUpdateCenter(false)).thenReturn(Optional.absent()); underTest.handle(request, response); assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo( "{" + " \"installing\": []," + " \"removing\": []," + " \"updating\": []" + "}"); }
@Test public void empty_array_is_returned_when_update_center_is_unavailable() throws Exception { when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.absent()); underTest.handle(request, response); assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo(JSON_EMPTY_UPGRADE_LIST); }
@Test public void empty_array_when_update_center_is_unavailable() { when(updateCenterMatrixFactory.getUpdateCenter(false)).thenReturn(Optional.absent()); String response = tester.newRequest().execute().getInput(); assertJson(response).withStrictArrayOrder().isSimilarTo(JSON_EMPTY_PLUGIN_LIST); }
@Test public void empty_array_is_returned_when_update_center_is_not_accessible() throws Exception { logInAsSystemAdministrator(); when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.absent()); underTest.handle(request, response); assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo(JSON_EMPTY_PLUGIN_LIST); }
@Test public void enable_strict_order_of_arrays() { expectedException.expect(AssertionError.class); assertJson("[1,2]").withStrictArrayOrder().isSimilarTo("[2, 1]"); }
@Test public void verify_JSON_response_against_example() throws Exception { SonarUpdate sonarUpdate = createSonar_51_update(); when(updateCenter.findSonarUpdates()).thenReturn(of(sonarUpdate)); underTest.handle(request, response); assertJson(response.outputAsString()).withStrictArrayOrder() .isSimilarTo(new WsActionTester(underTest).getDef().responseExampleAsString()); } }
@Test public void empty_array_is_returned_when_there_is_no_upgrade_available() throws Exception { underTest.handle(request, response); assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo(JSON_EMPTY_UPGRADE_LIST); }
@Test public void list() throws Exception { WsTester tester = new WsTester(underTest, new MetricWs()); String response = tester.newGetRequest("api/webservices", "list").execute().outputAsString(); assertJson(response).withStrictArrayOrder().isSimilarTo(getClass().getResource("list-example.json")); }
@Test public void json_example() throws IOException { ComponentDto project = initJsonExampleComponents(); logInWithBrowsePermission(project); String response = ws.newRequest() .setParam(PARAM_COMPONENT_ID, project.uuid()) .execute().getInput(); JsonAssert.assertJson(response) .withStrictArrayOrder() .isSimilarTo(getClass().getResource("tree-example.json")); }
@Test public void search_for_users_with_one_permission() { insertUsersHavingGlobalPermissions(); loginAsAdmin(db.getDefaultOrganization()); String result = newRequest().setParam("permission", "scan").execute().getInput(); assertJson(result).withStrictArrayOrder().isSimilarTo(getClass().getResource("UsersActionTest/users.json")); }
@Test public void empty_array_is_returned_when_there_is_not_plugin_installed() { String response = tester.newRequest().execute().getInput(); assertJson(response).withStrictArrayOrder().isSimilarTo(JSON_EMPTY_PLUGIN_LIST); }
@Test public void empty_arrays_are_returned_when_there_nothing_pending() throws Exception { logInAsSystemAdministrator(); underTest.handle(request, response); assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo( "{" + " \"installing\": []," + " \"removing\": []," + " \"updating\": []" + "}"); }
@Test public void empty_array_is_returned_when_there_is_no_plugin_available() throws Exception { logInAsSystemAdministrator(); underTest.handle(request, response); assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo(JSON_EMPTY_PLUGIN_LIST); }
@Test public void empty_array_is_returned_when_there_is_no_plugin_available() throws Exception { logInAsSystemAdministrator(); underTest.handle(request, response); assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo(JSON_EMPTY_PLUGIN_LIST); }
@Test public void verify_properties_written_by_writePluginMetadata() { PluginWSCommons.writePluginInfo(jsonWriter, gitPluginInfo(), null, null, null); jsonWriter.close(); assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo("{" + " \"key\": \"scmgit\"," + " \"name\": \"Git\"," + " \"description\": \"Git SCM Provider.\"," + " \"version\": \"1.0\"," + " \"license\": \"GNU LGPL 3\"," + " \"organizationName\": \"SonarSource\"," + " \"organizationUrl\": \"http://www.sonarsource.com\"," + " \"homepageUrl\": \"https://redirect.sonarsource.com/plugins/scmgit.html\"," + " \"issueTrackerUrl\": \"http://jira.sonarsource.com/browse/SONARSCGIT\"" + "}"); }
@Test public void verify_properties_written_by_writePluginMetadata_with_dto() { PluginDto pluginDto = new PluginDto().setUpdatedAt(123456L); PluginWSCommons.writePluginInfo(jsonWriter, gitPluginInfo(), null, pluginDto, null); jsonWriter.close(); assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo("{" + " \"key\": \"scmgit\"," + " \"name\": \"Git\"," + " \"description\": \"Git SCM Provider.\"," + " \"version\": \"1.0\"," + " \"license\": \"GNU LGPL 3\"," + " \"organizationName\": \"SonarSource\"," + " \"organizationUrl\": \"http://www.sonarsource.com\"," + " \"homepageUrl\": \"https://redirect.sonarsource.com/plugins/scmgit.html\"," + " \"issueTrackerUrl\": \"http://jira.sonarsource.com/browse/SONARSCGIT\"," + " \"updatedAt\": 123456" + "}"); }
@Test public void empty_result_without_views() { db.organizations().setDefaultTemplates(db.getDefaultOrganization(), "AU-Tpxb--iU5OvuD2FLy", "AU-TpxcA-iU5OvuD2FLz", "AU-TpxcA-iU5OvuD2FLx"); String result = newRequest(underTestWithoutViews).execute().getInput(); assertJson(result) .withStrictArrayOrder() .ignoreFields("permissions") .isSimilarTo("{" + " \"permissionTemplates\": []," + " \"defaultTemplates\": [" + " {" + " \"templateId\": \"AU-Tpxb--iU5OvuD2FLy\"," + " \"qualifier\": \"TRK\"" + " }" + " ]" + "}"); }
@Test public void writeRelease() { jsonWriter.beginObject(); PluginWSCommons.writeRelease(jsonWriter, newRelease().setDisplayVersion("1.0 (build 42)")); jsonWriter.endObject(); jsonWriter.close(); assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo("{" + " \"release\": {" + " \"version\": \"1.0 (build 42)\"," + " \"date\": \"2015-04-16\"," + " \"description\": \"release description\"," + " \"changeLogUrl\": \"http://change.org/plugin\"" + " }" + "}"); } @Test
@Test public void json_example() { OrganizationDto organizationDto = db.organizations().insert(); ComponentDto project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("my_project")); componentDb.insertComponent(newModuleDto(project).setDbKey("my_project:module_1")); ComponentDto anotherProject = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("another_project")); componentDb.insertComponent(newModuleDto(anotherProject).setDbKey("my_new_project:module_1")); ComponentDto module2 = componentDb.insertComponent(newModuleDto(project).setDbKey("my_project:module_2")); componentDb.insertComponent(newFileDto(module2, null)); String result = ws.newRequest() .setParam(PARAM_PROJECT, "my_project") .setParam(PARAM_FROM, "my_") .setParam(PARAM_TO, "my_new_") .setParam(PARAM_DRY_RUN, String.valueOf(true)) .execute().getInput(); assertJson(result).withStrictArrayOrder().isSimilarTo(getClass().getResource("bulk_update_key-example.json")); }
@Test public void search_for_users_with_response_example() { UserDto user1 = db.users().insertUser(newUserDto().setLogin("admin").setName("Administrator").setEmail("admin@admin.com")); db.organizations().addMember(db.getDefaultOrganization(), user1); UserDto user2 = db.users().insertUser(newUserDto().setLogin("george.orwell").setName("George Orwell").setEmail("george.orwell@1984.net")); db.organizations().addMember(db.getDefaultOrganization(), user2); db.users().insertPermissionOnUser(user1, ADMINISTER_QUALITY_PROFILES); db.users().insertPermissionOnUser(user1, ADMINISTER); db.users().insertPermissionOnUser(user1, ADMINISTER_QUALITY_GATES); db.users().insertPermissionOnUser(user2, SCAN); loginAsAdmin(db.getDefaultOrganization()); String result = newRequest().execute().getInput(); assertJson(result).withStrictArrayOrder().isSimilarTo(getClass().getResource("users-example.json")); }