]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9181 WS api/projects/search filters on provisioned projects
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 4 Sep 2017 15:44:40 +0000 (17:44 +0200)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Mon, 11 Sep 2017 09:28:29 +0000 (11:28 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java
server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchAction.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchActionTest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/project/ProjectsService.java
sonar-ws/src/main/java/org/sonarqube/ws/client/project/ProjectsWsParameters.java
sonar-ws/src/main/java/org/sonarqube/ws/client/project/SearchWsRequest.java
sonar-ws/src/test/java/org/sonarqube/ws/client/project/ProjectsServiceTest.java
tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectSearchTest.java

index 2568f8ba22b3a1361baea9225ca0ceef368b57c1..11335fc10d2305a6673fd5f95b7a1a2e0b0c7f86 100644 (file)
@@ -36,6 +36,7 @@ public class ComponentQuery {
   private final Boolean isPrivate;
   private final Set<Long> componentIds;
   private final Long analyzedBefore;
+  private final boolean onProvisionedOnly;
 
   private ComponentQuery(Builder builder) {
     this.nameOrKeyQuery = builder.nameOrKeyQuery;
@@ -45,6 +46,7 @@ public class ComponentQuery {
     this.componentIds = builder.componentIds;
     this.isPrivate = builder.isPrivate;
     this.analyzedBefore = builder.analyzedBefore;
+    this.onProvisionedOnly = builder.onProvisionedOnly;
   }
 
   public String[] getQualifiers() {
@@ -91,6 +93,10 @@ public class ComponentQuery {
     return analyzedBefore;
   }
 
+  public boolean isOnProvisionedOnly() {
+    return onProvisionedOnly;
+  }
+
   public static Builder builder() {
     return new Builder();
   }
@@ -103,6 +109,7 @@ public class ComponentQuery {
     private Boolean isPrivate;
     private Set<Long> componentIds;
     private Long analyzedBefore;
+    private boolean onProvisionedOnly = false;
 
     public Builder setNameOrKeyQuery(@Nullable String nameOrKeyQuery) {
       this.nameOrKeyQuery = nameOrKeyQuery;
@@ -142,6 +149,11 @@ public class ComponentQuery {
       return this;
     }
 
+    public Builder setOnProvisionedOnly(boolean onProvisionedOnly) {
+      this.onProvisionedOnly = onProvisionedOnly;
+      return this;
+    }
+
     public ComponentQuery build() {
       checkArgument(qualifiers != null && qualifiers.length > 0, "At least one qualifier must be provided");
       checkArgument(nameOrKeyQuery != null || partialMatchOnKey == null, "A query must be provided if a partial match on key is specified.");
index d9e90aa811053645e21e6006ebb444ea8db0a970..0e189b06595ee6b872037e7c71483a5f286c6b13 100644 (file)
   <sql id="sqlSelectByQuery">
     from projects p
     <if test="query.analyzedBefore!=null">
-      inner join snapshots s on s.component_uuid=p.uuid and s.status='P' and s.islast=${_true}
-        and s.created_at &lt; #{query.analyzedBefore,jdbcType=BIGINT}
+      inner join snapshots sa on sa.component_uuid=p.uuid
+        and sa.status='P' and sa.islast=${_true} and sa.created_at &lt; #{query.analyzedBefore,jdbcType=BIGINT}
     </if>
     where
       p.enabled=${_true}
           and p.private=${_false}
         </if>
       </if>
+      <if test="query.isOnProvisionedOnly()">
+        and not exists(select 1 from snapshots sp where sp.component_uuid=p.uuid)
+      </if>
   </sql>
 
   <select id="selectDescendants" resultType="Component">
index 484612e7e28253ac5846631afcd9b8a63f051e37..490dcc5210dcbabfc088c7ed8aade6fd3231cf41 100644 (file)
@@ -26,6 +26,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.function.Supplier;
 import javax.annotation.Nullable;
 import org.apache.ibatis.session.RowBounds;
 import org.assertj.core.api.ListAssert;
@@ -628,40 +629,60 @@ public class ComponentDaoTest {
     String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)).getComponentUuid();
 
     Set<String> projectQualifiers = newHashSet(Qualifiers.PROJECT);
+    Supplier<ComponentQuery.Builder> query = () -> ComponentQuery.builder().setQualifiers(Qualifiers.PROJECT).setOnProvisionedOnly(true);
     assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, projectQualifiers, new RowBounds(0, 10)))
       .extracting(ComponentDto::uuid)
       .containsOnly(provisionedProject.uuid());
+    assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 0, 10))
+      .extracting(ComponentDto::uuid)
+      .containsOnly(provisionedProject.uuid());
 
     // pagination
-    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, projectQualifiers, new RowBounds(2, 10)))
-      .isEmpty();
+    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, projectQualifiers, new RowBounds(2, 10))).isEmpty();
+    assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 2, 10)).isEmpty();
 
     // filter on qualifiers
-    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, newHashSet("XXX"), new RowBounds(0, 10)))
-      .isEmpty();
+    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, newHashSet("XXX"), new RowBounds(0, 10))).isEmpty();
+    assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setQualifiers("XXX").build(), 0, 10)).isEmpty();
     assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, newHashSet(Qualifiers.PROJECT, "XXX"), new RowBounds(0, 10)))
       .extracting(ComponentDto::uuid)
       .containsOnly(provisionedProject.uuid());
+    assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setQualifiers(Qualifiers.PROJECT, "XXX").build(), 0, 10))
+      .extracting(ComponentDto::uuid)
+      .containsOnly(provisionedProject.uuid());
     assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, newHashSet(Qualifiers.PROJECT, Qualifiers.VIEW), new RowBounds(0, 10)))
       .extracting(ComponentDto::uuid)
       .containsOnly(provisionedProject.uuid(), provisionedView.uuid());
+    assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW).build(), 0, 10))
+      .extracting(ComponentDto::uuid)
+      .containsOnly(provisionedProject.uuid(), provisionedView.uuid());
 
     // match key
     assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), provisionedProject.getDbKey(), projectQualifiers, new RowBounds(0, 10)))
       .extracting(ComponentDto::uuid)
       .containsExactly(provisionedProject.uuid());
+    assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setNameOrKeyQuery(provisionedProject.getDbKey()).build(), 0, 10))
+      .extracting(ComponentDto::uuid)
+      .containsExactly(provisionedProject.uuid());
     assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "pROvisiONed.proJEcT", projectQualifiers, new RowBounds(0, 10)))
       .extracting(ComponentDto::uuid)
       .containsExactly(provisionedProject.uuid());
-    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "missing", projectQualifiers, new RowBounds(0, 10)))
-      .isEmpty();
-    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "to be escaped '\"\\%", projectQualifiers, new RowBounds(0, 10)))
+    assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setNameOrKeyQuery("pROvisiONed.proJEcT").setPartialMatchOnKey(true).build(), 0, 10))
+      .extracting(ComponentDto::uuid)
+      .containsExactly(provisionedProject.uuid());
+    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "missing", projectQualifiers, new RowBounds(0, 10))).isEmpty();
+    assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setNameOrKeyQuery("missing").setPartialMatchOnKey(true).build(), 0, 10)).isEmpty();
+    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "to be escaped '\"\\%", projectQualifiers, new RowBounds(0, 10))).isEmpty();
+    assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setNameOrKeyQuery("to be escaped '\"\\%").setPartialMatchOnKey(true).build(), 0, 10))
       .isEmpty();
 
     // match name
     assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "ned proj", projectQualifiers, new RowBounds(0, 10)))
       .extracting(ComponentDto::uuid)
       .containsExactly(provisionedProject.uuid());
+    assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setNameOrKeyQuery("ned proj").setPartialMatchOnKey(true).build(), 0, 10))
+      .extracting(ComponentDto::uuid)
+      .containsExactly(provisionedProject.uuid());
   }
 
   @Test
index d69f98c277ff3d0d25bb6f5f355abd8a408b721b..018cec3f8b6b6b408f2a335fc074e5de68117108 100644 (file)
@@ -44,6 +44,8 @@ public class ComponentQueryTest {
     assertThat(underTest.getLanguage()).isEqualTo("java");
     assertThat(underTest.getQualifiers()).containsOnly(PROJECT);
     assertThat(underTest.getAnalyzedBefore()).isEqualTo(1_000_000_000L);
+    assertThat(underTest.isOnProvisionedOnly()).isFalse();
+    assertThat(underTest.isPartialMatchOnKey()).isFalse();
   }
 
   @Test
index 562a136c070bb3c12d89edaefe1c8b558e33b1fd..d7b62b90be4a172581d48efda1f05f8667e956dd 100644 (file)
@@ -58,6 +58,7 @@ import static org.sonarqube.ws.WsProjects.SearchWsResponse.newBuilder;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.ACTION_SEARCH;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.MAX_PAGE_SIZE;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_ANALYZED_BEFORE;
+import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_ON_PROVISIONED_ONLY;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_ORGANIZATION;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_QUALIFIERS;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_VISIBILITY;
@@ -115,6 +116,12 @@ public class SearchAction implements ProjectsWsAction {
       .setDescription("Filter the projects for which last analysis is older than the given date (exclusive).<br> " +
         "Format: date or datetime ISO formats.")
       .setSince("6.6");
+
+    action.createParam(PARAM_ON_PROVISIONED_ONLY)
+      .setDescription("Filter the projects that are provisioned")
+      .setBooleanPossibleValues()
+      .setDefaultValue("false")
+      .setSince("6.6");
   }
 
   @Override
@@ -132,6 +139,7 @@ public class SearchAction implements ProjectsWsAction {
       .setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE))
       .setVisibility(request.param(PARAM_VISIBILITY))
       .setAnalyzedBefore(request.param(PARAM_ANALYZED_BEFORE))
+      .setOnProvisionedOnly(request.mandatoryParamAsBoolean(PARAM_ON_PROVISIONED_ONLY))
       .build();
   }
 
@@ -162,6 +170,7 @@ public class SearchAction implements ProjectsWsAction {
     });
     setNullable(request.getVisibility(), v -> query.setPrivate(Visibility.isPrivate(v)));
     setNullable(request.getAnalyzedBefore(), d -> query.setAnalyzedBefore(parseDateOrDateTime(d).getTime()));
+    setNullable(request.isOnProvisionedOnly(), query::setOnProvisionedOnly);
 
     return query.build();
   }
index c4fbc6a0bf6b92b3fd5ce7547e2d92e4d1d363e6..c3dbd732374031753874b95bd034e7fe88b8e990 100644 (file)
@@ -30,6 +30,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
@@ -68,6 +69,7 @@ import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES;
 import static org.sonar.test.JsonAssert.assertJson;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_ANALYZED_BEFORE;
+import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_ON_PROVISIONED_ONLY;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_ORGANIZATION;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_VISIBILITY;
 
@@ -242,6 +244,20 @@ public class SearchActionTest {
     assertThat(response.getComponentsList()).extracting(Component::getKey).containsExactly("project-key-4", "project-key-5", "project-key-6");
   }
 
+  @Test
+  public void provisioned_projects() {
+    userSession.addPermission(ADMINISTER, db.getDefaultOrganization());
+    ComponentDto provisionedProject = db.components().insertPrivateProject();
+    ComponentDto analyzedProject = db.components().insertPrivateProject();
+    db.components().insertSnapshot(newAnalysis(analyzedProject));
+
+    SearchWsResponse response = call(SearchWsRequest.builder().setOnProvisionedOnly(true).build());
+
+    assertThat(response.getComponentsList()).extracting(Component::getKey)
+      .containsExactlyInAnyOrder(provisionedProject.getKey())
+      .doesNotContain(analyzedProject.getKey());
+  }
+
   @Test
   public void fail_when_not_system_admin() throws Exception {
     userSession.addPermission(ADMINISTER_QUALITY_PROFILES, db.getDefaultOrganization());
@@ -275,16 +291,17 @@ public class SearchActionTest {
     assertThat(action.isInternal()).isTrue();
     assertThat(action.since()).isEqualTo("6.3");
     assertThat(action.handler()).isEqualTo(ws.getDef().handler());
-    assertThat(action.params()).hasSize(7);
+    assertThat(action.params()).hasSize(8).extracting(Param::key)
+      .containsExactlyInAnyOrder("organization", "q", "qualifiers", "p", "ps", "visibility", "analyzedBefore", "onProvisionedOnly");
     assertThat(action.responseExample()).isEqualTo(getClass().getResource("search-example.json"));
 
-    WebService.Param organization = action.param("organization");
+    Param organization = action.param("organization");
     Assertions.assertThat(organization.description()).isEqualTo("The key of the organization");
     Assertions.assertThat(organization.isInternal()).isTrue();
     Assertions.assertThat(organization.isRequired()).isFalse();
     Assertions.assertThat(organization.since()).isEqualTo("6.3");
 
-    WebService.Param qParam = action.param("q");
+    Param qParam = action.param("q");
     assertThat(qParam.isRequired()).isFalse();
     assertThat(qParam.description()).isEqualTo("Limit search to: " +
       "<ul>" +
@@ -292,30 +309,35 @@ public class SearchActionTest {
       "<li>component keys that contain the supplied string</li>" +
       "</ul>");
 
-    WebService.Param qualifierParam = action.param("qualifiers");
+    Param qualifierParam = action.param("qualifiers");
     assertThat(qualifierParam.isRequired()).isFalse();
     assertThat(qualifierParam.description()).isEqualTo("Comma-separated list of component qualifiers. Filter the results with the specified qualifiers");
     assertThat(qualifierParam.possibleValues()).containsOnly("TRK", "VW", "APP");
     assertThat(qualifierParam.defaultValue()).isEqualTo("TRK");
 
-    WebService.Param pParam = action.param("p");
+    Param pParam = action.param("p");
     assertThat(pParam.isRequired()).isFalse();
     assertThat(pParam.defaultValue()).isEqualTo("1");
     assertThat(pParam.description()).isEqualTo("1-based page number");
 
-    WebService.Param psParam = action.param("ps");
+    Param psParam = action.param("ps");
     assertThat(psParam.isRequired()).isFalse();
     assertThat(psParam.defaultValue()).isEqualTo("100");
     assertThat(psParam.description()).isEqualTo("Page size. Must be greater than 0 and less than 500");
 
-    WebService.Param visibilityParam = action.param("visibility");
+    Param visibilityParam = action.param("visibility");
     assertThat(visibilityParam.isRequired()).isFalse();
     assertThat(visibilityParam.description()).isEqualTo("Filter the projects that should be visible to everyone (public), or only specific user/groups (private).<br/>" +
       "If no visibility is specified, the default project visibility of the organization will be used.");
 
-    WebService.Param lastAnalysisBefore = action.param("analyzedBefore");
+    Param lastAnalysisBefore = action.param("analyzedBefore");
     assertThat(lastAnalysisBefore.isRequired()).isFalse();
     assertThat(lastAnalysisBefore.since()).isEqualTo("6.6");
+
+    Param onProvisionedOnly = action.param("onProvisionedOnly");
+    assertThat(onProvisionedOnly.possibleValues()).containsExactlyInAnyOrder("true", "false", "yes", "no");
+    assertThat(onProvisionedOnly.defaultValue()).isEqualTo("false");
+    assertThat(onProvisionedOnly.since()).isEqualTo("6.6");
   }
 
   @Test
@@ -352,6 +374,7 @@ public class SearchActionTest {
     setNullable(wsRequest.getPageSize(), pageSize -> request.setParam(PAGE_SIZE, String.valueOf(pageSize)));
     setNullable(wsRequest.getVisibility(), v -> request.setParam(PARAM_VISIBILITY, v));
     setNullable(wsRequest.getAnalyzedBefore(), d -> request.setParam(PARAM_ANALYZED_BEFORE, d));
+    request.setParam(PARAM_ON_PROVISIONED_ONLY, String.valueOf(wsRequest.isOnProvisionedOnly()));
     return request.executeProtobuf(SearchWsResponse.class);
   }
 
index 5dde5e0939fe8079f4ef401593590105cb784b80..a3acd885cdfc58b5b3578ad74d2f6483109a3324 100644 (file)
@@ -31,7 +31,6 @@ import org.sonarqube.ws.client.WsConnector;
 import static org.sonar.api.server.ws.WebService.Param.PAGE;
 import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
 import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
-import static org.sonar.api.utils.DateUtils.formatDateTimeNullSafe;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.ACTION_BULK_UPDATE_KEY;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.ACTION_CREATE;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.ACTION_SEARCH;
@@ -42,6 +41,7 @@ import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_ANALYZE
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_BRANCH;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_FROM;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_NAME;
+import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_ON_PROVISIONED_ONLY;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_ORGANIZATION;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT_ID;
@@ -117,7 +117,8 @@ public class ProjectsService extends BaseService {
       .setParam(PARAM_ANALYZED_BEFORE, request.getAnalyzedBefore())
       .setParam(TEXT_QUERY, request.getQuery())
       .setParam(PAGE, request.getPage())
-      .setParam(PAGE_SIZE, request.getPageSize());
+      .setParam(PAGE_SIZE, request.getPageSize())
+      .setParam(PARAM_ON_PROVISIONED_ONLY, request.isOnProvisionedOnly());
     return call(get, SearchWsResponse.parser());
   }
 
index e03d82faa64124722065a505e84abbc2479ccab7..131c6465645c586845efc611a17d5f07424e5dfd 100644 (file)
@@ -43,6 +43,7 @@ public class ProjectsWsParameters {
   public static final String PARAM_DRY_RUN = "dryRun";
   public static final String PARAM_VISIBILITY = "visibility";
   public static final String PARAM_ANALYZED_BEFORE = "analyzedBefore";
+  public static final String PARAM_ON_PROVISIONED_ONLY = "onProvisionedOnly";
 
   public static final String FILTER_LANGUAGES = "languages";
   public static final String FILTER_TAGS = "tags";
index ef36c34b61dd7e14c346f5f4bcee08d5de1b83b7..04d0e8d4fceb95c7d00274eb1e28c79e5c5d4391 100644 (file)
@@ -37,6 +37,7 @@ public class SearchWsRequest {
   private final Integer page;
   private final Integer pageSize;
   private final String analyzedBefore;
+  private final boolean onProvisionedOnly;
 
   public SearchWsRequest(Builder builder) {
     this.organization = builder.organization;
@@ -46,6 +47,7 @@ public class SearchWsRequest {
     this.page = builder.page;
     this.pageSize = builder.pageSize;
     this.analyzedBefore = builder.analyzedBefore;
+    this.onProvisionedOnly = builder.onProvisionedOnly;
   }
 
   @CheckForNull
@@ -82,6 +84,10 @@ public class SearchWsRequest {
     return analyzedBefore;
   }
 
+  public boolean isOnProvisionedOnly() {
+    return onProvisionedOnly;
+  }
+
   public static Builder builder() {
     return new Builder();
   }
@@ -94,6 +100,7 @@ public class SearchWsRequest {
     private String query;
     private String visibility;
     private String analyzedBefore;
+    private boolean onProvisionedOnly = false;
 
     public Builder setOrganization(@Nullable String organization) {
       this.organization = organization;
@@ -130,6 +137,11 @@ public class SearchWsRequest {
       return this;
     }
 
+    public Builder setOnProvisionedOnly(boolean onProvisionedOnly) {
+      this.onProvisionedOnly = onProvisionedOnly;
+      return this;
+    }
+
     public SearchWsRequest build() {
       checkArgument(pageSize == null || pageSize <= MAX_PAGE_SIZE, "Page size must not be greater than %s", MAX_PAGE_SIZE);
       return new SearchWsRequest(this);
index d8b8c7e5e6f117321831928f37f0516afc65f607..f3727f3885159a1798cd3bfeaf834bc4d599a36f 100644 (file)
@@ -139,6 +139,7 @@ public class ProjectsServiceTest {
       .setQuery("project")
       .setQualifiers(asList("TRK", "VW"))
       .setAnalyzedBefore("2017-09-01")
+      .setOnProvisionedOnly(true)
       .setPage(3)
       .setPageSize(10)
       .build());
@@ -149,6 +150,7 @@ public class ProjectsServiceTest {
       .hasParam("q", "project")
       .hasParam("analyzedBefore", "2017-09-01")
       .hasParam("qualifiers", "TRK,VW")
+      .hasParam("onProvisionedOnly", "true")
       .hasParam(PAGE, 3)
       .hasParam(PAGE_SIZE, 10)
       .andNoOtherParam();
index 0109913973874684c8aaa50964e51e0b0abf19d1..4882176d56759d75b79a7f5acbce2f58cc26640e 100644 (file)
@@ -31,6 +31,7 @@ import org.sonarqube.tests.Tester;
 import org.sonarqube.ws.Organizations;
 import org.sonarqube.ws.WsProjects.CreateWsResponse;
 import org.sonarqube.ws.WsProjects.SearchWsResponse;
+import org.sonarqube.ws.WsProjects.SearchWsResponse.Component;
 import org.sonarqube.ws.client.GetRequest;
 import org.sonarqube.ws.client.project.SearchWsRequest;
 
@@ -63,7 +64,7 @@ public class ProjectSearchTest {
       .setQualifiers(singletonList("TRK"))
       .setAnalyzedBefore(formatDate(oneYearAgo)).build());
 
-    assertThat(result.getComponentsList()).extracting(SearchWsResponse.Component::getKey).containsExactlyInAnyOrder(oldProject.getKey());
+    assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(oldProject.getKey());
   }
 
   @Test
@@ -83,7 +84,7 @@ public class ProjectSearchTest {
       .setQuery("JeCt-K")
       .build());
 
-    assertThat(result.getComponentsList()).extracting(SearchWsResponse.Component::getKey)
+    assertThat(result.getComponentsList()).extracting(Component::getKey)
       .containsExactlyInAnyOrder(lowerCaseProject.getKey(), upperCaseProject.getKey())
       .doesNotContain(anotherProject.getKey());
   }
@@ -100,9 +101,14 @@ public class ProjectSearchTest {
     String result = tester.wsClient().wsConnector().call(new GetRequest("api/projects/provisioned")
       .setParam("organization", organization.getKey()))
       .failIfNotSuccessful().content();
-
-    assertThat(result)
-      .contains(firstProvisionedProject.getKey(), secondProvisionedProject.getKey())
+   SearchWsResponse searchResult = tester.wsClient().projects().search(SearchWsRequest.builder()
+     .setQualifiers(singletonList("TRK"))
+     .setOrganization(organization.getKey())
+     .setOnProvisionedOnly(true).build());
+
+    assertThat(result).contains(firstProvisionedProject.getKey(), secondProvisionedProject.getKey()).doesNotContain(analyzedProject.getKey());
+    assertThat(searchResult.getComponentsList()).extracting(Component::getKey)
+      .containsOnly(firstProvisionedProject.getKey(), secondProvisionedProject.getKey())
       .doesNotContain(analyzedProject.getKey());
   }