Skip to content

Commit

Permalink
[CXF-9023] Increase unit test coverage on org.apache.cxf.bus (#1901)
Browse files Browse the repository at this point in the history
* [CXF-9023] Increase unit test coverage on org.apache.cxf.bus

* Remove the tests for classes that already have enough coverage

---------

Co-authored-by: Andriy Redko <drreta@gmail.com>
  • Loading branch information
jgoodyear and reta committed Jun 19, 2024
1 parent 94d649a commit 59bc6c2
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@

package org.apache.cxf.bus.managers;

import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.endpoint.DummyServer;
import org.apache.cxf.endpoint.Server;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

public class ServerRegistryImpTest {

Expand All @@ -40,6 +43,19 @@ public void testServerRegistryPreShutdown() {
assertEquals("The serverList should be clear ", serverRegistryImpl.serversList.size(), 0);
}

@Test
public void testServerRegistry() {
ServerRegistryImpl serverRegistryImpl = new ServerRegistryImpl();
assertEquals(0, serverRegistryImpl.getServers().size());
}


}
@Test
public void testBus() {
ServerRegistryImpl serverRegistryImpl = new ServerRegistryImpl();
Bus bus = serverRegistryImpl.getBus();
Bus differentBus = BusFactory.getDefaultBus();
serverRegistryImpl.setBus(differentBus);
assertNotEquals(bus, differentBus);
assertEquals(differentBus, serverRegistryImpl.getBus());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.cxf.bus.resource;

import java.util.List;

import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.resource.ResourceManager;
import org.apache.cxf.resource.ResourceResolver;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import static org.junit.Assert.assertEquals;

public class ResourceManagerImplTest {

private Bus bus;

private ResourceManagerImpl resourceManager;


@Before
public void setup() {
BusFactory.setDefaultBus(null);
BusFactory.setThreadDefaultBus(null);
bus = BusFactory.newInstance().createBus();
resourceManager = new ResourceManagerImpl(bus);
}

@Test
public void testOnFirstResolve() {
List<ResourceResolver> beforeFirstResolve = resourceManager.getResourceResolvers();
resourceManager.onFirstResolve();
List<ResourceResolver> afterFirstResolve = resourceManager.getResourceResolvers();
assertEquals("No additional resolvers added.", beforeFirstResolve.size(),
afterFirstResolve.size());
}

@Test
public void testSetResolvers() {
List<ResourceResolver> initialResolvers = resourceManager.getResourceResolvers();
ResourceResolver mockResourceResolver = Mockito.mock(ResourceResolver.class);
List<ResourceResolver> mockResolvers = List.of(mockResourceResolver);
resourceManager.setResolvers(mockResolvers);

List<ResourceResolver> actual = resourceManager.getResourceResolvers();
assertEquals("Contains our Mock ResourceResolver", 1, actual.size());

resourceManager.setResolvers(initialResolvers);
actual = resourceManager.getResourceResolvers();
assertEquals("Initial resolvers should have been cleared by set call.",
0, actual.size());
}

@Test
public void testGetRegistrationType() {
ResourceManagerImpl impl = new ResourceManagerImpl();
assertEquals("ResourceManagerImpl is of type ResourceManager.class",
ResourceManager.class, impl.getRegistrationType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@
import org.apache.cxf.transport.ConduitInitiatorManager;
import org.apache.cxf.transport.DestinationFactoryManager;
import org.apache.cxf.workqueue.WorkQueueManager;
import org.springframework.beans.factory.xml.NamespaceHandlerResolver;
import org.springframework.context.ApplicationContext;

import org.junit.After;
import org.junit.Test;
import org.mockito.Mockito;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -58,6 +61,7 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;

public class SpringBusFactoryTest {

Expand Down Expand Up @@ -94,13 +98,42 @@ public void testDefault() {

}

@Test
public void testNamespaceHandlerResolver() {
NamespaceHandlerResolver r = Mockito.mock(NamespaceHandlerResolver.class);
SpringBusFactory factory = new SpringBusFactory(r);
Bus bus = factory.createBus();
bus.shutdown(true);
verifyNoInteractions(r);

NamespaceHandlerResolver differentResolver = Mockito.mock(NamespaceHandlerResolver.class);
factory.setNamespaceHandlerResolver(differentResolver);
verifyNoInteractions(differentResolver);
}

@Test
public void testApplicationContext() {
ApplicationContext context = Mockito.mock(ApplicationContext.class);
SpringBusFactory factory = new SpringBusFactory(context);
assertEquals(context, factory.getApplicationContext());
}

@Test
public void testCustomFileName() {
String cfgFile = "org/apache/cxf/bus/spring/resources/bus-overwrite.xml";
Bus bus = new SpringBusFactory().createBus(cfgFile, true);
checkCustomerConfiguration(bus);
}

@Test
public void testCustomFileNames() {
String cfgFile = "org/apache/cxf/bus/spring/resources/bus-overwrite.xml";
String[] cfgFiles = new String[1];
cfgFiles[0] = cfgFile;
Bus bus = new SpringBusFactory().createBus(cfgFiles);
checkCustomerConfiguration(bus);
}

@Test
public void testCustomerBusShutdown() {
String cfgFile = "org/apache/cxf/bus/spring/customerBus.xml";
Expand Down Expand Up @@ -149,7 +182,7 @@ public void testForLifeCycle() {
BusLifeCycleManager lifeCycleManager = bus.getExtension(BusLifeCycleManager.class);
lifeCycleManager.registerLifeCycleListener(bl);
bus.shutdown(true);

verify(bl).preShutdown();
verify(bl).postShutdown();
}
Expand Down

0 comments on commit 59bc6c2

Please sign in to comment.