OsgiConfigInstallableParams implements SlingInstallableParams<OsgiConfigInstallable> { @NotNull @Override public OsgiConfigInstallable createInstallable(final PackageId parentPackageId, final String jcrPath) throws Exception { if (parseError != null) { throw parseError; } return new OsgiConfigInstallable(parentPackageId, jcrPath, properties, servicePid, factoryPid); } OsgiConfigInstallableParams(@NotNull final Map<String, Object> properties,
                                       @NotNull final String servicePid,
                                       @Nullable final String factoryPid,
                                       @Nullable final Exception parseError); String getServicePid(); String getFactoryPid(); Map<String, Object> getProperties(); Exception getParseError(); @NotNull @Override OsgiConfigInstallable createInstallable(final PackageId parentPackageId, final String jcrPath); @Override @NotNull Class<OsgiConfigInstallable> getInstallableType();  }
@Test(expected = IllegalArgumentException.class) public void testCreateInstallable_throws() throws Exception { final Map<String, Object> expectProperties = new LinkedHashMap<>(); expectProperties.put("foo", "bar"); expectProperties.put("bar", "foo"); final String expectServicePid = "myServicePid"; final String expectFactoryPid = "myFactoryPid"; final Exception expectParseError = new IllegalArgumentException("my parse error"); OsgiConfigInstallableParams params = new OsgiConfigInstallableParams(expectProperties, expectServicePid, expectFactoryPid, expectParseError); params.createInstallable(PackageId.fromString("test"), "/some/path"); }
@Test public void testCreateInstallable() throws Exception { final Map<String, Object> expectProperties = new LinkedHashMap<>(); expectProperties.put("foo", "bar"); expectProperties.put("bar", "foo"); final String expectServicePid = "myServicePid"; final String expectFactoryPid = "myFactoryPid"; final PackageId expectParentId = PackageId.fromString("test"); final String expectJcrPath = "/some/path"; OsgiConfigInstallableParams params = new OsgiConfigInstallableParams(expectProperties, expectServicePid, expectFactoryPid, null); OsgiConfigInstallable installable = params.createInstallable(expectParentId, expectJcrPath); assertSame("expect same parentId", expectParentId, installable.getParentId()); assertSame("expect same jcrPath", expectJcrPath, installable.getJcrPath()); assertEquals("expect same properties", expectProperties, params.getProperties()); assertEquals("expect same servicePid", expectServicePid, params.getServicePid()); assertEquals("expect same factoryPid", expectFactoryPid, params.getFactoryPid()); assertNull("expect null parseError", params.getParseError()); }