Issue #23507 config-api uses junit5 instead of junit4
- some tests were bit extended, some were deleted
diff --git a/nucleus/admin/config-api/pom.xml b/nucleus/admin/config-api/pom.xml
index 52cf426..25383db 100644
--- a/nucleus/admin/config-api/pom.xml
+++ b/nucleus/admin/config-api/pom.xml
@@ -95,6 +95,10 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
</dependency>
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/config/modularity/tests/BasicModularityTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/config/modularity/tests/BasicModularityTest.java
index 7f2be56..33f079c 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/config/modularity/tests/BasicModularityTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/config/modularity/tests/BasicModularityTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -23,17 +24,21 @@
import com.sun.enterprise.config.serverbeans.Config;
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.configapi.tests.ConfigApiTest;
-import org.glassfish.hk2.api.ServiceLocator;
-import org.glassfish.hk2.runlevel.RunLevelController;
-import org.glassfish.server.ServerEnvironmentImpl;
-import org.glassfish.tests.utils.Utils;
-import org.junit.Test;
-import org.jvnet.hk2.config.ConfigBeanProxy;
-import org.jvnet.hk2.config.types.Property;
import java.util.List;
-import static org.junit.Assert.*;
+import org.glassfish.api.admin.ServerEnvironment;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.hk2.runlevel.RunLevelController;
+import org.glassfish.tests.utils.Utils;
+import org.junit.jupiter.api.Test;
+import org.jvnet.hk2.config.ConfigBeanProxy;
+import org.jvnet.hk2.config.types.Property;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Testing Basic Functionality of Config Modularity API
@@ -42,7 +47,7 @@
*/
public class BasicModularityTest extends ConfigApiTest {
- private ServiceLocator habitat = Utils.instance.getHabitat(this);
+ private final ServiceLocator habitat = Utils.instance.getHabitat(this);
ConfigModularityUtils configModularityUtils = habitat.getService(ConfigModularityUtils.class);
@@ -56,117 +61,140 @@
// This part passes as the configuration for the class is present in the domain.xml
Class clz = configModularityUtils.getClassForFullName(ConfigExtensionZero.class.getName());
- assertNotNull("Cannot get config bean class using the class name", clz);
- assertEquals("The mapped class is not the same as the provided class name", ConfigExtensionZero.class.getName(), clz.getName());
+ assertNotNull(clz, "Cannot get config bean class using the class name");
+ assertEquals(ConfigExtensionZero.class.getName(), clz.getName(), "The mapped class is not the same as the provided class name");
// this part fails as the configuration is not present in domain.xml which was is a regression somewhere
clz = configModularityUtils.getClassForFullName(ConfigExtensionTwo.class.getName());
- assertNotNull("Cannot get config bean class using the class name", clz);
- assertEquals("The mapped class is not the same as the provided class name", ConfigExtensionTwo.class.getName(), clz.getName());
+ assertNotNull(clz, "Cannot get config bean class using the class name");
+ assertEquals(ConfigExtensionTwo.class.getName(), clz.getName(), "The mapped class is not the same as the provided class name");
}
@Test
public void locationTest() {
String location = "domain/configs/config[$CURRENT_INSTANCE_CONFIG_NAME]/config-extension-one/property[prop.foo]";
Class owningClass = configModularityUtils.getOwningClassForLocation(location);
- assertNotNull("Cannot find owning class for: " + location, owningClass);
- assertEquals("Cannot find the right owning class for location", Property.class.getName(), owningClass.getName());
+ assertNotNull(owningClass, "Cannot find owning class for: " + location);
+ assertEquals(Property.class.getName(), owningClass.getName(), "Cannot find the right owning class for location");
}
@Test
public void owningObjectTest() {
String location = "domain/configs/config[$CURRENT_INSTANCE_CONFIG_NAME]/config-extension-one/property[prop.foo]";
ConfigBeanProxy obj = configModularityUtils.getOwningObject(location);
- assertNotNull("Cannot find owning object for: " + location, obj);
- assertEquals("Getting Owning object for location is not right", "prop.foo.value.custom", ((Property) obj).getValue());
+ assertNotNull(obj, "Cannot find owning object for: " + location);
+ assertEquals("prop.foo.value.custom", ((Property) obj).getValue(), "Getting Owning object for location is not right");
}
@Test
public void moduleConfigurationXmlParserTest() {
List<com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue> values = configModularityUtils.getDefaultConfigurations(SimpleExtensionTypeOne.class, "admin-");
- assertEquals("Incorrect number of config bean configuration read ", 2, values.size());
+ assertEquals(2, values.size(), "Incorrect number of config bean configuration read ");
ConfigCustomizationToken token = configModularityUtils.getDefaultConfigurations(SimpleExtensionTypeOne.class, "embedded-").get(0).getCustomizationTokens().get(0);
- assertEquals("Customization Token reading broken ", "CUSTOM_TOKEN", token.getName());
- assertEquals("Customization Token reading broken ", "token-default-value", token.getValue());
+ assertEquals("CUSTOM_TOKEN", token.getName(), "Customization Token reading broken ");
+ assertEquals("token-default-value", token.getValue(), "Customization Token reading broken ");
}
@Test
public void serializeConfigBean() {
- Config config = habitat.<Config>getService(Config.class, ServerEnvironmentImpl.DEFAULT_INSTANCE_NAME);
- ConfigBeanProxy prox = (ConfigBeanProxy) config.getExtensionByType(ConfigExtensionZero.class);
+ Config config = habitat.<Config>getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
+ ConfigBeanProxy prox = config.getExtensionByType(ConfigExtensionZero.class);
String content = configModularityUtils.serializeConfigBean(prox);
- assertEquals("Cannot serialize config beans properly", "<config-extension-zero dummy=\"dummy-value\"></config-extension-zero>", content);
+ assertEquals("<config-extension-zero dummy=\"dummy-value\"></config-extension-zero>", content,
+ "Cannot serialize config beans properly");
}
@Test
public void serializeConfigBeanByType() {
String content = configModularityUtils.serializeConfigBeanByType(ConfigExtensionOne.class);
- assertEquals("Cannot serialize config beans from type", "<config-extension-one custom-token=\"${CUSTOM_TOKEN}\">\n" +
+ assertEquals("<config-extension-one custom-token=\"${CUSTOM_TOKEN}\">\n" +
" <property name=\"prop.foo\" value=\"prop.foo.value.custom\"></property>\n" +
- "</config-extension-one>", content);
+ "</config-extension-one>", content, "Cannot serialize config beans from type");
}
@Test
public void testConfigExtensionPatternImpl() {
- Config config = habitat.<Config>getService(Config.class, ServerEnvironmentImpl.DEFAULT_INSTANCE_NAME);
+ Config config = habitat.<Config>getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
SimpleConfigExtension simpleConfigExtension = config.getExtensionByType(SimpleConfigExtension.class);
SimpleExtensionTypeTwo typeTwo = simpleConfigExtension.getExtensionByType(SimpleExtensionTypeTwo.class);
- assertNotNull("cannot get extension using extensionmethod", typeTwo);
- assertEquals("Retrieved extension is not from the right type... ", "attribute.two", typeTwo.getAttributeTwo());
+ assertNotNull(typeTwo, "cannot get extension using extensionmethod");
+ assertEquals("attribute.two", typeTwo.getAttributeTwo(), "Retrieved extension is not from the right type... ");
}
@Test
public void testLoadingAndApplyingModuleConfigurationFile() {
- Config config = habitat.<Config>getService(Config.class, ServerEnvironmentImpl.DEFAULT_INSTANCE_NAME);
+ Config config = habitat.<Config>getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
ConfigExtensionTwo ext = config.getExtensionByType(ConfigExtensionTwo.class);
- assertEquals("The system property is overridden while it should have not", "user.customized.value", config.getSystemProperty("CUSTOM_TOKEN").getValue());
- assertTrue("Failed to add the extension from module configuration file: ", config.checkIfExtensionExists(ConfigExtensionTwo.class));
+ assertNotNull(ext);
+ assertEquals("user.customized.value", config.getSystemProperty("CUSTOM_TOKEN").getValue(),
+ "The system property is overridden while it should have not");
+ assertTrue(config.checkIfExtensionExists(ConfigExtensionTwo.class),
+ "Failed to add the extension from module configuration file: ");
}
@Test
public void testHasNoCustomization() {
- Config config = habitat.<Config>getService(Config.class, ServerEnvironmentImpl.DEFAULT_INSTANCE_NAME);
- assertNull("The @HasNocustomization annotation is broken", config.getExtensionByType(ConfigExtensionThree.class));
+ Config config = habitat.<Config>getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
+ assertNull(config.getExtensionByType(ConfigExtensionThree.class), "The @HasNocustomization annotation is broken");
}
@Test
public void getCurrentConfigurationForConfigBean() throws Exception {
- List<com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue> values = configModularityUtils.getDefaultConfigurations(SimpleExtensionTypeOne.class, "admin-");
- com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue def = configModularityUtils.getDefaultConfigurations(SimpleExtensionTypeOne.class, "embedded-").get(0);
+ com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue def = configModularityUtils
+ .getDefaultConfigurations(SimpleExtensionTypeOne.class, "embedded-").get(0);
SimpleExtensionTypeOne simple = configModularityUtils.getCurrentConfigBeanForDefaultValue(def);
- assertNotNull("Cannot get config bean of a module based on the default module configuration information", simple);
+ assertNotNull(simple,
+ "Cannot get config bean of a module based on the default module configuration information");
}
@Test
public void testLoadingAdminFile() throws Exception {
- List<com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue> values = configModularityUtils.getDefaultConfigurations(ConfigExtensionTwo.class, "admin");
- assertEquals("Incorrect customization type loaded ", ConfigCustomizationToken.CustomizationType.FILE, values.get(0).getCustomizationTokens().get(0).getCustomizationType());
- assertEquals("Incorrect customization details value ", FileTypeDetails.FileExistCondition.MUST_EXIST, ((FileTypeDetails) values.get(0).getCustomizationTokens().get(0).getTokenTypeDetails()).getExistCondition());
+ List<com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue> values = configModularityUtils
+ .getDefaultConfigurations(ConfigExtensionTwo.class, "admin");
+ assertEquals(ConfigCustomizationToken.CustomizationType.FILE,
+ values.get(0).getCustomizationTokens().get(0).getCustomizationType(),
+ "Incorrect customization type loaded ");
+ assertEquals(FileTypeDetails.FileExistCondition.MUST_EXIST,
+ ((FileTypeDetails) values.get(0).getCustomizationTokens().get(0).getTokenTypeDetails()).getExistCondition(),
+ "Incorrect customization details value ");
}
+
@Test
public void testLoadingEmbeddedFile() throws Exception {
- List<com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue> values = values = configModularityUtils.getDefaultConfigurations(ConfigExtensionTwo.class, "embedded");
- assertEquals("Incorrect customization type loaded ", ConfigCustomizationToken.CustomizationType.PORT, values.get(0).getCustomizationTokens().get(0).getCustomizationType());
- assertEquals("Incorrect customization details value ", "1000", ((PortTypeDetails) values.get(0).getCustomizationTokens().get(0).getTokenTypeDetails()).getBaseOffset());
- assertEquals("validation expression is returned incorrectly ", "[a-zA-Z0-9]+", values.get(0).getCustomizationTokens().get(0).getValidationExpression());
+ List<com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue> values = configModularityUtils
+ .getDefaultConfigurations(ConfigExtensionTwo.class, "embedded");
+ assertEquals(ConfigCustomizationToken.CustomizationType.PORT,
+ values.get(0).getCustomizationTokens().get(0).getCustomizationType(),
+ "Incorrect customization type loaded ");
+ assertEquals("1000",
+ ((PortTypeDetails) values.get(0).getCustomizationTokens().get(0).getTokenTypeDetails()).getBaseOffset(),
+ "Incorrect customization details value ");
+ assertEquals("[a-zA-Z0-9]+", values.get(0).getCustomizationTokens().get(0).getValidationExpression(),
+ "validation expression is returned incorrectly ");
}
+
@Test
public void testLoadingDefaultFile() throws Exception {
- List<com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue> values = configModularityUtils.getDefaultConfigurations(ConfigExtensionTwo.class, "non-existing-runtime-type");
- assertEquals("validation expression is returned incorrectly ", ".*[0-9]{10}.*", values.get(0).getCustomizationTokens().get(0).getValidationExpression());
+ List<com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue> values = configModularityUtils
+ .getDefaultConfigurations(ConfigExtensionTwo.class, "non-existing-runtime-type");
+ assertEquals(".*[0-9]{10}.*", values.get(0).getCustomizationTokens().get(0).getValidationExpression(),
+ "validation expression is returned incorrectly ");
}
+
@Test
public void tesOnTheFlyConfigurationGenerationMethod() {
- List<com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue> values = configModularityUtils.getDefaultConfigurations(SimpleExtensionThree.class, "non-existing-runtime-type");
- assertEquals("On the fly config generation/reading is broken", "<xml-doc></xml-doc>", values.get(0).getXmlConfiguration());
+ List<com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue> values = configModularityUtils
+ .getDefaultConfigurations(SimpleExtensionThree.class, "non-existing-runtime-type");
+ assertEquals("<xml-doc></xml-doc>", values.get(0).getXmlConfiguration(),
+ "On the fly config generation/reading is broken");
}
@@ -174,10 +202,10 @@
public void testRanking() {
Domain d = habitat.<Domain>getService(Domain.class);
RankedConfigBean rankedConfigBean = d.getExtensionByType(RankedConfigBean.class);
- assertEquals("invalid current value", "simple-value-zero",rankedConfigBean.getSimpleAttribute());
+ assertEquals("simple-value-zero",rankedConfigBean.getSimpleAttribute(), "invalid current value");
ensureRunLevel(4);
rankedConfigBean = d.getExtensionByType(RankedConfigBean.class);
- assertEquals("invalid current value", "simple-value-one", rankedConfigBean.getSimpleAttribute() );
+ assertEquals("simple-value-one", rankedConfigBean.getSimpleAttribute() , "invalid current value");
}
//TODO add more tests to cover token processing and i18n support
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/AddPropertyTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/AddPropertyTest.java
index 83a2c21..3b2190e 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/AddPropertyTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/AddPropertyTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -17,26 +18,26 @@
package com.sun.enterprise.configapi.tests;
import com.sun.enterprise.config.serverbeans.Domain;
-import org.jvnet.hk2.config.types.Property;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
-import org.jvnet.hk2.config.Changed;
+
+import java.beans.PropertyChangeEvent;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigBean;
-import org.jvnet.hk2.config.ConfigBeanProxy;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.Dom;
-import org.jvnet.hk2.config.NotProcessed;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
import org.jvnet.hk2.config.TransactionListener;
import org.jvnet.hk2.config.Transactions;
import org.jvnet.hk2.config.UnprocessedChangeEvents;
+import org.jvnet.hk2.config.types.Property;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyVetoException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* User: Jerome Dochez
@@ -45,20 +46,27 @@
*/
public class AddPropertyTest extends ConfigApiTest {
+ private List<PropertyChangeEvent> events;
+
+ @Override
public String getFileName() {
return "DomainTest";
}
- List<PropertyChangeEvent> events = null;
@Test
public void transactionEvents() throws TransactionFailure {
final Domain domain = getHabitat().getService(Domain.class);
+ assertNotNull(domain);
final TransactionListener listener = new TransactionListener() {
- public void transactionCommited(List<PropertyChangeEvent> changes) {
- events = changes;
- }
+ @Override
+ public void transactionCommited(List<PropertyChangeEvent> changes) {
+ events = changes;
+ }
+
+
+ @Override
public void unprocessedTransactedEvents(List<UnprocessedChangeEvents> changes) {
}
};
@@ -68,28 +76,21 @@
try {
transactions.addTransactionsListener(listener);
- assertTrue(domain!=null);
- ConfigSupport.apply(new SingleConfigCode<Domain>() {
-
- public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
- Property prop = domain.createChild(Property.class);
- domain.getProperty().add(prop);
- prop.setName("Jerome");
- prop.setValue("was here");
- return prop;
- }
- }, domain);
+ SingleConfigCode<Domain> configCode = (SingleConfigCode<Domain>) domain1 -> {
+ Property prop = domain1.createChild(Property.class);
+ domain1.getProperty().add(prop);
+ prop.setName("Jerome");
+ prop.setValue("was here");
+ return prop;
+ };
+ ConfigSupport.apply(configCode, domain);
transactions.waitForDrain();
- assertTrue(events!=null);
- logger.fine("Number of events " + events.size());
- assertTrue(events.size()==3);
- for (PropertyChangeEvent event : events) {
- logger.fine(event.toString());
- }
+ assertNotNull(events);
+ assertThat(events, hasSize(3));
- Map<String, String> configChanges = new HashMap<String, String>();
+ Map<String, String> configChanges = new HashMap<>();
configChanges.put("name", "julien");
configChanges.put("value", "petit clown");
ConfigBean domainBean = (ConfigBean) Dom.unwrap(domain);
@@ -98,28 +99,8 @@
transactions.waitForDrain();
- assertTrue(events!=null);
- logger.fine("Number of events " + events.size());
- assertTrue(events.size()==3);
- for (PropertyChangeEvent event : events) {
- logger.fine(event.toString());
- }
-
- final UnprocessedChangeEvents unprocessed =
- ConfigSupport.sortAndDispatch(events.toArray(new PropertyChangeEvent[0]), new Changed() {
- /**
- * Notification of a change on a configuration object
- *
- * @param type type of change : ADD mean the changedInstance was added to the parent
- * REMOVE means the changedInstance was removed from the parent, CHANGE means the
- * changedInstance has mutated.
- * @param changedType type of the configuration object
- * @param changedInstance changed instance.
- */
- public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> changedType, T changedInstance) {
- return new NotProcessed("unimplemented by AddPropertyTest");
- }
- }, logger);
+ assertNotNull(events);
+ assertThat(events, hasSize(3));
} finally {
transactions.removeTransactionsListener(listener);
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ApplicationsTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ApplicationsTest.java
index e46b387..fa043b3 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ApplicationsTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ApplicationsTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,14 +17,23 @@
package com.sun.enterprise.configapi.tests;
-import org.junit.Test;
-import static org.junit.Assert.assertTrue;
-import org.glassfish.api.admin.config.ApplicationName;
-import org.jvnet.hk2.config.*;
-import com.sun.enterprise.config.serverbeans.*;
+import com.sun.enterprise.config.serverbeans.Application;
+import com.sun.enterprise.config.serverbeans.Applications;
import java.util.List;
-import java.beans.*;
+
+import org.glassfish.api.admin.config.ApplicationName;
+import org.junit.jupiter.api.Test;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.SingleConfigCode;
+import org.jvnet.hk2.config.TransactionFailure;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Applications related tests
@@ -31,7 +41,7 @@
*/
public class ApplicationsTest extends ConfigApiTest {
-
+ @Override
public String getFileName() {
return "DomainTest";
}
@@ -39,48 +49,41 @@
@Test
public void appsExistTest() {
Applications apps = getHabitat().getService(Applications.class);
- assertTrue(apps!=null);
+ assertNotNull(apps);
+ assertThat(apps.getApplications(), hasSize(1));
}
@Test
public void getModulesTest() {
Applications apps = getHabitat().getService(Applications.class);
List<ApplicationName> modules = apps.getModules();
- for (ApplicationName module : modules) {
- logger.fine("Module = " + module.getName());
- }
- assertTrue(modules!=null);
+ assertThat(modules, hasSize(1));
}
@Test
public void getApplicationTest() {
Applications apps = getHabitat().getService(Applications.class);
Application app = apps.getApplication("simple");
- assertTrue(app != null);
+ assertNotNull(app);
}
/**
* Test which is expecting an UnsupportedOperationException since we are
* operating on a copy list of the original getModules() list.
- *
- * @throws TransactionFailure
*/
- @Test(expected = UnsupportedOperationException.class)
- public void removalTest() throws Throwable {
- Applications apps = getHabitat().getService(Applications.class);
- try {
- ConfigSupport.apply(new SingleConfigCode<Applications>() {
- public Object run(Applications param) throws PropertyVetoException, TransactionFailure {
- List<Application> appList = param.getApplications();
- for (Application application : param.getApplicationsWithSnifferType("web")) {
- assertTrue(appList.remove(application));
- }
- return null;
- }
- }, apps);
- } catch(TransactionFailure e) {
- // good, an exception was thrown, hopfully the right one !
- throw e.getCause();
- }
+ @Test
+ public void removalTest() {
+ final Applications apps = getHabitat().getService(Applications.class);
+ final SingleConfigCode<Applications> configCode = param -> {
+ List<Application> appList = param.getApplications();
+ for (Application application : param.getApplicationsWithSnifferType("web")) {
+ assertTrue(appList.remove(application));
+ }
+ return null;
+ };
+ final TransactionFailure failure = assertThrows(TransactionFailure.class, () -> {
+ ConfigSupport.apply(configCode, apps);
+ });
+ assertThat(failure.getCause(), instanceOf(UnsupportedOperationException.class));
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/AttributeRemovalTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/AttributeRemovalTest.java
index 59c5a27..db04480 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/AttributeRemovalTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/AttributeRemovalTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,18 +17,21 @@
package com.sun.enterprise.configapi.tests;
-import com.sun.enterprise.config.serverbeans.Server;
-import org.junit.Test;
-import org.junit.Before;
-import org.jvnet.hk2.config.*;
-import org.glassfish.tests.utils.Utils;
import com.sun.enterprise.config.serverbeans.HttpService;
+import com.sun.enterprise.config.serverbeans.Server;
import com.sun.enterprise.config.serverbeans.VirtualServer;
-import java.beans.PropertyChangeEvent;
import java.beans.PropertyVetoException;
-import java.util.List;
-import java.util.logging.Level;
+import org.glassfish.tests.utils.Utils;
+import org.junit.jupiter.api.Test;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.SingleConfigCode;
+import org.jvnet.hk2.config.TransactionFailure;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* User: Jerome Dochez
@@ -36,6 +40,7 @@
*/
public class AttributeRemovalTest extends ConfigApiTest {
+ @Override
public String getFileName() {
return "DomainTest";
}
@@ -44,66 +49,45 @@
public void removeAttributeTest() throws TransactionFailure {
HttpService httpService = Utils.instance.getHabitat(this).getService(HttpService.class);
VirtualServer vs = httpService.getVirtualServerByName("server");
- ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {
+ SingleConfigCode<VirtualServer> configCodeWebModule = virtualServer -> {
+ virtualServer.setDefaultWebModule("/context/bar");
+ return null;
+ };
+ ConfigSupport.apply(configCodeWebModule, vs);
+ assertNotNull(vs.getDefaultWebModule());
- public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
- param.setDefaultWebModule("/context/bar");
- return null;
- }
- }, vs);
-
- // ensure it's here
- org.junit.Assert.assertNotNull(vs.getDefaultWebModule());
-
- ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {
-
- public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
- param.setDefaultWebModule(null);
- return null;
- }
- }, vs);
-
- // ensure it's removed
- org.junit.Assert.assertNull(vs.getDefaultWebModule());
- }
-
- @Test(expected=PropertyVetoException.class)
- public void readOnlyRemovalTest() throws TransactionFailure , PropertyVetoException{
- Server server = getHabitat().getService(Server.class);
- logger.fine("config-ref is " + server.getConfigRef());
- try {
- server.setConfigRef(null);
- } catch (PropertyVetoException e) {
- if (logger.isLoggable(Level.FINE))
- e.printStackTrace();
- throw e;
- }
+ SingleConfigCode<VirtualServer> configCodeNullWebModule = virtualServer -> {
+ virtualServer.setDefaultWebModule(null);
+ return null;
+ };
+ ConfigSupport.apply(configCodeNullWebModule, vs);
+ assertNull(vs.getDefaultWebModule());
}
@Test
+ public void readOnlyRemovalTest(){
+ Server server = getHabitat().getService(Server.class);
+ logger.fine("config-ref is " + server.getConfigRef());
+ assertThrows(PropertyVetoException.class, () -> server.setConfigRef(null));
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
public void deprecatedWrite() throws TransactionFailure {
final Server server = getHabitat().getService(Server.class);
final String value = server.getNodeRef();
- logger.fine("node-ref is " + server.getNodeRef());
- ConfigSupport.apply(new SingleConfigCode<Server>() {
- @Override
- public Object run(Server s) throws PropertyVetoException, TransactionFailure {
- s.setNodeAgentRef(value);
- return null;
- }
- }, server);
- logger.fine("node-agent-ref is " + server.getNodeAgentRef());
- // restore
- ConfigSupport.apply(new SingleConfigCode<Server>() {
- @Override
- public Object run(Server s) throws PropertyVetoException, TransactionFailure {
- s.setNodeAgentRef(null);
- return null;
- }
- }, server);
- logger.fine("after, node-agent-ref is " + server.getNodeAgentRef());
+ final SingleConfigCode<Server> configCode = virtualServer -> {
+ virtualServer.setNodeAgentRef(null);
+ return null;
+ };
+ ConfigSupport.apply(configCode, server);
+ assertNull(server.getNodeRef());
+ SingleConfigCode<Server> restoreConfig = virtualServer -> {
+ virtualServer.setNodeAgentRef(value);
+ return null;
+ };
+ ConfigSupport.apply(restoreConfig, server);
+ assertEquals(value, server.getNodeAgentRef());
}
-
-
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/CollectionsAccessTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/CollectionsAccessTest.java
index 59345e9..496921f 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/CollectionsAccessTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/CollectionsAccessTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,17 +17,19 @@
package com.sun.enterprise.configapi.tests;
-import org.junit.Test;
-import static org.junit.Assert.*;
-import org.jvnet.hk2.config.TransactionFailure;
-import org.jvnet.hk2.config.ConfigSupport;
-import org.jvnet.hk2.config.SingleConfigCode;
-import org.glassfish.api.admin.config.ApplicationName;
-import com.sun.enterprise.config.serverbeans.Applications;
import com.sun.enterprise.config.serverbeans.Application;
+import com.sun.enterprise.config.serverbeans.Applications;
import java.util.List;
-import java.beans.PropertyVetoException;
+
+import org.glassfish.api.admin.config.ApplicationName;
+import org.junit.jupiter.api.Test;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.SingleConfigCode;
+import org.jvnet.hk2.config.TransactionFailure;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* User: Jerome Dochez
@@ -36,48 +39,46 @@
public class CollectionsAccessTest extends ConfigApiTest {
+ @Override
public String getFileName() {
return "DomainTest";
}
- @Test(expected=IllegalStateException.class)
- public void unprotectedAccess() throws IllegalStateException {
+ @Test
+ public void unprotectedAccess() {
Applications apps = getHabitat().getService(Applications.class);
- assertTrue(apps!=null);
- apps.getModules().add(null);
+ assertNotNull(apps);
+ assertThrows(IllegalStateException.class, () -> apps.getModules().add(null));
}
- @Test(expected= TransactionFailure.class)
+ @Test
public void semiProtectedTest() throws TransactionFailure {
final Applications apps = getHabitat().getService(Applications.class);
- assertTrue(apps!=null);
- ConfigSupport.apply(new SingleConfigCode<Applications>() {
- public Object run(Applications param) throws PropertyVetoException, TransactionFailure {
- // this is the bug, we should not get the list from apps but from param.
- List<ApplicationName> modules = apps.getModules();
- Application m = param.createChild(Application.class);
- modules.add(m); // should throw an exception
- return m;
- }
- }, apps);
+ assertNotNull(apps);
+ SingleConfigCode<Applications> configCode = proxy -> {
+ List<ApplicationName> modules = proxy.getModules();
+ Application m = proxy.createChild(Application.class);
+ modules.add(m);
+ return m;
+ };
+ assertThrows(TransactionFailure.class, () -> ConfigSupport.apply(configCode, apps));
}
@Test
public void protectedTest() throws TransactionFailure {
final Applications apps = getHabitat().getService(Applications.class);
- assertTrue(apps!=null);
- ConfigSupport.apply(new SingleConfigCode<Applications>() {
- public Object run(Applications param) throws PropertyVetoException, TransactionFailure {
- List<ApplicationName> modules = param.getModules();
- Application m = param.createChild(Application.class);
- m.setName( "ejb-test" );
- m.setLocation("test-location");
- m.setObjectType("ejb");
- modules.add(m);
- modules.remove(m);
- return m;
- }
- }, apps);
+ assertNotNull(apps);
+ SingleConfigCode<Applications> configCode = proxy -> {
+ List<ApplicationName> modules = proxy.getModules();
+ Application m = proxy.createChild(Application.class);
+ m.setName( "ejb-test" );
+ m.setLocation("test-location");
+ m.setObjectType("ejb");
+ modules.add(m);
+ modules.remove(m);
+ return m;
+ };
+ ConfigSupport.apply(configCode, apps);
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ConfigApiTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ConfigApiTest.java
index 8a0e9c4..29a21f2 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ConfigApiTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ConfigApiTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -21,10 +22,11 @@
import org.glassfish.config.support.GlassFishDocument;
import org.glassfish.hk2.api.ActiveDescriptor;
import org.glassfish.hk2.api.ServiceLocator;
-import org.glassfish.hk2.utilities.BuilderHelper;
import org.glassfish.hk2.utilities.ServiceLocatorUtilities;
import org.jvnet.hk2.config.DomDocument;
+import static org.glassfish.hk2.utilities.BuilderHelper.createConstantDescriptor;
+
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import org.glassfish.api.admin.ServerEnvironment;
@@ -39,36 +41,39 @@
@Override
public DomDocument getDocument(ServiceLocator habitat) {
DomDocument doc = habitat.getService(GlassFishDocument.class);
- if (doc==null) {
+ if (doc == null) {
return new GlassFishDocument(habitat, Executors.newCachedThreadPool(new ThreadFactory() {
- public Thread newThread(Runnable r) {
- Thread t = Executors.defaultThreadFactory().newThread(r);
- t.setDaemon(true);
- return t;
- }
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread t = Executors.defaultThreadFactory().newThread(r);
+ t.setDaemon(true);
+ return t;
+ }
- }));
+ }));
}
return doc;
}
+
@Override
- public void decorate(ServiceLocator habitat) {
- Server server = habitat.getService(Server.class, "server");
- if (server != null) {
- ActiveDescriptor<Server> serverDescriptor = BuilderHelper.createConstantDescriptor(server,
- ServerEnvironment.DEFAULT_INSTANCE_NAME, Server.class);
- ServiceLocatorUtilities.addOneDescriptor(habitat, serverDescriptor);
+ public void decorate(ServiceLocator locator) {
+ Server server = locator.getService(Server.class, "server");
+ if (server == null) {
+ return;
+ }
+ ActiveDescriptor<Server> serverDescriptor
+ = createConstantDescriptor(server, ServerEnvironment.DEFAULT_INSTANCE_NAME, Server.class);
+ ServiceLocatorUtilities.addOneDescriptor(locator, serverDescriptor);
- server.getConfig().addIndex(habitat, ServerEnvironment.DEFAULT_INSTANCE_NAME);
+ server.getConfig().addIndex(locator, ServerEnvironment.DEFAULT_INSTANCE_NAME);
- Cluster c = server.getCluster();
- if (c != null) {
- ActiveDescriptor<Cluster> clusterDescriptor = BuilderHelper.createConstantDescriptor(c,
- ServerEnvironment.DEFAULT_INSTANCE_NAME, Cluster.class);
- ServiceLocatorUtilities.addOneDescriptor(habitat, clusterDescriptor);
- }
+ Cluster c = server.getCluster();
+ if (c != null) {
+ ActiveDescriptor<Cluster> clusterDescriptor
+ = createConstantDescriptor(c, ServerEnvironment.DEFAULT_INSTANCE_NAME, Cluster.class);
+ ServiceLocatorUtilities.addOneDescriptor(locator, clusterDescriptor);
}
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ConfigListenerTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ConfigListenerTest.java
index 171b7c4..0121998 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ConfigListenerTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ConfigListenerTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,129 +17,112 @@
package com.sun.enterprise.configapi.tests;
+import com.sun.enterprise.configapi.tests.example.HttpListenerContainer;
+
+import org.glassfish.config.support.ConfigConfigBeanListener;
import org.glassfish.grizzly.config.dom.NetworkListener;
import org.glassfish.hk2.api.DynamicConfiguration;
import org.glassfish.hk2.api.DynamicConfigurationService;
import org.glassfish.hk2.api.ServiceHandle;
import org.glassfish.hk2.api.ServiceLocator;
-
-import org.glassfish.config.support.ConfigConfigBeanListener;
import org.glassfish.tests.utils.Utils;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.ObservableBean;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
import org.jvnet.hk2.config.Transactions;
-import com.sun.enterprise.config.serverbeans.Config;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Simple ConfigListener tests
*/
public class ConfigListenerTest extends ConfigApiTest {
- ServiceLocator habitat;
+ private static final SingleConfigCode<NetworkListener> configCodeRestore = param -> {
+ param.setPort("8080");
+ return null;
+ };
+
+ private ServiceLocator habitat;
+ private Transactions transactions;
+ private HttpListenerContainer container;
+
@Override
public String getFileName() {
return "DomainTest";
}
- @Before
+ @BeforeEach
public void setup() {
habitat = Utils.instance.getHabitat(this);
// make sure the ConfigConfigListener exists
ServiceHandle<ConfigConfigBeanListener> i = habitat.getServiceHandle(ConfigConfigBeanListener.class);
ConfigConfigBeanListener ccbl = i.getService();
- assertTrue(ccbl != null);
+ assertNotNull(ccbl);
+ transactions = getHabitat().getService(Transactions.class);
+ container = registerAndCreateHttpListenerContainer(habitat);
}
- private HttpListenerContainer registerAndCreateHttpListenerContainer(ServiceLocator locator) {
- HttpListenerContainer retVal = locator.getService(HttpListenerContainer.class);
- if (retVal != null) return retVal;
- DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
- Assert.assertNotNull(dcs);
-
- DynamicConfiguration config = dcs.createDynamicConfiguration();
-
- config.addActiveDescriptor(HttpListenerContainer.class);
-
- config.commit();
-
- return locator.getService(HttpListenerContainer.class);
+ @AfterEach
+ public void reset() throws TransactionFailure {
+ ConfigSupport.apply(configCodeRestore, container.httpListener);
+ assertEquals("8080", container.httpListener.getPort());
}
-
@Test
public void changedTest() throws TransactionFailure {
-
- Transactions transactions = getHabitat().getService(Transactions.class);
-
- HttpListenerContainer container = registerAndCreateHttpListenerContainer(habitat);
-
- ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {
-
- @Override
- public Object run(NetworkListener param) {
- param.setPort("8989");
- return null;
- }
- }, container.httpListener);
+ SingleConfigCode<NetworkListener> configCode = listener -> {
+ listener.setPort("8989");
+ return null;
+ };
+ ConfigSupport.apply(configCode, container.httpListener);
+ assertEquals("8989", container.httpListener.getPort());
transactions.waitForDrain();
assertTrue(container.received);
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(container.httpListener);
bean.removeListener(container);
-
- // put back the right values in the domain to avoid test collisions
- ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {
-
- @Override
- public Object run(NetworkListener param) {
- param.setPort("8080");
- return null;
- }
- }, container.httpListener);
}
@Test
public void removeListenerTest() throws TransactionFailure {
-
- Transactions transactions = getHabitat().getService(Transactions.class);
-
- HttpListenerContainer container = registerAndCreateHttpListenerContainer(habitat);
-
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(container.httpListener);
bean.removeListener(container);
- ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {
-
- @Override
- public Object run(NetworkListener param) {
- param.setPort("8989");
- return null;
- }
- }, container.httpListener);
+ SingleConfigCode<NetworkListener> configCode = listener -> {
+ listener.setPort("8989");
+ return null;
+ };
+ ConfigSupport.apply(configCode, container.httpListener);
transactions.waitForDrain();
assertFalse(container.received);
+ }
- // put back the right values in the domain to avoid test collisions
- ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {
- @Override
- public Object run(NetworkListener param) {
- param.setPort("8080");
- return null;
- }
- }, container.httpListener);
+ private HttpListenerContainer registerAndCreateHttpListenerContainer(ServiceLocator locator) {
+ HttpListenerContainer retVal = locator.getService(HttpListenerContainer.class);
+ if (retVal != null) {
+ return retVal;
+ }
+
+ DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
+ assertNotNull(dcs);
+
+ DynamicConfiguration config = dcs.createDynamicConfiguration();
+ config.addActiveDescriptor(HttpListenerContainer.class);
+ config.commit();
+
+ return locator.getService(HttpListenerContainer.class);
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ConfigPersistence.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ConfigPersistence.java
index e9dfe44..1026c91 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ConfigPersistence.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ConfigPersistence.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,8 +17,6 @@
package com.sun.enterprise.configapi.tests;
-import static org.junit.Assert.assertTrue;
-
import java.beans.PropertyChangeEvent;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -29,11 +28,10 @@
import org.glassfish.config.support.ConfigurationPersistence;
import org.glassfish.tests.utils.Utils;
-import org.junit.After;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.DomDocument;
import org.jvnet.hk2.config.IndentingXMLStreamWriter;
-import org.jvnet.hk2.config.TransactionFailure;
import org.jvnet.hk2.config.TransactionListener;
import org.jvnet.hk2.config.Transactions;
import org.jvnet.hk2.config.UnprocessedChangeEvents;
@@ -45,67 +43,62 @@
*/
public abstract class ConfigPersistence extends ConfigApiTest {
- @After
+ public abstract void doTest() throws Exception;
+
+ public abstract void assertResult(String resultingXml);
+
+ @AfterEach
public void tearDown() {
- Utils.instance.shutdownServiceLocator(this);
+ Utils.instance.shutdownServiceLocator(this);
}
- @Test
- public void test() throws TransactionFailure {
+ @Test
+ public void test() throws Exception {
final DomDocument document = getDocument(getHabitat());
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.reset();
- final ConfigurationPersistence testPersistence = new ConfigurationPersistence() {
- public void save(DomDocument doc) throws IOException, XMLStreamException {
- XMLOutputFactory factory = XMLOutputFactory.newInstance();
- XMLStreamWriter writer = factory.createXMLStreamWriter(baos);
+ final ConfigurationPersistence testPersistence = doc -> {
+ XMLOutputFactory factory = XMLOutputFactory.newInstance();
+ XMLStreamWriter writer = factory.createXMLStreamWriter(baos);
+ try {
doc.writeTo(new IndentingXMLStreamWriter(writer));
+ } finally {
writer.close();
}
};
TransactionListener testListener = new TransactionListener() {
+
+ @Override
public void transactionCommited(List<PropertyChangeEvent> changes) {
try {
testPersistence.save(document);
- } catch (IOException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- } catch (XMLStreamException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ } catch (IOException | XMLStreamException e) {
+ e.printStackTrace();
}
}
- public void unprocessedTransactedEvents(List<UnprocessedChangeEvents> changes) {
+ @Override
+ public void unprocessedTransactedEvents(List<UnprocessedChangeEvents> changes) {
}
};
Transactions transactions = getHabitat().getService(Transactions.class);
try {
transactions.addTransactionsListener(testListener);
-
doTest();
- } catch(TransactionFailure f) {
- f.printStackTrace();
- throw f;
-
} finally {
transactions.waitForDrain();
transactions.removeTransactionsListener(testListener);
}
// now check if we persisted correctly...
-
final String resultingXml = baos.toString();
-
logger.fine(resultingXml);
- assertTrue("assertResult from " + getClass().getName() + " was false from " + resultingXml, assertResult(resultingXml));
+ assertResult(resultingXml);
}
-
- public abstract void doTest() throws TransactionFailure;
-
- public abstract boolean assertResult(String resultingXml);
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DeepCopyTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DeepCopyTest.java
index 107736c..ab933c6 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DeepCopyTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DeepCopyTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -18,19 +19,27 @@
import com.sun.enterprise.config.serverbeans.Config;
import com.sun.enterprise.config.serverbeans.Configs;
-import org.glassfish.config.support.ConfigurationPersistence;
-import org.junit.Assert;
-import org.junit.Test;
-import org.jvnet.hk2.config.*;
+
+import java.io.ByteArrayOutputStream;
+import java.util.logging.Level;
import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
-import java.beans.PropertyVetoException;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.logging.Level;
+
+import org.junit.jupiter.api.Test;
+import org.jvnet.hk2.config.ConfigBeanProxy;
+import org.jvnet.hk2.config.ConfigModel;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.Dom;
+import org.jvnet.hk2.config.DomDocument;
+import org.jvnet.hk2.config.IndentingXMLStreamWriter;
+import org.jvnet.hk2.config.SingleConfigCode;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.stringContainsInOrder;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Test the deepCopy feature of ConfigBeans.
@@ -39,6 +48,10 @@
*/
public class DeepCopyTest extends ConfigApiTest {
+ private final DomDocument document = getDocument(getHabitat());
+
+
+ @Override
public String getFileName() {
return "DomainTest";
}
@@ -46,57 +59,42 @@
@Test
public void configCopy() throws Exception {
final Config config = getHabitat().getService(Config.class);
- Assert.assertNotNull(config);
+ assertNotNull(config);
String configName = config.getName();
- final Config newConfig = (Config) ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() {
- @Override
- public Object run(ConfigBeanProxy parent) throws PropertyVetoException, TransactionFailure {
- return config.deepCopy(parent);
- }
- }, config.getParent());
- Assert.assertNotNull(newConfig);
- try {
- newConfig.setName("some-config");
- } catch(Exception e) {
- // I was expecting this...
- }
- ConfigSupport.apply(new SingleConfigCode<Config>() {
- @Override
- public Object run(Config wConfig) throws PropertyVetoException, TransactionFailure {
- wConfig.setName("some-config");
- return null;
- }
- }, newConfig);
- Assert.assertEquals(newConfig.getName(), "some-config");
- Assert.assertEquals(config.getName(), configName);
+ final Config newConfig = (Config) ConfigSupport.apply(parent -> config.deepCopy(parent), config.getParent());
+ assertNotNull(newConfig);
+ assertThrows(IllegalStateException.class, () -> newConfig.setName("some-config"));
+ SingleConfigCode<Config> configCode = cfg -> {
+ cfg.setName("some-config");
+ return null;
+ };
+ ConfigSupport.apply(configCode, newConfig);
+ assertEquals("some-config", newConfig.getName());
+ assertEquals(configName, config.getName());
// add it the parent
- ConfigSupport.apply(new SingleConfigCode<Configs>() {
- @Override
- public Object run(Configs wConfigs) throws PropertyVetoException, TransactionFailure {
- wConfigs.getConfig().add(newConfig);
- return null;
- }
- }, getHabitat().<Configs>getService(Configs.class));
- String resultingXML = save(document).toString();
- Assert.assertTrue("Expecting some-config, got " + resultingXML, resultingXML.contains("some-config"));
+ SingleConfigCode<Configs> configCodeParent = configs -> {
+ configs.getConfig().add(newConfig);
+ return null;
+ };
+ ConfigSupport.apply(configCodeParent, getHabitat().<Configs>getService(Configs.class));
+ String resultingXML = save(document);
+ assertThat("Expecting some-config, got " + resultingXML, resultingXML, stringContainsInOrder("some-config"));
}
@Test
public void parentingTest() throws Exception {
final Config config = getHabitat().getService(Config.class);
- Assert.assertNotNull(config);
- String configName = config.getName();
- final Config newConfig = (Config) ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() {
- @Override
- public Object run(ConfigBeanProxy parent) throws PropertyVetoException, TransactionFailure {
- Config newConfig = (Config) config.deepCopy(parent);
- newConfig.setName("cloned-config");
- return newConfig;
- }
- }, config.getParent());
- Assert.assertNotNull(newConfig);
+ assertNotNull(config);
+ assertEquals("server-config", config.getName());
+ SingleConfigCode<ConfigBeanProxy> configCode = configProxy -> {
+ Config newConfig1 = (Config) config.deepCopy(configProxy);
+ newConfig1.setName("cloned-config");
+ return newConfig1;
+ };
+ final Config newConfig = (Config) ConfigSupport.apply(configCode, config.getParent());
+ assertNotNull(newConfig);
// now let's check the parents are correct.
Dom original = Dom.unwrap(config);
@@ -112,48 +110,56 @@
private void assertTypes(Dom original, Dom cloned) {
logger.info(original.model.getTagName()+":" + original.getKey() + ":" + original.getClass().getSimpleName() +
" and " + cloned.model.getTagName()+":" + cloned.getKey() + ":" + cloned.getClass().getSimpleName());
- Assert.assertEquals(original.getClass(), cloned.getClass());
+ assertEquals(original.getClass(), cloned.getClass());
for (String elementName : original.getElementNames()) {
ConfigModel.Property property = original.model.getElement(elementName);
- if (property != null && property.isLeaf()) continue;
+ if (property != null && property.isLeaf()) {
+ continue;
+ }
Dom originalChild = original.element(elementName);
Dom clonedChild = cloned.element(elementName);
- if (originalChild==null && clonedChild==null) continue;
- Assert.assertNotNull(originalChild);
- Assert.assertNotNull(clonedChild);
+ if (originalChild==null && clonedChild==null) {
+ continue;
+ }
+ assertNotNull(originalChild);
+ assertNotNull(clonedChild);
assertTypes(originalChild, clonedChild);
}
}
private void assertParenting(Dom dom) {
-
for (String elementName : dom.model.getElementNames()) {
ConfigModel.Property property = dom.model.getElement(elementName);
- if (property.isLeaf()) continue;
+ if (property.isLeaf()) {
+ continue;
+ }
Dom child = dom.element(elementName);
- if (child==null) continue;
+ if (child==null) {
+ continue;
+ }
if (logger.isLoggable(Level.FINE)) {
- logger.fine("Parent of " + child.model.targetTypeName + ":" + child.getKey() + " is " + child.parent().getKey() + " while I am " + dom.getKey());
+ logger.fine("Parent of " + child.model.targetTypeName + ":" + child.getKey() + " is "
+ + child.parent().getKey() + " while I am " + dom.getKey());
}
logger.info("Parent of " + child.model.targetTypeName + ":" + child.getKey() + " is " +
child.parent().model.targetTypeName + ":" + child.parent().getKey() + " while I am " +
dom.model.targetTypeName + ":" + dom.getKey());
- Assert.assertEquals(dom, child.parent());
+ assertEquals(dom, child.parent());
assertParenting(child);
}
}
- final DomDocument document = getDocument(getHabitat());
-
- public OutputStream save(DomDocument doc) throws IOException, XMLStreamException {
- final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- outStream.reset();
-
- XMLOutputFactory factory = XMLOutputFactory.newInstance();
- XMLStreamWriter writer = factory.createXMLStreamWriter(outStream);
- doc.writeTo(new IndentingXMLStreamWriter(writer));
- writer.close();
- return outStream;
+ private String save(DomDocument doc) throws Exception {
+ try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) {
+ XMLOutputFactory factory = XMLOutputFactory.newInstance();
+ XMLStreamWriter writer = factory.createXMLStreamWriter(outStream);
+ try {
+ doc.writeTo(new IndentingXMLStreamWriter(writer));
+ } finally {
+ writer.close();
+ }
+ return outStream.toString();
+ }
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DefaultValueTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DefaultValueTest.java
index bcaf04e..5b212e6 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DefaultValueTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DefaultValueTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,43 +17,44 @@
package com.sun.enterprise.configapi.tests;
-import org.glassfish.grizzly.config.dom.*;
-import static org.junit.Assert.assertEquals;
-import org.junit.Before;
-import org.junit.Test;
+import org.glassfish.grizzly.config.dom.Http;
+import org.glassfish.grizzly.config.dom.NetworkListener;
+import org.glassfish.grizzly.config.dom.NetworkListeners;
+import org.glassfish.grizzly.config.dom.Protocol;
+import org.glassfish.grizzly.config.dom.Protocols;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.Attribute;
import org.jvnet.hk2.config.Dom;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
/**
* Test attribute and raw attribute access *
*/
public class DefaultValueTest extends ConfigApiTest {
- NetworkListener listener;
+ private NetworkListener listener;
+ @Override
public String getFileName() {
return "DomainTest";
}
- @Before
+ @BeforeEach
public void setup() {
NetworkListeners httpService = getHabitat().getService(NetworkListeners.class);
listener = httpService.getNetworkListener().get(0);
-
}
@Test
public void rawAttributeTest() throws NoSuchMethodException {
-
String address = listener.getAddress();
-
Dom raw = Dom.unwrap(listener);
Attribute attr = raw.getProxyType().getMethod("getAddress").getAnnotation(Attribute.class);
- assertEquals(attr.defaultValue(), address);
-
- assertEquals(raw.attribute("address"), address);
- assertEquals(raw.rawAttribute("address"), address);
-
+ assertEquals(address, attr.defaultValue());
+ assertEquals(address, raw.attribute("address"));
+ assertEquals(address, raw.rawAttribute("address"));
}
@Test
@@ -60,9 +62,7 @@
Protocols protocols = getHabitat().getService(Protocols.class);
for (Protocol protocol : protocols.getProtocol()) {
Http http = protocol.getHttp();
- System.out.println(http.getCompressableMimeType());
+ assertEquals(Http.COMPRESSABLE_MIME_TYPE, http.getCompressableMimeType());
}
-
}
-
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DirectAccessTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DirectAccessTest.java
index 6680ae5..95f599d 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DirectAccessTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DirectAccessTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -24,8 +25,12 @@
import org.glassfish.tests.utils.Utils;
import org.jvnet.hk2.config.ConfigBean;
import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.Dom;
import org.jvnet.hk2.config.TransactionFailure;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.stringContainsInOrder;
+
import java.util.HashMap;
import java.util.Map;
@@ -36,7 +41,7 @@
*/
public class DirectAccessTest extends ConfigPersistence {
- ServiceLocator habitat = Utils.instance.getHabitat(this);
+ private final ServiceLocator locator = Utils.instance.getHabitat(this);
/**
* Returns the file name without the .xml extension to load the test configuration
@@ -44,6 +49,7 @@
*
* @return the configuration file name
*/
+ @Override
public String getFileName() {
return "DomainTest";
}
@@ -51,42 +57,43 @@
@Override
public ServiceLocator getBaseServiceLocator() {
- return habitat;
+ return locator;
}
+
@Override
public ServiceLocator getHabitat() {
- return getBaseServiceLocator();
+ return getBaseServiceLocator();
}
+
+ @Override
public void doTest() throws TransactionFailure {
- NetworkConfig networkConfig = habitat.getService(NetworkConfig.class);
- final NetworkListener listener = networkConfig.getNetworkListeners()
- .getNetworkListener().get(0);
+ NetworkConfig networkConfig = locator.getService(NetworkConfig.class);
+ final NetworkListener listener = networkConfig.getNetworkListeners().getNetworkListener().get(0);
final Http http = listener.findHttpProtocol().getHttp();
- ConfigBean config = (ConfigBean) ConfigBean.unwrap(http.getFileCache());
- ConfigBean config2 = (ConfigBean) ConfigBean.unwrap(http);
- Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
- Map<String, String> configChanges = new HashMap<String, String>();
+ ConfigBean config = (ConfigBean) Dom.unwrap(http.getFileCache());
+ ConfigBean config2 = (ConfigBean) Dom.unwrap(http);
+ Map<ConfigBean, Map<String, String>> changes = new HashMap<>();
+ Map<String, String> configChanges = new HashMap<>();
configChanges.put("max-age-seconds", "12543");
configChanges.put("max-cache-size-bytes", "1200");
- Map<String, String> config2Changes = new HashMap<String, String>();
+ Map<String, String> config2Changes = new HashMap<>();
config2Changes.put("version", "12351");
changes.put(config, configChanges);
changes.put(config2, config2Changes);
- JavaConfig javaConfig = habitat.getService(JavaConfig.class);
- ConfigBean javaConfigBean = (ConfigBean) ConfigBean.unwrap(javaConfig);
- Map<String, String> javaConfigChanges = new HashMap<String, String>();
+ JavaConfig javaConfig = locator.getService(JavaConfig.class);
+ ConfigBean javaConfigBean = (ConfigBean) Dom.unwrap(javaConfig);
+ Map<String, String> javaConfigChanges = new HashMap<>();
javaConfigChanges.put("jvm-options", "-XFooBar=false");
changes.put(javaConfigBean, javaConfigChanges);
getHabitat().<ConfigSupport>getService(ConfigSupport.class).apply(changes);
}
- public boolean assertResult(String s) {
- return s.contains("max-age-seconds=\"12543\"")
- && s.contains("version=\"12351\"")
- && s.contains("-XFooBar=false");
+ @Override
+ public void assertResult(String xml) {
+ assertThat(xml, stringContainsInOrder("-XFooBar=false", "version=\"12351\"", "max-age-seconds=\"12543\""));
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DirectCreationTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DirectCreationTest.java
index cb5cb90..2c67ebd 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DirectCreationTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DirectCreationTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,25 +17,30 @@
package com.sun.enterprise.configapi.tests;
+import com.sun.enterprise.config.serverbeans.AdminService;
import com.sun.enterprise.config.serverbeans.DasConfig;
import com.sun.enterprise.config.serverbeans.JavaConfig;
import com.sun.enterprise.config.serverbeans.Profiler;
-import com.sun.enterprise.config.serverbeans.AdminService;
-
-import org.glassfish.hk2.api.ServiceLocator;
-import org.glassfish.tests.utils.Utils;
-import static org.junit.Assert.*;
-import org.junit.Test;
-import org.jvnet.hk2.config.AttributeChanges;
-import org.jvnet.hk2.config.ConfigBean;
-import org.jvnet.hk2.config.ConfigBeanProxy;
-import org.jvnet.hk2.config.ConfigSupport;
-import org.jvnet.hk2.config.TransactionFailure;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+
+import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.tests.utils.Utils;
+import org.junit.jupiter.api.Test;
+import org.jvnet.hk2.config.AttributeChanges;
+import org.jvnet.hk2.config.ConfigBean;
+import org.jvnet.hk2.config.ConfigBeanProxy;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.Dom;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.stringContainsInOrder;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* User: Jerome Dochez
@@ -43,7 +49,7 @@
*/
public class DirectCreationTest extends ConfigPersistence {
- ServiceLocator habitat = Utils.instance.getHabitat(this);
+ private final ServiceLocator locator = Utils.instance.getHabitat(this);
/**
* Returns the file name without the .xml extension to load the test configuration
@@ -56,71 +62,65 @@
return "DomainTest";
}
+
@Override
public ServiceLocator getBaseServiceLocator() {
- return habitat;
+ return locator;
}
+
@Override
public ServiceLocator getHabitat() {
- return getBaseServiceLocator();
+ return getBaseServiceLocator();
}
- public void doTest() throws TransactionFailure {
- AdminService service = habitat.getService(AdminService.class);
-
- ConfigBean serviceBean = (ConfigBean) ConfigBean.unwrap(service);
- Class<?>[] subTypes = null;
- try {
- subTypes = ConfigSupport.getSubElementsTypes(serviceBean);
- } catch (ClassNotFoundException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- throw new RuntimeException(e);
- }
-
+ @Override
+ public void doTest() throws Exception {
+ AdminService service = locator.getService(AdminService.class);
+ ConfigBean serviceBean = (ConfigBean) Dom.unwrap(service);
+ Class<?>[] subTypes = ConfigSupport.getSubElementsTypes(serviceBean);
ConfigSupport support = getBaseServiceLocator().getService(ConfigSupport.class);
-
- assertNotNull("ConfigSupport not found", support);
+ assertNotNull(support, "ConfigSupport not found");
for (Class<?> subType : subTypes) {
-
- // TODO: JL force compilation error to mark this probably edit point for grizzly config
if (subType.getName().endsWith("DasConfig")) {
- Map<String, String> configChanges = new HashMap<String, String>();
+ Map<String, String> configChanges = new HashMap<>();
configChanges.put("dynamic-reload-enabled", "true");
configChanges.put("autodeploy-dir", "funky-dir");
- support.createAndSet(serviceBean, (Class<? extends ConfigBeanProxy>)subType, configChanges);
+ ConfigSupport.createAndSet(serviceBean, (Class<? extends ConfigBeanProxy>) subType, configChanges);
break;
}
}
- support.createAndSet(serviceBean, DasConfig.class, (List) null);
+ support.createAndSet(serviceBean, DasConfig.class, (List<AttributeChanges>) null);
- List<AttributeChanges> profilerChanges = new ArrayList<AttributeChanges>();
+ List<AttributeChanges> profilerChanges = new ArrayList<>();
String[] values = { "-Xmx512m", "-RFtrq", "-Xmw24" };
ConfigSupport.MultipleAttributeChanges multipleChanges = new ConfigSupport.MultipleAttributeChanges("jvm-options", values );
String[] values1 = { "profile" };
ConfigSupport.MultipleAttributeChanges multipleChanges1 = new ConfigSupport.MultipleAttributeChanges("name", values1 );
profilerChanges.add(multipleChanges);
profilerChanges.add(multipleChanges1);
- support.createAndSet((ConfigBean) ConfigBean.unwrap(habitat.<JavaConfig>getService(JavaConfig.class))
- , Profiler.class, profilerChanges);
+ support.createAndSet(unwrapConfigBean(), Profiler.class, profilerChanges);
}
@Test
- public void directAttributeNameTest() throws ClassNotFoundException {
-
- boolean foundOne=false;
- for (String attrName :
- ((ConfigBean) ConfigBean.unwrap(habitat.<JavaConfig>getService(JavaConfig.class))).model.getAttributeNames()) {
- assertTrue(attrName!=null);
- foundOne=true;
+ public void directAttributeNameTest() throws Exception {
+ Set<String> attributeNames = unwrapConfigBean().model.getAttributeNames();
+ assertThat(attributeNames, hasSize(13));
+ for (String attrName : attributeNames) {
+ assertNotNull(attrName);
}
- assertTrue(foundOne);
}
- public boolean assertResult(String s) {
- return s.contains("autodeploy-dir=\"funky-dir\"");
+ @Override
+ public void assertResult(String xml) {
+ assertThat(xml, stringContainsInOrder("autodeploy-dir=\"funky-dir\""));
+ }
+
+
+ private ConfigBean unwrapConfigBean() {
+ return (ConfigBean) Dom.unwrap(locator.<JavaConfig> getService(JavaConfig.class));
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DirectRemovalTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DirectRemovalTest.java
index 088c9f8..ea25f16 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DirectRemovalTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DirectRemovalTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -22,8 +23,13 @@
import org.glassfish.tests.utils.Utils;
import org.jvnet.hk2.config.ConfigBean;
import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.Dom;
import org.jvnet.hk2.config.TransactionFailure;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.stringContainsInOrder;
+
/**
* User: Jerome Dochez
* Date: Mar 27, 2008
@@ -31,7 +37,7 @@
*/
public class DirectRemovalTest extends ConfigPersistence {
- ServiceLocator habitat = Utils.instance.getHabitat(this);
+ private final ServiceLocator habitat = Utils.instance.getHabitat(this);
/**
* Returns the file name without the .xml extension to load the test configuration
@@ -39,6 +45,7 @@
*
* @return the configuration file name
*/
+ @Override
public String getFileName() {
return "DomainTest";
}
@@ -48,22 +55,20 @@
return habitat;
}
+ @Override
public void doTest() throws TransactionFailure {
-
NetworkListeners listeners = habitat.getService(NetworkListeners.class);
-
- ConfigBean serviceBean = (ConfigBean) ConfigBean.unwrap(listeners);
-
+ ConfigBean serviceBean = (ConfigBean) Dom.unwrap(listeners);
for (NetworkListener listener : listeners.getNetworkListener()) {
if (listener.getName().endsWith("http-listener-1")) {
- ConfigSupport.deleteChild(serviceBean, (ConfigBean) ConfigBean.unwrap(listener));
+ ConfigSupport.deleteChild(serviceBean, (ConfigBean) Dom.unwrap(listener));
break;
}
}
}
- public boolean assertResult(String s) {
- // we must not find it
- return !s.contains("id=\"http-listener-1\"");
+ @Override
+ public void assertResult(String xml) {
+ assertThat(xml, not(stringContainsInOrder("id=\"http-listener-1\"")));
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DomainTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DomainTest.java
index 0e2fa86..a96f7d4 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DomainTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DomainTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -17,8 +18,10 @@
package com.sun.enterprise.configapi.tests;
import com.sun.enterprise.config.serverbeans.Domain;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* Domain related tests
@@ -29,9 +32,7 @@
@Test
public void domainExist() {
-
Domain domain = getHabitat().getService(Domain.class);
- assertTrue(domain != null);
+ assertNotNull(domain);
}
-
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DuplicateKeyedElementTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DuplicateKeyedElementTest.java
index 964158d..f956623 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DuplicateKeyedElementTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/DuplicateKeyedElementTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,14 +17,13 @@
package com.sun.enterprise.configapi.tests;
-import java.beans.PropertyVetoException;
-
import com.sun.enterprise.config.serverbeans.HttpService;
import com.sun.enterprise.config.serverbeans.VirtualServer;
import org.jvnet.hk2.config.types.Property;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
@@ -34,72 +34,55 @@
* @author Jerome Dochez
*/
public class DuplicateKeyedElementTest extends ConfigApiTest {
- boolean result = false;
+ @Override
public String getFileName() {
return "DomainTest";
}
- @Test(expected = TransactionFailure.class)
+ @Test
public void duplicateKeyTest() throws TransactionFailure {
- HttpService httpService = getHabitat().getService(HttpService.class);
- assertNotNull(httpService);
- // let's find a acceptable target.
- VirtualServer target = null;
- for (VirtualServer vs : httpService.getVirtualServer()) {
- if (!vs.getProperty().isEmpty()) {
- target = vs;
- break;
- }
- }
+ final VirtualServer target = findVirtualServerWithProperties();
assertNotNull(target);
final Property prop = target.getProperty().get(0);
- Property newProp = (Property) ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {
- public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
- // first one is fine...
- Property dupProp = param.createChild(Property.class);
- dupProp.setName(prop.getName());
- dupProp.setValue(prop.getValue().toUpperCase());
- // this should fail...
- param.getProperty().add(dupProp);
- return dupProp;
- }
- }, target);
- // if we arrive here, this is an error, we succeeded adding a property with
- // the same key name.
- assertTrue(false);
+ final SingleConfigCode<VirtualServer> configCode = virtualServer -> {
+ // first one is fine...
+ Property dupProp = virtualServer.createChild(Property.class);
+ dupProp.setName(prop.getName());
+ dupProp.setValue(prop.getValue().toUpperCase());
+ // this should fail...
+ throw assertThrows(IllegalArgumentException.class, () -> virtualServer.getProperty().add(dupProp));
+ };
+ assertThrows(TransactionFailure.class, () -> ConfigSupport.apply(configCode, target));
}
- @Test(expected = TransactionFailure.class)
+ @Test
public void identicalKeyTest() throws TransactionFailure {
+ final VirtualServer target = findVirtualServerWithProperties();
+ assertNotNull(target);
+ final SingleConfigCode<VirtualServer> configCode = virtualServer -> {
+ // first one is fine...
+ Property firstProp = virtualServer.createChild(Property.class);
+ firstProp.setName("foo");
+ firstProp.setValue("bar");
+ virtualServer.getProperty().add(firstProp);
+ // this should fail...
+ Property secondProp = virtualServer.createChild(Property.class);
+ secondProp.setName("foo");
+ secondProp.setValue("bar");
+ throw assertThrows(IllegalArgumentException.class, () -> virtualServer.getProperty().add(secondProp));
+ };
+ assertThrows(TransactionFailure.class, () -> ConfigSupport.apply(configCode, target));
+ }
+
+ private VirtualServer findVirtualServerWithProperties() {
HttpService httpService = getHabitat().getService(HttpService.class);
assertNotNull(httpService);
- // let's find a acceptable target.
- VirtualServer target = null;
for (VirtualServer vs : httpService.getVirtualServer()) {
if (!vs.getProperty().isEmpty()) {
- target = vs;
- break;
+ return vs;
}
}
- assertNotNull(target);
- Property newProp = (Property) ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {
- public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
- // first one is fine...
- Property firstProp = param.createChild(Property.class);
- firstProp.setName("foo");
- firstProp.setValue("bar");
- param.getProperty().add(firstProp);
- // this should fail...
- Property secondProp = param.createChild(Property.class);
- secondProp.setName("foo");
- secondProp.setValue("bar");
- param.getProperty().add(secondProp);
- return secondProp;
- }
- }, target);
- // if we arrive here, this is an error, we succeeded adding a property with
- // the same key name.
- assertTrue(false);
+ return null;
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/EnabledTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/EnabledTest.java
index 1e9b5cc..f08eecf 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/EnabledTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/EnabledTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,14 +17,15 @@
package com.sun.enterprise.configapi.tests;
+import java.util.List;
+
import org.glassfish.grizzly.config.dom.NetworkConfig;
import org.glassfish.grizzly.config.dom.NetworkListener;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-import java.util.List;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* HttpListener.getEnabled() API test
@@ -31,13 +33,15 @@
* User: Jerome Dochez Date: Feb 21, 2008 Time: 2:06:44 PM
*/
public class EnabledTest extends ConfigApiTest {
+ private List<NetworkListener> listeners;
+
+ @Override
public String getFileName() {
return "DomainTest";
}
- List<NetworkListener> listeners = null;
- @Before
+ @BeforeEach
public void setup() {
NetworkConfig service = getHabitat().getService(NetworkConfig.class);
assertTrue(service != null);
@@ -47,12 +51,11 @@
@Test
public void enabled() {
for (NetworkListener listener : listeners) {
- logger.fine("Listener " + listener.getName() + " enabled "
- + listener.getEnabled());
+ logger.fine("Listener " + listener.getName() + " enabled " + listener.getEnabled());
if ("http-listener-2".equals(listener.getName())) {
- assertFalse(new Boolean(listener.getEnabled()));
+ assertFalse(Boolean.parseBoolean(listener.getEnabled()));
} else {
- assertTrue(new Boolean(listener.getEnabled()));
+ assertTrue(Boolean.parseBoolean(listener.getEnabled()));
}
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/GetElementTypeByNameTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/GetElementTypeByNameTest.java
index 5458a7d..dc1b5ae 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/GetElementTypeByNameTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/GetElementTypeByNameTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,12 +17,15 @@
package com.sun.enterprise.configapi.tests;
-import org.junit.Test;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import com.sun.enterprise.config.serverbeans.Config;
+
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigBeanProxy;
import org.jvnet.hk2.config.ConfigSupport;
-import com.sun.enterprise.config.serverbeans.Config;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.StringEndsWith.endsWith;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* Test the getElementTypeByName ConfigSupport API
@@ -30,21 +34,17 @@
*/
public class GetElementTypeByNameTest extends ConfigApiTest {
+ @Override
public String getFileName() {
return "DomainTest";
}
@Test
- public void testAppRoot() {
- Config c = getHabitat().getService(Config.class);
- Class<? extends ConfigBeanProxy> elementType = null;
- try {
- elementType = ConfigSupport.getElementTypeByName(c, "admin-service");
- } catch (Exception e) {
- e.printStackTrace();
- }
+ public void testAppRoot() throws Exception {
+ Config cfg = getHabitat().getService(Config.class);
+ Class<? extends ConfigBeanProxy> elementType = ConfigSupport.getElementTypeByName(cfg, "admin-service");
assertNotNull(elementType);
- assertTrue(elementType.getName().endsWith("AdminService"));
+ assertThat(elementType.getName(), endsWith("AdminService"));
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/HttpListenerTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/HttpListenerTest.java
index 32991e3..b486e36 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/HttpListenerTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/HttpListenerTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,13 +20,15 @@
import org.glassfish.grizzly.config.dom.NetworkListener;
import org.glassfish.grizzly.config.dom.NetworkListeners;
import org.glassfish.grizzly.config.dom.Transport;
-import static org.junit.Assert.assertTrue;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
/**
* HttpListener related tests
*
@@ -33,46 +36,41 @@
*/
public class HttpListenerTest extends ConfigApiTest {
+ private NetworkListener listener;
+ @Override
public String getFileName() {
return "DomainTest";
}
- NetworkListener listener = null;
- @Before
+ @BeforeEach
public void setup() {
NetworkListeners service = getHabitat().getService(NetworkListeners.class);
- assertTrue(service!=null);
+ assertNotNull(service);
for (NetworkListener item : service.getNetworkListener()) {
if ("http-listener-1".equals(item.getName())) {
listener= item;
break;
}
}
-
- logger.fine("listener = " + listener);
- assertTrue(listener!=null);
-
+ assertNotNull(listener);
}
@Test
public void portTest() {
- logger.fine("port = " + listener.getPort());
- assertTrue("8080".equals(listener.getPort()));
+ assertEquals("8080", listener.getPort());
}
@Test
public void validTransaction() throws TransactionFailure {
-
- ConfigSupport.apply(new SingleConfigCode<Transport>() {
- public Object run(Transport okToChange) {
- okToChange.setAcceptorThreads("2");
- logger.fine("ID inside the transaction is " + okToChange.getName());
- return null;
- }
- }, listener.findTransport());
+ SingleConfigCode<Transport> configCode = transport -> {
+ transport.setAcceptorThreads("2");
+ logger.fine("ID inside the transaction is " + transport.getName());
+ return null;
+ };
+ ConfigSupport.apply(configCode, listener.findTransport());
logger.fine("ID outside the transaction is " + listener.getName());
- assertTrue("2".equals(listener.findTransport().getAcceptorThreads()));
+ assertEquals("2", listener.findTransport().getAcceptorThreads());
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/HttpServiceTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/HttpServiceTest.java
index c698314..123a95a 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/HttpServiceTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/HttpServiceTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -21,76 +22,72 @@
import org.glassfish.grizzly.config.dom.NetworkConfig;
import org.glassfish.grizzly.config.dom.NetworkListener;
import org.glassfish.grizzly.config.dom.Protocol;
-import static junit.framework.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
/**
* HttpService related tests
*
* @author Jerome Dochez
*/
public class HttpServiceTest extends ConfigApiTest {
+
+ private NetworkListener listener;
+
+ @Override
public String getFileName() {
return "DomainTest";
}
- NetworkListener listener = null;
- @Before
+ @BeforeEach
public void setup() {
listener = getHabitat().<NetworkConfig>getService(NetworkConfig.class).getNetworkListener("admin-listener");
- assertTrue(listener != null);
+ assertNotNull(listener);
}
@Test
public void connectionTest() {
final String max = listener.findHttpProtocol().getHttp().getMaxConnections();
- logger.fine("Max connections = " + max);
- assertEquals("Should only allow 250 connections. The default is 256, however.", "250", max);
+ assertEquals("250", max, "Should only allow 250 connections. The default is 256, however.");
}
@Test
public void validTransaction() throws TransactionFailure {
final String max = listener.findHttpProtocol().getHttp().getMaxConnections();
- ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {
- public Object run(NetworkListener okToChange) throws TransactionFailure {
- final Http http = okToChange.createChild(Http.class);
- http.setMaxConnections("100");
- http.setTimeoutSeconds("65");
- http.setFileCache(http.createChild(FileCache.class));
- ConfigSupport.apply(new SingleConfigCode<Protocol>() {
- @Override
- public Object run(Protocol param) {
- param.setHttp(http);
- return null;
- }
- }, okToChange.findHttpProtocol());
- return http;
- }
- }, listener);
-
- ConfigSupport.apply(new SingleConfigCode<Http>() {
- @Override
- public Object run(Http param) {
- param.setMaxConnections(max);
+ SingleConfigCode<NetworkListener> listenerConfigCode = networkListener -> {
+ final Http http = networkListener.createChild(Http.class);
+ http.setMaxConnections("100");
+ http.setTimeoutSeconds("65");
+ http.setFileCache(http.createChild(FileCache.class));
+ SingleConfigCode<Protocol> protocolConfigCode = protocol -> {
+ protocol.setHttp(http);
return null;
- }
- }, listener.findHttpProtocol().getHttp());
- try {
- ConfigSupport.apply(new SingleConfigCode<Http>() {
- public Object run(Http param) throws TransactionFailure {
- param.setMaxConnections("7");
- throw new TransactionFailure("Sorry, changed my mind", null);
- }
- }, listener.findHttpProtocol().getHttp());
- } catch (TransactionFailure e) {
- logger.fine("good, got my exception about changing my mind");
- }
+ };
+ ConfigSupport.apply(protocolConfigCode, networkListener.findHttpProtocol());
+ return http;
+ };
+ ConfigSupport.apply(listenerConfigCode, listener);
+
+ SingleConfigCode<Http> httpConfigCode = (SingleConfigCode<Http>) http -> {
+ http.setMaxConnections(max);
+ return null;
+ };
+ ConfigSupport.apply(httpConfigCode, listener.findHttpProtocol().getHttp());
+ SingleConfigCode<Http> configCode = http -> {
+ http.setMaxConnections("7");
+ throw new TransactionFailure("Sorry, changed my mind", null);
+ };
+ assertThrows(TransactionFailure.class,
+ () -> ConfigSupport.apply(configCode, listener.findHttpProtocol().getHttp()));
+ assertEquals(max, listener.findHttpProtocol().getHttp().getMaxConnections());
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/JavaConfigSubTypesTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/JavaConfigSubTypesTest.java
index 2b0653d..cb47b86 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/JavaConfigSubTypesTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/JavaConfigSubTypesTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,20 +17,23 @@
package com.sun.enterprise.configapi.tests;
-import org.junit.Test;
-import org.junit.Assert;
-import org.jvnet.hk2.config.ConfigSupport;
-import org.jvnet.hk2.config.ConfigBean;
-import org.jvnet.hk2.config.TransactionFailure;
-import org.jvnet.hk2.config.SingleConfigCode;
-import org.glassfish.hk2.api.ServiceLocator;
-import org.glassfish.tests.utils.Utils;
import com.sun.enterprise.config.serverbeans.JavaConfig;
-import java.util.logging.Logger;
-import java.util.logging.Level;
import java.util.List;
-import java.beans.PropertyVetoException;
+import java.util.logging.Logger;
+
+import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.tests.utils.Utils;
+import org.junit.jupiter.api.Test;
+import org.jvnet.hk2.config.ConfigBean;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.Dom;
+import org.jvnet.hk2.config.SingleConfigCode;
+import org.jvnet.hk2.config.TransactionFailure;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.stringContainsInOrder;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* User: Jerome Dochez
@@ -38,26 +42,7 @@
*/
public class JavaConfigSubTypesTest extends ConfigPersistence {
-
- @Test
- public void testSubTypesOfDomain() {
- JavaConfig config = super.getHabitat().getService(JavaConfig.class);
- try {
- Class<?>[] subTypes = ConfigSupport.getSubElementsTypes((ConfigBean) ConfigBean.unwrap(config));
- boolean found=false;
- for (Class subType : subTypes) {
- Logger.getAnonymousLogger().fine("Found class " + subType);
- if (subType.getName().equals(List.class.getName())) {
- found=true;
- }
- }
- Assert.assertTrue(found);;
- } catch(ClassNotFoundException e) {
- logger.log(Level.SEVERE, e.getMessage(), e);
- }
- }
-
- ServiceLocator habitat = Utils.instance.getHabitat(this);
+ private final ServiceLocator habitat = Utils.instance.getHabitat(this);
/**
* Returns the file name without the .xml extension to load the test configuration
@@ -65,38 +50,54 @@
*
* @return the configuration file name
*/
+ @Override
public String getFileName() {
return "DomainTest";
}
+
@Override
public ServiceLocator getBaseServiceLocator() {
return habitat;
}
+
@Override
public ServiceLocator getHabitat() {
- return getBaseServiceLocator();
+ return getBaseServiceLocator();
}
+
+ @Override
@Test
public void doTest() throws TransactionFailure {
-
-
JavaConfig javaConfig = habitat.getService(JavaConfig.class);
+ SingleConfigCode<JavaConfig> configCode = (SingleConfigCode<JavaConfig>) jvm -> {
+ List<String> jvmOptions = jvm.getJvmOptions();
+ jvmOptions.add("-XFooBar=true");
+ return jvmOptions;
+ };
+ ConfigSupport.apply(configCode, javaConfig);
+ }
- ConfigSupport.apply(new SingleConfigCode<JavaConfig>() {
- public Object run(JavaConfig param) throws PropertyVetoException, TransactionFailure {
- List<String> jvmOptions = param.getJvmOptions();
- jvmOptions.add("-XFooBar=true");
- return jvmOptions;
+
+ @Override
+ public void assertResult(String xml) {
+ assertThat(xml, stringContainsInOrder("-XFooBar"));
+ }
+
+
+ @Test
+ public void testSubTypesOfDomain() throws Exception {
+ JavaConfig config = super.getHabitat().getService(JavaConfig.class);
+ Class<?>[] subTypes = ConfigSupport.getSubElementsTypes((ConfigBean) Dom.unwrap(config));
+ boolean found = false;
+ for (Class<?> subType : subTypes) {
+ Logger.getAnonymousLogger().fine("Found class " + subType);
+ if (subType.getName().equals(List.class.getName())) {
+ found = true;
}
- }, javaConfig);
-
+ }
+ assertTrue(found);
}
-
- public boolean assertResult(String s) {
- return s.indexOf("-XFooBar")!=-1;
- }
-
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ModulesTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ModulesTest.java
index aeaa54a..cf80195 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ModulesTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ModulesTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -17,39 +18,41 @@
package com.sun.enterprise.configapi.tests;
import com.sun.enterprise.config.serverbeans.Applications;
-import org.glassfish.api.admin.config.ApplicationName;
-import static org.junit.Assert.assertTrue;
-import org.junit.Before;
-import org.junit.Test;
import java.util.Collection;
+import org.glassfish.api.admin.config.ApplicationName;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
/**
* Modules related tests
*/
public class ModulesTest extends ConfigApiTest {
+ private Collection<? extends ApplicationName> modules;
+
@Override
public String getFileName() {
return "DomainTest";
}
- Collection<? extends ApplicationName> modules = null;
- @Before
+ @BeforeEach
public void setup() {
Applications apps = getHabitat().getService(Applications.class);
- assertTrue(apps!=null);
+ assertNotNull(apps);
modules = apps.getModules();
- assertTrue(modules!=null);
-
+ assertNotNull(modules);
}
@Test
public void modulesTest() {
for (ApplicationName module : modules) {
logger.fine("Found module " + module.getName());
- assertTrue(module.getName()!=null);
+ assertNotNull(module.getName());
}
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ParentConfigListenerTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ParentConfigListenerTest.java
index ab41839..2adb968 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ParentConfigListenerTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ParentConfigListenerTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,23 +17,23 @@
package com.sun.enterprise.configapi.tests;
+import java.util.List;
+
import org.glassfish.grizzly.config.dom.NetworkListener;
import org.glassfish.grizzly.config.dom.NetworkListeners;
import org.glassfish.hk2.api.ServiceHandle;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.tests.utils.Utils;
-import static org.junit.Assert.assertTrue;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.Assert;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.ObservableBean;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
import org.jvnet.hk2.config.Transactions;
-import java.util.Collection;
-import java.util.List;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* This test will ensure that when a class is injected with a parent bean and a child
@@ -43,54 +44,48 @@
*/
public class ParentConfigListenerTest extends ConfigApiTest {
- ServiceLocator habitat;
+ private ServiceLocator locator;
+ @Override
public String getFileName() {
return "DomainTest";
}
- @Before
+ @BeforeEach
public void setup() {
- habitat = Utils.instance.getHabitat(this);
+ locator = Utils.instance.getHabitat(this);
}
-
-
-
@Test
public void addHttpListenerTest() throws TransactionFailure {
- NetworkListenersContainer container = habitat.getService(NetworkListenersContainer.class);
-
- ConfigSupport.apply(new SingleConfigCode<NetworkListeners>() {
-
- public Object run(NetworkListeners param) throws TransactionFailure {
- NetworkListener newListener = param.createChild(NetworkListener.class);
- newListener.setName("Funky-Listener");
- newListener.setPort("8078");
- param.getNetworkListener().add(newListener);
- return null;
- }
- }, container.httpService);
+ NetworkListenersContainer container = locator.getService(NetworkListenersContainer.class);
+ SingleConfigCode<NetworkListeners> configCode = listeners -> {
+ NetworkListener newListener = listeners.createChild(NetworkListener.class);
+ newListener.setName("Funky-Listener");
+ newListener.setPort("8078");
+ listeners.getNetworkListener().add(newListener);
+ return null;
+ };
+ ConfigSupport.apply(configCode, container.httpService);
getHabitat().<Transactions>getService(Transactions.class).waitForDrain();
assertTrue(container.received);
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(container.httpService);
// let's check that my newly added listener is available in the habitat.
- List<ServiceHandle<NetworkListener>> networkListeners = habitat.getAllServiceHandles(NetworkListener.class);
+ List<ServiceHandle<NetworkListener>> networkListeners = locator.getAllServiceHandles(NetworkListener.class);
boolean found = false;
-
for (ServiceHandle<NetworkListener> nlSH : networkListeners) {
- NetworkListener nl = (NetworkListener) nlSH.getService();
+ NetworkListener nl = nlSH.getService();
if (nl.getName().equals("Funky-Listener")) {
- found=true;
+ found = true;
}
}
- Assert.assertTrue("Newly added listener not found", found);
+ assertTrue(found, "Newly added listener not found");
// direct access.
- NetworkListener nl = habitat.getService(NetworkListener.class, "Funky-Listener");
- Assert.assertTrue("Direct access to newly added listener failed", nl!=null);
+ NetworkListener networkListener = locator.getService(NetworkListener.class, "Funky-Listener");
+ assertNotNull(networkListener, "Direct access to newly added listener failed");
bean.removeListener(container);
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ParentTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ParentTest.java
index cfac43c..4ff1b79 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ParentTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/ParentTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -18,10 +19,11 @@
import org.glassfish.grizzly.config.dom.NetworkListener;
import org.glassfish.grizzly.config.dom.NetworkListeners;
-import static org.junit.Assert.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigBeanProxy;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
/**
* test the getParentAPI.
*
@@ -29,7 +31,7 @@
*/
public class ParentTest extends ConfigApiTest {
-
+ @Override
public String getFileName() {
return "DomainTest";
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/PersistenceTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/PersistenceTest.java
index 948b4a6..8b5ebb7 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/PersistenceTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/PersistenceTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -22,29 +23,33 @@
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.stringContainsInOrder;
+
/**
* Test the persistence to a file...
*/
public class PersistenceTest extends ConfigPersistence {
+ @Override
public String getFileName() {
return "DomainTest";
}
+
+ @Override
public void doTest() throws TransactionFailure {
NetworkListeners service = getHabitat().getService(NetworkListeners.class);
- // now do a transaction
-
- ConfigSupport.apply(new SingleConfigCode<Transport>() {
- public Object run(Transport param) {
- param.setAcceptorThreads("8989");
- return null;
- }
- }, service.getNetworkListener().get(0).findTransport());
- //To change body of implemented methods use File | Settings | File Templates.
+ SingleConfigCode<Transport> configCode = (SingleConfigCode<Transport>) transport -> {
+ transport.setAcceptorThreads("8989");
+ return null;
+ };
+ ConfigSupport.apply(configCode, service.getNetworkListener().get(0).findTransport());
}
- public boolean assertResult(String s) {
- return s.contains("acceptor-threads=\"8989\"");
+
+ @Override
+ public void assertResult(String xml) {
+ assertThat(xml, stringContainsInOrder("acceptor-threads=\"8989\""));
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/PropertyChangeListenerTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/PropertyChangeListenerTest.java
index fba2e04..a7d07fd 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/PropertyChangeListenerTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/PropertyChangeListenerTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,19 +17,26 @@
package com.sun.enterprise.configapi.tests;
-import org.jvnet.hk2.config.*;
-import org.jvnet.hk2.config.types.Property;
-import org.junit.Before;
-import org.junit.Test;
-import static org.junit.Assert.*;
+import com.sun.enterprise.config.serverbeans.HttpService;
+import com.sun.enterprise.config.serverbeans.VirtualServer;
+
+import java.beans.PropertyChangeEvent;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.tests.utils.Utils;
-import com.sun.enterprise.config.serverbeans.*;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.jvnet.hk2.config.ConfigListener;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.ObservableBean;
+import org.jvnet.hk2.config.SingleConfigCode;
+import org.jvnet.hk2.config.TransactionFailure;
+import org.jvnet.hk2.config.Transactions;
+import org.jvnet.hk2.config.UnprocessedChangeEvents;
+import org.jvnet.hk2.config.types.Property;
-
-import java.beans.PropertyVetoException;
-import java.beans.PropertyChangeEvent;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* This test listen to a property change event only injecting the parent containing the property.
@@ -37,54 +45,55 @@
*/
public class PropertyChangeListenerTest extends ConfigApiTest implements ConfigListener {
- ServiceLocator habitat;
- boolean result = false;
+ private ServiceLocator locator;
+ private boolean result;
+ @Override
public String getFileName() {
return "DomainTest";
}
- @Before
+ @BeforeEach
public void setup() {
- habitat = Utils.instance.getHabitat(this);
+ locator = Utils.instance.getHabitat(this);
}
@Test
public void propertyChangeEventReceptionTest() throws TransactionFailure {
- HttpService httpService = habitat.getService(HttpService.class);
+ HttpService httpService = locator.getService(HttpService.class);
assertNotNull(httpService);
// let's find a acceptable target.
- VirtualServer target =null;
- for (VirtualServer vs : httpService.getVirtualServer()) {
- if (!vs.getProperty().isEmpty()) {
- target = vs;
- break;
- }
- }
+ VirtualServer target = null;
+ for (VirtualServer vs : httpService.getVirtualServer()) {
+ if (!vs.getProperty().isEmpty()) {
+ target = vs;
+ break;
+ }
+ }
- assertNotNull(target);
+ assertNotNull(target);
- ((ObservableBean) ConfigSupport.getImpl(target)).addListener(this);
- final Property prop = target.getProperty().get(0);
+ ((ObservableBean) ConfigSupport.getImpl(target)).addListener(this);
+ final Property prop = target.getProperty().get(0);
- ConfigSupport.apply(new SingleConfigCode<Property>() {
+ SingleConfigCode<Property> configCode = property -> {
+ // first one is fine...
+ property.setValue(prop.getValue().toUpperCase());
+ return null;
+ };
+ ConfigSupport.apply(configCode, prop);
- public Object run(Property param) throws PropertyVetoException, TransactionFailure {
- // first one is fine...
- param.setValue(prop.getValue().toUpperCase());
- return null;
- }
- }, prop);
+ getHabitat().<Transactions> getService(Transactions.class).waitForDrain();
+ assertTrue(result);
+ ((ObservableBean) ConfigSupport.getImpl(target)).removeListener(this);
+ }
- getHabitat().<Transactions>getService(Transactions.class).waitForDrain();
- assertTrue(result);
- ((ObservableBean) ConfigSupport.getImpl(target)).removeListener(this);
- }
- public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
- result = true;
- return null;
- }
+ @Override
+ public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
+ result = true;
+ return null;
+ }
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/RawValueTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/RawValueTest.java
index a69565d..5935734 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/RawValueTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/RawValueTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,38 +17,43 @@
package com.sun.enterprise.configapi.tests;
-import org.junit.Before;
-import org.junit.Test;
-import static org.junit.Assert.*;
-import org.glassfish.config.support.GlassFishConfigBean;
import com.sun.enterprise.config.serverbeans.Domain;
+import org.glassfish.config.support.GlassFishConfigBean;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertAll;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
/**
- * Created by IntelliJ IDEA.
* User: dochez
* Date: Jan 30, 2008
* Time: 11:18:52 AM
- * To change this template use File | Settings | File Templates.
*/
public class RawValueTest extends ConfigApiTest {
+ @Override
public String getFileName() {
return "DomainTest";
}
- @Before
+ @BeforeEach
public void setup() {
System.setProperty("com.sun.aas.instanceRoot", "cafebabe");
}
-
@Test
public void testAppRoot() {
Domain domain = getHabitat().getService(Domain.class);
Domain rawDomain = GlassFishConfigBean.getRawView(domain);
String appRoot = domain.getApplicationRoot();
String appRawRoot = rawDomain.getApplicationRoot();
- assertFalse(appRawRoot.equals(appRoot));
- assertTrue(appRawRoot.startsWith("${"));
+ assertAll(
+ () -> assertNotEquals(appRoot, appRawRoot),
+ () -> assertThat(appRawRoot, startsWith("${"))
+ );
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/Ssl2EnabledTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/Ssl2EnabledTest.java
index 8a2cc7e..bd92a42 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/Ssl2EnabledTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/Ssl2EnabledTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,31 +17,33 @@
package com.sun.enterprise.configapi.tests;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import org.glassfish.grizzly.config.dom.NetworkConfig;
import org.glassfish.grizzly.config.dom.NetworkListener;
import org.glassfish.grizzly.config.dom.Protocol;
import org.glassfish.grizzly.config.dom.Ssl;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* User: Jerome Dochez Date: Mar 4, 2008 Time: 2:44:59 PM
*/
public class Ssl2EnabledTest extends ConfigApiTest {
+
+ @Override
public String getFileName() {
return "DomainTest";
}
- NetworkConfig config = null;
+ private NetworkConfig config;
- @Before
+ @BeforeEach
public void setup() {
config = getHabitat().getService(NetworkConfig.class);
- assertTrue(config != null);
-
+ assertNotNull(config);
}
@Test
@@ -50,13 +53,9 @@
if (httpProtocol != null) {
Ssl ssl = httpProtocol.getSsl();
if (ssl != null) {
- try {
- logger.fine("SSL2 ENABLED = " + ssl.getSsl2Enabled());
- assertFalse(Boolean.parseBoolean(ssl.getSsl2Enabled()));
- assertFalse(Boolean.parseBoolean(ssl.getSsl3Enabled()));
- } catch (Exception e) {
- e.printStackTrace();
- }
+ assertFalse(Boolean.parseBoolean(ssl.getSsl2Enabled()));
+ assertFalse(Boolean.parseBoolean(ssl.getSsl3Enabled()));
+ assertTrue(Boolean.parseBoolean(ssl.getTlsEnabled()));
}
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/SubTypesTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/SubTypesTest.java
index 8c62e50..93a1788 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/SubTypesTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/SubTypesTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -18,11 +19,17 @@
import com.sun.enterprise.config.serverbeans.Domain;
-import java.util.logging.Logger;
-import org.junit.Test;
-import static org.junit.Assert.assertTrue;
-import org.jvnet.hk2.config.ConfigSupport;
+import java.util.Set;
+
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigBean;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.Dom;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItems;
+import static org.junit.jupiter.api.Assertions.assertAll;
/**
@@ -33,43 +40,25 @@
public class SubTypesTest extends ConfigApiTest {
// not testing all the sub types, just a few to be sure it works ok.
- String expectedClassNames[] = {
- "com.sun.enterprise.config.serverbeans.Applications",
- "com.sun.enterprise.config.serverbeans.Configs",
- "com.sun.enterprise.config.serverbeans.Clusters"
+ private static final Class<?>[] expectedClassNames = {
+ com.sun.enterprise.config.serverbeans.Applications.class,
+ com.sun.enterprise.config.serverbeans.Configs.class,
+ com.sun.enterprise.config.serverbeans.Clusters.class
};
+ @Override
public String getFileName() {
return "DomainTest";
}
@Test
- public void testSubTypesOfDomain() {
+ public void testSubTypesOfDomain() throws Exception {
Domain domain = super.getHabitat().getService(Domain.class);
- try {
- Class<?>[] subTypes = ConfigSupport.getSubElementsTypes((ConfigBean) ConfigBean.unwrap(domain));
- for (Class subType : subTypes) {
- Logger.getAnonymousLogger().fine("Found class" + subType);
- }
- for (String expectedClassName : expectedClassNames) {
- boolean found=false;
- for (Class<?> subType : subTypes) {
- if (subType.getName().equals(expectedClassName)) {
- found = true;
- break;
- }
- }
- if (!found) {
- Logger.getAnonymousLogger().severe("Cannot find " + expectedClassName + " from list of subtypes");
- for (Class subType : subTypes) {
- Logger.getAnonymousLogger().severe("Found class" + subType);
- }
- throw new RuntimeException("Cannot find " + expectedClassName);
- }
- }
- } catch(ClassNotFoundException e) {
- e.printStackTrace();
- }
+ Class<?>[] subTypes = ConfigSupport.getSubElementsTypes((ConfigBean) Dom.unwrap(domain));
+ assertAll(
+ () -> assertThat(subTypes.length, equalTo(12)),
+ () -> assertThat(Set.of(subTypes), hasItems(expectedClassNames))
+ );
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TransactionCallBackTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TransactionCallBackTest.java
index 688d6e5..c9b8e9d 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TransactionCallBackTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TransactionCallBackTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,20 +17,24 @@
package com.sun.enterprise.configapi.tests;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
import org.glassfish.grizzly.config.dom.NetworkListener;
import org.glassfish.grizzly.config.dom.NetworkListeners;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.tests.utils.Utils;
import org.jvnet.hk2.config.ConfigBean;
import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.Dom;
import org.jvnet.hk2.config.TransactionCallBack;
import org.jvnet.hk2.config.TransactionFailure;
import org.jvnet.hk2.config.WriteableView;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.stringContainsInOrder;
/**
* User: Jerome Dochez
@@ -38,7 +43,7 @@
*/
public class TransactionCallBackTest extends ConfigPersistence {
- ServiceLocator habitat = Utils.instance.getHabitat(this);
+ private final ServiceLocator locator = Utils.instance.getHabitat(this);
/**
* Returns the file name without the .xml extension to load the test configuration
@@ -46,49 +51,51 @@
*
* @return the configuration file name
*/
+ @Override
public String getFileName() {
return "DomainTest";
}
+
@Override
public ServiceLocator getBaseServiceLocator() {
- return habitat;
+ return locator;
}
+
@Override
public ServiceLocator getHabitat() {
- return getBaseServiceLocator();
+ return getBaseServiceLocator();
}
+
+ @Override
public void doTest() throws TransactionFailure {
- ConfigBean serviceBean = (ConfigBean) ConfigBean.unwrap(habitat.<NetworkListeners>getService(NetworkListeners.class));
- Map<String, String> configChanges = new HashMap<String, String>();
+ ConfigBean serviceBean = (ConfigBean) Dom.unwrap(locator.<NetworkListeners> getService(NetworkListeners.class));
+ Map<String, String> configChanges = new HashMap<>();
configChanges.put("name", "funky-listener");
- ConfigSupport.createAndSet(serviceBean, NetworkListener.class, configChanges,
- new TransactionCallBack<WriteableView>() {
- @SuppressWarnings({"unchecked"})
- public void performOn(WriteableView param) throws TransactionFailure {
- // if you know the type...
- NetworkListener listener = param.getProxy(NetworkListener.class);
- listener.setName("Aleksey");
- // if you don't know the type
- Method m;
- try {
- m = param.getProxyType().getMethod("setAddress", String.class);
- m.invoke(param.getProxy(param.getProxyType()), "localhost");
- } catch (NoSuchMethodException e) {
- throw new TransactionFailure("Cannot find getProperty method", e);
- } catch (IllegalAccessException e) {
- throw new TransactionFailure("Cannot call getProperty method", e);
- } catch (InvocationTargetException e) {
- throw new TransactionFailure("Cannot call getProperty method", e);
- }
- }
- });
+ TransactionCallBack<WriteableView> callBack = view -> {
+ // if you know the type...
+ NetworkListener listener = view.getProxy(NetworkListener.class);
+ listener.setName("Aleksey");
+ // if you don't know the type
+ Method setAddressMethod;
+ try {
+ setAddressMethod = view.getProxyType().getMethod("setAddress", String.class);
+ setAddressMethod.invoke(view.getProxy(view.getProxyType()), "localhost");
+ } catch (NoSuchMethodException e1) {
+ throw new TransactionFailure("Cannot find getProperty method", e1);
+ } catch (IllegalAccessException | InvocationTargetException e2) {
+ throw new TransactionFailure("Cannot call getProperty method", e2);
+ }
+ };
+ ConfigSupport.createAndSet(serviceBean, NetworkListener.class, configChanges, callBack);
}
- public boolean assertResult(String s) {
- return s.contains("Aleksey") && s.contains("localhost");
+
+ @Override
+ public void assertResult(String xml) {
+ assertThat(xml, stringContainsInOrder("localhost", "Aleksey"));
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TransactionListenerTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TransactionListenerTest.java
index ea9b989..8e0c53a 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TransactionListenerTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TransactionListenerTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -17,11 +18,14 @@
package com.sun.enterprise.configapi.tests;
import com.sun.enterprise.config.serverbeans.HttpService;
+
+import java.beans.PropertyChangeEvent;
+import java.util.List;
+
import org.glassfish.grizzly.config.dom.Http;
import org.glassfish.grizzly.config.dom.NetworkConfig;
import org.glassfish.grizzly.config.dom.NetworkListener;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
@@ -29,35 +33,44 @@
import org.jvnet.hk2.config.Transactions;
import org.jvnet.hk2.config.UnprocessedChangeEvents;
-import java.beans.PropertyChangeEvent;
-import java.util.List;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+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 static org.junit.jupiter.api.Assertions.assertTrue;
/**
- * Created by IntelliJ IDEA.
* User: dochez
* Date: Jan 23, 2008
* Time: 10:48:55 PM
*/
public class TransactionListenerTest extends ConfigApiTest {
+
+ private HttpService httpService;
+ private List<PropertyChangeEvent> events;
+
+ @Override
public String getFileName() {
return "DomainTest";
}
- HttpService httpService = null;
- List<PropertyChangeEvent> events = null;
@Test
public void transactionEvents() throws Exception, TransactionFailure {
httpService = getHabitat().getService(HttpService.class);
- NetworkConfig networkConfig = getHabitat().getService(NetworkConfig.class);
- final NetworkListener netListener = networkConfig.getNetworkListeners()
- .getNetworkListener().get(0);
+ final NetworkConfig networkConfig = getHabitat().getService(NetworkConfig.class);
+ final NetworkListener netListener = networkConfig.getNetworkListeners().getNetworkListener().get(0);
final Http http = netListener.findHttpProtocol().getHttp();
final TransactionListener listener = new TransactionListener() {
- public void transactionCommited(List<PropertyChangeEvent> changes) {
- events = changes;
- }
+ @Override
+ public void transactionCommited(List<PropertyChangeEvent> changes) {
+ events = changes;
+ }
+
+
+ @Override
public void unprocessedTransactedEvents(List<UnprocessedChangeEvents> changes) {
}
};
@@ -66,41 +79,34 @@
try {
transactions.addTransactionsListener(listener);
- assertTrue(httpService!=null);
+ assertNotNull(httpService);
logger.fine("Max connections = " + http.getMaxConnections());
- ConfigSupport.apply(new SingleConfigCode<Http>() {
-
- public Object run(Http param) {
- param.setMaxConnections("500");
- return null;
- }
- }, http);
+ SingleConfigCode<Http> configCode = httpConfig -> {
+ httpConfig.setMaxConnections("500");
+ return null;
+ };
+ ConfigSupport.apply(configCode, http);
assertTrue("500".equals(http.getMaxConnections()));
transactions.waitForDrain();
- assertTrue(events!=null);
- logger.fine("Number of events " + events.size());
- assertTrue(events.size()==1);
+ assertNotNull(events);
+ assertThat(events, hasSize(1));
PropertyChangeEvent event = events.iterator().next();
- assertTrue("max-connections".equals(event.getPropertyName()));
- assertTrue("500".equals(event.getNewValue().toString()));
- assertTrue("250".equals(event.getOldValue().toString()));
- } catch(Exception t) {
- t.printStackTrace();
- throw t;
- }finally {
+ assertAll(
+ () -> assertEquals("max-connections", event.getPropertyName()),
+ () -> assertEquals("500", event.getNewValue().toString()),
+ () -> assertEquals("250", event.getOldValue().toString())
+ );
+ } finally {
transactions.removeTransactionsListener(listener);
}
// put back the right values in the domain to avoid test collisions
- ConfigSupport.apply(new SingleConfigCode<Http>() {
-
- public Object run(Http param) {
- param.setMaxConnections("250");
- return null;
- }
- }, http);
-
+ SingleConfigCode<Http> configCode = httpConfig -> {
+ httpConfig.setMaxConnections("250");
+ return null;
+ };
+ ConfigSupport.apply(configCode, http);
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TranslatedValuesTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TranslatedValuesTest.java
index ddc0e3a..b1ccfb6 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TranslatedValuesTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TranslatedValuesTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,14 +17,18 @@
package com.sun.enterprise.configapi.tests;
-import org.junit.Test;
-import org.junit.Before;
-import static org.junit.Assert.*;
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.config.serverbeans.JavaConfig;
import java.io.File;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.stringContainsInOrder;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
/**
* Simple test for translated values access
*
@@ -31,11 +36,12 @@
*/
public class TranslatedValuesTest extends ConfigApiTest {
+ @Override
public String getFileName() {
return "DomainTest";
}
- @Before
+ @BeforeEach
public void setup() {
System.setProperty("com.sun.aas.instanceRoot", "cafebabe");
System.setProperty("com.sun.aas.javaRoot", System.getProperty("user.home"));
@@ -54,9 +60,8 @@
if (System.getProperty("user.home").contains(File.separator)) {
JavaConfig config = getHabitat().getService(JavaConfig.class);
String javaRoot = config.getJavaHome();
- assertTrue(javaRoot.indexOf(File.separatorChar)!=-1);
+ assertThat(javaRoot, stringContainsInOrder(File.separator));
}
- assertTrue(true);
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TranslatedViewCreationTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TranslatedViewCreationTest.java
index 625289b..5427eea 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TranslatedViewCreationTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TranslatedViewCreationTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,19 +17,18 @@
package com.sun.enterprise.configapi.tests;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyVetoException;
-import java.util.List;
-
import com.sun.enterprise.config.serverbeans.HttpService;
import com.sun.enterprise.config.serverbeans.VirtualServer;
+
+import java.beans.PropertyChangeEvent;
+import java.util.List;
+
import org.glassfish.config.support.GlassFishConfigBean;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.tests.utils.Utils;
-import org.junit.After;
-import static org.junit.Assert.assertTrue;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
@@ -36,6 +36,13 @@
import org.jvnet.hk2.config.Transactions;
import org.jvnet.hk2.config.UnprocessedChangeEvents;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.fail;
+
/**
* User: Jerome Dochez
* Date: Jun 24, 2008
@@ -43,90 +50,89 @@
*/
public class TranslatedViewCreationTest extends ConfigApiTest {
- final static String propName = "com.sun.my.chosen.docroot";
+ private static final String propName = "com.sun.my.chosen.docroot";
+ private HttpService httpService;
+ private List<PropertyChangeEvent> events;
+ private ServiceLocator locator;
+
+ @Override
public String getFileName() {
return "DomainTest";
}
- HttpService httpService = null;
- List<PropertyChangeEvent> events;
- ServiceLocator habitat;
-
- @Before
+ @BeforeEach
public void setup() {
System.setProperty(propName, "/foo/bar/docroot");
- habitat = Utils.instance.getHabitat(this);
+ locator = Utils.instance.getHabitat(this);
+ }
+ @AfterEach
+ public void tearDown() {
+ System.setProperty(propName, "");
}
@Override
public ServiceLocator getBaseServiceLocator() {
- return habitat;
+ return locator;
}
@Test
public void createVirtualServerTest() throws TransactionFailure {
httpService = getHabitat().getService(HttpService.class);
final TransactionListener listener = new TransactionListener() {
- public void transactionCommited(List<PropertyChangeEvent> changes) {
- events = changes;
- }
+ @Override
+ public void transactionCommited(List<PropertyChangeEvent> changes) {
+ events = changes;
+ }
+
+
+ @Override
public void unprocessedTransactedEvents(List<UnprocessedChangeEvents> changes) {
}
};
Transactions transactions = getHabitat().getService(Transactions.class);
-
try {
transactions.addTransactionsListener(listener);
- assertTrue(httpService!=null);
- ConfigSupport.apply(new SingleConfigCode<HttpService>() {
-
- public Object run(HttpService param) throws PropertyVetoException, TransactionFailure {
- VirtualServer newVirtualServer = param.createChild(VirtualServer.class);
- newVirtualServer.setDocroot("${"+propName+"}");
- newVirtualServer.setId("translated-view-creation");
- param.getVirtualServer().add(newVirtualServer);
- return null;
- }
- }, httpService);
+ assertNotNull(httpService);
+ SingleConfigCode<HttpService> configCode = http -> {
+ VirtualServer newVirtualServer = http.createChild(VirtualServer.class);
+ newVirtualServer.setDocroot("${" + propName + "}");
+ newVirtualServer.setId("translated-view-creation");
+ http.getVirtualServer().add(newVirtualServer);
+ return null;
+ };
+ ConfigSupport.apply(configCode, httpService);
// first let check that our new virtual server has the right translated value
VirtualServer vs = httpService.getVirtualServerByName("translated-view-creation");
- assertTrue(vs!=null);
+ assertNotNull(vs);
String docRoot = vs.getDocroot();
- assertTrue("/foo/bar/docroot".equals(docRoot));
+ assertEquals("/foo/bar/docroot", docRoot);
transactions.waitForDrain();
- assertTrue(events!=null);
- logger.fine("Number of events " + events.size());
- assertTrue(events.size()==3);
+ assertNotNull(events);
+ assertThat(events, hasSize(3));
for (PropertyChangeEvent event : events) {
if ("virtual-server".equals(event.getPropertyName())) {
VirtualServer newVS = (VirtualServer) event.getNewValue();
- assertTrue(event.getOldValue()==null);
+ assertNull(event.getOldValue());
docRoot = newVS.getDocroot();
- assertTrue("/foo/bar/docroot".equals(docRoot));
+ assertEquals("/foo/bar/docroot", docRoot);
VirtualServer rawView = GlassFishConfigBean.getRawView(newVS);
- assertTrue(rawView!=null);
- assertTrue(rawView.getDocroot().equalsIgnoreCase("${" + propName + "}"));
+ assertNotNull(rawView);
+ assertEquals("${" + propName + "}", rawView.getDocroot());
return;
}
}
- assertTrue(false);
-
+ fail("virtual-server event wasn't found");
} finally {
transactions.removeTransactionsListener(listener);
}
}
-
- @After
- public void tearDown() {
- System.setProperty(propName, "");
- }
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TraversalTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TraversalTest.java
deleted file mode 100644
index ed4b0f2..0000000
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/TraversalTest.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-package com.sun.enterprise.configapi.tests;
-
-import org.glassfish.hk2.api.ServiceLocator;
-import org.jvnet.hk2.config.Dom;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.util.Set;
-import java.util.logging.Logger;
-
-import com.sun.enterprise.config.serverbeans.Domain;
-
-/**
- * Traverse a config tree using the hk2 model APIs.
- *
- * @author Jerome Dochez
- */
-public class TraversalTest extends ConfigApiTest {
-
- static Logger logger = Logger.getAnonymousLogger();
-
- public String getFileName() {
- return "DomainTest";
- }
-
- @Test
- public void traverse() {
- ServiceLocator habitat = super.getHabitat();
- Domain domain = Domain.class.cast(habitat.<Domain>getService(Domain.class));
- introspect(0, Dom.unwrap(domain));
- }
-
-
- @Ignore
- private void introspect(int indent, Dom proxy) {
- indent = indent + 1;
- Set<String> ss = proxy.getAttributeNames();
- String id = "";
- for (int i = 0; i < indent; i++) {
- id = id + " ";
- }
- logger.fine(id + "--------" + proxy.model.key);
- for (String a : ss) {
-
- logger.fine(id + a + "=" + proxy.attribute(a));
- }
-
-
- Set<String> elem = proxy.getElementNames();
-
- for (String bb : elem) {
-
-
- logger.fine(id + "<" + bb + ">");
- org.jvnet.hk2.config.ConfigModel.Property prop = proxy.model.getElement(bb);
- if (prop != null && proxy.model.getElement(bb).isLeaf()) {
- logger.fine(proxy.leafElement(bb));
- } else {
- introspect(indent, proxy.element(bb));
- }
- logger.fine(id + "</" + bb + ">");
- logger.fine(" ");
-
- }
- }
-}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/UnprocessedEventsTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/UnprocessedEventsTest.java
index d48d030..45e64f0 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/UnprocessedEventsTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/UnprocessedEventsTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009, 2021 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -23,10 +24,7 @@
import org.glassfish.grizzly.config.dom.NetworkListener;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.tests.utils.Utils;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigListener;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.ObservableBean;
@@ -37,14 +35,18 @@
import org.jvnet.hk2.config.UnprocessedChangeEvent;
import org.jvnet.hk2.config.UnprocessedChangeEvents;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
/**
* @author Jerome Dochez
*/
-public class UnprocessedEventsTest extends ConfigApiTest
- implements ConfigListener, TransactionListener {
+public class UnprocessedEventsTest extends ConfigApiTest implements ConfigListener, TransactionListener {
- ServiceLocator habitat = Utils.instance.getHabitat(this);
- UnprocessedChangeEvents unprocessed = null;
+ private final ServiceLocator habitat = Utils.instance.getHabitat(this);
+ private UnprocessedChangeEvents unprocessed;
/**
* Returns the DomainTest file name without the .xml extension to load the test configuration
@@ -52,6 +54,7 @@
*
* @return the configuration file name
*/
+ @Override
public String getFileName() {
return "DomainTest";
}
@@ -61,69 +64,64 @@
// let's find our target
NetworkConfig service = habitat.getService(NetworkConfig.class);
- NetworkListener listener = service.getNetworkListener("http-listener-1");
- assertNotNull(listener);
+ NetworkListener networkListener = service.getNetworkListener("http-listener-1");
+ assertNotNull(networkListener);
// Let's register a listener
- ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(listener);
+ ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(networkListener);
bean.addListener(this);
Transactions transactions = getHabitat().getService(Transactions.class);
try {
transactions.addTransactionsListener(this);
- ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {
- public Object run(NetworkListener param) {
- param.setPort("8908");
- return null;
- }
- }, listener);
+ SingleConfigCode<NetworkListener> configCode = listener -> {
+ listener.setPort("8908");
+ return null;
+ };
+ ConfigSupport.apply(configCode, networkListener);
// check the result.
- String port = listener.getPort();
+ String port = networkListener.getPort();
assertEquals(port, "8908");
// ensure events are delivered.
transactions.waitForDrain();
assertNotNull(unprocessed);
- ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {
- public Object run(NetworkListener param) {
- param.setPort("8080");
- return null;
- }
- }, listener);
-
- assertEquals(listener.getPort(), "8080");
+ SingleConfigCode<NetworkListener> configCodeReset = listener -> {
+ listener.setPort("8080");
+ return null;
+ };
+ ConfigSupport.apply(configCodeReset, networkListener);
+ assertEquals(networkListener.getPort(), "8080");
// ensure events are delivered.
transactions.waitForDrain();
assertNotNull(unprocessed);
-
- // finally
bean.removeListener(this);
} finally {
-
- // check we recevied the event
transactions.removeTransactionsListener(this);
}
}
+ @Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
- assertEquals("Array size", propertyChangeEvents.length, 1 );
-
+ assertEquals(propertyChangeEvents.length, 1, "Array size");
final UnprocessedChangeEvent unp = new UnprocessedChangeEvent(
propertyChangeEvents[0], "Java NIO port listener cannot reconfigure its port dynamically" );
unprocessed = new UnprocessedChangeEvents( unp );
return unprocessed;
}
+ @Override
public void transactionCommited(List<PropertyChangeEvent> changes) {
// don't care...
}
+ @Override
public void unprocessedTransactedEvents(List<UnprocessedChangeEvents> changes) {
- assertTrue(changes.size()==1);
+ assertThat(changes, hasSize(1));
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/VetoableChangeListenerTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/VetoableChangeListenerTest.java
index b51fc9e..6bbe1b7 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/VetoableChangeListenerTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/VetoableChangeListenerTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,19 +17,25 @@
package com.sun.enterprise.configapi.tests;
-import org.jvnet.hk2.config.*;
-import org.jvnet.hk2.config.types.*;
-import org.jvnet.hk2.component.*;
-import org.junit.*;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import com.sun.enterprise.config.serverbeans.HttpService;
+import com.sun.enterprise.config.serverbeans.VirtualServer;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyVetoException;
+import java.beans.VetoableChangeListener;
import org.glassfish.hk2.api.ServiceLocator;
-import org.glassfish.tests.utils.*;
+import org.glassfish.tests.utils.Utils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.jvnet.hk2.config.ConfigBean;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.ConstrainedBeanListener;
+import org.jvnet.hk2.config.SingleConfigCode;
+import org.jvnet.hk2.config.TransactionFailure;
-import com.sun.enterprise.config.serverbeans.*;
-
-import java.beans.*;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* This test registers an vetoable change listener on a config bean and vetoes
@@ -38,96 +45,58 @@
*/
public class VetoableChangeListenerTest extends ConfigApiTest implements VetoableChangeListener {
- ServiceLocator habitat;
- boolean result = false;
+ private ServiceLocator locator;
+ @Override
public String getFileName() {
return "DomainTest";
}
- @Before
+ @BeforeEach
public void setup() {
- habitat = Utils.instance.getHabitat(this);
+ locator = Utils.instance.getHabitat(this);
}
@Test
public void propertyChangeEventReceptionTest() throws TransactionFailure {
-
- HttpService httpService = habitat.getService(HttpService.class);
- assertNotNull(httpService);
-
- // let's find a acceptable target.
- VirtualServer target =null;
- for (VirtualServer vs : httpService.getVirtualServer()) {
- if (!vs.getProperty().isEmpty()) {
- target = vs;
- break;
- }
- }
-
+ final VirtualServer target = findTargetWithProperties();
assertNotNull(target);
+ SingleConfigCode<VirtualServer> configCode = vs -> {
+ vs.setId("foo");
+ vs.setAccessLog("Foo");
+ return null;
+ };
((ConfigBean) ConfigSupport.getImpl(target)).getOptionalFeature(ConstrainedBeanListener.class).addVetoableChangeListener(this);
-
- try {
- ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {
-
- public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
- param.setId("foo");
- param.setAccessLog("Foo");
- return null;
- }
- }, target);
- } catch(TransactionFailure e) {
- //e.printStackTrace();
- System.out.println("Got exception: " + e.getClass().getName() + " as expected, with message: " + e.getMessage());
- result=true;
- }
-
- assertTrue(result);
-
- result=false;
+ assertThrows(TransactionFailure.class, () -> ConfigSupport.apply(configCode, target));
// let's do it again.
- try {
- ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {
-
- public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
- param.setId("foo");
- param.setAccessLog("Foo");
- return null;
- }
- }, target);
- } catch(TransactionFailure e) {
- //e.printStackTrace();
- System.out.println("Got exception: " + e.getClass().getName() + " as expected, with message: " + e.getMessage());
- result=true;
- }
-
+ assertThrows(TransactionFailure.class, () -> ConfigSupport.apply(configCode, target));
((ConfigBean) ConfigSupport.getImpl(target)).getOptionalFeature(ConstrainedBeanListener.class).removeVetoableChangeListener(this);
- assertTrue(result);
-
- // this time it should work !
- try {
- ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {
-
- public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
- // first one is fine...
- param.setAccessLog("Foo");
- return null;
- }
- }, target);
- } catch(TransactionFailure e) {
- //e.printStackTrace();
- System.out.println("Got exception: " + e.getClass().getName() + " as expected, with message: " + e.getMessage());
- result=false;
- }
-
- assertTrue(result);
+ // this time it should work!
+ SingleConfigCode<VirtualServer> configCode2 = vs -> {
+ // first one is fine...
+ vs.setAccessLog("Foo");
+ return null;
+ };
+ ConfigSupport.apply(configCode2, target);
}
+ @Override
public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
throw new PropertyVetoException("I don't think so !", evt);
}
+
+
+ private VirtualServer findTargetWithProperties() {
+ HttpService httpService = locator.getService(HttpService.class);
+ assertNotNull(httpService);
+ for (VirtualServer vs : httpService.getVirtualServer()) {
+ if (!vs.getProperty().isEmpty()) {
+ return vs;
+ }
+ }
+ return null;
+ }
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/cluster/DuckMethodsTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/cluster/DuckMethodsTest.java
index 99967bf..fdb7805 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/cluster/DuckMethodsTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/cluster/DuckMethodsTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,17 +17,18 @@
package com.sun.enterprise.configapi.tests.cluster;
+import com.sun.enterprise.config.serverbeans.Cluster;
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.config.serverbeans.Server;
-import com.sun.enterprise.config.serverbeans.Cluster;
import com.sun.enterprise.configapi.tests.ConfigApiTest;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.tests.utils.Utils;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* Test a number of cluster related {@link org.jvnet.hk2.config.DuckTyped}
@@ -35,24 +37,25 @@
* @author Jerome Dochez
*/
public class DuckMethodsTest extends ConfigApiTest {
- ServiceLocator habitat;
+ private ServiceLocator locator;
+ @Override
public String getFileName() {
return "ClusterDomain";
}
- @Before
+ @BeforeEach
public void setup() {
- habitat = Utils.instance.getHabitat(this);
+ locator = Utils.instance.getHabitat(this);
}
@Test
public void getClusterFromServerTest() {
- Domain d = habitat.getService(Domain.class);
+ Domain d = locator.getService(Domain.class);
Server server = d.getServerNamed("server");
- assertTrue(server!=null);
+ assertNotNull(server);
Cluster cluster = server.getCluster();
- System.out.println("Cluster name is " + cluster.getName());
+ assertEquals("clusterA", cluster.getName());
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/concurrent/ConcurrentAccessTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/concurrent/ConcurrentAccessTest.java
index f61011a..0c66c05 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/concurrent/ConcurrentAccessTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/concurrent/ConcurrentAccessTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -18,49 +19,40 @@
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.configapi.tests.ConfigApiTest;
-import org.junit.Test;
+
+import java.util.concurrent.Semaphore;
+
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
-import java.beans.PropertyVetoException;
-import java.util.concurrent.Semaphore;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Concurrent access to the configuarion APIs related tests
* @author Jerome Dochez
*/
-
public class ConcurrentAccessTest extends ConfigApiTest {
+ @Override
public String getFileName() {
return "DomainTest";
}
@Test
- public void waitAndSuccessTest() throws TransactionFailure, InterruptedException {
- ConfigSupport.lockTimeOutInSeconds=1;
+ public void waitAndSuccessTest() throws Exception {
+ ConfigSupport.lockTimeOutInSeconds = 1;
runTest(200);
}
- @Test(expected=TransactionFailure.class)
- public void waitAndTimeOutTest() throws TransactionFailure, InterruptedException {
- ConfigSupport.lockTimeOutInSeconds=1;
- try {
- runTest(1200);
- } catch (TransactionFailure transactionFailure) {
- logger.fine("Got expected transaction failure, access timed out");
- throw transactionFailure;
- } catch (InterruptedException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- throw e;
- }
+ @Test
+ public void waitAndTimeOutTest() throws Exception {
+ ConfigSupport.lockTimeOutInSeconds = 1;
+ assertThrows(TransactionFailure.class, () -> runTest(1200));
}
-
-
- private void runTest(final int waitTime) throws TransactionFailure, InterruptedException {
-
+ private void runTest(final int waitTime) throws Exception {
final Domain domain = getHabitat().getService(Domain.class);
// my lock.
@@ -72,53 +64,43 @@
endOfAccess.acquire();
final long begin = System.currentTimeMillis();
-
+ final SingleConfigCode<Domain> configCode = domain1 -> {
+ logger.fine("got the lock at " + (System.currentTimeMillis() - begin));
+ lock.release();
+ try {
+ Thread.sleep(waitTime);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ logger.fine("release the lock at " + (System.currentTimeMillis() - begin));
+ return null;
+ };
// let's start a thread to hold the lock on Domain...
- Thread t = new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- ConfigSupport.apply(new SingleConfigCode<Domain>() {
- @Override
- public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
- logger.fine("got the lock at " + (System.currentTimeMillis() - begin));
- lock.release();
- try {
- Thread.sleep(waitTime);
- } catch (InterruptedException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- logger.fine("release the lock at " + (System.currentTimeMillis() - begin));
- return null;
- };
- }, domain);
- } catch(TransactionFailure e) {
- e.printStackTrace();
- }
+ Runnable job = () -> {
+ try {
+ ConfigSupport.apply(configCode, domain);
+ } catch (TransactionFailure e) {
+ e.printStackTrace();
+ } finally {
endOfAccess.release();
}
- });
+ };
+ final Thread t = new Thread(job);
t.start();
-
// let's change the last modified date...
lock.acquire();
logger.fine("looking for second lock at " + (System.currentTimeMillis() - begin));
+ final SingleConfigCode<Domain> releaseLockCode = domain1 -> {
+ logger.fine("got the second lock at " + (System.currentTimeMillis() - begin));
+ lock.release();
+ return null;
+ };
try {
- ConfigSupport.apply(new SingleConfigCode<Domain>() {
- @Override
- public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
- logger.fine("got the second lock at " + (System.currentTimeMillis() - begin));
- lock.release();
- return null;
- }
- }, domain);
+ ConfigSupport.apply(releaseLockCode, domain);
} finally {
endOfAccess.acquire();
}
-
-
}
-
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/dvt/AccessLogAllDefaultsTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/dvt/AccessLogAllDefaultsTest.java
index d479b9e..9bf9dd8 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/dvt/AccessLogAllDefaultsTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/dvt/AccessLogAllDefaultsTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -14,45 +15,39 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
package com.sun.enterprise.configapi.tests.dvt;
import com.sun.enterprise.config.serverbeans.AccessLog;
import com.sun.enterprise.configapi.tests.ConfigApiTest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import static org.junit.Assert.*;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
- *
* @author kedar
*/
public class AccessLogAllDefaultsTest extends ConfigApiTest {
- private AccessLog al = null;
-
- public AccessLogAllDefaultsTest() {
- }
+ private AccessLog al;
@Override
public String getFileName() {
return ("AccessLogAllDefaultsTest"); //this is the xml to load
}
- @Before
+ @BeforeEach
public void setUp() {
al = super.getHabitat().getService(AccessLog.class);
}
- @After
+ @AfterEach
public void tearDown() {
al = null;
}
+
@Test
public void testAllDefaults() {
assertEquals("true", al.getRotationEnabled());
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/dvt/SecurityServiceDefaultsTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/dvt/SecurityServiceDefaultsTest.java
index ba4ff44..aa9661a 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/dvt/SecurityServiceDefaultsTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/dvt/SecurityServiceDefaultsTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -18,48 +19,43 @@
import com.sun.enterprise.config.serverbeans.SecurityService;
import com.sun.enterprise.configapi.tests.ConfigApiTest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import static org.junit.Assert.*;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests the JdbcConnectionPool config bean's defaults.
* @author Kedar Mhaswade (km@dev.java.net)
*/
-
public class SecurityServiceDefaultsTest extends ConfigApiTest {
- SecurityService ss = null;
-
- public SecurityServiceDefaultsTest() {
- }
+ private SecurityService securityService;
@Override
public String getFileName() {
- return ("SecurityServiceDefaults"); //this is the xml to load
+ return "SecurityServiceDefaults"; //this is the xml to load
}
- @Before
+ @BeforeEach
public void setUp() {
- ss = super.getHabitat().getService(SecurityService.class);
+ securityService = super.getHabitat().getService(SecurityService.class);
}
- @After
+ @AfterEach
public void tearDown() {
- ss = null;
+ securityService = null;
}
- // TODO add test methods here.
- // The methods must be annotated with annotation @Test. For example:
- //
@Test
public void testFewDefaults() {
- assertEquals("file", ss.getDefaultRealm());
- assertEquals("true", ss.getActivateDefaultPrincipalToRoleMapping());
- assertEquals("AttributeDeprecated", ss.getAnonymousRole());
- assertEquals("false", ss.getAuditEnabled());
- assertEquals("default", ss.getAuditModules());
- assertEquals("default", ss.getJacc());
+ assertEquals("file", securityService.getDefaultRealm());
+ assertEquals("true", securityService.getActivateDefaultPrincipalToRoleMapping());
+ assertEquals("AttributeDeprecated", securityService.getAnonymousRole());
+ assertEquals("false", securityService.getAuditEnabled());
+ assertEquals("default", securityService.getAuditModules());
+ assertEquals("default", securityService.getJacc());
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/AnApplicationExtension.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/AnApplicationExtension.java
similarity index 90%
rename from nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/AnApplicationExtension.java
rename to nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/AnApplicationExtension.java
index 6007987..38c2f2a 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/AnApplicationExtension.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/AnApplicationExtension.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2011, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -14,10 +15,10 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
-package com.sun.enterprise.configapi.tests.extensibility;
+package com.sun.enterprise.configapi.tests.example;
import com.sun.enterprise.config.serverbeans.ApplicationExtension;
-import org.junit.Ignore;
+
import org.jvnet.hk2.config.Attribute;
import org.jvnet.hk2.config.Configured;
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/HttpListenerContainer.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/HttpListenerContainer.java
similarity index 83%
rename from nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/HttpListenerContainer.java
rename to nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/HttpListenerContainer.java
index 256c2bd..759f498 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/HttpListenerContainer.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/HttpListenerContainer.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -14,15 +15,12 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
-package com.sun.enterprise.configapi.tests;
+package com.sun.enterprise.configapi.tests.example;
import java.beans.PropertyChangeEvent;
import org.glassfish.grizzly.config.dom.NetworkListener;
import org.glassfish.hk2.api.PerLookup;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import org.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.config.ConfigListener;
import org.jvnet.hk2.config.UnprocessedChangeEvents;
@@ -30,20 +28,25 @@
import jakarta.inject.Inject;
import jakarta.inject.Named;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
/**
* Simple container code that is interested in getting notification of injected model changes
*
* @author Jerome Dochez
*/
-@Service @PerLookup
+@Service
+@PerLookup
public class HttpListenerContainer implements ConfigListener {
@Inject
@Named("http-listener-1")
- NetworkListener httpListener;
+ public NetworkListener httpListener;
- volatile boolean received=false;
+ public volatile boolean received = false;
+ @Override
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
if (received) {
// I am alredy happy
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/RandomContainer.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/RandomContainer.java
similarity index 79%
rename from nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/RandomContainer.java
rename to nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/RandomContainer.java
index a0ad0df..6dcc240 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/RandomContainer.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/RandomContainer.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -14,13 +15,13 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
-package com.sun.enterprise.configapi.tests.extensibility;
+package com.sun.enterprise.configapi.tests.example;
import org.glassfish.api.admin.config.Container;
import org.glassfish.api.admin.config.Named;
import org.jvnet.hk2.config.Attribute;
-import org.jvnet.hk2.config.Element;
import org.jvnet.hk2.config.Configured;
+import org.jvnet.hk2.config.Element;
/**
* @author Jerome Dochez
@@ -29,12 +30,12 @@
public interface RandomContainer extends Container, Named {
@Attribute
- public String getNumberOfRuntime();
+ String getNumberOfRuntime();
- public void setNumberOfRuntime();
+ void setNumberOfRuntime();
@Element
- public RandomElement getRandomElement();
+ RandomElement getRandomElement();
- public void setRandomElement(RandomElement randomElement);
+ void setRandomElement(RandomElement randomElement);
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/RandomElement.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/RandomElement.java
similarity index 84%
rename from nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/RandomElement.java
rename to nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/RandomElement.java
index 2e4fc72..7b8fe53 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/RandomElement.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/RandomElement.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -14,12 +15,11 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
-package com.sun.enterprise.configapi.tests.extensibility;
+package com.sun.enterprise.configapi.tests.example;
-import org.jvnet.hk2.config.Configured;
-import org.jvnet.hk2.config.ConfigBeanProxy;
import org.jvnet.hk2.config.Attribute;
-import org.glassfish.api.admin.config.Named;
+import org.jvnet.hk2.config.ConfigBeanProxy;
+import org.jvnet.hk2.config.Configured;
/**
* @author Jerome Dochez
@@ -28,7 +28,7 @@
public interface RandomElement extends ConfigBeanProxy {
@Attribute
- public String getAttr1();
+ String getAttr1();
- public void setAttr1(String string);
+ void setAttr1(String string);
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/RandomExtension.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/RandomExtension.java
similarity index 89%
rename from nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/RandomExtension.java
rename to nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/RandomExtension.java
index b627544..53c78fd 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/RandomExtension.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/example/RandomExtension.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -14,7 +15,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
-package com.sun.enterprise.configapi.tests.extensibility;
+package com.sun.enterprise.configapi.tests.example;
import org.glassfish.api.admin.config.ConfigExtension;
import org.jvnet.hk2.config.Attribute;
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/ContainerExtensionTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/ContainerExtensionTest.java
index aebcc39..d6a70e1 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/ContainerExtensionTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/extensibility/ContainerExtensionTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -17,17 +18,26 @@
package com.sun.enterprise.configapi.tests.extensibility;
import com.sun.enterprise.config.serverbeans.Application;
-import com.sun.enterprise.configapi.tests.ConfigApiTest;
import com.sun.enterprise.config.serverbeans.Config;
import com.sun.enterprise.config.serverbeans.Domain;
-import org.glassfish.tests.utils.Utils;
-import org.glassfish.api.admin.config.Container;
-import org.glassfish.hk2.api.ServiceLocator;
-import org.junit.Test;
-import static org.junit.Assert.*;
+import com.sun.enterprise.configapi.tests.ConfigApiTest;
+import com.sun.enterprise.configapi.tests.example.AnApplicationExtension;
+import com.sun.enterprise.configapi.tests.example.RandomContainer;
+import com.sun.enterprise.configapi.tests.example.RandomElement;
+import com.sun.enterprise.configapi.tests.example.RandomExtension;
import java.util.List;
+import org.glassfish.api.admin.config.Container;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.tests.utils.Utils;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
/**
* @author Jerome Dochez
*/
@@ -43,10 +53,9 @@
@Test
public void existenceTest() {
-
Config config = habitat.<Domain>getService(Domain.class).getConfigs().getConfig().get(0);
List<Container> containers = config.getContainers();
- assertTrue(containers.size()==2);
+ assertThat(containers, hasSize(2));
RandomContainer container = (RandomContainer) containers.get(0);
assertEquals("random", container.getName());
assertEquals("1243", container.getNumberOfRuntime());
@@ -67,6 +76,6 @@
public void applicationExtensionTest() {
Application a = habitat.getService(Application.class);
List<AnApplicationExtension> taes = a.getExtensionsByType(AnApplicationExtension.class);
- assertEquals(taes.size(), 2);
+ assertThat(taes, hasSize(2));
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/model/.gitkeep_empty_dir b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/model/.gitkeep_empty_dir
deleted file mode 100644
index e69de29..0000000
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/model/.gitkeep_empty_dir
+++ /dev/null
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/typedlistener/TypedListenerTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/typedlistener/TypedListenerTest.java
index 10b48ca..a437b06 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/typedlistener/TypedListenerTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/typedlistener/TypedListenerTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2011, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,16 +20,22 @@
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.config.serverbeans.SystemProperty;
import com.sun.enterprise.configapi.tests.ConfigApiTest;
+
import java.beans.PropertyChangeEvent;
-import java.beans.PropertyVetoException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
-import java.util.logging.Level;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
-import org.jvnet.hk2.config.*;
+import org.junit.jupiter.api.Test;
+import org.jvnet.hk2.config.ConfigListener;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.SingleConfigCode;
+import org.jvnet.hk2.config.TransactionFailure;
+import org.jvnet.hk2.config.Transactions;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test the listeners per type registration/events/un-registration.
@@ -36,8 +43,8 @@
*/
public class TypedListenerTest extends ConfigApiTest {
- List<PropertyChangeEvent> events = null;
- AtomicInteger listenersInvoked = new AtomicInteger();
+ private List<PropertyChangeEvent> events;
+ private final AtomicInteger listenersInvoked = new AtomicInteger();
@Override
public String getFileName() {
@@ -46,40 +53,30 @@
@Test
public void addElementTest() throws TransactionFailure {
-
final Domain domain = getHabitat().getService(Domain.class);
- final ConfigListener configListener = new ConfigListener() {
- @Override
- public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
- events = Arrays.asList(propertyChangeEvents);
- return null;
- }
+ final ConfigListener configListener = propertyChangeEvents -> {
+ events = Arrays.asList(propertyChangeEvents);
+ return null;
};
Transactions transactions = getHabitat().getService(Transactions.class);
-
try {
transactions.addListenerForType(SystemProperty.class, configListener);
- assertTrue(domain!=null);
+ assertNotNull(domain);
// adding
- ConfigSupport.apply(new SingleConfigCode<Domain>() {
-
- @Override
- public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
- SystemProperty prop = domain.createChild(SystemProperty.class);
- domain.getSystemProperty().add(prop);
- prop.setName("Jerome");
- prop.setValue("was here");
- return prop;
- }
- }, domain);
+ SingleConfigCode<Domain> configCode = domain1 -> {
+ SystemProperty sysProp = domain1.createChild(SystemProperty.class);
+ domain1.getSystemProperty().add(sysProp);
+ sysProp.setName("Jerome");
+ sysProp.setValue("was here");
+ return sysProp;
+ };
+ ConfigSupport.apply(configCode, domain);
transactions.waitForDrain();
- assertTrue(events!=null);
- logger.log(Level.FINE, "Number of events {0}", events.size());
- assertTrue(events.size()==3);
+ assertThat(events, hasSize(3));
for (PropertyChangeEvent event : events) {
logger.fine(event.toString());
}
@@ -87,20 +84,16 @@
// modification
for (SystemProperty prop : domain.getSystemProperty()) {
- if (prop.getName().equals("Jerome")) {
- ConfigSupport.apply(new SingleConfigCode<SystemProperty>() {
- @Override
- public Object run(SystemProperty param) throws PropertyVetoException, TransactionFailure {
- param.setValue("was also here");
- return null;
- }
- },prop);
+ if ("Jerome".equals(prop.getName())) {
+ SingleConfigCode<SystemProperty> configCode2 = sysProp -> {
+ sysProp.setValue("was also here");
+ return null;
+ };
+ ConfigSupport.apply(configCode2, prop);
break;
}
}
- assertTrue(events!=null);
- logger.log(Level.FINE, "Number of events {0}", events.size());
- assertTrue(events.size()==1);
+ assertThat(events, hasSize(1));
for (PropertyChangeEvent event : events) {
logger.fine(event.toString());
}
@@ -108,24 +101,19 @@
events = null;
// removal
- assertNotNull(ConfigSupport.apply(new SingleConfigCode<Domain>() {
-
- @Override
- public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
- for (SystemProperty prop : domain.getSystemProperty()) {
- if (prop.getName().equals("Jerome")) {
- domain.getSystemProperty().remove(prop);
- return prop;
- }
- }
- return null;
- }
- }, domain));
+ SingleConfigCode<Domain> configCode2 = domain1 -> {
+ for (SystemProperty prop : domain1.getSystemProperty()) {
+ if ("Jerome".equals(prop.getName())) {
+ domain1.getSystemProperty().remove(prop);
+ return prop;
+ }
+ }
+ return null;
+ };
+ assertNotNull(ConfigSupport.apply(configCode2, domain));
transactions.waitForDrain();
- assertTrue(events!=null);
- logger.log(Level.FINE, "Number of events {0}", events.size());
- assertTrue(events.size()==1);
+ assertThat(events, hasSize(1));
for (PropertyChangeEvent event : events) {
logger.fine(event.toString());
}
@@ -137,41 +125,31 @@
@Test
public void multipleListeners() throws TransactionFailure {
final Domain domain = getHabitat().getService(Domain.class);
- final ConfigListener configListener1 = new ConfigListener() {
- @Override
- public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
- listenersInvoked.incrementAndGet();
- return null;
- }
+ assertNotNull(domain);
+
+ final ConfigListener configListener1 = propertyChangeEvents -> {
+ listenersInvoked.incrementAndGet();
+ return null;
};
- final ConfigListener configListener2 = new ConfigListener() {
- @Override
- public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
- listenersInvoked.incrementAndGet();
- return null;
- }
+ final ConfigListener configListener2 = propertyChangeEvents -> {
+ listenersInvoked.incrementAndGet();
+ return null;
};
Transactions transactions = getHabitat().getService(Transactions.class);
-
try {
transactions.addListenerForType(SystemProperty.class, configListener1);
transactions.addListenerForType(SystemProperty.class, configListener2);
- assertTrue(domain!=null);
-
// adding
- ConfigSupport.apply(new SingleConfigCode<Domain>() {
-
- @Override
- public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
- SystemProperty prop = domain.createChild(SystemProperty.class);
- domain.getSystemProperty().add(prop);
- prop.setName("Jerome");
- prop.setValue("was here");
- return prop;
- }
- }, domain);
+ SingleConfigCode<Domain> configCode = domain1 -> {
+ SystemProperty prop = domain1.createChild(SystemProperty.class);
+ domain1.getSystemProperty().add(prop);
+ prop.setName("Jerome");
+ prop.setValue("was here");
+ return prop;
+ };
+ ConfigSupport.apply(configCode, domain);
transactions.waitForDrain();
assertTrue(listenersInvoked.intValue()==2);
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/validation/FieldsValidationTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/validation/FieldsValidationTest.java
index 63ee830..a63ef38 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/validation/FieldsValidationTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/validation/FieldsValidationTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -18,21 +19,27 @@
import com.sun.enterprise.config.serverbeans.AdminService;
import com.sun.enterprise.configapi.tests.ConfigApiTest;
-import junit.framework.Assert;
-import org.junit.Test;
+
+import java.beans.PropertyVetoException;
+
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
import jakarta.validation.ConstraintViolationException;
-import java.beans.PropertyVetoException;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* Test Field validation
*/
-
public class FieldsValidationTest extends ConfigApiTest {
+ @Override
public String getFileName() {
return "DomainTest";
}
@@ -40,7 +47,7 @@
@Test
public void testNotNullField() {
AdminService admin = super.getHabitat().getService(AdminService.class);
- Assert.assertNotNull(admin);
+ assertNotNull(admin);
try {
ConfigSupport.apply(new SingleConfigCode<AdminService>() {
@Override
@@ -49,11 +56,9 @@
return null;
}
}, admin);
- Assert.fail("Exception not raised when setting a @NotNull annotated field with null");
+ fail("Exception not raised when setting a @NotNull annotated field with null");
} catch(TransactionFailure e) {
- if (e.getCause()!=null) {
- Assert.assertTrue(e.getCause() instanceof ConstraintViolationException);
- }
+ assertThat(e.getCause(), instanceOf(ConstraintViolationException.class));
}
}
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/validation/ReferenceConstrainClusterTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/validation/ReferenceConstrainClusterTest.java
index fec0a1f..d8632c9 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/validation/ReferenceConstrainClusterTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/validation/ReferenceConstrainClusterTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,27 +20,30 @@
import com.sun.enterprise.config.serverbeans.Cluster;
import com.sun.enterprise.config.serverbeans.ServerRef;
import com.sun.enterprise.configapi.tests.ConfigApiTest;
+
import java.util.HashMap;
import java.util.Map;
-import jakarta.validation.ConstraintViolationException;
-import org.junit.Test;
-import org.junit.Before;
+
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.tests.utils.Utils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigBean;
import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.Dom;
import org.jvnet.hk2.config.TransactionFailure;
-import static org.junit.Assert.*;
+import jakarta.validation.ConstraintViolationException;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
/**
- *
* @author mmares
*/
public class ReferenceConstrainClusterTest extends ConfigApiTest {
-// private Logger logger = Logger.getLogger(ReferenceConstrainTest.class.getName());
- private ServiceLocator habitat;
+ private ServiceLocator locator;
@Override
public String getFileName() {
@@ -48,7 +52,7 @@
@Override
public ServiceLocator getBaseServiceLocator() {
- return habitat;
+ return locator;
}
private ConstraintViolationException findConstrViolation(Throwable thr) {
@@ -61,19 +65,33 @@
return findConstrViolation(thr.getCause());
}
- @Before
+ @BeforeEach
public void createNewHabitat() {
- this.habitat = Utils.instance.getHabitat(this);
+ this.locator = Utils.instance.getHabitat(this);
+ }
+
+ @Test
+ public void clusterServerRefValid() throws TransactionFailure {
+ Cluster cluster = locator.getService(Cluster.class, "clusterA");
+ assertNotNull(cluster);
+ ServerRef sref = cluster.getServerRef().get(0);
+ ConfigBean serverConfig = (ConfigBean) Dom.unwrap(sref);
+ Map<ConfigBean, Map<String, String>> changes = new HashMap<>();
+ Map<String, String> configChanges = new HashMap<>();
+ configChanges.put("ref", "server");
+ changes.put(serverConfig, configChanges);
+ ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
+ cs.apply(changes);
}
@Test
public void clusterServerRefInvalid() throws TransactionFailure {
- Cluster cluster = habitat.getService(Cluster.class, "clusterA");
+ Cluster cluster = locator.getService(Cluster.class, "clusterA");
assertNotNull(cluster);
ServerRef sref = cluster.getServerRef().get(0);
- ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(sref);
- Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
- Map<String, String> configChanges = new HashMap<String, String>();
+ ConfigBean serverConfig = (ConfigBean) Dom.unwrap(sref);
+ Map<ConfigBean, Map<String, String>> changes = new HashMap<>();
+ Map<String, String> configChanges = new HashMap<>();
configChanges.put("ref", "server-nonexist");
changes.put(serverConfig, configChanges);
try {
@@ -87,30 +105,25 @@
}
@Test
- public void clusterServerRefValid() throws TransactionFailure {
- Cluster cluster = habitat.getService(Cluster.class, "clusterA");
+ public void clusterConfigRefValid() throws TransactionFailure {
+ Cluster cluster = locator.getService(Cluster.class, "clusterA");
assertNotNull(cluster);
- ServerRef sref = cluster.getServerRef().get(0);
- ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(sref);
- Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
- Map<String, String> configChanges = new HashMap<String, String>();
- configChanges.put("ref", "server");
+ ConfigBean serverConfig = (ConfigBean) Dom.unwrap(cluster);
+ Map<ConfigBean, Map<String, String>> changes = new HashMap<>();
+ Map<String, String> configChanges = new HashMap<>();
+ configChanges.put("config-ref", "server-config");
changes.put(serverConfig, configChanges);
- try {
- ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
- cs.apply(changes);
- } catch (TransactionFailure tf) {
- fail("Can not reach this point");
- }
+ ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
+ cs.apply(changes);
}
@Test
public void clusterConfigRefInvalid() throws TransactionFailure {
- Cluster cluster = habitat.getService(Cluster.class, "clusterA");
+ Cluster cluster = locator.getService(Cluster.class, "clusterA");
assertNotNull(cluster);
- ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(cluster);
- Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
- Map<String, String> configChanges = new HashMap<String, String>();
+ ConfigBean serverConfig = (ConfigBean) Dom.unwrap(cluster);
+ Map<ConfigBean, Map<String, String>> changes = new HashMap<>();
+ Map<String, String> configChanges = new HashMap<>();
configChanges.put("config-ref", "server-config-nonexist");
changes.put(serverConfig, configChanges);
try {
@@ -122,22 +135,4 @@
assertNotNull(cv);
}
}
-
- @Test
- public void clusterConfigRefValid() throws TransactionFailure {
- Cluster cluster = habitat.getService(Cluster.class, "clusterA");
- assertNotNull(cluster);
- ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(cluster);
- Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
- Map<String, String> configChanges = new HashMap<String, String>();
- configChanges.put("config-ref", "server-config");
- changes.put(serverConfig, configChanges);
- try {
- ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
- cs.apply(changes);
- } catch (TransactionFailure tf) {
- fail("Can not reach this point");
- }
- }
-
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/validation/ReferenceConstrainTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/validation/ReferenceConstrainTest.java
index b406181..fcbf233 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/validation/ReferenceConstrainTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/validation/ReferenceConstrainTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,18 +20,23 @@
import com.sun.enterprise.config.serverbeans.JmxConnector;
import com.sun.enterprise.config.serverbeans.Server;
import com.sun.enterprise.configapi.tests.ConfigApiTest;
+
import java.util.HashMap;
import java.util.Map;
-import jakarta.validation.ConstraintViolationException;
-import org.junit.Test;
-import org.junit.Before;
+
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.tests.utils.Utils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.jvnet.hk2.config.ConfigBean;
import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.Dom;
import org.jvnet.hk2.config.TransactionFailure;
-import static org.junit.Assert.*;
+import jakarta.validation.ConstraintViolationException;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
/**
*
@@ -38,8 +44,7 @@
*/
public class ReferenceConstrainTest extends ConfigApiTest {
-// private Logger logger = Logger.getLogger(ReferenceConstrainTest.class.getName());
- private ServiceLocator habitat;
+ private ServiceLocator locator;
@Override
public String getFileName() {
@@ -48,7 +53,7 @@
@Override
public ServiceLocator getBaseServiceLocator() {
- return habitat;
+ return locator;
}
private ConstraintViolationException findConstrViolation(Throwable thr) {
@@ -61,18 +66,31 @@
return findConstrViolation(thr.getCause());
}
- @Before
+ @BeforeEach
public void createNewHabitat() {
- this.habitat = Utils.instance.getHabitat(this);
+ this.locator = Utils.instance.getHabitat(this);
+ }
+
+ @Test
+ public void serverConfigRefValid() throws TransactionFailure {
+ Server server = locator.getService(Server.class, "server");
+ assertNotNull(server);
+ ConfigBean serverConfig = (ConfigBean) Dom.unwrap(server);
+ Map<ConfigBean, Map<String, String>> changes = new HashMap<>();
+ Map<String, String> configChanges = new HashMap<>();
+ configChanges.put("config-ref", "server-config");
+ changes.put(serverConfig, configChanges);
+ ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
+ cs.apply(changes);
}
@Test
public void serverConfigRefInvalid() throws TransactionFailure {
- Server server = habitat.getService(Server.class, "server");
+ Server server = locator.getService(Server.class, "server");
assertNotNull(server);
- ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(server);
- Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
- Map<String, String> configChanges = new HashMap<String, String>();
+ ConfigBean serverConfig = (ConfigBean) Dom.unwrap(server);
+ Map<ConfigBean, Map<String, String>> changes = new HashMap<>();
+ Map<String, String> configChanges = new HashMap<>();
configChanges.put("config-ref", "server-config-nonexist");
changes.put(serverConfig, configChanges);
try {
@@ -86,29 +104,25 @@
}
@Test
- public void serverConfigRefValid() throws TransactionFailure {
- Server server = habitat.getService(Server.class, "server");
- assertNotNull(server);
- ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(server);
- Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
- Map<String, String> configChanges = new HashMap<String, String>();
- configChanges.put("config-ref", "server-config");
+ public void jmxConnectorAuthRealmRefValid() throws TransactionFailure {
+ JmxConnector jmxConnector = locator.getService(JmxConnector.class, "system");
+ assertNotNull(jmxConnector);
+ ConfigBean serverConfig = (ConfigBean) Dom.unwrap(jmxConnector);
+ Map<ConfigBean, Map<String, String>> changes = new HashMap<>();
+ Map<String, String> configChanges = new HashMap<>();
+ configChanges.put("auth-realm-name", "file");
changes.put(serverConfig, configChanges);
- try {
- ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
- cs.apply(changes);
- } catch (TransactionFailure tf) {
- fail("Can not reach this point");
- }
+ ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
+ cs.apply(changes);
}
@Test
public void jmxConnectorAuthRealmRefInvalid() throws TransactionFailure {
- JmxConnector jmxConnector = habitat.getService(JmxConnector.class, "system");
+ JmxConnector jmxConnector = locator.getService(JmxConnector.class, "system");
assertNotNull(jmxConnector);
- ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(jmxConnector);
- Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
- Map<String, String> configChanges = new HashMap<String, String>();
+ ConfigBean serverConfig = (ConfigBean) Dom.unwrap(jmxConnector);
+ Map<ConfigBean, Map<String, String>> changes = new HashMap<>();
+ Map<String, String> configChanges = new HashMap<>();
configChanges.put("auth-realm-name", "realm-not-exist");
changes.put(serverConfig, configChanges);
try {
@@ -121,21 +135,4 @@
}
}
- @Test
- public void jmxConnectorAuthRealmRefValid() throws TransactionFailure {
- JmxConnector jmxConnector = habitat.getService(JmxConnector.class, "system");
- assertNotNull(jmxConnector);
- ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(jmxConnector);
- Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
- Map<String, String> configChanges = new HashMap<String, String>();
- configChanges.put("auth-realm-name", "file");
- changes.put(serverConfig, configChanges);
- try {
- ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
- cs.apply(changes);
- } catch (TransactionFailure tf) {
- fail("Can not reach this point");
- }
- }
-
}
diff --git a/nucleus/admin/config-api/src/test/java/org/glassfish/config/support/DomainXmlPreParserTest.java b/nucleus/admin/config-api/src/test/java/org/glassfish/config/support/DomainXmlPreParserTest.java
index 3f17c02..e437c98 100644
--- a/nucleus/admin/config-api/src/test/java/org/glassfish/config/support/DomainXmlPreParserTest.java
+++ b/nucleus/admin/config-api/src/test/java/org/glassfish/config/support/DomainXmlPreParserTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,28 +17,35 @@
package org.glassfish.config.support;
-import java.io.*;
-import java.net.*;
-import java.util.*;
+import java.net.URL;
+import java.util.List;
+
import javax.xml.stream.XMLInputFactory;
+
import org.glassfish.config.support.DomainXmlPreParser.DomainXmlPreParserException;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
/**
- *
* @author bnevins
*/
public class DomainXmlPreParserTest {
- public DomainXmlPreParserTest() {
- }
+ private static URL stock, i1, i1i2, c1i1, c1i1c1i2, noconfigfori1;
+ private static ClassLoader classLoader = DomainXmlPreParserTest.class.getClassLoader();
+ private static XMLInputFactory xif = XMLInputFactory.newInstance();
- @BeforeClass
+ @BeforeAll
public static void setUpClass() throws Exception {
stock = loadURL("parser/stock.xml");
i1 = loadURL("parser/i1.xml");
@@ -54,22 +62,10 @@
return url;
}
- @AfterClass
- public static void tearDownClass() throws Exception {
- }
-
- @Before
- public void setUp() {
- }
-
- @After
- public void tearDown() {
- }
-
- @Test(expected=DomainXmlPreParser.DomainXmlPreParserException.class)
+ @Test
public void stockDomainHasNoInstance() throws DomainXmlPreParserException {
System.out.println("stockDomainHasNoInstance");
- DomainXmlPreParser pp = new DomainXmlPreParser(stock, xif, "i1");
+ assertThrows(DomainXmlPreParserException.class, () -> new DomainXmlPreParser(stock, xif, "i1"));
}
@Test
@@ -80,10 +76,10 @@
String clusterName = pp.getClusterName();
String configName = pp.getConfigName();
- assertTrue(servers.size() == 1);
- assertTrue(servers.get(0).equals("i1"));
+ assertThat(servers, hasSize(1));
+ assertEquals("i1", servers.get(0));
assertNull(clusterName);
- assertEquals(configName, "i1-config");
+ assertEquals("i1-config", configName);
}
@Test
@@ -94,11 +90,10 @@
String clusterName = pp.getClusterName();
String configName = pp.getConfigName();
- assertTrue(servers.size() == 1);
- assertTrue(servers.contains("i1"));
- assertFalse(servers.contains("i2"));
+ assertThat(servers, hasSize(1));
+ assertThat(servers, contains("i1"));
assertNull(clusterName);
- assertEquals(configName, "i1-config");
+ assertEquals("i1-config", configName);
}
@Test
@@ -109,11 +104,10 @@
String clusterName = pp.getClusterName();
String configName = pp.getConfigName();
- assertTrue(servers.size() == 1);
- assertTrue(servers.contains("i2"));
- assertFalse(servers.contains("i1"));
+ assertThat(servers, hasSize(1));
+ assertThat(servers, contains("i2"));
assertNull(clusterName);
- assertEquals(configName, "i2-config");
+ assertEquals("i2-config", configName);
}
@Test
@@ -124,10 +118,10 @@
String clusterName = pp.getClusterName();
String configName = pp.getConfigName();
- assertTrue(servers.size() == 1);
- assertTrue(servers.contains("c1i1"));
- assertEquals(clusterName, "c1");
- assertEquals(configName, "c1-config");
+ assertThat(servers, hasSize(1));
+ assertThat(servers, contains("c1i1"));
+ assertEquals("c1", clusterName);
+ assertEquals("c1-config", configName);
}
@Test
@@ -138,27 +132,20 @@
String clusterName = pp.getClusterName();
String configName = pp.getConfigName();
- assertTrue(servers.size() == 2);
- assertTrue(servers.contains("c1i1"));
- assertTrue(servers.contains("c1i2"));
- assertEquals(clusterName, "c1");
- assertEquals(configName, "c1-config");
+ assertThat(servers, hasSize(2));
+ assertThat(servers, contains("c1i1", "c1i2"));
+ assertEquals("c1", clusterName);
+ assertEquals("c1-config", configName);
}
@Test
public void noConfigTest() {
System.out.println("noConfigTest");
try {
- DomainXmlPreParser pp = new DomainXmlPreParser(noconfigfori1, xif, "i1");
+ new DomainXmlPreParser(noconfigfori1, xif, "i1");
fail("Expected an exception!!!");
- }
- catch(DomainXmlPreParserException e) {
- assertTrue(e.getMessage().startsWith("The config element, "));
- System.out.println(e);
+ } catch (DomainXmlPreParserException e) {
+ assertThat(e.getMessage(), startsWith("The config element, "));
}
}
-
- private static URL stock, i1, i1i2, c1i1, c1i1c1i2, noconfigfori1;
- private static ClassLoader classLoader = DomainXmlPreParserTest.class.getClassLoader();
- private static XMLInputFactory xif = XMLInputFactory.newInstance();
}