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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
