1   package com.atlassian.plugin.osgi;
2   
3   import com.atlassian.plugin.DefaultModuleDescriptorFactory;
4   import com.atlassian.plugin.JarPluginArtifact;
5   import com.atlassian.plugin.descriptors.AbstractModuleDescriptor;
6   import com.atlassian.plugin.test.PluginJarBuilder;
7   import com.atlassian.plugin.hostcontainer.DefaultHostContainer;
8   
9   import java.io.File;
10  
11  public class TestLogging extends PluginInContainerTestBase
12  {
13      public void testToStringPriming() throws Exception
14      {
15          final DefaultModuleDescriptorFactory factory = new DefaultModuleDescriptorFactory(new DefaultHostContainer());
16          final File pluginJar = new PluginJarBuilder("testUpgradeOfBundledPlugin")
17                  .addFormattedResource("atlassian-plugin.xml",
18                          "<atlassian-plugin name='Test' key='test.bundled.plugin' pluginsVersion='2'>",
19                          "    <plugin-info>",
20                          "        <version>1.0</version>",
21                          "    </plugin-info>",
22                          "    <component key='obj' class='my.Foo'/>",
23                          "</atlassian-plugin>")
24                  .addFormattedJava("my.Foo",
25                          "package my;",
26                          "import com.atlassian.plugin.osgi.TestLogging;",
27                          "public class Foo {",
28                          "  public Foo() {",
29                          "     throw new TestLogging.CountingException();",
30                          "  }",
31                          "}")
32                  .build();
33          initBundlingPluginManager(factory, pluginJar);
34  
35          // for some reason, it is called 14 times w/o priming, but 19 with.  Sadly, this test only works correctly
36          // when invoked from Maven
37          assertEquals(19, CountingException.count);
38      }
39  
40      public static class CountingException extends RuntimeException
41      {
42          public static int count = 0;
43          public String toString()
44          {
45              count++;
46              return "count:"+count;
47          }
48      }
49  }