package isomorphly;

import isomorphly.annotations.Component;
import isomorphly.annotations.Group;

import java.lang.annotation.Annotation;
import java.util.List;

import test.isomorphly.dummy.annotations.Plugin;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * Unit test for IsomorphlyEngine.
 */
public class IsomorphlyEngineTest extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
	private IsomorphlyEngine engine;
	
    public IsomorphlyEngineTest( String testName )
    {
        super( testName );
        String packageNames[] = {"test.isomorphly.dummy.annotations", "test.isomorphly.dummy.implementation"};
        engine = new IsomorphlyEngine(packageNames);
    }

    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( IsomorphlyEngineTest.class );
    }

    public void testIsomorphlyEngineInstance()
    {
        assertTrue( engine != null );
    }
    
    public void testEngineInit() {
        engine.init();
        assertTrue("engine not properly initialized.", engine.isInitialized());
    }

    public void testGroupScan()
    {
    	engine.init();
    	
    	List<Class<?>> groups = engine.getIsomorphlyGroups();
    	
    	assertNotNull("Groups should not null. Is engine's initialization ok?", groups);

    	assertFalse("Groups should not be empty. Is engine's initialization ok?", groups.isEmpty());
    	
    	for (Class<?> cls : groups) {
    		assertTrue(cls.isAnnotation());
    		assertTrue(cls.isAnnotationPresent(Group.class));
    	}

    	assertTrue(true);
    }
    
    public void testComponentsScan()
    {
    	engine.init();
    	
    	List<Class<?>> components = engine.getIsomorphlyComponents();
    	
    	assertNotNull("Components should not null. Is engine's initialization ok?", components);

    	assertTrue("Components should not be empty. Is engine's initialization ok?", components.size() > 0);
    	
    	for (Class<?> cls : components) {
    		assertTrue(cls.isAnnotation());
    		assertTrue(cls.isAnnotationPresent(Component.class));
    	}

    	assertTrue(true);
    }
    
    public void testPluginsScan()
    {
    	engine.init();
    	
    	List<Class<?>> annotatedClientGroups = engine.getIsomorphlyClientGroups();

    	assertFalse("AnnotatedClientGroups should not be empty. Is engine's initialization ok?", annotatedClientGroups.isEmpty());
    
    	for (Class<?> cls : annotatedClientGroups) {
    		assertFalse("AnnotatedClient classes cannot be Interfaces", cls.isInterface());
    		assertFalse("AnnotatedClient classes cannot be Annotations", cls.isAnnotation());
    		
    		boolean foundValidParentGroupAnnotation = false;
    		
    		for (Annotation a : cls.getAnnotations()) {
    			foundValidParentGroupAnnotation |= a.annotationType().isAnnotationPresent(Group.class);
    		} 
    		
    		assertTrue("Unable to find a valid @Group Annotation in " + cls.getName(), foundValidParentGroupAnnotation);
    		
    	}

    	assertTrue(engine != null);
    }
    
    
    
}

@@ -161,57 +161,8 @@
 t;%0A%0A
-import test.isomorphly.dummy.annotations.Plugin;%0A
 impo
@@ -1038,16 +1038,53 @@
 neInit()
+ throws IsomorphlyValidationException
  %7B%0A     
@@ -1097,24 +1097,25 @@
 ine.init();%0A
+%0A
         asse
@@ -1216,35 +1216,69 @@
 tGroupScan()
-%0A    %7B
+ throws IsomorphlyValidationException
 %0A    
+%7B%0A%09
 %09engine.init
@@ -1746,35 +1746,69 @@
 onentsScan()
-%0A    %7B
+ throws IsomorphlyValidationException
 %0A    
+%7B%0A%09
 %09engine.init
@@ -2309,27 +2309,1002 @@
 nsScan()
+ throws IsomorphlyValidationException%0A    %7B%0A%09%09engine.init();%0A    %09%0A    %09List%3CClass%3C?%3E%3E annotatedClientGroups = engine.getIsomorphlyClientGroups();%0A%0A    %09assertFalse(%22AnnotatedClientGroups should not be empty. Is engine's initialization ok?%22, annotatedClientGroups.isEmpty());%0A    %0A    %09for (Class%3C?%3E cls : annotatedClientGroups) %7B%0A    %09%09assertFalse(%22AnnotatedClient classes cannot be Interfaces%22, cls.isInterface());%0A    %09%09assertFalse(%22AnnotatedClient classes cannot be Annotations%22, cls.isAnnotation());%0A    %09%09%0A    %09%09boolean foundValidParentGroupAnnotation = false;%0A    %09%09%0A    %09%09for (Annotation a : cls.getAnnotations()) %7B%0A    %09%09%09foundValidParentGroupAnnotation %7C= a.annotationType().isAnnotationPresent(Group.class);%0A    %09%09%7D %0A    %09%09%0A    %09%09assertTrue(%22Unable to find a valid @Group Annotation in %22 + cls.getName(), foundValidParentGroupAnnotation);%0A    %09%09%0A    %09%7D%0A%0A    %09assertTrue(engine != null);%0A    %7D%0A  %0A    public void functionScanTest() throws IsomorphlyValidationException
 %0A    %7B%0A
-    
+%09
 %09engine.

add test on plugins scan and IsomorphlyValidationException throwing on validation tests