public String generateJsonMetadata(BundleBuildRequest request, BundleBuildResponse response) {
    File bundleDir = new File(response.getBundleDataDirectory());
    List<BundleFile> files = getBundleFilesWithSumsForDirectory(bundleDir, bundleDir);

    Gson gson =
        new GsonBuilder()
            .serializeNulls()
            .registerTypeAdapter(DateTime.class, new JodaDateTimeAdapter())
            .registerTypeAdapter(LocalDate.class, new JodaLocalDateAdapter())
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES)
            .setPrettyPrinting()
            .create();

    Bundle bundle = new Bundle();

    bundle.setId(request.getBundleName());

    bundle.setName(request.getBundleName());

    bundle.setServiceDateFrom(request.getBundleStartDate());
    bundle.setServiceDateTo(request.getBundleEndDate());

    DateTime now = new DateTime();

    bundle.setCreated(now);
    bundle.setUpdated(now);

    List<String> applicableAgencyIds = new ArrayList<String>();
    // TODO this should come from somewhere
    applicableAgencyIds.add("MTA NYCT");

    bundle.setApplicableAgencyIds(applicableAgencyIds);

    bundle.setFiles(files);

    String output = gson.toJson(bundle);

    String outputFilename = response.getBundleRootDirectory() + File.separator + META_DATA_FILE;
    File outputFile = new File(outputFilename);
    _log.info("creating metadata file=" + outputFilename);
    PrintWriter writer = null;
    try {
      writer = new PrintWriter(outputFile);
      writer.print(output);
    } catch (Exception any) {
      _log.error(any.toString(), any);
      response.setException(any);
    } finally {
      writer.close();
    }
    return outputFilename;
  }
  @Test
  public void testBuild() {
    String bundleDir = "test";
    String tmpDir = new FileUtils().createTmpDirectory();

    BundleBuildRequest request = new BundleBuildRequest();
    request.setBundleDirectory(bundleDir);
    request.setBundleName("testname");
    request.setTmpDirectory(tmpDir);
    request.setBundleStartDate("2012-04-08");
    request.setBundleEndDate("2012-07-07");
    assertNotNull(request.getTmpDirectory());
    assertNotNull(request.getBundleDirectory());
    BundleBuildResponse response = new BundleBuildResponse("" + System.currentTimeMillis());
    assertEquals(0, response.getStatusList().size());

    // step 1
    _service.download(request, response);
    assertNotNull(response.getGtfsList());
    assertEquals(1, response.getGtfsList().size());

    assertNotNull(response.getStifZipList());
    assertEquals(1, response.getStifZipList().size());

    assertNotNull(response.getStatusList());
    assertTrue(response.getStatusList().size() > 0);

    assertNotNull(response.getConfigList());
    assertEquals(0, response.getConfigList().size());

    // step 2
    _service.prepare(request, response);

    assertFalse(response.isComplete());

    // step 3
    int rc = _service.build(request, response);
    if (response.getException() != null) {
      _log.error("Failed with exception=" + response.getException());
    }
    assertNull(response.getException());
    assertFalse(response.isComplete());
    assertEquals(0, rc);

    // step 4
    // OBANYC-1451 -- fails on OSX TODO
    // _service.assemble(request, response);

    // step 5
    _service.upload(request, response);
    assertFalse(response.isComplete()); // set by BundleRequestService
  }