Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
gberardi-pillar committed Mar 1, 2024
1 parent e8241d5 commit 813177d
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions tests/lib/ocpp/v201/test_smart_charging_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
namespace ocpp::v201 {

static const int STATION_WIDE_ID = 0;
static const int DEFAULT_EVSE_ID = 1;
static const int DEFAULT_PROFILE_ID = 1;

class ChargepointTestFixtureV201 : public ::testing::TestWithParam<std::tuple<int, int, ProfileValidationResultEnum>> {
protected:
Expand Down Expand Up @@ -136,8 +138,6 @@ class ChargepointTestFixtureV201 : public ::testing::TestWithParam<std::tuple<in
std::map<int32_t, std::unique_ptr<Evse>> evses;
std::shared_ptr<DatabaseHandler> database_handler;

const int profile_id = 1;
const int evse_id = 1;
bool ignore_no_transaction = true;
const int profile_max_stack_level = 1;
const int max_charging_profiles_installed = 1;
Expand All @@ -148,27 +148,27 @@ class ChargepointTestFixtureV201 : public ::testing::TestWithParam<std::tuple<in
};

TEST_F(ChargepointTestFixtureV201, K01FR03_IfTxProfileIsMissingTransactionId_ThenProfileIsInvalid) {
create_evse_with_id(evse_id);
create_evse_with_id(DEFAULT_EVSE_ID);
auto profile = create_tx_profile_with_missing_transaction_id(create_charge_schedule(ChargingRateUnitEnum::A));
auto sut = handler.validate_tx_profile(profile, *evses[evse_id]);
auto sut = handler.validate_tx_profile(profile, *evses[DEFAULT_EVSE_ID]);

EXPECT_THAT(sut, testing::Eq(ProfileValidationResultEnum::TxProfileMissingTransactionId));
}

TEST_F(ChargepointTestFixtureV201, K01FR16_IfTxProfileHasEvseIdNotGreaterThanZero_ThenProfileIsInvalid) {
auto wrong_evse_id = STATION_WIDE_ID;
create_evse_with_id(wrong_evse_id);
auto profile = create_charging_profile(profile_id, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), uuid());
auto profile = create_charging_profile(DEFAULT_PROFILE_ID, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), uuid());
auto sut = handler.validate_tx_profile(profile, *evses[wrong_evse_id]);

EXPECT_THAT(sut, testing::Eq(ProfileValidationResultEnum::TxProfileEvseIdNotGreaterThanZero));
}

TEST_F(ChargepointTestFixtureV201, K01FR33_IfTxProfileTransactionIsNotOnEvse_ThenProfileIsInvalid) {
create_evse_with_id(evse_id);
open_evse_transaction(evse_id, "wrong transaction id");
auto profile = create_charging_profile(profile_id, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), uuid());
auto sut = handler.validate_tx_profile(profile, *evses[evse_id]);
create_evse_with_id(DEFAULT_EVSE_ID);
open_evse_transaction(DEFAULT_EVSE_ID, "wrong transaction id");
auto profile = create_charging_profile(DEFAULT_PROFILE_ID, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), uuid());
auto sut = handler.validate_tx_profile(profile, *evses[DEFAULT_EVSE_ID]);

EXPECT_THAT(sut, testing::Eq(ProfileValidationResultEnum::TxProfileTransactionNotOnEvse));
}
Expand All @@ -178,83 +178,83 @@ TEST_F(ChargepointTestFixtureV201, K01FR09_IfTxProfileEvseHasNoActiveTransaction
auto meter_start = MeterValue();
auto id_token = IdToken();
auto date_time = ocpp::DateTime("2024-01-17T17:00:00");
create_evse_with_id(evse_id);
auto profile = create_charging_profile(profile_id, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), uuid());
auto sut = handler.validate_tx_profile(profile, *evses[evse_id]);
create_evse_with_id(DEFAULT_EVSE_ID);
auto profile = create_charging_profile(DEFAULT_PROFILE_ID, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), uuid());
auto sut = handler.validate_tx_profile(profile, *evses[DEFAULT_EVSE_ID]);

EXPECT_THAT(sut, testing::Eq(ProfileValidationResultEnum::TxProfileEvseHasNoActiveTransaction));
}

TEST_F(ChargepointTestFixtureV201,
K01FR06_IfTxProfileHasSameTransactionAndStackLevelAsAnotherTxProfile_ThenProfileIsInvalid) {
create_evse_with_id(evse_id);
create_evse_with_id(DEFAULT_EVSE_ID);
std::string transaction_id = uuid();
open_evse_transaction(evse_id, transaction_id);
open_evse_transaction(DEFAULT_EVSE_ID, transaction_id);

auto same_stack_level = 42;
auto profile_1 =
create_charging_profile(profile_id, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), transaction_id, same_stack_level);
create_charging_profile(DEFAULT_PROFILE_ID, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), transaction_id, same_stack_level);
auto profile_2 =
create_charging_profile(profile_id + 1, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), transaction_id, same_stack_level);
handler.add_profile(evse_id, profile_2);
auto sut = handler.validate_tx_profile(profile_1, *evses[evse_id]);
create_charging_profile(DEFAULT_PROFILE_ID + 1, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), transaction_id, same_stack_level);
handler.add_profile(DEFAULT_EVSE_ID, profile_2);
auto sut = handler.validate_tx_profile(profile_1, *evses[DEFAULT_EVSE_ID]);

EXPECT_THAT(sut, testing::Eq(ProfileValidationResultEnum::TxProfileConflictingStackLevel));
}

TEST_F(ChargepointTestFixtureV201,
K01FR06_IfTxProfileHasDifferentTransactionButSameStackLevelAsAnotherTxProfile_ThenProfileIsValid) {
create_evse_with_id(evse_id);
create_evse_with_id(DEFAULT_EVSE_ID);
std::string transaction_id = uuid();
std::string different_transaction_id = uuid();
open_evse_transaction(evse_id, transaction_id);
open_evse_transaction(DEFAULT_EVSE_ID, transaction_id);

auto same_stack_level = 42;
auto profile_1 =
create_charging_profile(profile_id, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), transaction_id, same_stack_level);
create_charging_profile(DEFAULT_PROFILE_ID, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), transaction_id, same_stack_level);
auto profile_2 =
create_charging_profile(profile_id + 1, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), different_transaction_id, same_stack_level);
handler.add_profile(evse_id, profile_2);
auto sut = handler.validate_tx_profile(profile_1, *evses[evse_id]);
create_charging_profile(DEFAULT_PROFILE_ID + 1, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), different_transaction_id, same_stack_level);
handler.add_profile(DEFAULT_EVSE_ID, profile_2);
auto sut = handler.validate_tx_profile(profile_1, *evses[DEFAULT_EVSE_ID]);

EXPECT_THAT(sut, testing::Eq(ProfileValidationResultEnum::Valid));
}

TEST_F(ChargepointTestFixtureV201,
K01FR06_IfTxProfileHasSameTransactionButDifferentStackLevelAsAnotherTxProfile_ThenProfileIsValid) {
create_evse_with_id(evse_id);
create_evse_with_id(DEFAULT_EVSE_ID);
std::string same_transaction_id = uuid();
open_evse_transaction(evse_id, same_transaction_id);
open_evse_transaction(DEFAULT_EVSE_ID, same_transaction_id);

auto stack_level_1 = 42;
auto stack_level_2 = 43;

auto profile_1 =
create_charging_profile(profile_id, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), same_transaction_id, stack_level_1);
create_charging_profile(DEFAULT_PROFILE_ID, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), same_transaction_id, stack_level_1);
auto profile_2 =
create_charging_profile(profile_id + 1, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), same_transaction_id, stack_level_2);
create_charging_profile(DEFAULT_PROFILE_ID + 1, ChargingProfilePurposeEnum::TxProfile, create_charge_schedule(ChargingRateUnitEnum::A), same_transaction_id, stack_level_2);

handler.add_profile(evse_id, profile_2);
auto sut = handler.validate_tx_profile(profile_1, *evses[evse_id]);
handler.add_profile(DEFAULT_EVSE_ID, profile_2);
auto sut = handler.validate_tx_profile(profile_1, *evses[DEFAULT_EVSE_ID]);

EXPECT_THAT(sut, testing::Eq(ProfileValidationResultEnum::Valid));
}

INSTANTIATE_TEST_SUITE_P(TxDefaultProfileValidationV201_Param_Test_Instantiate,
ChargepointTestFixtureV201,
testing::Values(
std::make_tuple(1, STATION_WIDE_ID, ProfileValidationResultEnum::DuplicateTxDefaultProfileFound),
std::make_tuple(STATION_WIDE_ID, 1, ProfileValidationResultEnum::DuplicateTxDefaultProfileFound),
std::make_tuple(DEFAULT_EVSE_ID, STATION_WIDE_ID, ProfileValidationResultEnum::DuplicateTxDefaultProfileFound),
std::make_tuple(STATION_WIDE_ID, DEFAULT_EVSE_ID, ProfileValidationResultEnum::DuplicateTxDefaultProfileFound),
std::make_tuple(STATION_WIDE_ID, STATION_WIDE_ID, ProfileValidationResultEnum::Valid),
std::make_tuple(1, 1, ProfileValidationResultEnum::Valid)
std::make_tuple(DEFAULT_EVSE_ID, DEFAULT_EVSE_ID, ProfileValidationResultEnum::Valid)
));

TEST_P(ChargepointTestFixtureV201, TxDefaultProfileValidationV201Tests) {
auto [existing_evse_id, added_evse_id, expected] = GetParam();
install_profile_on_evse(existing_evse_id, profile_id);
install_profile_on_evse(existing_evse_id, DEFAULT_PROFILE_ID);

create_evse_with_id(added_evse_id);
auto profile = create_charging_profile(profile_id + 1, ChargingProfilePurposeEnum::TxDefaultProfile, create_charge_schedule(ChargingRateUnitEnum::A), uuid());
auto profile = create_charging_profile(DEFAULT_PROFILE_ID + 1, ChargingProfilePurposeEnum::TxDefaultProfile, create_charge_schedule(ChargingRateUnitEnum::A), uuid());
auto sut = handler.validate_tx_default_profile(profile, *evses[added_evse_id]);

EXPECT_THAT(sut, testing::Eq(expected));
Expand All @@ -263,22 +263,22 @@ TEST_P(ChargepointTestFixtureV201, TxDefaultProfileValidationV201Tests) {
// TODO: delete me
TEST_F(ChargepointTestFixtureV201,
K01FR52_IfTxDefaultProfileWithSameStackLevelAlreadyExistsOnAnEvse_ThenProfileIsInvalid) {
install_profile_on_evse(1, profile_id);
install_profile_on_evse(1, DEFAULT_PROFILE_ID);

create_evse_with_id(STATION_WIDE_ID);
auto profile = create_charging_profile(profile_id + 1, ChargingProfilePurposeEnum::TxDefaultProfile, create_charge_schedule(ChargingRateUnitEnum::A), uuid());
auto profile = create_charging_profile(DEFAULT_PROFILE_ID + 1, ChargingProfilePurposeEnum::TxDefaultProfile, create_charge_schedule(ChargingRateUnitEnum::A), uuid());
auto sut = handler.validate_tx_default_profile(profile, *evses[STATION_WIDE_ID]);

EXPECT_THAT(sut, testing::Eq(ProfileValidationResultEnum::DuplicateTxDefaultProfileFound));
}

TEST_F(ChargepointTestFixtureV201,
K01FR53_IfEvseSpecificTxDefaultProfileWithSameStackLevelAlreadyExistsStationWide_ThenProfileIsInvalid) {
install_profile_on_evse(STATION_WIDE_ID, profile_id);
install_profile_on_evse(STATION_WIDE_ID, DEFAULT_PROFILE_ID);

create_evse_with_id(evse_id);
auto profile = create_charging_profile(profile_id + 1, ChargingProfilePurposeEnum::TxDefaultProfile, create_charge_schedule(ChargingRateUnitEnum::A), uuid());
auto sut = handler.validate_tx_default_profile(profile, *evses[evse_id]);
create_evse_with_id(DEFAULT_EVSE_ID);
auto profile = create_charging_profile(DEFAULT_PROFILE_ID + 1, ChargingProfilePurposeEnum::TxDefaultProfile, create_charge_schedule(ChargingRateUnitEnum::A), uuid());
auto sut = handler.validate_tx_default_profile(profile, *evses[DEFAULT_EVSE_ID]);

EXPECT_THAT(sut, testing::Eq(ProfileValidationResultEnum::DuplicateTxDefaultProfileFound));
}
Expand Down

0 comments on commit 813177d

Please sign in to comment.