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");
}
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);
}
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);
}
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);
}
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());
}
Aggregations