Ejemplo n.º 1
0
 public void testShouldExportServiceManifestAsString() {
   String serviceProviderId = getManifest().getServiceProviderId();
   String manifestAsString = getManifest().toString();
   try {
     XmlBeanServiceManifestDocument parsedManifest =
         XmlBeanServiceManifestDocument.Factory.parse(manifestAsString);
     assertEquals(
         "converted field mismatch.",
         serviceProviderId,
         parsedManifest.getServiceManifest().getServiceProviderId());
   } catch (XmlException e) {
     fail("export creates invalid manifest");
     e
         .printStackTrace(); // To change body of catch statement use File | Settings | File
                             // Templates.
   }
 }
Ejemplo n.º 2
0
  /** Runs the test suite using the textual runner. */
  public static void main(String[] args) {

    if (args.length == 0) {
      log.info("ERROR: No arguements specified!");

      log.info(
          "Usage: java -jar VmContextualizer.jar <function> <working_directory> [<options>] ...");
      log.info("  <function> values:");
      log.info("    \"1\": Unit tests");
      log.info("    \"2\": Perf evalauation");
      log.info("    \"3\": Recontextualization Standalone");
      log.info("  <working_directory>:");
      log.info("    Path to config file and working directory");
      log.info("    Value of \"default\" uses hardcoded default config data for unit testing");
      log.info("  Arguments for function \"1\":");
      log.info("    [<manifest_path>]:");
      log.info("      Path to manifest file, includes file name");
      log.info("    [<desired_image_format>]:");
      log.info("      Image format to convert to");
      log.info("  Arguments for function \"3\":");
      log.info("    [<hypervisor_uri>]:");
      log.info("      Hypervisor URI used by recontextualization");
      log.info("    [<recontext_domain>]:");
      log.info("      VM name used by recontextualization");

      log.info("Example: java -jar VmContextualizer.jar 1 default ...");

    } else {
      if (Integer.parseInt(args[0]) == 1) { // Unit Tests (Option 1)

        if (args.length == 1) {
          log.warn(
              "WARNING: No working directory specified using default config, location and manifest!");
        } else {

          if (!args[1].equals("default")) {
            System.out.println(args[1]);
            configFilePath = new String(args[1]);
          }

          if (args.length == 2) {
            log.warn("WARNING: No manifest file specified using default!");
          }

          if (args.length == 3) {
            log.info("Using manifest location: " + args[2]);
            File smFile = new File(args[2]);
            XmlBeanServiceManifestDocument doc = null;
            try {
              doc = XmlBeanServiceManifestDocument.Factory.parse(smFile);
            } catch (XmlException e) {
              e.printStackTrace();
            } catch (IOException e) {
              e.printStackTrace();
            }
            testManifest = Manifest.Factory.newInstance(doc);
          }

          if (args.length == 4) {
            log.info("Using image format: " + args[3]);
            imageFormat = args[3];
          }
        }

        TestSuite testSuite = new TestSuite();
        testSuite.addTestSuite(VmcApiTest.class);
        if (configFilePath != null) {
          System.setProperty("configFilePath", configFilePath); // For other TestSuites
        }
        testSuite.addTestSuite(VmcApiRecontextTest.class);
        junit.textui.TestRunner.run(testSuite);

      } else if (Integer.parseInt(args[0]) == 2) { // Performance Evaluation (Option 2)

        System.out.println("Running Evaluation:");
        // TODO: Add new evaluation
        System.out.println("Performance evaluation is not implemented");

      } else if (Integer.parseInt(args[0]) == 3) { // Recontextualization (Option 3)
        System.out.println("Running the VMC in Recontextualization Mode...");
        VmcApiRecontextTest vmcApiRecontextTest = new VmcApiRecontextTest("");
        if (args.length == 5) {

          log.info("Using config file path: " + args[1]);
          if (!args[1].equals("default")) {
            System.out.println(args[1]);
            configFilePath = new String(args[1]);
          }

          log.info("Using working directory: " + args[2]);
          log.info(
              "Using Hypervisor URI: "
                  + args[3]); // TODO at some point put/get this in the properties file
          log.info(
              "Using VM Name: "
                  + args[4]); // TODO at some point put/get this in the properties file

          vmcApiRecontextTest.recontextualize(configFilePath, true, args[3], args[4]);
        } else {
          log.error("ERROR: Not enough arguments for Recontextualization Mode!");
          log.info(
              "USAGE: java -jar VmContextualizer.jar 3 default <hypervisor_uri> <recontext_domain>");
        }

      } else {
        log.error("ERROR: Unknown test number specified!");
      }
    }
  }
Ejemplo n.º 3
0
 public void testShouldLoadManifestFromFile() throws XmlException, IOException {
   InputStream in = this.getClass().getResourceAsStream("/SP-ManifestExample.xml");
   XmlBeanServiceManifestDocument doc = XmlBeanServiceManifestDocument.Factory.parse(in);
   Manifest manifest = Manifest.Factory.newInstance(doc);
   assertFalse(manifest.hasErrors());
 }