Java Code Examples for org.wso2.carbon.automation.engine.annotations.ExecutionEnvironment

The following examples show how to use org.wso2.carbon.automation.engine.annotations.ExecutionEnvironment. These examples are extracted from open source projects. 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
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = "wso2.esb", description = "Tests sequences from  the governance registry with inbound endpoint")
public void testSequence() throws Exception {

    logViewerClient.clearLogs();

    //Copy file to source folder from which the inbound endpoint will pick up the message
    File sourceFile = new File(pathToDir + File.separator + "test.xml");
    File targetFile = new File(InboundFileFolder + File.separator + "test.xml");
    if (!sourceFile.exists()) {
        sourceFile.createNewFile();
    }
    log.info("Copying files to the target folder");
    FileUtils.copyFile(sourceFile, targetFile);

    //And file inbound endpoint
    addInboundEndpoint(createInboundEP());

    Assert.assertTrue(Utils.checkForLog(logViewerClient, "Proxy invoked by dynamic sequence in file inbound",
            10), "The XML file is not getting read");

}
 
Example 2
Source Project: micro-integrator   Source File: VFSTransportTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = { "wso2.esb" }, description = "Writing to a file the content of a xml with content in text element")
public void testVFSProxyPlainXMLWriter() throws Exception {

    File outfile = new File(proxyVFSRoots.get("salesforce_DAMAS_writeFile") + File.separator +
            "out" + File.separator + "out_reply.xml");

    String request =
            " <ns:text xmlns:ns=\"http://ws.apache.org/commons/ns/payload\"><test>request_value</test></ns:text>";
    Map<String, String> headers = new HashMap<>();
    headers.put("Content-type", "text/xml;charset=UTF-8");
    headers.put("Accept-Charset", "UTF-8");
    HttpRequestUtil.doPost(new URL(getProxyServiceURLHttp("salesforce_DAMAS_writeFile")), request, headers);

    Awaitility.await().pollInterval(50, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).until(isFileExist(outfile));
    Assert.assertTrue(outfile.exists());
    Assert.assertTrue(doesFileContain(outfile, "request_value"), "Sent request body not found");
}
 
Example 3
Source Project: micro-integrator   Source File: VFSTransportTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = { "wso2.esb" }, description = "Sending a file through VFS Transport : " + "transport.vfs.FileURI = "
        + "/home/someuser/somedir " + "transport.vfs.ContentType = text/plain, "
        + "transport.vfs.FileNamePattern = *")
public void testVFSProxyFileURI_LinuxPath_SelectAll_FileNamePattern() throws Exception {

    //Related proxy : VFSProxy3
    File sourceFile = new File(pathToVfsDir + File.separator + "test.txt");
    File targetFile = new File(proxyVFSRoots.get("VFSProxy3") + File.separator + "in" + File.separator + "test.txt");
    File outfile = new File(proxyVFSRoots.get("VFSProxy3") + File.separator + "out" + File.separator + "out.txt");

    FileUtils.copyFile(sourceFile, targetFile);
    Awaitility.await().pollInterval(50, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS)
            .until(isFileExist(outfile));
    Assert.assertTrue(outfile.exists());
    Assert.assertTrue(doesFileContain(outfile,"[email protected]"));
}
 
Example 4
Source Project: product-ei   Source File: LoadBalanceEndpointTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = {"wso2.esb"}, description = "Sending a Message to a loadbalancing endpoint in Config Reg")
public void testSendingToLoaBalancingEndpoint_ConfigReg()
        throws IOException, EndpointAdminEndpointAdminException,
               LoginAuthenticationExceptionException,
               XMLStreamException {

    String response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadbalancingEndPoint_Config_Reg"),
                                                      null);
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_1"));

    response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadbalancingEndPoint_Config_Reg"),
                                               null);
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_2"));

    response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadbalancingEndPoint_Config_Reg"),
                                               null);
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_3"));

}
 
Example 5
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.ALL
})
@Test(groups = "wso2.esb", description = "<property name=\"RETRY_ON_SOAPFAULT\" value=\"true\"/>", enabled=false)
public void testRetryOnSOAPFaultWithInOutTrue() throws Exception {

    AxisServiceClient serviceClient = new AxisServiceClient();
    serviceClient.fireAndForget(clearCountRequest(), getBackEndServiceUrl(), "clearRequestCount");
    OMElement requestCount = serviceClient.sendReceive(getCountRequest(), getBackEndServiceUrl(), "getRequestCount");
    Assert.assertEquals(requestCount.getFirstElement().getText(), "0", "Request Cunt not clear");

    serviceClient.sendRobust(getThrowAxisFaultRequest(), getProxyServiceURLHttp("messageProcessorRetryOnSOAPFaultTrueTestProxy"), "throwAxisFault");
    Thread.sleep(5000);
    requestCount = serviceClient.sendReceive(getCountRequest(), getBackEndServiceUrl(), "getRequestCount");
    Assert.assertEquals(requestCount.getFirstElement().getText(), "5", "Request Count mismatched. Not sent all request");

}
 
Example 6
Source Project: product-ei   Source File: DBReportMediatorTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = "wso2.esb", description = "Insert or update DB table using message contents."
)
public void DBReportUseMessageContentTestCase() throws Exception {
    double price = 200.0;
    OMElement response;
    String priceMessageContent;
    h2DataBaseManager.executeUpdate("INSERT INTO company VALUES(100.0,'ABC')");
    h2DataBaseManager.executeUpdate("INSERT INTO company VALUES(2000.0,'XYZ')");
    h2DataBaseManager.executeUpdate("INSERT INTO company VALUES(" + price + ",'WSO2')");
    h2DataBaseManager.executeUpdate("INSERT INTO company VALUES(300.0,'MNO')");

    File synapseFile = new File(getClass().getResource("/artifacts/ESB/mediatorconfig/dbreport/" +
            "dbReportMediatorUsingMessageContentTestProxy.xml").getPath());
    addProxyService(updateSynapseConfiguration(synapseFile));
    priceMessageContent = getPrice();
    assertEquals(priceMessageContent, Double.toString(price), "Fault, invalid response");
    response = axis2Client.sendSimpleStockQuoteRequest(getProxyServiceURLHttp
            ("dbReportMediatorUsingMessageContentTestProxy"), null, "WSO2");
    priceMessageContent = getPrice();
    OMElement returnElement = response.getFirstElement();
    OMElement lastElement = returnElement.getFirstChildWithName(new QName("http://services.samples/xsd", "last"));
    assertEquals(priceMessageContent, lastElement.getText(), "Fault, invalid response");
}
 
Example 7
Source Project: product-ei   Source File: FaultyDataServiceTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test(groups = "wso2.dss", dependsOnMethods = {"serviceReDeployment"},
      description = "send requests to redeployed service")
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
public void serviceInvocation()
        throws RemoteException, ServiceAdminException, XPathExpressionException {
    OMElement response;
    String serviceEndPoint = getServiceUrlHttp(serviceName) +"/";
    AxisServiceClient axisServiceClient = new AxisServiceClient();
    for (int i = 0; i < 5; i++) {
        response = axisServiceClient.sendReceive(getPayload(), serviceEndPoint, "showAllOffices");
        Assert.assertTrue(response.toString().contains("<Office>"), "Expected Result not Found");
        Assert.assertTrue(response.toString().contains("<officeCode>"), "Expected Result not Found");
        Assert.assertTrue(response.toString().contains("<city>"), "Expected Result not Found");
        Assert.assertTrue(response.toString().contains("<phone>"), "Expected Result not Found");
        Assert.assertTrue(response.toString().contains("</Office>"), "Expected Result not Found");
    }
    log.info("service invocation success");
}
 
Example 8
Source Project: product-ei   Source File: SendIntegrationTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE
})
    @Test(groups = "wso2.esb", description = "Test sending request to Load Balancing Endpoint With the RoundRobin Algorithm BuildMessage Enabled")
    public void testSendingLoadBalancingEndpoint4() throws IOException {

        String response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint4"),
                                                          "http://localhost:9001/services/LBService1");
        Assert.assertNotNull(response);
        Assert.assertTrue(response.toString().contains("Response from server: Server_1"));

        response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint4"),
                                                   "http://localhost:9002/services/LBService1");
        Assert.assertNotNull(response);
        Assert.assertTrue(response.toString().contains("Response from server: Server_2"));

        response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint4"),
                                                   "http://localhost:9003/services/LBService1");
        Assert.assertNotNull(response);
        Assert.assertTrue(response.toString().contains("Response from server: Server_3"));

        response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint4"),
                                                   "http://localhost:9001/services/LBService1");
        Assert.assertNotNull(response);
        Assert.assertTrue(response.toString().contains("Response from server: Server_1"));

    }
 
Example 9
Source Project: product-ei   Source File: Sample62TestCase.java    License: Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = { "wso2.esb" },
      description = "Routing a Message to a Dynamic List of Recipients and Aggregating Responses")
public void testRoutingMessagesAndAggregatingResponses() throws Exception {

	OMElement response = axis2Client.sendSimpleQuoteRequest("http://localhost:8480/", null, "WSO2");
	System.out.println(response.toString());

	Assert.assertTrue(response.toString().contains("getSimpleQuoteResponse"),
	                  "GetSimpleQuoteResponse not found");
	Assert.assertTrue(response.toString().contains("WSO2 Company"), "WSO2 Company not found");

	Thread.sleep(3000);

	boolean is9001Called = isAxisServiceCalled(listener1);
	boolean is9002Called = isAxisServiceCalled(listener2);
	boolean is9003Called = isAxisServiceCalled(listener3);

	Assert.assertTrue(is9001Called, "Service 9001 not called");
	Assert.assertTrue(is9002Called, "Service 9002 not called");
	Assert.assertTrue(is9003Called, "Service 9003 not called");

	listener1.clear();
	listener2.clear();
	listener3.clear();
}
 
Example 10
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.ALL})
@Test(groups = "wso2.esb", description = "disabling auto primitive option with a given regex pattern in synapse "
                                         + "properties  ")
public void testDisablingAutoConversionToScientificNotationInJsonStreamFormatter() throws Exception {
    String payload = "<coordinates>\n"
                     + "   <location>\n"
                     + "       <name>Bermuda Triangle</name>\n"
                     + "       <n>25e1</n>\n"
                     + "       <w>7.1e1</w>\n"
                     + "   </location>\n"
                     + "   <location>\n"
                     + "       <name>Eiffel Tower</name>\n"
                     + "       <n>4.8e3</n>\n"
                     + "       <e>1.8e2</e>\n"
                     + "   </location>\n"
                     + "</coordinates>";
    HttpResponse response = httpClient.doPost(getProxyServiceURLHttp("JSONDisableAutoPrimitiveNumericTestProxy"),
            null, payload, "application/xml");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    response.getEntity().writeTo(bos);
    String actualResult = new String(bos.toByteArray());
    String expectedPayload = "{\"coordinates\":{\"location\":[{\"name\":\"Bermuda Triangle\",\"n\":\"25e1\""
                             + ",\"w\":\"7.1e1\"},{\"name\":\"Eiffel Tower\",\"n\":\"4.8e3\",\"e\":\"1.8e2\"}]}}";
    Assert.assertEquals(actualResult, expectedPayload);
}
 
Example 11
Source Project: micro-integrator   Source File: SendIntegrationTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = "wso2.esb", description = "Test sending request to Load Balancing Endpoint With the RoundRobin Algorithm Receiving Sequence Dynamic BuildMessage Enabled")
public void testSendingLoadBalancingEndpoint16() throws IOException {

    String response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint16"),
            "http://localhost:9001/services/LBService1");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_1"));

    response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint16"),
            "http://localhost:9002/services/LBService1");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_2"));

    response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint16"),
            "http://localhost:9003/services/LBService1");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_3"));

    response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint16"),
            "http://localhost:9001/services/LBService1");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_1"));

}
 
Example 12
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = { "wso2.esb" }, description = "Enrich mediator:Add as a sibling to message body")
public void addAsSiblingToMessageBody() throws Exception {
    wireMonitorServer.start();
    String payload =
            "<m:getQuote xmlns:m=\"http://services.samples\">" + "<m:request>" + "</m:request>" + "</m:getQuote>";
    OMElement payloadOM = AXIOMUtil.stringToOM(payload);
    try {
        OMElement response = axis2Client
                .sendSimpleStockQuoteRequest(getProxyServiceURLHttp("enrichAddSiblingInOutMessageTestProxy"), null,
                        payloadOM);
    } catch (Exception e) {

    }
    String wireResponse = wireMonitorServer.getCapturedMessage();
    String expectedSoapBody = "<soapenv:Body>" + "<m:symbol1 xmlns:m=\"http://services.samples\">IBM</m:symbol1>"
            + "<m:symbol2 xmlns:m=\"http://services.samples\">WSO2</m:symbol2>" + "</soapenv:Body>";
    assertTrue(wireResponse.contains(expectedSoapBody), "Invalid soap body");

}
 
Example 13
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
@Test(groups = "wso2.esb", description = "<property name=\"RETRY_ON_SOAPFAULT\" value=\"true\"/>", enabled = false)
public void testRetryOnSOAPFaultWithInOutTrue() throws Exception {

    AxisServiceClient serviceClient = new AxisServiceClient();
    serviceClient.fireAndForget(clearCountRequest(), getBackEndServiceUrl(), "clearRequestCount");
    OMElement requestCount = serviceClient
            .sendReceive(getCountRequest(), getBackEndServiceUrl(), "getRequestCount");
    Assert.assertEquals(requestCount.getFirstElement().getText(), "0", "Request Cunt not clear");

    serviceClient.sendRobust(getThrowAxisFaultRequest(),
            getProxyServiceURLHttp("messageProcessorRetryOnSOAPFaultTrueTestProxy"), "throwAxisFault");
    Thread.sleep(5000);
    requestCount = serviceClient.sendReceive(getCountRequest(), getBackEndServiceUrl(), "getRequestCount");
    Assert.assertEquals(requestCount.getFirstElement().getText(), "5",
            "Request Count mismatched. Not sent all request");

}
 
Example 14
Source Project: product-ei   Source File: CloneLargeMessageTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = "wso2.esb", description = "Tests large message ~3MB")
public void testLargeMessage() throws Exception {

    String symbol = FixedSizeSymbolGenerator.generateMessageMB(3);
    String response = client.getResponse(getProxyServiceURLHttp("CloneAndAggregateTestProxy"), symbol);
    symbol = null;
    Assert.assertNotNull(response);
    OMElement envelope = client.toOMElement(response);
    OMElement soapBody = envelope.getFirstElement();
    Iterator iterator =
            soapBody.getChildrenWithName(new QName("http://services.samples",
                                                   "getQuoteResponse"));
    int i = 0;
    while (iterator.hasNext()) {
        i++;
        OMElement getQuote = (OMElement) iterator.next();
        Assert.assertTrue(getQuote.toString().contains("WSO2"));
    }
    Assert.assertEquals(i, 2, " Aggregated message should contain two chilled element"); // Aggregated message should contain two
    // return elements from each cloned endpoint
    response = null;
}
 
Example 15
Source Project: micro-integrator   Source File: SpringMediationTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = { "wso2.esb", "localOnly" }, description = "Spring Mediator "
        + "-Added Simple bean into lib -referring to an invalid spring xml")
public void uploadSequenceHavingInvalidSpringXMLTest() throws Exception {

    loadESBConfigurationFromClasspath(
            "/artifacts/ESB/mediatorconfig/spring/spring_mediation_invalid_spring_bean.xml");
    try {
        axis2Client.sendSimpleStockQuoteRequest(getMainSequenceURL(), null, "WSO2");
        Assert.fail("Request must failed since it refers invalid spring bean");
    } catch (Exception expected) {
        assertEquals(expected.getMessage(),
                "Cannot reference application context with key : conf:/spring/invalidSpringbeammmn.xml",
                "Error Message Mismatched when referring invalid springbean in sequence");

    }
}
 
Example 16
Source Project: product-ei   Source File: DBlookupMediatorTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = "wso2.esb", description = "Test dblookup mediator with multiple SQL statements")
public void dbLookupMediatorTestMultipleStatements() throws Exception {
    h2DatabaseManager.executeUpdate("INSERT INTO company VALUES(100.0,'IBM')");
    h2DatabaseManager.executeUpdate("INSERT INTO company VALUES(2000.0,'XYZ')");
    h2DatabaseManager.executeUpdate("INSERT INTO company VALUES(" + WSO2_PRICE + ",'WSO2')");
    h2DatabaseManager.executeUpdate("INSERT INTO company VALUES(300.0,'MNO')");
    URL fileLocation = getClass().getResource("/artifacts/ESB/mediatorconfig/dblookup/" +
            "dbLookupMediatorMultipleSQLStatementsTestProxy.xml");
    String proxyContent = FileUtils.readFileToString(new File(fileLocation.toURI()));
    proxyContent = updateDatabaseInfo(proxyContent);
    addProxyService(AXIOMUtil.stringToOM(proxyContent));
    OMElement response = axis2Client.sendSimpleStockQuoteRequest(getProxyServiceURLHttp
            ("dbLookupMediatorMultipleSQLStatementsTestProxy"), null, "WSO2");
    Assert.assertTrue(response.toString().contains("WSO2"));
}
 
Example 17
Source Project: product-ei   Source File: GroovyScriptSupportTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE
})
    @Test(groups = {"wso2.esb", "localOnly"}, description = "Script Mediator -Run a Groovy script with the mediator",enabled =false)
    public void testGroovyScriptMediation() throws Exception {
        OMElement response = axis2Client.sendSimpleStockQuoteRequest(
                getProxyServiceURLHttp("scriptMediatorGroovyBasicTestProxy"), null,
                "IBM");

        String lastPrice = response.getFirstElement().getFirstChildWithName(new QName("http://services.samples/xsd", "last"))
                .getText();
        assertNotNull(lastPrice, "Fault: response message 'last' price null");

        String symbol = response.getFirstElement().getFirstChildWithName(new QName("http://services.samples/xsd", "symbol"))
                .getText();
        assertEquals(symbol, "IBM", "Fault: value 'symbol' mismatched");
    }
 
Example 18
Source Project: product-ei   Source File: InboundTransportTest.java    License: Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = { "wso2.esb" },
      dependsOnMethods = "testInboundEndpointContentTypeInvalid",
      description = "Inbound Endpoint Content type not specified Test case")
public void testInboundEndpointContentTypeNotSpecified() throws Exception {

    File sourceFile = new File(pathToFtpDir + File.separator + TEST_XML_FILE_NAME);
    File targetFolder = new File(inboundFileListeningFolder + File.separator + "in");
    File targetFile = new File(targetFolder + File.separator + "in.xml");
    try {
        FileUtils.copyFile(sourceFile, targetFile);
        addInboundEndpoint(addEndpoint7());
        Awaitility.await()
                  .pollInterval(50, TimeUnit.MILLISECONDS)
                  .atMost(60, TimeUnit.SECONDS)
                  .until(isFileNotExist(targetFile));
        Assert.assertTrue(!targetFile.exists(), "File not processed");
    } finally {
        deleteFile(targetFile);
    }
}
 
Example 19
Source Project: product-ei   Source File: SpringMediationTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE
})
    @Test(groups = {"wso2.esb", "localOnly"}, description = "Spring Mediator " +
                                                            "-Added Simple bean into lib " +
                                                            "-Different bean ids in spring xml")
    public void providingNonExistingBeanNamesTest() throws Exception {
        loadESBConfigurationFromClasspath("/artifacts/ESB/mediatorconfig/spring/spring_mediation_different_bean_id.xml");
        try {
            axis2Client.sendSimpleStockQuoteRequest
                    (getMainSequenceURL(), null, "IBM");
            fail("Request must throw a axisFault since sequence refers a non existing bean id");
        } catch (AxisFault axisFault) {
            assertEquals(axisFault.getMessage(), "No bean named 'springtestNonExisting' is defined", "Fault: Error message mismatched");
        }

    }
 
Example 20
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = {"wso2.esb"}, description = "Test for DEFAULT_REQUEST_TYPE for nhttp transport")
public void testReturnContentType() throws Exception {
    try {
        String url = getApiInvocationURL("defaultRequestContentTypeApi").concat("?symbol=wso2");
        HttpUriRequest request = new HttpPut(url);
        DefaultHttpClient client = new DefaultHttpClient();

        ((HttpPut)request).setEntity(new StringEntity("<request/>"));

        HttpResponse response = client.execute(request);
        Assert.assertNotNull(response);
        Assert.assertTrue(getResponse(response).toString().contains("WSO2"));
    } catch (IOException e) {
        log.error("Error while sending the request to the endpoint. ", e);
    }

}
 
Example 21
Source Project: product-ei   Source File: SendIntegrationTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE
})
    @Test(groups = "wso2.esb", description = "Test sending request to Load Balancing Endpoint With the RoundRobin Algorithm")
    public void testSendingLoadBalancingEndpoint2() throws IOException {

        String response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint2"),
                                                          "http://localhost:9001/services/LBService1");
        Assert.assertNotNull(response);
        Assert.assertTrue(response.toString().contains("Response from server: Server_1"));

        response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint2"),
                                                   "http://localhost:9002/services/LBService1");
        Assert.assertNotNull(response);
        Assert.assertTrue(response.toString().contains("Response from server: Server_2"));

        response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint2"),
                                                   "http://localhost:9003/services/LBService1");
        Assert.assertNotNull(response);
        Assert.assertTrue(response.toString().contains("Response from server: Server_3"));

        response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint2"),
                                                   "http://localhost:9001/services/LBService1");
        Assert.assertNotNull(response);
        Assert.assertTrue(response.toString().contains("Response from server: Server_1"));

    }
 
Example 22
/**
 * This test case checks whether an Age header is returned with the response.
 */
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = { "wso2.esb" }, description = "Testing with a large cache time out value for cache mediator")
public void testAgeHeader() throws Exception {
    String apiName = "includeAge";

    Map<String, String> headers = new HashMap<>();

    headers.put("Content-Type", "text/xml;charset=UTF-8");
    headers.put("SOAPAction", "urn:getQuote");

    //will not be a cache hit
    HttpRequestUtil.doPost(new URL(getApiInvocationURL(apiName)), messagePayload, headers);

    //will be a cache hit
    HttpResponse response2 = HttpRequestUtil.doPost(new URL(getApiInvocationURL(apiName)), messagePayload, headers);

    assertNotNull(response2.getHeaders().get("Age"), "Age header is not included");
}
 
Example 23
Source Project: micro-integrator   Source File: SendIntegrationTestCase.java    License: Apache License 2.0 5 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = "wso2.esb", description = "Test sending request to Fail Over Endpoint Receiving Sequence in Config Registry")
public void testSendingFailOverEndpoint_Receiving_Sequence_ConfigReg() throws IOException, InterruptedException {
    OMElement response = axis2Client
            .sendSimpleStockQuoteRequest(getProxyServiceURLHttp("failOverEndPoint_Receiving_Sequence_ConfigReg"),
                    null, "WSO2");
    Assert.assertTrue(response.toString().contains("WSO2 Company"));

    axis2Server1.stop();
    response = axis2Client
            .sendSimpleStockQuoteRequest(getProxyServiceURLHttp("failOverEndPoint_Receiving_Sequence_ConfigReg"),
                    null, "WSO2");
    Assert.assertTrue(response.toString().contains("WSO2 Company"));

    axis2Server1.start();
    axis2Server2.stop();

    Thread.sleep(2000);

    int counter = 0;
    while (!AxisServiceClientUtils.isServiceAvailable("http://localhost:9001/services/SimpleStockQuoteService")) {
        if (counter > 100) {
            break;
        }
        counter++;
    }

    if (counter > 100) {
        throw new AssertionError("Axis2 Server didn't started with in expected time period.");
    } else {

        response = axis2Client.sendSimpleStockQuoteRequest(
                getProxyServiceURLHttp("failOverEndPoint_Receiving_Sequence_ConfigReg"), null, "WSO2");
        Assert.assertTrue(response.toString().contains("WSO2 Company"));

    }

}
 
Example 24
Source Project: micro-integrator   Source File: SendIntegrationTestCase.java    License: Apache License 2.0 5 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = "wso2.esb", description = "Test sending request to Load Balancing Endpoint With the WeightedRoundRobin Algorithm Receiving Sequence in Conf Registry while BuildMessage Disabled")
public void testSendingLoadBalancingEndpoint5() throws IOException {

    String response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint5"),
            "http://localhost:9001/services/LBService1");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_1"));

    response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint5"),
            "http://localhost:9002/services/LBService1");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_2"));

    response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint5"),
            "http://localhost:9002/services/LBService1");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_2"));

    response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint5"),
            "http://localhost:9003/services/LBService1");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_3"));

    response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint5"),
            "http://localhost:9001/services/LBService1");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_1"));
}
 
Example 25
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = { "wso2.esb" }, description = "With Stream B&F, json format, json evaluators, incoming json, "
        + "outgoing json ")
public void incomingJsontransformJsonPayloadByArgsJsonExpressions() throws Exception {

    loadESBConfigurationFromClasspath(
            "/artifacts/ESB/mediatorconfig/payload/factory/jsonFormat_JsonExpressiosns.xml");
    postRequestWithJsonPayload(JSON_PAYLOAD, JSON_TYPE);
    assertTrue(responsePayload.contains("wso2"), "Symbol wso2 not found in response message"); // fail

}
 
Example 26
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = "wso2.esb", description = "Tests small message in small number ~100")
public void testLargeNumbers() throws Exception {
    String symbol = FixedSizeSymbolGenerator.generateMessageKB(5);
    String response;
    for (int i = 0; i < 100; i++) {
        response = client.getResponse(getProxyServiceURLHttp("CloneAndAggregateTestProxy"), symbol);
        Assert.assertNotNull(response);
        Assert.assertTrue(response.contains("WSO2"));
    }
    symbol = null;
}
 
Example 27
Source Project: micro-integrator   Source File: CollectorTypeTestCase.java    License: Apache License 2.0 5 votes vote down vote up
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = { "wso2.esb" }, description = "Creating Collector Type Mediator Test Case")
public void testCollectorTypeMediator() throws AxisFault, XPathExpressionException {
    OMElement response;
    try {
        response = axis2Client.sendSimpleStockQuoteRequest(getProxyServiceURLHttp(PROXY_NAME),
                getBackEndServiceUrl(ESBTestConstant.SIMPLE_STOCK_QUOTE_SERVICE), "WSO2");
        //            String changeValue = response.getFirstElement().getFirstChildWithName(new QName
        //                                                                                  ("http://services.samples/xsd", "change")).getText();

        response = axis2Client.sendSimpleStockQuoteRequest(getProxyServiceURLHttp(PROXY_NAME),
                getBackEndServiceUrl(ESBTestConstant.SIMPLE_STOCK_QUOTE_SERVICE), "WSO2");
        //            String change1Value = response.getFirstElement().getFirstChildWithName(new QName
        //                                                                                   ("http://services.samples/xsd", "change")).getText();

        response = axis2Client.sendSimpleStockQuoteRequest(getProxyServiceURLHttp(PROXY_NAME),
                getBackEndServiceUrl(ESBTestConstant.SIMPLE_STOCK_QUOTE_SERVICE), "WSO2");
        //            String change2Value = response.getFirstElement().getFirstChildWithName(new QName
        //                                                                                   ("http://services.samples/xsd", "change")).getText();

        /*if (changeValue.equals(change1Value)) {
            assertFalse(false, "Response caching worked even with the controller cache in 'in' sequence");
        }

        if (change1Value.equals(change2Value)) {
            assertFalse(false, "Response caching worked even with the controller cache in 'in' sequence");
        }
        if (change2Value.equals(changeValue)) {
            assertFalse(false, "Response caching worked even with the controller cache in 'in' sequence");
        }*/
        fail("Response caching worked even with the controller cache in 'in' sequence");
    } catch (AxisFault message) {
        assertEquals(message.getReason(), ESBTestConstant.INCOMING_MESSAGE_IS_NULL,
                "CacheMediator Request messages cannot be handled in a collector cache");
    }
}
 
Example 28
Source Project: micro-integrator   Source File: SendIntegrationTestCase.java    License: Apache License 2.0 5 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = "wso2.esb", description = "Test sending request to Address Endpoint Build Message Before Sending")
public void testSendingAddressEndpoint_BuildMessage() throws IOException {
    OMElement response = axis2Client
            .sendSimpleStockQuoteRequest(getProxyServiceURLHttp("addressEndPointBM"), null, "WSO2");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("WSO2 Company"));
}
 
Example 29
Source Project: product-ei   Source File: NewInstanceTestCase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Starts up the product and checks whether it can be logged in by admin successfully.
 */
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = {"mb.server.startup"})
public void waitForLoginTestCase() {
    long startTime = System.currentTimeMillis();
    boolean loginFailed = true;
    while (((System.currentTimeMillis() - startTime) < TIMEOUT) && loginFailed) {
        log.info("Waiting to login user...");
        try {
            LoginLogoutClient loginClient = new LoginLogoutClient("https://localhost:9445/services/", "admin",
                    "admin");
            loginClient.login();
            loginFailed = false;
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.info("Login failed after server startup", e);
            }
            try {
                Thread.sleep(2000);
            } catch (InterruptedException ignored) {
                // Nothing to do
            }
        }
    }

    Assert.assertFalse(loginFailed);

}
 
Example 30
Source Project: product-ei   Source File: VFSTransportTestCase.java    License: Apache License 2.0 5 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = {"wso2.esb"}, description = "Sending a file through VFS Transport : " +
                                           "transport.vfs.FileURI = Linux Path, " +
                                           "transport.vfs.ContentType = text/xml, " +
                                           "transport.vfs.FileNamePattern = - *\\.xml " +
                                           "transport.vfs.ActionAfterFailure=DELETE")
public void testVFSProxyActionAfterFailure_DELETE()
        throws Exception {

    addVFSProxy13();

    File sourceFile = new File(pathToVfsDir + File.separator + "fail.xml");
    File targetFile = new File(pathToVfsDir + "test" + File.separator + "in" + File.separator + "fail.xml");
    try {
        FileUtils.copyFile(sourceFile, targetFile);
        Thread.sleep(2000);

        File outfile = new File(pathToVfsDir + "test" + File.separator + "out" + File.separator + "out.xml");
        Assert.assertTrue(!outfile.exists());

        File originalFile = new File(pathToVfsDir + "test" + File.separator + "failure" + File.separator + "fail.xml");

        Assert.assertTrue(!originalFile.exists());
        Assert.assertFalse(new File(pathToVfsDir + "test" + File.separator + "in" + File.separator +
                                    "fail.xml.lock").exists(), "lock file exists even after moving the failed file");
    } finally {
        deleteFile(targetFile);
        removeProxy("VFSProxy13");
    }
}