Search in sources :

Example 1 with Group

use of com.yandex.money.api.model.showcase.components.containers.Group in project yandex-money-sdk-java by yandex-money.

the class ShowcaseParserTest method checkForm.

private void checkForm(Group form) {
    assertNotNull(form);
    assertEquals(form.layout, Group.Layout.VERTICAL);
    List<Component> components = form.items;
    assertEquals(components.size(), 13);
    Component component = components.get(0);
    assertTrue(component instanceof Text);
    Text text = (Text) component;
    assertEquals(text.valueAutoFill, Parameter.AutoFill.CURRENT_USER_ACCOUNT);
    checkComponentFields(text, "name1", "required");
    assertEquals(text.minLength, Integer.valueOf(2));
    assertEquals(text.maxLength, Integer.valueOf(10));
    assertEquals(text.pattern, "\\D*?");
    component = components.get(1);
    assertTrue(component instanceof Number);
    Number number = (Number) component;
    checkComponentFields(number, "name2", "10.00");
    checkNumberField(number);
    component = components.get(2);
    assertTrue(component instanceof Amount);
    Amount amount = (Amount) component;
    checkComponentFields(amount, "name3", "10.00");
    checkNumberField(amount);
    assertEquals(amount.currency, Currency.RUB);
    checkFee(amount.fee);
    component = components.get(3);
    assertTrue(component instanceof Email);
    checkComponentFields(component, "name4", "vyasevich@yamoney.ru");
    component = components.get(4);
    assertTrue(component instanceof Tel);
    checkComponentFields(component, "name5", "79876543210");
    component = components.get(5);
    assertTrue(component instanceof Checkbox);
    Checkbox checkbox = (Checkbox) component;
    checkComponentFields(component, "name6", "true");
    assertTrue(checkbox.checked);
    component = components.get(6);
    assertTrue(component instanceof Date);
    Date date = (Date) component;
    checkComponentFields(date, "name7", "2005-01-01");
    checkDate(date);
    component = components.get(7);
    assertTrue(component instanceof Month);
    Month month = (Month) component;
    checkComponentFields(month, "name8", "2005-01");
    checkDate(month);
    component = components.get(8);
    assertTrue(component instanceof Select);
    Select select = (Select) component;
    checkComponentFields(select, "name9", "value2");
    assertEquals(select.style, Select.Style.RADIO_GROUP);
    checkOptions(select.options);
    component = components.get(9);
    assertTrue(component instanceof TextArea);
    TextArea textArea = (TextArea) component;
    checkComponentFields(textArea, "name10", "value");
    assertEquals(textArea.minLength, Integer.valueOf(2));
    assertEquals(textArea.maxLength, Integer.valueOf(10));
    component = components.get(10);
    assertTrue(component instanceof Submit);
    Submit submit = (Submit) component;
    assertEquals(submit.hint, "hint");
    assertEquals(submit.label, "label");
    assertEquals(submit.alert, "alert");
    assertTrue(submit.required);
    assertFalse(submit.readonly);
    component = components.get(11);
    assertTrue(component instanceof Group);
    Group group = (Group) component;
    assertEquals(group.label, "label");
    assertEquals(group.layout, Group.Layout.HORIZONTAL);
    assertNotNull(group.items);
    assertEquals(group.items.size(), 2);
    component = components.get(12);
    assertTrue(component instanceof Paragraph);
    Paragraph paragraph = (Paragraph) component;
    assertEquals(paragraph.label, "label");
    List<TextBlock> items = paragraph.items;
    assertNotNull(items);
    assertEquals(items.size(), 3);
    TextBlock block = items.get(0);
    assertEquals(block.text, "Text with ");
    block = items.get(1);
    assertEquals(block.text, "link");
    assertTrue(block instanceof TextBlock.WithLink);
    TextBlock.WithLink link = (TextBlock.WithLink) block;
    assertEquals(link.link, "https://money.yandex.ru");
    block = items.get(2);
    assertEquals(block.text, ".");
}
Also used : Group(com.yandex.money.api.model.showcase.components.containers.Group) Email(com.yandex.money.api.model.showcase.components.uicontrols.Email) TextArea(com.yandex.money.api.model.showcase.components.uicontrols.TextArea) Amount(com.yandex.money.api.model.showcase.components.uicontrols.Amount) Text(com.yandex.money.api.model.showcase.components.uicontrols.Text) Date(com.yandex.money.api.model.showcase.components.uicontrols.Date) Paragraph(com.yandex.money.api.model.showcase.components.containers.Paragraph) Month(com.yandex.money.api.model.showcase.components.uicontrols.Month) Number(com.yandex.money.api.model.showcase.components.uicontrols.Number) Checkbox(com.yandex.money.api.model.showcase.components.uicontrols.Checkbox) Select(com.yandex.money.api.model.showcase.components.uicontrols.Select) Submit(com.yandex.money.api.model.showcase.components.uicontrols.Submit) Tel(com.yandex.money.api.model.showcase.components.uicontrols.Tel) Component(com.yandex.money.api.model.showcase.components.Component) TextBlock(com.yandex.money.api.model.showcase.components.TextBlock)

Example 2 with Group

use of com.yandex.money.api.model.showcase.components.containers.Group in project yandex-money-sdk-java by yandex-money.

the class ShowcaseParserTest method checkOptions.

private void checkOptions(List<Select.Option> options) {
    assertEquals(options.size(), 3);
    Select.Option option = options.get(0);
    assertEquals(option.label, "label1");
    assertEquals(option.value, "value1");
    assertNull(option.group);
    option = options.get(1);
    assertEquals(option.label, "label2");
    assertEquals(option.value, "value2");
    assertNull(option.group);
    option = options.get(2);
    assertEquals(option.label, "label3");
    assertEquals(option.value, "value3");
    Group group = option.group;
    assertNotNull(group);
    List<Component> items = group.items;
    assertEquals(items.size(), 1);
    Component component = items.get(0);
    assertTrue(component instanceof Text);
    ParameterControl control = (ParameterControl) component;
    assertEquals(control.name, "name14");
    assertEquals(control.getValue(), "readonly");
    assertEquals(control.hint, "hint");
    assertEquals(control.label, "label");
    assertEquals(control.alert, "alert");
    assertFalse(control.required);
    assertTrue(control.readonly);
}
Also used : Group(com.yandex.money.api.model.showcase.components.containers.Group) Select(com.yandex.money.api.model.showcase.components.uicontrols.Select) ParameterControl(com.yandex.money.api.model.showcase.components.uicontrols.ParameterControl) Text(com.yandex.money.api.model.showcase.components.uicontrols.Text) Component(com.yandex.money.api.model.showcase.components.Component)

Example 3 with Group

use of com.yandex.money.api.model.showcase.components.containers.Group in project yandex-money-sdk-java by yandex-money.

the class ShowcaseProcessTest method getEmptyShowcase.

private static Showcase getEmptyShowcase() {
    Group.Builder builder = new Group.Builder();
    Group group = builder.create();
    return new Showcase.Builder().setTitle("foo").setErrors(Collections.<Showcase.Error>emptyList()).setForm(group).setHiddenFields(Collections.<String, String>emptyMap()).setMoneySources(Collections.<AllowedMoneySource>emptyList()).create();
}
Also used : Group(com.yandex.money.api.model.showcase.components.containers.Group) Showcase(com.yandex.money.api.model.showcase.Showcase) AllowedMoneySource(com.yandex.money.api.model.AllowedMoneySource)

Example 4 with Group

use of com.yandex.money.api.model.showcase.components.containers.Group in project yandex-money-sdk-java by yandex-money.

the class ShowcaseTypeAdapter method deserialize.

@Override
public Showcase deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject object = json.getAsJsonObject();
    Group form = null;
    JsonArray array = object.getAsJsonArray(MEMBER_FORM);
    if (array != null) {
        form = ListDelegate.deserialize(array, context);
    }
    List<AllowedMoneySource> moneySources = context.deserialize(object.get(MEMBER_MONEY_SOURCE), new TypeToken<List<AllowedMoneySource>>() {
    }.getType());
    List<Error> errors = ErrorTypeAdapter.getInstance().fromJson(object.getAsJsonArray(MEMBER_ERROR));
    return new Showcase.Builder().setTitle(getString(object, MEMBER_TITLE)).setHiddenFields(getNotNullMap(object, MEMBER_HIDDEN_FIELDS)).setForm(form).setMoneySources(toEmptyListIfNull(moneySources)).setErrors(toEmptyListIfNull(errors)).create();
}
Also used : JsonArray(com.google.gson.JsonArray) Group(com.yandex.money.api.model.showcase.components.containers.Group) AllowedMoneySource(com.yandex.money.api.model.AllowedMoneySource) TypeToken(com.google.gson.reflect.TypeToken) JsonObject(com.google.gson.JsonObject) JsonUtils.toJsonObject(com.yandex.money.api.typeadapters.JsonUtils.toJsonObject) Error(com.yandex.money.api.model.showcase.Showcase.Error)

Example 5 with Group

use of com.yandex.money.api.model.showcase.components.containers.Group in project yandex-money-sdk-java by yandex-money.

the class SelectTypeAdapter method deserialize.

@Override
protected void deserialize(JsonObject src, Select.Builder builder, JsonDeserializationContext context) {
    for (JsonElement item : src.getAsJsonArray(MEMBER_OPTIONS)) {
        JsonObject itemObject = item.getAsJsonObject();
        JsonElement jsonGroup = itemObject.get(MEMBER_GROUP);
        Group group = null;
        if (jsonGroup != null) {
            group = ListDelegate.deserialize(jsonGroup.getAsJsonArray(), context);
        }
        Select.Option option = new Select.Option(itemObject.get(MEMBER_LABEL).getAsString(), itemObject.get(MEMBER_VALUE).getAsString(), group);
        builder.addOption(option);
    }
    builder.setStyle(Select.Style.parse(getString(src, MEMBER_STYLE)));
    super.deserialize(src, builder, context);
}
Also used : Group(com.yandex.money.api.model.showcase.components.containers.Group) JsonElement(com.google.gson.JsonElement) Select(com.yandex.money.api.model.showcase.components.uicontrols.Select) JsonObject(com.google.gson.JsonObject)

Aggregations

Group (com.yandex.money.api.model.showcase.components.containers.Group)6 Component (com.yandex.money.api.model.showcase.components.Component)3 Select (com.yandex.money.api.model.showcase.components.uicontrols.Select)3 JsonObject (com.google.gson.JsonObject)2 AllowedMoneySource (com.yandex.money.api.model.AllowedMoneySource)2 Showcase (com.yandex.money.api.model.showcase.Showcase)2 Text (com.yandex.money.api.model.showcase.components.uicontrols.Text)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 TypeToken (com.google.gson.reflect.TypeToken)1 Error (com.yandex.money.api.model.showcase.Showcase.Error)1 TextBlock (com.yandex.money.api.model.showcase.components.TextBlock)1 Paragraph (com.yandex.money.api.model.showcase.components.containers.Paragraph)1 Amount (com.yandex.money.api.model.showcase.components.uicontrols.Amount)1 Checkbox (com.yandex.money.api.model.showcase.components.uicontrols.Checkbox)1 Date (com.yandex.money.api.model.showcase.components.uicontrols.Date)1 Email (com.yandex.money.api.model.showcase.components.uicontrols.Email)1 Month (com.yandex.money.api.model.showcase.components.uicontrols.Month)1 Number (com.yandex.money.api.model.showcase.components.uicontrols.Number)1 ParameterControl (com.yandex.money.api.model.showcase.components.uicontrols.ParameterControl)1