AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Java random data generator8/14/2023 ![]() Hopefully this will give you a head start in generating data in development and test environments for new projects. Note that if you intend on replacing the component that generates words, you should have a good collection of words of various lengths from 2 up to say 8 or more characters. AddressDataValues – Generates city names, street names and address suffixes.ContentDataValues.java – Generates words, business types, email domain names and top level domain values.NameDataValues – Generates names and suffix/prefixes.The different pieces that can be replaced are as follows : You can always start working with the default implementation and use a more locale specific implementation if you need it later. To use this new implementation, just create an instance of the data provider and pass it to the instance of the data factory.ĭf.setNameDataValues(new ScandinavianNames()) Obviously, to use all your own names you would add and return values for last name and the suffix/prefix values. for the other values, just use the defaults NameDataValues defaults = new DefaultNameDataValues() delegate to the default implementation for the other values If (estimatedDeliveryDate.before(actualDeliveryDate)) " delivered on " + dateToString(actualDeliveryDate) " deliver by = "+dateToString(estimatedDeliveryDate)+ String msg = "Ordered on "+dateToString(orderDate) + deliver between 2 days prior and 3 days after delivery estimateĭate actualDeliveryDate = df.getDate(estimatedDeliveryDate, -2, 3) estimate delivery 4-10 days after orderingĭate estimatedDeliveryDate = df.getDate(orderDate, 4, 10) Here’s a more complex example that uses different date rules to come up with some complex test data.ĭate orderDate = df.getDateBetween(minDate, maxDate) ![]() You can also specify a negative minimum days value that could return a date prior to the base date or a positive minimum date value to get a later date. In this case, we make the end date within 10 days of the begin date :ĭate end = df.getDate(start, 0, 10) //set end to within 10 days of the start To do this, you can specify the number of days from the base date you want to generate a result. For example, helpdesk support tickets or hotel stays don’t last for years. In many cases, you might want your end date to be only within a few days of the start date. The result is a list of dates where the second date is always later than the first : ("Date range = " + dateToString(start) + " to " + dateToString(end)) In this case, you would plug the start date in as the minimum date value :ĭate end = df.getDateBetween(start, maxDate) Typically, a random date might be constrained by some other date, for example you can’t have an end date that occurs before the start date. ![]() This produces a list of random dates between and the current date. There are a number of features to create dates, the first being creating a random date which is usually in a given sensible date range.ĭate start = df.getDateBetween(minDate, maxDate) ![]() Poulan Insurance located at 816 Cohen Blvd,Lake City,74839Ĭrescent Services located at 1085 Cloveridge Boulevard,Bemiss,08769 Sugar Hill Textiles located at 1141 Loudon Circle,Cordele,83937Īlbany Engineering located at 1185 Grieves Avenue,Sugar Hill,36753 ![]() Uvalda Signs located at 1383 Beam Way,Lyons,19316Īlma Accounting located at 1386 Countiss St,Nashville,14967įort Stewart Engineering located at 1753 Bethesda Rd,Springfield,26306 String address = df.getAddress()+","+df.getCity()+","+df.getNumberText(5) Addresses and business names can be created using the following code : The DataFactory class can generate different types of values, from addresses to random text to random dates, to dates within a fixed time period. String name = df.getFirstName() + " "+ df.getLastName() Now you can create instances of the DataFactory class and create data : To add DataFactory to your maven project, just add it as a dependency in your pom.xml file. It was primarily written for populating database for dev or test environments by providing values for names, addresses, email addresses, phone numbers, text, and dates. DataFactory is a project I just released which allows you to easily generate test data. ![]()
0 Comments
Read More
Leave a Reply. |