Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.kie.workbench.common.services.refactoring.backend.server.query.findfieldtypes;
  
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.List;
  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.uberfire.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.ValueFieldIndexTerm;
 import  org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm;
 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 FindTypeFieldsQuery() {
             @Override
             public ResponseBuilder getResponseBuilder() {
                 return new DefaultResponseBuilderioService() );
             }
         } );
     }};
 
     @Test
         final Instance<NamedQuerynamedQueriesProducer = mock( Instance.class );
         when( namedQueriesProducer.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 );
         final Path path2 = .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( "FindTypeFieldsQuery",
                                                                                new HashSet<ValueIndexTerm>() {{
                                                                                    addnew ValueTypeIndexTerm( "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant" ) );
                                                                                    addnew ValueFieldIndexTerm( "age" ) );
                                                                                }},
                                                                                0,
                                                                                10 );
 
             try {
                 final PageResponse<RefactoringPageRow> response = service.queryrequest );
                 assertNotNull( response );
                 assertEquals( 2,
                               response.getPageRowList().size() );
                 assertResponseContainsresponse.getPageRowList(),
                                         path1 );
                 assertResponseContainsresponse.getPageRowList(),
                                         path2 );
 
             } catch ( IllegalArgumentException e ) {
                 fail();
             }
         }
 
     }
 
     @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 ) );
            put( ProjectRootPathIndexTerm.TERM,
                 new FilenameAnalyzer( LUCENE_40 ) );
        }};
    }
    @Override
        return new TestDrlFileTypeDefinition();
    }
    @Override
    protected String getRepositoryName() {
        return this.getClass().getSimpleName();
    }
    private void assertResponseContainsfinal List<RefactoringPageRow> rows,
                                         final Path path ) {
        for ( RefactoringPageRow row : rows ) {
            final String rowFileName = ( (org.uberfire.backend.vfs.Path) row.getValue() ).getFileName();
            final String fileName = path.getFileName().toString();
            if ( rowFileName.endsWithfileName ) ) {
                return;
            }
        }
        fail( "Response does not contain expected Path '" + path.toUri().toString() + "'." );
    }
New to GrepCode? Check out our FAQ X