Skip to content

Commit

Permalink
changes to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcin committed Aug 28, 2020
1 parent 248311f commit a285116
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 13 deletions.
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 @@ -32,6 +32,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 +48,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 Down Expand Up @@ -77,7 +77,7 @@ static final class Check extends SimpleProgressCheckFactoryCheck<SlingJcrInstall
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 @@ -96,8 +96,10 @@ public void simulateSling(final SlingSimulator slingSimulator, final Set<String>
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@

package net.adamcin.oakpal.core.checks;

import org.junit.Test;

import static net.adamcin.oakpal.api.JavaxJson.obj;
import static org.junit.Assert.*;

public class SlingJcrInstallerTest {

@Test
public void testNullSafety() throws Exception {
new SlingJcrInstaller().newInstance(obj().get())
.importedPath(null, null, null, null);
}
}

0 comments on commit a285116

Please sign in to comment.