@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));
  }
Example #2
0
  private void exportConsumerTypes(File baseDir) throws IOException {
    File typeDir = new File(baseDir.getCanonicalPath(), "consumer_types");
    typeDir.mkdir();

    for (ConsumerType type : consumerTypeCurator.listAll()) {
      File file = new File(typeDir.getCanonicalPath(), type.getLabel() + ".json");
      FileWriter writer = new FileWriter(file);
      consumerType.export(mapper, writer, type);
      writer.close();
    }
  }
 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;
 }