use of net.andreinc.mockneat.MockNeat in project mockneat by nomemory.
the class MockUnitExamplesMapToString method main.
public static void main(String[] args) {
MockNeat m = MockNeat.threadLocal();
MockUnitString mus = m.ints().mapToString();
String integer = mus.val();
System.out.println(integer);
MockUnitString oddOrEven = m.ints().mapToString(i -> i % 2 == 0 ? "even" : "odd");
List<String> oddOrEvenList = oddOrEven.list(10).val();
System.out.println(oddOrEvenList);
}
use of net.andreinc.mockneat.MockNeat in project mockneat by nomemory.
the class MockUnitsExample01 method main.
public static void main(String[] args) {
MockNeat m = MockNeat.threadLocal();
// A mockUnit that can generate integers
MockUnit<Integer> intMockUnit = m.ints().bound(100);
// A mockUnit that can generate list of integers
MockUnit<List<Integer>> listMockUnit = intMockUnit.list(100);
// Generating an integer with the mockUnit
int integer = intMockUnit.val();
// Generating a list of integers
List<Integer> list = listMockUnit.val();
// Generating another list of integers
List<Integer> list2 = listMockUnit.val();
List<Integer[]> listArray = m.ints().range(0, 100).array(100).list(ArrayList.class, 100).val();
List<String> l = m.fmt("{ username: #{user}, email: #{email} }").param("user", m.users()).param("email", m.emails().domain("gameloft.com")).list(100).val();
System.out.println(l);
}
use of net.andreinc.mockneat.MockNeat in project mockneat by nomemory.
the class QuickExamples method main.
public static void main(String[] args) {
MockNeat mock = MockNeat.threadLocal();
// Generating an arbitrary integer in the range [200, 100)
Integer int1 = mock.ints().range(100, 200).val();
// Generating an AMEX or a MasterCard credit card number
String amex = mock.creditCards().types(AMERICAN_EXPRESS, MASTERCARD).val();
// Generate an IPV4 address of Class A
String ipv4ClassA = mock.ipv4s().type(IPv4Type.CLASS_A).val();
// Generate a random name with a 50% chance of a having a midle name
String fullName = mock.names().full().val();
MockUnitInt integers = mock.ints().bound(10);
int[] arr1 = integers.arrayPrimitive(10).val();
Integer[] arr2 = integers.array(10).val();
List<Integer> list1 = integers.list(LinkedList.class, 10).val();
}
use of net.andreinc.mockneat.MockNeat in project mockneat by nomemory.
the class UsersGroupsAssoc method main.
public static void main(String[] args) {
MockNeat mock = MockNeat.threadLocal();
// Create a list of 5 groups
List<Group> groups = mock.reflect(Group.class).field("id", mock.longSeq().start(100).increment(100)).field("name", mock.regex("Group [A-Z]{3}[0-9]{2}")).list(5).val();
System.out.println(groups);
List<User> users = mock.reflect(User.class).field("id", mock.longSeq()).field("groupId", mock.from(groups).map(Group::getId)).field("email", mock.emails()).list(100).val();
System.out.println(users);
}
use of net.andreinc.mockneat.MockNeat in project mockneat by nomemory.
the class HrSchema method main.
public static void main(String[] args) {
MockNeat m = MockNeat.threadLocal();
// Generate Regions
List<Region> regions = m.reflect(Region.class).field("id", m.longSeq()).field("name", m.seq(REGIONS)).list(REGIONS.size()).val();
// Generate Countries
final int totalCountries = 241;
List<Country> countries = m.reflect(Country.class).field("id", m.seq(DictType.COUNTRY_ISO_CODE_2)).field("name", m.seq(DictType.COUNTRY_NAME).mapToString().replaceAll("'", "''")).field("regionId", m.from(regions).map(Region::getId)).list(totalCountries).val();
// Generate Locations
int totalLocations = 200;
List<Location> locations = m.reflect(Location.class).field("id", m.longSeq().start(1000).increment(100)).field("street", streeNameGenerator()).field("city", m.cities().capitals()).field("postalCode", m.regex("[A-Z]{1,3}[0-9]{1,2}[A-Z]{1,2}[0-9]{3,5}")).field("countryId", m.from(countries).map(Country::getId)).map(HrSchema::cityWithCountryId).list(totalLocations).val();
// Departments
int totalDepartments = 16;
List<Departments> departments = m.reflect(Departments.class).field("id", m.longSeq().start(10).increment(10)).field("depName", m.seq(DEPARTMENTS)).field("locationId", m.from(locations).map(Location::getId)).list(16).val();
// Employees
int totalEmployees = 1500;
LocalDate minDate = LocalDate.of(1990, 1, 1);
List<Employee> employees = m.reflect(Employee.class).field("id", m.longSeq().start(1)).field("firstName", m.names().first()).field("lastName", m.names().last()).field("email", m.emails()).field("phoneNumber", m.regex("([0-9]{3}) [0-9]{10}")).field("hireDate", m.localDates().past(minDate).toUtilDate()).field("salary", m.doubles().range(2000.0, 10000.0)).field("depId", m.from(departments).map(Departments::getId)).map(HrSchema::populateHireDateStr).list(totalEmployees).val();
// Decide who is manager
int totalNumManagers = 100;
List<Long> managersIds = m.from(employees).map(Employee::getId).list(totalNumManagers).val().stream().distinct().collect(Collectors.toList());
// Set Up managers for employees
employees.forEach(e -> {
long empId = e.getId();
long mngId = e.getId();
// id and managerId
while (mngId == empId) mngId = m.from(managersIds).val();
e.setManagerId(mngId);
});
// Set Up Managers for departments
MockUnit<Long> managersIdSeq = m.seq(managersIds);
departments.forEach(d -> d.setManagerId(managersIdSeq.val()));
// Print everything
System.out.println("SET FOREIGN_KEY_CHECKS = 0;");
printSql("INSERT INTO regions VALUE (#{region.id}, '#{region.name}');", "region", regions);
printSql("INSERT INTO countries VALUES('#{country.id}', '#{country.name}', #{country.regionId});", "country", countries);
printSql("INSERT INTO locations VALUES(#{l.id}, '#{l.street}', '#{l.postalCode}', '#{l.city}', #{l.state}, '#{l.countryId}');", "l", locations);
printSql("INSERT INTO departments VALUES(#{dep.id}, '#{dep.depName}', #{dep.managerId}, #{dep.locationId});", "dep", departments);
printSql("INSERT INTO employees VALUES(#{e.id}, '#{e.firstName}', '#{e.lastName}', '#{e.email}', '#{e.phoneNumber}', #{e.hireDateStr}, #{e.salary}, #{e.managerId}, #{e.depId});", "e", employees);
System.out.println("SET FOREIGN_KEY_CHECKS = 1;");
System.out.println("COMMIT;");
}
Aggregations