Package com.mockey.model

Examples of com.mockey.model.Service


   */
  @Test
  public void validateSearchResultByServiceTag() {

    IMockeyStorage store = new InMemoryMockeyStorage();
    Service a = new Service();
    a.setServiceName("Service A");
    a.setTag("   tagCC");
    store.saveOrUpdateService(a);

    String term = "cats";
    SearchResultBuilder resultBuilder = new SearchResultBuilder();
    List<SearchResult> resultList = resultBuilder.buildSearchResults(term,
View Full Code Here


   */
  @Test
  public void validateSearchResultByServicePlanTag() {

    IMockeyStorage store = new InMemoryMockeyStorage();
    Service a = new Service();
    a.setServiceName("Service A");
    a.setTag("   tagCC");
    store.saveOrUpdateService(a);
   
    ServicePlan servicePlan = new ServicePlan();
    servicePlan.setName("ServicePlan A");
    servicePlan.setTag("service_plan_tag_123");
View Full Code Here

  public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    Long serviceId = new Long(req.getParameter("serviceId"));
    String scenarioIdAsString = req.getParameter("scenarioId");
    Service service = store.getServiceById(serviceId);
    Scenario scenario = null;
    resp.setContentType("application/json");
    PrintWriter out = resp.getWriter();
    try {
      scenario = service.getScenario(new Long(scenarioIdAsString));
      JSONObject jsonObject = new JSONObject();
      jsonObject.put("serviceId", "" + serviceId);
      jsonObject.put("serviceName", "" + service.getServiceName());
      jsonObject.put("scenarioId", "" + scenario.getId());
      jsonObject.put("tag", "" + scenario.getTag());
      jsonObject.put("httpResponseStatusCode", "" + scenario.getHttpResponseStatusCode());
      jsonObject.put("httpMethodType", "" + scenario.getHttpMethodType());
      jsonObject.put("name", scenario.getScenarioName());
      jsonObject.put("match", scenario.getMatchStringArg());
      jsonObject.put("matchRegexFlag", scenario.isMatchStringArgEvaluationRulesFlag());
      jsonObject.put("response", scenario.getResponseMessage());
      jsonObject.put("responseHeader", scenario.getResponseHeader());

      // Error handling flags
      String scenarioErrorId = (service.getErrorScenario() != null) ? "" + service.getErrorScenario().getId()
          : "-1";
      if (scenarioErrorId.equals(scenarioIdAsString)) {
        jsonObject.put("scenarioErrorFlag", true);
      } else {
        jsonObject.put("scenarioErrorFlag", false);
View Full Code Here

        serviceIdMergeSource = new Long(serviceMergeIdList[i]);
        serviceIdMergeDestination = new Long(req
            .getParameter("serviceIdMergeDestination"));
        if (!serviceIdMergeSource.equals(serviceIdMergeDestination)) {

          Service serviceMergeSource = store
              .getServiceById(serviceIdMergeSource);
          Service serviceMergeDestination = store
              .getServiceById(serviceIdMergeDestination);
          MockeyXmlFileManager configurationReader = MockeyXmlFileManager.getInstance();
          mergeResults = configurationReader.mergeServices(
              serviceMergeSource, serviceMergeDestination,
              mergeResults, null);

        }
        responseMap.put("additions", mergeResults.getAdditionMsg());
        responseMap.put("conflicts", mergeResults.getConflictMsg());
      }
     
    } catch (Exception e) {
      // Do nothing
      log.error("Something wrong with merging services.", e);
      responseMap.put("conflicts", "Unable to merge services. The services selected may be missing or contain bad data. Sorry about this.");

    }
   
    // IF NO CONFLICTS, THEN DELETE OLD SOURCE SERVICES
    if(mergeResults!=null && (mergeResults.getConflictMsgs()==null || mergeResults.getConflictMsgs().isEmpty())){
      for (int i = 0; i < serviceMergeIdList.length; i++) {
        serviceIdMergeSource = new Long(serviceMergeIdList[i]);
        Service service = store.getServiceById(serviceIdMergeSource);
        store.deleteService(service);
      }
     
    }
    resp.setContentType("application/json");
View Full Code Here

        store.setReadOnlyMode(TRANSIENT_STATE);
        int serviceResponseType = Integer.parseInt(req
            .getParameter("responseType"));
        for (Iterator<Service> iterator = services.iterator(); iterator
            .hasNext();) {
          Service service = iterator.next();

          service.setServiceResponseType(serviceResponseType);
          store.saveOrUpdateService(service);
        }
      } catch (Exception e) {
        logger.error("Unable to update service(s", e);
      }
      // #3 Return store back to original setting.
      store.setReadOnlyMode(origReadOnlyMode);
      resp.setContentType("application/json");
      PrintWriter out = resp.getWriter();
      Map<String, String> successMessage = new HashMap<String, String>();
      successMessage.put("success", "updated");
      String resultingJSON = Util.getJSON(successMessage);
      out.println(resultingJSON);
      out.flush();
      out.close();
      return;
    }
    Long serviceId = null;
    try {
      serviceId = new Long(req.getParameter("serviceId"));
    } catch (Exception e) {
      // Do nothing
    }

    if (req.getParameter("deleteService") != null && serviceId != null) {
      Service service = store.getServiceById(serviceId);
      store.deleteService(service);
      store.deleteFulfilledClientRequestsForService(serviceId);

      Util.saveSuccessMessage("Service '" + service.getServiceName()
          + "' was deleted.", req);

      // Check to see if any plans need an update.
      String errorMessage = null;
      if (service.isReferencedInAServicePlan()) {
        errorMessage = "Warning: the deleted service is referenced in service plans.";
      }

      if (errorMessage != null) {
        Util.saveErrorMessage(errorMessage, req);
      }
      String contextRoot = req.getContextPath();
      resp.sendRedirect(Url.getContextAwarePath("home", contextRoot));
      return;
    } else if (req.getParameter("duplicateService") != null
        && serviceId != null) {
      Service service = store.getServiceById(serviceId);
      Service duplicateService = store.duplicateService(service);
      String contextRoot = req.getContextPath();
      resp.sendRedirect(Url.getContextAwarePath("setup?serviceId="
          + duplicateService.getId(), contextRoot));
      return;
    }

    super.service(req, resp);
  }
View Full Code Here

    try {
      serviceId = new Long(req.getParameter("serviceId"));
    } catch (Exception e) {
      // Do nothing
    }
    Service service = null;

    if (serviceId != null) {
      service = store.getServiceById(serviceId);
    }
    if (service == null) {
      service = new Service();
    }

    req.setAttribute("mockservice", service);

    req.setAttribute("requestInspectorList", PluginStore.getInstance()
View Full Code Here

        targetHttpReqURI = twistInfo.getTwistedValue(originalHttpReqURI);
      }
    }

    Url serviceUrl = new Url(targetHttpReqURI);
    Service service = store.getServiceByUrl(serviceUrl.getFullUrl());
    // ************************************************************************
    // STEP #2) Process your original request.
    // ************************************************************************
    RequestFromClient request = new RequestFromClient(originalHttpReqFromClient);

    // ************************************************************************
    // STEP #3) JAVA and JSON implemented Inspectors
    // ************************************************************************

    PluginStore pluginStore = PluginStore.getInstance();
    RequestInspectionResult inspectionMessage = pluginStore.processRequestInspectors(service, request);

    // ************************************************************************
    // STEP #4) Get the Response (static,dynamic, or proxy).
    // ************************************************************************
    service.setHttpMethod(originalHttpReqFromClient.getMethod());
    ResponseFromService response = service.execute(request, serviceUrl);

    // ************************************************************************
    // STEP #5) If twisting was enabled, let's be sure to set the original URL
    // ************************************************************************
    if (!originalHttpReqURI.equalsIgnoreCase(targetHttpReqURI)) {
      response.setOriginalRequestUrlBeforeTwisting(new Url(originalHttpReqURI));
    }
    logRequestAsFulfilled(service, request, response, originalHttpReqFromClient.getRemoteAddr(), inspectionMessage);

    try {
      // Wait for a X hang time seconds.
      logger.debug("Waiting..." + service.getHangTime() + " miliseconds ");
      Thread.currentThread().sleep(service.getHangTime());
      logger.debug("Done Waiting");
    } catch (Exception e) {
      // Catch interrupt exception.
      // Or not.
    }

    if (!(service.getServiceResponseType() == Service.SERVICE_RESPONSE_TYPE_PROXY)) {
      if (response.getHeaders() != null) {
        for (Header h : response.getHeaders()) {
          resp.setHeader(h.getName(), h.getValue());
        }
      }
View Full Code Here

    return planList;
  }

  public List<Service> getServices() {
    List<Service> services = new ArrayList<Service>();
    Service service = new Service();
    service.setServiceName("testname");
    service.setDescription("test description");

    Scenario scenario = new Scenario();
    scenario.setScenarioName("a");
    scenario.setRequestMessage("request message a");
    scenario.setResponseMessage("response message a");
    service.saveOrUpdateScenario(scenario);
    scenario = new Scenario();
    scenario.setScenarioName("b");
    scenario.setRequestMessage("request message b");
    scenario.setResponseMessage("response message b");
    service.saveOrUpdateScenario(scenario);
    services.add(service);
    Service service2 = new Service();
    service2.setServiceName("testname2");
    service2.setDescription("test description2");

    Scenario scenario2 = new Scenario();
    scenario2.setScenarioName("a");
    scenario2.setRequestMessage("request message a");
    scenario2.setResponseMessage("response message a");
    service2.saveOrUpdateScenario(scenario);
    scenario2 = new Scenario();
    scenario2.setScenarioName("b");
    scenario2.setRequestMessage("request message b");
    scenario2.setResponseMessage("response message b");
    service2.saveOrUpdateScenario(scenario);
    services.add(service2);
    return services;
  }
View Full Code Here

    for (Service uploadedServiceBean : serviceListToAdd) {
      List<Service> serviceBeansInMemory = store.getServices();
      Iterator<Service> inMemoryServiceIter = serviceBeansInMemory.iterator();

      boolean existingService = false;
      Service inMemoryServiceBean = null;

      while (inMemoryServiceIter.hasNext()) {
        inMemoryServiceBean = (Service) inMemoryServiceIter.next();

        // Same name?
        if (uploadedServiceBean.getServiceName().trim().toLowerCase()
            .equals(inMemoryServiceBean.getServiceName().trim().toLowerCase())) {
          existingService = true;
          mergeResults.addConflictMsg("Service '" + uploadedServiceBean.getServiceName()
              + "' not created because one with the same name already defined. '"
              + inMemoryServiceBean.getServiceName() + "' ");

        }
      }
      if (!existingService) {
        // YES, no in-store matching Name.
View Full Code Here

  public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String serviceId = req.getParameter(ServiceConfigurationAPI.API_SERVICE_ID);
    String serviceName = req.getParameter(ServiceConfigurationAPI.API_SERVICE_NAME);

    Service service = null;
    JSONObject jsonResultObject = new JSONObject();

    if (serviceId != null) {
      service = store.getServiceById(new Long(serviceId));
    } else if (serviceName != null) {
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.