/**
 * Copyright (c) 2016 NumberFour AG.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   NumberFour AG - Initial API and implementation
 */
package org.eclipse.n4js.hlc.tests;

import static java.util.Collections.singletonMap;
import static org.eclipse.n4js.hlc.tests.IncompleteApiImplementationTest.runCaptureOut;
import static org.eclipse.n4js.runner.SystemLoaderInfo.COMMON_JS;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import org.eclipse.n4js.hlc.base.BuildType;
import org.eclipse.n4js.hlc.base.ExitCodeException;
import org.eclipse.n4js.utils.io.FileDeleter;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * Downloads, installs, compiles and runs 'express' where target platform file specifies version range.
 */
public class TargetPlatformRangeConfigurationsTest extends BaseN4jscExternalTest {
	File workspace;

	/** Prepare workspace. */
	@Before
	public void setupWorkspace() throws IOException {
		workspace = setupWorkspace("external");
	}

	/** Delete workspace. */
	@After
	public void deleteWorkspace() throws IOException {
		FileDeleter.delete(workspace.toPath(), true);
	}

	@Override
	protected Map<String, String> getNpmDependencies() {
		return singletonMap("express", "@\">=4.0.0 <5.0.0\"");
	}

	/**
	 * Test for compiling project with external dependency specified within version range.
	 */
	@Test
	public void testCompileAndRunWithExternalDependencies() throws IOException, ExitCodeException {
		final String wsRoot = workspace.getAbsolutePath().toString();
		final String fileToRun = wsRoot + "/external.project/src/Main.n4js";

		final String[] args = {
				"--systemLoader", COMMON_JS.getId(),
				"--targetPlatformFile", getTargetPlatformFile().getAbsolutePath(),
				"--targetPlatformInstallLocation", getTargetPlatformInstallLocation().getAbsolutePath(),
				"-rw", "nodejs",
				"-r", fileToRun,
				"--verbose",
				"--projectlocations", wsRoot,
				"-t", BuildType.allprojects.toString()
		};
		final String out = runCaptureOut(args);
		N4CliHelper.assertExpectedOutput(
				"express properties: application, request, response, Route, Router, query, static", out);
	}
}

@@ -1484,11 +1484,12 @@
 .0 %3C
-5.0
+4.16
 .0%5C%22
@@ -2254,135 +2254,520 @@
 ;%0A%09%09
-N4CliHelper.assertExpectedOutput(%0A%09%09%09%09%22express properties: application, request, response, Route, Router, query, static%22, out);
+// note: express version 4.16.0 introduced more properties, so by checking for the following properties we can%0A%09%09// assert that the version range %22%3E=4.0.0 %3C4.16.0%22 specified above was taken into account during installation:%0A%09%09N4CliHelper.assertExpectedOutput(%0A%09%09%09%09%22express properties: application, request, response, Route, Router, query, static%22, out);%0A%09%09// express version 4.16.0 or 4.16.1 would give us:%0A%09%09// %22express properties: application, request, response, Route, Router, json, query, static, urlencoded%22
 %0A%09%7D%0A

Fix test TargetPlatformRangeConfigurationsTest (#256)