コード例 #1
0
  @Test
  public void testServiceConfig() throws Exception {
    deploy("OSGI-INF/convert-service-config-test.xml");
    assertNotNull(Framework.getLocalService(ConversionService.class));

    assertEquals(12, ConversionServiceImpl.getGCIntervalInMinutes());
    assertEquals(132, ConversionServiceImpl.getMaxCacheSizeInKB());
    assertFalse(ConversionServiceImpl.isCacheEnabled());
  }
コード例 #2
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);
  }
コード例 #3
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"));
  }
コード例 #4
0
 /** @since 6.0 */
 public static void deleteCache() {
   cacheLock.writeLock().lock();
   try {
     cache.clear();
     new File(ConversionServiceImpl.getCacheBasePath()).delete();
   } finally {
     cacheLock.writeLock().unlock();
   }
 }
コード例 #5
0
  protected static String getCacheEntryPath(String key) {
    Path path = new Path(ConversionServiceImpl.getCacheBasePath());

    List<String> subPath = getSubPathFromKey(key);

    for (String subPart : subPath) {
      path = path.append(subPart);
      new File(path.toString()).mkdir();
    }

    // path = path.append(key);

    return path.toString();
  }