]> 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)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 15 Nov 2016 08:56:53 +0000 (09:56 +0100)
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..b21b723d51c2e1485ef15d69c30754e15ad6ce12 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 = componentDb.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 = componentDb.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);