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 org.junit.Test;
 import  org.uberfire.ext.metadata.backend.lucene.analyzer.FilenameAnalyzer;
 import  org.kie.workbench.common.services.refactoring.model.index.terms.ProjectRootPathIndexTerm;
 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.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 FindRulesByProjectQuery() {
             @Override
             public ResponseBuilder getResponseBuilder() {
                 return new DefaultResponseBuilderioService() );
             }
         } );
     }};
 
     @Test
     public void testQueryInvalidIndexTerms() throws IOExceptionInterruptedException {
         final Instance<NamedQuerynamedQueriesProducer = mockInstance.class );
         whennamedQueriesProducer.iterator() ).thenReturn( .iterator() );
 
         final RefactoringQueryServiceImpl service = new RefactoringQueryServiceImplgetConfig(),
                                                                                      namedQueriesProducer );
         service.init();
 
         //Add test files
         final Path path1 = .resolve( "drl1.drl" );
         final String drl1 = loadText"drl1.drl" );
         ioService().write( path1,
                            drl1 );
 
         Thread.sleep( 5000 ); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
 
         {
             final RefactoringPageRequest request = new RefactoringPageRequest( "FindRulesByProjectQuery",
                                                                                new HashSet<ValueIndexTerm>(),
                                                                                0,
                                                                                -1 );
 
             try {
                 final PageResponse<RefactoringPageRow> response = service.queryrequest );
                 fail();
             } catch ( IllegalArgumentException e ) {
                 //Swallow. Expected
             }
         }
 
         {
             final RefactoringPageRequest request = new RefactoringPageRequest( "FindRulesByProjectQuery",
                                                                                new HashSet<ValueIndexTerm>() {{
                                                                                    addnew ValueTypeIndexTerm( "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant" ) );
                                                                                }},
                                                                                0,
                                                                                -1 );
 
             try {
                 final PageResponse<RefactoringPageRow> response = service.queryrequest );
                 fail();
             } catch ( IllegalArgumentException e ) {
                 //Swallow. Expected
             }
         }
 
         {
             final RefactoringPageRequest request = new RefactoringPageRequest( "FindRulesByProjectQuery",
                                                                                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.queryrequest );
                fail();
            } catch ( IllegalArgumentException e ) {
                //Swallow. Expected
            }
        }
    }
    @Override
    protected TestIndexer getIndexer() {
        return new TestDrlFileIndexer();
    }
    @Override
    public Map<StringAnalyzergetAnalyzers() {
        return new HashMap<StringAnalyzer>() {{
            put( RuleAttributeIndexTerm.TERM,
                 new RuleAttributeNameAnalyzer ) );
            put( ProjectRootPathIndexTerm.TERM,
                 new FilenameAnalyzer(  ) );
        }};
    }
    @Override
        return new TestDrlFileTypeDefinition();
    }
    @Override
    protected String getRepositoryName() {
        return this.getClass().getSimpleName();
    }
New to GrepCode? Check out our FAQ X