Search in sources :

Example 1 with ContentType

use of io.restassured.http.ContentType in project bisq-api by mrosseel.

the class PaymentAccountIT method create_validSpecificBanks_returnsCreatedAccount.

@InSequence(2)
@Test
public void create_validSpecificBanks_returnsCreatedAccount() {
    final int alicePort = getAlicePort();
    final Faker faker = new Faker();
    final SpecificBanksAccountPaymentAccount accountToCreate = new SpecificBanksAccountPaymentAccount();
    ApiTestHelper.randomizeAccountPayload(accountToCreate);
    accountToCreate.accountNr = faker.finance().iban();
    accountToCreate.accountType = faker.options().option("savings", "avista");
    accountToCreate.bankId = faker.finance().bic();
    accountToCreate.bankName = faker.company().name();
    accountToCreate.branchId = faker.company().buzzword();
    accountToCreate.countryCode = faker.address().countryCode();
    accountToCreate.holderName = faker.name().fullName();
    accountToCreate.holderTaxId = faker.finance().creditCard();
    accountToCreate.acceptedBanks = Arrays.asList(faker.finance().bic(), faker.finance().bic());
    final String acceptedBanks = accountToCreate.acceptedBanks.stream().reduce((i, a) -> a.length() > 0 ? i + ", " + a : i).orElse("");
    final String expectedPaymentDetails = String.format("Transfers with specific banks - Holder name: %s, Bank name: %s, Bank ID (BIC/SWIFT): %s, Branch no.: %s, Account no. (IBAN): %s, Country of bank: %s, Accepted banks: %s", accountToCreate.holderName, accountToCreate.bankName, accountToCreate.bankId, accountToCreate.branchId, accountToCreate.accountNr, CountryUtil.getNameByCode(accountToCreate.countryCode), acceptedBanks);
    given().port(alicePort).contentType(ContentType.JSON).body(accountToCreate).when().post("/api/v1/payment-accounts").then().statusCode(200).and().body("id", isA(String.class)).and().body("paymentMethod", equalTo(accountToCreate.paymentMethod)).and().body("accountName", equalTo(accountToCreate.accountName)).and().body("paymentDetails", equalTo(expectedPaymentDetails)).and().body("selectedTradeCurrency", equalTo(accountToCreate.selectedTradeCurrency)).and().body("tradeCurrencies", equalTo(accountToCreate.tradeCurrencies)).and().body("accountNr", equalTo(accountToCreate.accountNr)).and().body("accountType", equalTo(accountToCreate.accountType)).and().body("bankId", equalTo(accountToCreate.bankId)).and().body("bankName", equalTo(accountToCreate.bankName)).and().body("branchId", equalTo(accountToCreate.branchId)).and().body("countryCode", equalTo(accountToCreate.countryCode)).and().body("holderName", equalTo(accountToCreate.holderName)).and().body("holderTaxId", equalTo(accountToCreate.holderTaxId)).and().body("acceptedBanks", equalTo(accountToCreate.acceptedBanks)).and().body("size()", equalTo(15));
}
Also used : Container(org.arquillian.cube.docker.impl.client.containerobject.dsl.Container) Arrays(java.util.Arrays) Arquillian(org.jboss.arquillian.junit.Arquillian) io.bisq.api.model.payment(io.bisq.api.model.payment) CountryUtil(io.bisq.common.locale.CountryUtil) ContentType(io.restassured.http.ContentType) RunWith(org.junit.runner.RunWith) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence) DockerContainer(org.arquillian.cube.docker.impl.client.containerobject.dsl.DockerContainer) List(java.util.List) Faker(com.github.javafaker.Faker) RestAssured.given(io.restassured.RestAssured.given) Assert(org.junit.Assert) Collections(java.util.Collections) Faker(com.github.javafaker.Faker) InSequence(org.jboss.arquillian.junit.InSequence) Test(org.junit.Test)

Example 2 with ContentType

use of io.restassured.http.ContentType in project rest-assured by rest-assured.

the class EncoderRegistry method getAt.

/**
 * Retrieve a encoder for the given content-type.  This
 * is called by HTTPBuilder to retrieve the correct encoder for a given
 * content-type.  The encoder is then used to serialize the request data
 * in the request body.
 *
 * @param contentType
 * @return encoder that can interpret the given content type,
 * or null.
 */
public Closure getAt(Object contentType) {
    String ct = contentType.toString();
    int idx = ct.indexOf(';');
    if (idx > 0)
        ct = ct.substring(0, idx);
    Closure closure = registeredEncoders.get(ct);
    if (closure == null) {
        final ContentType foundCt = ContentType.fromContentType(ct);
        if (foundCt != null) {
            closure = registeredEncoders.get(foundCt.toString());
        }
    }
    // We couldn't find an explicit encoder for the given content-type so try to find a match
    if (closure == null) {
        closure = tryToFindMatchingEncoder(ct);
    }
    // If no encoder could be found then use binary
    if (closure == null) {
        return getAt(ContentType.BINARY.toString());
    }
    return closure;
}
Also used : MethodClosure(org.codehaus.groovy.runtime.MethodClosure) Closure(groovy.lang.Closure) ContentType(io.restassured.http.ContentType) FileReader.readToString(io.restassured.internal.support.FileReader.readToString) GString(groovy.lang.GString)

Example 3 with ContentType

use of io.restassured.http.ContentType in project bisq-api by mrosseel.

the class PaymentAccountIT method create_validSpecificBanks_returnsCreatedAccount.

@InSequence(2)
@Test
public void create_validSpecificBanks_returnsCreatedAccount() {
    final int alicePort = getAlicePort();
    final Faker faker = new Faker();
    final SpecificBanksAccountPaymentAccount accountToCreate = new SpecificBanksAccountPaymentAccount();
    ApiTestHelper.randomizeAccountPayload(accountToCreate);
    accountToCreate.accountNr = faker.finance().iban();
    accountToCreate.accountType = faker.options().option("savings", "avista");
    accountToCreate.bankId = faker.finance().bic();
    accountToCreate.bankName = faker.company().name();
    accountToCreate.branchId = faker.company().buzzword();
    accountToCreate.countryCode = "AT";
    accountToCreate.holderName = faker.name().fullName();
    accountToCreate.holderTaxId = faker.finance().creditCard();
    accountToCreate.acceptedBanks = Arrays.asList(faker.finance().bic(), faker.finance().bic());
    final String acceptedBanks = accountToCreate.acceptedBanks.stream().reduce((i, a) -> a.length() > 0 ? i + ", " + a : i).orElse("");
    final String expectedPaymentDetails = String.format("Transfers with specific banks - Holder name: %s, Bank name: %s, Bank ID (BIC/SWIFT): %s, Branch no.: %s, Account no. (IBAN): %s, Country of bank: %s, Accepted banks: %s", accountToCreate.holderName, accountToCreate.bankName, accountToCreate.bankId, accountToCreate.branchId, accountToCreate.accountNr, CountryUtil.getNameByCode(accountToCreate.countryCode), acceptedBanks);
    given().port(alicePort).contentType(ContentType.JSON).body(accountToCreate).when().post("/api/v1/payment-accounts").then().statusCode(200).and().body("id", isA(String.class)).and().body("paymentMethod", equalTo(accountToCreate.paymentMethod)).and().body("accountName", equalTo(accountToCreate.accountName)).and().body("paymentDetails", equalTo(expectedPaymentDetails)).and().body("selectedTradeCurrency", equalTo(accountToCreate.selectedTradeCurrency)).and().body("tradeCurrencies", equalTo(accountToCreate.tradeCurrencies)).and().body("accountNr", equalTo(accountToCreate.accountNr)).and().body("accountType", equalTo(accountToCreate.accountType)).and().body("bankId", equalTo(accountToCreate.bankId)).and().body("bankName", equalTo(accountToCreate.bankName)).and().body("branchId", equalTo(accountToCreate.branchId)).and().body("countryCode", equalTo(accountToCreate.countryCode)).and().body("holderName", equalTo(accountToCreate.holderName)).and().body("holderTaxId", equalTo(accountToCreate.holderTaxId)).and().body("acceptedBanks", equalTo(accountToCreate.acceptedBanks)).and().body("size()", equalTo(15));
}
Also used : Container(org.arquillian.cube.docker.impl.client.containerobject.dsl.Container) Arrays(java.util.Arrays) Arquillian(org.jboss.arquillian.junit.Arquillian) ContentType(io.restassured.http.ContentType) RunWith(org.junit.runner.RunWith) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) network.bisq.api.model.payment(network.bisq.api.model.payment) InSequence(org.jboss.arquillian.junit.InSequence) DockerContainer(org.arquillian.cube.docker.impl.client.containerobject.dsl.DockerContainer) List(java.util.List) Faker(com.github.javafaker.Faker) CountryUtil(bisq.core.locale.CountryUtil) RestAssured.given(io.restassured.RestAssured.given) Assert(org.junit.Assert) Collections(java.util.Collections) Faker(com.github.javafaker.Faker) InSequence(org.jboss.arquillian.junit.InSequence) Test(org.junit.Test)

Aggregations

ContentType (io.restassured.http.ContentType)3 Faker (com.github.javafaker.Faker)2 RestAssured.given (io.restassured.RestAssured.given)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Container (org.arquillian.cube.docker.impl.client.containerobject.dsl.Container)2 DockerContainer (org.arquillian.cube.docker.impl.client.containerobject.dsl.DockerContainer)2 Matchers (org.hamcrest.Matchers)2 Arquillian (org.jboss.arquillian.junit.Arquillian)2 InSequence (org.jboss.arquillian.junit.InSequence)2 Assert (org.junit.Assert)2 Test (org.junit.Test)2 RunWith (org.junit.runner.RunWith)2 CountryUtil (bisq.core.locale.CountryUtil)1 Closure (groovy.lang.Closure)1 GString (groovy.lang.GString)1 io.bisq.api.model.payment (io.bisq.api.model.payment)1 CountryUtil (io.bisq.common.locale.CountryUtil)1 FileReader.readToString (io.restassured.internal.support.FileReader.readToString)1