/*
 * (C) Copyright 2016 Boni Garcia (http://bonigarcia.github.io/)
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 */
package io.bonigarcia.webrtc;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
import org.kurento.client.MediaPipeline;
import org.kurento.client.WebRtcEndpoint;
import org.kurento.test.base.FunctionalTest;
import org.kurento.test.browser.Browser;
import org.kurento.test.browser.BrowserType;
import org.kurento.test.browser.WebPageType;
import org.kurento.test.browser.WebRtcChannel;
import org.kurento.test.browser.WebRtcMode;
import org.kurento.test.browser.WebRtcTestPage;
import org.kurento.test.config.BrowserConfig;
import org.kurento.test.config.BrowserScope;
import org.kurento.test.config.TestScenario;
import org.kurento.test.latency.VideoTagType;

public class WebRtcOne2OneTest extends FunctionalTest {

  private static final int PLAYTIME = 10; // seconds to play in WebRTC

  @Parameters(name = "{index}: {0}")
  public static Collection<Object[]> data() {
    // Test: Chrome in local (presenter and viewer)
    TestScenario test = new TestScenario();
    test.addBrowser(BrowserConfig.PRESENTER, new Browser.Builder().webPageType(WebPageType.WEBRTC)
        .browserType(BrowserType.CHROME).scope(BrowserScope.LOCAL).build());
    test.addBrowser(BrowserConfig.VIEWER, new Browser.Builder().webPageType(WebPageType.WEBRTC)
        .browserType(BrowserType.CHROME).scope(BrowserScope.LOCAL).build());
    return Arrays.asList(new Object[][] { { test } });
  }

  @Test
  public void tesOne2One() throws Exception {
    // Media pipeline
    MediaPipeline mp = kurentoClient.createMediaPipeline();
    WebRtcEndpoint masterWebRtcEp = new WebRtcEndpoint.Builder(mp).build();
    WebRtcEndpoint viewerWebRtcEP = new WebRtcEndpoint.Builder(mp).build();
    masterWebRtcEp.connect(viewerWebRtcEP);

    // Sync presenter and viewer time
    WebRtcTestPage[] browsers = { getPresenter(), getViewer() };
    String[] videoTags = { VideoTagType.LOCAL.getId(), VideoTagType.REMOTE.getId() };
    String[] peerConnections = { "webRtcPeer.peerConnection", "webRtcPeer.peerConnection" };
    syncTimeForOcr(browsers, videoTags, peerConnections);

    // Subscribe to playing event (presenter/viewer)
    getPresenter().subscribeLocalEvents("playing");
    getPresenter().initWebRtc(masterWebRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_ONLY);

    getViewer().subscribeEvents("playing");
    getViewer().initWebRtc(viewerWebRtcEP, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY);

    getPresenter().waitForEvent("playing");
    getViewer().waitForEvent("playing");

    // Start OCR
    getPresenter().startOcr();
    getViewer().startOcr();

    // Guard time to play the video
    waitSeconds(PLAYTIME);

    // Get OCR results and stas
    Map<String, String> presenterOcr = getPresenter().getOcr();
    Map<String, String> viewerOcr = getViewer().getOcr();

    List<Map<String, String>> presenterStats = getPresenter().getStatsList();
    List<Map<String, String>> viewerStats = getViewer().getStatsList();

    // Finish OCR, close browser, release media pipeline
    getPresenter().endOcr();
    getViewer().endOcr();

    getPresenter().close();
    getViewer().close();

    mp.release();

    // Process data and write CSV
    processOcrDataToCsv(this.getClass().getSimpleName() + ".csv", presenterOcr, viewerOcr,
        presenterStats, viewerStats);
  }

}

@@ -1479,43 +1479,18 @@
 TIME
+_SEC
  = 10;
- // seconds to play in WebRTC
 %0A%0A  
@@ -1574,60 +1574,8 @@
 ) %7B%0A
-    // Test: Chrome in local (presenter and viewer)%0A
     
@@ -2178,19 +2178,22 @@
 ndpoint 
-mas
+presen
 terWebRt
@@ -2318,19 +2318,22 @@
 ();%0A    
-mas
+presen
 terWebRt
@@ -2842,11 +2842,14 @@
 Rtc(
-mas
+presen
 terW
@@ -2879,32 +2879,40 @@
 AUDIO_AND_VIDEO,
+%0A       
  WebRtcMode.SEND
@@ -2915,25 +2915,24 @@
 SEND_ONLY);%0A
-%0A
     getViewe
@@ -3059,17 +3059,16 @@
 _ONLY);%0A
-%0A
     getP
@@ -3233,30 +3233,12 @@
  // 
-Guard time to play the
+Play
  vid
@@ -3264,16 +3264,20 @@
 PLAYTIME
+_SEC
 );%0A%0A    
@@ -3302,16 +3302,22 @@
  and sta
+tistic
 s%0A    Ma
@@ -3428,25 +3428,24 @@
 ).getOcr();%0A
-%0A
     List%3CMap
@@ -3691,25 +3691,24 @@
 ).endOcr();%0A
-%0A
     getPrese
@@ -3744,25 +3744,24 @@
 ().close();%0A
-%0A
     mp.relea

Refactor one to one test