Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.kie.workbench.common.services.refactoring.backend.server.query.findrules;
  
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;
  import  javax.enterprise.inject.Instance;
  
 import  org.apache.lucene.analysis.Analyzer;
 import  org.junit.Test;
 import  org.kie.workbench.common.services.refactoring.model.index.terms.RuleAttributeIndexTerm;
 import  org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm;
 import  org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueRuleIndexTerm;
 import  org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueTypeIndexTerm;
 import  org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest;
 import  org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow;
 import  org.kie.workbench.common.services.refactoring.service.RefactoringQueryService;
 import  org.uberfire.java.nio.file.Path;
 import  org.uberfire.paging.PageResponse;
 
 import static org.apache.lucene.util.Version.*;
 import static org.junit.Assert.*;
 import static org.mockito.Mockito.*;
 
 
     private Set<NamedQueryqueries = new HashSet<NamedQuery>() {{
         addnew FindRulesQuery() {
             @Override
             public ResponseBuilder getResponseBuilder() {
                 return new DefaultResponseBuilderioService() );
             }
         } );
     }};
 
     @Test
         final Instance<NamedQuerynamedQueriesProducer = mock( Instance.class );
         when( namedQueriesProducer.iterator() ).thenReturn( .iterator() );
 
         final RefactoringQueryService service = new RefactoringQueryServiceImplgetConfig(),
                                                                                  namedQueriesProducer );
 
         //Don't ask, but we need to write a single file first in order for indexing to work
         final Path basePath = getDirectoryPath().resolveSibling( "someNewOtherPath" );
         ioService().write( basePath.resolve( "dummy" ),
                            "<none>" );
 
         //Add test files
         final Path path1 = basePath.resolve( "drl1.drl" );
         final String drl1 = loadText"drl1.drl" );
         ioService().write( path1,
                            drl1 );
         final Path path2 = basePath.resolve( "drl2.drl" );
         final String drl2 = loadText"drl2.drl" );
         ioService().write( path2,
                            drl2 );
 
         Thread.sleep( 5000 ); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
 
         {
             final RefactoringPageRequest request = new RefactoringPageRequest( "FindRulesQuery",
                                                                                new HashSet<ValueIndexTerm>(),
                                                                                0,
                                                                                -1 );
 
             try {
                 final PageResponse<RefactoringPageRow> response = service.query( request );
                 fail();
             } catch ( IllegalArgumentException e ) {
                 //Swallow. Expected
             }
         }
 
         {
             final RefactoringPageRequest request = new RefactoringPageRequest( "FindRulesQuery",
                                                                                new HashSet<ValueIndexTerm>() {{
                                                                                    addnew ValueTypeIndexTerm( "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant" ) );
                                                                                }},
                                                                                0,
                                                                                -1 );
 
             try {
                 final PageResponse<RefactoringPageRow> response = service.query( request );
                 fail();
             } catch ( IllegalArgumentException e ) {
                 //Swallow. Expected
             }
        }
        {
            final RefactoringPageRequest request = new RefactoringPageRequest( "FindRulesQuery",
                                                                               new HashSet<ValueIndexTerm>() {{
                                                                                   addnew ValueRuleIndexTerm( "myRule" ) );
                                                                                   addnew ValueTypeIndexTerm( "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant" ) );
                                                                               }},
                                                                               0,
                                                                               -1 );
            try {
                final PageResponse<RefactoringPageRow> response = service.query( request );
                fail();
            } catch ( IllegalArgumentException e ) {
                //Swallow. Expected
            }
        }
    }
    @Override
    protected TestIndexer getIndexer() {
        return new TestDrlFileIndexer();
    }
    @Override
    public Map<String, Analyzer> getAnalyzers() {
        return new HashMap<String, Analyzer>() {{
            put( RuleAttributeIndexTerm.TERM,
                 new RuleAttributeNameAnalyzer( LUCENE_40 ) );
        }};
    }
    @Override
        return new TestDrlFileTypeDefinition();
    }
    @Override
    protected String getRepositoryName() {
        return this.getClass().getSimpleName();
    }
New to GrepCode? Check out our FAQ X