View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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  package com.eviware.soapui.impl.wsdl.teststeps.assertions.http;
13  
14  import java.util.List;
15  
16  import com.eviware.soapui.config.TestAssertionConfig;
17  import com.eviware.soapui.impl.support.http.HttpRequest;
18  import com.eviware.soapui.impl.wsdl.submit.transports.http.HTMLPageSourceDownloader;
19  import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
20  import com.eviware.soapui.impl.wsdl.teststeps.assertions.AbstractTestAssertionFactory;
21  import com.eviware.soapui.model.iface.MessageExchange;
22  import com.eviware.soapui.model.iface.SubmitContext;
23  import com.eviware.soapui.model.testsuite.Assertable;
24  import com.eviware.soapui.model.testsuite.AssertionError;
25  import com.eviware.soapui.model.testsuite.AssertionException;
26  import com.eviware.soapui.model.testsuite.RequestAssertion;
27  import com.eviware.soapui.model.testsuite.ResponseAssertion;
28  
29  public class HttpDownloadAllResourcesAssertion extends WsdlMessageAssertion implements ResponseAssertion,
30  		RequestAssertion
31  {
32  	public static final String ID = "HTTP Download all resources";
33  	public static final String LABEL = "HTTP Download all resources";
34  
35  	public HttpDownloadAllResourcesAssertion( TestAssertionConfig assertionConfig, Assertable assertable )
36  	{
37  		super( assertionConfig, assertable, false, false, false, true );
38  	}
39  
40  	@Override
41  	protected String internalAssertResponse( MessageExchange messageExchange, SubmitContext context )
42  			throws AssertionException
43  	{
44  
45  		List<String> missingResourcesList = ( List<String> )context
46  				.getProperty( HTMLPageSourceDownloader.MISSING_RESOURCES_LIST );
47  		if( missingResourcesList != null && !missingResourcesList.isEmpty() )
48  		{
49  			StringBuilder sb = new StringBuilder( "Missing resources: \n" );
50  			for( String url : missingResourcesList )
51  			{
52  				sb.append( url + "  ;\n" );
53  			}
54  			throw new AssertionException( new AssertionError( sb.toString() ) );
55  		}
56  
57  		return "HTTP Download all resources OK";
58  	}
59  
60  	@Override
61  	protected String internalAssertRequest( MessageExchange messageExchange, SubmitContext context )
62  			throws AssertionException
63  	{
64  		return "HTTP Download all resources OK";
65  	}
66  
67  	public static class Factory extends AbstractTestAssertionFactory
68  	{
69  		public Factory()
70  		{
71  			super( HttpDownloadAllResourcesAssertion.ID, HttpDownloadAllResourcesAssertion.LABEL,
72  					HttpDownloadAllResourcesAssertion.class, HttpRequest.class );
73  		}
74  
75  		@Override
76  		public Class<? extends WsdlMessageAssertion> getAssertionClassType()
77  		{
78  			return HttpDownloadAllResourcesAssertion.class;
79  		}
80  	}
81  }