Search in sources :

Example 11 with InstallableResource

use of org.apache.sling.installer.api.InstallableResource in project sling by apache.

the class ConfigInstallTest method testInstallUpdateRemoveConfigFactoryResource.

@Test
public void testInstallUpdateRemoveConfigFactoryResource() throws Exception {
    final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
    cfgData.put("foo", "bar");
    final String cfgFactoryPid = getClass().getSimpleName() + "." + uniqueID();
    final String alias = "alias" + uniqueID();
    // install factory config
    final InstallableResource rsrc = new InstallableResource("/configA/" + cfgFactoryPid + "-" + alias, null, cfgData, null, InstallableResource.TYPE_PROPERTIES, 10);
    installer.updateResources(URL_SCHEME, new InstallableResource[] { rsrc }, null);
    // get factory config
    waitForFactoryConfigValue("After installing", cfgFactoryPid, "foo", "bar");
    // create second factory configuration with same alias
    final Dictionary<String, Object> secondData = new Hashtable<String, Object>();
    secondData.put("foo", "bla");
    final InstallableResource rsrc2 = new InstallableResource("/configB/" + cfgFactoryPid + "-" + alias, null, secondData, null, InstallableResource.TYPE_PROPERTIES, 20);
    installer.updateResources(URL_SCHEME, new InstallableResource[] { rsrc2 }, null);
    // get updated factory config
    waitForFactoryConfigValue("After updating", cfgFactoryPid, "foo", "bla");
    // remove factory config
    installer.updateResources(URL_SCHEME, null, new String[] { "/configB/" + cfgFactoryPid + "-" + alias });
    waitForFactoryConfigValue("After updating", cfgFactoryPid, "foo", "bar");
}
Also used : Hashtable(java.util.Hashtable) InstallableResource(org.apache.sling.installer.api.InstallableResource) Test(org.junit.Test)

Example 12 with InstallableResource

use of org.apache.sling.installer.api.InstallableResource in project sling by apache.

the class ConfigInstallTest method testInstallUpdateRemoveTemplateConfigFactory.

@Test
public void testInstallUpdateRemoveTemplateConfigFactory() throws Exception {
    final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
    cfgData.put("foo", "bar");
    cfgData.put(InstallableResource.RESOURCE_IS_TEMPLATE, "true");
    final String cfgFactoryPid = getClass().getSimpleName() + "." + uniqueID();
    final String alias = "alias" + uniqueID();
    // install factory config
    final InstallableResource rsrc = new InstallableResource("/configA/" + cfgFactoryPid + "-" + alias, null, cfgData, null, InstallableResource.TYPE_PROPERTIES, 10);
    installer.updateResources(URL_SCHEME, new InstallableResource[] { rsrc }, null);
    // get factory config
    final Configuration cfg = waitForFactoryConfigValue("After installing", cfgFactoryPid, "foo", "bar");
    // update configuration
    final Dictionary<String, Object> secondData = new Hashtable<String, Object>();
    secondData.put("foo", "bla");
    cfg.update(secondData);
    waitForResource(URL_SCHEME + ":/configA/" + cfgFactoryPid + "-" + alias, ResourceState.IGNORED);
    // get updated factory config
    final Configuration secondCfg = waitForFactoryConfigValue("After updating", cfgFactoryPid, "foo", "bla");
    // remove config
    secondCfg.delete();
    // we have to wait here as no state change is happening
    sleep(200);
    waitForResource(URL_SCHEME + ":/configA/" + cfgFactoryPid + "-" + alias, ResourceState.IGNORED);
    waitForFactoryConfiguration("After deleting", cfgFactoryPid, false);
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) InstallableResource(org.apache.sling.installer.api.InstallableResource) Test(org.junit.Test)

Example 13 with InstallableResource

use of org.apache.sling.installer.api.InstallableResource in project sling by apache.

the class ConfigInstallTest method testInstallUpdateRemoveTemplateConfigResource.

@Test
public void testInstallUpdateRemoveTemplateConfigResource() throws Exception {
    final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
    cfgData.put("foo", "bar");
    cfgData.put(InstallableResource.RESOURCE_IS_TEMPLATE, "true");
    final String cfgPid = getClass().getSimpleName() + "." + uniqueID();
    // install config
    final InstallableResource rsrc = new InstallableResource("/configA/" + cfgPid, null, cfgData, null, InstallableResource.TYPE_PROPERTIES, 10);
    installer.updateResources(URL_SCHEME, new InstallableResource[] { rsrc }, null);
    // get config
    waitForConfigValue("After installing", cfgPid, "foo", "bar");
    // create second configuration
    final Dictionary<String, Object> secondData = new Hashtable<String, Object>();
    secondData.put("foo", "bla");
    final InstallableResource rsrc2 = new InstallableResource("/configB/" + cfgPid, null, secondData, null, InstallableResource.TYPE_PROPERTIES, 20);
    installer.updateResources(URL_SCHEME, new InstallableResource[] { rsrc2 }, null);
    // get updated config
    waitForConfigValue("After updating", cfgPid, "foo", "bla");
    // remove config
    installer.updateResources(URL_SCHEME, null, new String[] { "/configB/" + cfgPid });
    waitForConfiguration("After deleting", cfgPid, false);
}
Also used : Hashtable(java.util.Hashtable) InstallableResource(org.apache.sling.installer.api.InstallableResource) Test(org.junit.Test)

Example 14 with InstallableResource

use of org.apache.sling.installer.api.InstallableResource in project sling by apache.

the class ConfigInstallTest method testInstallUpdateRemoveTemplateConfigFactoryResource.

@Test
public void testInstallUpdateRemoveTemplateConfigFactoryResource() throws Exception {
    final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
    cfgData.put("foo", "bar");
    cfgData.put(InstallableResource.RESOURCE_IS_TEMPLATE, "true");
    final String cfgFactoryPid = getClass().getSimpleName() + "." + uniqueID();
    final String alias = "alias" + uniqueID();
    // install factory config
    final InstallableResource rsrc = new InstallableResource("/configA/" + cfgFactoryPid + "-" + alias, null, cfgData, null, InstallableResource.TYPE_PROPERTIES, 10);
    installer.updateResources(URL_SCHEME, new InstallableResource[] { rsrc }, null);
    // get factory config
    waitForFactoryConfigValue("After installing", cfgFactoryPid, "foo", "bar");
    // create second factory configuration
    final Dictionary<String, Object> secondData = new Hashtable<String, Object>();
    secondData.put("foo", "bla");
    final InstallableResource rsrc2 = new InstallableResource("/configB/" + cfgFactoryPid + "-" + alias, null, secondData, null, InstallableResource.TYPE_PROPERTIES, 20);
    installer.updateResources(URL_SCHEME, new InstallableResource[] { rsrc2 }, null);
    // get updated factory config
    waitForFactoryConfigValue("After updating", cfgFactoryPid, "foo", "bla");
    // remove config
    installer.updateResources(URL_SCHEME, null, new String[] { "/configB/" + cfgFactoryPid + "-" + alias });
    waitForFactoryConfiguration("After deleting", cfgFactoryPid, false);
}
Also used : Hashtable(java.util.Hashtable) InstallableResource(org.apache.sling.installer.api.InstallableResource) Test(org.junit.Test)

Example 15 with InstallableResource

use of org.apache.sling.installer.api.InstallableResource in project sling by apache.

the class RegisteredResourceTest method testLocalFileCopy.

@org.junit.Test
public void testLocalFileCopy() throws Exception {
    final File localFile = File.createTempFile("testLocalFileCopy", ".data");
    localFile.deleteOnExit();
    final BundleContext bc = new MockBundleContext();
    final File f = getTestBundle("testbundle-1.0.jar");
    final InputStream s = new FileInputStream(f);
    FileDataStore.SHARED = new FileDataStore(bc) {

        @Override
        public File createNewDataFile(InputStream stream, String url, String digest, String hint) throws IOException {
            this.copyToLocalStorage(stream, localFile);
            return localFile;
        }
    };
    InternalResource.create("test", new InstallableResource("test:1.jar", s, null, "somedigest", null, null));
    assertTrue("Local file exists", localFile.exists());
    assertEquals("Local file length matches our data", f.length(), localFile.length());
}
Also used : FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InstallableResource(org.apache.sling.installer.api.InstallableResource) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

InstallableResource (org.apache.sling.installer.api.InstallableResource)47 Hashtable (java.util.Hashtable)23 Test (org.junit.Test)21 File (java.io.File)8 IOException (java.io.IOException)8 InputStream (java.io.InputStream)7 Configuration (org.osgi.service.cm.Configuration)6 FileInputStream (java.io.FileInputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 TaskResource (org.apache.sling.installer.api.tasks.TaskResource)3 TransformationResult (org.apache.sling.installer.api.tasks.TransformationResult)3 FileOutputStream (java.io.FileOutputStream)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 URL (java.net.URL)2 LinkedList (java.util.LinkedList)2 Node (javax.jcr.Node)2 OsgiInstaller (org.apache.sling.installer.api.OsgiInstaller)2 ModelArchiveReader (org.apache.sling.provisioning.model.io.ModelArchiveReader)2