Skip to content

Commit

Permalink
eclipse-ee4j#24158 Enhance existing test to test an aliased property.
Browse files Browse the repository at this point in the history
Signed-off-by:Ondro Mihalyi <mihalyi@omnifish.ee>
  • Loading branch information
OndroMih committed Nov 19, 2022
1 parent c1f2642 commit 8197344
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions nucleus/core/kernel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.glassfish.main.core.kernel.test.KernelJUnitExtension;
import org.glassfish.tests.utils.mock.MockGenerator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.jvnet.hk2.config.ConfigListener;
import org.jvnet.hk2.config.ConfigSupport;
Expand All @@ -46,6 +45,9 @@
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

/**
* test the set command
Expand All @@ -66,8 +68,17 @@ public void addMissingServices() {
adminSubject = mockGenerator.createAsadminSubject();
}

@Test
public void simpleAttributeSetTest() {
@ParameterizedTest(name = "{index}: Test setting {0}")
@CsvSource({
"a direct property,"
+ "configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.port,"
+ "8090",
"an aliased property,"
+ "server.network-config.network-listeners.network-listener.http-listener-1.port,"
+ "8090"

})
public void setListenerPortNumber(String testDescription, String propertyName, String propertyValue) {
CommandRunnerImpl runner = locator.getService(CommandRunnerImpl.class);
assertNotNull(runner);

Expand All @@ -81,15 +92,16 @@ public void simpleAttributeSetTest() {
}
}
assertNotNull(listener);

String oldPortValue = listener.getPort();

// Let's register a listener
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(listener);
bean.addListener(this);

// parameters to the command
ParameterMap parameters = new ParameterMap();
parameters.set("DEFAULT",
"configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.port=8090");
parameters.set("DEFAULT", propertyName + "=" + propertyValue);
// execute the set command.
PlainTextActionReporter reporter = new PlainTextActionReporter();
CommandInvocation invocation = runner.getCommandInvocation("set", reporter, adminSubject).parameters(parameters);
Expand All @@ -103,13 +115,13 @@ public void simpleAttributeSetTest() {

// check the result.
String port = listener.getPort();
assertEquals("8090", port);
assertEquals(propertyValue, port);

// check we recevied the event
assertNotNull(event);
assertAll(
() -> assertEquals("8080", event.getOldValue()),
() -> assertEquals("8090", event.getNewValue()),
() -> assertEquals(oldPortValue, event.getOldValue()),
() -> assertEquals(propertyValue, event.getNewValue()),
() -> assertEquals("port", event.getPropertyName())
);

Expand Down

0 comments on commit 8197344

Please sign in to comment.