package org.drools.guvnor.server.util;

import junit.framework.Assert;

import org.drools.guvnor.client.common.AssetFormats;
import org.drools.guvnor.client.rpc.AnalysisReport;
import org.drools.guvnor.server.ServiceImplementation;
import org.drools.repository.AssetItem;
import org.drools.repository.PackageItem;
import org.drools.repository.RulesRepository;
import org.drools.verifier.VerifierConfiguration;
import org.junit.Before;
import org.junit.Test;

public class VerifierRunnerTest {

    private ServiceImplementation serviceImplementation;
    private PackageItem           packageItem;

    @Before
    public void setUp() throws Exception {
        serviceImplementation = new ServiceImplementation();

        serviceImplementation.repository = new RulesRepository( TestEnvironmentSessionHelper.getSession() );

        packageItem = serviceImplementation.getRulesRepository().createPackage( "VerifierRunnerTest",
                                                                                "" );
    }

    @Test
    public void verifyPackageItem() { 
        VerifierRunner verifierRunner = checkinDRLAssetToPackage( "/VerifierCauseTrace.drl" );

        AnalysisReport report = verifierRunner.verify( packageItem.getName(),
                                                       VerifierConfiguration.VERIFYING_SCOPE_KNOWLEDGE_PACKAGE );

        Assert.assertNotNull( report );
        Assert.assertEquals( 1,
                             report.warnings.length );

        System.out.println( report.warnings[0].description );
    }

    private VerifierRunner checkinDRLAssetToPackage(String assetName) {
        VerifierRunner verifierRunner = new VerifierRunner();
        AssetItem asset = packageItem.addAsset( "verifyPackageItem",
                                                "" );
        asset.updateFormat( AssetFormats.DRL );

        asset.updateContent( IO.read( this.getClass().getResourceAsStream( assetName ) ) );
        asset.checkin( "" );

        return verifierRunner;
    }
}

@@ -33,16 +33,47 @@
 .util;%0A%0A
+import java.util.Collections;%0A%0A
 import j
@@ -1096,10 +1096,9 @@
 () %7B
- 
 %0A
+
     
@@ -1259,18 +1259,8 @@
 Item
-.getName()
 ,%0A  
@@ -1367,16 +1367,95 @@
 _PACKAGE
+,%0A                                                       Collections.EMPTY_LIST
  );%0A%0A   

Fix for a broken Guvnor test. Problem happened when Package name was verified instead of PackageItem.