Search in sources :

Example 1 with TestExtension

use of org.xwiki.repository.test.TestExtension in project xwiki-platform by xwiki.

the class RepositoryTest method testRestAccessToImportedExtension.

private void testRestAccessToImportedExtension() throws Exception {
    // 2.0
    TestExtension emptyExtension = getRepositoryTestUtils().getTestExtension(new ExtensionId("emptyjar", "1.0"), "jar");
    long fileSize = FileUtils.sizeOf(emptyExtension.getFile().getFile());
    ExtensionVersion extension = getUtil().rest().getResource(Resources.EXTENSION_VERSION, null, "maven:extension", "2.0");
    Assert.assertEquals("maven:extension", extension.getId());
    Assert.assertEquals("jar", extension.getType());
    Assert.assertEquals("2.0", extension.getVersion());
    Assert.assertEquals("name", extension.getName());
    Assert.assertEquals("summary2", extension.getSummary());
    Assert.assertEquals("summary2\n      some more details", extension.getDescription());
    Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
    Assert.assertEquals(Arrays.asList("maven:oldextension", "maven:oldversionnedextension"), extension.getFeatures());
    Assert.assertEquals("maven:oldextension", extension.getExtensionFeatures().get(0).getId());
    Assert.assertEquals("2.0", extension.getExtensionFeatures().get(0).getVersion());
    Assert.assertEquals("maven:oldversionnedextension", extension.getExtensionFeatures().get(1).getId());
    Assert.assertEquals("10.0", extension.getExtensionFeatures().get(1).getVersion());
    Assert.assertEquals("GNU Lesser General Public License 2.1", extension.getLicenses().get(0).getName());
    Assert.assertEquals(fileSize, getUtil().rest().getBuffer(Resources.EXTENSION_VERSION_FILE, null, "maven:extension", "2.0").length);
    // 1.0
    extension = getUtil().rest().getResource(Resources.EXTENSION_VERSION, null, "maven:extension", "1.0");
    Assert.assertEquals("maven:extension", extension.getId());
    Assert.assertEquals("jar", extension.getType());
    Assert.assertEquals("1.0", extension.getVersion());
    Assert.assertEquals("name", extension.getName());
    Assert.assertEquals("summary2", extension.getSummary());
    Assert.assertEquals("summary2\n      some more details", extension.getDescription());
    Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
    Assert.assertEquals(Arrays.asList("maven:oldextension", "maven:oldversionnedextension"), extension.getFeatures());
    Assert.assertEquals("maven:oldextension", extension.getExtensionFeatures().get(0).getId());
    Assert.assertEquals("1.0", extension.getExtensionFeatures().get(0).getVersion());
    Assert.assertEquals("maven:oldversionnedextension", extension.getExtensionFeatures().get(1).getId());
    Assert.assertEquals("10.0", extension.getExtensionFeatures().get(1).getVersion());
    Assert.assertEquals("GNU Lesser General Public License 2.1", extension.getLicenses().get(0).getName());
    Assert.assertEquals(FileUtils.sizeOf(emptyExtension.getFile().getFile()), getUtil().rest().getBuffer(Resources.EXTENSION_VERSION_FILE, null, "maven:extension", "1.0").length);
    // 0.9
    extension = getUtil().rest().getResource(Resources.EXTENSION_VERSION, null, "maven:extension", "0.9");
    Assert.assertEquals("maven:extension", extension.getId());
    Assert.assertEquals("jar", extension.getType());
    Assert.assertEquals("0.9", extension.getVersion());
    Assert.assertEquals("name", extension.getName());
    Assert.assertEquals("summary2", extension.getSummary());
    Assert.assertEquals("summary2\n      some more details", extension.getDescription());
    Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
    Assert.assertEquals(Arrays.asList(), extension.getFeatures());
    Assert.assertEquals(Arrays.asList(), extension.getExtensionFeatures());
    Assert.assertEquals("GNU Lesser General Public License 2.1", extension.getLicenses().get(0).getName());
    Assert.assertEquals(fileSize, getUtil().rest().getBuffer(Resources.EXTENSION_VERSION_FILE, null, "maven:extension", "0.9").length);
}
Also used : TestExtension(org.xwiki.repository.test.TestExtension) ExtensionId(org.xwiki.extension.ExtensionId) ExtensionVersion(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionVersion)

Example 2 with TestExtension

use of org.xwiki.repository.test.TestExtension in project xwiki-platform by xwiki.

the class ExtensionIT method testDowngrade.

/**
 * Tests how an extension is downgraded.
 */
@Test
public void testDowngrade() throws Exception {
    // Setup the extension.
    String extensionId = "alice-xar-extension";
    String oldVersion = "1.3";
    String newVersion = "2.1.4";
    TestExtension oldExtension = getRepositoryTestUtils().getTestExtension(new ExtensionId(extensionId, oldVersion), "xar");
    getRepositoryTestUtils().addExtension(oldExtension);
    TestExtension newExtension = getRepositoryTestUtils().getTestExtension(new ExtensionId(extensionId, newVersion), "xar");
    getRepositoryTestUtils().attachFile(newExtension);
    getRepositoryTestUtils().addVersionObject(newExtension, newVersion, "attach:" + newExtension.getFile().getName());
    // Make sure the new version is installed.
    getExtensionTestUtils().install(new ExtensionId(extensionId, newVersion));
    // Downgrade the extension.
    ExtensionAdministrationPage adminPage = ExtensionAdministrationPage.gotoPage();
    ExtensionPane extensionPane = adminPage.getSearchBar().clickAdvancedSearch().search(extensionId, oldVersion).getExtension(0);
    assertEquals("remote-installed", extensionPane.getStatus());
    assertEquals("Version 2.1.4 is installed", extensionPane.getStatusMessage());
    extensionPane = extensionPane.downgrade();
    // Check the downgrade plan.
    List<DependencyPane> downgradePlan = extensionPane.openProgressSection().getJobPlan();
    assertEquals(1, downgradePlan.size());
    assertEquals(extensionId, downgradePlan.get(0).getName());
    assertEquals(oldVersion, downgradePlan.get(0).getVersion());
    assertEquals("remote-installed", downgradePlan.get(0).getStatus());
    assertEquals("Version 2.1.4 is installed", downgradePlan.get(0).getStatusMessage());
    // Finish the downgrade and check the downgrade log.
    extensionPane = extensionPane.confirm();
    assertEquals("installed", extensionPane.getStatus());
    assertEquals("Installed", extensionPane.getStatusMessage());
    List<LogItemPane> log = extensionPane.openProgressSection().getJobLog();
    assertTrue(log.size() > 2);
    assertEquals("info", log.get(2).getLevel());
    assertEquals("Resolving extension [alice-xar-extension 1.3] on namespace [Home]", log.get(2).getMessage());
    assertEquals("info", log.get(log.size() - 1).getLevel());
    assertEquals("Finished job of type [install] with identifier " + "[extension/action/alice-xar-extension/wiki:xwiki]", log.get(log.size() - 1).getMessage());
    // Assert the changes.
    ViewPage viewPage = getUtil().gotoPage("ExtensionTest", "Alice");
    assertEquals("Alice Macro", viewPage.getDocumentTitle());
    assertTrue(viewPage.getContent().contains("Alice says hello!"));
}
Also used : LogItemPane(org.xwiki.extension.test.po.LogItemPane) ExtensionAdministrationPage(org.xwiki.extension.test.po.ExtensionAdministrationPage) DependencyPane(org.xwiki.extension.test.po.DependencyPane) TestExtension(org.xwiki.repository.test.TestExtension) ExtensionId(org.xwiki.extension.ExtensionId) ViewPage(org.xwiki.test.ui.po.ViewPage) ExtensionPane(org.xwiki.extension.test.po.ExtensionPane) Test(org.junit.Test)

Example 3 with TestExtension

use of org.xwiki.repository.test.TestExtension in project xwiki-platform by xwiki.

the class ExtensionIT method testDependencies.

/**
 * Tests how extension dependencies are displayed (both direct and backward dependencies).
 */
@Test
public void testDependencies() throws Exception {
    // Setup the extension and its dependencies.
    ExtensionId dependencyId = new ExtensionId("bob-xar-extension", "2.5-milestone-2");
    TestExtension dependency = getRepositoryTestUtils().getTestExtension(dependencyId, "xar");
    dependency.setName("Bob Wiki Macro");
    dependency.setSummary("Required by Alice");
    getRepositoryTestUtils().addExtension(dependency);
    ExtensionId extensionId = new ExtensionId("alice-xar-extension", "1.3");
    TestExtension extension = getRepositoryTestUtils().getTestExtension(extensionId, "xar");
    extension.addDependency(new DefaultExtensionDependency(dependencyId.getId(), new DefaultVersionConstraint(dependencyId.getVersion().getValue())));
    extension.addDependency(new DefaultExtensionDependency("missing-dependency", new DefaultVersionConstraint("135")));
    extension.addDependency(new DefaultExtensionDependency("org.xwiki.platform:xwiki-platform-sheet-api", new DefaultVersionConstraint("[3.2,)")));
    extension.addDependency(new DefaultExtensionDependency("org.xwiki.commons:xwiki-commons-diff-api", new DefaultVersionConstraint("2.7")));
    extension.addDependency(new DefaultExtensionDependency("org.xwiki.platform:xwiki-platform-display-api", new DefaultVersionConstraint("100.1")));
    getRepositoryTestUtils().addExtension(extension);
    // Search the extension and assert the list of dependencies.
    ExtensionAdministrationPage adminPage = ExtensionAdministrationPage.gotoPage();
    ExtensionPane extensionPane = adminPage.getSearchBar().clickAdvancedSearch().search(extensionId).getExtension(0);
    ExtensionDependenciesPane dependenciesPane = extensionPane.openDependenciesSection();
    List<DependencyPane> directDependencies = dependenciesPane.getDirectDependencies();
    assertEquals(5, directDependencies.size());
    assertEquals(dependency.getName(), directDependencies.get(0).getName());
    assertEquals(dependencyId.getVersion().getValue(), directDependencies.get(0).getVersion());
    assertEquals("remote", directDependencies.get(0).getStatus());
    assertNull(directDependencies.get(0).getStatusMessage());
    assertNull(directDependencies.get(1).getLink());
    assertEquals("missing-dependency", directDependencies.get(1).getName());
    assertEquals("135", directDependencies.get(1).getVersion());
    assertEquals("unknown", directDependencies.get(1).getStatus());
    assertNull(directDependencies.get(1).getStatusMessage());
    assertNotNull(directDependencies.get(2).getLink());
    assertEquals("XWiki Platform - Sheet - API", directDependencies.get(2).getName());
    assertEquals("[3.2,)", directDependencies.get(2).getVersion());
    assertEquals("core", directDependencies.get(2).getStatus());
    assertEquals("Provided", directDependencies.get(2).getStatusMessage());
    assertNotNull(directDependencies.get(3).getLink());
    assertEquals("XWiki Commons - Diff API", directDependencies.get(3).getName());
    assertEquals("2.7", directDependencies.get(3).getVersion());
    assertEquals("remote-core", directDependencies.get(3).getStatus());
    assertTrue(directDependencies.get(3).getStatusMessage().matches("Version [^\\s]+ is provided"));
    assertEquals("XWiki Platform - Display API", directDependencies.get(4).getName());
    assertEquals("100.1", directDependencies.get(4).getVersion());
    assertEquals("remote-core-incompatible", directDependencies.get(4).getStatus());
    assertTrue(directDependencies.get(4).getStatusMessage().matches("Incompatible with provided version [^\\s]+"));
    assertTrue(dependenciesPane.getBackwardDependencies().isEmpty());
    // Follow the link to a dependency.
    directDependencies.get(0).getLink().click();
    adminPage = new ExtensionAdministrationPage();
    extensionPane = adminPage.getSearchResults().getExtension(0);
    assertEquals(dependency.getName(), extensionPane.getName());
    assertEquals(dependencyId.getVersion().getValue(), extensionPane.getVersion());
    assertEquals(dependency.getSummary(), extensionPane.getSummary());
    // Check that we are still in the administration.
    assertTrue(new AdministrationPage().hasSection("XWiki.Extensions"));
}
Also used : ExtensionAdministrationPage(org.xwiki.extension.test.po.ExtensionAdministrationPage) AdministrationPage(org.xwiki.administration.test.po.AdministrationPage) ExtensionAdministrationPage(org.xwiki.extension.test.po.ExtensionAdministrationPage) DefaultVersionConstraint(org.xwiki.extension.version.internal.DefaultVersionConstraint) ExtensionDependenciesPane(org.xwiki.extension.test.po.ExtensionDependenciesPane) DependencyPane(org.xwiki.extension.test.po.DependencyPane) ExtensionId(org.xwiki.extension.ExtensionId) TestExtension(org.xwiki.repository.test.TestExtension) ExtensionPane(org.xwiki.extension.test.po.ExtensionPane) DefaultExtensionDependency(org.xwiki.extension.DefaultExtensionDependency) Test(org.junit.Test)

Example 4 with TestExtension

use of org.xwiki.repository.test.TestExtension in project xwiki-platform by xwiki.

the class ExtensionIT method testInstallScriptService.

/**
 * Tests if a Java component script service is properly installed.
 */
@Test
public void testInstallScriptService() throws Exception {
    // Make sure the script service is not available before the extension is installed.
    ViewPage viewPage = getUtil().createPage(getTestClassName(), getTestMethodName(), "{{velocity}}$services.greeter.greet('world') " + "$services.greeter.greet('XWiki', 'default'){{/velocity}}", "");
    assertFalse(viewPage.getContent().contains("Hello world! Hello XWiki!"));
    // Setup the extension.
    ExtensionId extensionId = new ExtensionId("scriptServiceJarExtension", "4.2-milestone-1");
    TestExtension extension = getRepositoryTestUtils().getTestExtension(extensionId, "jar");
    getRepositoryTestUtils().addExtension(extension);
    // Search the extension and install it.
    ExtensionAdministrationPage adminPage = ExtensionAdministrationPage.gotoPage();
    ExtensionPane extensionPane = adminPage.getSearchBar().clickAdvancedSearch().search(extensionId).getExtension(0);
    extensionPane.install().confirm();
    // Check the result.
    assertEquals("Hello world! Hello XWiki!", getUtil().gotoPage(getTestClassName(), getTestMethodName()).getContent());
}
Also used : ExtensionAdministrationPage(org.xwiki.extension.test.po.ExtensionAdministrationPage) ExtensionId(org.xwiki.extension.ExtensionId) TestExtension(org.xwiki.repository.test.TestExtension) ViewPage(org.xwiki.test.ui.po.ViewPage) ExtensionPane(org.xwiki.extension.test.po.ExtensionPane) Test(org.junit.Test)

Example 5 with TestExtension

use of org.xwiki.repository.test.TestExtension in project xwiki-platform by xwiki.

the class ExtensionIT method testInstall.

/**
 * Tests how an extension is installed.
 */
@Test
public void testInstall() throws Exception {
    // Setup the extension and its dependencies.
    ExtensionId extensionId = new ExtensionId("alice-xar-extension", "1.3");
    TestExtension extension = getRepositoryTestUtils().getTestExtension(extensionId, "xar");
    ExtensionId dependencyId = new ExtensionId("bob-xar-extension", "2.5-milestone-2");
    getRepositoryTestUtils().addExtension(getRepositoryTestUtils().getTestExtension(dependencyId, "xar"));
    extension.addDependency(new DefaultExtensionDependency(dependencyId.getId(), new DefaultVersionConstraint(dependencyId.getVersion().getValue())));
    extension.addDependency(new DefaultExtensionDependency("org.xwiki.platform:xwiki-platform-sheet-api", new DefaultVersionConstraint("[3.2,)")));
    getRepositoryTestUtils().addExtension(extension);
    // Search the extension and install it.
    ExtensionAdministrationPage adminPage = ExtensionAdministrationPage.gotoPage();
    ExtensionPane extensionPane = adminPage.getSearchBar().clickAdvancedSearch().search(extensionId).getExtension(0);
    extensionPane = extensionPane.install();
    // Assert the install plan.
    List<DependencyPane> installPlan = extensionPane.openProgressSection().getJobPlan();
    assertEquals(2, installPlan.size());
    assertEquals(dependencyId, installPlan.get(0).getId());
    assertEquals(extensionId, installPlan.get(1).getId());
    // Finish the install and assert the install log.
    List<LogItemPane> log = extensionPane.confirm().openProgressSection().getJobLog();
    int logSize = log.size();
    assertTrue(logSize > 1);
    assertEquals("info", log.get(0).getLevel());
    assertEquals("Starting job of type [install] with identifier " + "[extension/action/alice-xar-extension/wiki:xwiki]", log.get(0).getMessage());
    assertEquals("info", log.get(logSize - 1).getLevel());
    assertEquals("Finished job of type [install] with identifier " + "[extension/action/alice-xar-extension/wiki:xwiki]", log.get(logSize - 1).getMessage());
    // Test that both extensions are usable.
    ViewPage viewPage = getUtil().createPage(getTestClassName(), getTestMethodName(), "{{alice/}}\n\n{{bob/}}", "");
    String content = viewPage.getContent();
    assertTrue(content.contains("Alice says hello!"));
    assertTrue(content.contains("Bob says hi!"));
    // Check the list of installed extensions.
    adminPage = ExtensionAdministrationPage.gotoInstalledExtensions();
    SearchResultsPane searchResults = adminPage.getSearchBar().search("bob");
    assertEquals(1, searchResults.getDisplayedResultsCount());
    extensionPane = searchResults.getExtension(0);
    assertEquals("installed-dependency", extensionPane.getStatus());
    assertEquals("Installed as dependency", extensionPane.getStatusMessage());
    assertEquals(dependencyId, extensionPane.getId());
    assertNotNull(extensionPane.getUninstallButton());
    searchResults = new SimpleSearchPane().search("alice");
    assertEquals(1, searchResults.getDisplayedResultsCount());
    extensionPane = searchResults.getExtension(0);
    assertEquals("installed", extensionPane.getStatus());
    assertEquals("Installed", extensionPane.getStatusMessage());
    assertEquals(extensionId, extensionPane.getId());
    assertNotNull(extensionPane.getUninstallButton());
    // Check if the progress log is persisted.
    extensionPane = extensionPane.showDetails();
    log = extensionPane.openProgressSection().getJobLog();
    assertEquals(logSize, log.size());
    assertEquals("info", log.get(0).getLevel());
    assertEquals("Starting job of type [install] with identifier " + "[extension/action/alice-xar-extension/wiki:xwiki]", log.get(0).getMessage());
    assertEquals("info", log.get(logSize - 1).getLevel());
    assertEquals("Finished job of type [install] with identifier " + "[extension/action/alice-xar-extension/wiki:xwiki]", log.get(logSize - 1).getMessage());
    // Check if the dependency is properly listed as installed.
    List<DependencyPane> dependencies = extensionPane.openDependenciesSection().getDirectDependencies();
    assertEquals(2, dependencies.size());
    assertEquals(dependencyId, dependencies.get(0).getId());
    assertEquals("installed-dependency", dependencies.get(0).getStatus());
    assertEquals("Installed as dependency", dependencies.get(0).getStatusMessage());
    // Check the backward dependency.
    dependencies.get(0).getLink().click();
    extensionPane = new ExtensionAdministrationPage().getSearchResults().getExtension(0);
    dependencies = extensionPane.openDependenciesSection().getBackwardDependencies();
    assertEquals(1, dependencies.size());
    assertEquals(extensionId, dependencies.get(0).getId());
    assertEquals("installed", dependencies.get(0).getStatus());
    assertEquals("Installed", dependencies.get(0).getStatusMessage());
}
Also used : ExtensionAdministrationPage(org.xwiki.extension.test.po.ExtensionAdministrationPage) DependencyPane(org.xwiki.extension.test.po.DependencyPane) ExtensionId(org.xwiki.extension.ExtensionId) TestExtension(org.xwiki.repository.test.TestExtension) ViewPage(org.xwiki.test.ui.po.ViewPage) ExtensionPane(org.xwiki.extension.test.po.ExtensionPane) SimpleSearchPane(org.xwiki.extension.test.po.SimpleSearchPane) DefaultVersionConstraint(org.xwiki.extension.version.internal.DefaultVersionConstraint) LogItemPane(org.xwiki.extension.test.po.LogItemPane) DefaultVersionConstraint(org.xwiki.extension.version.internal.DefaultVersionConstraint) SearchResultsPane(org.xwiki.extension.test.po.SearchResultsPane) DefaultExtensionDependency(org.xwiki.extension.DefaultExtensionDependency) Test(org.junit.Test)

Aggregations

ExtensionId (org.xwiki.extension.ExtensionId)11 TestExtension (org.xwiki.repository.test.TestExtension)11 Test (org.junit.Test)10 ExtensionAdministrationPage (org.xwiki.extension.test.po.ExtensionAdministrationPage)10 ExtensionPane (org.xwiki.extension.test.po.ExtensionPane)8 DependencyPane (org.xwiki.extension.test.po.DependencyPane)5 LogItemPane (org.xwiki.extension.test.po.LogItemPane)5 SearchResultsPane (org.xwiki.extension.test.po.SearchResultsPane)5 ViewPage (org.xwiki.test.ui.po.ViewPage)5 SimpleSearchPane (org.xwiki.extension.test.po.SimpleSearchPane)4 DefaultExtensionDependency (org.xwiki.extension.DefaultExtensionDependency)3 DefaultVersionConstraint (org.xwiki.extension.version.internal.DefaultVersionConstraint)3 WebElement (org.openqa.selenium.WebElement)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Select (org.openqa.selenium.support.ui.Select)1 AdministrationPage (org.xwiki.administration.test.po.AdministrationPage)1 DefaultExtensionAuthor (org.xwiki.extension.DefaultExtensionAuthor)1