Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes to increase coverage #67

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright 2020 Mark Adamcin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.adamcin.oakpal.api;

import org.apache.jackrabbit.vault.packaging.PackageId;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertSame;

public class EmbeddedPackageInstallableTest {
@Test
public void testConstructorAndGetters() {
final PackageId expectParentId = PackageId.fromString("test:test:1");
final String expectJcrPath = "/some/path";
final PackageId expectSubpackageId = PackageId.fromString("test:testtest:1");
final EmbeddedPackageInstallable installable =
new EmbeddedPackageInstallable(expectParentId, expectJcrPath, expectSubpackageId);

assertSame("expect parentId", expectParentId, installable.getParentId());
assertSame("expect jcrPath", expectJcrPath, installable.getJcrPath());
assertSame("expect subpackageId", expectSubpackageId, installable.getEmbeddedId());
}

@Test
public void testEquals() {
EmbeddedPackageInstallable self = new EmbeddedPackageInstallable(
PackageId.fromString("test:test:1"),
"/some/path",
PackageId.fromString("test:testtest:1"));

assertEquals("expect self to equal self", self, self);
assertFalse("expect self to not equal null", self.equals(null));

assertEquals("expect self to equal other same params", self,
new EmbeddedPackageInstallable(
self.getParentId(),
self.getJcrPath(),
self.getEmbeddedId()));
assertNotEquals("expect self to equal other different path", self,
new EmbeddedPackageInstallable(
self.getParentId(),
"/some/other/path",
self.getEmbeddedId()));
assertNotEquals("expect self to equal other different parent id", self,
new EmbeddedPackageInstallable(
self.getEmbeddedId(),
self.getJcrPath(),
self.getEmbeddedId()));
assertNotEquals("expect self to equal other different embedded id", self,
new EmbeddedPackageInstallable(
self.getParentId(),
self.getJcrPath(),
self.getParentId()));
}

@Test
public void testHashCode() {
EmbeddedPackageInstallable self = new EmbeddedPackageInstallable(
PackageId.fromString("test:test:1"),
"/some/path",
PackageId.fromString("test:testtest:1"));

assertEquals("expect self to equal self", self.hashCode(), self.hashCode());

assertEquals("expect self to equal other same params", self.hashCode(),
new EmbeddedPackageInstallable(
self.getParentId(),
self.getJcrPath(),
self.getEmbeddedId()).hashCode());
assertNotEquals("expect self to equal other different path", self.hashCode(),
new EmbeddedPackageInstallable(
self.getParentId(),
"/some/other/path",
self.getEmbeddedId()).hashCode());
assertNotEquals("expect self to equal other different parent id", self.hashCode(),
new EmbeddedPackageInstallable(
self.getEmbeddedId(),
self.getJcrPath(),
self.getEmbeddedId()).hashCode());
assertNotEquals("expect self to equal other different embedded id", self.hashCode(),
new EmbeddedPackageInstallable(
self.getParentId(),
self.getJcrPath(),
self.getParentId()).hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,32 @@
* limitations under the License.
*/

package net.adamcin.oakpal.core.sling;
package net.adamcin.oakpal.api;

import net.adamcin.oakpal.api.EmbeddedPackageInstallable;
import org.apache.jackrabbit.vault.packaging.PackageId;
import org.junit.Test;

import java.util.Collections;
import java.util.Map;

import static org.junit.Assert.*;

public class EmbeddedPackageInstallableTest {
public class OsgiConfigInstallableTest {

@Test
public void testConstructorAndGetters() {
final PackageId expectParentId = PackageId.fromString("test:test:1");
final String expectJcrPath = "/some/path";
final PackageId expectSubpackageId = PackageId.fromString("test:testtest:1");
final EmbeddedPackageInstallable installable =
new EmbeddedPackageInstallable(expectParentId, expectJcrPath, expectSubpackageId);
final Map<String, Object> expectProps = Collections.singletonMap("key", "value");
final String expectServicePid = "some.service.Pid";
final String expectFactoryPid = "some.factory.Pid";
final OsgiConfigInstallable installable = new OsgiConfigInstallable(expectParentId,
expectJcrPath, expectProps, expectServicePid, expectFactoryPid);

assertSame("expect parentId", expectParentId, installable.getParentId());
assertSame("expect jcrPath", expectJcrPath, installable.getJcrPath());
assertSame("expect subpackageId", expectSubpackageId, installable.getEmbeddedId());
assertEquals("expect equal props", expectProps, installable.getProperties());
assertEquals("expect equal servicePid", expectServicePid, installable.getServicePid());
assertEquals("expect equal factoryPid", expectFactoryPid, installable.getFactoryPid());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

package net.adamcin.oakpal.core.sling;
package net.adamcin.oakpal.api;

import net.adamcin.oakpal.api.RepoInitScriptsInstallable;
import org.apache.jackrabbit.vault.packaging.PackageId;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2020 Mark Adamcin
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal"
jcr:mixinTypes="[rep:AccessControllable]"
jcr:primaryType="nt:folder"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2020 Mark Adamcin
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal"
jcr:mixinTypes="[rep:AccessControllable]"
jcr:primaryType="nt:folder"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2020 Mark Adamcin
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal"
jcr:mixinTypes="[rep:AccessControllable]"
jcr:primaryType="nt:folder"/>
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void identifySubpackage(final PackageId packageId, final PackageId parent

@Override
public void beforeSlingInstall(final PackageId lastPackage,
final SlingInstallable slingInstallable,
final SlingInstallable<?> slingInstallable,
final Session inspectSession) throws RepositoryException {
wrapped.beforeSlingInstall(lastPackage, slingInstallable, inspectSession);
}
Expand All @@ -151,7 +151,7 @@ public void identifyEmbeddedPackage(final PackageId packageId, final PackageId p

@Override
public void appliedRepoInitScripts(final PackageId lastPackage,
final SlingInstallable slingInstallable,
final SlingInstallable<?> slingInstallable,
final Session inspectSession) throws RepositoryException {
wrapped.appliedRepoInitScripts(lastPackage, slingInstallable, inspectSession);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void identifySubpackage(final PackageId packageId, final PackageId parent

@Override
public void beforeSlingInstall(final PackageId lastPackage,
final SlingInstallable slingInstallable,
final SlingInstallable<?> slingInstallable,
final Session inspectSession) throws RepositoryException {
if (!silenced) {
wrapped.beforeSlingInstall(lastPackage, slingInstallable, inspectSession);
Expand All @@ -166,7 +166,7 @@ public void identifyEmbeddedPackage(final PackageId packageId, final PackageId p

@Override
public void appliedRepoInitScripts(final PackageId lastPackage,
final SlingInstallable slingInstallable,
final SlingInstallable<?> slingInstallable,
final Session inspectSession) throws RepositoryException {
if (!silenced) {
wrapped.appliedRepoInitScripts(lastPackage, slingInstallable, inspectSession);
Expand Down
37 changes: 36 additions & 1 deletion core/src/main/java/net/adamcin/oakpal/core/checks/Echo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

import net.adamcin.oakpal.api.PathAction;
import net.adamcin.oakpal.api.ProgressCheck;
import net.adamcin.oakpal.api.SlingInstallable;
import net.adamcin.oakpal.api.SlingSimulator;
import net.adamcin.oakpal.api.Violation;
import org.apache.jackrabbit.vault.fs.config.MetaInf;
import org.apache.jackrabbit.vault.packaging.PackageId;
import org.apache.jackrabbit.vault.packaging.PackageProperties;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ConsumerType;

import javax.jcr.Node;
Expand All @@ -34,6 +37,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import java.util.jar.Manifest;

Expand Down Expand Up @@ -134,7 +138,38 @@ public void deletedPath(final PackageId packageId, final String path, final Sess
@Override
public void afterExtract(final PackageId packageId, final Session inspectSession) throws RepositoryException {
echo("afterExtract(packageId: %s, inspectSession: %s)", packageId,
Optional.ofNullable(inspectSession).map(Session::getUserID).orElse(null));
sessionToString(inspectSession));
}

@Override
public void simulateSling(final SlingSimulator slingSimulator, final Set<String> runModes) {
echo("simulateSling(slingSimulator: %s, runModes: %s)", slingSimulator.getClass().getName(), runModes);
}

@Override
public void identifyEmbeddedPackage(final PackageId packageId, final PackageId parentId, final String jcrPath) {
echo("identifyEmbeddedPackage(packageId: %s, parentId: %s, jcrPath: %s)", packageId, parentId, jcrPath);
}

@Override
public void beforeSlingInstall(final PackageId lastPackage, final SlingInstallable<?> slingInstallable, final Session inspectSession) throws RepositoryException {
echo("beforeSlingInstall(lastPackage: %s, slingInstallable: %s, inspectSession: %s)", lastPackage, slingInstallable,
sessionToString(inspectSession));
}

@Override
public void appliedRepoInitScripts(final PackageId lastPackage, final SlingInstallable<?> slingInstallable, final Session inspectSession) throws RepositoryException {
echo("appliedRepoInitScripts(lastPackage: %s, slingInstallable: %s, inspectSession: %s)", lastPackage, slingInstallable,
sessionToString(inspectSession));
}

@Override
public void afterScanPackage(final PackageId packageId, final Session inspectSession) throws RepositoryException {
echo("afterScanPackage(packageId: %s, inspectSession: %s)", packageId, sessionToString(inspectSession));
}

@Nullable String sessionToString(final @Nullable Session session) throws RepositoryException {
return Optional.ofNullable(session).map(Session::getUserID).orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.adamcin.oakpal.api.ProgressCheck;
import net.adamcin.oakpal.api.ProgressCheckFactory;
import net.adamcin.oakpal.api.Severity;
import net.adamcin.oakpal.api.SilenceableCheck;
import net.adamcin.oakpal.api.SimpleProgressCheckFactoryCheck;
import net.adamcin.oakpal.api.SlingSimulator;
import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
Expand All @@ -32,6 +33,7 @@
import javax.jcr.RepositoryException;
import javax.json.JsonObject;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
Expand All @@ -47,7 +49,6 @@
* </dl>
*/
public final class SlingJcrInstaller implements ProgressCheckFactory {
static final String DEFAULT_INSTALL_PATH_PATTERN = "^(/[^/]*)*/(install|config)$";
static final List<String> DEFAULT_ROOT_PATHS = Arrays.asList("/apps", "/libs");

@ProviderType
Expand All @@ -73,11 +74,14 @@ public ProgressCheck newInstance(final JsonObject config) {
return new Check(rootPaths);
}

static final class Check extends SimpleProgressCheckFactoryCheck<SlingJcrInstaller> {
/**
* This check implements {@link SilenceableCheck} specifically to avoid be wrapped with a silencing facade.
*/
static final class Check extends SimpleProgressCheckFactoryCheck<SlingJcrInstaller> implements SilenceableCheck {
private final List<String> rootPaths;

private SlingSimulator slingSimulator;
private Pattern installPattern = Pattern.compile(DEFAULT_INSTALL_PATH_PATTERN);
private Pattern installPattern = compileInstallPattern(Collections.emptySet());

Check(final @NotNull List<String> rootPaths) {
super(SlingJcrInstaller.class);
Expand All @@ -89,15 +93,22 @@ public void startedScan() {
super.startedScan();
}

@Override
public void setSilenced(final boolean silenced) {
/* do nothing, because we currently collect no violations in this check */
}

@Override
public void simulateSling(final SlingSimulator slingSimulator, final Set<String> runModes) {
this.slingSimulator = slingSimulator;
installPattern = compileInstallPattern(runModes);
}

Pattern compileInstallPattern(final @NotNull Set<String> runModes) {
return Pattern.compile(String.format("^(/[^/]*)*/(install|config)(\\.(%s))*$",
String.join("|", runModes)));
String patternSuffix = runModes.isEmpty()
? "$"
: String.format("(\\.(%s))*$", String.join("|", runModes));
return Pattern.compile("^(/[^/]*)*/(install|config)" + patternSuffix);
}

@Override
Expand Down
Loading