     
     private var client: StompClient!
     private var socket: WebSocket!
-    private let host = "http://10.1.20.28:8080"
+    private var jSession: String!
+    private let baseURL = NSURL(string: "http://10.1.20.25:9090")!
+    private let accoutId = "laphone"
     
     override func setUp() {
         super.setUp()
         
-        let url = NSURL(string: host + "/traderdesktop")!.appendServerIdAndSessionId()
+        logIn()
+        
+        let url = baseURL.URLByAppendingPathComponent("/traderdesktop").appendServerIdAndSessionId()
         socket = WebSocket(url: url)
+        socket.headers["Cookie"] = jSession
         client = StompClient(socket: socket)
+        
     }
     
     override func tearDown() {
         super.tearDown()
+        
+        logOut()
     }
     
     // MARK: - Disabled Tests
-    func disable_testSubscribeAccountPNL() {
+    func testSubscribeAccountPNL() {
         let delegate = AccountPNLDelegate()
         delegate.expectation = expectationWithDescription("Subscribe account pnl")
         client.delegate = delegate
-
+        
+        client.connect()
+     
+        waitForExpectationsWithTimeout(5.0, handler: nil)
+    }
+    
+    func testSubscribeMarginUsage() {
+        let delegate = MarginUsageDelegate()
+        delegate.expectation = expectationWithDescription("Subscribe margin usage")
+        client.delegate = delegate
+        
+        client.connect()
+        
+        waitForExpectationsWithTimeout(5.0, handler: nil)
+    }
+    
+    func testSubscribeModelInfo() {
+        let delegate = ModelInfoDelegate()
+        delegate.expectation = expectationWithDescription("Subscribe model info")
+        client.delegate = delegate
+        
+        client.connect()
+        
+        waitForExpectationsWithTimeout(5.0, handler: nil)
+    }
+    
+    func testSubscribeModelPNL() {
+        let delegate = ModelPNLDelegate()
+        delegate.expectation = expectationWithDescription("Subscribe model PNL")
+        client.delegate = delegate
+        
+        client.connect()
+        
+        waitForExpectationsWithTimeout(5.0, handler: nil)
+    }
+    
+    func testSubscribeBlotter() {
+        let delegate = BlotterDelegate()
+        delegate.expectation = expectationWithDescription("Subscribe blotter")
+        client.delegate = delegate
+        
+        client.connect()
+        
+        waitForExpectationsWithTimeout(5.0, handler: nil)
+    }
+    
+    func testSubscribeSymbolsPrice() {
+        let delegate = SymbolsPriceDelegate()
+        delegate.expectation = expectationWithDescription("Subscribe symbols price")
+        client.delegate = delegate
+        
+        client.connect()
+        
+        waitForExpectationsWithTimeout(5.0, handler: nil)
+    }
+    
+    // MARK: - Private Methods
+    private func logIn() {
+        let expectation = expectationWithDescription("Log in")
+        
         let session = NSURLSession.sharedSession()
-        let loginURLString = host + "/trader/desktop/auth/login"
-        let request = NSMutableURLRequest(URL: NSURL(string: loginURLString)!)
+        let url = baseURL.URLByAppendingPathComponent("/trader/desktop/auth/login")
+        let request = NSMutableURLRequest(URL: url)
         request.HTTPMethod = "POST"
         request.addValue("application/json", forHTTPHeaderField: "Content-Type")
-        
-        let param = ["id" : "laphone", "pass" : "laphone"]
+        let param = ["id" : accoutId, "pass" : "laphone"]
         let data = try! NSJSONSerialization.dataWithJSONObject(param, options: NSJSONWritingOptions(rawValue: 0))
         request.HTTPBody = data
         

class AccountPNLDelegate: NSObject, StompClientDelegate {
    
    // MARK: - Public Properties
    var expectation: XCTestExpectation!
    
    // MARK: - Private Properties
    private let destination = "/account/accountpnl/laphone"
    
    // MARK: - Stomp Client Delegate
    func stompClientDidConnected(client: StompClient) {
        client.subscribe(destination, parameters: nil)
    }
    
    func stompClient(client: StompClient, didErrorOccurred error: NSError) {
        XCTAssertTrue(false, "Error: \(error.localizedDescription)")
        expectation.fulfill()
    }
    
    func stompClient(client: StompClient, didReceivedData data: NSData) {
        let json = try! NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments)
        XCTAssertEqual(json["accountId"], "laphone", "Account Id is wrong.")
        
        client.unsubscribe(destination)
        
        XCTAssertNotNil(expectation, "Expectation doesn't setup.")
        expectation.fulfill()
    }
    
}

                let cookie = cookies.filter({
                    $0.name == "JSESSIONID"
                }).first!
                self.jSession = cookie.name + "=" + cookie.value
            } else {
                XCTAssert(false, "Status code isn't 200. Login failed.")
            }
            
            expectation.fulfill()
        }
        task.resume()
        
        waitForExpectationsWithTimeout(5.0, handler: nil)
    }
    
    private func logOut() {
        let expectation = expectationWithDescription("Log out")
        
        let session = NSURLSession.sharedSession()
        let url = baseURL.URLByAppendingPathComponent("/trader/desktop/auth/logout")
        let request = NSMutableURLRequest(URL: url)
        request.HTTPMethod = "POST"
        
        let task = session.dataTaskWithRequest(request) { (data, response, error) in
            let res = response as! NSHTTPURLResponse
            if res.statusCode != 200 {
                XCTAssert(false, "Status code isn't 200. Logout failed.")
            }
            
            expectation.fulfill()
        }
        task.resume()
        
        waitForExpectationsWithTimeout(5.0, handler: nil)
    }
    
    // MARK: - Disabled Tests
    func disbale_testSubscribeTopicLog() {
        let delegate = TopicLogDelegate()
        delegate.expectation = expectationWithDescription("Subscribe topci log")
        client.delegate = delegate
        
        client.connect()
        
        waitForExpectationsWithTimeout(5.0, handler: nil)
    }
    
    func disable_testSubscribeSystemInfo() {
        let delegate = SystemInfoDelegate()
        delegate.expectation = expectationWithDescription("Subscribe system info")
        client.delegate = delegate
        
        client.connect()
        
        waitForExpectationsWithTimeout(5.0, handler: nil)
    }
    
}
