@Test public void testCRUD() { String type = "JarJar-" + System.currentTimeMillis(); ConsumerType consumerType = new ConsumerType(); consumerType.setLabel(type); assertEquals("the label getter works", type, consumerType.getLabel()); // Ensure it is not there assertTrue("The type already exists", !this.typeExists(type)); // Create it consumerType = consumerTypeResource.create(consumerType); // Make sure it is there assertTrue("The type was not found", this.typeExists(type)); // Find it by ID ConsumerType consumerType2 = consumerTypeResource.getConsumerType(consumerType.getId()); assertNotNull("The type was not found by ID", consumerType2); // Update it String type2 = "JarJar2-" + System.currentTimeMillis(); consumerType.setLabel(type2); consumerTypeResource.update(consumerType); assertTrue("The update was not found", this.typeExists(type2)); // Delete It consumerTypeResource.deleteConsumerType(consumerType.getId()); // Make sure it is not there assertTrue("The type was found after a delete", !this.typeExists(type)); }
public boolean typeExists(String type) { List<ConsumerType> types = consumerTypeResource.list(); boolean found = false; for (ConsumerType aType : types) { found = type.equals(aType.getLabel()); if (found) { break; } } return found; }