You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by tm...@apache.org on 2021/05/06 09:25:24 UTC

[sling-org-apache-sling-distribution-core] branch SLING-9873-1 updated: SLING-9873 - Use the character ] as path delimiter

This is an automated email from the ASF dual-hosted git repository.

tmaret pushed a commit to branch SLING-9873-1
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-core.git


The following commit(s) were added to refs/heads/SLING-9873-1 by this push:
     new c3f273b  SLING-9873 - Use the character ] as path delimiter
c3f273b is described below

commit c3f273b5843ce6addb6737fbff0f2d8356413fee
Author: tmaret <tm...@adobe.com>
AuthorDate: Thu May 6 11:25:11 2021 +0200

    SLING-9873 - Use the character ] as path delimiter
---
 .../packaging/impl/SimpleDistributionPackage.java  |  2 +-
 .../impl/SimpleDistributionPackageTest.java        | 51 ++++++----------------
 2 files changed, 15 insertions(+), 38 deletions(-)

diff --git a/src/main/java/org/apache/sling/distribution/packaging/impl/SimpleDistributionPackage.java b/src/main/java/org/apache/sling/distribution/packaging/impl/SimpleDistributionPackage.java
index 8aec301..c8196a6 100644
--- a/src/main/java/org/apache/sling/distribution/packaging/impl/SimpleDistributionPackage.java
+++ b/src/main/java/org/apache/sling/distribution/packaging/impl/SimpleDistributionPackage.java
@@ -41,7 +41,7 @@ public class SimpleDistributionPackage extends AbstractDistributionPackage imple
     private final static String PACKAGE_START = "DSTRPCK::";
     private final static String PACKAGE_START_OLD = "DSTRPCK:";
     private final static String DELIM = "|";
-    private final static String PATH_DELIM = ":";
+    private final static String PATH_DELIM = "]";
     private final static String PATH_DELIM_OLD = ",";
     private final long size;
 
diff --git a/src/test/java/org/apache/sling/distribution/packaging/impl/SimpleDistributionPackageTest.java b/src/test/java/org/apache/sling/distribution/packaging/impl/SimpleDistributionPackageTest.java
index 76d1dc1..9009d54 100644
--- a/src/test/java/org/apache/sling/distribution/packaging/impl/SimpleDistributionPackageTest.java
+++ b/src/test/java/org/apache/sling/distribution/packaging/impl/SimpleDistributionPackageTest.java
@@ -32,7 +32,6 @@ import org.junit.Test;
 import org.mockito.Mockito;
 
 import static org.apache.commons.io.IOUtils.toInputStream;
-import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
@@ -49,9 +48,6 @@ public class SimpleDistributionPackageTest {
 
     private static final String TYPE = "testPackageType";
 
-    private static final String DSTRPCK_DELETE = "DSTRPCK::DELETE|/abc:/c";
-    private static final String DSTRPCK_ITEM_WITH_COMMA_DELETE = "DSTRPCK::DELETE|/ab,c:/c";
-
     @Test
     public void testInvalid() {
         String id = "invalid";
@@ -83,49 +79,20 @@ public class SimpleDistributionPackageTest {
 
     @Test
     public void testPackageWithNamespaceInPath() {
-        DistributionRequest req = new SimpleDistributionRequest(DistributionRequestType.ADD, "/a/jcr:content", "/b");
-        SimpleDistributionPackage pkgOut = new SimpleDistributionPackage(req, TYPE);
-        SimpleDistributionPackage pkgIn = SimpleDistributionPackage.fromStream(toInputStream(pkgOut.toString(), Charset.defaultCharset()), TYPE);
-        assertNotNull(pkgIn);
-        assertArrayEquals(pkgOut.getInfo().getPaths(), pkgIn.getInfo().getPaths());
+        DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/a/jcr:content", "/b");
+        testPackageSerDeser(request);
     }
 
     @Test
     public void testCreatedAndReadPackagesEqualityWithCommaInName() throws Exception {
         DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.DELETE, "/ab,c", "/c");
-        SimpleDistributionPackage createdPackage = new SimpleDistributionPackage(request, "VOID");
-        assertThat(createdPackage.toString(), equalTo(DSTRPCK_ITEM_WITH_COMMA_DELETE));
-        // Just to run the code
-        createdPackage.acquire();
-        createdPackage.release();
-        createdPackage.close();
-        createdPackage.delete();
-
-        SimpleDistributionPackage readPackage = SimpleDistributionPackage.fromStream(new ByteArrayInputStream(DSTRPCK_ITEM_WITH_COMMA_DELETE.getBytes()), "VOID");
-        assertNotNull(readPackage);
-        assertEquals(Arrays.toString(createdPackage.getInfo().getPaths()), Arrays.toString(readPackage.getInfo().getPaths()));
+        testPackageSerDeser(request);
     }
     
     @Test
     public void testCreatedAndReadPackagesEquality() throws Exception {
         DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.DELETE, "/abc", "/c");
-        SimpleDistributionPackage createdPackage = new SimpleDistributionPackage(request, "VOID");
-        assertThat(createdPackage.toString(), equalTo(DSTRPCK_DELETE));
-        // Just to run the code
-        createdPackage.acquire();
-        createdPackage.release();
-        createdPackage.close();
-        createdPackage.delete();
-        
-        SimpleDistributionPackage readPackage = SimpleDistributionPackage.fromStream(new ByteArrayInputStream(DSTRPCK_DELETE.getBytes()), "VOID");
-        assertNotNull(readPackage);
-        assertEquals(DSTRPCK_DELETE.length(), readPackage.getSize());
-        assertEquals(createdPackage.getType(), readPackage.getType());
-        assertEquals(createdPackage.getInfo().getRequestType(), readPackage.getInfo().getRequestType());
-        assertEquals(Arrays.toString(createdPackage.getInfo().getPaths()), Arrays.toString(readPackage.getInfo().getPaths()));
-        assertEquals(createdPackage.getId(), readPackage.getId());
-        assertTrue(IOUtils.contentEquals(createdPackage.createInputStream(), readPackage.createInputStream()));
-        
+        testPackageSerDeser(request);
     }
 
     @Test
@@ -140,4 +107,14 @@ public class SimpleDistributionPackageTest {
         assertEquals(createdPackage.getId(), readPackage.getId());
         assertTrue(IOUtils.contentEquals(createdPackage.createInputStream(), readPackage.createInputStream()));
     }
+
+    private void testPackageSerDeser(DistributionRequest request) {
+        SimpleDistributionPackage pkgOut = new SimpleDistributionPackage(request, TYPE);
+        SimpleDistributionPackage pkgIn = SimpleDistributionPackage.fromStream(toInputStream(pkgOut.toString(), Charset.defaultCharset()), TYPE);
+        assertNotNull(pkgIn);
+        assertArrayEquals(pkgOut.getInfo().getPaths(), pkgIn.getInfo().getPaths());
+        assertEquals(pkgOut.getType(), pkgIn.getType());
+        assertEquals(pkgOut.getId(), pkgIn.getId());
+        assertEquals(pkgOut.getInfo().getRequestType(), pkgIn.getInfo().getRequestType());
+    }
 }