LCOV - code coverage report
Current view: top level - model - AdminData.hpp (source / functions) Coverage Total Hit
Test: final-coverage.info Lines: 79.3 % 29 23
Test Date: 2025-02-14 17:40:40 Functions: 80.0 % 15 12

            Line data    Source code
       1              : /*
       2              :  ___________________________________________
       3              : |    _     ___                        _     |
       4              : |   | |   |__ \                      | |    |
       5              : |   | |__    ) |__ _  __ _  ___ _ __ | |_   |
       6              : |   | '_ \  / // _` |/ _` |/ _ \ '_ \| __|  |  HTTP/2 AGENT FOR MOCK TESTING
       7              : |   | | | |/ /| (_| | (_| |  __/ | | | |_   |  Version 0.0.z
       8              : |   |_| |_|____\__,_|\__, |\___|_| |_|\__|  |  https://github.com/testillano/h2agent
       9              : |                     __/ |                 |
      10              : |                    |___/                  |
      11              : |___________________________________________|
      12              : 
      13              : Licensed under the MIT License <http://opensource.org/licenses/MIT>.
      14              : SPDX-License-Identifier: MIT
      15              : Copyright (c) 2021 Eduardo Ramos
      16              : 
      17              : Permission is hereby  granted, free of charge, to any  person obtaining a copy
      18              : of this software and associated  documentation files (the "Software"), to deal
      19              : in the Software  without restriction, including without  limitation the rights
      20              : to  use, copy,  modify, merge,  publish, distribute,  sublicense, and/or  sell
      21              : copies  of  the Software,  and  to  permit persons  to  whom  the Software  is
      22              : furnished to do so, subject to the following conditions:
      23              : 
      24              : The above copyright notice and this permission notice shall be included in all
      25              : copies or substantial portions of the Software.
      26              : 
      27              : THE SOFTWARE  IS PROVIDED "AS  IS", WITHOUT WARRANTY  OF ANY KIND,  EXPRESS OR
      28              : IMPLIED,  INCLUDING BUT  NOT  LIMITED TO  THE  WARRANTIES OF  MERCHANTABILITY,
      29              : FITNESS FOR  A PARTICULAR PURPOSE AND  NONINFRINGEMENT. IN NO EVENT  SHALL THE
      30              : AUTHORS  OR COPYRIGHT  HOLDERS  BE  LIABLE FOR  ANY  CLAIM,  DAMAGES OR  OTHER
      31              : LIABILITY, WHETHER IN AN ACTION OF  CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      32              : OUT OF OR IN CONNECTION WITH THE SOFTWARE  OR THE USE OR OTHER DEALINGS IN THE
      33              : SOFTWARE.
      34              : */
      35              : 
      36              : #pragma once
      37              : 
      38              : //#include <string>
      39              : #include <mutex>
      40              : #include <shared_mutex>
      41              : 
      42              : #include <nlohmann/json.hpp>
      43              : 
      44              : #include <AdminServerMatchingData.hpp>
      45              : #include <AdminServerProvisionData.hpp>
      46              : #include <AdminClientEndpointData.hpp>
      47              : #include <AdminClientProvisionData.hpp>
      48              : #include <AdminSchemaData.hpp>
      49              : #include <common.hpp>
      50              : 
      51              : namespace h2agent
      52              : {
      53              : namespace model
      54              : {
      55              : 
      56              : class AdminData
      57              : {
      58              :     AdminServerMatchingData server_matching_data_{};
      59              :     AdminServerProvisionData server_provision_data_{};
      60              :     AdminClientEndpointData client_endpoint_data_{};
      61              :     AdminClientProvisionData client_provision_data_{};
      62              :     AdminSchemaData schema_data_{};
      63              : 
      64              : public:
      65              : 
      66              :     /** Empty constructor */
      67          173 :     AdminData() {;}
      68              : 
      69              :     /**
      70              :      * Loads admin matching operation data
      71              :      *
      72              :      * @param j json document from operation body request
      73              :      *
      74              :      * @return Boolean about success operation
      75              :      */
      76          142 :     AdminServerMatchingData::LoadResult loadServerMatching(const nlohmann::json &j) {
      77          142 :         return server_matching_data_.load(j);
      78              :     }
      79              : 
      80              :     /**
      81              :      * Loads admin server provision operation data
      82              :      *
      83              :      * @param j json document from operation body request
      84              :      * @param cr common resources references (general configuration, global variables, file manager, mock server events data)
      85              :      *
      86              :      * @return Boolean about success operation
      87              :      */
      88          123 :     AdminServerProvisionData::LoadResult loadServerProvision(const nlohmann::json &j, const common_resources_t &cr) {
      89          123 :         return server_provision_data_.load(j, (server_matching_data_.getAlgorithm() == AdminServerMatchingData::AlgorithmType::RegexMatching), cr);
      90              :     }
      91              : 
      92              :     /**
      93              :      * Loads admin client endpoint operation data
      94              :      *
      95              :      * @param j json document from operation body request
      96              :      * @param cr common resources references (general configuration, global variables, file manager, mock client events data)
      97              :      *
      98              :      * @return Boolean about success operation
      99              :      */
     100           20 :     AdminClientEndpointData::LoadResult loadClientEndpoint(const nlohmann::json &j, const common_resources_t &cr) {
     101           20 :         return client_endpoint_data_.load(j, cr);
     102              :     }
     103              : 
     104              :     /**
     105              :      * Loads admin client provision operation data
     106              :      *
     107              :      * @param j json document from operation body request
     108              :      * @param cr common resources references (general configuration, global variables, file manager, mock client events data)
     109              :      *
     110              :      * @return Boolean about success operation
     111              :      */
     112            0 :     AdminClientProvisionData::LoadResult loadClientProvision(const nlohmann::json &j, const common_resources_t &cr) {
     113            0 :         return client_provision_data_.load(j, cr);
     114              :     }
     115              : 
     116              :     /**
     117              :      * Loads admin schema operation data
     118              :      *
     119              :      * @param j json document from operation body request
     120              :      *
     121              :      * @return Boolean about success operation
     122              :      */
     123          336 :     AdminSchemaData::LoadResult loadSchema(const nlohmann::json &j) {
     124          336 :         return schema_data_.load(j);
     125              :     }
     126              : 
     127              :     /**
     128              :      * Clears admin server provisions data
     129              :      *
     130              :      * @return True if something was removed, false if already empty
     131              :      */
     132           10 :     bool clearServerProvisions() {
     133           10 :         return server_provision_data_.clear();
     134              :     }
     135              : 
     136              :     /**
     137              :      * Clears admin client endpoints data
     138              :      *
     139              :      * @return True if something was removed, false if already empty
     140              :      */
     141            9 :     bool clearClientEndpoints() {
     142            9 :         return client_endpoint_data_.clear();
     143              :     }
     144              : 
     145              :     /**
     146              :      * Clears admin client provisions data
     147              :      *
     148              :      * @return True if something was removed, false if already empty
     149              :      */
     150            0 :     bool clearClientProvisions() {
     151            0 :         return client_provision_data_.clear();
     152              :     }
     153              : 
     154              :     /**
     155              :      * Clears admin schemas data
     156              :      *
     157              :      * @return True if something was removed, false if already empty
     158              :      */
     159            5 :     bool clearSchemas() {
     160            5 :         return schema_data_.clear();
     161              :     }
     162              : 
     163              :     /**
     164              :      * Gets admin matching data
     165              :      */
     166           51 :     const AdminServerMatchingData& getServerMatchingData() const {
     167           51 :         return server_matching_data_;
     168              :     }
     169              : 
     170              :     /**
     171              :      * Gets admin server provision data
     172              :      */
     173          334 :     const AdminServerProvisionData& getServerProvisionData() const {
     174          334 :         return server_provision_data_;
     175              :     }
     176              : 
     177              :     /**
     178              :      * Gets admin client endpoint data
     179              :      */
     180            6 :     const AdminClientEndpointData& getClientEndpointData() const {
     181            6 :         return client_endpoint_data_;
     182              :     }
     183              : 
     184              :     /**
     185              :      * Gets admin client provision data
     186              :      */
     187            0 :     const AdminClientProvisionData& getClientProvisionData() const {
     188            0 :         return client_provision_data_;
     189              :     }
     190              : 
     191              :     /**
     192              :      * Gets admin schema data
     193              :      */
     194           31 :     const AdminSchemaData& getSchemaData() const {
     195           31 :         return schema_data_;
     196              :     }
     197              : };
     198              : 
     199              : }
     200              : }
     201              : 
        

Generated by: LCOV version 2.0-1