Search in sources :

Example 26 with RepoResult

use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.

the class ApiRouteServiceTest method testGetIndexTime.

public void testGetIndexTime() {
    Request mockRequest = mock(Request.class);
    Repo repoMock = mock(Repo.class);
    when(mockRequest.queryParams("reponame")).thenReturn("somename");
    when(mockRequest.queryParams()).thenReturn((new HashMap<String, String>() {

        {
            put("reponame", "reponame");
        }
    }).keySet());
    when(repoMock.getRepoByName("somename")).thenReturn(new RepoResult(0, "name", "scm", "url", "username", "password", "source", "branch", "\n" + "{\"rowId\":1,\"name\":\"test\",\"scm\":\"git\",\"url\":\"/test/\",\"username\":\"\",\"password\":\"\",\"source\":\"\",\"branch\":\"master\",\"data\":{\"averageIndexTimeSeconds\":9,\"indexStatus\":\"success\",\"jobRunTime\":{\"seconds\":1496356541,\"nanos\":188000000}}}"));
    ApiRouteService apiRouteService = new ApiRouteService(null, null, repoMock, null, null);
    String averageIndexTimeSeconds = apiRouteService.getIndexTime(mockRequest, null);
    assertThat(averageIndexTimeSeconds).isEqualTo("0 seconds ago");
}
Also used : Repo(com.searchcode.app.dao.Repo) ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Request(spark.Request) RepoResult(com.searchcode.app.model.RepoResult)

Example 27 with RepoResult

use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.

the class ValidatorServiceTest method testValidatorServiceExistingName.

public void testValidatorServiceExistingName() {
    Repo mockRepo = mock(Repo.class);
    ValidatorService validatorService = new ValidatorService(mockRepo, new Helpers());
    when(mockRepo.getRepoByName("exists")).thenReturn(new RepoResult());
    RepoResult repoResult = new RepoResult(0, "exists", "something", "url", "", "", "source", "branch", "{}");
    ValidatorResult validate = validatorService.validate(repoResult);
    assertThat(validate.isValid).isFalse();
}
Also used : Repo(com.searchcode.app.dao.Repo) Helpers(com.searchcode.app.util.Helpers) ValidatorResult(com.searchcode.app.model.ValidatorResult) RepoResult(com.searchcode.app.model.RepoResult)

Example 28 with RepoResult

use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.

the class ValidatorServiceTest method testRepoResultInValidReponame.

public void testRepoResultInValidReponame() {
    ValidatorService validatorService = new ValidatorService();
    ValidatorResult validate = validatorService.validate(new RepoResult(0, "some/thing", "something", "url", "", "", "source", "branch", "{}"));
    assertThat(validate.isValid).isFalse();
}
Also used : ValidatorResult(com.searchcode.app.model.ValidatorResult) RepoResult(com.searchcode.app.model.RepoResult)

Example 29 with RepoResult

use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.

the class UniqueRepoQueueTest method testEnqueueDifferent.

public void testEnqueueDifferent() {
    UniqueRepoQueue queue = new UniqueRepoQueue(new ConcurrentArrayQueue<>());
    RepoResult rr1 = new RepoResult(1, "name", "scm", "url", "username", "password", "source", "branch", "");
    RepoResult rr2 = new RepoResult(2, "name2", "scm", "url", "username", "password", "source", "branch", "");
    queue.add(rr1);
    queue.add(rr2);
    assertEquals(2, queue.size());
}
Also used : RepoResult(com.searchcode.app.model.RepoResult)

Example 30 with RepoResult

use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.

the class UniqueRepoQueueTest method testBleedingBetweenUniqueQueues.

public void testBleedingBetweenUniqueQueues() {
    UniqueRepoQueue queue1 = Singleton.getUniqueGitRepoQueue();
    UniqueRepoQueue queue2 = Singleton.getUniqueSvnRepoQueue();
    RepoResult rr1 = new RepoResult(1, "name", "git", "url", "username", "password", "source", "branch", "");
    RepoResult rr2 = new RepoResult(2, "name2", "svn", "url", "username", "password", "source", "branch", "");
    queue1.add(rr1);
    queue2.add(rr2);
    assertEquals(1, queue1.size());
    assertEquals(1, queue2.size());
    assertTrue(rr1.equals(queue1.poll()));
    assertTrue(rr2.equals(queue2.poll()));
}
Also used : RepoResult(com.searchcode.app.model.RepoResult)

Aggregations

RepoResult (com.searchcode.app.model.RepoResult)59 Repo (com.searchcode.app.dao.Repo)13 ApiResponse (com.searchcode.app.dto.api.ApiResponse)9 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)9 Request (spark.Request)9 ValidatorResult (com.searchcode.app.model.ValidatorResult)8 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)8 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)8 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 SQLException (java.sql.SQLException)5 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)3 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)2 RunningIndexJob (com.searchcode.app.dto.RunningIndexJob)2 File (java.io.File)2 Gson (com.google.gson.Gson)1 Data (com.searchcode.app.dao.Data)1 IndexBaseRepoJob (com.searchcode.app.jobs.repository.IndexBaseRepoJob)1 IndexFileRepoJob (com.searchcode.app.jobs.repository.IndexFileRepoJob)1