]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9551 Test page extensions are returned for application
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 25 Jul 2017 09:59:49 +0000 (11:59 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 31 Jul 2017 09:27:51 +0000 (11:27 +0200)
server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
server/sonar-server/src/test/java/org/sonar/server/ui/PageRepositoryTest.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java

index e976aecd5e09c513835cd8e7e882954f839864d3..9d8a938cc9ee4fa45e0403ca6a54cd40c8326c8a 100644 (file)
@@ -103,25 +103,6 @@ public class ComponentAction implements NavigationWsAction {
     this.billingValidations = billingValidations;
   }
 
-  private static Consumer<QualityProfile> writeToJson(JsonWriter json) {
-    return profile -> json.beginObject()
-      .prop("key", profile.getQpKey())
-      .prop("name", profile.getQpName())
-      .prop("language", profile.getLanguageKey())
-      .endObject();
-  }
-
-  private static Function<MeasureDto, Stream<QualityProfile>> toQualityProfiles() {
-    return dbMeasure -> QPMeasureData.fromJson(dbMeasure.getData()).getProfiles().stream();
-  }
-
-  private static void writePage(JsonWriter json, Page page) {
-    json.beginObject()
-      .prop("key", page.getKey())
-      .prop("name", page.getName())
-      .endObject();
-  }
-
   @Override
   public void define(NewController context) {
     NewAction projectNavigation = context.createAction("component")
@@ -168,6 +149,25 @@ public class ComponentAction implements NavigationWsAction {
     }
   }
 
+  private static Consumer<QualityProfile> writeToJson(JsonWriter json) {
+    return profile -> json.beginObject()
+      .prop("key", profile.getQpKey())
+      .prop("name", profile.getQpName())
+      .prop("language", profile.getLanguageKey())
+      .endObject();
+  }
+
+  private static Function<MeasureDto, Stream<QualityProfile>> toQualityProfiles() {
+    return dbMeasure -> QPMeasureData.fromJson(dbMeasure.getData()).getProfiles().stream();
+  }
+
+  private static void writePage(JsonWriter json, Page page) {
+    json.beginObject()
+      .prop("key", page.getKey())
+      .prop("name", page.getName())
+      .endObject();
+  }
+
   private void writeComponent(JsonWriter json, DbSession session, ComponentDto component, OrganizationDto organizationDto, @Nullable SnapshotDto analysis) {
     json.prop("key", component.key())
       .prop("organization", organizationDto.getKey())
index cde31b07f52f603585834871543a026233fb77d6..3571d324692daf8675de3fe3afed2608fcb9d554 100644 (file)
@@ -82,7 +82,8 @@ public class PageRepositoryTest {
       .addPage(Page.builder("my_plugin/K2").setName("K2").setScope(COMPONENT).setComponentQualifiers(Qualifier.PROJECT).build())
       .addPage(Page.builder("my_plugin/K3").setName("K3").setScope(COMPONENT).setComponentQualifiers(Qualifier.MODULE).build())
       .addPage(Page.builder("my_plugin/K4").setName("K4").setScope(GLOBAL).build())
-      .addPage(Page.builder("my_plugin/K5").setName("K5").setScope(COMPONENT).setComponentQualifiers(Qualifier.VIEW).build());
+      .addPage(Page.builder("my_plugin/K5").setName("K5").setScope(COMPONENT).setComponentQualifiers(Qualifier.VIEW).build())
+      .addPage(Page.builder("my_plugin/K6").setName("K6").setScope(COMPONENT).setComponentQualifiers(Qualifier.APP).build());
     underTest = new PageRepository(pluginRepository, new PageDefinition[] {plugin});
     underTest.start();
 
index 74ad74ed8f9689ec55d38c95c5b212e3695663a3..93545bdf5f928087c8b52c6150861028160abfff 100644 (file)
@@ -280,6 +280,25 @@ public class ComponentActionTest {
     executeAndVerify(project.key(), "return_extensions.json");
   }
 
+  @Test
+  public void return_extensions_for_application() throws Exception {
+    Page page = Page.builder("my_plugin/app_page")
+      .setName("App Page")
+      .setScope(COMPONENT)
+      .setComponentQualifiers(Qualifier.VIEW, Qualifier.APP)
+      .build();
+
+    init(page);
+    ComponentDto application = componentDbTester.insertApplication(dbTester.getDefaultOrganization());
+    userSession.registerComponents(application);
+
+    String result = ws.newRequest()
+      .setParam(PARAM_COMPONENT, application.key())
+      .execute().getInput();
+
+    assertThat(result).contains("my_plugin/app_page");
+  }
+
   @Test
   public void return_extensions_for_admin() throws Exception {
     init(createPages());