示例#1
0
  @Override
  protected void setUp() throws Exception {
    tmp = IO.getFile("generated/tmp");
    tmp.mkdirs();

    configuration = new HashMap<String, Object>();
    configuration.put(
        Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    configuration.put(Constants.FRAMEWORK_STORAGE, new File(tmp, "fwstorage").getAbsolutePath());
    configuration.put(
        Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.4");
    framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration);
    framework.init();
    framework.start();
    BundleContext context = framework.getBundleContext();

    String[] bundles = {
      "../cnf/repo/osgi.cmpn/osgi.cmpn-4.3.1.jar", "testdata/slf4j-simple-1.7.12.jar",
      "testdata/slf4j-api-1.7.12.jar", "testdata/org.apache.aries.util-1.1.0.jar",
      "testdata/org.apache.aries.jmx-1.1.1.jar", "generated/biz.aQute.remote.test.jmx.jar"
    };

    for (String bundle : bundles) {
      String location = "reference:" + IO.getFile(bundle).toURI().toString();
      Bundle b = context.installBundle(location);
      if (!bundle.contains("slf4j-simple")) {
        b.start();
      }
    }

    super.setUp();
  }
  /**
   * Get a reference to the basic IM operation set.
   *
   * @throws Exception if this is not a good day.
   */
  protected void setUp() throws Exception {
    super.setUp();
    fixture.setUp();

    Map supportedOperationSets = fixture.provider.getSupportedOperationSets();

    if (supportedOperationSets == null || supportedOperationSets.size() < 1)
      throw new NullPointerException(
          "No OperationSet implementations are supported by " + "this ICQ implementation. ");

    // get the operation set presence here.
    opSetBasicIM =
        (OperationSetBasicInstantMessaging)
            supportedOperationSets.get(OperationSetBasicInstantMessaging.class.getName());

    // if the op set is null then the implementation doesn't offer a typing.
    // operation set which is unacceptable for icq.
    if (opSetBasicIM == null) {
      throw new NullPointerException("No implementation for basic IM was found");
    }

    // we also need the presence op set in order to retrieve contacts.
    opSetPresence =
        (OperationSetPresence) supportedOperationSets.get(OperationSetPresence.class.getName());

    // if the op set is null show that we're not happy.
    if (opSetPresence == null) {
      throw new NullPointerException(
          "An implementation of the ICQ service must provide an "
              + "implementation of at least one of the PresenceOperationSets");
    }
  }
示例#3
0
 public static void testConfigurableForNonPrimitives() {
   Map<String, String> p = new HashMap<String, String>();
   C config = Configurable.createConfigurable(C.class, p);
   assertNull(config.port());
   p.put("port", "10");
   config = Configurable.createConfigurable(C.class, p);
   assertEquals(Integer.valueOf(10), config.port()); // property port is
   // not set
 }
示例#4
0
 /** Test export annotation. */
 public static void testExportAnnotation() throws Exception {
   Builder a = new Builder();
   a.addClasspath(new File("bin"));
   a.setProperty("build", "xyz");
   a.setProperty("Export-Package", "test.versionpolicy.api");
   a.build();
   Map<String, String> attrs = a.getExports().getByFQN("test.versionpolicy.api");
   assertEquals("1.2.0.xyz", attrs.get("version"));
   assertEquals("PrivateImpl", attrs.get("exclude:"));
   assertEquals("a", attrs.get("mandatory:"));
 }
示例#5
0
  /** Test default package versions. */
  public static void testDefaultPackageVersion() throws Exception {
    Builder a = new Builder();
    a.addClasspath(new File("bin"));
    a.setProperty("Bundle-Version", "1.2.3");
    a.setProperty("Export-Package", "test.refer");
    Jar jar = a.build();

    Manifest m = jar.getManifest();
    Parameters exports =
        Processor.parseHeader(m.getMainAttributes().getValue(Constants.EXPORT_PACKAGE), null);
    Map<String, String> attrs = exports.get("test.refer");
    assertNotNull(attrs);
    assertEquals("1.2.3", attrs.get("version"));
  }
  /**
   * Verifies that all operation sets have the type they are declarded to have.
   *
   * @throws java.lang.Exception if a class indicated in one of the keys could not be forName()ed.
   */
  public void testOperationSetTypes() throws Exception {
    Map<String, OperationSet> supportedOperationSets =
        fixture.provider1.getSupportedOperationSets();

    // make sure that keys (which are supposed to be class names) correspond
    // what the class of the values recorded against them.
    for (Map.Entry<String, OperationSet> entry : supportedOperationSets.entrySet()) {
      String setName = entry.getKey();
      Object opSet = entry.getValue();

      assertTrue(
          opSet + " was not an instance of " + setName + " as declared",
          Class.forName(setName).isInstance(opSet));
    }
  }
示例#7
0
  /** Test import provide:. */
  public static void testExportProvided() throws Exception {
    Builder a = new Builder();
    a.addClasspath(IO.getFile("jar/osgi.jar"));
    a.addClasspath(new File("bin"));
    a.setProperty("Private-Package", "test.refer");
    a.setProperty("Export-Package", "org.osgi.service.http;provide:=true");
    Jar jar = a.build();
    Map<String, String> event = a.getImports().getByFQN("org.osgi.service.event");
    assertEquals("[1.0,2)", event.get("version"));
    Map<String, String> http = a.getImports().getByFQN("org.osgi.service.http");
    assertEquals("[1.2,1.3)", http.get("version"));

    Manifest m = jar.getManifest();
    String imports = m.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
    assertFalse(imports.contains(Constants.PROVIDE_DIRECTIVE));
  }
  /**
   * Get a reference to the basic IM operation set.
   *
   * @throws Exception if this is not a good day.
   */
  protected void setUp() throws Exception {
    super.setUp();
    fixture.setUp();

    Map<String, OperationSet> supportedOperationSets1 =
        fixture.provider1.getSupportedOperationSets();

    if (supportedOperationSets1 == null || supportedOperationSets1.size() < 1)
      throw new NullPointerException(
          "No OperationSet implementations are supported by " + "this implementation. ");

    // get the operation set presence here.
    opSetBasicIM1 =
        (OperationSetBasicInstantMessaging)
            supportedOperationSets1.get(OperationSetBasicInstantMessaging.class.getName());

    if (opSetBasicIM1 == null) {
      throw new NullPointerException("No implementation for basic IM was found");
    }

    // we also need the presence op set in order to retrieve contacts.
    opSetPresence1 =
        (OperationSetPresence) supportedOperationSets1.get(OperationSetPresence.class.getName());

    // if the op set is null show that we're not happy.
    if (opSetPresence1 == null) {
      throw new NullPointerException(
          "An implementation of the service must provide an "
              + "implementation of at least one of the PresenceOperationSets");
    }

    Map<String, OperationSet> supportedOperationSets2 =
        fixture.provider2.getSupportedOperationSets();

    if (supportedOperationSets2 == null || supportedOperationSets2.size() < 1)
      throw new NullPointerException(
          "No OperationSet implementations are supported by " + "this implementation. ");

    // get the operation set presence here.
    opSetBasicIM2 =
        (OperationSetBasicInstantMessaging)
            supportedOperationSets2.get(OperationSetBasicInstantMessaging.class.getName());

    if (opSetBasicIM2 == null) {
      throw new NullPointerException("No implementation for basic IM was found");
    }

    opSetPresence2 =
        (OperationSetPresence) supportedOperationSets2.get(OperationSetPresence.class.getName());

    // if the op set is null show that we're not happy.
    if (opSetPresence2 == null) {
      throw new NullPointerException(
          "An implementation of the service must provide an "
              + "implementation of at least one of the PresenceOperationSets");
    }
  }
  protected void setUp() throws Exception {
    super.setUp();
    fixture.setUp();

    Map<String, OperationSet> supportedOperationSets = fixture.provider.getSupportedOperationSets();

    if (supportedOperationSets == null || supportedOperationSets.size() < 1)
      throw new NullPointerException(
          "No OperationSet implementations are supported by " + "this ICQ implementation. ");

    // get the operation set presence here.
    operationSetPresence =
        (OperationSetPresence) supportedOperationSets.get(OperationSetPresence.class.getName());

    // if the op set is null then the implementation doesn't offer a presence
    // operation set which is unacceptable for icq.
    if (operationSetPresence == null) {
      throw new NullPointerException(
          "An implementation of the ICQ service must provide an "
              + "implementation of at least the one of the Presence "
              + "Operation Sets");
    }
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    fixture.setUp();

    Map<String, OperationSet> supportedOperationSets1 =
        fixture.provider1.getSupportedOperationSets();

    if (supportedOperationSets1 == null || supportedOperationSets1.size() < 1)
      throw new NullPointerException(
          "No OperationSet implementations are supported by " + "this Gibberish implementation. ");

    // get the operation set presence here.
    opSetPersPresence1 =
        (OperationSetPersistentPresence)
            supportedOperationSets1.get(OperationSetPersistentPresence.class.getName());

    // if still null then the implementation doesn't offer a presence
    // operation set which is unacceptable for gibberish.
    if (opSetPersPresence1 == null)
      throw new NullPointerException(
          "An implementation of the gibberish service must provide an "
              + "implementation of at least the one of the Presence "
              + "Operation Sets");

    // lets do it once again for the second provider
    Map<String, OperationSet> supportedOperationSets2 =
        fixture.provider2.getSupportedOperationSets();

    if (supportedOperationSets2 == null || supportedOperationSets2.size() < 1)
      throw new NullPointerException(
          "No OperationSet implementations are supported by " + "this Gibberish implementation. ");

    // get the operation set presence here.
    opSetPersPresence2 =
        (OperationSetPersistentPresence)
            supportedOperationSets2.get(OperationSetPersistentPresence.class.getName());

    // if still null then the implementation doesn't offer a presence
    // operation set which is unacceptable for Gibberish.
    if (opSetPersPresence2 == null)
      throw new NullPointerException(
          "An implementation of the Gibberish service must provide an "
              + "implementation of at least the one of the Presence "
              + "Operation Sets");
  }
  public void testStatelessSearch()
      throws org.jzkit.configuration.api.ConfigurationException, org.jzkit.search.SearchException,
          org.jzkit.search.util.ResultSet.IRResultSetException,
          org.jzkit.search.util.QueryModel.InvalidQueryException {

    Logger log = Logger.getLogger(TestService.class.getName());

    log.info("Starting jzkit2 server...");

    RecordFormatSpecification request_spec = new ArchetypeRecordFormatSpecification("F");
    ExplicitRecordFormatSpecification display_spec =
        new ExplicitRecordFormatSpecification("text:html:F");

    ApplicationContext app_context =
        new ClassPathXmlApplicationContext("TestApplicationContext.xml");
    log.info("JZKit server startup completed");

    Vector collection_ids = new Vector();
    collection_ids.add("LC/BOOKS");

    QueryModel qm = new PrefixString("@attrset bib-1 @attr 1=4 Science");

    System.err.println("Processing search......");

    try {
      Map additional_properties = new HashMap();
      additional_properties.put("base_dir", "/a/b/c/d");

      StatelessQueryService stateless_query_service =
          (StatelessQueryService) app_context.getBean("StatelessQueryService");

      org.jzkit.search.landscape.SimpleLandscapeSpecification landscape =
          new org.jzkit.search.landscape.SimpleLandscapeSpecification(collection_ids);
      // Test 1 - Kick off a search
      StatelessSearchResultsPageDTO rp =
          stateless_query_service.getResultsPageFor(
              null, qm, landscape, 1, 5, request_spec, display_spec, additional_properties);

      if (rp != null) {
        System.err.println(
            "Result Set Size....."
                + rp.total_hit_count
                + " records - result contains "
                + rp.number_of_records
                + " records");
        System.err.println("Result Set ID : " + rp.result_set_id);
      } else {
        System.err.println("Results page was null");
      }

      if (rp.records != null) {
        for (int i = 0; ((i < rp.records.length) && (i < 25)); i++) {
          System.err.println(
              "Getting next record (" + i + " out of " + rp.number_of_records + ").....");
          InformationFragment frag = rp.records[i];
          System.err.println(frag);
        }
      }

      // Test 2 - use the result set ID to get a page of requests
      rp =
          stateless_query_service.getResultsPageFor(
              rp.result_set_id,
              qm,
              landscape,
              6,
              5,
              request_spec,
              display_spec,
              additional_properties);

      if (rp.records != null) {
        for (int i = 0; ((i < rp.records.length) && (i < 25)); i++) {
          System.err.println(
              "Getting next record (" + i + " out of " + rp.number_of_records + ").....");
          InformationFragment frag = rp.records[i];
          System.err.println(frag);
        }
      }

      // Test 3 - Use the query to get a cache hit
      rp =
          stateless_query_service.getResultsPageFor(
              null, qm, landscape, 6, 5, request_spec, display_spec, additional_properties);

      if (rp.records != null) {
        for (int i = 0; ((i < rp.records.length) && (i < 25)); i++) {
          System.err.println(
              "Getting next record (" + i + " out of " + rp.number_of_records + ").....");
          InformationFragment frag = rp.records[i];
          System.err.println(frag);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#12
0
  public static void testNaming() throws Exception {
    Map<String, Object> map = Create.map();

    map.put("_secret", "_secret");
    map.put("_secret", "_secret");
    map.put(".secret", ".secret");
    map.put("$new", "$new");
    map.put("new", "new");
    map.put("secret", "secret");
    map.put("a_b_c", "a_b_c");
    map.put("a.b.c", "a.b.c");
    map.put(".a_b", ".a_b");
    map.put("$$$$a_b", "$$$$a_b");
    map.put("$$$$a.b", "$$$$a.b");
    map.put("a", "a");
    map.put("a$", "a$");
    map.put("a$$", "a$$");
    map.put("a$.$", "a$.$");
    map.put("a$_$", "a$_$");
    map.put("a..", "a..");
    map.put("noid", "noid");
    map.put("nullid", "nullid");

    Naming trt = Configurable.createConfigurable(Naming.class, map);

    // By name
    assertEquals("secret", trt.secret());
    assertEquals("_secret", trt.__secret());
    assertEquals(".secret", trt._secret());
    assertEquals("new", trt.$new());
    assertEquals("$new", trt.$$new());
    assertEquals("a.b.c", trt.a_b_c());
    assertEquals("a_b_c", trt.a__b__c());
    assertEquals(".a_b", trt._a__b());
    assertEquals("$$$$a.b", trt.$$$$$$$$a_b());
    assertEquals("$$$$a_b", trt.$$$$$$$$a__b());
    assertEquals("a", trt.a$());
    assertEquals("a$", trt.a$$());
    assertEquals("a$", trt.a$$$());
    assertEquals("a$.$", trt.a$$_$$());
    assertEquals("a$_$", trt.a$$__$$());
    assertEquals("a..", trt.a_$_());
    assertEquals("noid", trt.noid());
    assertEquals("nullid", trt.nullid());

    // By AD
    assertEquals("secret", trt.xsecret());
    assertEquals("_secret", trt.x__secret());
    assertEquals(".secret", trt.x_secret());
    assertEquals("new", trt.x$new());
    assertEquals("$new", trt.x$$new());
    assertEquals("a.b.c", trt.xa_b_c());
    assertEquals("a_b_c", trt.xa__b__c());
    assertEquals(".a_b", trt.x_a__b());
    assertEquals("$$$$a.b", trt.x$$$$$$$$a_b());
    assertEquals("$$$$a_b", trt.x$$$$$$$$a__b());
    assertEquals("a", trt.xa$());
    assertEquals("a$", trt.xa$$());
    assertEquals("a$", trt.xa$$$());
    assertEquals("a$.$", trt.xa$$_$$());

    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$Naming.xml");
    IO.copy(r.openInputStream(), System.err);
    Document d = db.parse(r.openInputStream(), "UTF-8");
    assertEquals(
        "http://www.osgi.org/xmlns/metatype/v1.1.0", d.getDocumentElement().getNamespaceURI());
  }