public Artifact getArtifact(int counter) { Artifact cogs = new Artifact(); cogs.setId(counter); if (counter % 5 == 0) { cogs.setName("Cogs special"); if (counter % 2 == 0) { Company acme = new Company(); acme.setName("Acme special, Inc."); acme.setWebsite("http://www.acme special.com"); acme.setLatitude(41.998 + counter); acme.setLongitude(-87.966 + counter); cogs.setManufacturer(acme); } else { Company widgets = new Company(); widgets.setName("Widgets counter Inc."); widgets.setWebsite("http://www.widgets counter.com"); widgets.setLatitude(41.998 + counter); widgets.setLongitude(-87.966 + counter); cogs.setManufacturer(widgets); } } else { cogs.setName("Cogs " + counter); if (counter % 2 == 0) { Company acme = new Company(); acme.setName("Acme " + counter + ", Inc."); acme.setWebsite("http://www.acme" + counter + ".com"); acme.setLatitude(41.998 + counter); acme.setLongitude(-87.966 + counter); cogs.setManufacturer(acme); } else { Company widgets = new Company(); widgets.setName("Widgets " + counter + ", Inc."); widgets.setWebsite("http://www.widgets" + counter + ".com"); widgets.setLatitude(41.998 + counter); widgets.setLongitude(-87.966 + counter); cogs.setManufacturer(widgets); } } cogs.setInventory(1000 + counter); return cogs; }
@Test public void testUpdate() { Company cp = em.createNamedQuery("Company.findByName", Company.class) .setParameter("name", "Windy") .getSingleResult(); assertNotNull(cp.getId()); String originalName = cp.getName(); String newName = "Chicago Beverage"; tx.begin(); cp.setName(newName); tx.commit(); assertNotEquals(originalName, cp.getName()); assertTrue(newName.equals(cp.getName())); tx.begin(); cp.setName(originalName); tx.commit(); }
@Test public void testCreate() { Company cm = new Company(); cm.setName("Windy"); cm.setProductName("Root"); cm.setProductType("Beer"); tx.begin(); em.persist(cm); tx.commit(); assertNotNull(cm.getId()); }
public static Company createCompany() { // Create company Company sampleCompany = new Company(); sampleCompany.setName("ACME Corporation"); // Create all employees Employee craig = new Employee(); craig.setName("Craig"); craig.setAddress("Redmond"); craig.setSalary(123456); Employee erik = new Employee(); erik.setName("Erik"); erik.setAddress("Utrecht"); erik.setSalary(12345); Employee ralf = new Employee(); ralf.setName("Ralf"); ralf.setAddress("Koblenz"); ralf.setSalary(1234); Employee ray = new Employee(); ray.setName("Ray"); ray.setAddress("Redmond"); ray.setSalary(234567); Employee klaus = new Employee(); klaus.setName("Klaus"); klaus.setAddress("Boston"); klaus.setSalary(23456); Employee karl = new Employee(); karl.setName("Karl"); karl.setAddress("Riga"); karl.setSalary(2345); Employee joe = new Employee(); joe.setName("Joe"); joe.setAddress("Wifi City"); joe.setSalary(2344); // Create research department Department research = new Department(); research.setManager(craig); research.setName("Research"); research.getEmployees().add(erik); research.getEmployees().add(ralf); sampleCompany.getDepts().add(research); // Create development department Department development = new Department(); development.setManager(ray); development.setName("Development"); sampleCompany.getDepts().add(development); // Create sub-department dev1 Department dev1 = new Department(); dev1.setName("Dev1"); dev1.setManager(klaus); development.getSubdepts().add(dev1); // Create sub-department dev11 Department dev11 = new Department(); dev11.setName("Dev1.1"); dev11.setManager(karl); dev11.getEmployees().add(joe); dev1.getSubdepts().add(dev11); return sampleCompany; }