View Javadoc

1   /*
2    * soapUI, copyright (C) 2004-2008 eviware.com
3    *
4    * soapUI is free software; you can redistribute it and/or modify it under the
5    * terms of version 2.1 of the GNU Lesser General Public License as published by
6    * the Free Software Foundation.
7    *
8    * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9    * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   * See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.support.resolver;
14  
15  import com.eviware.soapui.impl.wsdl.WsdlProject;
16  import com.eviware.soapui.impl.wsdl.teststeps.PropertyTransfer;
17  import com.eviware.soapui.impl.wsdl.teststeps.PropertyTransfersTestStep;
18  import com.eviware.soapui.model.testsuite.TestProperty;
19  import com.eviware.soapui.support.StringUtils;
20  import com.eviware.soapui.support.UISupport;
21  import com.eviware.soapui.support.resolver.ResolveContext.Resolver;
22  
23  public class CreateMissingPropertyResolver implements Resolver
24  {
25  	private boolean resolved = false;
26  	private PropertyTransfersTestStep parentPropertyTestStep = null;
27  	private PropertyTransfer badTransfer = null;
28  
29  	public CreateMissingPropertyResolver(PropertyTransfer transfer, PropertyTransfersTestStep parent)
30  	{
31  		parentPropertyTestStep = parent;
32  		badTransfer = transfer;
33  	}
34  
35  	public String getDescription()
36  	{
37  		return "Create new property";
38  	}
39  
40  	@Override
41  	public String toString()
42  	{
43  		return getDescription();
44  	}
45  
46  	public String getResolvedPath()
47  	{
48  		return null;
49  	}
50  
51  	public boolean isResolved()
52  	{
53  		return resolved;
54  	}
55  
56  	public boolean resolve()
57  	{
58  		WsdlProject project = parentPropertyTestStep.getTestCase().getTestSuite().getProject();
59  
60  		String name = UISupport.prompt("Specify unique property name", "Add Property", "");
61  		if (StringUtils.hasContent(name))
62  		{
63  			if (project.hasProperty(name))
64  			{
65  				UISupport.showErrorMessage("Property name [" + name + "] already exists. Property transfer will be disabled.");
66  				badTransfer.setDisabled(true);
67  				
68  			}
69  			else
70  			{
71  				TestProperty newProperty = project.addProperty(name);
72  				name = UISupport.prompt("What is default value for property " + name, "Add Property Value", "");
73  				if (StringUtils.hasContent(name))
74  					newProperty.setValue(name);
75  				else
76  					newProperty.setValue(newProperty.getName());
77  				badTransfer.setSourcePropertyName(newProperty.getName());
78  				resolved = true;
79  			}
80  		} else {
81  			UISupport.showInfoMessage("Canceled. Property transfer will be disabled.");
82  			badTransfer.setDisabled(true);
83  		}
84  		return resolved;
85  	}
86  
87  }