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