forked from eclipse-jkube/jkube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix (jkube-kit/common) : PluginServiceFactory fails to resolve constr…
…uctor arguments for more than one level subclasses PluginServiceFactory tries to create ServiceImpl objects by invoking their constructors with constructor parameter. This works fine when constructor parameter is not using complex inheritance; but if we provide a nested subtype as constructor argument to PluginServiceFactory (let's say BaseA > BaseB > BaseC) it fails to resolve constructor argument. Instead of just getting types via `constructorParameter.getClass().getInterfaces()` try getting all possible subtypes recursively. Signed-off-by: Rohan Kumar <rohaan@redhat.com>
- Loading branch information
1 parent
67aab45
commit 7777376
Showing
3 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...rc/test/java/org/eclipse/jkube/kit/common/util/PluginServiceFactoryNestedContextTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.common.util; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class PluginServiceFactoryNestedContextTest { | ||
private PluginServiceFactory<TestContext> pluginServiceFactory; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
pluginServiceFactory = new PluginServiceFactory<>(new DefaultTestContext()); | ||
} | ||
|
||
@Test | ||
void createServiceObjects_whenSubInterfacePassed_shouldMatchServiceImplementation() { | ||
// Given | ||
final String[] descriptorPaths = new String[] { "service/test-services-nested-context"}; | ||
// When | ||
final List<TestService> result = pluginServiceFactory.createServiceObjects(descriptorPaths); | ||
// Then | ||
assertThat(result).hasSize(1); | ||
} | ||
|
||
public static class TestServiceImplWithBaseContext implements TestService { | ||
public TestServiceImplWithBaseContext(BaseContext ctx) { } | ||
|
||
@Override | ||
public String getName() { return "one"; } | ||
} | ||
|
||
private interface TestService { | ||
String getName(); | ||
} | ||
|
||
private static class DefaultTestContext implements TestContext { } | ||
|
||
private interface TestContext extends BaseContext { } | ||
|
||
private interface BaseContext { } | ||
} |
1 change: 1 addition & 0 deletions
1
jkube-kit/common/src/test/resources/service/test-services-nested-context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.eclipse.jkube.kit.common.util.PluginServiceFactoryNestedContextTest$TestServiceImplWithBaseContext,5 |