You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2019/08/17 19:51:12 UTC
[jmeter] branch master updated: Spec for CompareAssertion
This is an automated email from the ASF dual-hosted git repository.
fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git
The following commit(s) were added to refs/heads/master by this push:
new fdccd01 Spec for CompareAssertion
fdccd01 is described below
commit fdccd017c7eed8234d0e58c3e6c260ab9f7002ab
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Sat Aug 17 21:50:40 2019 +0200
Spec for CompareAssertion
---
.../jmeter/assertions/CompareAssertionSpec.groovy | 75 ++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/src/components/src/test/groovy/org/apache/jmeter/assertions/CompareAssertionSpec.groovy b/src/components/src/test/groovy/org/apache/jmeter/assertions/CompareAssertionSpec.groovy
new file mode 100644
index 0000000..7d32cb1
--- /dev/null
+++ b/src/components/src/test/groovy/org/apache/jmeter/assertions/CompareAssertionSpec.groovy
@@ -0,0 +1,75 @@
+/*
+ * 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.jmeter.assertions
+
+import org.apache.commons.lang3.StringUtils
+import org.apache.jmeter.samplers.SampleResult
+import spock.lang.Specification
+import spock.lang.Unroll
+
+import java.nio.charset.StandardCharsets
+
+@Unroll
+class CompareAssertionSpec extends Specification {
+
+ def sut = new CompareAssertion()
+
+ def "Result is simple assertionResult when only one response is given"() {
+ given:
+ sut.setName("myName")
+ sut.iterationStart(null)
+ when:
+ def assertionResult = sut.getResult(null)
+ then:
+ assertionResult.getName() == "myName"
+ }
+
+ def "content '#content' with compareContent==#compareContent, skip=#skip, elapsed=#elapsed and compareTime==#compareTime"() {
+ given:
+ sut.setName("myName")
+ def firstResponse = simpleResult("OK", 100)
+ sut.iterationStart(null)
+ sut.getResult(firstResponse)
+ sut.setCompareContent(compareContent)
+ sut.setCompareTime(compareTime)
+ if (skip != null) {
+ def subst = new SubstitutionElement()
+ subst.setRegex(skip)
+ sut.setStringsToSkip(Arrays.asList(subst))
+ }
+ when:
+ def assertionResult = sut.getResult(simpleResult(content, elapsed))
+ then:
+ assertionResult.isFailure() == isFailure
+ where:
+ compareContent | compareTime | content | elapsed | skip | isFailure
+ true | -1 | "OK" | 100 | null | false
+ true | -1 | "different" | 100 | null | true
+ false | -1 | "different" | 100 | null | false
+ false | -1 | "different OK" | 100 | "d\\w+\\s" | false
+ true | 10 | "OK" | 120 | null | true
+ true | 10 | "OK" | 110 | null | false
+ }
+
+ private SampleResult simpleResult(String data, long elapsed) {
+ def result = new SampleResult(0L, elapsed)
+ result.setResponseData(data, StandardCharsets.UTF_8.name())
+ result.sampleEnd()
+ return result
+ }
+}
\ No newline at end of file