View Javadoc

1   /*
2    * soapUI, copyright (C) 2004-2010 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
66  						+ "] already exists. Property transfer will be disabled." );
67  				badTransfer.setDisabled( true );
68  
69  			}
70  			else
71  			{
72  				TestProperty newProperty = project.addProperty( name );
73  				name = UISupport.prompt( "What is default value for property " + name, "Add Property Value", "" );
74  				if( StringUtils.hasContent( name ) )
75  					newProperty.setValue( name );
76  				else
77  					newProperty.setValue( newProperty.getName() );
78  				badTransfer.setSourcePropertyName( newProperty.getName() );
79  				resolved = true;
80  			}
81  		}
82  		else
83  		{
84  			UISupport.showInfoMessage( "Canceled. Property transfer will be disabled." );
85  			badTransfer.setDisabled( true );
86  		}
87  		return resolved;
88  	}
89  
90  }