Coverage Report - org.mule.tck.transformer.ValidateResponse
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidateResponse
0%
0/9
0%
0/8
0
 
 1  
 /*
 2  
  * $Id: ValidateResponse.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.tck.transformer;
 12  
 
 13  
 import org.mule.api.transformer.TransformerException;
 14  
 import org.mule.config.i18n.MessageFactory;
 15  
 import org.mule.transformer.AbstractTransformer;
 16  
 import org.mule.util.IOUtils;
 17  
 
 18  
 import java.io.InputStream;
 19  
 
 20  
 /**
 21  
  * Throws an exception if the message does not contain "success".
 22  
  */
 23  0
 public class ValidateResponse extends AbstractTransformer
 24  
 {
 25  
     @Override
 26  
     protected Object doTransform(Object src, String encoding) throws TransformerException
 27  
     {
 28  0
         String response = null;
 29  0
         if (src instanceof String)
 30  
         {
 31  0
             response = (String) src;
 32  
         }
 33  0
         else if (src instanceof InputStream)
 34  
         {
 35  0
             response = IOUtils.toString((InputStream) src);
 36  
         }
 37  
         
 38  0
         if (response != null && response.contains("success"))
 39  
         {
 40  0
             return response;
 41  
         }
 42  
         else
 43  
         {
 44  0
             throw new TransformerException(MessageFactory.createStaticMessage("Invalid response from service: " + response));
 45  
         }
 46  
     }
 47  
 }
 48  
 
 49