Skip to content

Commit

Permalink
full coverage for sling package
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcin committed Aug 31, 2020
1 parent bddc96f commit 7d6262a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,11 @@ public void setErrorListener(final ErrorListener errorListener) {
};
}

public @Nullable JcrPackage
openEmbeddedPackage(@NotNull final EmbeddedPackageInstallable installable) throws RepositoryException {
public @NotNull JcrPackage
openEmbeddedPackage(@NotNull final EmbeddedPackageInstallable installable) throws IOException, RepositoryException {
Node packageNode = session.getNode(installable.getJcrPath());
try (InputStream input = JcrUtils.readFile(packageNode)) {
return packageManager.upload(input, true, true);
} catch (IOException e) {
errorListener.onSlingEmbeddedPackageError(e, installable);
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

import net.adamcin.oakpal.api.EmbeddedPackageInstallable;
import net.adamcin.oakpal.api.Fun;
import net.adamcin.oakpal.api.Nothing;
import net.adamcin.oakpal.api.OsgiConfigInstallable;
import net.adamcin.oakpal.api.Result;
import net.adamcin.oakpal.api.SlingOpenable;
import net.adamcin.oakpal.core.OakpalPlan;
import net.adamcin.oakpal.testing.TestPackageUtil;
import org.apache.jackrabbit.commons.JcrUtils;
Expand All @@ -29,6 +31,7 @@
import org.apache.jackrabbit.vault.packaging.PackageId;
import org.apache.jackrabbit.vault.packaging.VaultPackage;
import org.apache.sling.installer.api.InstallableResource;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import org.mockito.ArgumentMatcher;

Expand Down Expand Up @@ -497,6 +500,31 @@ public void testReadInstallableResourceFromNode_package() throws Exception {
});
}

static class UnsupportedSlingOpenable implements SlingOpenable<Nothing> {
private final PackageId parentId;
private final String jcrPath;

public UnsupportedSlingOpenable(final PackageId parentId, final String jcrPath) {
this.parentId = parentId;
this.jcrPath = jcrPath;
}

@Override
public @NotNull PackageId getParentId() {
return parentId;
}

@Override
public @NotNull String getJcrPath() {
return jcrPath;
}
}

@Test(expected = IllegalArgumentException.class)
public void testOpen_unsupported() throws Exception {
slingSimulator.open(new UnsupportedSlingOpenable(PackageId.fromString("test"), "/test/installable")).tryGet();
}

private static ArgumentMatcher<Node> nodeWithPath(String path) {
return new ArgumentMatcher<Node>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
import org.apache.jackrabbit.vault.packaging.PackageId;
import org.junit.Test;

import javax.jcr.Node;

import static net.adamcin.oakpal.core.sling.NoopSlingSimulator.instance;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;

public class NoopSlingSimulatorTest {

Expand All @@ -42,4 +45,24 @@ public void testOpenEmbeddedPackage() throws Exception {
PackageId.fromString("test:pack:2"))).tryGet();
}

@Test
public void testSetPackageManager() {
instance().setPackageManager(null);
}

@Test
public void testSetErrorListener() {
instance().setErrorListener(null);
}

@Test
public void testSetSession() {
instance().setSession(null);
}

@Test
public void testPrepareInstallableNode() {
assertNull("always null",
instance().prepareInstallableNode(PackageId.fromString("test:pack:1"), mock(Node.class)));
}
}

0 comments on commit 7d6262a

Please sign in to comment.