Package by.stub.yaml.stubs

Examples of by.stub.yaml.stubs.StubHttpLifecycle


   private synchronized StubHttpLifecycle getMatchedStubHttpLifecycle(final StubHttpLifecycle assertingLifecycle) {
      final int listIndex = stubHttpLifecycles.indexOf(assertingLifecycle);
      if (listIndex < 0) {
         return StubHttpLifecycle.NULL;
      }
      final StubHttpLifecycle foundStubHttpLifecycle = stubHttpLifecycles.get(listIndex);
      foundStubHttpLifecycle.setResourceId(listIndex);

      return foundStubHttpLifecycle;
   }
View Full Code Here


      resetStubHttpLifecycles(stubHttpLifecycles);
   }

   public synchronized String refreshStubbedData(final YamlParser yamlParser, final String put, final int stubIndexToUpdate) throws Exception {
      final List<StubHttpLifecycle> stubHttpLifecycles = yamlParser.parse(this.dataYaml.getParent(), put);
      final StubHttpLifecycle newStubHttpLifecycle = stubHttpLifecycles.get(0);
      updateStubHttpLifecycleByIndex(stubIndexToUpdate, newStubHttpLifecycle);

      return newStubHttpLifecycle.getRequest().getUrl();
   }
View Full Code Here

   public synchronized boolean isStubHttpLifecycleExistsByIndex(final int httpLifecycleIndex) {
      return stubHttpLifecycles.size() - 1 >= httpLifecycleIndex;
   }

   public synchronized StubHttpLifecycle deleteStubHttpLifecycleByIndex(final int httpLifecycleIndex) {
      final StubHttpLifecycle removedLifecycle = stubHttpLifecycles.remove(httpLifecycleIndex);
      updateResourceIDHeaders();

      return removedLifecycle;
   }
View Full Code Here

   public DataStore(final List<StubHttpLifecycle> stubHttpLifecycles) {
      this.stubHttpLifecycles = Collections.synchronizedList(stubHttpLifecycles);
   }

   public StubResponse findStubResponseFor(final StubRequest assertionStubRequest) {
      return identifyTypeOfStubResponse(new StubHttpLifecycle(assertionStubRequest, new StubResponse()));
   }
View Full Code Here

   private StubResponse identifyTypeOfStubResponse(final StubHttpLifecycle assertionStubHttpLifecycle) {

      if (stubHttpLifecycles.contains(assertionStubHttpLifecycle)) {
         final int indexOf = stubHttpLifecycles.indexOf(assertionStubHttpLifecycle);
         final StubHttpLifecycle foundStubHttpLifecycle = stubHttpLifecycles.get(indexOf);

         final Map<String, String> headers = foundStubHttpLifecycle.getRequest().getHeaders();
         if (headers.containsKey(StubRequest.AUTH_HEADER)) {
            final String foundBasicAuthorization = headers.get(StubRequest.AUTH_HEADER);
            final String givenBasicAuthorization = assertionStubHttpLifecycle.getRequest().getHeaders().get(StubRequest.AUTH_HEADER);

            if (!foundBasicAuthorization.equals(givenBasicAuthorization)) {
               return new UnauthorizedStubResponse();
            }
         }

         if (foundStubHttpLifecycle.getResponse().getHeaders().containsKey("location")) {
            final RedirectStubResponse redirectStubResponse = new RedirectStubResponse();

            redirectStubResponse.setLatency(foundStubHttpLifecycle.getResponse().getLatency());
            redirectStubResponse.setBody(foundStubHttpLifecycle.getResponse().getBody());
            redirectStubResponse.setStatus(foundStubHttpLifecycle.getResponse().getStatus());
            redirectStubResponse.setHeaders(foundStubHttpLifecycle.getResponse().getHeaders());

            return redirectStubResponse;
         }

         return foundStubHttpLifecycle.getResponse();
      }

      return new NotFoundStubResponse();
   }
View Full Code Here

      for (final Object rawParentNode : loadedYamlData) {

         final LinkedHashMap<String, LinkedHashMap> parentNode = (LinkedHashMap<String, LinkedHashMap>) rawParentNode;

         final StubHttpLifecycle parentStub = new StubHttpLifecycle(new StubRequest(), new StubResponse());
         httpLifecycles.add(parentStub);

         mapParentYamlNodeToPojo(parentStub, parentNode);

         final String method = parentStub.getRequest().getMethod();
         final String url = parentStub.getRequest().getUrl();
         final String loadedMsg = String.format("Loaded: %s %s", method, url);
         ANSITerminal.loaded(loadedMsg);
      }

      return httpLifecycles;
View Full Code Here

      final List<StubHttpLifecycle> httpLifecycles = new LinkedList<StubHttpLifecycle>();
      for (final Object rawParentNode : loadedYamlData) {

         final Map<String, Object> parentNodePropertiesMap = (Map<String, Object>) rawParentNode;
         final StubHttpLifecycle stubHttpLifecycle = unmarshallYamlNodeToHttpLifeCycle(parentNodePropertiesMap);
         httpLifecycles.add(stubHttpLifecycle);
         stubHttpLifecycle.setResourceId(httpLifecycles.size() - 1);
      }

      return httpLifecycles;
   }
View Full Code Here

   }


   private StubHttpLifecycle unmarshallYamlNodeToHttpLifeCycle(final Map<String, Object> parentNodesMap) throws Exception {

      final StubHttpLifecycle httpLifecycle = new StubHttpLifecycle();

      for (final Map.Entry<String, Object> parentNode : parentNodesMap.entrySet()) {

         final Object parentNodeValue = parentNode.getValue();

         if (parentNodeValue instanceof Map) {
            handleMapNode(httpLifecycle, parentNode);

         } else if (parentNodeValue instanceof List) {
            handleListNode(httpLifecycle, parentNode);
         }
      }

      httpLifecycle.setMarshalledYaml(marshallNodeMapToYamlSnippet(parentNodesMap));

      return httpLifecycle;
   }
View Full Code Here

      this.stubHttpLifecycles = Collections.synchronizedList(stubHttpLifecycles);
      this.stubbyHttpTransport = new StubbyHttpTransport();
   }

   public StubResponse findStubResponseFor(final StubRequest assertingRequest) {
      final StubHttpLifecycle assertingLifecycle = new StubHttpLifecycle();
      assertingLifecycle.setRequest(assertingRequest);
      assertingLifecycle.setResponse(StubResponse.newStubResponse());

      return identifyStubResponseType(assertingLifecycle);
   }
View Full Code Here

      return identifyStubResponseType(assertingLifecycle);
   }

   private StubResponse identifyStubResponseType(final StubHttpLifecycle assertingLifecycle) {

      final StubHttpLifecycle matchedLifecycle = getMatchedStubHttpLifecycle(assertingLifecycle);
      if (ObjectUtils.isNull(matchedLifecycle)) {
         return new NotFoundStubResponse();
      }

      final StubResponse stubResponse = matchedLifecycle.getResponse();
      if (matchedLifecycle.isRestricted() && matchedLifecycle.hasNotAuthorized(assertingLifecycle)) {
         return new UnauthorizedStubResponse();
      }

      if (stubResponse.hasHeaderLocation()) {
         return RedirectStubResponse.newRedirectStubResponse(stubResponse);
View Full Code Here

TOP

Related Classes of by.stub.yaml.stubs.StubHttpLifecycle

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.