Search in sources :

Example 31 with WsTester

use of org.sonar.server.ws.WsTester in project sonarqube by SonarSource.

the class AppActionTest method should_generate_app_init_info.

@Test
public void should_generate_app_init_info() throws Exception {
    AppAction app = new AppAction(languages, db.getDbClient(), i18n, userSessionRule, defaultOrganizationProvider);
    WsTester tester = new WsTester(new RulesWs(app));
    userSessionRule.addPermission(ADMINISTER_QUALITY_PROFILES, defaultOrganizationProvider.get().getUuid());
    QualityProfileDto profile1 = QProfileTesting.newXooP1("org-123");
    QualityProfileDto profile2 = QProfileTesting.newXooP2("org-123").setParentKee(QProfileTesting.XOO_P1_KEY);
    db.getDbClient().qualityProfileDao().insert(db.getSession(), profile1);
    db.getDbClient().qualityProfileDao().insert(db.getSession(), profile2);
    db.commit();
    Language xoo = mock(Language.class);
    when(xoo.getKey()).thenReturn("xoo");
    when(xoo.getName()).thenReturn("Xoo");
    Language whitespace = mock(Language.class);
    when(whitespace.getKey()).thenReturn("ws");
    when(whitespace.getName()).thenReturn("Whitespace");
    when(languages.get("xoo")).thenReturn(xoo);
    when(languages.all()).thenReturn(new Language[] { xoo, whitespace });
    RuleRepositoryDto repo1 = new RuleRepositoryDto("xoo", "xoo", "SonarQube");
    RuleRepositoryDto repo2 = new RuleRepositoryDto("squid", "ws", "SonarQube");
    db.getDbClient().ruleRepositoryDao().insert(db.getSession(), asList(repo1, repo2));
    db.getSession().commit();
    when(i18n.message(isA(Locale.class), anyString(), anyString())).thenAnswer(invocation -> invocation.getArguments()[1]);
    tester.newGetRequest("api/rules", "app").execute().assertJson(this.getClass(), "app.json");
}
Also used : Locale(java.util.Locale) WsTester(org.sonar.server.ws.WsTester) Language(org.sonar.api.resources.Language) RuleRepositoryDto(org.sonar.db.rule.RuleRepositoryDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 32 with WsTester

use of org.sonar.server.ws.WsTester in project sonarqube by SonarSource.

the class LinesActionTest method setUp.

@Before
public void setUp() {
    htmlSourceDecorator = mock(HtmlSourceDecorator.class);
    when(htmlSourceDecorator.getDecoratedSourceAsHtml(anyString(), anyString(), anyString())).then(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocationOnMock) throws Throwable {
            return "<p>" + invocationOnMock.getArguments()[0] + "</p>";
        }
    });
    sourceService = new SourceService(dbTester.getDbClient(), htmlSourceDecorator);
    componentDao = new ComponentDao();
    wsTester = new WsTester(new SourcesWs(new LinesAction(new ComponentFinder(dbTester.getDbClient()), dbTester.getDbClient(), sourceService, htmlSourceDecorator, userSessionRule)));
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) HtmlSourceDecorator(org.sonar.server.source.HtmlSourceDecorator) WsTester(org.sonar.server.ws.WsTester) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString) SourceService(org.sonar.server.source.SourceService) ComponentDao(org.sonar.db.component.ComponentDao) Before(org.junit.Before)

Example 33 with WsTester

use of org.sonar.server.ws.WsTester in project sonarqube by SonarSource.

the class IssuesActionTest method before.

@Before
public void before() {
    IssueIndex issueIndex = new IssueIndex(es.client(), system2, userSessionRule, new AuthorizationTypeSupport(userSessionRule));
    IssuesAction issuesAction = new IssuesAction(db.getDbClient(), issueIndex, userSessionRule, new ComponentFinder(db.getDbClient()));
    tester = new WsTester(new BatchWs(issuesAction));
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) WsTester(org.sonar.server.ws.WsTester) IssueIndex(org.sonar.server.issue.index.IssueIndex) AuthorizationTypeSupport(org.sonar.server.permission.index.AuthorizationTypeSupport) Before(org.junit.Before)

Example 34 with WsTester

use of org.sonar.server.ws.WsTester in project sonarqube by SonarSource.

the class UsersActionTest method before.

@Before
public void before() {
    userIndex = new UserIndex(es.client());
    usersAction = new UsersAction(userIndex, userSessionRule);
    tester = new WsTester(new BatchWs(usersAction));
}
Also used : UserIndex(org.sonar.server.user.index.UserIndex) WsTester(org.sonar.server.ws.WsTester) Before(org.junit.Before)

Example 35 with WsTester

use of org.sonar.server.ws.WsTester in project sonarqube by SonarSource.

the class AppActionTest method setUp.

@Before
public void setUp() {
    insertMetrics();
    wsTester = new WsTester(new ComponentsWs(new AppAction(dbTester.getDbClient(), userSessionRule, new ComponentFinder(dbTester.getDbClient())), mock(SuggestionsAction.class)));
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) WsTester(org.sonar.server.ws.WsTester) Before(org.junit.Before)

Aggregations

WsTester (org.sonar.server.ws.WsTester)71 Before (org.junit.Before)50 Test (org.junit.Test)21 DbClient (org.sonar.db.DbClient)18 ComponentFinder (org.sonar.server.component.ComponentFinder)15 WebService (org.sonar.api.server.ws.WebService)12 UserSession (org.sonar.server.user.UserSession)5 Languages (org.sonar.api.resources.Languages)4 QProfileFactory (org.sonar.server.qualityprofile.QProfileFactory)4 UserDto (org.sonar.db.user.UserDto)3 DefaultOrganizationProvider (org.sonar.server.organization.DefaultOrganizationProvider)3 UserJsonWriter (org.sonar.server.user.ws.UserJsonWriter)3 I18n (org.sonar.api.i18n.I18n)2 System2 (org.sonar.api.utils.System2)2 OrganizationDao (org.sonar.db.organization.OrganizationDao)2 RuleRepositoryDto (org.sonar.db.rule.RuleRepositoryDto)2 DefaultOrganization (org.sonar.server.organization.DefaultOrganization)2 UserUpdater (org.sonar.server.user.UserUpdater)2 UserIndex (org.sonar.server.user.index.UserIndex)2 Locale (java.util.Locale)1