You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2022/10/21 15:01:22 UTC

[skywalking-agent-test-tool] branch master updated: Support not blank validator (#46)

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

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-agent-test-tool.git


The following commit(s) were added to refs/heads/master by this push:
     new 7f20775  Support not blank validator (#46)
7f20775 is described below

commit 7f20775e0631356c4823d9372b09d653db0e6540
Author: pg.yang <pg...@hotmail.com>
AuthorDate: Fri Oct 21 23:01:16 2022 +0800

    Support not blank validator (#46)
---
 README.md                                          |  2 +-
 .../tool/validator/assertor/ExpressParser.java     |  5 +++
 .../assertor/element/NotBlankAssertor.java         | 33 ++++++++++++++++++
 .../tool/validator/assertor/DataAssertTest.java    | 18 ++++++++++
 .../test/resources/blank-validator/actualData.yaml | 40 ++++++++++++++++++++++
 .../resources/blank-validator/expectedData.yaml    | 40 ++++++++++++++++++++++
 validator/src/test/resources/expectedData.yaml     |  4 +--
 7 files changed, 139 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index d7252f3..2b7b46f 100644
--- a/README.md
+++ b/README.md
@@ -75,7 +75,7 @@ java -jar \
 NOTICE: the `expected data` have to call `expectedData.yaml`, and the `actual data` must name as `actualData.yaml`. These files save all the segment and meter data, and in the same directory, `/path/to/download-folder`.
 JVM argument `caseName` just for show in the log.
 
-The format and documentation of `expectedData.yaml` could be found in [SkyWalking plugin test doc](https://skywalking.apache.org/docs/skywalking-java/latest/en/setup/service-agent/java-agent/plugin-test/)
+The format and documentation of `expectedData.yaml` could be found in [SkyWalking plugin test doc](https://skywalking.apache.org/docs/skywalking-java/next/en/setup/service-agent/java-agent/plugin-test/)
 
 # Contact Us
 * Mail list: **dev@skywalking.apache.org**. Mail to `dev-subscribe@skywalking.apache.org`, follow the reply to subscribe the mail list.
diff --git a/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/ExpressParser.java b/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/ExpressParser.java
index 84ff2d0..40c105d 100644
--- a/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/ExpressParser.java
+++ b/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/ExpressParser.java
@@ -22,6 +22,7 @@ import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.E
 import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.GreatThanAssertor;
 import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.GreetEqualAssertor;
 import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.NoopAssertor;
+import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.NotBlankAssertor;
 import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.NotEqualsAssertor;
 import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.NotNullAssertor;
 import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.NullAssertor;
@@ -37,6 +38,10 @@ public class ExpressParser {
             return new NotNullAssertor();
         }
 
+        if (expressTrim.equals("not blank")) {
+            return new NotBlankAssertor();
+        }
+
         if (expressTrim.equals("null")) {
             return new NullAssertor();
         }
diff --git a/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NotBlankAssertor.java b/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NotBlankAssertor.java
new file mode 100644
index 0000000..4029f17
--- /dev/null
+++ b/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NotBlankAssertor.java
@@ -0,0 +1,33 @@
+/*
+ * 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.skywalking.plugin.test.agent.tool.validator.assertor.element;
+
+import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ValueAssertFailedException;
+
+public class NotBlankAssertor extends ElementAssertor {
+    public NotBlankAssertor() {
+        super(null);
+    }
+
+    @Override
+    public void assertValue(String desc, String actualValue) {
+        if (actualValue == null || actualValue.trim().isEmpty()) {
+            throw new ValueAssertFailedException(desc, "not blank", actualValue);
+        }
+    }
+}
diff --git a/validator/src/test/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/DataAssertTest.java b/validator/src/test/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/DataAssertTest.java
index e226009..75390ff 100644
--- a/validator/src/test/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/DataAssertTest.java
+++ b/validator/src/test/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/DataAssertTest.java
@@ -20,6 +20,7 @@ package org.apache.skywalking.plugin.test.agent.tool.validator.assertor;
 import java.io.File;
 import org.apache.skywalking.plugin.test.agent.tool.validator.entity.Data;
 import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class DataAssertTest {
@@ -39,4 +40,21 @@ public class DataAssertTest {
         }
     }
 
+    @Test(expected = AssertFailedException.class)
+    public void testNotBlankAssertFunction() {
+        try {
+            File actualData = new File(DataAssertTest.class.getResource("/blank-validator/actualData.yaml").getFile());
+            File expectedData = new File(
+                DataAssertTest.class.getResource("/blank-validator/expectedData.yaml").getFile());
+            DataAssert.assertEquals(
+                Data.Loader.loadData(expectedData),
+                Data.Loader.loadData(actualData)
+            );
+        } catch (AssertFailedException e) {
+            System.out.println(e.getCauseMessage());
+            Assert.assertTrue(e.getCauseMessage().contains("{not blank}"));
+            throw e;
+        }
+    }
+
 }
\ No newline at end of file
diff --git a/validator/src/test/resources/blank-validator/actualData.yaml b/validator/src/test/resources/blank-validator/actualData.yaml
new file mode 100644
index 0000000..4947d2a
--- /dev/null
+++ b/validator/src/test/resources/blank-validator/actualData.yaml
@@ -0,0 +1,40 @@
+# 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.
+segmentItems:
+  - serviceName: jettyserver-scenario
+    segmentSize: 1
+    segments:
+      - segmentId: b7b87f050b004bcbaf6c3b461e310b39.19.15860972284530000
+        spans:
+          - operationName: /jettyserver-case/case/receiveContext-0
+            operationId: 0
+            parentSpanId: -1
+            spanId: 0
+            spanLayer: Http
+            startTime: 1586097228454
+            endTime: 1586097230551
+            componentId: 19
+            isError: false
+            spanType: Entry
+            peer: ''
+            skipAnalysis: false
+            tags:
+              - {key: url, value: '    '}
+              - {key: http.method, value: GET}
+            refs:
+              - {parentEndpoint: /jettyclient-case/case/jettyclient-case, networkAddress: 'localhost:18080',
+                 refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: 9da55094db7845919d8de81cf26e9769.44.15860972266610000,
+                 parentServiceInstance: 2c6396ba48d549c99ae3c1643aae5a90@172.17.0.2, parentService: jettyclient-scenario,
+                 traceId: 9da55094db7845919d8de81cf26e9769.44.15860972266610001}
\ No newline at end of file
diff --git a/validator/src/test/resources/blank-validator/expectedData.yaml b/validator/src/test/resources/blank-validator/expectedData.yaml
new file mode 100644
index 0000000..2106268
--- /dev/null
+++ b/validator/src/test/resources/blank-validator/expectedData.yaml
@@ -0,0 +1,40 @@
+# 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.
+segmentItems:
+  - serviceName: jettyserver-scenario
+    segmentSize: 1
+    segments:
+      - segmentId: not null
+        spans:
+          - operationName: /jettyserver-case/case/receiveContext-0
+            operationId: 0
+            parentSpanId: -1
+            spanId: 0
+            spanLayer: Http
+            startTime: gt 0
+            endTime: gt 0
+            componentId: 19
+            isError: false
+            spanType: Entry
+            peer: ''
+            skipAnalysis: false
+            tags:
+              - {key: url, value: not blank}
+              - {key: http.method, value: GET}
+            refs:
+              - {parentEndpoint: /jettyclient-case/case/jettyclient-case, networkAddress: 'localhost:18080',
+                 refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null,
+                 parentServiceInstance: not null, parentService: jettyclient-scenario,
+                 traceId: not null}
\ No newline at end of file
diff --git a/validator/src/test/resources/expectedData.yaml b/validator/src/test/resources/expectedData.yaml
index a4e1ff5..e3a4d69 100644
--- a/validator/src/test/resources/expectedData.yaml
+++ b/validator/src/test/resources/expectedData.yaml
@@ -74,7 +74,7 @@ segmentItems:
             skipAnalysis: false
             tags:
               - {key: http.method, value: GET}
-              - {key: url, value: 'http://localhost:18080/jettyserver-case/case/receiveContext-0'}
+              - {key: url, value: not blank}
           - operationName: /jettyclient-case/case/jettyclient-case
             operationId: 0
             parentSpanId: -1
@@ -112,7 +112,7 @@ logItems:
         body:
           type: ''
           content:
-            json: "something json to log"
+            json: not blank
         traceContext:
           traceId: not null
           traceSegmentId: not null