Exemplo n.º 1
0
  @Test
  public void testConverterLookup() throws Exception {
    deploy("OSGI-INF/converters-test-contrib1.xml");
    ConversionService cs = Framework.getLocalService(ConversionService.class);

    String converterName = cs.getConverterName("text/plain", "test/me");
    assertEquals("dummy1", converterName);

    converterName = cs.getConverterName("text/plain2", "test/me");
    assertNull(converterName);

    deploy("OSGI-INF/converters-test-contrib2.xml");

    converterName = cs.getConverterName("test/me", "foo/bar");
    assertEquals("dummy2", converterName);

    converterName = cs.getConverterName("text/plain", "foo/bar");
    assertEquals("dummyChain", converterName);

    Converter cv = ConversionServiceImpl.getConverter("dummyChain");
    assertNotNull(cv);
    boolean isChain = false;
    if (cv instanceof ChainedConverter) {
      ChainedConverter ccv = (ChainedConverter) cv;
      List<String> steps = ccv.getSteps();
      assertNotNull(steps);
      assertSame(2, steps.size());
      assertTrue(steps.contains("test/me"));
      assertTrue(steps.contains("foo/bar"));
      isChain = true;
    }
    assertTrue(isChain);

    converterName = cs.getConverterName("something", "somethingelse");
    assertEquals("custom", converterName);

    converterName = cs.getConverterName("any", "somethingelse");
    assertEquals("wildcard", converterName);

    converterName = cs.getConverterName("text/plain", "jacky/chan");
    assertEquals("dummyChain2", converterName);
    Converter cv2 = ConversionServiceImpl.getConverter("dummyChain2");
    assertNotNull(cv2);
    isChain = false;
    if (cv2 instanceof ChainedConverter) {
      ChainedConverter ccv = (ChainedConverter) cv2;
      List<String> steps = ccv.getSteps();
      assertNull(steps);
      isChain = true;
    }
    assertTrue(isChain);
  }
Exemplo n.º 2
0
  @Test
  public void testServiceContrib() throws Exception {
    deploy("OSGI-INF/converters-test-contrib1.xml");
    assertNotNull(Framework.getLocalService(ConversionService.class));

    Converter cv1 = ConversionServiceImpl.getConverter("dummy1");
    assertNotNull(cv1);

    ConverterDescriptor desc1 = ConversionServiceImpl.getConverterDescriptor("dummy1");
    assertNotNull(desc1);

    assertEquals("test/me", desc1.getDestinationMimeType());
    assertSame(2, desc1.getSourceMimeTypes().size());
    assertTrue(desc1.getSourceMimeTypes().contains("text/plain"));
    assertTrue(desc1.getSourceMimeTypes().contains("text/xml"));
  }