//# 0 errors, 57 messages
//#
/*
    //#simplemathsconfirmationstrategy.java:1:1: class: net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy
    //#simplemathsconfirmationstrategy.java:1:1: method: net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy.net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init
 * Copyright (c) 2003-2006, Simon Brown
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   - Neither the name of Pebble nor the names of its contributors may
 *     be used to endorse or promote products derived from this software
 *     without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package net.sourceforge.pebble.confirmation;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.Random;

/**
 * Simple maths confirmation strategy that asks the user to add/subtract/multiply
 * two random numbers together.
 *
 * @author    Simon Brown
 */
public class SimpleMathsConfirmationStrategy extends AbstractConfirmationStrategy {
    //#simplemathsconfirmationstrategy.java:44: method: void net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy.net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy()
    //#input(void net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy()): this
    //#simplemathsconfirmationstrategy.java:44: end of method: void net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy.net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy()

  private static final String ARGUMENT1 = "SimpleMathsConfirmationStrategyArg1";
  private static final String ARGUMENT2 = "SimpleMathsConfirmationStrategyArg2";
  private static final String OPERATOR = "SimpleMathsConfirmationStrategyOperator";
  private static final String ANSWER = "SimpleMathsConfirmationStrategyAnswer";

  /**
   * Called before showing the confirmation page.
   *
   * @param request the HttpServletRequest used in the confirmation
   */
  public void setupConfirmation(HttpServletRequest request) {
    Random r = new Random();
    //#simplemathsconfirmationstrategy.java:57: method: void net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy.setupConfirmation(HttpServletRequest)
    //#input(void setupConfirmation(HttpServletRequest)): request
    //#pre[1] (void setupConfirmation(HttpServletRequest)): request != null
    //#presumption(void setupConfirmation(HttpServletRequest)): (java.util.Random:nextInt(...)@58 + 1)*(java.util.Random:nextInt(...)@59 + 1) in -2_147_483_648..4_294_967_295
    //#presumption(void setupConfirmation(HttpServletRequest)): java.util.Random:nextInt(...)@58 <= 4_294_967_294
    //#presumption(void setupConfirmation(HttpServletRequest)): java.util.Random:nextInt(...)@58 + java.util.Random:nextInt(...)@59 in -2_147_483_650..4_294_967_293
    //#presumption(void setupConfirmation(HttpServletRequest)): java.util.Random:nextInt(...)@59 <= 4_294_967_294
    //#presumption(void setupConfirmation(HttpServletRequest)): java.util.Random:nextInt(...)@59 - java.util.Random:nextInt(...)@58 in -4_294_967_295..2_147_483_648
    //#presumption(void setupConfirmation(HttpServletRequest)): javax.servlet.http.HttpServletRequest:getSession(...)@61 != null
    //#presumption(void setupConfirmation(HttpServletRequest)): javax.servlet.http.HttpServletRequest:getSession(...)@62 != null
    //#presumption(void setupConfirmation(HttpServletRequest)): javax.servlet.http.HttpServletRequest:getSession(...)@66 != null
    //#presumption(void setupConfirmation(HttpServletRequest)): javax.servlet.http.HttpServletRequest:getSession(...)@67 != null
    //#presumption(void setupConfirmation(HttpServletRequest)): javax.servlet.http.HttpServletRequest:getSession(...)@70 != null
    //#presumption(void setupConfirmation(HttpServletRequest)): javax.servlet.http.HttpServletRequest:getSession(...)@71 != null
    //#presumption(void setupConfirmation(HttpServletRequest)): javax.servlet.http.HttpServletRequest:getSession(...)@74 != null
    //#presumption(void setupConfirmation(HttpServletRequest)): javax.servlet.http.HttpServletRequest:getSession(...)@75 != null
    //#test_vector(void setupConfirmation(HttpServletRequest)): java.util.Random:nextInt(...)@60: {0}, {1}, {2}, {-2_147_483_648..-1, 3..4_294_967_295}
    int arg1 = r.nextInt(10) + 1;
    int arg2 = r.nextInt(10) + 1;
    int op = r.nextInt(3);
    ((ServletRequest) request.getSession()).setAttribute(ARGUMENT1, arg1);
    ((ServletRequest) request.getSession()).setAttribute(ARGUMENT2, arg2);

    switch (op) {
      case 0 :
        ((ServletRequest) request.getSession()).setAttribute(OPERATOR, "+");
        ((ServletRequest) request.getSession()).setAttribute(ANSWER, arg1 + arg2);
        break;
      case 1 :
        ((ServletRequest) request.getSession()).setAttribute(OPERATOR, "-");
        ((ServletRequest) request.getSession()).setAttribute(ANSWER, arg1 - arg2);
        break;
      case 2 :
        ((ServletRequest) request.getSession()).setAttribute(OPERATOR, "*");
        ((ServletRequest) request.getSession()).setAttribute(ANSWER, arg1 * arg2);
        break;
    }
  }
    //#simplemathsconfirmationstrategy.java:78: end of method: void net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy.setupConfirmation(HttpServletRequest)

  /**
   * Gets the URI of the confirmation page.
   *
   * @return a URI, relative to the web application root.
   */
  public String getUri() {
    return "/WEB-INF/jsp/confirmation/maths.jsp";
    //#simplemathsconfirmationstrategy.java:86: method: String net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy.getUri()
    //#output(String getUri()): return_value
    //#post(String getUri()): return_value == &".WEB-INF.jsp.confirmation.maths.jsp"
    //#simplemathsconfirmationstrategy.java:86: end of method: String net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy.getUri()
  }

  /**
   * Called to determine whether confirmation was successful.
   *
   * @param request   the HttpServletRequest used in the confirmation
   * @return  true if the confirmation was successful, false otherwise
   */
  public boolean isConfirmed(HttpServletRequest request) {
    Integer answer = (Integer)((ServletRequest) request.getSession()).getAttribute(ANSWER);
    //#simplemathsconfirmationstrategy.java:96: method: bool net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy.isConfirmed(HttpServletRequest)
    //#input(bool isConfirmed(HttpServletRequest)): request
    //#output(bool isConfirmed(HttpServletRequest)): return_value
    //#pre[1] (bool isConfirmed(HttpServletRequest)): request != null
    //#presumption(bool isConfirmed(HttpServletRequest)): javax.servlet.ServletRequest:getAttribute(...)@96 != null
    //#presumption(bool isConfirmed(HttpServletRequest)): javax.servlet.http.HttpServletRequest:getSession(...)@96 != null
    //#post(bool isConfirmed(HttpServletRequest)): init'ed(return_value)
    String userAnswer = request.getParameter("answer");

    return answer.toString().equals(userAnswer);
    //#simplemathsconfirmationstrategy.java:99: end of method: bool net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy.isConfirmed(HttpServletRequest)
  }

}    //#output(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): __Descendant_Table[net/sourceforge/pebble/confirmation/SimpleMathsConfirmationStrategy]
    //#output(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): __Dispatch_Table.confirmationRequired(Lnet/sourceforge/pebble/domain/Blog;)Z
    //#output(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): __Dispatch_Table.confirmationRequired(Lnet/sourceforge/pebble/domain/Comment;)Z
    //#output(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): __Dispatch_Table.getUri()Ljava/lang/String;
    //#output(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): __Dispatch_Table.isConfirmed(Ljavax/servlet/http/HttpServletRequest;)Z
    //#output(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): __Dispatch_Table.setupConfirmation(Ljavax/servlet/http/HttpServletRequest;)V
    //#output(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): net/sourceforge/pebble/api/confirmation/CommentConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/SimpleMathsConfirmationStrategy]
    //#output(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): net/sourceforge/pebble/api/confirmation/ConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/SimpleMathsConfirmationStrategy]
    //#output(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): net/sourceforge/pebble/api/confirmation/TrackBackConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/SimpleMathsConfirmationStrategy]
    //#output(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): net/sourceforge/pebble/confirmation/AbstractConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/SimpleMathsConfirmationStrategy]
    //#post(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): __Descendant_Table[net/sourceforge/pebble/confirmation/SimpleMathsConfirmationStrategy] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): net/sourceforge/pebble/api/confirmation/CommentConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/SimpleMathsConfirmationStrategy] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): net/sourceforge/pebble/api/confirmation/ConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/SimpleMathsConfirmationStrategy] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): net/sourceforge/pebble/api/confirmation/TrackBackConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/SimpleMathsConfirmationStrategy] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): net/sourceforge/pebble/confirmation/AbstractConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/SimpleMathsConfirmationStrategy] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): __Dispatch_Table.confirmationRequired(Lnet/sourceforge/pebble/domain/Blog;)Z == &net/sourceforge/pebble/confirmation/AbstractConfirmationStrategy.confirmationRequired
    //#post(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): __Dispatch_Table.confirmationRequired(Lnet/sourceforge/pebble/domain/Comment;)Z == &net/sourceforge/pebble/confirmation/AbstractConfirmationStrategy.confirmationRequired
    //#post(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): __Dispatch_Table.getUri()Ljava/lang/String; == &getUri
    //#post(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): __Dispatch_Table.isConfirmed(Ljavax/servlet/http/HttpServletRequest;)Z == &isConfirmed
    //#post(net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init): __Dispatch_Table.setupConfirmation(Ljavax/servlet/http/HttpServletRequest;)V == &setupConfirmation
    //#simplemathsconfirmationstrategy.java:: end of method: net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy.net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy__static_init
    //#simplemathsconfirmationstrategy.java:: end of class: net.sourceforge.pebble.confirmation.SimpleMathsConfirmationStrategy
