/*
*Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
*WSO2 Inc. 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.wso2.carbon.esb.websocket.inbound.transport.test;

import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.esb.websocket.client.WebSocketTestClient;
import org.wso2.carbon.esb.websocket.server.WebSocketServer;
import org.wso2.esb.integration.common.utils.ESBIntegrationTest;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class WebSocketInboundTestCase extends ESBIntegrationTest {

    private WebSocketServer webSocketServer;
    private WebSocketTestClient webSocketTestClient;

    @BeforeClass(alwaysRun = true)
    public void setEnvironment() throws Exception {
        webSocketServer = new WebSocketServer(7474);
        webSocketServer.run();
        super.init();
        loadESBConfigurationFromClasspath("/artifacts/ESB/websocket/synapse-websocket-inbound.xml");
    }

    @Test(groups = "wso2.esb",
          description = "Web Socket transport test", timeOut = 60000)
    public void webSocketInboundTest() throws Exception {
        int latchCountDownInSecs = 30;
        CountDownLatch latch = new CountDownLatch(1);
        webSocketTestClient = new WebSocketTestClient("ws://localhost:9091/", latch);
        webSocketTestClient.handhshake();
        String text = "{message:\"hello web socket test\"}";
        webSocketTestClient.sendText(text);
        latch.await(latchCountDownInSecs, TimeUnit.SECONDS);
        Assert.assertEquals(webSocketTestClient.getTextReceived(), text);
    }

    @AfterClass(alwaysRun = true)
    public void destroy() throws Exception {
        try {
            if (webSocketTestClient != null) {
                webSocketTestClient.shutDown();
            }
        } catch (InterruptedException e) {
            log.error("Error while closing the Web Socket Client");
            //ignore
        }
        try {
            super.cleanup();
        } finally {
            if (webSocketServer != null) {
                webSocketServer.stop();
            }
        }

    }
}

@@ -1,12 +1,15 @@
 /*%0A
-*
+ *  
 Copyrigh
@@ -20,15 +20,10 @@
 ) 20
-05-2010
+17
 , WS
@@ -73,19 +73,23 @@
 served.%0A
+ 
 *%0A
-*
+ *  
 WSO2 Inc
@@ -142,17 +142,20 @@
 icense,%0A
-*
+ *  
 Version 
@@ -208,17 +208,20 @@
  except%0A
-*
+ *  
 in compl
@@ -244,17 +244,20 @@
 icense.%0A
-*
+ *  
 You may 
@@ -288,19 +288,23 @@
 ense at%0A
+ 
 *%0A
-*
+ *  
 http://w
@@ -342,11 +342,15 @@
 2.0%0A
+ 
 *%0A
-*
+ *  
 Unle
@@ -404,17 +404,20 @@
 riting,%0A
-*
+ *  
 software
@@ -468,17 +468,20 @@
 d on an%0A
-*
+ *  
 %22AS IS%22 
@@ -527,17 +527,20 @@
  OF ANY%0A
-*
+ *  
 KIND, ei
@@ -589,17 +589,20 @@
 for the%0A
-*
+ *  
 specific
@@ -649,17 +649,20 @@
 tations%0A
-*
+ *  
 under th
@@ -672,16 +672,20 @@
 icense.%0A
+ *%0A 
 */%0Apacka

update license header