This is an automated email from the ASF dual-hosted git repository. reta pushed a commit to branch 3.6.x-fixes in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 9bc78f8e23741b74af5d137e8c7a358740a7b5dd Author: Andriy Redko <[email protected]> AuthorDate: Fri Aug 25 10:44:53 2023 -0400 CXF-8855: Get rid of EasyMock in cxf-rt-ws-transfer (#1390) (cherry picked from commit 7e088f4aa5ddc849411f70635ed50859bfa236f8) # Conflicts: # rt/ws/transfer/pom.xml --- rt/ws/transfer/pom.xml | 187 +++++++++++---------- .../transfer/integration/ResourceFactoryTest.java | 27 +-- .../cxf/ws/transfer/integration/ResourceTest.java | 33 ++-- 3 files changed, 123 insertions(+), 124 deletions(-) diff --git a/rt/ws/transfer/pom.xml b/rt/ws/transfer/pom.xml index 230fa5433a..bb9480a27c 100644 --- a/rt/ws/transfer/pom.xml +++ b/rt/ws/transfer/pom.xml @@ -1,99 +1,100 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> + <modelVersion>4.0.0</modelVersion> - <artifactId>cxf-rt-ws-transfer</artifactId> - <packaging>jar</packaging> - <name>Apache CXF Runtime WS Transfer</name> - <url>https://cxf.apache.org</url> + <artifactId>cxf-rt-ws-transfer</artifactId> + <packaging>jar</packaging> + <name>Apache CXF Runtime WS Transfer</name> + <url>https://cxf.apache.org</url> - <parent> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-parent</artifactId> - <version>3.6.2-SNAPSHOT</version> - <relativePath>../../../parent/pom.xml</relativePath> - </parent> + <parent> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-parent</artifactId> + <version>3.6.2-SNAPSHOT</version> + <relativePath>../../../parent/pom.xml</relativePath> + </parent> - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <cxf.module.name>org.apache.cxf.ws.transfer</cxf.module.name> - </properties> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <cxf.module.name>org.apache.cxf.ws.transfer</cxf.module.name> + </properties> - <dependencies> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>cxf-rt-frontend-jaxws</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.sun.xml.messaging.saaj</groupId> - <artifactId>saaj-impl</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>cxf-rt-transports-local</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.easymock</groupId> - <artifactId>easymock</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-xjc-plugin</artifactId> - <version>${cxf.xjc-utils.version}</version> - <executions> - <execution> - <id>generate-transfer</id> - <phase>generate-sources</phase> - <goals> - <goal>xsdtojava</goal> - </goals> - <configuration> - <fork>${cxf.xjcplugin.forkmode}</fork> - <additionalJvmArgs>${cxf.xjc.jvmArgs}</additionalJvmArgs> - <sourceRoot>${basedir}/target/generated-sources/xjc</sourceRoot> - <xsdOptions> - <xsdOption> - <xsd>${basedir}/src/main/resources/schemas/transfer.xsd</xsd> - <packagename>org.apache.cxf.ws.transfer</packagename> - <bindingFile>${basedir}/src/main/resources/schemas/transfer.xjb</bindingFile> - <catalog>${basedir}/src/main/resources/schemas/catalog.cat</catalog> - </xsdOption> - </xsdOptions> - </configuration> - </execution> - <execution> - <id>generate-fragment</id> - <phase>generate-sources</phase> - <goals> - <goal>xsdtojava</goal> - </goals> - <configuration> - <fork>${cxf.xjcplugin.forkmode}</fork> - <additionalJvmArgs>${cxf.xjc.jvmArgs}</additionalJvmArgs> - <sourceRoot>${basedir}/target/generated-sources/xjc</sourceRoot> - <xsdOptions> - <xsdOption> - <xsd>${basedir}/src/main/resources/schemas/fragment.xsd</xsd> - <packagename>org.apache.cxf.ws.transfer.dialect.fragment</packagename> - <catalog>${basedir}/src/main/resources/schemas/catalog-fragment.cat</catalog> - </xsdOption> - </xsdOptions> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> + <dependencies> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>cxf-rt-frontend-jaxws</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.sun.xml.messaging.saaj</groupId> + <artifactId>saaj-impl</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>cxf-rt-transports-local</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>${cxf.mockito.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-xjc-plugin</artifactId> + <version>${cxf.xjc-utils.version}</version> + <executions> + <execution> + <id>generate-transfer</id> + <phase>generate-sources</phase> + <goals> + <goal>xsdtojava</goal> + </goals> + <configuration> + <fork>${cxf.xjcplugin.forkmode}</fork> + <additionalJvmArgs>${cxf.xjc.jvmArgs}</additionalJvmArgs> + <sourceRoot>${basedir}/target/generated-sources/xjc</sourceRoot> + <xsdOptions> + <xsdOption> + <xsd>${basedir}/src/main/resources/schemas/transfer.xsd</xsd> + <packagename>org.apache.cxf.ws.transfer</packagename> + <bindingFile>${basedir}/src/main/resources/schemas/transfer.xjb</bindingFile> + <catalog>${basedir}/src/main/resources/schemas/catalog.cat</catalog> + </xsdOption> + </xsdOptions> + </configuration> + </execution> + <execution> + <id>generate-fragment</id> + <phase>generate-sources</phase> + <goals> + <goal>xsdtojava</goal> + </goals> + <configuration> + <fork>${cxf.xjcplugin.forkmode}</fork> + <additionalJvmArgs>${cxf.xjc.jvmArgs}</additionalJvmArgs> + <sourceRoot>${basedir}/target/generated-sources/xjc</sourceRoot> + <xsdOptions> + <xsdOption> + <xsd>${basedir}/src/main/resources/schemas/fragment.xsd</xsd> + <packagename>org.apache.cxf.ws.transfer.dialect.fragment</packagename> + <catalog>${basedir}/src/main/resources/schemas/catalog-fragment.cat</catalog> + </xsdOption> + </xsdOptions> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> diff --git a/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/ResourceFactoryTest.java b/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/ResourceFactoryTest.java index 01010894ee..ce69c61eee 100644 --- a/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/ResourceFactoryTest.java +++ b/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/ResourceFactoryTest.java @@ -32,10 +32,15 @@ import org.apache.cxf.ws.transfer.Representation; import org.apache.cxf.ws.transfer.manager.ResourceManager; import org.apache.cxf.ws.transfer.resourcefactory.ResourceFactory; -import org.easymock.EasyMock; import org.junit.Assert; import org.junit.Test; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + public class ResourceFactoryTest extends IntegrationBaseTest { private static final String RESOURCE_UUID = "123456"; @@ -74,11 +79,9 @@ public class ResourceFactoryTest extends IntegrationBaseTest { @Test public void createLocalResourceTest() { ReferenceParametersType refParams = createReferenceParameters(); - ResourceManager manager = EasyMock.createMock(ResourceManager.class); - EasyMock.expect(manager.create(EasyMock.isA(Representation.class))) - .andReturn(refParams); - EasyMock.expectLastCall().once(); - EasyMock.replay(manager); + ResourceManager manager = mock(ResourceManager.class); + when(manager.create(isA(Representation.class))) + .thenReturn(refParams); Server localResourceFactory = createLocalResourceFactory(manager); ResourceFactory client = createClient(); @@ -89,7 +92,7 @@ public class ResourceFactoryTest extends IntegrationBaseTest { createRequest.setRepresentation(representation); CreateResponse response = client.create(createRequest); - EasyMock.verify(manager); + verify(manager, times(1)).create(isA(Representation.class)); Assert.assertEquals("ResourceAddress is other than expected.", RESOURCE_ADDRESS, response.getResourceCreated().getAddress().getValue()); @@ -106,11 +109,9 @@ public class ResourceFactoryTest extends IntegrationBaseTest { @Test public void createRemoteResourceTest() { ReferenceParametersType refParams = createReferenceParameters(); - ResourceManager manager = EasyMock.createMock(ResourceManager.class); - EasyMock.expect(manager.create(EasyMock.isA(Representation.class))) - .andReturn(refParams); - EasyMock.expectLastCall().once(); - EasyMock.replay(manager); + ResourceManager manager = mock(ResourceManager.class); + when(manager.create(isA(Representation.class))) + .thenReturn(refParams); Server remoteResourceFactory = createRemoteResourceFactory(); Server remoteResource = createRemoteResource(manager); @@ -122,7 +123,7 @@ public class ResourceFactoryTest extends IntegrationBaseTest { createRequest.setRepresentation(representation); CreateResponse response = client.create(createRequest); - EasyMock.verify(manager); + verify(manager, times(1)).create(isA(Representation.class)); Assert.assertEquals("ResourceAddress is other than expected.", RESOURCE_REMOTE_ADDRESS, response.getResourceCreated().getAddress().getValue()); diff --git a/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/ResourceTest.java b/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/ResourceTest.java index 7e5bdf8845..936e4e24d0 100644 --- a/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/ResourceTest.java +++ b/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/ResourceTest.java @@ -41,10 +41,15 @@ import org.apache.cxf.ws.transfer.manager.MemoryResourceManager; import org.apache.cxf.ws.transfer.manager.ResourceManager; import org.apache.cxf.ws.transfer.resource.Resource; -import org.easymock.EasyMock; import org.junit.Assert; import org.junit.Test; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + public class ResourceTest extends IntegrationBaseTest { private static final String UUID_VALUE = "123456"; @@ -81,10 +86,8 @@ public class ResourceTest extends IntegrationBaseTest { Representation representation = new Representation(); representation.setAny(representationEl); - ResourceManager manager = EasyMock.createMock(ResourceManager.class); - EasyMock.expect(manager.get(EasyMock.isA(ReferenceParametersType.class))).andReturn(representation); - EasyMock.expectLastCall().once(); - EasyMock.replay(manager); + ResourceManager manager = mock(ResourceManager.class); + when(manager.get(isA(ReferenceParametersType.class))).thenReturn(representation); ReferenceParametersType refParams = new ReferenceParametersType(); Element uuid = DOMUtils.getEmptyDocument().createElementNS( @@ -96,7 +99,7 @@ public class ResourceTest extends IntegrationBaseTest { Resource client = createClient(refParams); GetResponse response = client.get(new Get()); - EasyMock.verify(manager); + verify(manager, times(1)).get(isA(ReferenceParametersType.class)); representationEl = (Element) response.getRepresentation().getAny(); Assert.assertEquals("Namespace is other than expected.", @@ -111,12 +114,8 @@ public class ResourceTest extends IntegrationBaseTest { @Test public void putRequestTest() { - ResourceManager manager = EasyMock.createMock(ResourceManager.class); - EasyMock.expect(manager.get(EasyMock.isA(ReferenceParametersType.class))).andReturn(new Representation()); - EasyMock.expectLastCall().once(); - manager.put(EasyMock.isA(ReferenceParametersType.class), EasyMock.isA(Representation.class)); - EasyMock.expectLastCall().once(); - EasyMock.replay(manager); + ResourceManager manager = mock(ResourceManager.class); + when(manager.get(isA(ReferenceParametersType.class))).thenReturn(new Representation()); ReferenceParametersType refParams = new ReferenceParametersType(); Element uuid = DOMUtils.getEmptyDocument().createElementNS( @@ -137,7 +136,8 @@ public class ResourceTest extends IntegrationBaseTest { putRequest.setRepresentation(representation); PutResponse response = client.put(putRequest); - EasyMock.verify(manager); + verify(manager, times(1)).get(isA(ReferenceParametersType.class)); + verify(manager, times(1)).put(isA(ReferenceParametersType.class), isA(Representation.class)); representationEl = (Element) response.getRepresentation().getAny(); Assert.assertEquals("Namespace is other than expected.", @@ -152,10 +152,7 @@ public class ResourceTest extends IntegrationBaseTest { @Test public void deleteRequestTest() { - ResourceManager manager = EasyMock.createMock(ResourceManager.class); - manager.delete(EasyMock.isA(ReferenceParametersType.class)); - EasyMock.expectLastCall().once(); - EasyMock.replay(manager); + ResourceManager manager = mock(ResourceManager.class); ReferenceParametersType refParams = new ReferenceParametersType(); Element uuid = DOMUtils.getEmptyDocument().createElementNS( @@ -167,7 +164,7 @@ public class ResourceTest extends IntegrationBaseTest { Resource client = createClient(refParams); client.delete(new Delete()); - EasyMock.verify(manager); + verify(manager, times(1)).delete(isA(ReferenceParametersType.class)); server.destroy(); }
