@Test public void toQueryOptions_load_all_fields() { RuleMapping mapping = new RuleMapping(languages, macroInterpreter, debtModel, userSessionRule); SimpleGetRequest request = new SimpleGetRequest(); request.setParam(Param.PAGE, "1"); request.setParam(Param.PAGE_SIZE, "10"); QueryContext queryContext = mapping.newQueryOptions(SearchOptions.create(request)); assertThat(queryContext.getFieldsToReturn()).isEmpty(); }
@Test public void toQueryOptions_html_note_requires_markdown_note() { RuleMapping mapping = new RuleMapping(languages, macroInterpreter, debtModel, userSessionRule); SimpleGetRequest request = new SimpleGetRequest(); request.setParam(Param.PAGE, "1"); request.setParam(Param.PAGE_SIZE, "10"); request.setParam(Param.FIELDS, "htmlNote"); QueryContext queryContext = mapping.newQueryOptions(SearchOptions.create(request)); assertThat(queryContext.getFieldsToReturn()) .containsOnly(RuleNormalizer.RuleField.NOTE.field()); }
@Test public void toQueryOptions_debt_characteristics() { RuleMapping mapping = new RuleMapping(languages, macroInterpreter, debtModel, userSessionRule); SimpleGetRequest request = new SimpleGetRequest(); request.setParam(Param.PAGE, "1"); request.setParam(Param.PAGE_SIZE, "10"); request.setParam(Param.FIELDS, "debtChar"); QueryContext queryContext = mapping.newQueryOptions(SearchOptions.create(request)); assertThat(queryContext.getFieldsToReturn()) .containsOnly(RuleNormalizer.RuleField.CHARACTERISTIC.field()); }
@Test public void toQueryOptions_debt_requires_group_of_fields() { RuleMapping mapping = new RuleMapping(languages, macroInterpreter, debtModel, userSessionRule); SimpleGetRequest request = new SimpleGetRequest(); request.setParam(Param.PAGE, "1"); request.setParam(Param.PAGE_SIZE, "10"); request.setParam(Param.FIELDS, "debtRemFn"); QueryContext queryContext = mapping.newQueryOptions(SearchOptions.create(request)); assertThat(queryContext.getFieldsToReturn()) .containsOnly( RuleNormalizer.RuleField.DEBT_FUNCTION_COEFFICIENT.field(), RuleNormalizer.RuleField.DEBT_FUNCTION_OFFSET.field(), RuleNormalizer.RuleField.DEBT_FUNCTION_TYPE.field()); }
@Test public void toQueryOptions_load_only_few_simple_fields() { RuleMapping mapping = new RuleMapping(languages, macroInterpreter, debtModel, userSessionRule); SimpleGetRequest request = new SimpleGetRequest(); request.setParam(Param.PAGE, "1"); request.setParam(Param.PAGE_SIZE, "10"); request.setParam(Param.FIELDS, "repo,name,lang"); QueryContext queryContext = mapping.newQueryOptions(SearchOptions.create(request)); assertThat(queryContext.getFieldsToReturn()) .containsOnly( RuleNormalizer.RuleField.REPOSITORY.field(), RuleNormalizer.RuleField.NAME.field(), RuleNormalizer.RuleField.LANGUAGE.field()); }
@Test public void toQueryOptions_debt_overloaded() { RuleMapping mapping = new RuleMapping(languages, macroInterpreter, debtModel, userSessionRule); SimpleGetRequest request = new SimpleGetRequest(); request.setParam(Param.PAGE, "1"); request.setParam(Param.PAGE_SIZE, "10"); request.setParam(Param.FIELDS, "debtOverloaded"); QueryContext queryContext = mapping.newQueryOptions(SearchOptions.create(request)); assertThat(queryContext.getFieldsToReturn()) .containsOnly( RuleNormalizer.RuleField.CHARACTERISTIC_OVERLOADED.field(), RuleNormalizer.RuleField.SUB_CHARACTERISTIC_OVERLOADED.field(), RuleNormalizer.RuleField.DEBT_FUNCTION_TYPE_OVERLOADED.field()); }