package org.graalvm.component.installer.commands;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import org.graalvm.component.installer.BundleConstants;
import org.graalvm.component.installer.CommandTestBase;
import org.graalvm.component.installer.Commands;
import org.graalvm.component.installer.DownloadURLIterable;
import org.graalvm.component.installer.Version;
import org.graalvm.component.installer.model.CatalogContents;
import org.graalvm.component.installer.model.ComponentInfo;
import org.graalvm.component.installer.persist.ProxyResource;
import org.graalvm.component.installer.remote.CatalogIterable;
import org.graalvm.component.installer.remote.RemoteCatalogDownloader;
import static org.junit.Assert.assertEquals;
import org.junit.Rule;
import org.junit.Test;
public class InfoTest extends CommandTestBase {
@Rule public final ProxyResource proxyResource = new ProxyResource();
private Version initVersion(String s) throws IOException {
Version v = Version.fromString(s);
storage.graalInfo.put(BundleConstants.GRAAL_VERSION, v.toString());
Path catalogPath = dataFile("../repo/catalog.properties");
RemoteCatalogDownloader downloader = new RemoteCatalogDownloader(
this,
this,
catalogPath.toUri().toURL());
registry = new CatalogContents(this, downloader.getStorage(), localRegistry);
paramIterable = new CatalogIterable(this, this);
return v;
}
@Test
public void testInfoLocalComponent() throws Exception {
Path p = dataFile("truffleruby2.jar");
textParams.add(p.toString());
p = dataFile("../repo/python/1.0.0.0");
textParams.add(p.toString());
InfoCommand cmd = new InfoCommand();
cmd.init(this, this.withBundle(InfoCommand.class));
cmd.collectComponents();
List<ComponentInfo> comps = cmd.getComponents();
assertEquals(2, comps.size());
ComponentInfo ruby = comps.get(0);
assertEquals("org.graalvm.ruby", ruby.getId());
ruby.getVersion().toString();
assertEquals("1.0", ruby.getVersion().originalString());
ComponentInfo python = comps.get(1);
assertEquals("org.graalvm.python", python.getId());
assertEquals("1.0.0.0", python.getVersion().originalString());
}
@Test
public void testInfoDownloadedComponent() throws Exception {
Path p = dataFile("truffleruby2.jar");
options.put(Commands.OPTION_URLS, "");
textParams.add(p.toUri().toString());
paramIterable = new DownloadURLIterable(this, this);
InfoCommand cmd = new InfoCommand();
cmd.init(this, this.withBundle(InfoCommand.class));
cmd.collectComponents();
List<ComponentInfo> comps = cmd.getComponents();
assertEquals(1, comps.size());
ComponentInfo ruby = comps.get(0);
assertEquals("org.graalvm.ruby", ruby.getId());
ruby.getVersion().toString();
assertEquals("1.0", ruby.getVersion().originalString());
}
@Test
public void testInfoCompatibleComponents() throws Exception {
initVersion("1.0.0");
textParams.add("ruby");
textParams.add("python");
InfoCommand cmd = new InfoCommand();
cmd.init(this, this.withBundle(InfoCommand.class));
cmd.collectComponents();
List<ComponentInfo> comps = cmd.getComponents();
assertEquals(2, comps.size());
}
@Test
public void testIncompatibleComponentInfo() throws Exception {
initVersion("1.0.0");
textParams.add("r");
InfoCommand cmd = new InfoCommand();
cmd.init(this, this.withBundle(InfoCommand.class));
cmd.collectComponents();
List<ComponentInfo> comps = cmd.getComponents();
assertEquals(1, comps.size());
}
@Test
public void testSpecificVersionInfo() throws Exception {
initVersion("1.0.0");
textParams.add("ruby=1.0.1.1");
InfoCommand cmd = new InfoCommand();
cmd.init(this, this.withBundle(InfoCommand.class));
cmd.collectComponents();
List<ComponentInfo> comps = cmd.getComponents();
assertEquals(1, comps.size());
}
}