org.apache.jmeter.assertions.AssertionResult Java Examples
The following examples show how to use
org.apache.jmeter.assertions.AssertionResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testYamlAssertion4() throws IOException { File test = new File(getClass().getResource("/test.yml").getPath()); String response = FileUtils.readFileToString(test); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData(response.getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setInputFormat(JSONPathAssertion.INPUT_YAML); instance.setJsonPath("$.developers"); instance.setJsonValidationBool(true); instance.setIsRegex(false); instance.setExpectedValue("[\"rultor\",\"salikjan\",\"sherif\"]"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example #2
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testGetResult_inverted_null() { System.out.println("getResult notexist"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": [{\"key\": null}]}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval[*].key"); instance.setJsonValidationBool(true); instance.setExpectNull(true); instance.setInvert(true); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertTrue(result.isFailure()); }
Example #3
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testGetResult_negative_invert() { System.out.println("getResult simple"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": 123}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setJsonValidationBool(true); instance.setExpectedValue("1234"); instance.setInvert(true); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertFalse(result.isFailure()); assertEquals(expResult.getName(), result.getName()); }
Example #4
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testGetResult_match_msg_problem() { System.out.println("getResult notexist"); SampleResult samplerResult = new SampleResult(); String str = "{\"execution\":[{\"scenario\":{\"requests\":[{\"headers\":{\"headerkey\":\"header value\"}}]}}]}"; samplerResult.setResponseData(str.getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.execution[0].scenario.requests[0].headers"); instance.setJsonValidationBool(true); instance.setExpectNull(false); instance.setExpectedValue("{headerkey=header value}"); instance.setInvert(false); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertTrue(result.isFailure()); assertEquals("Value expected to match regexp '{headerkey=header value}', but it did not match: '{\"headerkey\":\"header value\"}'", result.getFailureMessage()); }
Example #5
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testGetResult_not_regexp() { System.out.println("not regexp"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": \"some complicated value\"}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setJsonValidationBool(true); instance.setExpectedValue("some.+"); AssertionResult result = instance.getResult(samplerResult); assertFalse(result.isFailure()); instance.setIsRegex(false); AssertionResult result2 = instance.getResult(samplerResult); assertTrue(result2.isFailure()); }
Example #6
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testGetResult_positive_invert() { System.out.println("getResult simple"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": 123}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setJsonValidationBool(true); instance.setExpectedValue("123"); instance.setInvert(true); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertTrue(result.isFailure()); assertEquals(expResult.getName(), result.getName()); }
Example #7
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testGetResult_positive_regexp() { System.out.println("getResult simple"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": 123}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setJsonValidationBool(true); instance.setExpectedValue("(123|456)"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); samplerResult.setResponseData("{\"myval\": 456}".getBytes()); AssertionResult result2 = instance.getResult(samplerResult); assertFalse(result2.isFailure()); }
Example #8
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testGetResultFloat() { System.out.println("testGetResultFloat"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": [{\"test\":0.0000123456789}]}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval[*].test"); instance.setJsonValidationBool(true); instance.setIsRegex(false); instance.setExpectedValue("0.0000123456789"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example #9
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testYamlAssertion() throws IOException { File test = new File(getClass().getResource("/test1.yml").getPath()); String response = FileUtils.readFileToString(test); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData(response.getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setInputFormat(JSONPathAssertion.INPUT_YAML); instance.setJsonPath("$.execution[*].concurrency"); instance.setJsonValidationBool(true); instance.setIsRegex(false); instance.setExpectedValue("100"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example #10
Source File: ElasticSearchMetric.java From jmeter-elasticsearch-backend-listener with MIT License | 6 votes |
/** * This method adds all the assertions for the current sampleResult */ private void addAssertions() { AssertionResult[] assertionResults = this.sampleResult.getAssertionResults(); if (assertionResults != null) { Map<String, Object>[] assertionArray = new HashMap[assertionResults.length]; Integer i = 0; String failureMessage = ""; boolean isFailure = false; for (AssertionResult assertionResult : assertionResults) { HashMap<String, Object> assertionMap = new HashMap<>(); boolean failure = assertionResult.isFailure() || assertionResult.isError(); isFailure = isFailure || assertionResult.isFailure() || assertionResult.isError(); assertionMap.put("failure", failure); assertionMap.put("failureMessage", assertionResult.getFailureMessage()); failureMessage += assertionResult.getFailureMessage() + "\n"; assertionMap.put("name", assertionResult.getName()); assertionArray[i] = assertionMap; i++; } addFilteredJSON("AssertionResults", assertionArray); addFilteredJSON("FailureMessage", failureMessage); addFilteredJSON("Success", !isFailure); } }
Example #11
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testYamlAssertion2() throws IOException { File test = new File(getClass().getResource("/test1.yml").getPath()); String response = FileUtils.readFileToString(test); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData(response.getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setInputFormat(JSONPathAssertion.INPUT_YAML); instance.setJsonPath("$.scenarios.quick-test.requests[0]"); instance.setJsonValidationBool(true); instance.setIsRegex(false); instance.setExpectedValue("http://blazedemo.com"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example #12
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testYamlAssertion3() throws IOException { File test = new File(getClass().getResource("/test1.yml").getPath()); String response = FileUtils.readFileToString(test); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData(response.getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setInputFormat(JSONPathAssertion.INPUT_YAML); instance.setJsonPath("$.name"); instance.setJsonValidationBool(true); instance.setIsRegex(false); instance.setExpectedValue("camel"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example #13
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_match_msg_problem2() { SampleResult samplerResult = new SampleResult(); String str = "{\n" + " \"code\":200,\n" + " \"contact\":{\n" + " \"id\":28071,\n" + " \"description\":\"test description\",\n" + " \"info\":{\n" + " \"ngn_number\":[\n" + " \"2003\",\n" + " \"2004\"\n" + " ]\n" + " }\n" + " }\n" + "}"; samplerResult.setResponseData(str.getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.contact.info.ngn_number"); instance.setJsonValidationBool(true); instance.setExpectNull(false); instance.setExpectedValue("[\"2003\",\"2004\"]"); instance.setInvert(false); instance.setIsRegex(false); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example #14
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_null_novalidate() { System.out.println("getResult null novalidate"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": null}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setJsonValidationBool(false); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example #15
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_dict() { System.out.println("getResult notexist"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": {\"key\": \"val\"}}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setJsonValidationBool(true); instance.setExpectedValue("{\"key\":\"val\"}"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example #16
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_list_empty_validate() { System.out.println("getResult list-empty"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": []}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setJsonValidationBool(true); instance.setExpectedValue("[]"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example #17
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_list_empty_novalidate() { System.out.println("getResult list-empty"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": []}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval[*]"); instance.setJsonValidationBool(false); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example #18
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_list_negative() { System.out.println("getResult list-neg"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": [{\"test\":1},{\"test\":2},{\"test\":3}]}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval[*].test"); instance.setJsonValidationBool(true); instance.setExpectedValue("5"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertTrue(result.isFailure()); }
Example #19
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_list_val() { System.out.println("getResult list-val"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": [{\"test\":1},{\"test\":2},{\"test\":3}]}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval[*].test"); instance.setJsonValidationBool(true); instance.setExpectedValue("2"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example #20
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_no_such_path() { System.out.println("getResult notexist"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": null}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.notexist"); instance.setJsonValidationBool(false); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertTrue(result.isFailure()); }
Example #21
Source File: CountTypeUpdater.java From jmeter-prometheus-plugin with Apache License 2.0 | 5 votes |
@Override public void update(SampleEvent event) { if(this.config.listenToSamples()) { boolean successful = event.getResult().isSuccessful(); this.inc(this.labelValues(event), successful); } else if(this.config.listenToAssertions()) { for(AssertionResult assertion : event.getResult().getAssertionResults()) { updateAssertions(new AssertionContext(assertion, event)); } } }
Example #22
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_null_not_found() { System.out.println("getResult null"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": 123}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setExpectNull(true); instance.setJsonValidationBool(true); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertTrue(result.isFailure()); }
Example #23
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_null() { System.out.println("getResult null"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": null}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setExpectNull(true); instance.setJsonValidationBool(true); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example #24
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_negative() { System.out.println("getResult simple"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": 123}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setJsonValidationBool(true); instance.setExpectedValue("1234"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertTrue(result.isFailure()); }
Example #25
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_positive() { System.out.println("getResult simple"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": 123}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setJsonValidationBool(true); instance.setExpectedValue("123"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example #26
Source File: DebuggerEngineTest.java From jmeter-debugger with Apache License 2.0 | 5 votes |
@Test public void runVariablesInAssertions() throws Exception { TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/debug.jmx", "debug.jmx"); Debugger sel = new Debugger(prov, new FrontendMock()); AbstractThreadGroup tg = prov.getTG(0); sel.selectThreadGroup(tg); HashTree testTree = sel.getSelectedTree(); TestSampleListener listener = new TestSampleListener(); testTree.add(testTree.getArray()[0], listener); DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree); LoopController samplerController = (LoopController) tg2.getSamplerController(); samplerController.setLoops(1); samplerController.setContinueForever(false); JMeter.convertSubTree(testTree); DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext()); StepTriggerCounter hook = new StepTriggerCounter(); engine.setStepper(hook); engine.configure(testTree); engine.runTest(); while (engine.isActive()) { Thread.sleep(1000); } assertEquals(4, hook.cnt); assertEquals(1, listener.events.size()); SampleEvent event = listener.events.get(0); SampleResult result = event.getResult(); AssertionResult[] assertionResults = result.getAssertionResults(); assertEquals(1, assertionResults.length); AssertionResult assertionRes = assertionResults[0]; assertNull(assertionRes.getFailureMessage()); }
Example #27
Source File: CountTypeUpdaterTest.java From jmeter-prometheus-plugin with Apache License 2.0 | 5 votes |
public static SampleResult newSampleResultWithAssertion(boolean success) { SampleResult res = newSampleResult(success); AssertionResult assertion = new AssertionResult(TestUtilities.TEST_ASSERTION_NAME); assertion.setFailure(!success); res.addAssertionResult(assertion); return res; }
Example #28
Source File: AssertionDebug.java From jmeter-debugger with Apache License 2.0 | 4 votes |
@Override public AssertionResult getResult(SampleResult sampleResult) { prepareBean(); getHook().stepOn(this); return wrapped.getResult(sampleResult); }
Example #29
Source File: CountTypeUpdaterTest.java From jmeter-prometheus-plugin with Apache License 2.0 | 4 votes |
public static AssertionResult altAssertion(boolean success) { AssertionResult assertion = new AssertionResult(TestUtilities.TEST_ASSERTION_NAME_ALT); assertion.setFailure(!success); return assertion; }
Example #30
Source File: AbstractUpdater.java From jmeter-prometheus-plugin with Apache License 2.0 | 4 votes |
public AssertionContext(AssertionResult a, SampleEvent e) { this.assertion = a; this.event = e; }