/*
 * (C) Copyright 2014 Kurento (http://kurento.org/)
 *
 * 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 org.kurento.test.sanity;

import static org.kurento.commons.PropertiesManager.getProperty;
import static org.kurento.test.config.TestConfiguration.BOWER_KURENTO_CLIENT_TAG_DEFAULT;
import static org.kurento.test.config.TestConfiguration.BOWER_KURENTO_CLIENT_TAG_PROP;
import static org.kurento.test.config.TestConfiguration.BOWER_KURENTO_UTILS_TAG_DEFAULT;
import static org.kurento.test.config.TestConfiguration.BOWER_KURENTO_UTILS_TAG_PROP;

import java.io.File;
import java.io.IOException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kurento.test.utils.Shell;
import org.springframework.core.io.ClassPathResource;

/**
 * Sanity test for kurento-js releases with Bower.
 * 
 * @author Boni Garcia (bgarcia@gsyc.es)
 * @since 4.2.5
 */
public class KurentoJsBowerTest extends KurentoJsBase {

	public KurentoJsBowerTest() {
		kurentoUrl = "./";
	}

	@BeforeClass
	public static void runBower() throws IOException {
		String bowerClientTag = getProperty(BOWER_KURENTO_CLIENT_TAG_PROP,
				BOWER_KURENTO_CLIENT_TAG_DEFAULT);
		String bowerUtilsTag = getProperty(BOWER_KURENTO_UTILS_TAG_PROP,
				BOWER_KURENTO_UTILS_TAG_DEFAULT);
		if (!bowerClientTag.isEmpty()) {
			bowerClientTag = "#" + bowerClientTag;
		}
		if (!bowerUtilsTag.isEmpty()) {
			bowerUtilsTag = "#" + bowerUtilsTag;
		}

		log.debug("Using bower to download kurento-client" + bowerClientTag
				+ "\n" + Shell.runAndWait("sh", "-c",
						"bower install kurento-client" + bowerClientTag));
		log.debug("Using bower to download kurento-utils" + bowerUtilsTag + "\n"
				+ Shell.runAndWait("sh", "-c",
						"bower install kurento-utils" + bowerUtilsTag));

		final String outputFolder = new ClassPathResource("static").getFile()
				.getAbsolutePath() + File.separator;

		log.debug("Copying files from bower_components/kurento-utils/js to "
				+ outputFolder
				+ Shell.runAndWait("sh", "-c",
						"cp -r bower_components/kurento-utils/js "
								+ outputFolder));
		log.debug("Copying files from bower_components/kurento-client/js to "
				+ outputFolder
				+ Shell.runAndWait("sh", "-c",
						"cp -r bower_components/kurento-client/js "
								+ outputFolder));
	}

	@AfterClass
	public static void rmBower() {
		Shell.runAndWait("sh", "-c", "rm -rf bower_components");
	}

	@Test
	public void kurentoJsBowerTest() {
		doTest();
	}

}

@@ -1936,32 +1936,37 @@
 %09%7D%0A%0A%09%09log.debug(
+%0A%09%09%09%09
 %22Using bower to 
@@ -2010,20 +2010,22 @@
 tTag
-%0A%09%09%09%09
+ 
 + %22%5Cn%22
- 
+%0A%09%09%09%09%09%09
 + Sh
@@ -2049,32 +2049,34 @@
 h%22, %22-c%22,%0A%09%09%09%09%09%09
+%09%09
 %22bower install k
@@ -2066,32 +2066,45 @@
 %09%22bower install 
+--allow-root 
 kurento-client%22 
@@ -2094,33 +2094,43 @@
  kurento-client%22
- 
+%0A%09%09%09%09%09%09%09%09%09%09
 + bowerClientTag
@@ -2264,16 +2264,29 @@
 install 
+--allow-root 
 kurento-
@@ -2283,33 +2283,41 @@
 t kurento-utils%22
- 
+%0A%09%09%09%09%09%09%09%09
 + bowerUtilsTag)

Include --allow-root parameter in bower install