]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8318 api/project_links/search support null name or type
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 20 Oct 2016 14:53:30 +0000 (16:53 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 21 Oct 2016 14:47:41 +0000 (16:47 +0200)
server/sonar-server/src/main/java/org/sonar/server/projectlink/ws/SearchAction.java
server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java

index b06605c123561c468c118b512ae0c0a19b45c57c..726b74bf4099a55582f0f1634a13bbae6e84d966 100644 (file)
@@ -108,12 +108,16 @@ public class SearchAction implements ProjectLinksWsAction {
   }
 
   private static Link buildLink(ComponentLinkDto link) {
-    return Link.newBuilder()
+    Link.Builder builder = Link.newBuilder()
       .setId(String.valueOf(link.getId()))
-      .setName(link.getName())
-      .setType(link.getType())
-      .setUrl(link.getHref())
-      .build();
+      .setUrl(link.getHref());
+    if (link.getName() != null) {
+      builder.setName(link.getName());
+    }
+    if (link.getType() != null) {
+      builder.setType(link.getType());
+    }
+    return builder.build();
   }
 
   private ComponentDto getComponentByUuidOrKey(DbSession dbSession, SearchWsRequest request) {
index 45557966b7736682588f57ef81f651e21c13a2de..42505af918866b5631707b5b48c425f8cb139bb9 100644 (file)
@@ -58,19 +58,17 @@ public class SearchActionTest {
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
-
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
-
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
-  DbClient dbClient = db.getDbClient();
-  DbSession dbSession = db.getSession();
-  ComponentDbTester componentDb = new ComponentDbTester(db);
 
-  WsActionTester ws;
+  private DbClient dbClient = db.getDbClient();
+  private DbSession dbSession = db.getSession();
+  private ComponentDbTester componentDb = new ComponentDbTester(db);
 
-  SearchAction underTest;
+  private SearchAction underTest;
+  private WsActionTester ws;
 
   @Before
   public void setUp() {
@@ -144,6 +142,24 @@ public class SearchActionTest {
     assertThat(response.getLinks(0).getId()).isEqualTo(customLink1.getIdAsString());
   }
 
+  @Test
+  public void request_does_not_fail_when_link_has_no_name() throws IOException {
+    ComponentDto project = db.components().insertProject();
+    ComponentLinkDto foo = new ComponentLinkDto().setComponentUuid(project.uuid()).setHref("foo").setType("type");
+    insertLink(foo);
+
+    callByKey(project.key());
+  }
+
+  @Test
+  public void request_does_not_fail_when_link_has_no_type() throws IOException {
+    ComponentDto project = db.components().insertProject();
+    ComponentLinkDto foo = new ComponentLinkDto().setComponentUuid(project.uuid()).setHref("foo").setName("name");
+    insertLink(foo);
+
+    callByKey(project.key());
+  }
+
   @Test
   public void global_admin() throws IOException {
     userSession.login("login").setGlobalPermissions(SYSTEM_ADMIN);