Skip to content

Commit

Permalink
[CXF-9042] Fixed non-idempotent unit tests (apache#1978)
Browse files Browse the repository at this point in the history
* fixed non-idempotent unit tests

* updated MBeans unregistering

* create new document when creating token wrapper

(cherry picked from commit 0740778)
(cherry picked from commit 9f0f6d7)
(cherry picked from commit 1a13da7)
  • Loading branch information
kaiyaok2 authored and reta committed Aug 3, 2024
1 parent 2616f63 commit f0328f9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,30 @@ public void testWorkQueueInstrumentation() throws Exception {
ObjectName name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME
+ ":type=WorkQueues,*");
Set<ObjectName> s = mbs.queryNames(name, null);
assertEquals(2, s.size());
Iterator<ObjectName> it = s.iterator();
while (it.hasNext()) {
ObjectName n = it.next();
Long result =
(Long)mbs.invoke(n, "getWorkQueueMaxSize", new Object[0], new String[0]);
assertEquals(result, Long.valueOf(256));
Integer hwm =
(Integer)mbs.invoke(n, "getHighWaterMark", new Object[0], new String[0]);
if (n.getCanonicalName().contains("test-wq")) {
assertEquals(10, hwm.intValue());
} else {
assertEquals(15, hwm.intValue());
try {
assertEquals(2, s.size());
Iterator<ObjectName> it = s.iterator();
while (it.hasNext()) {
ObjectName n = it.next();
Long result =
(Long)mbs.invoke(n, "getWorkQueueMaxSize", new Object[0], new String[0]);
assertEquals(result, Long.valueOf(256));
Integer hwm =
(Integer)mbs.invoke(n, "getHighWaterMark", new Object[0], new String[0]);
if (n.getCanonicalName().contains("test-wq")) {
assertEquals(10, hwm.intValue());
} else {
assertEquals(15, hwm.intValue());
}
}
} finally {
// Unregister MBeans at the end of the test
Iterator<ObjectName> it2 = s.iterator();
while (it2.hasNext()) {
mbs.unregisterMBean(it2.next());
}
bus.shutdown(true);
}

bus.shutdown(true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public void testSAMLToJWTTransformation() throws Exception {
}

private Element createTokenWrapper(String token) {
Document doc = DOMUtils.getEmptyDocument();
Document doc = DOMUtils.createDocument();
Element tokenWrapper = doc.createElementNS(null, "TokenWrapper");
tokenWrapper.setTextContent(token);
return tokenWrapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,11 @@ private void doJAXBPayload(Dispatch<Object> disp) throws Exception {

@Test
public void testJAXBObjectPAYLOADWithFeature() throws Exception {
// Save initial counts
int initialCount = TestDispatchFeature.getCount();
int initialInInterceptorCount = TestDispatchFeature.getInInterceptorCount();
int initialOutInterceptorCount = TestDispatchFeature.getOutInterceptorCount();

createBus("org/apache/cxf/systest/dispatch/client-config.xml");
BusFactory.setThreadDefaultBus(bus);

Expand Down Expand Up @@ -654,15 +659,13 @@ public void testJAXBObjectPAYLOADWithFeature() throws Exception {
String responseValue = ((GreetMeResponse)response).getResponseType();
assertEquals("Expected string, " + expected, expected, responseValue);

assertEquals("Feature should be applied", 1, TestDispatchFeature.getCount());
assertEquals("Feature should be applied", initialCount + 1, TestDispatchFeature.getCount());
assertEquals("Feature based interceptors should be added",
1, TestDispatchFeature.getCount());

initialCount + 1, TestDispatchFeature.getCount());
assertEquals("Feature based In interceptors has be added to in chain.",
1, TestDispatchFeature.getInInterceptorCount());

initialInInterceptorCount + 1, TestDispatchFeature.getInInterceptorCount());
assertEquals("Feature based interceptors has to be added to out chain.",
1, TestDispatchFeature.getOutInterceptorCount());
initialOutInterceptorCount + 1, TestDispatchFeature.getOutInterceptorCount());
bus.shutdown(true);
}

Expand Down

0 comments on commit f0328f9

Please sign in to comment.