You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@texera.apache.org by "aglinxinyuan (via GitHub)" <gi...@apache.org> on 2026/06/06 07:41:40 UTC
[PR] test(amber): add unit test coverage for dashboard/hub entity model [texera]
aglinxinyuan opened a new pull request, #5402:
URL: https://github.com/apache/texera/pull/5402
### What changes were proposed in this PR?
Adds `HubEntityModelSpec` covering all three files in `amber/.../web/resource/dashboard/hub/` — the entity-kind dispatch types the Hub dashboard uses and the jOOQ table lookups they drive. Bundled because the three files are a tight `apply(EntityType)` dispatch family.
| File | Behavior pinned |
| --- | --- |
| `ActionType.scala` | Four subtypes (`View` / `Like` / `Clone` / `Unlike`) expose lowercase `value`; `toString = value` override (what reaches log lines, not the case-object name); `fromString` exact-match + case-insensitive; throws `IllegalArgumentException` with input in message on unknown / empty; `@JsonValue` + `@JsonCreator` Jackson round-trip via `JSONUtils.objectMapper` (emits lowercase string, accepts case-insensitive). |
| `EntityType.scala` | Same shape — `Workflow` / `Dataset` carry `"workflow"` / `"dataset"`; toString-equals-value override; case-insensitive `fromString`; unknown-input error; Jackson round-trip. |
| `EntityTables.scala` dispatch | `BaseEntityTable.apply`, `LikeTable.apply`, `CloneTable.apply`, `ViewCountTable.apply` each dispatched against both `EntityType` subtypes. Each `case object` exposes its `table` / `idColumn` / `isPublicColumn` / `uidColumn` / `viewCountColumn` from the production jOOQ generated tables — a regression that wired a column to the wrong jOOQ field would fail here. `CloneTable(Dataset)` throws `IllegalArgumentException` since clone is workflow-only today; a future `DatasetCloneTable` should remove that assertion deliberately. |
No production code changed; this is test-only.
### Any related issues, documentation, discussions?
Closes #5397
### How was this PR tested?
```
sbt "WorkflowExecutionService/Test/testOnly org.apache.texera.web.resource.dashboard.hub.HubEntityModelSpec"
# → 24 tests, all pass
sbt "WorkflowExecutionService/Test/scalafmtCheck"
# → clean
```
### Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.7)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(amber): add unit test coverage for dashboard/hub entity model [texera]
Posted by "aglinxinyuan (via GitHub)" <gi...@apache.org>.
aglinxinyuan commented on code in PR #5402:
URL: https://github.com/apache/texera/pull/5402#discussion_r3366972424
##########
amber/src/test/scala/org/apache/texera/web/resource/dashboard/hub/HubEntityModelSpec.scala:
##########
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.web.resource.dashboard.hub
+
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.apache.texera.dao.jooq.generated.Tables._
+import org.scalatest.flatspec.AnyFlatSpec
+
+class HubEntityModelSpec extends AnyFlatSpec {
+
+ // ---------------------------------------------------------------------------
+ // ActionType
+ // ---------------------------------------------------------------------------
+
+ "ActionType subtypes" should "expose their lowercase string value" in {
+ assert(ActionType.View.value == "view")
+ assert(ActionType.Like.value == "like")
+ assert(ActionType.Clone.value == "clone")
+ assert(ActionType.Unlike.value == "unlike")
+ }
+
+ it should "have toString equal to value (override pin)" in {
+ // The trait override `toString = value` is what reaches log lines and
+ // tracking pipelines. Pin so a regression that returns the case-object
+ // name (e.g. "View" instead of "view") breaks here.
+ val all: List[ActionType] =
+ List(ActionType.View, ActionType.Like, ActionType.Clone, ActionType.Unlike)
+ all.foreach(a => assert(a.toString == a.value, s"$a.toString != $a.value"))
+ }
+
+ "ActionType.fromString" should "match each subtype exactly" in {
+ assert(ActionType.fromString("view") == ActionType.View)
+ assert(ActionType.fromString("like") == ActionType.Like)
+ assert(ActionType.fromString("clone") == ActionType.Clone)
+ assert(ActionType.fromString("unlike") == ActionType.Unlike)
+ }
+
+ it should "match case-insensitively" in {
+ assert(ActionType.fromString("VIEW") == ActionType.View)
+ assert(ActionType.fromString("Like") == ActionType.Like)
+ assert(ActionType.fromString("CLONE") == ActionType.Clone)
+ assert(ActionType.fromString("uNlIkE") == ActionType.Unlike)
+ }
+
+ it should "throw IllegalArgumentException for an unknown action, naming the input" in {
+ val ex = intercept[IllegalArgumentException] {
+ ActionType.fromString("delete")
+ }
+ assert(ex.getMessage.contains("delete"), s"unexpected message: ${ex.getMessage}")
+ }
+
+ it should "throw IllegalArgumentException for an empty string" in {
+ intercept[IllegalArgumentException] {
+ ActionType.fromString("")
+ }
+ }
Review Comment:
Done in d04e516529 — the empty-string test now asserts the message contains the concrete `''` representation, not just that an exception is thrown.
##########
amber/src/test/scala/org/apache/texera/web/resource/dashboard/hub/HubEntityModelSpec.scala:
##########
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.web.resource.dashboard.hub
+
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.apache.texera.dao.jooq.generated.Tables._
+import org.scalatest.flatspec.AnyFlatSpec
+
+class HubEntityModelSpec extends AnyFlatSpec {
+
+ // ---------------------------------------------------------------------------
+ // ActionType
+ // ---------------------------------------------------------------------------
+
+ "ActionType subtypes" should "expose their lowercase string value" in {
+ assert(ActionType.View.value == "view")
+ assert(ActionType.Like.value == "like")
+ assert(ActionType.Clone.value == "clone")
+ assert(ActionType.Unlike.value == "unlike")
+ }
+
+ it should "have toString equal to value (override pin)" in {
+ // The trait override `toString = value` is what reaches log lines and
+ // tracking pipelines. Pin so a regression that returns the case-object
+ // name (e.g. "View" instead of "view") breaks here.
+ val all: List[ActionType] =
+ List(ActionType.View, ActionType.Like, ActionType.Clone, ActionType.Unlike)
+ all.foreach(a => assert(a.toString == a.value, s"$a.toString != $a.value"))
+ }
+
+ "ActionType.fromString" should "match each subtype exactly" in {
+ assert(ActionType.fromString("view") == ActionType.View)
+ assert(ActionType.fromString("like") == ActionType.Like)
+ assert(ActionType.fromString("clone") == ActionType.Clone)
+ assert(ActionType.fromString("unlike") == ActionType.Unlike)
+ }
+
+ it should "match case-insensitively" in {
+ assert(ActionType.fromString("VIEW") == ActionType.View)
+ assert(ActionType.fromString("Like") == ActionType.Like)
+ assert(ActionType.fromString("CLONE") == ActionType.Clone)
+ assert(ActionType.fromString("uNlIkE") == ActionType.Unlike)
+ }
+
+ it should "throw IllegalArgumentException for an unknown action, naming the input" in {
+ val ex = intercept[IllegalArgumentException] {
+ ActionType.fromString("delete")
+ }
+ assert(ex.getMessage.contains("delete"), s"unexpected message: ${ex.getMessage}")
+ }
+
+ it should "throw IllegalArgumentException for an empty string" in {
+ intercept[IllegalArgumentException] {
+ ActionType.fromString("")
+ }
+ }
+
+ "ActionType Jackson round-trip" should "serialize each subtype as its lowercase string value" in {
+ // `@JsonValue` on `value` instructs Jackson to emit the field's value
+ // string instead of a wrapping object form.
+ assert(objectMapper.writeValueAsString(ActionType.View: ActionType) == "\"view\"")
+ assert(objectMapper.writeValueAsString(ActionType.Like: ActionType) == "\"like\"")
+ assert(objectMapper.writeValueAsString(ActionType.Clone: ActionType) == "\"clone\"")
+ assert(objectMapper.writeValueAsString(ActionType.Unlike: ActionType) == "\"unlike\"")
+ }
+
+ it should "deserialize from the lowercase string back to the canonical subtype" in {
+ // `@JsonCreator` on `fromString` lets Jackson reconstruct the subtype
+ // from a raw string field.
+ assert(objectMapper.readValue("\"view\"", classOf[ActionType]) == ActionType.View)
+ assert(objectMapper.readValue("\"like\"", classOf[ActionType]) == ActionType.Like)
+ assert(objectMapper.readValue("\"clone\"", classOf[ActionType]) == ActionType.Clone)
+ assert(objectMapper.readValue("\"unlike\"", classOf[ActionType]) == ActionType.Unlike)
+ }
+
+ it should "honor the case-insensitive deserialization via @JsonCreator" in {
+ assert(objectMapper.readValue("\"VIEW\"", classOf[ActionType]) == ActionType.View)
+ }
+
+ // ---------------------------------------------------------------------------
+ // EntityType
+ // ---------------------------------------------------------------------------
+
+ "EntityType subtypes" should "expose their lowercase string value" in {
+ assert(EntityType.Workflow.value == "workflow")
+ assert(EntityType.Dataset.value == "dataset")
+ }
+
+ it should "have toString equal to value (override pin)" in {
+ val all: List[EntityType] = List(EntityType.Workflow, EntityType.Dataset)
+ all.foreach(e => assert(e.toString == e.value, s"$e.toString != $e.value"))
+ }
+
+ "EntityType.fromString" should "match each subtype exactly" in {
+ assert(EntityType.fromString("workflow") == EntityType.Workflow)
+ assert(EntityType.fromString("dataset") == EntityType.Dataset)
+ }
+
+ it should "match case-insensitively" in {
+ assert(EntityType.fromString("WORKFLOW") == EntityType.Workflow)
+ assert(EntityType.fromString("Dataset") == EntityType.Dataset)
+ }
+
+ it should "throw IllegalArgumentException for an unknown kind, naming the input" in {
+ val ex = intercept[IllegalArgumentException] {
+ EntityType.fromString("project")
+ }
+ assert(ex.getMessage.contains("project"))
+ }
+
+ it should "throw IllegalArgumentException for an empty string" in {
+ intercept[IllegalArgumentException] {
+ EntityType.fromString("")
+ }
+ }
Review Comment:
Done in d04e516529 — the empty-string test now asserts the message contains the concrete `''` representation, not just that an exception is thrown.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(amber): add unit test coverage for dashboard/hub entity model [texera]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #5402:
URL: https://github.com/apache/texera/pull/5402#discussion_r3366924978
##########
amber/src/test/scala/org/apache/texera/web/resource/dashboard/hub/HubEntityModelSpec.scala:
##########
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.web.resource.dashboard.hub
+
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.apache.texera.dao.jooq.generated.Tables._
+import org.scalatest.flatspec.AnyFlatSpec
+
+class HubEntityModelSpec extends AnyFlatSpec {
+
+ // ---------------------------------------------------------------------------
+ // ActionType
+ // ---------------------------------------------------------------------------
+
+ "ActionType subtypes" should "expose their lowercase string value" in {
+ assert(ActionType.View.value == "view")
+ assert(ActionType.Like.value == "like")
+ assert(ActionType.Clone.value == "clone")
+ assert(ActionType.Unlike.value == "unlike")
+ }
+
+ it should "have toString equal to value (override pin)" in {
+ // The trait override `toString = value` is what reaches log lines and
+ // tracking pipelines. Pin so a regression that returns the case-object
+ // name (e.g. "View" instead of "view") breaks here.
+ val all: List[ActionType] =
+ List(ActionType.View, ActionType.Like, ActionType.Clone, ActionType.Unlike)
+ all.foreach(a => assert(a.toString == a.value, s"$a.toString != $a.value"))
+ }
+
+ "ActionType.fromString" should "match each subtype exactly" in {
+ assert(ActionType.fromString("view") == ActionType.View)
+ assert(ActionType.fromString("like") == ActionType.Like)
+ assert(ActionType.fromString("clone") == ActionType.Clone)
+ assert(ActionType.fromString("unlike") == ActionType.Unlike)
+ }
+
+ it should "match case-insensitively" in {
+ assert(ActionType.fromString("VIEW") == ActionType.View)
+ assert(ActionType.fromString("Like") == ActionType.Like)
+ assert(ActionType.fromString("CLONE") == ActionType.Clone)
+ assert(ActionType.fromString("uNlIkE") == ActionType.Unlike)
+ }
+
+ it should "throw IllegalArgumentException for an unknown action, naming the input" in {
+ val ex = intercept[IllegalArgumentException] {
+ ActionType.fromString("delete")
+ }
+ assert(ex.getMessage.contains("delete"), s"unexpected message: ${ex.getMessage}")
+ }
+
+ it should "throw IllegalArgumentException for an empty string" in {
+ intercept[IllegalArgumentException] {
+ ActionType.fromString("")
+ }
+ }
+
+ "ActionType Jackson round-trip" should "serialize each subtype as its lowercase string value" in {
+ // `@JsonValue` on `value` instructs Jackson to emit the field's value
+ // string instead of a wrapping object form.
+ assert(objectMapper.writeValueAsString(ActionType.View: ActionType) == "\"view\"")
+ assert(objectMapper.writeValueAsString(ActionType.Like: ActionType) == "\"like\"")
+ assert(objectMapper.writeValueAsString(ActionType.Clone: ActionType) == "\"clone\"")
+ assert(objectMapper.writeValueAsString(ActionType.Unlike: ActionType) == "\"unlike\"")
+ }
+
+ it should "deserialize from the lowercase string back to the canonical subtype" in {
+ // `@JsonCreator` on `fromString` lets Jackson reconstruct the subtype
+ // from a raw string field.
+ assert(objectMapper.readValue("\"view\"", classOf[ActionType]) == ActionType.View)
+ assert(objectMapper.readValue("\"like\"", classOf[ActionType]) == ActionType.Like)
+ assert(objectMapper.readValue("\"clone\"", classOf[ActionType]) == ActionType.Clone)
+ assert(objectMapper.readValue("\"unlike\"", classOf[ActionType]) == ActionType.Unlike)
+ }
+
+ it should "honor the case-insensitive deserialization via @JsonCreator" in {
+ assert(objectMapper.readValue("\"VIEW\"", classOf[ActionType]) == ActionType.View)
+ }
+
+ // ---------------------------------------------------------------------------
+ // EntityType
+ // ---------------------------------------------------------------------------
+
+ "EntityType subtypes" should "expose their lowercase string value" in {
+ assert(EntityType.Workflow.value == "workflow")
+ assert(EntityType.Dataset.value == "dataset")
+ }
+
+ it should "have toString equal to value (override pin)" in {
+ val all: List[EntityType] = List(EntityType.Workflow, EntityType.Dataset)
+ all.foreach(e => assert(e.toString == e.value, s"$e.toString != $e.value"))
+ }
Review Comment:
Same as the ActionType toString pin: the failure message currently relies on `$e` (i.e., `e.toString`), which is the behavior under test. Using a stable name (class simple name) will make failures clearer if `toString` regresses.
##########
amber/src/test/scala/org/apache/texera/web/resource/dashboard/hub/HubEntityModelSpec.scala:
##########
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.web.resource.dashboard.hub
+
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.apache.texera.dao.jooq.generated.Tables._
+import org.scalatest.flatspec.AnyFlatSpec
+
+class HubEntityModelSpec extends AnyFlatSpec {
+
+ // ---------------------------------------------------------------------------
+ // ActionType
+ // ---------------------------------------------------------------------------
+
+ "ActionType subtypes" should "expose their lowercase string value" in {
+ assert(ActionType.View.value == "view")
+ assert(ActionType.Like.value == "like")
+ assert(ActionType.Clone.value == "clone")
+ assert(ActionType.Unlike.value == "unlike")
+ }
+
+ it should "have toString equal to value (override pin)" in {
+ // The trait override `toString = value` is what reaches log lines and
+ // tracking pipelines. Pin so a regression that returns the case-object
+ // name (e.g. "View" instead of "view") breaks here.
+ val all: List[ActionType] =
+ List(ActionType.View, ActionType.Like, ActionType.Clone, ActionType.Unlike)
+ all.foreach(a => assert(a.toString == a.value, s"$a.toString != $a.value"))
+ }
Review Comment:
This assertion’s failure message uses `$a` (i.e., `a.toString`) even though `toString` is what the test is trying to pin. If `toString` regresses, the failure output can become misleading/harder to diagnose. Consider using a stable identifier (class simple name) in the message instead.
##########
amber/src/test/scala/org/apache/texera/web/resource/dashboard/hub/HubEntityModelSpec.scala:
##########
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.web.resource.dashboard.hub
+
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.apache.texera.dao.jooq.generated.Tables._
+import org.scalatest.flatspec.AnyFlatSpec
+
+class HubEntityModelSpec extends AnyFlatSpec {
+
+ // ---------------------------------------------------------------------------
+ // ActionType
+ // ---------------------------------------------------------------------------
+
+ "ActionType subtypes" should "expose their lowercase string value" in {
+ assert(ActionType.View.value == "view")
+ assert(ActionType.Like.value == "like")
+ assert(ActionType.Clone.value == "clone")
+ assert(ActionType.Unlike.value == "unlike")
+ }
+
+ it should "have toString equal to value (override pin)" in {
+ // The trait override `toString = value` is what reaches log lines and
+ // tracking pipelines. Pin so a regression that returns the case-object
+ // name (e.g. "View" instead of "view") breaks here.
+ val all: List[ActionType] =
+ List(ActionType.View, ActionType.Like, ActionType.Clone, ActionType.Unlike)
+ all.foreach(a => assert(a.toString == a.value, s"$a.toString != $a.value"))
+ }
+
+ "ActionType.fromString" should "match each subtype exactly" in {
+ assert(ActionType.fromString("view") == ActionType.View)
+ assert(ActionType.fromString("like") == ActionType.Like)
+ assert(ActionType.fromString("clone") == ActionType.Clone)
+ assert(ActionType.fromString("unlike") == ActionType.Unlike)
+ }
+
+ it should "match case-insensitively" in {
+ assert(ActionType.fromString("VIEW") == ActionType.View)
+ assert(ActionType.fromString("Like") == ActionType.Like)
+ assert(ActionType.fromString("CLONE") == ActionType.Clone)
+ assert(ActionType.fromString("uNlIkE") == ActionType.Unlike)
+ }
+
+ it should "throw IllegalArgumentException for an unknown action, naming the input" in {
+ val ex = intercept[IllegalArgumentException] {
+ ActionType.fromString("delete")
+ }
+ assert(ex.getMessage.contains("delete"), s"unexpected message: ${ex.getMessage}")
+ }
+
+ it should "throw IllegalArgumentException for an empty string" in {
+ intercept[IllegalArgumentException] {
+ ActionType.fromString("")
+ }
+ }
+
+ "ActionType Jackson round-trip" should "serialize each subtype as its lowercase string value" in {
+ // `@JsonValue` on `value` instructs Jackson to emit the field's value
+ // string instead of a wrapping object form.
+ assert(objectMapper.writeValueAsString(ActionType.View: ActionType) == "\"view\"")
+ assert(objectMapper.writeValueAsString(ActionType.Like: ActionType) == "\"like\"")
+ assert(objectMapper.writeValueAsString(ActionType.Clone: ActionType) == "\"clone\"")
+ assert(objectMapper.writeValueAsString(ActionType.Unlike: ActionType) == "\"unlike\"")
+ }
+
+ it should "deserialize from the lowercase string back to the canonical subtype" in {
+ // `@JsonCreator` on `fromString` lets Jackson reconstruct the subtype
+ // from a raw string field.
+ assert(objectMapper.readValue("\"view\"", classOf[ActionType]) == ActionType.View)
+ assert(objectMapper.readValue("\"like\"", classOf[ActionType]) == ActionType.Like)
+ assert(objectMapper.readValue("\"clone\"", classOf[ActionType]) == ActionType.Clone)
+ assert(objectMapper.readValue("\"unlike\"", classOf[ActionType]) == ActionType.Unlike)
+ }
+
+ it should "honor the case-insensitive deserialization via @JsonCreator" in {
+ assert(objectMapper.readValue("\"VIEW\"", classOf[ActionType]) == ActionType.View)
+ }
+
+ // ---------------------------------------------------------------------------
+ // EntityType
+ // ---------------------------------------------------------------------------
+
+ "EntityType subtypes" should "expose their lowercase string value" in {
+ assert(EntityType.Workflow.value == "workflow")
+ assert(EntityType.Dataset.value == "dataset")
+ }
+
+ it should "have toString equal to value (override pin)" in {
+ val all: List[EntityType] = List(EntityType.Workflow, EntityType.Dataset)
+ all.foreach(e => assert(e.toString == e.value, s"$e.toString != $e.value"))
+ }
+
+ "EntityType.fromString" should "match each subtype exactly" in {
+ assert(EntityType.fromString("workflow") == EntityType.Workflow)
+ assert(EntityType.fromString("dataset") == EntityType.Dataset)
+ }
+
+ it should "match case-insensitively" in {
+ assert(EntityType.fromString("WORKFLOW") == EntityType.Workflow)
+ assert(EntityType.fromString("Dataset") == EntityType.Dataset)
+ }
+
+ it should "throw IllegalArgumentException for an unknown kind, naming the input" in {
+ val ex = intercept[IllegalArgumentException] {
+ EntityType.fromString("project")
+ }
+ assert(ex.getMessage.contains("project"))
+ }
+
+ it should "throw IllegalArgumentException for an empty string" in {
+ intercept[IllegalArgumentException] {
+ EntityType.fromString("")
+ }
+ }
Review Comment:
As with ActionType, the PR description/issue states the tests should pin that the IllegalArgumentException message names the unsupported input for unknown *and empty* strings, but this empty-string test only asserts an exception is thrown. Consider asserting for the concrete empty-input representation (currently `''`) to actually pin the contract.
##########
amber/src/test/scala/org/apache/texera/web/resource/dashboard/hub/HubEntityModelSpec.scala:
##########
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.web.resource.dashboard.hub
+
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.apache.texera.dao.jooq.generated.Tables._
+import org.scalatest.flatspec.AnyFlatSpec
+
+class HubEntityModelSpec extends AnyFlatSpec {
+
+ // ---------------------------------------------------------------------------
+ // ActionType
+ // ---------------------------------------------------------------------------
+
+ "ActionType subtypes" should "expose their lowercase string value" in {
+ assert(ActionType.View.value == "view")
+ assert(ActionType.Like.value == "like")
+ assert(ActionType.Clone.value == "clone")
+ assert(ActionType.Unlike.value == "unlike")
+ }
+
+ it should "have toString equal to value (override pin)" in {
+ // The trait override `toString = value` is what reaches log lines and
+ // tracking pipelines. Pin so a regression that returns the case-object
+ // name (e.g. "View" instead of "view") breaks here.
+ val all: List[ActionType] =
+ List(ActionType.View, ActionType.Like, ActionType.Clone, ActionType.Unlike)
+ all.foreach(a => assert(a.toString == a.value, s"$a.toString != $a.value"))
+ }
+
+ "ActionType.fromString" should "match each subtype exactly" in {
+ assert(ActionType.fromString("view") == ActionType.View)
+ assert(ActionType.fromString("like") == ActionType.Like)
+ assert(ActionType.fromString("clone") == ActionType.Clone)
+ assert(ActionType.fromString("unlike") == ActionType.Unlike)
+ }
+
+ it should "match case-insensitively" in {
+ assert(ActionType.fromString("VIEW") == ActionType.View)
+ assert(ActionType.fromString("Like") == ActionType.Like)
+ assert(ActionType.fromString("CLONE") == ActionType.Clone)
+ assert(ActionType.fromString("uNlIkE") == ActionType.Unlike)
+ }
+
+ it should "throw IllegalArgumentException for an unknown action, naming the input" in {
+ val ex = intercept[IllegalArgumentException] {
+ ActionType.fromString("delete")
+ }
+ assert(ex.getMessage.contains("delete"), s"unexpected message: ${ex.getMessage}")
+ }
+
+ it should "throw IllegalArgumentException for an empty string" in {
+ intercept[IllegalArgumentException] {
+ ActionType.fromString("")
+ }
+ }
Review Comment:
The PR description/issue says the tests should pin that the IllegalArgumentException message includes the unsupported input for unknown *and empty* strings, but this empty-string test only checks that an exception is thrown. Because `"".contains("")` is always true, it’s better to assert for the concrete empty-input representation (currently `''`).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(amber): add unit test coverage for dashboard/hub entity model [texera]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #5402:
URL: https://github.com/apache/texera/pull/5402#issuecomment-4637873547
## [Codecov](https://app.codecov.io/gh/apache/texera/pull/5402?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 51.77%. Comparing base ([`6a9437e`](https://app.codecov.io/gh/apache/texera/commit/6a9437ed6e46599044f4f7762dc23e4065624262?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`c468757`](https://app.codecov.io/gh/apache/texera/commit/c468757dcfa4ca9fac403dac4edead5e3f46ceb2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 1 commits behind head on main.
:white_check_mark: All tests successful. No failed tests found.
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #5402 +/- ##
============================================
+ Coverage 51.62% 51.77% +0.15%
- Complexity 2419 2424 +5
============================================
Files 1056 1056
Lines 41049 41049
Branches 4410 4410
============================================
+ Hits 21190 21252 +62
+ Misses 18619 18555 -64
- Partials 1240 1242 +2
```
| [Flag](https://app.codecov.io/gh/apache/texera/pull/5402/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | *Carryforward flag |
|---|---|---|---|
| [access-control-service](https://app.codecov.io/gh/apache/texera/pull/5402/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `41.89% <ø> (ø)` | | Carriedforward from [6a9437e](https://app.codecov.io/gh/apache/texera/commit/6a9437ed6e46599044f4f7762dc23e4065624262?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [agent-service](https://app.codecov.io/gh/apache/texera/pull/5402/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `33.76% <ø> (ø)` | | Carriedforward from [6a9437e](https://app.codecov.io/gh/apache/texera/commit/6a9437ed6e46599044f4f7762dc23e4065624262?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [amber](https://app.codecov.io/gh/apache/texera/pull/5402/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `52.66% <ø> (+0.39%)` | :arrow_up: | |
| [computing-unit-managing-service](https://app.codecov.io/gh/apache/texera/pull/5402/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `1.38% <ø> (ø)` | | Carriedforward from [6a9437e](https://app.codecov.io/gh/apache/texera/commit/6a9437ed6e46599044f4f7762dc23e4065624262?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [config-service](https://app.codecov.io/gh/apache/texera/pull/5402/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `54.68% <ø> (ø)` | | Carriedforward from [6a9437e](https://app.codecov.io/gh/apache/texera/commit/6a9437ed6e46599044f4f7762dc23e4065624262?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [file-service](https://app.codecov.io/gh/apache/texera/pull/5402/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `38.42% <ø> (ø)` | | Carriedforward from [6a9437e](https://app.codecov.io/gh/apache/texera/commit/6a9437ed6e46599044f4f7762dc23e4065624262?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [frontend](https://app.codecov.io/gh/apache/texera/pull/5402/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `46.30% <ø> (ø)` | | Carriedforward from [6a9437e](https://app.codecov.io/gh/apache/texera/commit/6a9437ed6e46599044f4f7762dc23e4065624262?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [pyamber](https://app.codecov.io/gh/apache/texera/pull/5402/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `90.69% <ø> (ø)` | | Carriedforward from [6a9437e](https://app.codecov.io/gh/apache/texera/commit/6a9437ed6e46599044f4f7762dc23e4065624262?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [python](https://app.codecov.io/gh/apache/texera/pull/5402/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `90.84% <ø> (ø)` | | Carriedforward from [6a9437e](https://app.codecov.io/gh/apache/texera/commit/6a9437ed6e46599044f4f7762dc23e4065624262?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [workflow-compiling-service](https://app.codecov.io/gh/apache/texera/pull/5402/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `58.39% <ø> (ø)` | | Carriedforward from [6a9437e](https://app.codecov.io/gh/apache/texera/commit/6a9437ed6e46599044f4f7762dc23e4065624262?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
*This pull request uses carry forward flags. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/texera/pull/5402?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(amber): add unit test coverage for dashboard/hub entity model [texera]
Posted by "aglinxinyuan (via GitHub)" <gi...@apache.org>.
aglinxinyuan commented on code in PR #5402:
URL: https://github.com/apache/texera/pull/5402#discussion_r3366972649
##########
amber/src/test/scala/org/apache/texera/web/resource/dashboard/hub/HubEntityModelSpec.scala:
##########
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.web.resource.dashboard.hub
+
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.apache.texera.dao.jooq.generated.Tables._
+import org.scalatest.flatspec.AnyFlatSpec
+
+class HubEntityModelSpec extends AnyFlatSpec {
+
+ // ---------------------------------------------------------------------------
+ // ActionType
+ // ---------------------------------------------------------------------------
+
+ "ActionType subtypes" should "expose their lowercase string value" in {
+ assert(ActionType.View.value == "view")
+ assert(ActionType.Like.value == "like")
+ assert(ActionType.Clone.value == "clone")
+ assert(ActionType.Unlike.value == "unlike")
+ }
+
+ it should "have toString equal to value (override pin)" in {
+ // The trait override `toString = value` is what reaches log lines and
+ // tracking pipelines. Pin so a regression that returns the case-object
+ // name (e.g. "View" instead of "view") breaks here.
+ val all: List[ActionType] =
+ List(ActionType.View, ActionType.Like, ActionType.Clone, ActionType.Unlike)
+ all.foreach(a => assert(a.toString == a.value, s"$a.toString != $a.value"))
+ }
Review Comment:
Done in d04e516529 — switched the failure message to use `a.getClass.getSimpleName` (stable across the SUT) instead of the toString-interpolation that was itself the contract being pinned. A regression in toString now produces a readable diagnostic naming the case object.
##########
amber/src/test/scala/org/apache/texera/web/resource/dashboard/hub/HubEntityModelSpec.scala:
##########
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.web.resource.dashboard.hub
+
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.apache.texera.dao.jooq.generated.Tables._
+import org.scalatest.flatspec.AnyFlatSpec
+
+class HubEntityModelSpec extends AnyFlatSpec {
+
+ // ---------------------------------------------------------------------------
+ // ActionType
+ // ---------------------------------------------------------------------------
+
+ "ActionType subtypes" should "expose their lowercase string value" in {
+ assert(ActionType.View.value == "view")
+ assert(ActionType.Like.value == "like")
+ assert(ActionType.Clone.value == "clone")
+ assert(ActionType.Unlike.value == "unlike")
+ }
+
+ it should "have toString equal to value (override pin)" in {
+ // The trait override `toString = value` is what reaches log lines and
+ // tracking pipelines. Pin so a regression that returns the case-object
+ // name (e.g. "View" instead of "view") breaks here.
+ val all: List[ActionType] =
+ List(ActionType.View, ActionType.Like, ActionType.Clone, ActionType.Unlike)
+ all.foreach(a => assert(a.toString == a.value, s"$a.toString != $a.value"))
+ }
+
+ "ActionType.fromString" should "match each subtype exactly" in {
+ assert(ActionType.fromString("view") == ActionType.View)
+ assert(ActionType.fromString("like") == ActionType.Like)
+ assert(ActionType.fromString("clone") == ActionType.Clone)
+ assert(ActionType.fromString("unlike") == ActionType.Unlike)
+ }
+
+ it should "match case-insensitively" in {
+ assert(ActionType.fromString("VIEW") == ActionType.View)
+ assert(ActionType.fromString("Like") == ActionType.Like)
+ assert(ActionType.fromString("CLONE") == ActionType.Clone)
+ assert(ActionType.fromString("uNlIkE") == ActionType.Unlike)
+ }
+
+ it should "throw IllegalArgumentException for an unknown action, naming the input" in {
+ val ex = intercept[IllegalArgumentException] {
+ ActionType.fromString("delete")
+ }
+ assert(ex.getMessage.contains("delete"), s"unexpected message: ${ex.getMessage}")
+ }
+
+ it should "throw IllegalArgumentException for an empty string" in {
+ intercept[IllegalArgumentException] {
+ ActionType.fromString("")
+ }
+ }
+
+ "ActionType Jackson round-trip" should "serialize each subtype as its lowercase string value" in {
+ // `@JsonValue` on `value` instructs Jackson to emit the field's value
+ // string instead of a wrapping object form.
+ assert(objectMapper.writeValueAsString(ActionType.View: ActionType) == "\"view\"")
+ assert(objectMapper.writeValueAsString(ActionType.Like: ActionType) == "\"like\"")
+ assert(objectMapper.writeValueAsString(ActionType.Clone: ActionType) == "\"clone\"")
+ assert(objectMapper.writeValueAsString(ActionType.Unlike: ActionType) == "\"unlike\"")
+ }
+
+ it should "deserialize from the lowercase string back to the canonical subtype" in {
+ // `@JsonCreator` on `fromString` lets Jackson reconstruct the subtype
+ // from a raw string field.
+ assert(objectMapper.readValue("\"view\"", classOf[ActionType]) == ActionType.View)
+ assert(objectMapper.readValue("\"like\"", classOf[ActionType]) == ActionType.Like)
+ assert(objectMapper.readValue("\"clone\"", classOf[ActionType]) == ActionType.Clone)
+ assert(objectMapper.readValue("\"unlike\"", classOf[ActionType]) == ActionType.Unlike)
+ }
+
+ it should "honor the case-insensitive deserialization via @JsonCreator" in {
+ assert(objectMapper.readValue("\"VIEW\"", classOf[ActionType]) == ActionType.View)
+ }
+
+ // ---------------------------------------------------------------------------
+ // EntityType
+ // ---------------------------------------------------------------------------
+
+ "EntityType subtypes" should "expose their lowercase string value" in {
+ assert(EntityType.Workflow.value == "workflow")
+ assert(EntityType.Dataset.value == "dataset")
+ }
+
+ it should "have toString equal to value (override pin)" in {
+ val all: List[EntityType] = List(EntityType.Workflow, EntityType.Dataset)
+ all.foreach(e => assert(e.toString == e.value, s"$e.toString != $e.value"))
+ }
Review Comment:
Done in d04e516529 — switched the failure message to use `a.getClass.getSimpleName` (stable across the SUT) instead of the toString-interpolation that was itself the contract being pinned. A regression in toString now produces a readable diagnostic naming the case object.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(amber): add unit test coverage for dashboard/hub entity model [texera]
Posted by "aglinxinyuan (via GitHub)" <gi...@apache.org>.
aglinxinyuan merged PR #5402:
URL: https://github.com/apache/texera/pull/5402
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org