Skip to content

Commit

Permalink
Improve testcoverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasrosdal committed Oct 4, 2024
1 parent 8c938d2 commit bb5618b
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 86 deletions.
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@
</configuration>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.12</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
27 changes: 27 additions & 0 deletions src/test/java/FaultTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import org.junit.jupiter.api.Test;
import javax.wsdl.*;
import javax.wsdl.factory.WSDLFactory;

import static org.junit.jupiter.api.Assertions.*;

public class FaultTest {

@Test
public void testFaultElement() throws Exception {
WSDLFactory factory = WSDLFactory.newInstance();
Definition definition = factory.newDefinition();

// Create a new operation with a fault
Operation operation = definition.createOperation();
operation.setName("testOperation");

Fault fault = definition.createFault();
fault.setName("TestFault");
fault.setDocumentationElement(definition.getDocumentationElement());

operation.addFault(fault);

// Check the fault name and linkage
assertEquals("TestFault", operation.getFault("TestFault").getName());
}
}
31 changes: 31 additions & 0 deletions src/test/java/SOAPBindingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import com.ibm.wsdl.extensions.soap.SOAPBindingImpl;
import org.junit.jupiter.api.Test;
import javax.wsdl.*;
import javax.wsdl.extensions.*;
import javax.wsdl.extensions.soap.SOAPBinding;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;

import static org.junit.jupiter.api.Assertions.*;

public class SOAPBindingTest {

@Test
public void testSOAPBindingAttributes() throws Exception {
WSDLFactory factory = WSDLFactory.newInstance();
Definition definition = factory.newDefinition();

// Create and add a SOAP binding to the definition
SOAPBinding soapBinding = new SOAPBindingImpl();
soapBinding.setTransportURI("http://schemas.xmlsoap.org/soap/http");
soapBinding.setStyle("document");

Binding binding = definition.createBinding();
binding.setQName(new QName("http://www.example.com/sample", "SampleBinding"));
binding.addExtensibilityElement(soapBinding);

// Validate SOAP binding properties
assertEquals("http://schemas.xmlsoap.org/soap/http", soapBinding.getTransportURI());
assertEquals("document", soapBinding.getStyle());
}
}
86 changes: 0 additions & 86 deletions src/test/java/WSDLReaderTest.java

This file was deleted.

85 changes: 85 additions & 0 deletions src/test/java/WSDLReaderWriterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import org.junit.jupiter.api.Test;
import org.xml.sax.InputSource;

import javax.wsdl.*;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import javax.wsdl.xml.WSDLWriter;
import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

import javax.xml.namespace.QName;
import javax.xml.transform.stream.StreamSource;

public class WSDLReaderWriterTest {

@Test
public void testReadAndWriteWSDL() throws Exception {
// Create WSDLFactory and WSDLReader/Writer instances
WSDLFactory factory = WSDLFactory.newInstance();
WSDLReader reader = factory.newWSDLReader();
WSDLWriter writer = factory.newWSDLWriter();

// Load a sample WSDL file
String wsdlPath = "src/test/resources/sample.wsdl";
Definition definition = reader.readWSDL(wsdlPath);

// Ensure the WSDL Definition is correctly read
assertNotNull(definition, "WSDL Definition should not be null");

// Verify basic WSDL properties
assertEquals("http://www.example.com/sample", definition.getTargetNamespace(),
"The target namespace should match the expected value");

// Check Services in the WSDL
Map<?, ?> services = definition.getServices();
assertNotNull(services, "Services should not be null");
assertEquals(1, services.size(), "There should be exactly one service defined");

// Retrieve and validate the service
Service service = (Service) services.get(new QName("http://www.example.com/sample", "SampleService"));
assertNotNull(service, "SampleService should be present in the WSDL");

// Write the WSDL back to a string
StringWriter stringWriter = new StringWriter();
writer.writeWSDL(definition, stringWriter);

// Validate the Written WSDL Content
String writtenWsdlContent = stringWriter.toString();
assertNotNull(writtenWsdlContent, "The written WSDL content should not be null");
assertTrue(writtenWsdlContent.contains("SampleService"), "The written WSDL should contain the service name 'SampleService'");
assertTrue(writtenWsdlContent.contains("SampleSoapBinding"), "The written WSDL should contain the binding name 'SampleSoapBinding'");
assertTrue(writtenWsdlContent.contains("getSampleRequest"), "The written WSDL should contain the input message name 'getSampleRequest'");
assertTrue(writtenWsdlContent.contains("getSampleResponse"), "The written WSDL should contain the output message name 'getSampleResponse'");

// Re-read the written WSDL content using a StreamSource instead of passing null
ByteArrayInputStream inputStream = new ByteArrayInputStream(writtenWsdlContent.getBytes(StandardCharsets.UTF_8));
InputSource streamSource = new InputSource(inputStream);

// Use readWSDL with StreamSource
Definition reReadDefinition = reader.readWSDL(null, streamSource);
assertNotNull(reReadDefinition, "The re-read WSDL definition should not be null");

// Compare basic properties between the original and re-read definitions
assertEquals(definition.getTargetNamespace(), reReadDefinition.getTargetNamespace(),
"The target namespace should match between the original and re-read definitions");

// Validate Services in the Re-read Definition
Map<?, ?> reReadServices = reReadDefinition.getServices();
assertNotNull(reReadServices, "Re-read services map should not be null");
assertEquals(1, reReadServices.size(), "Re-read definition should have exactly one service defined");

// Verify the re-read service name
Service reReadService = (Service) reReadServices.get(new QName("http://www.example.com/sample", "SampleService"));
assertNotNull(reReadService, "The re-read SampleService should be present in the re-read WSDL");

// Additional validation to ensure the re-read WSDL matches the original definition
assertEquals(service.getQName(), reReadService.getQName(), "Service QName should match between original and re-read WSDL");
assertEquals(service.getPorts().size(), reReadService.getPorts().size(),
"The number of ports should match between original and re-read WSDL");
}
}

0 comments on commit bb5618b

Please sign in to comment.