@Test public void testGetSearchClauseOneProjectIsFlag() throws Exception { final CustomFieldParamsImpl customFieldParams = new CustomFieldParamsImpl(); customFieldParams.addValue(Collections.singleton("123")); final Map<String, Object> map = MapBuilder.<String, Object>newBuilder() .add(urlParameterName, customFieldParams) .add( SystemSearchConstants.forProject().getUrlParameter(), Collections.singletonList("-1")) .toMap(); FieldValuesHolder values = new FieldValuesHolderImpl(map); final AtomicBoolean specialCalled = new AtomicBoolean(false); final IndexedInputHelper helper = new DefaultIndexedInputHelper<Version>( indexInfoResolver, operandResolver, fieldFlagOperandRegistry, searchContextVisibilityChecker) { @Override public Clause getClauseForNavigatorValues(final String clauseName, final Set values) { return null; } }; transformer = new VersionCustomFieldSearchInputTransformer( urlParameterName, clauseNames, customField, indexInfoResolver, operandResolver, fieldFlagOperandRegistry, searchContextVisibilityChecker, versionResolver, customFieldInputHelper, versionManager) { @Override protected DefaultIndexedInputHelper getDefaultIndexedInputHelper() { throw new UnsupportedOperationException( "Should not have called through to the special indexed input helper"); } @Override protected IndexedInputHelper getIndexedInputHelper() { specialCalled.set(true); return helper; } @Override protected String getClauseName(final User searcher, final ClauseNames clauseNames) { return primaryClauseName; } }; replay(); transformer.getSearchClause(theUser, values); assertTrue(specialCalled.get()); }
@Test public void testGetSearchClauseValuesPresentParamsNull() throws Exception { final String searcherId = "searcherId"; final FieldValuesHolderImpl valuesHolder = new FieldValuesHolderImpl(); valuesHolder.put(searcherId, null); final VersionCustomFieldSearchInputTransformer transformer = new VersionCustomFieldSearchInputTransformer( searcherId, new ClauseNames("clauseName"), mockController.getMock(CustomField.class), mockController.getMock(VersionIndexInfoResolver.class), mockController.getMock(JqlOperandResolver.class), mockController.getMock(FieldFlagOperandRegistry.class), searchContextVisibilityChecker, versionResolver, customFieldInputHelper, versionManager) { @Override protected Clause getClauseFromParams( final User searcher, final CustomFieldParams params, final FieldValuesHolder fieldValuesHolder) { fail("Should not have been called"); return null; } }; mockController.replay(); assertNull(transformer.getSearchClause(null, valuesHolder)); mockController.verify(); }
@Test public void testGetSearchClauseValuesNotPresent() throws Exception { final FieldValuesHolderImpl valuesHolder = new FieldValuesHolderImpl(); VersionCustomFieldSearchInputTransformer transformer = createTransformer("cf[1000]"); assertNull(transformer.getSearchClause(null, valuesHolder)); mockController.verify(); }
@Test public void testGetSearchClauseValuesPresentParamsNotEmpty() throws Exception { final String searcherId = "searcherId"; final String clauseName = "clauseName"; final CustomFieldParamsImpl customFieldParams = new CustomFieldParamsImpl(); customFieldParams.addValue(Collections.singleton("dontcare")); final FieldValuesHolderImpl valuesHolder = new FieldValuesHolderImpl(); valuesHolder.put(searcherId, customFieldParams); final AtomicBoolean wasCalled = new AtomicBoolean(false); final Clause expectedClause = new TerminalClauseImpl(clauseName, Operator.EQUALS, "blah"); final VersionCustomFieldSearchInputTransformer transformer = new VersionCustomFieldSearchInputTransformer( searcherId, new ClauseNames(clauseName), mockController.getMock(CustomField.class), mockController.getMock(VersionIndexInfoResolver.class), mockController.getMock(JqlOperandResolver.class), mockController.getMock(FieldFlagOperandRegistry.class), searchContextVisibilityChecker, versionResolver, customFieldInputHelper, versionManager) { @Override protected Clause getClauseFromParams( final User searcher, final CustomFieldParams params, final FieldValuesHolder fieldValuesHolder) { wasCalled.set(true); return expectedClause; } }; mockController.replay(); assertEquals(expectedClause, transformer.getSearchClause(null, valuesHolder)); assertTrue(wasCalled.get()); mockController.verify(); }
@Test public void testGetSearchClauseNoNavigatorValues() throws Exception { FieldValuesHolder values = new FieldValuesHolderImpl(MapBuilder.emptyMap()); transformer = new VersionCustomFieldSearchInputTransformer( urlParameterName, clauseNames, customField, indexInfoResolver, operandResolver, fieldFlagOperandRegistry, searchContextVisibilityChecker, versionResolver, customFieldInputHelper, versionManager); replay(); final Clause result = transformer.getSearchClause(theUser, values); assertNull(result); }