Skip to content

Commit

Permalink
create fat test for merging with server.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-confino committed Oct 10, 2024
1 parent dac2b6f commit 5ce8c23
Show file tree
Hide file tree
Showing 26 changed files with 1,228 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ public void refreshServerXMLFromPublish() throws Exception {
/**
* Swaps in a different server.xml file from the server directory.
*
* @param fileName
* @param fileName the name of a server.xml file found in the wlp/usr/[server]/ directory
* @throws Exception
*/
public void swapInServerXMLFromPublish(String fileName) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,13 @@ private static boolean isServersIdentical(List<InProgressModel> processedModels)

private static boolean isInfoIdentical(List<InProgressModel> models) {
List<Info> infos = models.stream().map(m -> m.model).map(OpenAPI::getInfo).collect(toList());

for (Info i : infos) {
System.out.println("GREP! " + i.getDescription() + " " + i.getTermsOfService() + " " +
i.getTitle() + " " + i.getVersion() + " " + i.getContact() + " " + i.getLicense() + " "
+ i.getExtensions() + " " + i.getClass().getName());
}

return allEqual(infos, ModelEquality::equals);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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
*
* Contributors:
Expand Down Expand Up @@ -49,14 +49,24 @@ private static boolean equalsImpl(Object a, Object b) {
return true;
}

/*
* Take https://github.com/smallrye/smallrye-open-api/blob/3.13.0/core/src/main/java/io/smallrye/openapi/api/models/ExtensibleImpl.java
* extensions is null. If you call addExtension() it will become an map with an item.
* if you then call remove, it will remove the item from the list and not null it.
* In short new ExtensibleImpl().addExtension(x).removeExtension(x) is not equals() new ExtensibleImpl().
*
* So to work around that, we treat null and empty maps as equivalent.
*
* This may need to be extended to cover lists
*/
if (a == null) {
if (b == null) {
if (nullOrEmptyMap(b)) {
return true;
} else {
return false;
}
} else if (b == null) {
return false;
return nullOrEmptyMap(a);
}

Optional<ModelType> modelObject = ModelType.getModelObject(a.getClass());
Expand All @@ -79,6 +89,7 @@ private static boolean equalsImpl(Object a, Object b) {

@Trivial
private static boolean equalsMap(Map<?, ?> a, Map<?, ?> b) {

if (!Objects.equals(a.keySet(), b.keySet())) {
return false;
}
Expand Down Expand Up @@ -124,4 +135,16 @@ private static boolean equalsModelObject(ModelType modelType, Object a, Object b
return true;
}

@Trivial
private static boolean nullOrEmptyMap(Object a) {
if (a == null) {
return true;
}
if (a instanceof Map) {
Map<?, ?> m = (Map<?, ?>) a;
return m.isEmpty();
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,17 @@ public static Info getConfiguredInfo(Config config) {
* @return {@code true} if all elements of {@code collection} are equal, {@code false} otherwise
*/
public static <T> boolean allEqual(Collection<? extends T> collection, BiPredicate<? super T, ? super T> comparator) {

Iterator<? extends T> i = collection.iterator();
if (!i.hasNext()) {
return true;
}

T first = i.next();
while (i.hasNext()) {
if (!equals(first, i.next(), comparator)) {
T next = i.next();

if (!equals(first, next, comparator)) {
return false;
}
}
Expand All @@ -207,6 +210,9 @@ public static <T> boolean allEqual(Collection<? extends T> collection, BiPredica
* @return {@code true} if {@code a} and {@code b} are equal, {@code false} otherwise
*/
public static <T> boolean equals(T a, T b, BiPredicate<? super T, ? super T> comparator) {

System.out.println("GREPGREP " + a + " " + b + " " + comparator.getClass().toGenericString());

if (a == null) {
return b == null ? true : false;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2021 IBM Corporation and others.
* Copyright (c) 2017, 2024 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
Expand All @@ -25,6 +25,7 @@
import io.openliberty.microprofile.openapi20.fat.deployments.MergeServerXMLTestWithUpdate;
import io.openliberty.microprofile.openapi20.fat.deployments.MergeTest;
import io.openliberty.microprofile.openapi20.fat.deployments.MergeWithServletTest;
import io.openliberty.microprofile.openapi20.fat.deployments.StartupWarningMessagesTest;
import io.openliberty.microprofile.openapi20.fat.shutdown.ShutdownTest;

@RunWith(Suite.class)
Expand All @@ -37,7 +38,8 @@
MergeServerXMLTestWithUpdate.class,
MergeTest.class,
MergeWithServletTest.class,
ShutdownTest.class
ShutdownTest.class,
StartupWarningMessagesTest.class
})
public class FATSuite {
public static RepeatTests repeatDefault(String serverName) {
Expand Down
Loading

0 comments on commit 5ce8c23

Please sign in to comment.