Search in sources :

Example 26 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class JmsUtil method runTest.

@Override
public SampleResult runTest(JavaSamplerContext ctx) {
    SampleResult result = new SampleResult();
    result.setContentType("plain/text");
    result.setDataType(SampleResult.TEXT);
    result.setDataEncoding(SampleResult.DEFAULT_HTTP_ENCODING);
    String connectionUrl = ctx.getParameter("connection.url");
    String bindingUrl = ctx.getParameter("binding.url");
    String message = ctx.getParameter("message");
    if (connectionUrl == null || "".equals(connectionUrl)) {
        result.setSuccessful(false);
        result.setResponseMessage("Connection URL cannot be empty.");
        result.setResponseCode("0xDEAD");
    } else {
        if (bindingUrl == null || "".equals(bindingUrl)) {
            result.setSuccessful(false);
            result.setResponseMessage("Binding URL cannot be empty.");
            result.setResponseCode("0xDEAD");
        } else {
            try {
                ConnectionFactory connectionFactory = new AMQConnectionFactory(connectionUrl);
                AMQBindingURL burl = new AMQBindingURL(bindingUrl);
                Destination destinationProducer = new AMQAnyDestination(burl);
                JmsTemplate sender = new JmsTemplate();
                sender.setConnectionFactory(connectionFactory);
                sender.setDefaultDestination(destinationProducer);
                BinaryMessageConverter bmc = new BinaryMessageConverter();
                sender.setMessageConverter(bmc);
                BinaryMessagepostProcessor postProcessor = new BinaryMessagepostProcessor();
                sender.setDeliveryMode(2);
                int rt = 30000;
                try {
                    rt = Integer.valueOf(ctx.getParameter("receive.timeout"));
                } catch (Exception e) {
                }
                sender.setReceiveTimeout(rt);
                String direction = ctx.getParameter("direction");
                if (direction == null || "".equals(direction)) {
                    direction = "send";
                }
                if (direction.toLowerCase().equals("send")) {
                    Map<String, String> mp = getMessageProperties(ctx.getParameter("header.properties"));
                    postProcessor.setMessageProperties(mp);
                    sender.convertAndSend((Object) message, postProcessor);
                    result.setSuccessful(true);
                    result.setResponseMessage("Message sent.");
                } else {
                    if (direction.toLowerCase().equals("receive")) {
                        System.out.println("Receive");
                        String messageSelector = ctx.getParameter("message.selector");
                        System.out.println("Selector: " + messageSelector);
                        Object obj = null;
                        if (messageSelector != null && !"".equals(messageSelector)) {
                            obj = sender.receiveSelectedAndConvert(messageSelector);
                        } else {
                            obj = sender.receiveAndConvert();
                        }
                        if (obj != null) {
                            result.setSuccessful(true);
                            result.setResponseData(obj.toString().getBytes());
                            String paramName = ctx.getParameter("header.property.reference");
                            if (paramName != null && !"".equals(paramName))
                                JMeterUtils.setProperty(paramName, concatProperties(bmc.getMessageProperties()));
                        } else {
                            result.setSuccessful(false);
                            result.setResponseData("Conection timeout".getBytes());
                        }
                    } else {
                        result.setSuccessful(false);
                        result.setResponseMessage("Unknown direction.");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                result.setSuccessful(false);
                result.setResponseMessage("Exception");
                result.setResponseData(e.getMessage().getBytes());
            }
        }
    }
    return result;
}
Also used : AMQAnyDestination(org.apache.qpid.client.AMQAnyDestination) Destination(javax.jms.Destination) AMQBindingURL(org.apache.qpid.url.AMQBindingURL) AMQConnectionFactory(org.apache.qpid.client.AMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) AMQAnyDestination(org.apache.qpid.client.AMQAnyDestination) AMQConnectionFactory(org.apache.qpid.client.AMQConnectionFactory) JmsTemplate(org.springframework.jms.core.JmsTemplate) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 27 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class CaseFormatTest method setUp.

@Before
public void setUp() {
    changeCase = new CaseFormat();
    result = new SampleResult();
    JMeterContext jmctx = JMeterContextService.getContext();
    String data = "dummy data";
    result.setResponseData(data, null);
    JMeterVariables vars = new JMeterVariables();
    jmctx.setVariables(vars);
    jmctx.setPreviousResult(result);
    params = new LinkedList<>();
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 28 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class DoubleSumTest method testExecute.

/**
 * Test of execute method, of class DoubleSum.
 */
@Test
public void testExecute() throws Exception {
    System.out.println("execute");
    SampleResult previousResult = null;
    Sampler currentSampler = null;
    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable("1.256"));
    parameters.add(new CompoundVariable("4.3346"));
    DoubleSum instance = new DoubleSum();
    instance.setParameters(parameters);
    String expResult = "5.5906";
    String result = instance.execute(null, null);
    Assert.assertEquals(expResult, result);
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Sampler(org.apache.jmeter.samplers.Sampler) ArrayList(java.util.ArrayList) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 29 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class EnvTest method testExecute_3.

@Test
public void testExecute_3() throws Exception {
    System.out.println("execute 1");
    SampleResult previousResult = null;
    Sampler currentSampler = null;
    Assert.assertNull(JMeterContextService.getContext().getVariables().get("toto"));
    Collection<CompoundVariable> parameters = new ArrayList<>();
    String overrideKey = key + "testExecute_3";
    String defaultValue = "defaultValue";
    parameters.add(new CompoundVariable(overrideKey));
    parameters.add(new CompoundVariable(""));
    parameters.add(new CompoundVariable(defaultValue));
    Env instance = new Env();
    instance.setParameters(parameters);
    String result = instance.execute(null, null);
    Assert.assertEquals(defaultValue, result);
    Assert.assertNull(JMeterContextService.getContext().getVariables().get("toto"));
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Sampler(org.apache.jmeter.samplers.Sampler) ArrayList(java.util.ArrayList) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 30 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class EnvTest method testExecute_2.

@Test
public void testExecute_2() throws Exception {
    System.out.println("execute 1");
    SampleResult previousResult = null;
    Sampler currentSampler = null;
    Assert.assertNull(JMeterContextService.getContext().getVariables().get("toto"));
    Collection<CompoundVariable> parameters = new ArrayList<>();
    String overrideKey = key + "testExecute_2";
    parameters.add(new CompoundVariable(overrideKey));
    Env instance = new Env();
    instance.setParameters(parameters);
    String result = instance.execute(null, null);
    Assert.assertEquals(overrideKey, result);
    Assert.assertNull(JMeterContextService.getContext().getVariables().get("toto"));
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Sampler(org.apache.jmeter.samplers.Sampler) ArrayList(java.util.ArrayList) SampleResult(org.apache.jmeter.samplers.SampleResult)

Aggregations

SampleResult (org.apache.jmeter.samplers.SampleResult)381 Test (org.junit.Test)83 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)71 Test (org.junit.jupiter.api.Test)59 JMeterContext (org.apache.jmeter.threads.JMeterContext)47 BeforeEach (org.junit.jupiter.api.BeforeEach)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 SampleEvent (org.apache.jmeter.samplers.SampleEvent)30 Sampler (org.apache.jmeter.samplers.Sampler)30 AssertionResult (org.apache.jmeter.assertions.AssertionResult)27 ArrayList (java.util.ArrayList)26 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)20 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)20 IOException (java.io.IOException)17 Arguments (org.apache.jmeter.config.Arguments)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)13 CorrectedResultCollector (kg.apc.jmeter.vizualizers.CorrectedResultCollector)12 URL (java.net.URL)9 File (java.io.File)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7