Search in sources :

Example 11 with ApiResult

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

the class ApiTest method testSaveRetrieve.

public void testSaveRetrieve() {
    String randomApiString = this.getRandomString();
    this.api.saveApi(new ApiResult(0, randomApiString, "privateKey", "", ""));
    ApiResult apiResult = this.api.getApiByPublicKey(randomApiString);
    assertThat(apiResult.getPublicKey()).isEqualTo(randomApiString);
    assertThat(apiResult.getPrivateKey()).isEqualTo("privateKey");
    this.api.deleteApiByPublicKey(randomApiString);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult)

Example 12 with ApiResult

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

the class ApiTest method testMultipleRetrieveCache.

public void testMultipleRetrieveCache() {
    String randomApiString = this.getRandomString();
    this.api.saveApi(new ApiResult(0, randomApiString, "privateKey", "", ""));
    for (int i = 0; i < 500; i++) {
        ApiResult apiResult = this.api.getApiByPublicKey(randomApiString);
        assertThat(apiResult.getPublicKey()).isEqualTo(randomApiString);
        assertThat(apiResult.getPrivateKey()).isEqualTo("privateKey");
    }
    this.api.deleteApiByPublicKey(randomApiString);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult)

Example 13 with ApiResult

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

the class ApiTest method testGetAllApi.

public void testGetAllApi() {
    String randomApi1 = this.getRandomString();
    String randomApi2 = this.getRandomString();
    this.api.saveApi(new ApiResult(0, randomApi1, "privateKey", "", ""));
    this.api.saveApi(new ApiResult(0, randomApi2, "privateKey", "", ""));
    assertThat(this.api.getAllApi().size()).isEqualTo(2);
    this.api.deleteApiByPublicKey(randomApi1);
    this.api.deleteApiByPublicKey(randomApi2);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult)

Example 14 with ApiResult

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

the class ApiServiceTest method testCase2.

public void testCase2() {
    Api apiMock = mock(Api.class);
    when(apiMock.getApiByPublicKey("publicKey")).thenReturn(new ApiResult(1, "publicKey", "privateKey", "", ""));
    ApiService service = new ApiService(apiMock);
    boolean actual = service.validateRequest("publicKey", "1577b8c8f5781bf2817a45bfb47ded066c579c37", "testmessage1", ApiService.HmacType.SHA1);
    assertTrue(actual);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult) Api(com.searchcode.app.dao.Api)

Example 15 with ApiResult

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

the class ApiServiceTest method testValidateRequestInCorrectHmac.

public void testValidateRequestInCorrectHmac() {
    Api apiMock = mock(Api.class);
    when(apiMock.getApiByPublicKey("publicKey")).thenReturn(new ApiResult(1, "publicKey", "privateKey", "", ""));
    ApiService service = new ApiService(apiMock);
    boolean actual = service.validateRequest("publicKey", "incorrecthmac", "stringtohmac", ApiService.HmacType.SHA1);
    assertFalse(actual);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult) Api(com.searchcode.app.dao.Api)

Aggregations

ApiResult (com.searchcode.app.model.ApiResult)18 Api (com.searchcode.app.dao.Api)10 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)1