Issue #23507 deployment-admin now uses junit5 instead of junit4 - however both tests remain disabled, because they reproduce NPE. Somebody "fixed" it by ignoring all exceptions
diff --git a/nucleus/deployment/admin/pom.xml b/nucleus/deployment/admin/pom.xml index 6d73650..e26145e 100755 --- a/nucleus/deployment/admin/pom.xml +++ b/nucleus/deployment/admin/pom.xml
@@ -94,6 +94,10 @@ </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/deployment/admin/src/test/java/org/glassfish/deployment/admin/ListComponentsCommandTest.java b/nucleus/deployment/admin/src/test/java/org/glassfish/deployment/admin/ListComponentsCommandTest.java index d7c174c..cfc7454 100644 --- a/nucleus/deployment/admin/src/test/java/org/glassfish/deployment/admin/ListComponentsCommandTest.java +++ b/nucleus/deployment/admin/src/test/java/org/glassfish/deployment/admin/ListComponentsCommandTest.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,337 +17,598 @@ package org.glassfish.deployment.admin; -import java.io.File; -import static org.junit.Assert.*; +import com.sun.enterprise.config.serverbeans.AppTenants; +import com.sun.enterprise.config.serverbeans.Application; +import com.sun.enterprise.config.serverbeans.ApplicationConfig; +import com.sun.enterprise.config.serverbeans.ApplicationExtension; +import com.sun.enterprise.config.serverbeans.ApplicationRef; +import com.sun.enterprise.config.serverbeans.Engine; +import com.sun.enterprise.config.serverbeans.Module; +import com.sun.enterprise.config.serverbeans.Resources; -import org.junit.Test; -import org.junit.Before; -import org.jvnet.hk2.config.DuckTyped; +import java.beans.PropertyVetoException; +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.glassfish.api.deployment.DeployCommandParameters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.jvnet.hk2.config.ConfigBeanProxy; +import org.jvnet.hk2.config.DuckTyped; import org.jvnet.hk2.config.TransactionFailure; import org.jvnet.hk2.config.types.Property; -import com.sun.enterprise.config.serverbeans.*; -import org.glassfish.api.deployment.DeployCommandParameters; -import com.sun.enterprise.config.serverbeans.Module; - -import java.beans.PropertyVetoException; -import java.util.List; -import java.util.Map; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Properties; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * junit test to test ListComponentsCommand class */ public class ListComponentsCommandTest { - private ListComponentsCommand lcc = null; - @Test - public void isApplicationOfThisTypeTest() { - try { - ApplicationTest app = new ApplicationTest(); - Engine eng = new EngineTest(); - eng.setSniffer("web"); - List<Engine> engines = new ArrayList<Engine>(); - engines.add(eng); - List<Module> modules = new ArrayList<Module>(); - ModuleTest aModule = new ModuleTest(); - aModule.setEngines(engines); - modules.add(aModule); - app.setModules(modules); + private ListComponentsCommand lcc; - boolean ret = lcc.isApplicationOfThisType(app, "web"); - assertTrue("test app with sniffer engine=web", true==lcc.isApplicationOfThisType(app, "web")); - //negative testcase - assertFalse("test app with sniffer engine=web", true==lcc.isApplicationOfThisType(app, "ejb")); - } - catch (Exception ex) { - //ignore exception - } - } - - @Test - public void getSnifferEnginesTest() { - try { - Engine eng1 = new EngineTest(); - eng1.setSniffer("web"); - Engine eng2 = new EngineTest(); - eng2.setSniffer("security"); - List<Engine> engines = new ArrayList<Engine>(); - engines.add(eng1); - engines.add(eng2); - - ApplicationTest app = new ApplicationTest(); - List<Module> modules = new ArrayList<Module>(); - ModuleTest aModule = new ModuleTest(); - aModule.setEngines(engines); - modules.add(aModule); - app.setModules(modules); - String snifferEngines = lcc.getSnifferEngines(app.getModule().get(0), true); - assertEquals("compare all sniffer engines", "<web, security>", - snifferEngines); - } - catch (Exception ex) { - //ignore exception - } - } - - - @Before + @BeforeEach public void setup() { lcc = new ListComponentsCommand(); } + + @Test + @Disabled("FIXME: Reproduces NPE in ListComponentsCommand.getAppEngines") + public void isApplicationOfThisTypeTest() throws Exception { + ApplicationTest app = new ApplicationTest(); + Engine eng = new EngineTest(); + eng.setSniffer("web"); + List<Engine> engines = new ArrayList<>(); + engines.add(eng); + List<Module> modules = new ArrayList<>(); + ModuleTest aModule = new ModuleTest(); + aModule.setEngines(engines); + modules.add(aModule); + app.setModules(modules); + + assertTrue(lcc.isApplicationOfThisType(app, "web"), "test app with sniffer engine=web"); + assertFalse(lcc.isApplicationOfThisType(app, "ejb"), "test app with sniffer engine=web"); + } + + + @Test + @Disabled("FIXME: Reproduces NPE in ListComponentsCommand.displaySnifferEngine") + public void getSnifferEnginesTest() throws Exception { + Engine eng1 = new EngineTest(); + eng1.setSniffer("web"); + Engine eng2 = new EngineTest(); + eng2.setSniffer("security"); + List<Engine> engines = new ArrayList<>(); + engines.add(eng1); + engines.add(eng2); + + ApplicationTest app = new ApplicationTest(); + List<Module> modules = new ArrayList<>(); + ModuleTest aModule = new ModuleTest(); + aModule.setEngines(engines); + modules.add(aModule); + app.setModules(modules); + String snifferEngines = lcc.getSnifferEngines(app.getModule().get(0), true); + assertEquals("<web, security>", snifferEngines, "compare all sniffer engines"); + } + public class RandomConfig implements ConfigBeanProxy { + @Override @DuckTyped public ConfigBeanProxy getParent() { - // TODO throw new UnsupportedOperationException(); } + + + @Override @DuckTyped public <T extends ConfigBeanProxy> T getParent(Class<T> type) { - // TODO throw new UnsupportedOperationException(); } + + @DuckTyped public Property getProperty(String name) { - // TODO throw new UnsupportedOperationException(); } + @DuckTyped public String getPropertyValue(String name) { - // TODO throw new UnsupportedOperationException(); } + @DuckTyped public String getPropertyValue(String name, String defaultValue) { - // TODO throw new UnsupportedOperationException(); } + + @Override @DuckTyped public <T extends ConfigBeanProxy> T createChild(Class<T> type) throws TransactionFailure { throw new UnsupportedOperationException(); } + @Override public ConfigBeanProxy deepCopy(ConfigBeanProxy parent) { throw new UnsupportedOperationException(); } - //hk2's Injectable class - public void injectedInto(Object target){} + + // hk2's Injectable class + public void injectedInto(Object target) { + } } public class ModuleTest extends RandomConfig implements Module { + @Override public String getName() { return null; } - public void setName(String value) throws PropertyVetoException {} + + @Override + public void setName(String value) throws PropertyVetoException { + } private List<Engine> engineList = null; + @Override public List<Engine> getEngines() { return engineList; } - public Engine getEngine(String snifferType) {return null;} + + + @Override + public Engine getEngine(String snifferType) { + return null; + } + public void setEngines(List<Engine> engines) { this.engineList = engines; } - public List<Property> getProperty() {return null;} - public void setResources(Resources res){} - public Resources getResources(){return null;} + + @Override + public List<Property> getProperty() { + return null; + } + + + @Override + public void setResources(Resources res) { + } + + + @Override + public Resources getResources() { + return null; + } + @Override public Property addProperty(Property prprt) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public Property lookupProperty(String string) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public Property removeProperty(String string) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public Property removeProperty(Property prprt) { throw new UnsupportedOperationException("Not supported yet."); } - - } - //mock-up Application object + + /** mock-up Application object */ public class ApplicationTest extends RandomConfig implements Application { + private List<Module> modules = null; + @Override public String getName() { return "hello"; } - public void setResources(Resources res){} - public Resources getResources(){return null;} - public void setName(String value) throws PropertyVetoException {} - public String getContextRoot() { return "hello";} - public void setContextRoot(String value) throws PropertyVetoException {} - public String getLocation(){ return "";} - public void setLocation(String value) throws PropertyVetoException{} - public String getObjectType(){ return "";} - public void setObjectType(String value) throws PropertyVetoException{} - public String getEnabled(){ return "";} - public void setEnabled(String value) throws PropertyVetoException{} - public String getLibraries(){ return "";} - public void setLibraries(String value) throws PropertyVetoException{} - public String getAvailabilityEnabled(){ return "";} - public void setAvailabilityEnabled(String value) throws PropertyVetoException{} - public String getAsyncReplication() { return "";} - public void setAsyncReplication (String value) throws PropertyVetoException {} - public String getDirectoryDeployed(){ return "";} - public void setDirectoryDeployed(String value) throws PropertyVetoException{} - public String getDescription(){ return "";} - public void setDescription(String value) throws PropertyVetoException{} - public String getDeploymentOrder() { return "100"; } - public void setDeploymentOrder(String value) throws PropertyVetoException {} - public List<Engine> getEngine(){ return null;} - public List<Property> getProperty(){ return null;} - public <T extends ApplicationConfig> T getApplicationConfig(Class<T> type) {return null;} - public List<ApplicationConfig> getApplicationConfigs() {return null;} - public Map<String, Properties> getModulePropertiesMap() {return null;} - public Module getModule(String moduleName) {return null;} - public boolean isStandaloneModule() {return false;} - public boolean isLifecycleModule() {return false;} - public boolean containsSnifferType(String snifferType) {return false;} + + @Override + public void setResources(Resources res) { + } + + + @Override + public Resources getResources() { + return null; + } + + + @Override + public void setName(String value) throws PropertyVetoException { + } + + + @Override + public String getContextRoot() { + return "hello"; + } + + + @Override + public void setContextRoot(String value) throws PropertyVetoException { + } + + + @Override + public String getLocation() { + return ""; + } + + + @Override + public void setLocation(String value) throws PropertyVetoException { + } + + + @Override + public String getObjectType() { + return ""; + } + + + @Override + public void setObjectType(String value) throws PropertyVetoException { + } + + + @Override + public String getEnabled() { + return ""; + } + + + @Override + public void setEnabled(String value) throws PropertyVetoException { + } + + + @Override + public String getLibraries() { + return ""; + } + + + @Override + public void setLibraries(String value) throws PropertyVetoException { + } + + + @Override + public String getAvailabilityEnabled() { + return ""; + } + + + @Override + public void setAvailabilityEnabled(String value) throws PropertyVetoException { + } + + + @Override + public String getAsyncReplication() { + return ""; + } + + + @Override + public void setAsyncReplication(String value) throws PropertyVetoException { + } + + + @Override + public String getDirectoryDeployed() { + return ""; + } + + + @Override + public void setDirectoryDeployed(String value) throws PropertyVetoException { + } + + + @Override + public String getDescription() { + return ""; + } + + + @Override + public void setDescription(String value) throws PropertyVetoException { + } + + + @Override + public String getDeploymentOrder() { + return "100"; + } + + + @Override + public void setDeploymentOrder(String value) throws PropertyVetoException { + } + + + @Override + public List<Engine> getEngine() { + return null; + } + + + @Override + public List<Property> getProperty() { + return null; + } + + + public <T extends ApplicationConfig> T getApplicationConfig(Class<T> type) { + return null; + } + + + public List<ApplicationConfig> getApplicationConfigs() { + return null; + } + + + @Override + public Map<String, Properties> getModulePropertiesMap() { + return null; + } + + + @Override + public Module getModule(String moduleName) { + return null; + } + + + @Override + public boolean isStandaloneModule() { + return false; + } + + + @Override + public boolean isLifecycleModule() { + return false; + } + + + @Override + public boolean containsSnifferType(String snifferType) { + return false; + } + + + @Override public List<Module> getModule() { return modules; } + public void setModules(List<Module> modules) { - this.modules = modules; + this.modules = modules; } - public Properties getDeployProperties() { - return new Properties(); - } - public DeployCommandParameters getDeployParameters(ApplicationRef appRef) { - return new DeployCommandParameters(); - } + @Override + public Properties getDeployProperties() { + return new Properties(); + } - public File application() {return null;} - public File deploymentPlan() {return null;} - public String archiveType() {return null;} - public void recordFileLocations(File appFile, File deploymentPlanFile) {} + + @Override + public DeployCommandParameters getDeployParameters(ApplicationRef appRef) { + return new DeployCommandParameters(); + } + + + @Override + public File application() { + return null; + } + + + @Override + public File deploymentPlan() { + return null; + } + + + @Override + public String archiveType() { + return null; + } + + + @Override + public void recordFileLocations(File appFile, File deploymentPlanFile) { + } + @Override public AppTenants getAppTenants() { throw new UnsupportedOperationException("Not supported yet."); } + @Override public void setAppTenants(AppTenants appTenants) { throw new UnsupportedOperationException("Not supported yet."); } + @Override - public List<ApplicationExtension> getExtensions() {return null;} + public List<ApplicationExtension> getExtensions() { + return null; + } + @Override public <T extends ApplicationExtension> T getExtensionByType(Class<T> type) { return null; } + + @Override public <T extends ApplicationExtension> List<T> getExtensionsByType(Class<T> type) { return null; } + @Override public Property addProperty(Property prprt) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public Property lookupProperty(String string) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public Property removeProperty(String string) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public Property removeProperty(Property prprt) { throw new UnsupportedOperationException("Not supported yet."); } } - //mock-up Engine object + /** mock-up Engine object */ public class EngineTest extends RandomConfig implements Engine { + private String sniffer = ""; - public String getSniffer() {return sniffer;} + + @Override + public String getSniffer() { + return sniffer; + } + + + @Override public void setSniffer(String value) throws PropertyVetoException { sniffer = value; } - public String getDescription() {return "";} - public void setDescription(String value) {} - public List<Property> getProperty() {return null;} - //config.serverbeans.Modules + + @Override + public String getDescription() { + return ""; + } + + + @Override + public void setDescription(String value) { + } + + + @Override + public List<Property> getProperty() { + return null; + } + + + // config.serverbeans.Modules public String getName() { return "hello"; } - public void setName(String value) throws PropertyVetoException {} + + + public void setName(String value) throws PropertyVetoException { + } + public ApplicationConfig getConfig() { return null; } - public void setConfig(ApplicationConfig config) throws PropertyVetoException {} + public void setConfig(ApplicationConfig config) throws PropertyVetoException { + } + + + @Override public List<ApplicationConfig> getApplicationConfigs() { return Collections.EMPTY_LIST; } + + @Override public ApplicationConfig getApplicationConfig() { return null; } + + @Override public void setApplicationConfig(ApplicationConfig config) { // no-op for this test } + + @Override public <T extends ApplicationConfig> T newApplicationConfig(Class<T> configType) throws TransactionFailure { return null; } + @Override public Property addProperty(Property prprt) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public Property lookupProperty(String string) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public Property removeProperty(String string) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public Property removeProperty(Property prprt) { throw new UnsupportedOperationException("Not supported yet.");