public class SwaggerModify_Test {

  private final SwaggerBuilder swaggerBuilder = emptyApiDefinition();
  private final SwaggerModify swaggerModify = new SwaggerModify();
  private final String path = anyPath();
  private final OperationIdentifier identifier = OperationIdentifier.Get(path);
  private final Consumer<Operation> modification =
      operation -> operation.setOperationId("someMethodName");

  @Test
  public void report_if_path_does_does_not_exist() {
    ModificationResult result = modify();

    assertThat("should not be successful, path does not exist", !result.success());
  }

  @Test
  public void apply_modification_if_operation_is_present() {
    swaggerBuilder.withPath(path).withGet();

    ModificationResult result = modify();

    assertThat("should be successful", result.success());
    assertThat(result.swagger().getPath(path).getGet().getOperationId(), is("someMethodName"));
  }

  private ModificationResult modify() {
    return swaggerModify.modify(swaggerBuilder.build(), identifier, modification);
  }
}
Exemplo n.º 2
0
 public OperationIdentifier completeCurrentOperation() {
   OperationIdentifier currentOp = currentOperationId();
   assertHierarchyNotEmpty();
   Long last = hierarchy.getLast();
   if (currentOp.getId() == last) {
     // typical scenario
     hierarchy.removeLast();
   } else {
     // this means that we're removing an operation id that has incomplete children
     // this is not strictly correct, we might fail fast here
     // however, this needs some discussion and making sure child operations are always completed
     // before the parent
     // (even in internal error conditions)
     hierarchy.remove(currentOp.getId());
   }
   id = null;
   return currentOp;
 }