Package com.mockey.model

Examples of com.mockey.model.Service


   *
   * @see #getGlobalStateSystemFilterTag()
   */
  public Service getServiceByUrl(String url) {

    Service service = null;
    String filterTag = this.getGlobalStateSystemFilterTag();
    try {

      // **************************************************
      // Be sure to include Filter match if non-empty
      // **************************************************

      Iterator<Service> iter = getServices().iterator();
      while (iter.hasNext()) {
        Service serviceTmp = iter.next();
        service = findServiceBasedOnUrlPattern(url, serviceTmp);
        if (service != null) {
          break;
        }
      }
    } catch (Exception e) {
      logger.error("Unable to retrieve service w/ url pattern: " + url, e);
    }

    if (service != null && filterTag != null && filterTag.trim().length() > 0 && service.hasTag(filterTag)) {
      logger.debug("Found service with Service path: " + url + ", with tag filter '" + filterTag + "'.");
      return service;
    } else if (service != null && filterTag != null && filterTag.trim().length() > 0 && !service.hasTag(filterTag)) {
      logger.debug("Found service with Service path: " + url + ", but DOES NOT have a matching tag filter of '"
          + filterTag + "', so Mockey is returning not-found.");
      service = null;
    } else if (service != null) {
      logger.debug("Found service with Service path: " + url + ". No tag filter. ");
      return service;
    } else {
      logger.debug("Didn't find service with Service path: " + url + ".  Creating a new one.");
    }

    service = new Service();
    try {
      Url newUrl = new Url(Url.getSchemeHostPortPathFromURL(url));
      service.setUrl(newUrl.getFullUrl());
      service.saveOrUpdateRealServiceUrl(newUrl);
      store.saveOrUpdateService(service);
View Full Code Here


   *            service state to compare to the url
   * @return service if url pattern matches
   */
  private Service findServiceBasedOnUrlPattern(String url, Service serviceToEvaluate) {
    Url fullUrl = new Url(serviceToEvaluate.getUrl());
    Service foundService = null;
    // EXAMPLE: "http://example.com/hotels/{hotel}/bookings/{booking}"
    UriTemplate template = new UriTemplate(fullUrl.getFullUrl());

    // EXAMPLE: "http://example.com/hotels/1/bookings/42"
    @SuppressWarnings("rawtypes")
View Full Code Here

   * Deep clone of a Service.
   *
   * @param service
   */
  public Service duplicateService(Service service) {
    Service newService = new Service();
    newService.setHangTime(service.getHangTime());
    newService.setHttpMethod(service.getHttpMethod());
    newService.setServiceName(service.getServiceName());
    newService.setServiceResponseTypeByString(service.getServiceResponseTypeAsString());
    newService.setDefaultRealUrlIndex(service.getDefaultRealUrlIndex());
    newService.setUrl(service.getUrl());
    // We don't do this because the Default scenario ID is not guaranteed to
    // be the same as the duplicate items are created.
    // newService.setDefaultScenarioId(service.getDefaultScenarioId());
    newService.setDescription(service.getDescription());
    // Meta data
    for (Url url : service.getRealServiceUrls()) {
      newService.saveOrUpdateRealServiceUrl(url);

    }
    // Why save, and save again below?
    // - The first save gets a Service ID created.
    // - Scenario's refer to the Service ID
    newService = this.saveOrUpdateService(newService);
    // Now add scenarios
    for (Scenario scenario : service.getScenarios()) {
      Scenario newScenario = new Scenario();
      newScenario.setHttpResponseStatusCode(scenario.getHttpResponseStatusCode());
      newScenario.setMatchStringArg(scenario.getMatchStringArg());
      newScenario.setResponseHeader(scenario.getResponseHeader());
      newScenario.setResponseMessage(scenario.getResponseMessage());
      newScenario.setScenarioName(scenario.getScenarioName());
      newScenario.setTag(scenario.getTag());

      newService.saveOrUpdateScenario(newScenario);

    }
    // Save AGAIN.
    newService = this.saveOrUpdateService(newService);
    return newService;
View Full Code Here

    this.writeMemoryToFile();
  }

  public void updateServicePlansWithNewScenarioName(Long serviceId, String oldScenarioName, String newScenarioName) {

    Service service = this.getServiceById(serviceId);
    if (service != null) {

      for (ServicePlan servicePlan : this.getServicePlans()) {
        for (PlanItem planItem : servicePlan.getPlanItemList()) {
          if (planItem.getServiceName() != null && planItem.getServiceName().equals(service.getServiceName())
              && planItem.getScenarioName().equals(oldScenarioName)) {
            planItem.setScenarioName(newScenarioName);
            // 'Add' will 'update' too.
            servicePlan.addPlanItem(planItem);
          }
View Full Code Here

    return scenarioRef;
  }

  public Scenario getUniversalErrorScenario() {
    Scenario error = null;
    Service service = getServiceById(this.universalErrorServiceId);
    if (service != null) {
      error = service.getScenario(this.universalErrorScenarioId);
    }
    return error;
  }
View Full Code Here

    if (servicePlan != null) {

      for (PlanItem planItem : servicePlan.getPlanItemList()) {

        Service service = this.getServiceByName(planItem.getServiceName());

        if (service != null) {
          service.setHangTime(planItem.getHangTime());
          service.setDefaultScenarioByName(planItem.getScenarioName());
          service.setServiceResponseType(planItem.getServiceResponseType());
          this.saveOrUpdateService(service);
        }
      }
      // Why do we save the Plan here?
      // To save the lastVisit time
View Full Code Here

TOP

Related Classes of com.mockey.model.Service

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.