Search in sources :

Example 16 with Faker

use of com.github.javafaker.Faker in project java-faker by DiUS.

the class UkLocalDirectivesTest method resolvesDirectivesOnlyInYmlFile.

/**
     * uk is interesting in that it has feminine and masculine prefixes for street names.  the feminine
     * and masculine prefixes are NOT methods on Address though as they only make sense for this locale (and possibly
     * others).  This test shows we can resolve within the yml file without reaching out to any of the {@link Faker}
     * child objects.
     */
@Test
public void resolvesDirectivesOnlyInYmlFile() {
    final Locale uk = new Locale("uk");
    final String streetName = new Faker(uk).address().streetName();
    final ArrayList<String> masc = Lists.newArrayList("пр.", "проспект", "пров.", "провулок");
    final ArrayList<String> fem = Lists.newArrayList("вул.", "вулиця", "пл.", "площа");
    boolean startsWithMascPrefix = false, startsWithFemPrefix = false;
    for (String mascPrefix : masc) {
        startsWithMascPrefix |= streetName.startsWith(mascPrefix);
    }
    for (String femPrefix : fem) {
        startsWithFemPrefix |= streetName.startsWith(femPrefix);
    }
    assertThat("the streetname starts with a fem or masc prefix", startsWithFemPrefix || startsWithMascPrefix, is(true));
}
Also used : Locale(java.util.Locale) Faker(com.github.javafaker.Faker) Test(org.junit.Test)

Example 17 with Faker

use of com.github.javafaker.Faker in project api-snippets by TwilioDevEd.

the class WebApp method main.

public static void main(String[] args) {
    // Serve static files from src/main/resources/public
    staticFileLocation("/public");
    // Create a Faker instance to generate a random username for the connecting user
    Faker faker = new Faker();
    // Create an access token using our Twilio credentials
    get("/token", "application/json", (request, response) -> {
        // Generate a random username for the connecting client
        String identity = faker.name().firstName() + faker.name().lastName() + faker.address().zipCode();
        // Create an endpoint ID which uniquely identifies the user on their current device
        String appName = "TwilioChatDemo";
        String endpointId = appName + ":" + identity + ":" + request.params("device");
        // Fetch environment info
        Map<String, String> env = new HashMap<String, String>();
        Path path = Paths.get(".env");
        Files.lines(path).forEach(s -> {
            String[] keyVal = s.split("=");
            String key = keyVal[0];
            String val = keyVal[1];
            env.put(key, val);
        });
        // Create IP messaging grant
        IpMessagingGrant grant = new IpMessagingGrant();
        grant.setEndpointId(endpointId);
        grant.setServiceSid(env.get("TWILIO_IPM_SERVICE_SID"));
        // Create access token
        AccessToken token = new AccessToken.Builder(System.getenv("TWILIO_ACCOUNT_SID"), System.getenv("TWILIO_API_KEY"), System.getenv("TWILIO_API_SECRET")).identity(identity).grant(grant).build();
        // create JSON response payload
        HashMap<String, String> json = new HashMap<String, String>();
        json.put("identity", identity);
        json.put("token", token.toJwt());
        // Render JSON response
        Gson gson = new Gson();
        return gson.toJson(json);
    });
}
Also used : Path(java.nio.file.Path) IpMessagingGrant(com.twilio.jwt.accesstoken.IpMessagingGrant) Faker(com.github.javafaker.Faker) HashMap(java.util.HashMap) AccessToken(com.twilio.jwt.accesstoken.AccessToken) Gson(com.google.gson.Gson)

Example 18 with Faker

use of com.github.javafaker.Faker in project api-snippets by TwilioDevEd.

the class Webapp method main.

public static void main(String[] args) {
    // Serve static files from src/main/resources/public
    staticFileLocation("/public");
    // Create a Faker instance to generate a random username for the connecting user
    final Faker faker = new Faker();
    // Create an access token using our Twilio credentials
    get("/token", "application/json", (request, response) -> {
        // Generate a random username for the connecting client
        final String identity = faker.firstName() + faker.lastName() + faker.zipCode();
        // Create Twilio Video messaging grant
        final VideoGrant grant = new VideoGrant();
        grant.configurationProfileSid = System.getenv("TWILIO_CONFIGURATION_SID");
        // Create access token
        final AccessToken token = new AccessToken.Builder(System.getenv("TWILIO_ACCOUNT_SID"), System.getenv("TWILIO_API_KEY"), System.getenv("TWILIO_API_SECRET")).identity(identity).grant(grant).build();
        // create JSON response payload 
        final HashMap<String, String> json = new HashMap<String, String>();
        json.put("identity", identity);
        json.put("token", token.toJWT());
        // Render JSON response
        final Gson gson = new Gson();
        return gson.toJson(json);
    });
}
Also used : VideoGrant(com.twilio.sdk.auth.VideoGrant) Faker(com.github.javafaker.Faker) HashMap(java.util.HashMap) AccessToken(com.twilio.sdk.auth.AccessToken) Gson(com.google.gson.Gson)

Example 19 with Faker

use of com.github.javafaker.Faker in project bisq-api by mrosseel.

the class ApiTestHelper method randomizeAccountPayload.

public static void randomizeAccountPayload(PaymentAccount accountToCreate) {
    final Faker faker = new Faker();
    accountToCreate.accountName = faker.commerce().productName();
    accountToCreate.selectedTradeCurrency = faker.options().option("PLN", "USD", "EUR", "GBP");
    accountToCreate.tradeCurrencies = Collections.singletonList(accountToCreate.selectedTradeCurrency);
}
Also used : Faker(com.github.javafaker.Faker)

Example 20 with Faker

use of com.github.javafaker.Faker in project bisq-api by mrosseel.

the class PaymentAccountIT method create_validCashApp_returnsCreatedAccount.

@InSequence(2)
@Test
public void create_validCashApp_returnsCreatedAccount() {
    final int alicePort = getAlicePort();
    final Faker faker = new Faker();
    final CashAppPaymentAccount accountToCreate = new CashAppPaymentAccount();
    ApiTestHelper.randomizeAccountPayload(accountToCreate);
    accountToCreate.cashTag = faker.commerce().promotionCode();
    final String expectedPaymentDetails = String.format("CashApp - Account: %s", accountToCreate.cashTag);
    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("cashTag", equalTo(accountToCreate.cashTag)).and().body("size()", equalTo(7));
}
Also used : Faker(com.github.javafaker.Faker) InSequence(org.jboss.arquillian.junit.InSequence) Test(org.junit.Test)

Aggregations

Faker (com.github.javafaker.Faker)31 Test (org.junit.Test)26 InSequence (org.jboss.arquillian.junit.InSequence)21 Locale (java.util.Locale)4 Gson (com.google.gson.Gson)3 HashMap (java.util.HashMap)3 AccessToken (com.twilio.jwt.accesstoken.AccessToken)2 AbstractFakerTest (com.github.javafaker.AbstractFakerTest)1 IpMessagingGrant (com.twilio.jwt.accesstoken.IpMessagingGrant)1 AccessToken (com.twilio.sdk.auth.AccessToken)1 VideoGrant (com.twilio.sdk.auth.VideoGrant)1 io.bisq.api.model.payment (io.bisq.api.model.payment)1 SepaPaymentAccount (io.bisq.api.model.payment.SepaPaymentAccount)1 CountryUtil (io.bisq.common.locale.CountryUtil)1 RestAssured.given (io.restassured.RestAssured.given)1 ContentType (io.restassured.http.ContentType)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1