Search in sources :

Example 1 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class PersistIssuesStepTest method setup.

@Before
public void setup() throws Exception {
    issueCache = new IssueCache(temp.newFile(), System2.INSTANCE);
    system2 = mock(System2.class);
    when(system2.now()).thenReturn(NOW);
    reportReader.setMetadata(ScannerReport.Metadata.getDefaultInstance());
    step = new PersistIssuesStep(dbClient, system2, new UpdateConflictResolver(), new RuleRepositoryImpl(dbClient), issueCache);
}
Also used : UpdateConflictResolver(org.sonar.server.computation.task.projectanalysis.issue.UpdateConflictResolver) RuleRepositoryImpl(org.sonar.server.computation.task.projectanalysis.issue.RuleRepositoryImpl) System2(org.sonar.api.utils.System2) IssueCache(org.sonar.server.computation.task.projectanalysis.issue.IssueCache) Before(org.junit.Before)

Example 2 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class IssueIndexDebtTest method setUp.

@Before
public void setUp() {
    System2 system = mock(System2.class);
    when(system.getDefaultTimeZone()).thenReturn(TimeZone.getTimeZone("+01:00"));
    when(system.now()).thenReturn(System.currentTimeMillis());
    index = new IssueIndex(tester.client(), system, userSessionRule, new AuthorizationTypeSupport(userSessionRule));
}
Also used : System2(org.sonar.api.utils.System2) AuthorizationTypeSupport(org.sonar.server.permission.index.AuthorizationTypeSupport) Before(org.junit.Before)

Example 3 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class GroupsActionTest method setUp.

@Before
public void setUp() {
    System2 system2 = new System2();
    UserDao userDao = new UserDao(system2);
    GroupDao groupDao = new GroupDao(system2);
    UserGroupDao userGroupDao = new UserGroupDao();
    GroupMembershipDao groupMembershipDao = new GroupMembershipDao();
    dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), userDao, groupDao, userGroupDao, groupMembershipDao);
    session = dbClient.openSession(false);
    session.commit();
    tester = new WsTester(new UsersWs(new GroupsAction(dbClient, userSession)));
    userSession.logIn().setSystemAdministrator();
}
Also used : GroupMembershipDao(org.sonar.db.user.GroupMembershipDao) DbClient(org.sonar.db.DbClient) UserDao(org.sonar.db.user.UserDao) WsTester(org.sonar.server.ws.WsTester) System2(org.sonar.api.utils.System2) GroupDao(org.sonar.db.user.GroupDao) UserGroupDao(org.sonar.db.user.UserGroupDao) UserGroupDao(org.sonar.db.user.UserGroupDao) Before(org.junit.Before)

Example 4 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class UserTokensWsTest method setUp.

@Before
public void setUp() {
    UserSession userSession = mock(UserSession.class);
    DbClient dbClient = mock(DbClient.class);
    System2 system = mock(System2.class);
    TokenGenerator tokenGenerator = mock(TokenGenerator.class);
    ws = new WsTester(new UserTokensWs(new GenerateAction(dbClient, userSession, system, tokenGenerator), new RevokeAction(dbClient, userSession), new SearchAction(dbClient, userSession)));
}
Also used : TokenGenerator(org.sonar.server.usertoken.TokenGenerator) DbClient(org.sonar.db.DbClient) WsTester(org.sonar.server.ws.WsTester) UserSession(org.sonar.server.user.UserSession) System2(org.sonar.api.utils.System2) Before(org.junit.Before)

Example 5 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class GlobalTempFolderProviderTest method createTempFolderDefault.

@Test
public void createTempFolderDefault() throws Exception {
    System2 system = mock(System2.class);
    tempFolderProvider = new GlobalTempFolderProvider(system);
    File userHome = temp.newFolder();
    when(system.envVariable("SONAR_USER_HOME")).thenReturn(null);
    when(system.property("user.home")).thenReturn(userHome.getAbsolutePath().toString());
    // if nothing is defined, it will be in {user.home}/.sonar/.sonartmp
    File defaultSonarHome = new File(userHome.getAbsolutePath(), ".sonar");
    File workingDir = new File(defaultSonarHome, CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE).getAbsoluteFile();
    try {
        TempFolder tempFolder = tempFolderProvider.provide(new GlobalProperties(Collections.<String, String>emptyMap()));
        tempFolder.newDir();
        tempFolder.newFile();
        assertThat(getCreatedTempDir(workingDir)).exists();
        assertThat(getCreatedTempDir(workingDir).list()).hasSize(2);
    } finally {
        FileUtils.deleteQuietly(workingDir);
    }
}
Also used : GlobalProperties(org.sonar.scanner.bootstrap.GlobalProperties) GlobalTempFolderProvider(org.sonar.scanner.bootstrap.GlobalTempFolderProvider) TempFolder(org.sonar.api.utils.TempFolder) System2(org.sonar.api.utils.System2) File(java.io.File) Test(org.junit.Test)

Aggregations

System2 (org.sonar.api.utils.System2)15 Before (org.junit.Before)8 Test (org.junit.Test)7 DbClient (org.sonar.db.DbClient)3 File (java.io.File)2 WsTester (org.sonar.server.ws.WsTester)2 Throwables (com.google.common.base.Throwables)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 LocalDate (java.time.LocalDate)1 Arrays (java.util.Arrays)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Properties (java.util.Properties)1 LongStream (java.util.stream.LongStream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1 Rule (org.junit.Rule)1 ExpectedException (org.junit.rules.ExpectedException)1