Search in sources :

Example 31 with InstallableResource

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

the class DictionaryDigestTest method testDictionaryDigestSameData.

@org.junit.Test
public void testDictionaryDigestSameData() throws Exception {
    final Hashtable<String, Object> d1 = new Hashtable<String, Object>();
    final Hashtable<String, Object> d2 = new Hashtable<String, Object>();
    setTestData(d1);
    setTestData(d2);
    assertEquals("Two dictionary with same values have the same key", create(new InstallableResource("a", null, d1, null, null, null)).getDigest(), create(new InstallableResource("a", null, d2, null, null, null)).getDigest());
}
Also used : Hashtable(java.util.Hashtable) InstallableResource(org.apache.sling.installer.api.InstallableResource)

Example 32 with InstallableResource

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

the class RegisteredResourceComparatorTest method getConfig.

private RegisteredResourceImpl getConfig(String url, Dictionary<String, Object> data, int priority, String digest, ResourceState state) throws IOException {
    if (data == null) {
        data = new Hashtable<String, Object>();
        data.put("foo", "bar");
    }
    new FileDataStore(new MockBundleContext());
    final InstallableResource r = new InstallableResource(url, null, data, digest, null, priority);
    final InternalResource internal = InternalResource.create("test", r);
    final RegisteredResourceImpl rr = RegisteredResourceImpl.create(internal);
    TransformationResult[] tr = new DefaultTransformer().transform(rr);
    if (tr == null) {
        final TransformationResult result = new TransformationResult();
        result.setId(url);
        result.setResourceType(InstallableResource.TYPE_CONFIG);
        tr = new TransformationResult[] { result };
    }
    final RegisteredResourceImpl result = (RegisteredResourceImpl) rr.clone(tr[0]);
    if (state != null) {
        result.setState(state, null);
    }
    return result;
}
Also used : InstallableResource(org.apache.sling.installer.api.InstallableResource) TransformationResult(org.apache.sling.installer.api.tasks.TransformationResult)

Example 33 with InstallableResource

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

the class TaskOrderingTest method getRegisteredResource.

private static EntityResourceList getRegisteredResource(String url) throws IOException {
    new FileDataStore(new MockBundleContext());
    final InternalResource internal = InternalResource.create("test", new InstallableResource(url, null, new Hashtable<String, Object>(), null, null, null));
    RegisteredResourceImpl rr = RegisteredResourceImpl.create(internal);
    TransformationResult[] tr = new DefaultTransformer().transform(rr);
    if (tr == null) {
        final TransformationResult result = new TransformationResult();
        result.setId(url);
        result.setResourceType(InstallableResource.TYPE_CONFIG);
        tr = new TransformationResult[] { result };
    }
    rr = (RegisteredResourceImpl) rr.clone(tr[0]);
    final EntityResourceList erl = new EntityResourceList("test", new MockInstallationListener());
    erl.addOrUpdate(rr);
    return erl;
}
Also used : MockInstallationListener(org.apache.sling.installer.core.impl.tasks.MockInstallationListener) InstallableResource(org.apache.sling.installer.api.InstallableResource) Hashtable(java.util.Hashtable) TransformationResult(org.apache.sling.installer.api.tasks.TransformationResult)

Example 34 with InstallableResource

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

the class RegisteredResourceComparatorTest method untransformedResource.

private RegisteredResource untransformedResource(String id, int prio) throws IOException {
    final ByteArrayInputStream is = new ByteArrayInputStream(id.getBytes("UTF-8"));
    final InstallableResource r = new InstallableResource(id, is, null, id, id, prio);
    final InternalResource internal = InternalResource.create("test", r);
    return RegisteredResourceImpl.create(internal);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InstallableResource(org.apache.sling.installer.api.InstallableResource)

Example 35 with InstallableResource

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

the class RegisteredResourceTest method testDictionaryDigestFromDictionaries.

@org.junit.Test
public void testDictionaryDigestFromDictionaries() throws Exception {
    final Hashtable<String, Object> d1 = new Hashtable<String, Object>();
    final Hashtable<String, Object> d2 = new Hashtable<String, Object>();
    final String[] keys = { "foo", "bar", "something" };
    for (int i = 0; i < keys.length; i++) {
        d1.put(keys[i], keys[i] + "." + keys[i]);
    }
    for (int i = keys.length - 1; i >= 0; i--) {
        d2.put(keys[i], keys[i] + "." + keys[i]);
    }
    final InstallableResource r1 = new InstallableResource("test:url1", null, d1, null, null, null);
    final InstallableResource r2 = new InstallableResource("test:url1", null, d2, null, null, null);
    assertEquals("Two InstallableResource (Dictionary) with same values but different key orderings must have the same key", create(r1).getDigest(), create(r2).getDigest());
}
Also used : Hashtable(java.util.Hashtable) InstallableResource(org.apache.sling.installer.api.InstallableResource) 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