Search in sources :

Example 1 with ExtensionInlinePage

use of org.xwiki.repository.test.po.editor.ExtensionInlinePage in project xwiki-platform by xwiki.

the class RepositoryTest method addExtension.

private void addExtension() throws Exception {
    // Create extension
    ExtensionsPage extensionsPage = ExtensionsPage.gotoPage();
    ExtensionInlinePage extensionInline = extensionsPage.contributeExtension(this.baseExtension.getName());
    Assert.assertEquals(this.baseExtension.getName(), extensionInline.getName());
    extensionInline.setDescription(this.baseExtension.getDescription());
    extensionInline.setInstallation("extension installation");
    extensionInline.setLicenseName(this.baseLicense.getName());
    extensionInline.setSource("http://source");
    extensionInline.setSummary(this.baseExtension.getSummary());
    extensionInline.setType(this.baseExtension.getType());
    ExtensionPage extensionPage = extensionInline.clickSaveAndView();
    // Test summary
    getDriver().findElementsWithoutWaiting(By.xpath("//tt[text()=\"" + this.baseExtension.getSummary() + "\"]"));
    Assert.assertFalse(extensionPage.isValidExtension());
    // Add versions
    // TODO: add XR UI to manipulate versions
    getRepositoryTestUtils().addVersionObject(this.baseExtension);
    getRepositoryTestUtils().addVersionObject(this.baseExtension, "10.0", getUtil().getAttachmentURL("Extension", this.baseExtension.getName(), this.baseExtension.getFile().getName()));
    getRepositoryTestUtils().addVersionObject(this.baseExtension, "2.0", "attach:" + this.baseExtension.getFile().getName());
    // Add dependencies
    // TODO: add XR UI to manipulate dependencies
    getRepositoryTestUtils().addDependencies(this.baseExtension, "10.0");
    // Add attachment
    getRepositoryTestUtils().attachFile(this.baseExtension);
    // Wait until all asynchronous tasks are done
    getRepositoryTestUtils().waitUntilReady();
    // Check livetable
    extensionsPage = ExtensionsPage.gotoPage();
    ExtensionsLiveTableElement livetable = extensionsPage.getLiveTable();
    livetable.filterName(this.baseExtension.getName());
    extensionPage = livetable.clickExtensionName(this.baseExtension.getName());
    // Validate extension state
    Assert.assertTrue(extensionPage.isValidExtension());
    // //////////////////////////////////////////
    // Validate REST
    // //////////////////////////////////////////
    // //////////////////////////////////////////
    // 1.0
    // //////////////////////////////////////////
    // Resolve
    ExtensionVersion extension = getUtil().rest().getResource(Resources.EXTENSION_VERSION, null, this.baseExtension.getId().getId(), "1.0");
    Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
    Assert.assertEquals(this.baseExtension.getType(), extension.getType());
    Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
    Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
    Assert.assertEquals(this.baseExtension.getDescription(), 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("1.0", extension.getVersion());
    Assert.assertEquals(getUtil().getURL(Arrays.asList("Extension", this.baseExtension.getName()), ""), extension.getWebsite());
    // File
    Assert.assertEquals(this.sizeOfFile, getUtil().rest().getBuffer(Resources.EXTENSION_VERSION_FILE, null, this.baseExtension.getId().getId(), "1.0").length);
    // //////////////////////////////////////////
    // 2.0
    // //////////////////////////////////////////
    // Resolve
    extension = getUtil().rest().getResource(Resources.EXTENSION_VERSION, null, this.baseExtension.getId().getId(), "2.0");
    Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
    Assert.assertEquals(this.baseExtension.getType(), extension.getType());
    Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
    Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
    Assert.assertEquals(this.baseExtension.getDescription(), 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("2.0", extension.getVersion());
    Assert.assertEquals(getUtil().getURL(Arrays.asList("Extension", this.baseExtension.getName()), ""), extension.getWebsite());
    // File
    Assert.assertEquals(this.sizeOfFile, getUtil().rest().getBuffer(Resources.EXTENSION_VERSION_FILE, null, this.baseExtension.getId().getId(), "2.0").length);
    // //////////////////////////////////////////
    // 10.0
    // //////////////////////////////////////////
    // Resolve
    extension = getUtil().rest().getResource(Resources.EXTENSION_VERSION, null, this.baseExtension.getId().getId(), "10.0");
    Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
    Assert.assertEquals(this.baseExtension.getType(), extension.getType());
    Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
    Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
    Assert.assertEquals("10.0", extension.getVersion());
    Assert.assertEquals(getUtil().getURL(Arrays.asList("Extension", this.baseExtension.getName()), ""), extension.getWebsite());
    ExtensionDependency dependency1 = extension.getDependencies().get(0);
    Assert.assertEquals("dependencyid1", dependency1.getId());
    Assert.assertEquals("1.0", dependency1.getConstraint());
    ExtensionDependency dependency2 = extension.getDependencies().get(1);
    Assert.assertEquals("dependencyid2", dependency2.getId());
    Assert.assertEquals("2.0", dependency2.getConstraint());
    // File
    Assert.assertEquals(this.sizeOfFile, getUtil().rest().getBuffer(Resources.EXTENSION_VERSION_FILE, null, this.baseExtension.getId().getId(), this.baseExtension.getId().getVersion().getValue()).length);
    // //////////////////////////////////////////
    // Search
    // //////////////////////////////////////////
    // Empty search
    extension = searchExtension(this.baseExtension.getId().getId());
    if (extension == null) {
        Assert.fail("Could not find extension [" + this.baseExtension.getId().getId() + "]");
    }
    Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
    Assert.assertEquals(this.baseExtension.getType(), extension.getType());
    Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
    Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
    Assert.assertEquals("10.0", extension.getVersion());
    // TODO: add support for dependencies in XR search
    // Search pattern
    Map<String, Object[]> queryParams = new HashMap<String, Object[]>();
    queryParams.put(Resources.QPARAM_SEARCH_QUERY, new Object[] { "macro" });
    ExtensionsSearchResult result = getUtil().rest().getResource(Resources.SEARCH, queryParams);
    Assert.assertEquals(1, result.getTotalHits());
    Assert.assertEquals(0, result.getOffset());
    extension = result.getExtensions().get(0);
    Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
    Assert.assertEquals(this.baseExtension.getType(), extension.getType());
    Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
    Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
    Assert.assertEquals("10.0", extension.getVersion());
    // Wrong search pattern
    queryParams.clear();
    queryParams.put(Resources.QPARAM_SEARCH_QUERY, new Object[] { "notexisting" });
    result = getUtil().rest().getResource(Resources.SEARCH, queryParams);
    Assert.assertEquals(0, result.getTotalHits());
    Assert.assertEquals(0, result.getOffset());
    Assert.assertEquals(0, result.getExtensions().size());
    // Search limit offset
    queryParams.clear();
    queryParams.put(Resources.QPARAM_LIST_START, new Object[] { 1 });
    result = getUtil().rest().getResource(Resources.SEARCH, queryParams);
    Assert.assertEquals(1, result.getOffset());
    Assert.assertEquals(result.getTotalHits() - 1, result.getExtensions().size());
    // Search limit nb
    queryParams.clear();
    queryParams.put(Resources.QPARAM_LIST_NUMBER, new Object[] { 0 });
    result = getUtil().rest().getResource(Resources.SEARCH, queryParams);
    Assert.assertTrue(result.getTotalHits() >= 1);
    Assert.assertEquals(0, result.getOffset());
    Assert.assertEquals(0, result.getExtensions().size());
}
Also used : ExtensionsSearchResult(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionsSearchResult) ExtensionInlinePage(org.xwiki.repository.test.po.editor.ExtensionInlinePage) ExtensionsPage(org.xwiki.repository.test.po.ExtensionsPage) ExtensionPage(org.xwiki.repository.test.po.ExtensionPage) HashMap(java.util.HashMap) ExtensionsLiveTableElement(org.xwiki.repository.test.po.ExtensionsLiveTableElement) ExtensionDependency(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionDependency) DefaultExtensionDependency(org.xwiki.extension.DefaultExtensionDependency) ExtensionVersion(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionVersion)

Aggregations

HashMap (java.util.HashMap)1 DefaultExtensionDependency (org.xwiki.extension.DefaultExtensionDependency)1 ExtensionDependency (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionDependency)1 ExtensionVersion (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionVersion)1 ExtensionsSearchResult (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionsSearchResult)1 ExtensionPage (org.xwiki.repository.test.po.ExtensionPage)1 ExtensionsLiveTableElement (org.xwiki.repository.test.po.ExtensionsLiveTableElement)1 ExtensionsPage (org.xwiki.repository.test.po.ExtensionsPage)1 ExtensionInlinePage (org.xwiki.repository.test.po.editor.ExtensionInlinePage)1