Skip to content

Commit

Permalink
Refactoring in admin-tests
Browse files Browse the repository at this point in the history
- I wasn't sure if it does what is expected, so I wrote a test
- I move these functions also to a standalone file.

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Nov 14, 2022
1 parent bbc07a3 commit 2becec0
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 71 deletions.
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;

import org.glassfish.main.admin.test.tool.DomainAdminRestClient;
import org.glassfish.main.admin.test.tool.RandomGenerator;
import org.glassfish.main.admin.test.webapp.HelloServlet;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -45,7 +46,7 @@ public class ApplicationITest extends RestTestBase {

@BeforeEach
public void initInstanceClient() {
appName = "testApp" + generateRandomString();
appName = "testApp" + RandomGenerator.generateRandomString();
client = new DomainAdminRestClient(getBaseInstanceUrl() + "/" + appName);
}

Expand Down Expand Up @@ -135,7 +136,7 @@ public void listSubComponents() throws URISyntaxException {

@Test
public void testCreatingAndDeletingApplicationRefs() throws URISyntaxException {
final String instanceName = "instance_" + generateRandomString();
final String instanceName = "instance_" + RandomGenerator.generateRandomString();
final String appRefUrl = "/domain/servers/server/" + instanceName + "/application-ref";

Map<String, String> newInstance = Map.of("id", instanceName, "node", "localhost-domain1");
Expand Down Expand Up @@ -183,7 +184,7 @@ public void testGetContextRoot() throws URISyntaxException {

@Test
public void testUndeploySubActionWarnings() throws URISyntaxException {
final String serverName = "in" + generateRandomNumber();
final String serverName = "in" + RandomGenerator.generateRandomNumber();
try {
Response response = managementClient.post("/domain/create-instance",
Map.of("id", serverName, "node", "localhost-domain1"));
Expand Down
Expand Up @@ -31,6 +31,7 @@
import java.util.stream.Stream;

import org.glassfish.admin.rest.client.utils.MarshallingUtils;
import org.glassfish.main.admin.test.tool.RandomGenerator;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.equalTo;
Expand Down Expand Up @@ -89,7 +90,7 @@ public void testSupportsUserManagement() {

@Test
public void testUserManagement() {
final String userName = "user" + generateRandomString();
final String userName = "user" + RandomGenerator.generateRandomString();
{
Response response = managementClient.post(URL_CREATE_USER, Map.of("id", userName, "AS_ADMIN_USERPASSWORD", "password"));
assertEquals(200, response.getStatus());
Expand Down
Expand Up @@ -21,6 +21,7 @@

import java.util.Map;

import org.glassfish.main.admin.test.tool.RandomGenerator;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.equalTo;
Expand All @@ -34,7 +35,7 @@ public class ClusterITest extends RestTestBase {

@Test
public void testClusterCreationAndDeletion() {
final String clusterName = "cluster_" + generateRandomString();
final String clusterName = "cluster_" + RandomGenerator.generateRandomString();
createCluster(clusterName);

Map<String, String> entity = getEntityValues(managementClient.get(URL_CLUSTER + "/" + clusterName));
Expand All @@ -45,7 +46,7 @@ public void testClusterCreationAndDeletion() {

@Test
public void testListLifecycleModules() {
final String clusterName = "cluster_" + generateRandomString();
final String clusterName = "cluster_" + RandomGenerator.generateRandomString();
Response response = managementClient.post(URL_CLUSTER, Map.of("id", clusterName));
assertThat(response.getStatus(), equalTo(200));

Expand Down
Expand Up @@ -20,6 +20,7 @@
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.Response;

import org.glassfish.main.admin.test.tool.RandomGenerator;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.equalTo;
Expand All @@ -32,7 +33,7 @@ public class ConfigITest extends RestTestBase {

@Test
public void testConfigCopy() {
String configName = "config-" + generateRandomString();
String configName = "config-" + RandomGenerator.generateRandomString();
MultivaluedHashMap<String, String> formData = new MultivaluedHashMap<>();
formData.add("id", "default-config");
formData.add("id", configName);
Expand Down
Expand Up @@ -22,6 +22,7 @@
import java.net.URISyntaxException;
import java.util.Map;

import org.glassfish.main.admin.test.tool.RandomGenerator;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -44,8 +45,8 @@ public class ElementStarITest extends RestTestBase {

@BeforeEach
public void before() {
instanceName1 = "instance_" + generateRandomString();
instanceName2 = "instance_" + generateRandomString();
instanceName1 = "instance_" + RandomGenerator.generateRandomString();
instanceName2 = "instance_" + RandomGenerator.generateRandomString();

Response response = managementClient.post(URL_CREATE_INSTANCE,
Map.of("id", instanceName1, "node", "localhost-domain1"));
Expand All @@ -66,8 +67,8 @@ public void after() {

@Test
public void testApplications() throws URISyntaxException {
final String app1 = "app" + generateRandomString();
final String app2 = "app" + generateRandomString();
final String app1 = "app" + RandomGenerator.generateRandomString();
final String app2 = "app" + RandomGenerator.generateRandomString();

deployApp(getWar("test"), app1, app1);
deployApp(getWar("test"), app2, app2);
Expand All @@ -94,7 +95,7 @@ public void testResources() {

@Test
public void testLoadBalancerConfigs() {
final String lbName = "lbconfig-" + generateRandomString();
final String lbName = "lbconfig-" + RandomGenerator.generateRandomString();
Response response = managementClient.post("/domain/lb-configs/lb-config/",
Map.of("id", lbName, "target", instanceName1));
assertEquals(200, response.getStatus());
Expand Down
Expand Up @@ -21,6 +21,7 @@

import java.util.Map;

import org.glassfish.main.admin.test.tool.RandomGenerator;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.equalTo;
Expand All @@ -35,7 +36,7 @@ public class ExternalResourceITest extends RestTestBase {

@Test
public void createAndDeleteExternalResource() {
final String resourceName = "resource_" + generateRandomString();
final String resourceName = "resource_" + RandomGenerator.generateRandomString();
final String jndiName = "jndi/" + resourceName;
Map<String, String> newResource = Map.of(
"id", resourceName,
Expand Down
Expand Up @@ -23,6 +23,8 @@
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

import org.glassfish.main.admin.test.tool.RandomGenerator;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -45,7 +47,7 @@ public void testReadingPoolEntity() {

@Test
public void testCreateAndDeletePool() {
String poolName = "TestPool" + generateRandomString();
String poolName = "TestPool" + RandomGenerator.generateRandomString();
Map<String, String> params = new HashMap<>();
params.put("name", poolName);
params.put("datasourceClassname", "org.apache.derby.jdbc.ClientDataSource");
Expand All @@ -65,7 +67,7 @@ public void testCreateAndDeletePool() {

@Test
public void testBackslashValidation() {
String poolName = "TestPool\\" + generateRandomString();
String poolName = "TestPool\\" + RandomGenerator.generateRandomString();
String encodedPoolName = URLEncoder.encode(poolName, StandardCharsets.UTF_8);
Map<String, String> params = new HashMap<>();
params.put("name", poolName);
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.HashMap;
import java.util.Map;

import org.glassfish.main.admin.test.tool.RandomGenerator;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

Expand All @@ -49,7 +50,7 @@ public class JmsITest extends RestTestBase {
@Test
public void testJmsConnectionFactories() {
// Create connection pool
final String poolName = "JmsConnectionFactory" + generateRandomString();
final String poolName = "JmsConnectionFactory" + RandomGenerator.generateRandomString();
Map<String, String> ccp_attrs = Map.of("name", poolName, "connectiondefinition",
"jakarta.jms.ConnectionFactory", "raname", "jmsra");
Response response = managementClient.post(URL_CONNECTOR_CONNECTION_POOL, ccp_attrs);
Expand Down Expand Up @@ -94,7 +95,7 @@ public void testJmsConnectionFactories() {

@Test
public void testJmsDestinationResources() {
final String jndiName = "jndi/" + generateRandomString();
final String jndiName = "jndi/" + RandomGenerator.generateRandomString();
String encodedJndiName = URLEncoder.encode(jndiName, StandardCharsets.UTF_8);

Map<String, String> attrs = Map.of("id", jndiName, "raname", "jmsra", "restype", "jakarta.jms.Topic");
Expand All @@ -112,9 +113,9 @@ public void testJmsDestinationResources() {

@Test
public void testJmsPhysicalDestination() {
final String destName = "jmsDest" + generateRandomString();
final int maxNumMsgs = generateRandomNumber(500);
final int consumerFlowLimit = generateRandomNumber(500);
final String destName = "jmsDest" + RandomGenerator.generateRandomString();
final int maxNumMsgs = RandomGenerator.generateRandomNumber(500);
final int consumerFlowLimit = RandomGenerator.generateRandomNumber(500);

createJmsPhysicalDestination(destName, DEST_TYPE, URL_SEVER_JMS_DEST);

Expand All @@ -140,7 +141,7 @@ public void testJmsPhysicalDestination() {
@Disabled("Enable and fix OpenMQ - require more detailed message and probably to fix the cause:"
+ " MQJMSRA_RA4001: getJMXServiceURLList:Exception:Message=Caught exception when contacing portmapper.]]")
public void testJmsPhysicalDestionationsWithClusters() {
final String destName = "jmsDest" + generateRandomString();
final String destName = "jmsDest" + RandomGenerator.generateRandomString();
final String clusterName = createCluster();
createClusterInstance(clusterName, "in1_" + clusterName);
startCluster(clusterName);
Expand Down Expand Up @@ -175,7 +176,7 @@ public void testJmsFlush() {

@Test
public void testJmsHosts() {
final String jmsHostName = "jmshost" + generateRandomString();
final String jmsHostName = "jmshost" + RandomGenerator.generateRandomString();
Map<String, String> newHost = Map.of("id", jmsHostName, "adminPassword", "admin", "port", "7676",
"adminUserName", "admin", "host", "localhost");

Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.util.Map;

import org.glassfish.admin.rest.client.utils.MarshallingUtils;
import org.glassfish.main.admin.test.tool.RandomGenerator;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -66,7 +67,7 @@ public static void initConfig() {

@BeforeEach
public void createConfig() {
testConfigName = "config-" + generateRandomString();
testConfigName = "config-" + RandomGenerator.generateRandomString();
MultivaluedMap<String, String> formData = new MultivaluedHashMap<>() {{
add("id", "default-config");
add("id", testConfigName);
Expand All @@ -93,7 +94,7 @@ public void getJvmOptions() {

@Test
public void createAndDeleteOptions() {
final String option1Name = "-Doption" + generateRandomString();
final String option1Name = "-Doption" + RandomGenerator.generateRandomString();
Map<String, String> newOptions = Map.of(option1Name, "someValue");

Response response = managementClient.post(testConfigJvmOptionsUrl, newOptions);
Expand All @@ -111,7 +112,7 @@ public void createAndDeleteOptions() {

@Test
public void createAndDeleteOptionsWithBackslashes() {
final String optionName = "-Dfile" + generateRandomString();
final String optionName = "-Dfile" + RandomGenerator.generateRandomString();
final String optionValue = "C:\\ABC\\DEF\\";
Map<String, String> newOptions = Map.of(optionName, escape(optionValue));

Expand All @@ -130,8 +131,8 @@ public void createAndDeleteOptionsWithBackslashes() {

@Test
public void createAndDeleteOptionsWithoutValues() {
final String option1Name = "-Doption" + generateRandomString();
final String option2Name = "-Doption" + generateRandomString();
final String option1Name = "-Doption" + RandomGenerator.generateRandomString();
final String option2Name = "-Doption" + RandomGenerator.generateRandomString();
Map<String, String> newOptions = Map.of(option1Name, "", option2Name, "");
Response response = managementClient.post(testConfigJvmOptionsUrl, newOptions);
assertEquals(200, response.getStatus());
Expand All @@ -149,7 +150,7 @@ public void createAndDeleteOptionsWithoutValues() {

@Test
public void testIsolatedOptionsCreationOnNewConfig() {
final String optionName = "-Doption" + generateRandomString();
final String optionName = "-Doption" + RandomGenerator.generateRandomString();
Map<String, String> newOptions = Map.of(optionName, "", "target", testConfigName);

// Test new config to make sure option is there
Expand All @@ -167,8 +168,8 @@ public void testIsolatedOptionsCreationOnNewConfig() {

@Test
public void testProfilerJvmOptions() {
final String profilerName = "profiler" + generateRandomString();
final String optionName = "-Doption" + generateRandomString();
final String profilerName = "profiler" + RandomGenerator.generateRandomString();
final String optionName = "-Doption" + RandomGenerator.generateRandomString();
Map<String, String> attrs = Map.of("name", profilerName, "target", testConfigName);
Map<String, String> newOptions = Map.of(optionName, "");
deleteProfiler(testConfigUrl + "/java-config/profiler/delete-profiler", testConfigName, false);
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.HashMap;
import java.util.Map;

import org.glassfish.main.admin.test.tool.RandomGenerator;
import org.junit.jupiter.api.Test;

import static jakarta.ws.rs.core.MediaType.APPLICATION_XML;
Expand All @@ -38,8 +39,8 @@ public class NoCLICommandResourceCreationITest extends RestTestBase {

@Test
public void testPropertyCreation() {
final String propertyKey = "propertyName" + generateRandomString();
String propertyValue = generateRandomString();
final String propertyKey = "propertyName" + RandomGenerator.generateRandomString();
String propertyValue = RandomGenerator.generateRandomString();

//Create a property
Map<String, String> param = new HashMap<>();
Expand All @@ -58,7 +59,7 @@ public void testPropertyCreation() {
assertEquals(propertyValue, entity.get("value"));

// Verify property update
propertyValue = generateRandomString();
propertyValue = RandomGenerator.generateRandomString();
param.put("value", propertyValue);
response = managementClient.put(URL_SERVER_PROPERTY, Entity.entity(getXmlForProperties(param), APPLICATION_XML));
assertEquals(200, response.getStatus());
Expand Down
Expand Up @@ -21,6 +21,7 @@

import java.util.Map;

import org.glassfish.main.admin.test.tool.RandomGenerator;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -33,7 +34,7 @@ public class PartialUpdateITest extends RestTestBase {
@Test
public void testPartialUpdate() {
final String endpoint = URL_JDBC_CONNECTION_POOL + "/DerbyPool";
final String newDesc = generateRandomString();
final String newDesc = RandomGenerator.generateRandomString();
Map<String, String> origAttrs = getEntityValues(managementClient.get(endpoint));
Map<String, String> newAttrs = Map.of("description", newDesc);
Response response = managementClient.post(endpoint, newAttrs);
Expand Down
Expand Up @@ -27,9 +27,11 @@

import org.codehaus.jettison.json.JSONArray;
import org.glassfish.admin.rest.client.utils.MarshallingUtils;
import org.glassfish.main.admin.test.tool.RandomGenerator;
import org.junit.jupiter.api.Test;

import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.glassfish.main.admin.test.tool.RandomGenerator.generateRandomString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -72,10 +74,10 @@ public void serverProperties() {
@Test
public void propsWithEmptyValues() {
List<Map<String, String>> properties = new ArrayList<>();
final String empty = "empty" + generateRandomNumber();
final String foo = "foo" + generateRandomNumber();
final String bar = "bar" + generateRandomNumber();
final String abc = "abc" + generateRandomNumber();
final String empty = "empty" + RandomGenerator.generateRandomNumber();
final String foo = "foo" + RandomGenerator.generateRandomNumber();
final String bar = "bar" + RandomGenerator.generateRandomNumber();
final String abc = "abc" + RandomGenerator.generateRandomNumber();

properties.add(createProperty(empty,""));
properties.add(createProperty(foo,"foovalue"));
Expand Down Expand Up @@ -159,7 +161,7 @@ public void testOptimizedPropertyHandling() {
@Test
public void testPropertiesWithDots() {
List<Map<String, String>> properties = new ArrayList<>();
final String key = "some.property.with.dots." + generateRandomNumber();
final String key = "some.property.with.dots." + RandomGenerator.generateRandomNumber();
final String description = "This is the description";
final String value = generateRandomString();
properties.add(createProperty(key, value, description));
Expand Down Expand Up @@ -276,8 +278,9 @@ private void createAndDeleteProperties(String endpoint) {

List<Map<String, String>> properties = new ArrayList<>();

for(int i = 0, max = generateRandomNumber(16); i < max; i++) {
properties.add(createProperty("property_" + generateRandomString(), generateRandomString(), generateRandomString()));
for(int i = 0, max = RandomGenerator.generateRandomNumber(16); i < max; i++) {
properties.add(
createProperty("property_" + generateRandomString(), generateRandomString(), generateRandomString()));
}

createProperties(endpoint, properties);
Expand Down

0 comments on commit 2becec0

Please sign in to comment.