コード例 #1
0
  @Test
  public void testTerminalClauseOneSearchHandler() throws Exception {
    final TerminalClause input = new TerminalClauseImpl("field", Operator.EQUALS, "Value");
    final SearchHandlerManager manager = mockController.getMock(SearchHandlerManager.class);

    final ClausePermissionHandler permissionHandler =
        mockController.getMock(ClausePermissionHandler.class);
    EasyMock.expect(permissionHandler.sanitise(null, input)).andReturn(input);

    final ClauseHandler handler = new MockClauseHandler(null, null, permissionHandler, null);
    EasyMock.expect(manager.getClauseHandler((User) null, "field"))
        .andReturn(Collections.singletonList(handler));

    final JqlOperandResolver jqlOperandResolver = mockController.getMock(JqlOperandResolver.class);

    mockController.replay();

    ClauseSanitisingVisitor visitor =
        new ClauseSanitisingVisitor(manager, jqlOperandResolver, null) {
          @Override
          TerminalClause sanitiseOperands(final TerminalClause clause) {
            return clause;
          }
        };

    final Clause clause = input.accept(visitor);
    assertSame(clause, input);

    mockController.verify();
  }
コード例 #2
0
  @Test
  public void testTerminalClauseTwoSearchHandlersDifferent() throws Exception {
    final TerminalClause input1 = new TerminalClauseImpl("field", Operator.EQUALS, "Value1");
    final TerminalClause input2 = new TerminalClauseImpl("field", Operator.EQUALS, "Value2");
    final SearchHandlerManager manager = mockController.getMock(SearchHandlerManager.class);

    final ClausePermissionHandler permissionHandler =
        mockController.getMock(ClausePermissionHandler.class);
    EasyMock.expect(permissionHandler.sanitise(null, input1)).andReturn(input1);
    EasyMock.expect(permissionHandler.sanitise(null, input1)).andReturn(input2);

    final ClauseHandler handler1 = new MockClauseHandler(null, null, permissionHandler, null);
    final ClauseHandler handler2 = new MockClauseHandler(null, null, permissionHandler, null);

    EasyMock.expect(manager.getClauseHandler((User) null, "field"))
        .andReturn(CollectionBuilder.newBuilder(handler1, handler2).asList());

    final JqlOperandResolver jqlOperandResolver = mockController.getMock(JqlOperandResolver.class);

    mockController.replay();

    ClauseSanitisingVisitor visitor =
        new ClauseSanitisingVisitor(manager, jqlOperandResolver, null) {
          @Override
          TerminalClause sanitiseOperands(final TerminalClause clause) {
            return clause;
          }
        };

    final Clause expected = new OrClause(input1, input2);
    final Clause clause = input1.accept(visitor);
    assertEquals(expected, clause);

    mockController.verify();
  }
コード例 #3
0
 private boolean stringValueExists(
     PossibleValuesHolder possibleValuesHolder, User searcher, String fieldName, String rawValue) {
   final String valuePrefix = "";
   final Collection<ClauseHandler> clauseHandlers =
       searchHandlerManager.getClauseHandler(searcher, fieldName);
   if (clauseHandlers != null && clauseHandlers.size() == 1) {
     ClauseHandler clauseHandler = clauseHandlers.iterator().next();
     if (clauseHandler instanceof ValueGeneratingClauseHandler) {
       if (possibleValuesHolder.getCurrentValues() == null) {
         final ClauseValuesGenerator.Results generatorResults =
             ((ValueGeneratingClauseHandler) (clauseHandler))
                 .getClauseValuesGenerator()
                 .getPossibleValues(
                     searcher,
                     jqlChangeItemMapping.mapJqlClauseToFieldName(fieldName),
                     valuePrefix,
                     Integer.MAX_VALUE);
         final List<ClauseValuesGenerator.Result> list = generatorResults.getResults();
         final Set<String> possibleValues = new HashSet<String>(list.size());
         for (ClauseValuesGenerator.Result result : list) {
           possibleValues.add(result.getValue().toLowerCase());
         }
         possibleValuesHolder.setCurrentValues(possibleValues);
       }
       if (!possibleValuesHolder.getCurrentValues().contains(rawValue.toLowerCase())) {
         if (possibleValuesHolder.getHistoricalValues() == null) {
           final Set<String> possibleValuesSet =
               findAllPossibleFieldTerms(searcher, fieldName.toLowerCase());
           possibleValuesHolder.setHistoricalValues(possibleValuesSet);
         }
         return possibleValuesHolder.getHistoricalValues().contains(rawValue.toLowerCase());
       }
       return possibleValuesHolder.getCurrentValues().contains(rawValue.toLowerCase());
     }
   }
   return false;
 }