Search in sources :

Example 1 with MenigaTransactionPage

use of com.meniga.sdk.models.transactions.MenigaTransactionPage in project mobile-sdk-android by meniga.

the class MenigaTransactionOperationsMock method splitTransaction.

@Override
public Result<List<MenigaTransaction>> splitTransaction(long parentId, MenigaDecimal amount, String text, long categoryId, boolean isFlagged) {
    TaskCompletionSource<List<MenigaTransaction>> task = new TaskCompletionSource<>();
    task.setResult(new MenigaTransactionPage());
    return new MTask<>(task.getTask(), task);
}
Also used : TaskCompletionSource(com.meniga.sdk.providers.tasks.TaskCompletionSource) MTask(com.meniga.sdk.helpers.MTask) ArrayList(java.util.ArrayList) List(java.util.List) MenigaTransactionPage(com.meniga.sdk.models.transactions.MenigaTransactionPage)

Example 2 with MenigaTransactionPage

use of com.meniga.sdk.models.transactions.MenigaTransactionPage in project mobile-sdk-android by meniga.

the class MenigaTransactionsTest method test.

@Test
public void test() throws Exception {
    // Create a MockWebServer. These are lean enough that you can create a new
    // instance for every unit test.
    MockWebServer server = new MockWebServer();
    // Schedule some responses.
    server.enqueue(new MockResponse().setBody(FileImporter.getJsonFileFromRaw("transactionsPage.json")));
    // Start the server.
    server.start();
    // Ask the server for its URL. You'll need this to make HTTP requests.
    HttpUrl baseUrl = server.url("/v1");
    MenigaSettings settings = new MenigaSettings.Builder().endpoint(baseUrl).build();
    MenigaSDK.init(settings);
    Task<MenigaTransactionPage> transactionsTask = MenigaTransaction.fetch(new TransactionsFilter.Builder().build()).getTask();
    transactionsTask.waitForCompletion();
    MenigaTransactionPage transactionPage = transactionsTask.getResult();
    Assert.assertNotNull(transactionPage);
    // Shut down the server. Instances cannot be reused.
    server.shutdown();
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) MockWebServer(okhttp3.mockwebserver.MockWebServer) TransactionsFilter(com.meniga.sdk.models.transactions.TransactionsFilter) MenigaTransactionPage(com.meniga.sdk.models.transactions.MenigaTransactionPage) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 3 with MenigaTransactionPage

use of com.meniga.sdk.models.transactions.MenigaTransactionPage in project mobile-sdk-android by meniga.

the class MenigaTransactionOperationsMock method gson.

private MenigaTransactionPage gson() {
    Gson gson = GsonProvider.getGsonBuilder();
    MenigaTransactionPage transactionPage = null;
    try {
        InputStream inputStream = FileImporter.getInputStreamFromRaw("transactions.json");
        MenigaTransaction[] arr = gson.fromJson(MenigaConverter.getAsArray(inputStream), MenigaTransaction[].class);
        transactionPage = new MenigaTransactionPage();
        transactionPage.addAll(Arrays.asList(arr));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return transactionPage;
}
Also used : MenigaTransaction(com.meniga.sdk.models.transactions.MenigaTransaction) InputStream(java.io.InputStream) Gson(com.google.gson.Gson) IOException(java.io.IOException) MenigaTransactionPage(com.meniga.sdk.models.transactions.MenigaTransactionPage)

Aggregations

MenigaTransactionPage (com.meniga.sdk.models.transactions.MenigaTransactionPage)3 Gson (com.google.gson.Gson)1 MTask (com.meniga.sdk.helpers.MTask)1 MenigaTransaction (com.meniga.sdk.models.transactions.MenigaTransaction)1 TransactionsFilter (com.meniga.sdk.models.transactions.TransactionsFilter)1 TaskCompletionSource (com.meniga.sdk.providers.tasks.TaskCompletionSource)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HttpUrl (okhttp3.HttpUrl)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 MockWebServer (okhttp3.mockwebserver.MockWebServer)1 Test (org.junit.Test)1