This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new 1fe19c2056 refactor(#3021): Clean up class Labels (#3022)
1fe19c2056 is described below

commit 1fe19c20564878dbe63c38ad723dfbafe7642277
Author: Philipp Zehnder <[email protected]>
AuthorDate: Mon Jul 15 06:26:43 2024 +0200

    refactor(#3021): Clean up class Labels (#3022)
---
 .../manager/selector/TestSelectorUtils.java        |  8 +--
 .../org/apache/streampipes/sdk/helpers/Labels.java | 46 +-------------
 .../apache/streampipes/sdk/helpers/LabelsTest.java | 71 +++++++++++++++++++---
 3 files changed, 71 insertions(+), 54 deletions(-)

diff --git 
a/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/selector/TestSelectorUtils.java
 
b/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/selector/TestSelectorUtils.java
index 10b292c73b..e830b41602 100644
--- 
a/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/selector/TestSelectorUtils.java
+++ 
b/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/selector/TestSelectorUtils.java
@@ -43,13 +43,13 @@ public class TestSelectorUtils {
             .domainProperty(SO.NUMBER)
             .scope(PropertyScope.DIMENSION_PROPERTY)
             .build())
-        .property(EpProperties.stringEp(Labels.withTitle("string", "string 
description"), "testString",
+        .property(EpProperties.stringEp(Labels.from("", "string", "string 
description"), "testString",
             "http://test.de";, ValueSpecifications.from("A", "B", "C")))
-        .property(EpProperties.stringEp(Labels.withTitle("string2", "string 
description"), "testString2",
+        .property(EpProperties.stringEp(Labels.from("", "string2", "string 
description"), "testString2",
             "http://test.de";, ValueSpecifications.from("A", "B", "C", "D")))
-        .property(EpProperties.integerEp(Labels.withTitle("integer2", 
"integerDescription"), "testInteger2",
+        .property(EpProperties.integerEp(Labels.from("", "integer2", 
"integerDescription"), "testInteger2",
             SO.NUMBER, ValueSpecifications.from(0.0f, 1.0f, 1.f)))
-        .property(EpProperties.integerEp(Labels.withTitle("integer", 
"integerDescription"), "testInteger",
+        .property(EpProperties.integerEp(Labels.from("", "integer", 
"integerDescription"), "testInteger",
             SO.NUMBER, ValueSpecifications.from(10.0f, 100.0f, 10.0f)))
         .property(EpProperties.nestedEp(Labels.from("location", "", ""), 
"location",
             EpProperties.doubleEp(Labels.withId("latitude"), "latitude", Geo
diff --git 
a/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/helpers/Labels.java 
b/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/helpers/Labels.java
index c09b591deb..0629a97584 100644
--- 
a/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/helpers/Labels.java
+++ 
b/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/helpers/Labels.java
@@ -18,27 +18,17 @@
 
 package org.apache.streampipes.sdk.helpers;
 
-import org.apache.streampipes.commons.resources.Resources;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Properties;
-
 public class Labels {
 
   /**
-   * @deprecated Externalize labels by using
-   * {@link 
org.apache.streampipes.sdk.builder.AbstractProcessingElementBuilder#withLocales(Locales...)}
-   * to ease future support for multiple languages.
    * Creates a new label with internalId, label and description. 
Fully-configured labels are required by static
    * properties and are mandatory for event properties.
    *
    * @param internalId  The internal identifier of the element, e.g., 
"latitude-field-mapping"
    * @param label       A human-readable title
    * @param description A human-readable brief summary of the element.
-   * @return
+   * @return label object with the specified properties
    */
-  @Deprecated(since = "0.90.0", forRemoval = true)
   public static Label from(String internalId, String label, String 
description) {
     return new Label(internalId, label, description);
   }
@@ -49,7 +39,7 @@ public class Labels {
    *
    *
    * @param internalId The internal identifier of the element, e.g., 
"latitude-field-mapping"
-   * @return Label
+   * @return label object with the internal id
    */
   public static Label withId(String internalId) {
     return new Label(internalId, "", "");
@@ -59,44 +49,14 @@ public class Labels {
    * Creates a label with the string value of an enum.
    * Static properties require a fully-specified label, see {@link 
#from(String, String, String)}
    * @param internalId The internal identifier of the element, e.g., 
"LATITUDE-FIELD-MAPPING"
-   * @return
+   * @return label object with the specified properties
    */
   public static Label withId(Enum<?> internalId) {
     return new Label(internalId.name(), "", "");
   }
 
-  @Deprecated
-  /**
-   *  @deprecated Externalize labels by using
-   *  {@link 
org.apache.streampipes.sdk.builder.AbstractProcessingElementBuilder#withLocales(Locales...)}
-   *  to ease future support for multiple languages.
-   */
-  public static Label withTitle(String label, String description) {
-    return new Label("", label, description);
-  }
-
   public static Label empty() {
     return new Label("", "", "");
   }
 
-  private static String findTitleLabel(String resourceIdentifier, String 
resourceName) throws Exception {
-    return 
loadProperties(resourceIdentifier).getProperty(makeResourceId(resourceName, 
true));
-  }
-
-  private static String findDescriptionLabel(String resourceIdentifier, String 
resourceName) throws Exception {
-    return 
loadProperties(resourceIdentifier).getProperty(makeResourceId(resourceName, 
false));
-  }
-
-  private static String makeResourceId(String resourceName, Boolean titleType) 
{
-    return resourceName + "." + (titleType ? "title" : "description");
-  }
-
-  private static Properties loadProperties(String filename) throws IOException 
{
-    URL url = Resources.asUrl(filename);
-    final Properties props = new Properties();
-
-    props.load(url.openStream());
-    return props;
-  }
-
 }
diff --git 
a/streampipes-sdk/src/test/java/org/apache/streampipes/sdk/helpers/LabelsTest.java
 
b/streampipes-sdk/src/test/java/org/apache/streampipes/sdk/helpers/LabelsTest.java
index b022fbeb0f..9313f6ac86 100644
--- 
a/streampipes-sdk/src/test/java/org/apache/streampipes/sdk/helpers/LabelsTest.java
+++ 
b/streampipes-sdk/src/test/java/org/apache/streampipes/sdk/helpers/LabelsTest.java
@@ -18,23 +18,80 @@
 
 package org.apache.streampipes.sdk.helpers;
 
-import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
 public class LabelsTest {
+
+  private static final String ID = "testId";
+  private static final String LABEL = "TestLabel";
+  private static final String INTERNAL_ID = "internalId";
+  private static final String DESCRIPTION = "TestDescription";
+
   private enum TestEnum {
-    TEST;
+    TEST
+  }
+
+  @Test
+  public void from_CreatesLabelWithAllFields() {
+    var result = Labels.from(ID, LABEL, DESCRIPTION);
+
+    assertEquals(ID, result.getInternalId());
+    assertEquals(LABEL, result.getLabel());
+    assertEquals(DESCRIPTION, result.getDescription());
   }
 
   @Test
-  public void withEnumId() {
+  public void from_HandlesEmptyLabelAndDescription() {
+    var result = Labels.from(ID, "", "");
+
+    assertEquals(ID, result.getInternalId());
+    assertEquals("", result.getLabel());
+    assertEquals("", result.getDescription());
+  }
+
+  @Test
+  public void from_HandlesNullLabelAndDescription() {
+    var result = Labels.from(ID, null, null);
+
+    assertEquals("testId", result.getInternalId());
+    assertNull(result.getLabel());
+    assertNull(result.getDescription());
+  }
+
+  @Test
+  public void withId_CreatesLabelWithInternalIdOnly() {
+    var result = Labels.withId(INTERNAL_ID);
+
+    assertEquals(INTERNAL_ID, result.getInternalId());
+    assertEquals("", result.getLabel());
+    assertEquals("", result.getDescription());
+  }
+
+  @Test
+  public void withId_HandlesEmptyStringInternalId() {
+    var result = Labels.withId("");
+
+    assertEquals("", result.getInternalId());
+    assertEquals("", result.getLabel());
+    assertEquals("", result.getDescription());
+  }
+
+  @Test
+  public void withId_CreatesLabelFromEnumWithCorrectInternalId() {
     var result = Labels.withId(TestEnum.TEST);
-    Assertions.assertEquals(TestEnum.TEST.name(), result.getInternalId());
+    assertEquals(TestEnum.TEST.name(), result.getInternalId());
   }
 
   @Test
-  public void withStringId() {
-    var result = Labels.withId("test");
-    Assertions.assertEquals("test", result.getInternalId());
+  public void empty_CreatesLabelWithEmptyFields() {
+    var result = Labels.empty();
+
+    assertEquals("", result.getInternalId());
+    assertEquals("", result.getLabel());
+    assertEquals("", result.getDescription());
   }
+
 }
\ No newline at end of file

Reply via email to