package com.atlassian.sal.ctk.test;

import java.util.Collection;

import org.springframework.stereotype.Component;

import com.atlassian.plugin.PluginController;
import com.atlassian.sal.api.component.ComponentLocator;
import com.atlassian.sal.ctk.CtkTest;
import com.atlassian.sal.ctk.CtkTestResults;
import com.atlassian.sal.spi.HostContextAccessor;

@Component
public class ComponentLocatorTest implements CtkTest
{

    public void execute(final CtkTestResults results)
    {
        try
        {
            final PluginController mgr = ComponentLocator.getComponent(PluginController.class);
            results.assertTrue("PluginController accessible in ComponentLocator", mgr != null);

            final Collection<PluginController> c = ComponentLocator.getComponents(PluginController.class);
            results.assertTrue("Should be one PluginController found", c != null && !c.isEmpty());
            results.assertTrue("There should be only one PluginController", c.size()==1);

            results.assertTrueOrWarn("HostContextAccessor should be accessible in ComponentLocator unless the application provides its own ComponentLocator and ", ComponentLocator.getComponent(HostContextAccessor.class) != null);
        } catch (final UnsupportedOperationException ex)
        {
            results.fail("ComponentLocator operations should be supported");
            ex.printStackTrace();
        }
    }
}

@@ -156,16 +156,60 @@
 roller;%0A
+import com.atlassian.plugin.PluginAccessor;%0A
 import c
@@ -1046,133 +1046,561 @@
     
-results.assertTrueOrWarn(%22HostContextAccessor should be accessible in ComponentLocator unless the application provides its ow
+final PluginAccessor accessor = ComponentLocator.getComponent(PluginAccessor.class);%0A            results.assertTrue(%22PluginAccessor accessible in ComponentLocator%22, accessor != null);%0A%0A            final Collection%3CPluginAccessor%3E ca = ComponentLocator.getComponents(PluginAccessor.class);%0A            results.assertTrue(%22Should be one PluginAccessor found%22, ca != null && !ca.isEmpty());%0A            results.assertTrue(%22There should be only one PluginAccessor%22, ca.size()==1);%0A%0A            results.assertTrueOrWarn(%22PluginAccessor should be accessible i
 n Co
@@ -1617,13 +1617,8 @@
 ator
- and 
 %22, C
@@ -1646,27 +1646,22 @@
 mponent(
-HostContext
+Plugin
 Accessor

Add test for PluginAccessor