Search in sources :

Example 1 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");
    String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    String API_KEY = System.getenv("TWILIO_API_KEY");
    String API_SECRET = System.getenv("TWILIO_API_SECRET");
    String TWILIO_CONFIGURATION_SID = System.getenv("TWILIO_CONFIGURATION_SID");
    // 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 Video grant
        VideoGrant grant = new VideoGrant().setConfigurationProfileSid(TWILIO_CONFIGURATION_SID);
        // Create access token
        AccessToken token = new AccessToken.Builder(ACCOUNT_SID, API_KEY, 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 : Faker(com.github.javafaker.Faker) HashMap(java.util.HashMap) AccessToken(com.twilio.jwt.accesstoken.AccessToken) Gson(com.google.gson.Gson)

Example 2 with Faker

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

the class Issue194SlashFormatRegexIT method enGBZipCodeReturnsProperRegexifiedValue.

@Test
public void enGBZipCodeReturnsProperRegexifiedValue() {
    final Locale uk = new Locale("en-GB");
    final String postalCode = new Faker(uk).address().zipCode();
    assertThat(postalCode, matchesRegularExpression("[A-PR-UWYZ]([A-HK-Y][0-9][ABEHMNPRVWXY0-9]?|[0-9][ABCDEFGHJKPSTUW0-9]?) [0-9][ABD-HJLNP-UW-Z]{2}"));
}
Also used : Locale(java.util.Locale) Faker(com.github.javafaker.Faker) Test(org.junit.Test)

Example 3 with Faker

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

the class Issue194SlashFormatRegexIT method enCAZipCodeReturnsProperRegexifiedValue.

@Test
public void enCAZipCodeReturnsProperRegexifiedValue() {
    final Locale uk = new Locale("en-CA");
    final String postalCode = new Faker(uk).address().zipCode();
    assertThat(postalCode, matchesRegularExpression("[A-CEJ-NPR-TVXY][0-9][A-CEJ-NPR-TV-Z] ?[0-9][A-CEJ-NPR-TV-Z][0-9]"));
}
Also used : Locale(java.util.Locale) Faker(com.github.javafaker.Faker) Test(org.junit.Test)

Example 4 with Faker

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

the class FakeValuesServiceTest method bothify2Args.

@Test
public void bothify2Args() {
    final DummyService dummy = mock(DummyService.class);
    Faker f = new Faker();
    String value = fakeValuesService.resolve("property.bothify_2", dummy, f);
    assertThat(value, matchesRegularExpression("[A-Z]{2}\\d{2}"));
}
Also used : Faker(com.github.javafaker.Faker) AbstractFakerTest(com.github.javafaker.AbstractFakerTest) Test(org.junit.Test)

Example 5 with Faker

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

the class ApiTestHelper method randomValidCreateSepaAccountPayload.

public static SepaPaymentAccount randomValidCreateSepaAccountPayload(String tradeCurrency, String countryCode) {
    final Faker faker = new Faker();
    final SepaPaymentAccount accountToCreate = new SepaPaymentAccount();
    if (null == countryCode)
        countryCode = faker.options().nextElement(CountryUtil.getAllSepaCountries()).code;
    accountToCreate.paymentMethod = PaymentMethod.SEPA_ID;
    accountToCreate.accountName = faker.commerce().productName();
    accountToCreate.bic = faker.finance().bic();
    accountToCreate.iban = faker.finance().iban();
    accountToCreate.holderName = faker.name().fullName();
    accountToCreate.countryCode = countryCode;
    accountToCreate.acceptedCountries = new ArrayList<>(new HashSet<>(Arrays.asList("PL", "GB", countryCode)));
    accountToCreate.selectedTradeCurrency = faker.options().option("PLN", "USD", "EUR", "GBP");
    if (null != tradeCurrency)
        accountToCreate.selectedTradeCurrency = tradeCurrency;
    accountToCreate.tradeCurrencies = Collections.singletonList(accountToCreate.selectedTradeCurrency);
    return accountToCreate;
}
Also used : Faker(com.github.javafaker.Faker) SepaPaymentAccount(io.bisq.api.model.payment.SepaPaymentAccount)

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