aglinxinyuan commented on code in PR #5769: URL: https://github.com/apache/texera/pull/5769#discussion_r3432538359
########## common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/visualization/urlviz/UrlVizOpExecSpec.scala: ########## @@ -0,0 +1,121 @@ +/* + * 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.amber.operator.visualization.urlviz + +import org.apache.texera.amber.core.tuple.{Attribute, AttributeType, Schema, Tuple, TupleLike} +import org.apache.texera.amber.util.JSONUtils.objectMapper +import org.scalatest.flatspec.AnyFlatSpec + +class UrlVizOpExecSpec extends AnyFlatSpec { + + // --------------------------------------------------------------------------- + // Fixtures + // --------------------------------------------------------------------------- + + private val attr = new Attribute("url", AttributeType.STRING) + private val schema: Schema = Schema().add(attr) + private def tuple(url: String): Tuple = + Tuple.builder(schema).add(attr, url).build() + + /** + * Build a descriptor JSON for `UrlVizOpExec`. The production class + * declares `urlContentAttrName` as a `val` initialized to `""`; the + * Jackson-`module-no-ctor-deser` module bypasses the val and writes + * to the underlying field via reflection, so the spec can supply + * any attribute name through the JSON wire-key. + * + * LogicalOp carries `@JsonTypeInfo(property = "operatorType")`, so + * the JSON must include the `operatorType` discriminator (value + * `"URLVisualizer"` per LogicalOp's `@JsonSubTypes` table). + */ + private def descJson(urlAttr: String): String = { + val node = objectMapper.createObjectNode() + node.put("operatorType", "URLVisualizer") + node.put("urlContentAttrName", urlAttr) + node.toString + } + + private def runSingle(exec: UrlVizOpExec, t: Tuple): String = { + val out = exec.processTuple(t, port = 0).toList + assert(out.size == 1, s"expected one emission, got: $out") + out.head match { + case tupleLike: TupleLike => + // The first field of the emitted TupleLike is the generated HTML. + tupleLike.getFields.head.toString + } + } Review Comment: Good catch — tightened in 3f38f84. `runSingle` now asserts `fields.size == 1` and `field.isInstanceOf[String]` before returning, so a regression emitting additional fields or a non-string value would fail loudly instead of silently passing through `toString`. -- 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]
