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());
}
use of org.apache.sling.installer.api.InstallableResource in project sling by apache.
the class RegisteredResourceTest method testConfigDigestIncludesUrl.
@org.junit.Test
public void testConfigDigestIncludesUrl() throws Exception {
final Dictionary<String, Object> data = new Hashtable<String, Object>();
final InstallableResource rA = new InstallableResource("test:urlA", null, data, null, null, null);
final InstallableResource rB = new InstallableResource("test:urlB", null, data, null, null, null);
assertTrue("Expecting configs with same data but different URLs to have same digests", create(rA).getDigest().equals(create(rB).getDigest()));
}
Aggregations