Skip to content

Commit 01c021e

Browse files
authored
Merge pull request #24627 from brianxjx/issue24584
Fixes #24584
2 parents eb6a319 + 2f54a85 commit 01c021e

29 files changed

+2218
-193
lines changed

dev/com.ibm.ws.http.plugin.merge/src/com/ibm/ws/http/plugin/merge/internal/PluginMergeToolImpl.java

Lines changed: 419 additions & 192 deletions
Large diffs are not rendered by default.

dev/com.ibm.ws.webserver.plugin.utility_fat/fat/src/com/ibm/ws/webserver/plugin/utility/fat/FATSuite.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
*/
3131
@SuiteClasses({
3232
PluginUtilityGenerateTest.class,
33-
PluginUtilityMergeTest.class })
33+
PluginUtilityMergeTest.class,
34+
PluginUtilityEndpointMergeTest.class })
3435
public class FATSuite {
3536

3637
static LibertyServer defaultServer = LibertyServerFactory.getLibertyServer("defaultServer");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* IBM Corporation - initial API and implementation
12+
*******************************************************************************/
13+
package com.ibm.ws.webserver.plugin.utility.fat;
14+
15+
import com.ibm.websphere.simplicity.Machine;
16+
import com.ibm.websphere.simplicity.log.Log;
17+
import com.ibm.websphere.simplicity.ProgramOutput;
18+
19+
import java.io.IOException;
20+
import java.nio.file.Files;
21+
import java.nio.file.Path;
22+
import java.nio.file.Paths;
23+
import java.util.ArrayList;
24+
import java.util.List;
25+
import java.util.stream.Stream;
26+
import java.util.stream.Collectors;
27+
28+
import org.junit.AfterClass;
29+
import org.junit.Before;
30+
import org.junit.After;
31+
import org.junit.BeforeClass;
32+
import org.junit.Test;
33+
import org.junit.runner.RunWith;
34+
35+
import static org.junit.Assert.assertEquals;
36+
import static org.junit.Assert.assertTrue;
37+
import static org.junit.Assert.assertFalse;
38+
39+
import componenttest.custom.junit.runner.FATRunner;
40+
import componenttest.topology.impl.LibertyServer;
41+
42+
@RunWith(FATRunner.class)
43+
public class PluginUtilityEndpointMergeTest {
44+
45+
private static final Class<?> c = PluginUtilityMergeTest.class;
46+
private static final LibertyServer defaultServer = FATSuite.defaultServer;
47+
48+
private static final String MERGED_PLUGIN_CFG_FILENAME = "merged-plugin-cfg.xml";
49+
public static final String pathToAutoFVTTestFiles = "lib/LibertyFATTestFiles/endpointtests/";
50+
51+
static Machine machine;
52+
String defaultServerInstallRoot = defaultServer.getInstallRoot();
53+
static Path workingDirectory = Paths.get("endpointtest");
54+
static Path mergedPluginCfgFile = Paths.get(workingDirectory.toAbsolutePath().toString(),MERGED_PLUGIN_CFG_FILENAME);
55+
56+
@BeforeClass
57+
public static void setUpClass() throws Exception {
58+
machine = defaultServer.getMachine();
59+
Files.createDirectory(workingDirectory);
60+
}
61+
62+
@AfterClass
63+
public static void cleanUpClass() throws Exception {
64+
// In case there was an accident
65+
Files.deleteIfExists(mergedPluginCfgFile);
66+
67+
// Clean up working directory
68+
workingDirectory.toFile().delete();
69+
}
70+
71+
@Before
72+
public void setUp() throws Exception {
73+
// In case there was an accident
74+
Files.deleteIfExists(mergedPluginCfgFile);
75+
}
76+
77+
@After
78+
public void cleanUp() throws Exception {
79+
Files.deleteIfExists(mergedPluginCfgFile);
80+
}
81+
82+
@Test
83+
public void testEndpointTest1() throws Exception {
84+
performDirTest("test1");
85+
}
86+
87+
@Test
88+
public void testEndpointTest2() throws Exception {
89+
performDirTest("test2");
90+
}
91+
92+
@Test
93+
public void testEndpointTest2_1() throws Exception {
94+
performDirTest("test2");
95+
}
96+
97+
@Test
98+
public void testEndpointTest3() throws Exception {
99+
performDirTest("vhost");
100+
}
101+
102+
@Test
103+
public void testEndpointTest4() throws Exception {
104+
performDirTest("vhost-name");
105+
}
106+
107+
@Test
108+
public void testEndpointTest5() throws Exception {
109+
performDirTest("vhost-port");
110+
}
111+
112+
private void performDirTest(String testDir) throws Exception {
113+
final String methodName = "performDirTest";
114+
Log.entering(c, methodName);
115+
Log.info(c, methodName, "Performing test for " + testDir);
116+
117+
Path testFilesDirectory = Paths.get(pathToAutoFVTTestFiles,testDir);
118+
Path expectedFile = Paths.get(testFilesDirectory.toAbsolutePath().toString(),"expected.xml");
119+
Path sourceConfigFiles = Paths.get(testFilesDirectory.toAbsolutePath().toString(),"source");
120+
121+
Log.info(c, methodName, "working directory: " + workingDirectory.toAbsolutePath().toString());
122+
ProgramOutput po = machine.execute(defaultServerInstallRoot + "/bin/pluginUtility",
123+
new String[] {"merge",
124+
"--sourcePath=" + sourceConfigFiles.toAbsolutePath().toString()
125+
}, workingDirectory.toAbsolutePath().toString());
126+
127+
Log.info(c, methodName, "-merge result:\n" + po.getStdout());
128+
assertEquals("pluginUtility task should complete with return code as 0.", 0, po.getReturnCode());
129+
assertTrue("Merged plugin-cfg.xml does not exist under " + workingDirectory.toAbsolutePath().toString(), Files.exists(mergedPluginCfgFile));
130+
131+
List<XMLIssue> issuesFound = XMLCompare.getInstance().compareEndpoints(expectedFile.toFile(),mergedPluginCfgFile.toFile());
132+
StringBuffer sb = new StringBuffer();
133+
boolean compareFailed = issuesFound.size() > 0;
134+
if(compareFailed) {
135+
for(XMLIssue issue:issuesFound) {
136+
sb.append("\t"+issue.getPath()+"\n");
137+
sb.append("\t\t"+issue.getProblem()+"\n");
138+
}
139+
List<String> fileList = convertFileToList(mergedPluginCfgFile.toAbsolutePath().toString());
140+
Log.info(c, methodName, "Failed merge file contents:");
141+
for(String line:fileList) {
142+
Log.info(c, methodName, line);
143+
}
144+
}
145+
assertFalse("Merged plugin-cfg.xml does not match expected plugin file for " + testDir + ":\n" + sb.toString(), compareFailed);
146+
147+
Log.exiting(c, methodName);
148+
149+
}
150+
151+
public List<String> convertFileToList(String filename) {
152+
List<String> list = new ArrayList<>();
153+
154+
try (Stream<String> stream = Files.lines(Paths.get(filename))) {
155+
list = stream.collect(Collectors.toList());
156+
} catch (IOException e) {
157+
e.printStackTrace();
158+
}
159+
return list;
160+
}
161+
}

0 commit comments

Comments
 (0)