public static List<Product> create( EntityManager entityManager, int numProducts, int numChildComponentsEach) { List<Product> mocks = new ArrayList<Product>(numProducts); for (int x = 0; x < numProducts; ++x) { Product mock = populate(new Product()); if (entityManager != null) { entityManager.persist(mock); Profile defaultAssignee = MockProfileFactory.create(entityManager); List<Component> components = MockComponentFactory.createWithProduct(entityManager, numChildComponentsEach, mock); for (Component component : components) { component.setInitialOwner(defaultAssignee); defaultAssignee.getInitialOwnerComponents().add(component); component.setProduct(mock); mock.getComponents().add(component); entityManager.persist(component); } Milestone defaultMilestone = new Milestone(); defaultMilestone.setProduct(mock); mock.getMilestones().add(defaultMilestone); defaultMilestone.setValue("---"); defaultMilestone.setSortkey((short) 0); entityManager.persist(defaultMilestone); mock.setDefaultmilestone(defaultMilestone.getValue()); } mocks.add(mock); } return mocks; }
private static synchronized Product populate(Product product) { int index = ++created; product.setName("Product" + index); product.setDescription("A product description " + index); product.setDefaultmilestone("---"); product.setClassifications(createClassification(index)); product.getClassifications().getProductses().add(product); return product; }