Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TCOMP-2100): backlog tasks #892

Merged
merged 3 commits into from
May 29, 2024
Merged

feat(TCOMP-2100): backlog tasks #892

merged 3 commits into from
May 29, 2024

Conversation

undx
Copy link
Member

@undx undx commented May 27, 2024

undx added 3 commits May 27, 2024 10:47
diff --git a/component-server-parent/component-server/src/main/java/org/talend/sdk/component/server/front/ComponentResourceImpl.java b/component-server-parent/component-server/src/main/java/org/talend/sdk/component/server/front/ComponentResourceImpl.java
index 3d47f106411..74b31d1dee2 100644
--- a/component-server-parent/component-server/src/main/java/org/talend/sdk/component/server/front/ComponentResourceImpl.java
+++ b/component-server-parent/component-server/src/main/java/org/talend/sdk/component/server/front/ComponentResourceImpl.java
@@ -149,7 +149,7 @@ public class ComponentResourceImpl implements ComponentResource {

     public static final String THEME_ALL = "all";

-    public static final String MEDIA_TYPE_SVG_XML = "image/svg+xml";
+    public static final String IMAGE_SVG_XML_TYPE = "image/svg+xml";

     private final ConcurrentMap<RequestKey, ComponentIndices> indicesPerRequest = new ConcurrentHashMap<>();

@@ -534,7 +534,7 @@ public class ComponentResourceImpl implements ComponentResource {
                     .replace("&lt;", "<")
                     .replace("&gt;", ">");

-            return Response.ok(svgs).type(MEDIA_TYPE_SVG_XML).build();
+            return Response.ok(svgs).type(IMAGE_SVG_XML_TYPE).build();
         } catch (Exception e) {
             log.error("[getIconIndex] {}", e.getMessage());
             return Response
@@ -669,7 +669,7 @@ public class ComponentResourceImpl implements ComponentResource {
             Map<String, IconSymbol> icons = components
                     .stream()
                     .filter(c -> c.getIconFamily().getCustomIcon() != null)
-                    .filter(c -> MEDIA_TYPE_SVG_XML.equals(c.getIconFamily().getCustomIconType()))
+                    .filter(c -> IMAGE_SVG_XML_TYPE.equals(c.getIconFamily().getCustomIconType()))
                     .map(c -> new IconSymbol(c.getIconFamily().getIcon(),
                             c.getFamilyDisplayName(),
                             "family",
@@ -680,7 +680,7 @@ public class ComponentResourceImpl implements ComponentResource {
             icons.putAll(components
                     .stream()
                     .filter(c -> c.getIcon().getCustomIcon() != null)
-                    .filter(c -> MEDIA_TYPE_SVG_XML.equals(c.getIcon().getCustomIconType()))
+                    .filter(c -> IMAGE_SVG_XML_TYPE.equals(c.getIcon().getCustomIconType()))
                     .map(c -> new IconSymbol(c.getIcon().getIcon(),
                             c.getFamilyDisplayName(),
                             "connector",
diff --git a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ComponentResourceImplTest.java b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ComponentResourceImplTest.java
index b9763b6dcdc..a656ae81994 100644
--- a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ComponentResourceImplTest.java
+++ b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ComponentResourceImplTest.java
@@ -29,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.fail;
 import static org.talend.sdk.component.server.front.ComponentResourceImpl.COMPONENT_TYPE_INPUT;
 import static org.talend.sdk.component.server.front.ComponentResourceImpl.COMPONENT_TYPE_PROCESSOR;
 import static org.talend.sdk.component.server.front.ComponentResourceImpl.COMPONENT_TYPE_STANDALONE;
-import static org.talend.sdk.component.server.front.ComponentResourceImpl.MEDIA_TYPE_SVG_XML;
+import static org.talend.sdk.component.server.front.ComponentResourceImpl.IMAGE_SVG_XML_TYPE;

 import java.io.File;
 import java.io.FileOutputStream;
@@ -248,7 +248,7 @@ class ComponentResourceImplTest {
                 .accept(APPLICATION_OCTET_STREAM_TYPE)
                 .get(Response.class);
         assertNotNull(icon);
-        assertEquals(MEDIA_TYPE_SVG_XML, icon.getMediaType().toString());
+        assertEquals(IMAGE_SVG_XML_TYPE, icon.getMediaType().toString());
     }

     @test
@@ -270,7 +270,7 @@ class ComponentResourceImplTest {
                 .accept(APPLICATION_OCTET_STREAM_TYPE)
                 .get(Response.class);
         assertNotNull(icon);
-        assertEquals(MEDIA_TYPE_SVG_XML, icon.getMediaType().toString());
+        assertEquals(IMAGE_SVG_XML_TYPE, icon.getMediaType().toString());

         assertThrows(NotFoundException.class, () -> base.path("component/icon/family/{id}")
                 .resolveTemplate("id", family)
@@ -322,17 +322,33 @@ class ComponentResourceImplTest {

     @test
     void getIconIndex() {
-        // content type
+        // wrong content type
         Response icons = base.path("component/icon/index")
                 .request(APPLICATION_SVG_XML_TYPE)
                 .accept(APPLICATION_SVG_XML_TYPE)
                 .get();
         assertNotNull(icons);
-        assertEquals(APPLICATION_SVG_XML_TYPE, icons.getMediaType());
+        assertEquals(406,  icons.getStatus());
+        // inexistant theme (no fallback)
+        icons = base.path("component/icon/index")
+                .queryParam("theme", "dak")
+                .request(IMAGE_SVG_XML_TYPE)
+                .accept(IMAGE_SVG_XML_TYPE)
+                .get();
+        assertEquals(404, icons.getStatus());
+        assertEquals(APPLICATION_JSON_TYPE, icons.getMediaType());
+
+        // content type
+        icons = base.path("component/icon/index")
+                .request(IMAGE_SVG_XML_TYPE)
+                .accept(IMAGE_SVG_XML_TYPE, APPLICATION_JSON_TYPE.toString())
+                .get();
+        assertNotNull(icons);
+        assertEquals(IMAGE_SVG_XML_TYPE, icons.getMediaType().toString());
         // default: light theme
         String content = base.path("component/icon/index")
-                .request(APPLICATION_SVG_XML_TYPE)
-                .accept(APPLICATION_SVG_XML_TYPE)
+                .request(IMAGE_SVG_XML_TYPE)
+                .accept(IMAGE_SVG_XML_TYPE)
                 .get(String.class);
         assertNotNull(content);
         assertTrue(
@@ -345,8 +361,8 @@ class ComponentResourceImplTest {
         // light theme
         content = base.path("component/icon/index")
                 .queryParam("theme", "light")
-                .request(APPLICATION_SVG_XML_TYPE)
-                .accept(APPLICATION_SVG_XML_TYPE)
+                .request(IMAGE_SVG_XML_TYPE)
+                .accept(IMAGE_SVG_XML_TYPE)
                 .get(String.class);
         assertNotNull(content);
         assertTrue(
@@ -360,8 +376,8 @@ class ComponentResourceImplTest {
         // dark theme
         content = base.path("component/icon/index")
                 .queryParam("theme", "dark")
-                .request(APPLICATION_SVG_XML_TYPE)
-                .accept(APPLICATION_SVG_XML_TYPE)
+                .request(IMAGE_SVG_XML_TYPE)
+                .accept(IMAGE_SVG_XML_TYPE)
                 .get(String.class);
         assertNotNull(content);
         assertTrue(
@@ -374,8 +390,8 @@ class ComponentResourceImplTest {
         // theme = all
         content = base.path("component/icon/index")
                 .queryParam("theme", "all")
-                .request(APPLICATION_SVG_XML_TYPE)
-                .accept(APPLICATION_SVG_XML_TYPE)
+                .request(IMAGE_SVG_XML_TYPE)
+                .accept(IMAGE_SVG_XML_TYPE)
                 .get(String.class);
         assertNotNull(content);
         assertTrue(
@@ -389,14 +405,6 @@ class ComponentResourceImplTest {
                 "connector=\"standalone\" family=\"chain\" id=\"myicon\" theme=\"light\" type=\"connector\""));
         assertTrue(
                 content.contains("connector=\"\" family=\"file\" id=\"file-family\" theme=\"light\" type=\"family\""));
-        // inexistant theme (no fallback)
-        icons = base.path("component/icon/index")
-                .queryParam("theme", "dak")
-                .request(APPLICATION_SVG_XML_TYPE)
-                .accept(APPLICATION_SVG_XML_TYPE)
-                .get();
-        assertEquals(404, icons.getStatus());
-        assertEquals(APPLICATION_JSON_TYPE, icons.getMediaType());
     }

     @test
@@ -691,7 +699,7 @@ class ComponentResourceImplTest {
             assertEquals("light", data.getIcon().getTheme());
             assertTrue(new String(data.getIcon().getCustomIcon(), StandardCharsets.UTF_8)
                     .startsWith("<svg xmlns=\"http://www.w3.org/2000/svg\""));
-            assertEquals(MEDIA_TYPE_SVG_XML, data.getIcon().getCustomIconType());
+            assertEquals(IMAGE_SVG_XML_TYPE, data.getIcon().getCustomIconType());
             assertEquals(singletonList("Misc/" + data.getFamilyDisplayName()), data.getCategories());
         } else {
             assertEquals(singletonList("Misc/" + data.getFamilyDisplayName()), data.getCategories());
diff --git a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/service/IconResolverTest.java b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/service/IconResolverTest.java
index 594decda0aa..7ee94341762 100644
--- a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/service/IconResolverTest.java
+++ b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/service/IconResolverTest.java
@@ -18,7 +18,7 @@ package org.talend.sdk.component.server.service;
 import static org.junit.Assert.assertNull;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.talend.sdk.component.server.front.ComponentResourceImpl.MEDIA_TYPE_SVG_XML;
+import static org.talend.sdk.component.server.front.ComponentResourceImpl.IMAGE_SVG_XML_TYPE;
 import static org.talend.sdk.component.server.front.ComponentResourceImpl.THEME_DARK;
 import static org.talend.sdk.component.server.front.ComponentResourceImpl.THEME_LIGHT;

@@ -68,12 +68,12 @@ class IconResolverTest {
         //
         IconResolver.Icon icon = resolver.resolve(plugin, "logo", THEME_DARK);
         assertNotNull(icon);
-        assertEquals(MEDIA_TYPE_SVG_XML, icon.getType());
+        assertEquals(IMAGE_SVG_XML_TYPE, icon.getType());
         assertEquals(THEME_DARK, icon.getTheme());
         //
         icon = resolver.resolve(plugin, PLUGIN_DB_INPUT, THEME_DARK);
         assertNotNull(icon);
-        assertEquals(MEDIA_TYPE_SVG_XML, icon.getType());
+        assertEquals(IMAGE_SVG_XML_TYPE, icon.getType());
         assertEquals(THEME_DARK, icon.getTheme());
         //
         icon = resolver.resolve(plugin, PLUGIN_DB_INPUT, THEME_LIGHT);
Copy link

sonar-eks bot commented May 27, 2024

Passed

Analysis Details

0 Issues

  • Bug 0 Bugs
  • Vulnerability 0 Vulnerabilities
  • Code Smell 0 Code Smells

Coverage and Duplications

  • Coverage 100.00% Coverage (54.20% Estimated after merge)
  • Duplications 0.00% Duplicated Code (1.30% Estimated after merge)

Project ID: org.talend.sdk.component:component-runtime

View in SonarQube

Copy link
Contributor

@acatoire acatoire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@acatoire acatoire merged commit ff37627 into master May 29, 2024
5 of 6 checks passed
@acatoire acatoire deleted the undx/TCOMP-2100-backlog branch May 29, 2024 15:18
acatoire pushed a commit that referenced this pull request May 29, 2024
acatoire pushed a commit that referenced this pull request Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants