Coverage Report - org.mule.tck.testmodels.services.TestServiceComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
TestServiceComponent
0%
0/26
0%
0/10
1.75
 
 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.testmodels.services;
 8  
 
 9  
 import org.mule.api.component.simple.EchoService;
 10  
 import org.mule.api.lifecycle.Disposable;
 11  
 import org.mule.tck.functional.FunctionalTestComponent;
 12  
 import org.mule.util.StringUtils;
 13  
 
 14  
 import java.util.Collections;
 15  
 import java.util.Date;
 16  
 import java.util.HashMap;
 17  
 import java.util.Map;
 18  
 
 19  
 /**
 20  
  * <code>TestServiceComponent</code> is a test WebServices service.
 21  
  */
 22  
 public class TestServiceComponent extends FunctionalTestComponent
 23  
     implements EchoService, DateService, PeopleService, Disposable
 24  
 {
 25  
     // we keep two collections - one static for testing the return of complex types
 26  
     // and one for modifying by methods invoked on the TestComponent instance
 27  
 
 28  0
     private static final Person[] originalPeople = new Person[]{new Person("Barney", "Rubble"),
 29  
         new Person("Fred", "Flintstone"), new Person("Wilma", "Flintstone")};
 30  
 
 31  0
     private final Map people = Collections.synchronizedMap(new HashMap());
 32  
 
 33  
     public TestServiceComponent()
 34  
     {
 35  0
         super();
 36  0
         people.put("Barney", originalPeople[0]);
 37  0
         people.put("Fred", originalPeople[1]);
 38  0
         people.put("Wilma", originalPeople[2]);
 39  0
     }
 40  
 
 41  
     public String echo(String echo)
 42  
     {
 43  0
         return echo;
 44  
     }
 45  
 
 46  
     public String getDate()
 47  
     {
 48  0
         return new Date().toString();
 49  
     }
 50  
 
 51  
     public Person getPerson(String firstName)
 52  
     {
 53  0
         if (StringUtils.isEmpty(firstName))
 54  
         {
 55  0
             throw new IllegalArgumentException("Name parameter cannot be null");
 56  
         }
 57  0
         return (Person)people.get(firstName);
 58  
     }
 59  
 
 60  
     public Person[] getPeople()
 61  
     {
 62  0
         return originalPeople;
 63  
     }
 64  
 
 65  
     public void addPerson(Person person) throws Exception
 66  
     {
 67  0
         if (person == null || person.getFirstName() == null || person.getLastName() == null)
 68  
         {
 69  0
             throw new IllegalArgumentException("null person, first name or last name");
 70  
         }
 71  0
         if (person.getFirstName().equals("Ross"))
 72  
         {
 73  0
             throw new Exception("Ross is banned");
 74  
         }
 75  0
         people.put(person.getFirstName(), person);
 76  0
         logger.debug("Added Person: " + person);
 77  0
     }
 78  
 
 79  
     public Person addPerson(String firstname, String surname) throws Exception
 80  
     {
 81  0
         Person p = new Person(firstname, surname);
 82  0
         addPerson(p);
 83  0
         logger.debug("Added Person: " + p);
 84  0
         return p;
 85  
     }
 86  
 
 87  
     /**
 88  
      * A lifecycle method where implementor should free up any resources. If an
 89  
      * exception is thrown it should just be logged and processing should continue.
 90  
      * This method should not throw RuntimeExceptions.
 91  
      */
 92  
     public void dispose()
 93  
     {
 94  0
         people.clear();
 95  0
     }
 96  
 
 97  
 }