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));
}
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);
});
}
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);
});
}
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);
}
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));
}
Aggregations