LCOV - code coverage report
Current view: top level - shared_model/validators - blocks_query_validator.hpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 13 13 100.0 %
Date: 2018-12-05 17:11:35 Functions: 9 10 90.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #ifndef IROHA_SHARED_MODEL_BLOCKS_QUERY_VALIDATOR_HPP
       7             : #define IROHA_SHARED_MODEL_BLOCKS_QUERY_VALIDATOR_HPP
       8             : 
       9             : #include "interfaces/queries/blocks_query.hpp"
      10             : #include "validators/answer.hpp"
      11             : 
      12             : namespace shared_model {
      13             :   namespace validation {
      14             :     /**
      15             :      * Class that validates blocks query field from query
      16             :      * @tparam FieldValidator - field validator type
      17             :      */
      18             :     template <typename FieldValidator>
      19             :     class BlocksQueryValidator {
      20             :      public:
      21             :       BlocksQueryValidator(
      22             :           const FieldValidator &field_validator = FieldValidator())
      23           4 :           : field_validator_(field_validator) {}
      24             : 
      25             :       /**
      26             :        * Applies validation to given query
      27             :        * @param qry - query to validate
      28             :        * @return Answer containing found error if any
      29             :        */
      30             :       Answer validate(const interface::BlocksQuery &qry) const {
      31           4 :         Answer answer;
      32           4 :         std::string qry_reason_name = "Blocks query";
      33           4 :         ReasonsGroupType qry_reason(qry_reason_name, GroupedReasons());
      34             : 
      35           4 :         field_validator_.validateCreatorAccountId(qry_reason,
      36           4 :                                                   qry.creatorAccountId());
      37           4 :         field_validator_.validateCreatedTime(qry_reason, qry.createdTime());
      38           4 :         field_validator_.validateCounter(qry_reason, qry.queryCounter());
      39             : 
      40           4 :         if (not qry_reason.second.empty()) {
      41           1 :           answer.addReason(std::move(qry_reason));
      42           1 :         }
      43           4 :         return answer;
      44           4 :       }
      45             : 
      46             :      protected:
      47             :       Answer answer_;
      48             :       FieldValidator field_validator_;
      49             :     };
      50             :   }  // namespace validation
      51             : }  // namespace shared_model
      52             : 
      53             : #endif  // IROHA_SHARED_MODEL_BLOCKS_QUERY_VALIDATOR_HPP

Generated by: LCOV version 1.13