Topic
  • No replies
Bhaskar_sekar
Bhaskar_sekar
1 Post

Pinned topic How to add Property values to attribute request?

‏2012-07-16T15:50:42Z |
Hi,

This is my file structure

example --- product --- src -- main -- java -- se -- sigma -- example --- Car.java
   

| | -- WebService.java
| |
   
 

| -- pom.xml
|
   
 

-- test --- src -- test -- java -- se -- sigma -- example --- FuelCarTest.java
     

| | | -- FuelCarSteps.java
| | |
     

| | -- resources -- se -- sigma -- example -- CarMaintenance.feature
| |
     

| -- pom.xml
|
     

-- pom.xml

This is the java class i am having

File: product/src/main/java/se/sigma/example/Car.java

package se.sigma.example;

import javax.jws.WebMethod;
import javax.jws.WebService;
import java.util.Date;

@WebService
public class Car {
private Integer fuelLevel;

public Car() {
fuelLevel = 0;
}

@WebMethod
public void addFuel(int addedAmount) {
String message = "adding " + addedAmount;
usageLog(message);
fuelLevel = fuelLevel + addedAmount;
}

@WebMethod
public Integer getFuelLevel() {
String message = "returning fuel level " + fuelLevel;
usageLog(message);
return fuelLevel;
}

@WebMethod
public void emptyFuel() {
String message = "Emptying fuel tank";
usageLog(message);
fuelLevel = 0;
}

private void usageLog(String message) {
Date now = new Date();
System.out.println(now + " " + message);
}
}

This would be the web service i am hosting

File: product/src/main/java/se/sigma/example/WebService.java

package se.sigma.example;

import javax.xml.ws.Endpoint;

public class WebService {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8090/car", new Car());
}
}

The XML I would be using is

<plugin>
<groupId>eviware</groupId>
<artifactId>maven-soapui-plugin</artifactId>
<version>4.0.1</version>
<configuration>
<projectFile>test/src/test/soapUI/CarMaintenance-soapui-project.xml</projectFile>
<outputFolder>./test/target/soapUI</outputFolder>
<junitReport>true</junitReport>
<printReport>true</printReport>
<projectProperties>
<value>addedFuel=17</value>
<value>expectedFuel=17</value>
</projectProperties>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>

My requirement is map the property value as attribute request.The fuel value's
should be taken at runtime instead of getting hardcoded values.

The Java code to read the properties will be as below

package se.sigma.example.junit;

import com.eviware.soapui.tools.SoapUITestCaseRunner;
import org.junit.Test;

public class FuelCarTest {
@Test
public void verifyTheInputValueIsReturned() throws Exception {
SoapUITestCaseRunner runner = new SoapUITestCaseRunner();
runner.setProjectFile("/Users/tsu/Dropbox/projects/tsu/blog/soapUI-junit-maven-cucumber/example/test/src/test/soapUI/CarMaintenance-soapui-project.xml");
String[] properties = new String[2];
properties[0] = "addedFuel=17";
properties[1] = "expectedFuel=17";
runner.setProjectProperties(properties);
runner.run();
}
}
Let me know how the values properties[0] and properties[1] can be added at run
time,instead of hardcoding the values.
Any suggestions are welcome