package net.sf.plugfy.verifier.spring;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;

import net.sf.plugfy.verifier.VerificationContext;

import org.apache.bcel.util.ClassLoaderRepository;
import org.junit.Test;

/**
 *  Unit tests for the spring verifier
 * 
 * @author markus
 */
public class SpringVerifierTest {
    
    /**
     * Test if missing bean classes are found
     * 
     * @throws Exception
     */
    @Test
    public void testVerifier() throws Exception {
        final URL url = new File("sample/sample-spring.jar").toURI().toURL();
        final ClassLoader classLoader = new URLClassLoader(new URL[] {url});
        VerificationContext context = new VerificationContext(new ClassLoaderRepository(classLoader), classLoader, url);
        new SpringVerifier().verify("bean-config.xml", context);
        System.out.println(context.getResult());
        System.out.println("-------------------");
        assertThat(context.getResult().toString(), is("[JavaViolation [sourceType=bean-config.xml, requiredType=org.springframework.samples.jpetstore.dao.ibatis.SqlMapAccountDao]]"));
    }

}

@@ -80,16 +80,51 @@
 rs.is;%0D%0A
+import static org.junit.Assert.*;%0D%0A
 import s
@@ -155,24 +155,24 @@
 ssertThat;%0D%0A
-
 %0D%0Aimport jav
@@ -291,16 +291,70 @@
 ontext;%0D
+%0Aimport net.sf.plugfy.verifier.container.JarVerifier;%0D
 %0A%0D%0Aimpor
@@ -680,16 +680,23 @@
 Verifier
+Classes
 () throw
@@ -1153,24 +1153,24 @@
 -------%22);%0D%0A
-
         asse
@@ -1348,14 +1348,904 @@
 %0D%0A    %7D%0D
+%0A    %0D%0A    /**%0D%0A     * Test if missing bean ids are found%0D%0A     * %0D%0A     * @throws Exception%0D%0A     */%0D%0A    @Test%0D%0A    public void testProperties() throws Exception %7B%0D%0A        final URL url = new File(%22sample/sample-spring.jar%22).toURI().toURL();%0D%0A        final ClassLoader classLoader = new URLClassLoader(new URL%5B%5D %7Burl%7D);%0D%0A        VerificationContext context = new VerificationContext(new ClassLoaderRepository(classLoader), classLoader, url);%0D%0A        new JarVerifier().verify(url, context);%0D%0A        System.out.println(context);%0D%0A        System.out.println(%22-------------------%22);%0D%0A        assertThat(context.toString(), is(%22VerificationContext %5Bverified=file:/D:/workspace/plugfy/sample/sample-spring.jar, result=%5BJavaViolation %5BsourceType=bean-config.xml, requiredType=org.springframework.samples.jpetstore.dao.ibatis.SqlMapAccountDao%5D%5D, missingBeanIds=%5BsampleBeanMissing%5D%5D%22));%0D%0A    %7D%0D
 %0A%0D%0A%7D%0D%0A

test missing bean ids