You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Thierry Ygé (JIRA)" <ji...@apache.org> on 2015/11/26 21:28:11 UTC

[jira] [Commented] (SLING-5330) add a method to include sling initial content rule in the generated manifest

    [ https://issues.apache.org/jira/browse/SLING-5330?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15029234#comment-15029234 ] 

Thierry Ygé commented on SLING-5330:
------------------------------------

Note that if we can implement this, it would help also then to cleanup the /var/sling/bundle-content which would then "grow" due to "status" node created each time a bundle with sling-initial-content is installed. 

It would then need something like this in the code of the TeleporterHttpClient:
New private method:
{code}
    private void cleanupVar(String bundleSymbolicName) throws MalformedURLException, IOException {
        // equivalent of
        // curl -u admin:admin -F :applyTo=/var/sling/bundle-content/$N -F :operation=delete http://localhost:8080/var/sling/bundle-content
        final String url = baseUrl + "/var/sling/bundle-content";
        final HttpURLConnection c = (HttpURLConnection)new URL(url).openConnection();

        try {
            setConnectionCredentials(c);
            new MultipartAdapter(c, CHARSET)
                    .parameter(":operation", "delete")
                    .parameter(":applyTo", "/var/sling/bundle-content/" + bundleSymbolicName)
                    .close();
            final int status = c.getResponseCode();
            if(status != 200) {
                throw new IOException("Got status code " + status + " for " + url);
            }
        } finally {
            c.disconnect();
        }
    }
{code}

Update the uninstallBundle:
{code}
    void uninstallBundle(String bundleSymbolicName) throws MalformedURLException, IOException {
...
        try {
...
            cleanupVar(bundleSymbolicName);
        } finally {
            c.disconnect();
        }
    }
{code}

Thus /var/sling/bundle-content wouldn't have any left over from test content / data which is preferred running many IT tests.

[~bdelacretaz] Did you had time to have a look at this requested enhancement ? it would be nice that it get in that module so I could make some progress using it for our own IT test framework.

> add a method to include sling initial content rule in the generated manifest
> ----------------------------------------------------------------------------
>
>                 Key: SLING-5330
>                 URL: https://issues.apache.org/jira/browse/SLING-5330
>             Project: Sling
>          Issue Type: Improvement
>          Components: Testing
>    Affects Versions: JUnit Tests Teleporter 1.0.4
>            Reporter: Thierry Ygé
>         Attachments: teleporter_patch.txt
>
>
> As now with the latest improvement to include any resources in the generated bundle that is sent over with the ClientSideTeleporter (SLING-5294), we see that it could be also nice to include a method to define some Sling-Initial-Content value.
> I have tried to implement a simple solution, it works fine in my prototype, which I have based on the documentation (https://sling.apache.org/documentation/bundles/content-loading-jcr-contentloader.html#loading-initial-content-from-bundles)
> Attached is a sample patch, with a junit test for the added class.
> It can then get used in a custom TeleporterRule.Customizer implemented in my test framework
> {code}
>     public void customize(TeleporterRule teleporterRule, String s) {
>        final ClientSideTeleporter cst = (ClientSideTeleporter) teleporterRule;
>       CustomizerParameter params = new CustomizerParameter(s);
>         for (PathImportOptions options : params.getWithContent()) {
>             cst.addImportOption(options);
>         }
> {code}
> In that example my customizer receive some parameter value, which it can extract the import options. Eventually if could be done at TeleportRule level it would be possible to include those with something like:
> {code}
> @Rule
> TeleporterRule teleporter = TeleporterRule.forClass(classUnderTest, "Launchpad").withResources("/my_resources/").withContent(myPathImportOptions);
> {code}
> Since I am not sure if this is something that is "generic" enough to be part of the TeleporterRule , I have only added it to the ClientSideTeleporter in my sample patch.
> Actually it could also be part of a custom implementation if SLING-5329 would be available. So that would reduce the required changes to resolve this requirement.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)