Package by.stub.yaml.stubs

Examples of by.stub.yaml.stubs.StubHttpLifecycle


         .newStubbedResponse()
         .withStatus(expectedStatus)
         .build();

      final List<StubHttpLifecycle> loadedHttpCycles = unmarshall(yaml);
      final StubHttpLifecycle actualHttpLifecycle = loadedHttpCycles.get(0);
      final StubResponse actualResponse = actualHttpLifecycle.getResponse(true);

      assertThat(actualHttpLifecycle.getAllResponses()).hasSize(1);
      assertThat(actualResponse.getStatus()).isEqualTo(expectedStatus);
   }
View Full Code Here


         .withSequenceResponseHeaders(sequenceResponseHeaderKey, sequenceResponseHeaderValue)
         .withSequenceResponseLiteralBody(sequenceResponseBody)
         .build();

      final List<StubHttpLifecycle> loadedHttpCycles = unmarshall(yaml);
      final StubHttpLifecycle actualHttpLifecycle = loadedHttpCycles.get(0);
      final StubResponse actualResponse = actualHttpLifecycle.getResponse(true);

      final MapEntry sequenceHeaderEntry = MapEntry.entry(sequenceResponseHeaderKey, sequenceResponseHeaderValue);

      assertThat(actualResponse).isInstanceOf(StubResponse.class);
      assertThat(actualResponse.getHeaders()).contains(sequenceHeaderEntry);
View Full Code Here

      builder.append(buildStubbyParametersHtmlTable());
      builder.append(buildEndpointStatsHtmlTable());

      final List<StubHttpLifecycle> stubHttpLifecycles = stubbedDataManager.getStubHttpLifecycles();
      for (int cycleIndex = 0; cycleIndex < stubHttpLifecycles.size(); cycleIndex++) {
         final StubHttpLifecycle stubHttpLifecycle = stubHttpLifecycles.get(cycleIndex);
         builder.append(buildStubRequestHtmlTable(stubHttpLifecycle));
         builder.append(buildStubResponseHtmlTable(stubHttpLifecycle));
         builder.append("<br /><br />");
      }
View Full Code Here

      this.stubbyHttpTransport = new StubbyHttpTransport();
      this.resourceStats = new ConcurrentHashMap<String, AtomicLong>();
   }

   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 String resourceId = matchedLifecycle.getResourceId();
      resourceStats.putIfAbsent(resourceId, new AtomicLong(0));
      resourceStats.get(resourceId).incrementAndGet();

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

      if (stubResponse.hasHeaderLocation()) {
         return RedirectStubResponse.newRedirectStubResponse(stubResponse);
      }

      if (stubResponse.isRecordingRequired()) {
         final String recordingSource = stubResponse.getBody();
         try {
            final StubbyResponse stubbyResponse = stubbyHttpTransport.fetchRecordableHTTPResponse(matchedLifecycle.getRequest(), recordingSource);
            ReflectionUtils.injectObjectFields(stubResponse, YamlProperties.BODY, stubbyResponse.getContent());
         } catch (Exception e) {
            ANSITerminal.error(String.format("Could not record from %s: %s", recordingSource, e.toString()));
         }
      }
View Full Code Here

   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

      final String stubType = uriFragments[urlFragmentsLength - 2];

      if (REGEX_NUMERIC.matcher(stubType).matches()) {
         final int sequencedResponseId = Integer.parseInt(stubType);
         final int stubHttpCycleIndex = Integer.parseInt(uriFragments[urlFragmentsLength - 4]);
         final StubHttpLifecycle foundStubHttpLifecycle = throwErrorOnNonexistentResourceIndex(wrapper, stubHttpCycleIndex);
         renderAjaxResponseContent(wrapper, sequencedResponseId, targetFieldName, foundStubHttpLifecycle);
      } else {

         final int stubHttpCycleIndex = Integer.parseInt(uriFragments[urlFragmentsLength - 3]);
         final StubHttpLifecycle foundStubHttpLifecycle = throwErrorOnNonexistentResourceIndex(wrapper, stubHttpCycleIndex);
         if (REGEX_REQUEST.matcher(stubType).matches()) {
            renderAjaxResponseContent(wrapper, StubTypes.REQUEST, targetFieldName, foundStubHttpLifecycle);
         } else if (REGEX_RESPONSE.matcher(stubType).matches()) {
            renderAjaxResponseContent(wrapper, StubTypes.RESPONSE, targetFieldName, foundStubHttpLifecycle);
         } else if (REGEX_HTTPLIFECYCLE.matcher(stubType).matches()) {
View Full Code Here

      }
   }

   @VisibleForTesting
   StubHttpLifecycle throwErrorOnNonexistentResourceIndex(final HttpServletResponseWithGetStatus wrapper, final int stubHttpCycleIndex) throws IOException {
      final StubHttpLifecycle foundStubHttpLifecycle = stubbedDataManager.getMatchedStubHttpLifecycle(stubHttpCycleIndex);
      if (ObjectUtils.isNull(foundStubHttpLifecycle)) {
         wrapper.getWriter().println("Resource does not exist for ID: " + stubHttpCycleIndex);
      }
      return foundStubHttpLifecycle;
   }
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.