Examples of IMockeyStorage


Examples of com.mockey.storage.IMockeyStorage

    // For initialization (by default), the store is in transient mode,
    // which is important to prevent
    // file writing. Too much, too slow. Yuck.
    // inputSource.getByteStream();
    IMockeyStorage c = (IMockeyStorage) MockeyXmlFileConfigurationParser.fullSetDigester.parse(inputSource);
    return c;
  }
View Full Code Here

Examples of com.mockey.storage.IMockeyStorage

   * @throws org.xml.sax.SAXException
   */
  public List<Service> getMockService(InputSource inputSource) throws org.xml.sax.SAXParseException,
      java.io.IOException, org.xml.sax.SAXException {

    IMockeyStorage c = getMockeyStore(inputSource);
    List<Service> list = c.getServices();
    return list;
  }
View Full Code Here

Examples of com.mockey.storage.IMockeyStorage

   * appears 2 times, in type Scenario and Service
   */
  @Test
  public void validateSearchResultByName() {

    IMockeyStorage store = new InMemoryMockeyStorage();
    Service a = new Service();
    a.setServiceName("Service A");
    Scenario aScenario = new Scenario();
    aScenario.setScenarioName("Service Scenario A");
    a.saveOrUpdateScenario(aScenario);
    store.saveOrUpdateService(a);

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

Examples of com.mockey.storage.IMockeyStorage

   * appears 2 times, in type Scenario and Service
   */
  @Test
  public void validateSearchResultScenarioContent() {

    IMockeyStorage store = new InMemoryMockeyStorage();
    Service a = new Service();
    a.setServiceName("Service A");
    Scenario aScenario = new Scenario();
    aScenario.setScenarioName("Scenario A");
    aScenario.setResponseMessage("lorem ipsum");
    a.saveOrUpdateScenario(aScenario);
    store.saveOrUpdateService(a);

    String term = "cats";
    SearchResultBuilder resultBuilder = new SearchResultBuilder();
    List<SearchResult> resultList = resultBuilder.buildSearchResults(term,
        store);

    assert (resultList.size() == 0) : "Length should be 0 but was "
        + resultList.size();

    term = "  lorem   ";
    resultBuilder = new SearchResultBuilder();
    resultList = resultBuilder.buildSearchResults(term, store);
    assert (resultList.size() == 1) : "Length should be: 1 " + " but was '"
        + resultList.size() + "'";
    assert (resultList.get(0).getType() == SearchResultType.SERVICE_SCENARIO) : "Search type result should be 'scenario' but was '"
        + resultList.get(0).getType().toString() + "'";

    aScenario = new Scenario();
    aScenario.setScenarioName("Scenario B");
    aScenario.setResponseMessage("lorem ipsula");
    a.saveOrUpdateScenario(aScenario);
    store.saveOrUpdateService(a);

    term = "  lorem   ";
    resultBuilder = new SearchResultBuilder();
    resultList = resultBuilder.buildSearchResults(term, store);
    // We should have TWO scenarios with 'lorem' in content/
View Full Code Here

Examples of com.mockey.storage.IMockeyStorage

   * appears 2 times, in type Scenario and 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,
        store);
View Full Code Here

Examples of com.mockey.storage.IMockeyStorage

   * appears 2 times, in type Scenario and Service
   */
  @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");
    store.saveOrUpdateServicePlan(servicePlan);
   
    String term = "cats";
    SearchResultBuilder resultBuilder = new SearchResultBuilder();
    List<SearchResult> resultList = resultBuilder.buildSearchResults(term,
        store);
View Full Code Here

Examples of com.mockey.storage.IMockeyStorage

    // STEP #1. CREATE A TEMP STORE
    // Read the incoming XML file, and create a new/temporary store for the
    // need to ensure current store doesn't get overridden
    //
    MockeyXmlFileConfigurationReader msfr = new MockeyXmlFileConfigurationReader();
    IMockeyStorage mockServiceStoreTemporary = msfr.readDefinition(strXMLDefintion);

    // STEP #2. PROXY SETTINGS
    // If the proxy settings are _empty_, then set the incoming
    // proxy settings. Otherwise, call out a merge conflict.
    //
    ProxyServerModel proxyServerModel = store.getProxy();
    if (proxyServerModel.hasSettings()) {
      mergeResults.addConflictMsg("Proxy settings NOT set from incoming file.");
    } else {
      store.setProxy(mockServiceStoreTemporary.getProxy());
      mergeResults.addAdditionMsg("Proxy settings set.");
    }

    // STEP #3. BUILD SERVICE REFERENCES
    // Why is this needed?
    // We are adding _new_ services into the Store, and that means that the
    // store's state is always changing. We need references as a saved
    // snapshot list of store state prior to adding new services.
    // **********
    // I forget why we really need this though...
    // **********
    List<Service> serviceListFromRefs = new ArrayList<Service>();
    for (ServiceRef serviceRef : mockServiceStoreTemporary.getServiceRefs()) {
      try {

        String mockServiceDefinition = getFileContentAsString(new FileInputStream(serviceRef.getFileName()));

        // HACK:
        // I tried to find an easier way to use XML ENTITY and let
        // Digester
        // to the work of slurping up the XML but was unsuccessful.
        // Hence, the brute force.
        // YYYYY
        //

        List<Service> tmpList = msfr.readServiceDefinition(mockServiceDefinition);
        for (Service tmpService : tmpList) {
          serviceListFromRefs.add(tmpService);
        }
      } catch (SAXParseException spe) {
        logger.error("Unable to parse file of name " + serviceRef.getFileName(), spe);
        mergeResults.addConflictMsg("File not parseable: " + serviceRef.getFileName());

      } catch (FileNotFoundException fnf) {
        logger.error("File not found: " + serviceRef.getFileName());
        mergeResults.addConflictMsg("File not found: " + serviceRef.getFileName());
      }

    }
    addServicesToStore(mergeResults, serviceListFromRefs, tagArguments);

    // STEP #4. MERGE SERVICES AND SCENARIOS
    // Since this gets complicated, logic was moved to it's own method.
    mergeResults = addServicesToStore(mergeResults, mockServiceStoreTemporary.getServices(), tagArguments);

    // STEP #5. UNIVERSAL RESPONSE SETTINGS
    // Important: usage of the temporary-store's Scenario reference
    // information is used to set the primary in-memory store. The primary
    // store has all the information and the TEMP store only needs to pass
    // the references, e.g. Service 1, Scenario 2.
    if (store.getUniversalErrorScenario() != null
        && mockServiceStoreTemporary.getUniversalErrorScenarioRef() != null) {
      mergeResults.addConflictMsg("Universal error message already defined with name '"
          + store.getUniversalErrorScenario().getScenarioName() + "'");
    } else if (store.getUniversalErrorScenario() == null
        && mockServiceStoreTemporary.getUniversalErrorScenarioRef() != null) {
      store.setUniversalErrorScenarioRef(mockServiceStoreTemporary.getUniversalErrorScenarioRef());
      mergeResults.addAdditionMsg("Universal error response defined.");

    }

    // STEP #6. MERGE SERVICE PLANS
    for (ServicePlan servicePlan : mockServiceStoreTemporary.getServicePlans()) {
      if (tagArguments != null) {
        servicePlan.addTagToList(tagArguments);
      }
      store.saveOrUpdateServicePlan(servicePlan);
    }

    // STEP #7. TWIST CONFIGURATION
    for (TwistInfo twistInfo : mockServiceStoreTemporary.getTwistInfoList()) {
      store.saveOrUpdateTwistInfo(twistInfo);
    }

    // STEP #8. DEFAULT Service Plan ID
    // Only set a default service plan ID from the incoming XML file
    // if one is not already set in the current store.
    ServicePlan servicePlan = mockServiceStoreTemporary.getServicePlanById(mockServiceStoreTemporary
        .getDefaultServicePlanIdAsLong());
    if (servicePlan != null && store.getDefaultServicePlanIdAsLong() == null) {
      // OK, we have a 'default' service plan from the incoming file AND
      // the current store does not. Let's update the current store.
      store.setDefaultServicePlanId(mockServiceStoreTemporary.getDefaultServicePlanId());
      store.setServicePlan(servicePlan);

    }

    // Don't forget to set state back to original state.
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.