Search in sources :

Example 1 with KeyVal

use of com.meniga.sdk.helpers.KeyVal in project mobile-sdk-android by meniga.

the class MenigaAccountApiTest method shouldFetchMetadataByName.

@Test
public void shouldFetchMetadataByName() throws Exception {
    server.enqueue(new MockResponse());
    MenigaAccount account = MenigaAccountFactory.createAccount();
    Task<KeyVal<String, String>> task = account.fetchMetadataKeyVal("Valid to").getTask();
    task.waitForCompletion();
    RecordedRequest request = server.takeRequest();
    assertThat(request.getPath()).isEqualTo("/v1/accounts/0/metadata/Valid%20to");
    assertThat(request.getMethod()).isEqualTo("GET");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) KeyVal(com.meniga.sdk.helpers.KeyVal) Test(org.junit.Test)

Example 2 with KeyVal

use of com.meniga.sdk.helpers.KeyVal in project mobile-sdk-android by meniga.

the class MenigaAccountApiTest method shouldUpdateMetadata.

@Test
public void shouldUpdateMetadata() throws Exception {
    server.enqueue(new MockResponse());
    MenigaAccount account = MenigaAccountFactory.createAccount();
    Task<KeyVal<String, String>> task = account.updateMetadata(KeyVal.of("Valid to", "01/2100")).getTask();
    task.waitForCompletion();
    RecordedRequest request = server.takeRequest();
    assertThat(request.getPath()).isEqualTo("/v1/accounts/0/metadata");
    assertThat(request.getMethod()).isEqualTo("PUT");
    JsonAssert.with(request.getBody().readUtf8()).assertThat("$.name", equalTo("Valid to")).assertThat("$.value", equalTo("01/2100"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) KeyVal(com.meniga.sdk.helpers.KeyVal) Test(org.junit.Test)

Example 3 with KeyVal

use of com.meniga.sdk.helpers.KeyVal in project mobile-sdk-android by meniga.

the class MenigaIdNameKeyValConverter method responseBodyConverter.

@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
    Type typeListOfNetWorthType = new TypeToken<List<KeyVal<Long, String>>>() {
    }.getType();
    if (typeListOfNetWorthType.equals(type)) {
        return new Converter<ResponseBody, Object>() {

            @Override
            public Object convert(ResponseBody value) throws IOException {
                List<KeyVal<Long, String>> list = new ArrayList<>();
                JsonArray arr = getAsArray(value.byteStream());
                for (int i = 0; i < arr.size(); i++) {
                    JsonObject entry = (JsonObject) arr.get(i);
                    KeyVal<Long, String> item = new KeyVal<>(entry.get("id").getAsLong(), entry.get("name").getAsString());
                    list.add(item);
                }
                return list;
            }
        };
    }
    return null;
}
Also used : KeyVal(com.meniga.sdk.helpers.KeyVal) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ResponseBody(okhttp3.ResponseBody) JsonArray(com.google.gson.JsonArray) Type(java.lang.reflect.Type) Converter(retrofit2.Converter) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with KeyVal

use of com.meniga.sdk.helpers.KeyVal in project mobile-sdk-android by meniga.

the class MenigaAccountApiTest method shouldFetchMetadata.

@Test
public void shouldFetchMetadata() throws Exception {
    MenigaAccount account = MenigaAccountFactory.createAccount();
    server.enqueue(mockResponse("accountmetadata.json"));
    Task<List<KeyVal<String, String>>> task = account.fetchMetadata().getTask();
    task.waitForCompletion();
    RecordedRequest request = server.takeRequest();
    assertThat(request.getPath()).isEqualTo("/v1/accounts/0/metadata");
    assertThat(request.getMethod()).isEqualTo("GET");
    List<KeyVal<String, String>> result = task.getResult();
    assertThat(result.get(0).getKey()).isEqualTo("Card holder");
    assertThat(result.get(0).getValue()).isEqualTo("John Bob");
    assertThat(result.get(1).getKey()).isEqualTo("Card number");
    assertThat(result.get(1).getValue()).isEqualTo("1234 XXXX XXXX 5432");
    assertThat(result.get(2).getKey()).isEqualTo("Valid to");
    assertThat(result.get(2).getValue()).isEqualTo("12/2026");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) KeyVal(com.meniga.sdk.helpers.KeyVal) List(java.util.List) Test(org.junit.Test)

Example 5 with KeyVal

use of com.meniga.sdk.helpers.KeyVal in project mobile-sdk-android by meniga.

the class MenigaRealmAuthParameter method getDropDownValues.

public List<KeyVal<String, String>> getDropDownValues() {
    JsonParser parser = new JsonParser();
    JsonElement elements = parser.parse(dropDownValues);
    JsonArray values = elements.getAsJsonArray();
    List<KeyVal<String, String>> entries = new ArrayList<>();
    for (int i = 0; i < values.size(); i++) {
        JsonObject item = values.get(i).getAsJsonObject();
        KeyVal<String, String> entry = new KeyVal<>(item.get("Name").getAsString(), item.get("Value").getAsString());
        entries.add(entry);
    }
    return entries;
}
Also used : JsonArray(com.google.gson.JsonArray) KeyVal(com.meniga.sdk.helpers.KeyVal) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Aggregations

KeyVal (com.meniga.sdk.helpers.KeyVal)5 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 Test (org.junit.Test)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 JsonElement (com.google.gson.JsonElement)1 JsonParser (com.google.gson.JsonParser)1 Type (java.lang.reflect.Type)1 ResponseBody (okhttp3.ResponseBody)1 Converter (retrofit2.Converter)1