sling-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [sling-org-apache-sling-distribution-core] tmaret commented on a change in pull request #20: SLING-8591 - Hook to support custom code when installing or deleting …
Date Tue, 23 Jul 2019 07:46:11 GMT
tmaret commented on a change in pull request #20: SLING-8591 - Hook to support custom code
when installing or deleting …
URL: https://github.com/apache/sling-org-apache-sling-distribution-core/pull/20#discussion_r306171682
 
 

 ##########
 File path: src/test/java/org/apache/sling/distribution/packaging/impl/InMemoryDistributionPackageBuilderTest.java
 ##########
 @@ -18,30 +18,97 @@
  */
 package org.apache.sling.distribution.packaging.impl;
 
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.verify;
+
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.sling.api.resource.LoginException;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.distribution.DistributionRequestType;
 import org.apache.sling.distribution.SimpleDistributionRequest;
 import org.apache.sling.distribution.common.DistributionException;
 import org.apache.sling.distribution.packaging.DistributionPackage;
+import org.apache.sling.distribution.packaging.DistributionPackageInfo;
+import org.apache.sling.distribution.packaging.PackageInstallHook;
 import org.apache.sling.distribution.serialization.DistributionContentSerializer;
 import org.apache.sling.distribution.serialization.DistributionExportOptions;
+import org.apache.sling.testing.mock.sling.MockSling;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
-
+@RunWith(MockitoJUnitRunner.class)
 public class InMemoryDistributionPackageBuilderTest {
 
+    @Mock
+    private PackageInstallHook installHook;
+    
+    private ResourceResolver resolver;
+    private InMemoryDistributionPackageBuilder builder;
+    
+
+    @SuppressWarnings("deprecation")
+    @Before
+    public void before() throws LoginException {
+        resolver = MockSling.newResourceResolver(ResourceResolverType.JCR_OAK);
+        builder = new InMemoryDistributionPackageBuilder("name", new InMemDistributionContentSerializer(),
new String[0], new String[0], installHook);
+    }
+
+    @Test
+    public void testReadPackage() throws Exception {
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        Map<String, Object> info = new HashMap<String, Object>();
+        info.put("test1", "value1");
+        DistributionPackageUtils.writeInfo(outputStream, info);
+        InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
+
+        DistributionPackage distPackage = builder.readPackage(resolver, inputStream);
+        DistributionPackageInfo outInfo = distPackage.getInfo();
+        assertThat(outInfo.get("test1", String.class), equalTo("value1"));
+    }
+    
+    @Test
+    public void testGetPackageInvalid() throws Exception {
+        
 
 Review comment:
   sonar hint, seems empty :-)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message