* limitations under the License.
*/
/*
- * @file StorageDeserializer.cpp
+ * @file BucketDeserializer.cpp
* @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
* @version 1.0
- * @brief Methods implementation of Cynara::StorageDeserializer
+ * @brief Methods implementation of Cynara::BucketDeserializer
*/
#include <exceptions/BucketRecordCorruptedException.h>
-#include <storage/StorageDeserializer.h>
+#include <storage/BucketDeserializer.h>
#include <storage/StorageSerializer.h>
#include <types/Policy.h>
namespace Cynara {
-PolicyCollection StorageDeserializer::loadPolicies(std::istream &is) {
+PolicyCollection BucketDeserializer::loadPolicies(std::istream &is) {
PolicyCollection policies;
// TODO: Get someone smart to do error checking on stream
return policies;
}
-PolicyKey StorageDeserializer::parseKey(const std::string &line, std::size_t &beginToken) {
+PolicyKey BucketDeserializer::parseKey(const std::string &line, std::size_t &beginToken) {
std::array<std::string, 3> keyFeatures;
for(std::size_t tokenNum = 0; tokenNum < keyFeatures.size(); ++tokenNum) {
return PolicyKey(keyFeatures[0], keyFeatures[1], keyFeatures[2]);
}
-PolicyType StorageDeserializer::parsePolicyType(const std::string &line, std::size_t &beginToken) {
+PolicyType BucketDeserializer::parsePolicyType(const std::string &line, std::size_t &beginToken) {
PolicyType policyType;
try {
size_t newBegin = 0;
return policyType;
}
-PolicyResult::PolicyMetadata StorageDeserializer::parseMetadata(const std::string &line,
+PolicyResult::PolicyMetadata BucketDeserializer::parseMetadata(const std::string &line,
std::size_t &beginToken) {
if (beginToken < line.size()) {
auto ret = line.substr(beginToken + 1);
* @file load.cpp
* @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
* @version 1.0
- * @brief Tests for Cynara::StorageDeserializer
+ * @brief Tests for Cynara::BucketDeserializer
*/
#include <gtest/gtest.h>
#include <exceptions/BucketRecordCorruptedException.h>
-#include <service/storage/StorageDeserializer.h>
+#include <service/storage/BucketDeserializer.h>
#include <types/Policy.h>
#include "../../helpers.h"
== std::tie(arg->key(), arg->result());
}
-class DeserializerFixture : public ::testing::Test {
+class BucketDeserializerFixture : public ::testing::Test {
public:
- virtual ~DeserializerFixture() = default;
+ virtual ~BucketDeserializerFixture() = default;
PolicyPtr createPolicy(const PolicyKey &pk, const PolicyResult &pr) {
return std::make_shared<Policy>(pk, pr);
void checkCorruptedData(const std::string &data, const std::string &corruptedLine,
size_t corruptedLineNumber) {
std::istringstream ss(data);
- EXPECT_THROW(StorageDeserializer::loadPolicies(ss), BucketRecordCorruptedException);
+ EXPECT_THROW(BucketDeserializer::loadPolicies(ss), BucketRecordCorruptedException);
ss.seekg(0);
try {
- StorageDeserializer::loadPolicies(ss);
+ BucketDeserializer::loadPolicies(ss);
} catch (const BucketRecordCorruptedException &ex) {
ASSERT_EQ(corruptedLine, ex.line());
ASSERT_EQ(corruptedLineNumber, ex.lineNumber());
}
};
-TEST_F(DeserializerFixture, load_empty) {
+TEST_F(BucketDeserializerFixture, load_empty) {
using ::testing::IsEmpty;
std::istringstream ss;
- auto policies = StorageDeserializer::loadPolicies(ss);
+ auto policies = BucketDeserializer::loadPolicies(ss);
ASSERT_THAT(policies, IsEmpty());
}
-TEST_F(DeserializerFixture, load_1) {
+TEST_F(BucketDeserializerFixture, load_1) {
using ::testing::UnorderedElementsAre;
std::istringstream ss("c;u;p;0;meta");
- auto policies = StorageDeserializer::loadPolicies(ss);
+ auto policies = BucketDeserializer::loadPolicies(ss);
auto expectedPolicy = createPolicy({ "c", "u", "p" }, { PredefinedPolicyType::DENY, "meta" });
ASSERT_THAT(policies, UnorderedElementsAre(PolicyPtrEq(expectedPolicy)));
}
-TEST_F(DeserializerFixture, load_1_allow) {
+TEST_F(BucketDeserializerFixture, load_1_allow) {
using ::testing::UnorderedElementsAre;
std::istringstream ss("c;u;p;0xFFFF;meta");
- auto policies = StorageDeserializer::loadPolicies(ss);
+ auto policies = BucketDeserializer::loadPolicies(ss);
auto expectedPolicy = createPolicy({ "c", "u", "p" }, { PredefinedPolicyType::ALLOW, "meta" });
ASSERT_THAT(policies, UnorderedElementsAre(PolicyPtrEq(expectedPolicy)));
}
-TEST_F(DeserializerFixture, load_1_no_meta_sep) {
+TEST_F(BucketDeserializerFixture, load_1_no_meta_sep) {
using ::testing::UnorderedElementsAre;
std::istringstream ss("c;u;p;0;");
- auto policies = StorageDeserializer::loadPolicies(ss);
+ auto policies = BucketDeserializer::loadPolicies(ss);
auto expectedPolicy = createPolicy({ "c", "u", "p" }, { PredefinedPolicyType::DENY, "" });
ASSERT_THAT(policies, UnorderedElementsAre(PolicyPtrEq(expectedPolicy)));
}
-TEST_F(DeserializerFixture, load_1_no_meta_no_sep) {
+TEST_F(BucketDeserializerFixture, load_1_no_meta_no_sep) {
using ::testing::UnorderedElementsAre;
std::istringstream ss("c;u;p;0");
- auto policies = StorageDeserializer::loadPolicies(ss);
+ auto policies = BucketDeserializer::loadPolicies(ss);
auto expectedPolicy = createPolicy({ "c", "u", "p" }, { PredefinedPolicyType::DENY, "" });
ASSERT_THAT(policies, UnorderedElementsAre(PolicyPtrEq(expectedPolicy)));
}
-TEST_F(DeserializerFixture, load_2) {
+TEST_F(BucketDeserializerFixture, load_2) {
using ::testing::UnorderedElementsAre;
std::istringstream ss("c;u;p;0;meta\n"
"c;u;p;0;meta\n");
- auto policies = StorageDeserializer::loadPolicies(ss);
+ auto policies = BucketDeserializer::loadPolicies(ss);
auto expectedPolicy = createPolicy({ "c", "u", "p" }, { PredefinedPolicyType::DENY, "meta" });
ASSERT_THAT(policies, UnorderedElementsAre(PolicyPtrEq(expectedPolicy),
PolicyPtrEq(expectedPolicy)));
}
-TEST_F(DeserializerFixture, load_mixed) {
+TEST_F(BucketDeserializerFixture, load_mixed) {
using ::testing::UnorderedElementsAre;
using ::testing::UnorderedElementsAreArray;
"c2;u2;p2;0xFFFF;\n"
"c1;u1;p3;0xFFFE;bucket\n");
- auto policies = StorageDeserializer::loadPolicies(ss);
+ auto policies = BucketDeserializer::loadPolicies(ss);
PolicyCollection expectedPolices = {
createPolicy({ "c1", "u1", "p1" }, { PredefinedPolicyType::DENY, "meta" }),
createPolicy({ "c2", "u2", "p2" }, { PredefinedPolicyType::ALLOW, "meta2" }),
));
}
-TEST_F(DeserializerFixture, load_no_client) {
+TEST_F(BucketDeserializerFixture, load_no_client) {
auto data = "u;p;0;meta";
checkCorruptedData(data, data, 1);
}
-TEST_F(DeserializerFixture, load_no_type) {
+TEST_F(BucketDeserializerFixture, load_no_type) {
auto data = "c;u;p;meta";
checkCorruptedData(data, data, 1);
}
-TEST_F(DeserializerFixture, load_all_missing) {
+TEST_F(BucketDeserializerFixture, load_all_missing) {
auto data = ";;;";
checkCorruptedData(data, data, 1);
}
-TEST_F(DeserializerFixture, load_invalid_type) {
+TEST_F(BucketDeserializerFixture, load_invalid_type) {
auto data = "c;u;p;X";
checkCorruptedData(data, data, 1);
}
-TEST_F(DeserializerFixture, load_invalid_multiline) {
+TEST_F(BucketDeserializerFixture, load_invalid_multiline) {
auto data = "c1;u1;p1;0;meta\n"
"c;u;p;X\n"
"c1;u1;p1;0;meta\n";