Browse Source

SONAR-3016 Provide default filters through extension point

tags/3.1
David Gageot 12 years ago
parent
commit
97d560cc74

+ 11
- 0
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java View File

@@ -19,6 +19,12 @@
*/
package org.sonar.plugins.core;

import org.sonar.plugins.core.filters.MyFavouritesFilter;

import org.sonar.plugins.core.filters.TreeMapFilter;

import org.sonar.plugins.core.filters.ProjectFilter;

import com.google.common.collect.Lists;
import org.sonar.api.CoreProperties;
import org.sonar.api.Extension;
@@ -298,6 +304,11 @@ public final class CorePlugin extends SonarPlugin {
extensions.add(TestsViewerDefinition.class);
extensions.add(Lcom4Viewer.class);

// filters
extensions.add(ProjectFilter.class);
extensions.add(TreeMapFilter.class);
extensions.add(MyFavouritesFilter.class);

// widgets
extensions.add(AlertsWidget.class);
extensions.add(CoverageWidget.class);

+ 53
- 0
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java View File

@@ -0,0 +1,53 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2012 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.core.filters;

import org.sonar.api.web.Criterion;

import org.sonar.api.web.Filter;
import org.sonar.api.web.FilterColumn;
import org.sonar.api.web.FilterTemplate;

/**
* Default myfavourites filter.
*
* @since 3.1
*/
public class MyFavouritesFilter extends FilterTemplate {
@Override
public String getName() {
return "My favouritesBis";
}

@Override
public Filter createFilter() {
Filter filter = Filter.create();
filter.setDisplayAs(Filter.LIST);
filter.setFavouritesOnly(true);
filter.add(Criterion.create("qualifier", null, Criterion.EQ, "VW,SVW,TRK,BRC,DIR,PAC,FIL,CLA,UTS,LIB", false));
filter.add(FilterColumn.create("metric", "alert_status", FilterColumn.DESC, false));
filter.add(FilterColumn.create("name", null, FilterColumn.ASC, false));
filter.add(FilterColumn.create("metric", "ncloc", FilterColumn.DESC, false));
filter.add(FilterColumn.create("metric", "violations_density", FilterColumn.DESC, false));
filter.add(FilterColumn.create("date", null, FilterColumn.DESC, false));
return filter;
}
}

+ 53
- 0
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/ProjectFilter.java View File

@@ -0,0 +1,53 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2012 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.core.filters;

import org.sonar.api.web.Criterion;
import org.sonar.api.web.Filter;
import org.sonar.api.web.FilterColumn;
import org.sonar.api.web.FilterTemplate;

/**
* Default projects filter.
*
* @since 3.1
*/
public class ProjectFilter extends FilterTemplate {
@Override
public String getName() {
return "ProjectsBis";
}

@Override
public Filter createFilter() {
Filter filter = Filter.create();
filter.setDisplayAs(Filter.LIST);
filter.add(Criterion.create("qualifier", null, Criterion.EQ, "TRK", false));
filter.add(FilterColumn.create("metric", "alert_status", FilterColumn.DESC, false));
filter.add(FilterColumn.create("name", null, FilterColumn.ASC, false));
filter.add(FilterColumn.create("version", null, FilterColumn.DESC, false));
filter.add(FilterColumn.create("metric", "ncloc", FilterColumn.DESC, false));
filter.add(FilterColumn.create("metric", "violations_density", FilterColumn.DESC, false));
filter.add(FilterColumn.create("date", null, FilterColumn.DESC, false));
filter.add(FilterColumn.create("links", null, FilterColumn.DESC, false));
return filter;
}
}

+ 50
- 0
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/TreeMapFilter.java View File

@@ -0,0 +1,50 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2012 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.core.filters;

import org.sonar.api.web.Criterion;

import org.sonar.api.web.Filter;
import org.sonar.api.web.FilterColumn;
import org.sonar.api.web.FilterTemplate;

/**
* Default treemap filter.
*
* @since 3.1
*/
public class TreeMapFilter extends FilterTemplate {
@Override
public String getName() {
return "TreemapBis";
}

@Override
public Filter createFilter() {
Filter filter = Filter.create();
filter.setDisplayAs(Filter.TREEMAP);
filter.add(Criterion.create("qualifier", null, Criterion.EQ, "TRK", false));
filter.add(FilterColumn.create("name", null, FilterColumn.ASC, false));
filter.add(FilterColumn.create("metric", "ncloc", FilterColumn.DESC, false));
filter.add(FilterColumn.create("metric", "violations_density", FilterColumn.DESC, false));
return filter;
}
}

+ 40
- 0
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/MyFavouritesFilterTest.java View File

@@ -0,0 +1,40 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2012 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.core.filters;

import org.junit.Test;
import org.sonar.api.web.Filter;

import static org.fest.assertions.Assertions.assertThat;

public class MyFavouritesFilterTest {
@Test
public void should_create_filter() {
MyFavouritesFilter template = new MyFavouritesFilter();

Filter filter = template.createFilter();

assertThat(template.getName()).isEqualTo("My favouritesBis");
assertThat(filter).isNotNull();
assertThat(filter.isFavouritesOnly()).isTrue();
assertThat(filter.getCriteria()).hasSize(1);
assertThat(filter.getColumns()).hasSize(5);
}
}

+ 39
- 0
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/ProjectFilterTest.java View File

@@ -0,0 +1,39 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2012 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.core.filters;

import org.junit.Test;
import org.sonar.api.web.Filter;

import static org.fest.assertions.Assertions.assertThat;

public class ProjectFilterTest {
@Test
public void should_create_filter() {
ProjectFilter template = new ProjectFilter();
Filter filter = template.createFilter();

assertThat(template.getName()).isEqualTo("ProjectsBis");
assertThat(filter).isNotNull();
assertThat(filter.getCriteria()).hasSize(1);
assertThat(filter.getColumns()).hasSize(7);
}
}

+ 39
- 0
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/TreeMapFilterTest.java View File

@@ -0,0 +1,39 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2012 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.core.filters;

import org.junit.Test;
import org.sonar.api.web.Filter;

import static org.fest.assertions.Assertions.assertThat;

public class TreeMapFilterTest {
@Test
public void should_create_filter() {
TreeMapFilter template = new TreeMapFilter();

Filter filter = template.createFilter();

assertThat(template.getName()).isEqualTo("TreemapBis");
assertThat(filter).isNotNull();
assertThat(filter.getCriteria()).hasSize(1);
assertThat(filter.getColumns()).hasSize(3);
}
}

+ 10
- 3
sonar-plugin-api/src/main/java/org/sonar/api/web/Criterion.java View File

@@ -30,7 +30,12 @@ import java.util.Set;
* @since 3.1
*/
public class Criterion {
public static final Set<String> OPERATORS = ImmutableSortedSet.of("=", ">", "<", ">=", "<=");
public static final String EQ = "=";
public static final String GT = ">";
public static final String GTE = ">=";
public static final String LT = "<";
public static final String LTE = "<=";
public static final Set<String> OPERATORS = ImmutableSortedSet.of(EQ, GT, GTE, LT, LTE);

private final String family;
private final String key;
@@ -53,7 +58,7 @@ public class Criterion {
/**
* Creates a new {@link Criterion} with a numerical value.
*
* <p>Valid values for the {@code operator} are <code>=</code>, <code>&gt;</code>, <code>&gt;=</code>, <code>&lt;</code> and <code>&lt;=</code></p>
* <p>Valid values for the {@code operator} are {@value #EQ}, {@value #GT}, {@value #GTE}, {@value #LT} and {@value #LTE}</p>
*
* <p>When the {@link Filter} is persisted, a validation is made on the {@code family} and the {@code key}.
* They should point to a valid criterion.</p>
@@ -67,7 +72,7 @@ public class Criterion {
/**
* Creates a new {@link Criterion} with a text value.
*
* <p>Valid values for the {@code operator} are <code>=</code>, <code>&gt;</code>, <code>&gt;=</code>, <code>&lt;</code> and <code>&lt;=</code></p>
* <p>Valid values for the {@code operator} are {@value #EQ}, {@value #GT}, {@value #GTE}, {@value #LT} and {@value #LTE}</p>
*
* <p>When the {@link Filter} is persisted, a validation is made on the {@code family} and the {@code key}.
* They should point to a valid criterion.</p>
@@ -99,6 +104,8 @@ public class Criterion {
/**
* Get the the criterion's operator.
*
* <p>Valid values for the {@code operator} are {@value #EQ}, {@value #GT}, {@value #GTE}, {@value #LT} and {@value #LTE}</p>
*
* @return the operator
*/
public String getOperator() {

+ 66
- 56
sonar-plugin-api/src/main/java/org/sonar/api/web/Filter.java View File

@@ -36,18 +36,14 @@ public class Filter {
public static final String LIST = "list";
public static final String TREEMAP = "treemap";

private boolean shared;
private boolean favouritesOnly;
private String defaultPeriod;
private String resourceKeyLike;
private String resourceNameLike;
private String language;
private String searchFor;
private String displayAs;
private int pageSize;
private List<Criterion> criteria;
private List<FilterColumn> columns;

private Filter() {
displayAs = LIST;
criteria = Lists.newArrayList();
columns = Lists.newArrayList();
}
@@ -59,93 +55,107 @@ public class Filter {
return new Filter();
}

/**
* Get the list of {@link Criterion} used to narrow down the results of this {@link Filter}.
*
* @return the criteria
*/
public List<Criterion> getCriteria() {
return criteria;
}

/**
* Add a {@link Criterion} to the list used to narrow down the results of this {@link Filter}.
*
* @return this filter
*/
public Filter add(Criterion criterion) {
this.criteria.add(criterion);
return this;
}

/**
* Get the list of {@link FilterColumn} displayed by this {@link Filter}.
*
* @return this columns
*/
public List<FilterColumn> getColumns() {
return columns;
}

/**
* Add a {@link FilterColumn} to the list of columns displayed by this {@link Filter}.
*
* @return this filter
*/
public Filter add(FilterColumn column) {
this.columns.add(column);
return this;
}

public boolean isShared() {
return shared;
}

public Filter setShared(boolean shared) {
this.shared = shared;
return this;
}

/**
* The {@link Filter} can be configured to return only favourites.
*
* @return <code>true</code> if favourites only are returned
*/
public boolean isFavouritesOnly() {
return favouritesOnly;
}

/**
* The {@link Filter} can be configured to return only favourites.
*/
public Filter setFavouritesOnly(boolean favouritesOnly) {
this.favouritesOnly = favouritesOnly;
return this;
}

public String getDefaultPeriod() {
return defaultPeriod;
}

public Filter setDefaultPeriod(String defaultPeriod) {
Preconditions.checkArgument(LIST.equals(defaultPeriod) || TREEMAP.equals(defaultPeriod), "Default period should be either %s or %s, not %s", LIST, TREEMAP, defaultPeriod);
this.defaultPeriod = defaultPeriod;
return this;
}

public String getResourceKeyLike() {
return resourceKeyLike;
}

public Filter setResourceKeyLike(String resourceKeyLike) {
this.resourceKeyLike = resourceKeyLike;
return this;
}

public String getResourceNameLike() {
return resourceNameLike;
}

public Filter setResourceNameLike(String resourceNameLike) {
this.resourceNameLike = resourceNameLike;
return this;
}

public String getLanguage() {
return language;
}

public Filter setLanguage(String language) {
this.language = language;
return this;
}

public String getSearchFor() {
return searchFor;
/**
* Get the type of display used by this {@link Filter}.
*
* <p>Can be either {@value #LIST} or {@value #TREEMAP}</p>
*
* @return the display type
*/
public String getDisplayAs() {
return displayAs;
}

public Filter setSearchFor(String searchFor) {
this.searchFor = searchFor;
/**
* Set the type of display used by this {@link Filter}.
*
* <p>Can be either {@value #LIST} or {@value #TREEMAP}</p>
*
* @return this filter
* @throws IllegalArgumentException if {@code displayAs) is not {@value #LIST} or {@value #TREEMAP}
*/
public Filter setDisplayAs(String displayAs) {
Preconditions.checkArgument(LIST.equals(displayAs) || TREEMAP.equals(displayAs), "Default period should be either %s or %s, not %s", LIST, TREEMAP, displayAs);
this.displayAs = displayAs;
return this;
}

/**
* Get the size of a page displayed this {@link Filter}.
*
* <p>The page size is between <code>20</code> and <code>200</code> (included)</p>
*
* @return the display type
*/
public int getPageSize() {
return pageSize;
}

/**
* Set the size of a page displayed this {@link Filter}.
*
* <p>The page size should be between <code>20</code> and <code>200</code> (included)</p>
*
* @return the display type
* @throws IllegalArgumentException if {@code pageSize) is not lower than {@code 20} or greater than {@code 200}
*/
public Filter setPageSize(int pageSize) {
Preconditions.checkArgument((pageSize >= 20) && (pageSize <= 200), "page size should be between 20 and 200");
this.pageSize = pageSize;
return this;
}

+ 7
- 16
sonar-plugin-api/src/main/java/org/sonar/api/web/FilterColumn.java View File

@@ -31,36 +31,36 @@ import com.google.common.base.Preconditions;
* @since 3.1
*/
public class FilterColumn {
public static final Set<String> DIRECTIONS = ImmutableSortedSet.of("ASC", "DESC");
public static final String ASC = "ASC";
public static final String DESC = "DESC";
public static final Set<String> DIRECTIONS = ImmutableSortedSet.of(ASC, DESC);

private final String family;
private final String key;
private final String sortDirection;
private final int orderIndex;
private final boolean variation;

private FilterColumn(String family, String key, String sortDirection, int orderIndex, boolean variation) {
private FilterColumn(String family, String key, String sortDirection, boolean variation) {
Preconditions.checkArgument(DIRECTIONS.contains(sortDirection), "Valid directions are %s, not '%s'", DIRECTIONS, sortDirection);

this.family = family;
this.key = key;
this.sortDirection = sortDirection;
this.orderIndex = orderIndex;
this.variation = variation;
}

/**
* Creates a new {@link FilterColumn}.
*
* <p>Valid values for the {@code sortDirection} are <code>ASC</code> and <code>DESC</code></p>
* <p>Valid values for the {@code sortDirection} are {@value #ASC}, {@value #DESC}</p>
*
* <p>When the @{see Filter} is persisted, a validation is made on the {@code family} and the {@code key}.
* They should point to a valid column description.</p>
*
* @throws IllegalArgumentException if {@code sortDirection} is not valid
*/
public static FilterColumn create(String family, String key, String sortDirection, int orderIndex, boolean variation) {
return new FilterColumn(family, key, sortDirection, orderIndex, variation);
public static FilterColumn create(String family, String key, String sortDirection, boolean variation) {
return new FilterColumn(family, key, sortDirection, variation);
}

/**
@@ -90,15 +90,6 @@ public class FilterColumn {
return sortDirection;
}

/**
* Get the the column's index.
*
* @return the index
*/
public int getOrderIndex() {
return orderIndex;
}

/**
* A column can be based on the varation of a value rather than on the value itself.
*

+ 3
- 3
sonar-plugin-api/src/test/java/org/sonar/api/web/FilterColumnTest.java View File

@@ -29,8 +29,8 @@ public class FilterColumnTest {

@Test
public void should_accept_valid_direction() {
FilterColumn.create("", "", "ASC", 0, false);
FilterColumn.create("", "", "DESC", 0, false);
FilterColumn.create("", "", "ASC", false);
FilterColumn.create("", "", "DESC", false);
}

@Test
@@ -38,7 +38,7 @@ public class FilterColumnTest {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("Valid directions are [ASC, DESC], not 'UNKNOWN'");

FilterColumn.create("", "", "UNKNOWN", 0, false);
FilterColumn.create("", "", "UNKNOWN", false);
}

}

+ 3
- 3
sonar-plugin-api/src/test/java/org/sonar/api/web/FilterTest.java View File

@@ -31,8 +31,8 @@ public class FilterTest {

@Test
public void should_accept_valid_periods() {
Filter.create().setDefaultPeriod("list");
Filter.create().setDefaultPeriod("treemap");
Filter.create().setDisplayAs("list");
Filter.create().setDisplayAs("treemap");
}

@Test
@@ -40,6 +40,6 @@ public class FilterTest {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("Default period should be either list or treemap, not <invalid>");

Filter.create().setDefaultPeriod("<invalid>");
Filter.create().setDisplayAs("<invalid>");
}
}

+ 5
- 8
sonar-server/src/main/java/org/sonar/server/startup/RegisterNewFilters.java View File

@@ -81,6 +81,7 @@ public final class RegisterNewFilters {
if (filterDao.findFilter(name) == null) {
dto = createDtoFromExtension(name, filter);
filterDao.insert(dto);
LOG.info("New filter '" + dto.getName() + "' registered");
}
// and save the fact that is has now already been loaded
loadedTemplateDao.insert(new LoadedTemplateDto(name, LoadedTemplateDto.FILTER_TYPE));
@@ -97,15 +98,10 @@ public final class RegisterNewFilters {
FilterDto filterDto = new FilterDto()
.setName(name)
.setPageSize((long) filter.getPageSize())
.setShared(filter.isShared())
.setShared(true)
.setFavourites(filter.isFavouritesOnly())
.setDefaultView(filter.getDefaultPeriod());
.setDefaultView(filter.getDisplayAs());

addCriteria(filterDto, "key", "=", filter.getResourceKeyLike());
addCriteria(filterDto, "name", "=", filter.getResourceNameLike());
addCriteria(filterDto, "language", "=", filter.getLanguage());
addCriteria(filterDto, "qualifier", "=", filter.getSearchFor());
for (Criterion criterion : filter.getCriteria()) {
filterDto.add(new CriterionDto()
.setFamily(criterion.getFamily())
@@ -116,11 +112,12 @@ public final class RegisterNewFilters {
.setVariation(criterion.isVariation()));
}

long orderIndex = 1L;
for (FilterColumn column : filter.getColumns()) {
filterDto.add(new FilterColumnDto()
.setFamily(column.getFamily())
.setKey(column.getKey())
.setOrderIndex((long) column.getOrderIndex())
.setOrderIndex(orderIndex++)
.setSortDirection(column.getSortDirection())
.setVariation(column.isVariation()));
}

+ 9
- 26
sonar-server/src/test/java/org/sonar/server/startup/RegisterNewFiltersTest.java View File

@@ -19,18 +19,14 @@
*/
package org.sonar.server.startup;

import org.sonar.core.filter.FilterColumnDto;

import org.sonar.api.web.FilterColumn;

import org.sonar.api.web.Criterion;

import com.google.common.collect.Iterables;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.web.Criterion;
import org.sonar.api.web.Filter;
import org.sonar.api.web.FilterColumn;
import org.sonar.api.web.FilterTemplate;
import org.sonar.core.filter.CriterionDto;
import org.sonar.core.filter.FilterColumnDto;
import org.sonar.core.filter.FilterDao;
import org.sonar.core.filter.FilterDto;
import org.sonar.core.template.LoadedTemplateDao;
@@ -116,25 +112,16 @@ public class RegisterNewFiltersTest {
@Test
public void should_create_dto_from_extension() {
when(filterTemplate.createFilter()).thenReturn(Filter.create()
.setShared(true)
.setFavouritesOnly(false)
.setDefaultPeriod("list")
.setResourceKeyLike("*KEY*")
.setResourceNameLike("*NAME*")
.setLanguage("java")
.setSearchFor("TRK,BRC")
.setDisplayAs("list")
.setPageSize(200)
.add(Criterion.create("metric", "complexity", "<", 12f, false))
.add(Criterion.create("metric", "LCOM4", ">=", "5", true))
.add(FilterColumn.create("metric", "distance", "ASC", 1, false))
.add(FilterColumn.create("metric", "instability", "DESC", 2, true))
.add(Criterion.create("metric", "complexity", Criterion.LT, 12f, false))
.add(Criterion.create("metric", "LCOM4", Criterion.GTE, "5", true))
.add(FilterColumn.create("metric", "distance", "ASC", false))
.add(FilterColumn.create("metric", "instability", "DESC", true))
);

FilterDto dto = register.createDtoFromExtension("Fake", filterTemplate.createFilter());
CriterionDto criteriaResourceKeyDto = Iterables.get(dto.getCriteria(), 0);
CriterionDto criteriaResourceNameDto = Iterables.get(dto.getCriteria(), 1);
CriterionDto criteriaLangageDto = Iterables.get(dto.getCriteria(), 2);
CriterionDto criteriaSearchForDto = Iterables.get(dto.getCriteria(), 3);

assertThat(dto.getUserId()).isNull();
assertThat(dto.getName()).isEqualTo("Fake");
@@ -143,11 +130,7 @@ public class RegisterNewFiltersTest {
assertThat(dto.getDefaultView()).isEqualTo("list");
assertThat(dto.getPageSize()).isEqualTo(200L);

assertThat(dto.getCriteria()).hasSize(6);
assertThat(dto.getCriteria()).satisfies(contains(new CriterionDto().setFamily("key").setOperator("=").setTextValue("*KEY*")));
assertThat(dto.getCriteria()).satisfies(contains(new CriterionDto().setFamily("name").setOperator("=").setTextValue("*NAME*")));
assertThat(dto.getCriteria()).satisfies(contains(new CriterionDto().setFamily("language").setOperator("=").setTextValue("java")));
assertThat(dto.getCriteria()).satisfies(contains(new CriterionDto().setFamily("qualifier").setOperator("=").setTextValue("TRK,BRC")));
assertThat(dto.getCriteria()).hasSize(2);
assertThat(dto.getCriteria()).satisfies(contains(new CriterionDto().setFamily("metric").setKey("complexity").setOperator("<").setValue(12f).setVariation(false)));
assertThat(dto.getCriteria()).satisfies(contains(new CriterionDto().setFamily("metric").setKey("LCOM4").setOperator(">=").setTextValue("5").setVariation(true)));


Loading…
Cancel
Save