1 package com.atlassian.plugin.osgi.container;
2
3 import junit.framework.TestCase;
4 import com.atlassian.plugin.test.PluginTestUtils;
5 import com.atlassian.plugin.osgi.container.impl.DefaultOsgiPersistentCache;
6
7 import java.io.File;
8 import java.io.IOException;
9
10 import org.apache.commons.io.FileUtils;
11
12 public class TestDefaultOsgiPersistentCache extends TestCase
13 {
14 private File tmpDir;
15
16 @Override
17 protected void setUp() throws Exception
18 {
19 super.setUp();
20 tmpDir = PluginTestUtils.createTempDirectory(TestDefaultOsgiPersistentCache.class);
21 }
22
23 public void testRecordLastVersion() throws IOException
24 {
25 DefaultOsgiPersistentCache cache = new DefaultOsgiPersistentCache(tmpDir);
26 File versionFile = new File(new File(tmpDir, "transformed-plugins"), "cache.key");
27 cache.validate("1.0");
28 assertTrue(versionFile.exists());
29 String txt = FileUtils.readFileToString(versionFile);
30
31
32
33
34 assertEquals(String.valueOf(48563), txt);
35 }
36
37 public void testCleanOnUpgrade() throws IOException
38 {
39 DefaultOsgiPersistentCache cache = new DefaultOsgiPersistentCache(tmpDir);
40 File tmp = File.createTempFile("foo", ".txt", new File(tmpDir, "transformed-plugins"));
41 cache.validate("1.0");
42 assertTrue(tmp.exists());
43 cache.validate("2.0");
44 assertFalse(tmp.exists());
45 }
46
47 public void testNullVersion() throws IOException
48 {
49 DefaultOsgiPersistentCache cache = new DefaultOsgiPersistentCache(tmpDir);
50 cache.validate(null);
51 File tmp = File.createTempFile("foo", ".txt", new File(tmpDir, "transformed-plugins"));
52 assertTrue(tmp.exists());
53 cache.validate(null);
54 assertTrue(tmp.exists());
55 }
56
57 @Override
58 protected void tearDown() throws Exception
59 {
60 super.tearDown();
61 FileUtils.cleanDirectory(tmpDir);
62 }
63 }