-
Notifications
You must be signed in to change notification settings - Fork 622
33571 support merging zos connect's OpenAPI extension between multiple docs #33577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benjamin-confino
wants to merge
15
commits into
OpenLiberty:integration
Choose a base branch
from
benjamin-confino:33571-zos-connect
base: integration
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+596
−4
Open
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0a01069
Quick comment showing location of the other tests
benjamin-confino bc0ce9c
FAT test recreates the customer's issue
benjamin-confino b2189c1
Don't prevent merge if x-ibm-zcon-roles-allowed clashes
benjamin-confino 9bf2bde
merging z-con roles is working
benjamin-confino 8ce77ba
polish up test
benjamin-confino 3b0e2d7
minor corrections
benjamin-confino b1e51d6
re-enable trace
benjamin-confino 24730c8
check for null map as well as empty map
benjamin-confino 7445e40
Add size check to zcon extension equality
benjamin-confino 611cb01
add unit tests for zcon roles extension
benjamin-confino 05f1db9
set test to full mode
benjamin-confino 90e0536
prevent false positives when no zconExtension present
benjamin-confino 4e1d81e
Treat zero zconExtensions as identical
benjamin-confino 2cf5402
also test that the extension is no longer at the top level
benjamin-confino c5988da
Tolerate change in smallrye behaviour on version 4
benjamin-confino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
...at/src/io/openliberty/microprofile/openapi20/fat/deployments/ZOSConnectExtensionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 IBM Corporation and others. | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * http://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| *******************************************************************************/ | ||
| package io.openliberty.microprofile.openapi20.fat.deployments; | ||
|
|
||
| import static com.ibm.websphere.simplicity.ShrinkHelper.DeployOptions.SERVER_ONLY; | ||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.jboss.shrinkwrap.api.Archive; | ||
| import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
| import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
| import org.junit.After; | ||
| import org.junit.AfterClass; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.ibm.websphere.simplicity.PropertiesAsset; | ||
| import com.ibm.websphere.simplicity.ShrinkHelper; | ||
| import com.ibm.websphere.simplicity.config.MpOpenAPIElement; | ||
| import com.ibm.websphere.simplicity.config.MpOpenAPIInfoElement; | ||
| import com.ibm.websphere.simplicity.config.ServerConfiguration; | ||
|
|
||
| import componenttest.annotation.Server; | ||
| import componenttest.custom.junit.runner.FATRunner; | ||
| import componenttest.rules.repeater.RepeatTests; | ||
| import componenttest.topology.impl.LibertyFileManager; | ||
| import componenttest.topology.impl.LibertyServer; | ||
| import io.openliberty.microprofile.openapi20.fat.FATSuite; | ||
| import io.openliberty.microprofile.openapi20.fat.deployments.zosconnect.app.ZOSConnectTestApp; | ||
| import io.openliberty.microprofile.openapi20.fat.deployments.zosconnect.app.ZOSConnectTestResource; | ||
| import io.openliberty.microprofile.openapi20.fat.utils.OpenAPIConnection; | ||
| import io.openliberty.microprofile.openapi20.fat.utils.OpenAPITestUtil; | ||
|
|
||
| @RunWith(FATRunner.class) | ||
| public class ZOSConnectExtensionTest { | ||
|
|
||
| private static final String SERVER_NAME = "OpenAPIMergeWithServerXMLTestServer"; | ||
|
|
||
| @Server(SERVER_NAME) | ||
| public static LibertyServer server; | ||
|
|
||
| @ClassRule | ||
| public static RepeatTests r = FATSuite.repeatDefault(SERVER_NAME); | ||
|
|
||
| @BeforeClass | ||
| public static void startup() throws Exception { | ||
| server.saveServerConfiguration(); | ||
| server.startServer(); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void shutdown() throws Exception { | ||
| server.stopServer("CWWKO1683W", // Invalid info element | ||
| "CWWKO1678W", // Invalid application name | ||
| "CWWKO1679W" // Invalid module name | ||
| ); | ||
| } | ||
|
|
||
| @After | ||
| public void cleanup() throws Exception { | ||
| server.setMarkToEndOfLog(); | ||
| server.restoreServerConfiguration(); // Will stop all apps deployed via server.xml and clear openapi config | ||
| server.waitForConfigUpdateInLogUsingMark(null); | ||
|
|
||
| server.deleteAllDropinApplications(); // Will stop all dropin apps | ||
| server.removeAllInstalledAppsForValidation(); // Validates that all apps stop | ||
|
|
||
| // Delete everything from the apps directory | ||
| server.deleteDirectoryFromLibertyServerRoot("apps"); | ||
| LibertyFileManager.createRemoteFile(server.getMachine(), server.getServerRoot() + "/apps").mkdir(); | ||
| } | ||
|
|
||
| //This test creates an openAPI doc with a map containing values from two apps, and checks they preserve their ordering | ||
| @Test | ||
| public void testMergePreservesMapOrdering() throws Exception { | ||
| setMergeConfig(list("test1", "test2"), null, null); | ||
|
|
||
| PropertiesAsset scanConfig = new PropertiesAsset().addProperty("mp.openapi.scan.disable", | ||
| "true"); | ||
|
|
||
| WebArchive war1 = ShrinkWrap.create(WebArchive.class, "test1.war") | ||
| .addClasses(ZOSConnectTestApp.class, ZOSConnectTestResource.class) | ||
| .addAsResource(scanConfig, "META-INF/microprofile-config.properties") | ||
| .addAsManifestResource(ZOSConnectTestApp.class.getPackage(), "static-file-foo.json", "openapi.json"); | ||
| deployApp(war1); | ||
|
|
||
| WebArchive war2 = ShrinkWrap.create(WebArchive.class, "test2.war") | ||
| .addClasses(ZOSConnectTestApp.class, ZOSConnectTestResource.class) | ||
| .addAsResource(scanConfig, "META-INF/microprofile-config.properties") | ||
| .addAsManifestResource(ZOSConnectTestApp.class.getPackage(), "static-file-bar.json", "openapi.json"); | ||
| deployApp(war2); | ||
|
|
||
| // check that documentation includes all paths in the right order | ||
| String doc = OpenAPIConnection.openAPIDocsConnection(server, false).download(); | ||
| JsonNode openapiNode = OpenAPITestUtil.readYamlTree(doc).get("paths"); | ||
|
|
||
| List<String> pathNames = new ArrayList<>(); | ||
| openapiNode.fieldNames().forEachRemaining(pathNames::add); | ||
|
|
||
| assertEquals("There should be exactly six instances of [x-ibm-zcon-roles-allowed] (one per operation) in " + doc, | ||
| 6, StringUtils.countMatches(openapiNode.toPrettyString(), "x-ibm-zcon-roles-allowed")); | ||
|
|
||
| assertEquals("Bobs", openapiNode.path("/test1/foo1").path("get").path("x-ibm-zcon-roles-allowed").get(0).asText()); | ||
| assertEquals("Bobs", openapiNode.path("/test1/foo2").path("get").path("x-ibm-zcon-roles-allowed").get(0).asText()); | ||
| assertEquals("Robs", openapiNode.path("/test1/foo3").path("get").path("x-ibm-zcon-roles-allowed").get(0).asText()); | ||
| assertEquals("Staff", openapiNode.path("/test2/bar1").path("get").path("x-ibm-zcon-roles-allowed").get(0).asText()); | ||
| assertEquals("Staff", openapiNode.path("/test2/bar2").path("get").path("x-ibm-zcon-roles-allowed").get(0).asText()); | ||
| assertEquals("Guests", openapiNode.path("/test2/bar3").path("get").path("x-ibm-zcon-roles-allowed").get(0).asText()); | ||
|
|
||
| } | ||
|
|
||
| private void setMergeConfig(List<String> included, List<String> excluded, MpOpenAPIInfoElement info) throws Exception { | ||
| ServerConfiguration config = server.getServerConfiguration(); | ||
| MpOpenAPIElement mpOpenAPI = config.getMpOpenAPIElement(); | ||
|
|
||
| clearMergeConfig(mpOpenAPI); | ||
|
|
||
| mpOpenAPI.getIncludedApplications().addAll(applications(included)); | ||
| mpOpenAPI.getIncludedModules().addAll(modules(included)); | ||
| mpOpenAPI.getExcludedApplications().addAll(applications(excluded)); | ||
| mpOpenAPI.getExcludedModules().addAll(modules(excluded)); | ||
|
|
||
| mpOpenAPI.setInfo(info); | ||
|
|
||
| server.setMarkToEndOfLog(); | ||
| server.updateServerConfiguration(config); | ||
| server.waitForConfigUpdateInLogUsingMark(null); | ||
| } | ||
|
|
||
| private static void clearMergeConfig(MpOpenAPIElement mpOpenAPI) { | ||
| List<String> includedApplications = mpOpenAPI.getIncludedApplications(); | ||
| includedApplications.clear(); | ||
|
|
||
| List<String> includedModules = mpOpenAPI.getIncludedModules(); | ||
| includedModules.clear(); | ||
|
|
||
| List<String> excludedApplications = mpOpenAPI.getExcludedApplications(); | ||
| excludedApplications.clear(); | ||
|
|
||
| List<String> excludedModules = mpOpenAPI.getExcludedModules(); | ||
| excludedModules.clear(); | ||
|
|
||
| mpOpenAPI.setInfo(null); | ||
| } | ||
|
|
||
| private static List<String> list(String... values) { | ||
| return new ArrayList<>(Arrays.asList(values)); | ||
| } | ||
|
|
||
| private static List<String> applications(List<String> values) { | ||
| if (values == null) { | ||
| return Collections.emptyList(); | ||
| } | ||
| return values.stream() | ||
| .filter(v -> !v.contains("/")) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private static List<String> modules(List<String> values) { | ||
| if (values == null) { | ||
| return Collections.emptyList(); | ||
| } | ||
| return values.stream() | ||
| .filter(v -> v.contains("/")) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private void deployApp(Archive<?> app) throws Exception { | ||
| ShrinkHelper.exportDropinAppToServer(server, app, SERVER_ONLY); | ||
| } | ||
|
|
||
| } | ||
16 changes: 16 additions & 0 deletions
16
.../openliberty/microprofile/openapi20/fat/deployments/zosconnect/app/ZOSConnectTestApp.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 IBM Corporation and others. | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * http://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| *******************************************************************************/ | ||
| package io.openliberty.microprofile.openapi20.fat.deployments.zosconnect.app; | ||
|
|
||
| import javax.ws.rs.ApplicationPath; | ||
| import javax.ws.rs.core.Application; | ||
|
|
||
| @ApplicationPath("/") | ||
| public class ZOSConnectTestApp extends Application {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a
FULLmode test (especially if we add unit tests)