public void setUp() throws Exception {
    super.setUp();
    tempDirPath = getTempDir().getAbsolutePath() + File.separator;

    theDaemon = getMockLockssDaemon();
    theDaemon.getAlertManager();
    theDaemon.getPluginManager().setLoadablePluginsReady(true);
    theDaemon.getHashService();
    MockSystemMetrics metrics = new MyMockSystemMetrics();
    metrics.initService(theDaemon);
    theDaemon.setSystemMetrics(metrics);

    theDaemon.setDaemonInited(true);

    Properties props = new Properties();
    props.setProperty(SystemMetrics.PARAM_HASH_TEST_DURATION, "1000");
    props.setProperty(SystemMetrics.PARAM_HASH_TEST_BYTE_STEP, "1024");
    props.setProperty(ConfigManager.PARAM_PLATFORM_DISK_SPACE_LIST, tempDirPath);
    ConfigurationUtil.setCurrentConfigFromProps(props);

    pluginMgr = theDaemon.getPluginManager();
    pluginMgr.startService();
    theDaemon.getHashService().startService();
    metrics.startService();
    metrics.setHashSpeed(100);

    simPlugin = PluginTestUtil.findPlugin(SimulatedPlugin.class);
  }
示例#2
0
  public static void testEnum() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty("-metatype", "*");
    b.build();
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());

    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$Enums.xml");
    IO.copy(r.openInputStream(), System.err);

    Document d = db.parse(r.openInputStream());
    assertEquals(
        "http://www.osgi.org/xmlns/metatype/v1.1.0", d.getDocumentElement().getNamespaceURI());

    Properties p = new Properties();
    p.setProperty("r", "requireConfiguration");
    p.setProperty("i", "ignoreConfiguration");
    p.setProperty("o", "optionalConfiguration");
    Enums enums = Configurable.createConfigurable(Enums.class, (Map<Object, Object>) p);
    assertEquals(Enums.X.requireConfiguration, enums.r());
    assertEquals(Enums.X.ignoreConfiguration, enums.i());
    assertEquals(Enums.X.optionalConfiguration, enums.o());
  }
示例#3
0
  static <T> T set(Class<T> interf, Object value) {
    Properties p = new Properties();
    Method ms[] = interf.getMethods();

    for (Method m : ms) {
      p.put(m.getName(), value);
    }
    return Configurable.createConfigurable(interf, (Map<Object, Object>) p);
  }
示例#4
0
  public static void testSpecialConversions() throws URISyntaxException {
    Properties p = new Properties();
    p.put("enumv", "A");
    p.put("pattern", ".*");
    p.put("clazz", "java.lang.Object");
    p.put("constructor", "http://www.aQute.biz");

    SpecialConversions trt =
        Configurable.createConfigurable(SpecialConversions.class, (Map<Object, Object>) p);
    assertEquals(SpecialConversions.X.A, trt.enumv());
    assertEquals(".*", trt.pattern().pattern());
    assertEquals(Object.class, trt.clazz());
    assertEquals(new URI("http://www.aQute.biz"), trt.constructor());
  }
示例#5
0
  public void testInvalid() {
    Enumeration e = invalidRsls.keys();
    String key;
    String rsl;
    while (e.hasMoreElements()) {
      key = (String) e.nextElement();
      rsl = invalidRsls.getProperty(key);

      System.out.println("Parsing invalid rsl " + key + ": " + rsl);
      try {
        RslNode tree = RSLParser.parse(rsl);
        fail("Failed to catch parse error of " + rsl);
      } catch (Exception ex) {
      }
    }
  }
示例#6
0
  public void testValid() {
    Enumeration e = validRsls.keys();
    String key;
    String rsl;
    while (e.hasMoreElements()) {
      key = (String) e.nextElement();
      rsl = validRsls.getProperty(key);

      System.out.println("Parsing valid rsl " + key + ": " + rsl);
      try {
        RSLParser.parse(rsl);
      } catch (Exception ex) {
        ex.printStackTrace();
        fail("Failed to parse!!!");
      }
    }
  }
  public void tearDown() {
    String files = props.getProperty(FileSystemProvider.PROP_PAGEDIR);

    // Remove file
    File f = new File(files, NAME1 + FileSystemProvider.FILE_EXT);
    f.delete();

    f = new File(files, "OLD");

    TestEngine.deleteAll(f);
  }
  public static void testParseRunProperties() throws Exception {
    Workspace ws = Workspace.getWorkspace(new File("src/test/ws"));
    Project project = ws.getProject("p1");

    ProjectLauncherImpl launcher = new ProjectLauncherImpl(project);
    launcher.prepare();

    String arg = launcher.getRunVM().iterator().next();
    String s = "-D" + LauncherConstants.LAUNCHER_PROPERTIES + "=";
    String propertiesPath = arg.substring(s.length());
    Matcher matcher = Pattern.compile("^([\"'])(.*)\\1$").matcher(propertiesPath);
    if (matcher.matches()) {
      propertiesPath = matcher.group(2);
    }

    Properties launchProps = new Properties();
    launchProps.load(new FileInputStream(new File(propertiesPath)));
    assertEquals(
        new File("src/test/ws/p1/generated/p1.jar").getAbsolutePath(),
        launchProps.get("launch.bundles"));
  }
示例#9
0
  /**
   * We create a JAR with the test.classreferenc.ClassReference class. This class contains a
   * javax.swing.Box.class reference Prior to Java 1.5, this was done in a silly way that is handled
   * specially. After 1.5 it is a normal reference.
   *
   * @throws Exception
   */
  public void testReference() throws Exception {
    Properties properties = new Properties();
    properties.put("-classpath", "compilerversions/compilerversions.jar");
    String[] packages = {
      "sun_1_1",
      "sun_1_6",
      "eclipse_1_1",
      "sun_1_2",
      "sun_1_3",
      "sun_1_4",
      "sun_1_5",
      "sun_jsr14",
      "eclipse_1_5",
      "eclipse_1_6",
      "eclipse_1_2",
      "eclipse_1_3",
      "eclipse_1_4",
      "eclipse_jsr14"
    };
    for (int i = 0; i < packages.length; i++) {
      Builder builder = new Builder();
      properties.put("Export-Package", packages[i]);
      builder.setProperties(properties);
      Jar jar = builder.build();
      System.out.println(builder.getErrors());
      System.out.println(builder.getWarnings());
      assertEquals(0, builder.getErrors().size());
      assertEquals(0, builder.getWarnings().size());

      Manifest manifest = jar.getManifest();
      String imports = manifest.getMainAttributes().getValue("Import-Package");
      assertTrue(
          "Package " + packages[i] + "contains swing ref", imports.indexOf("javax.swing") >= 0);
      assertFalse(
          "Package " + packages[i] + "should not contain ClassRef",
          imports.indexOf("ClassRef") >= 0);
    }
  }
示例#10
0
  /**
   * Starts Grid instance. Note that if grid is already started, then it will be looked up and
   * returned from this method.
   *
   * @return Started grid.
   */
  private Grid startGrid() {
    Properties props = System.getProperties();

    gridName = props.getProperty(GRIDGAIN_NAME.name());

    if (!props.containsKey(GRIDGAIN_NAME.name()) || G.state(gridName) != GridFactoryState.STARTED) {
      selfStarted = true;

      // Set class loader for the spring.
      ClassLoader curCl = Thread.currentThread().getContextClassLoader();

      // Add no-op logger to remove no-appender warning.
      Appender app = new NullAppender();

      Logger.getRootLogger().addAppender(app);

      try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

        Grid grid = G.start(cfgPath);

        gridName = grid.name();

        System.setProperty(GRIDGAIN_NAME.name(), grid.name());

        return grid;
      } catch (GridException e) {
        throw new GridRuntimeException("Failed to start grid: " + cfgPath, e);
      } finally {
        Logger.getRootLogger().removeAppender(app);

        Thread.currentThread().setContextClassLoader(curCl);
      }
    }

    return G.grid(gridName);
  }
示例#11
0
  public void setUp() {
    validRsls = new Properties();
    validRsls.put("rsl1", "+(&(executable=myprogram)(stdin<2.4))(&(stdin=8)   \n\n\n(stdin=0))");
    validRsls.put("rsl2", "&(executable=myprogram)(stdin<2.4)(stdin=8)(stdin=0)");
    validRsls.put("rsl3", "&(a=a)(a=b)");
    validRsls.put("rsl4", " &(a=a)");
    validRsls.put(
        "rsl5",
        "(* dont use this comment *)\n&(string=\"my name is \"\"Nick Karonis\"\" today\") (*or this one*)");
    validRsls.put("rsl6", "&(&(&(&(a=a))))");
    validRsls.put("rsl7", "&(args=\"aa ) bb\")");
    validRsls.put("rsl8", "+(&(executable=myprogram)(stdin<2.4))(|(stdin=8)   \n\n\n(stdin=0))");
    validRsls.put(
        "rsl9",
        "+(&(executable=myprogram)(stdin<2.4)(|(a=bbb)(yyy=z)))(|(stdin=8)   \n\n\n(stdin=0))");
    validRsls.put("rsl10", "&(args=hello \n\n)");
    validRsls.put("rsl11", "&(executable=\"\")");
    validRsls.put("rsl12", "&(executable=\"abc \"\" \"\" def\")");
    // validRsls.put("rsl13", "args=\"aa ) \"\"bb cc dd\"");
    validRsls.put(
        "rsl14",
        "&((*comment*)string(*comment*) \n=(*comment\ncontinue comment*)\"my (* ok *) name is \"\"Nick Karonis\"\" today\"(*comment*)) (* or this one *)");
    validRsls.put(
        "rsl15",
        "&(* dont use this comment *)\n(\n(*comment*)string(*comment*)\n=(*comment\ncontinue comment*)\"my name is \"\"Nick Karonis\"\" today\"(*comment*)) (*or this one*)");
    // validRsls.put("rsl16", "(* dont use this comment *)\n(* comment*) string  (*
    // comment*)\n=(*comment\ncontinue comment*)\"my name is \"\"Nick Karonis\"\" today\"(*comment*)
    // (*or this one*)");
    validRsls.put(
        "rsl17",
        "+(* dont use this comment *)\n((*comment*)string(*comment*)=(*comment\ncontinue comment*)\"my name is \"\"Nick Karonis\"\" today\"(*comment*)) (*or this one*)");
    validRsls.put("rsl18", "+(string='let''s try ''single quotes'' with \"double too\" ok')");

    invalidRsls = new Properties();

    invalidRsls.put("rsl1", "(my executable=a.out)");
    invalidRsls.put("rsl2", "(executable=/home /a.ou:t#22)");
    invalidRsls.put("rsl3", "&(args=dddd)(executable=)(more_args=ooo)");
    invalidRsls.put("rsl4", "(executable=^$test $$$  quotes$)");
    invalidRsls.put("rsl5", "(executable=^$my value $ \nmore \"\"\" stuff)");
    invalidRsls.put("rsl6", "(executable=)");
    invalidRsls.put("rsl7", "(args=\"\"a\"\"b\")");
    invalidRsls.put("rsl8", "(args=hello \n\nworld)");
    invalidRsls.put("rsl9", "(arguments=\"ccc ddd\"\"zzz\"\")");
    // invalidRsls.put("rsl10", "&(arguments=\"\"\"\"\")(exe=abc)");
    invalidRsls.put("rsl11", "(a=a)");
    invalidRsls.put(
        "rsl12", "+(&(executable=myprogram)(stdin<2.4))(+(stdin=8)   \n\n\n(stdin=0))+");
    invalidRsls.put("rsl13", "(=a.out)");
    invalidRsls.put("rsl14", "(executable=\")");
    invalidRsls.put("rsl15", "(executable=^\")");
    invalidRsls.put("rsl16", "(executable=^/)");
  }