{
Poco::JSON::Object::Ptr object = JsonFormatter::parse(crto.getData());
int id = JsonFormatter::extract<int>(object, "id");
- std::vector<gde::Attribute> attributes = JsonFormatter::extractVector(object, "attributeCollection");
+ std::vector<gde::Attribute> attributes = JsonFormatter::extractVector<gde::Attribute>(object, "attributeCollection");
return gde::AttributeGroup(id, attributes);
}
}
{
Poco::JSON::Object::Ptr object = JsonFormatter::parse(crto.getData());
int id = JsonFormatter::extract<int>(object, "id");
- std::vector<Attribute> attributes = JsonFormatter::extractVector(object, "attributeCollection");
+ std::vector<Attribute> attributes = JsonFormatter::extractVector<gde::Attribute>(object, "attributeCollection");
return gde::AttributeGroup(id, attributes);
}
}
{
Poco::JSON::Object::Ptr object = JsonFormatter::parse(crto.getData());
int id = JsonFormatter::extract<int>(object, "id");
- std::vector<Attribute> attributes = JsonFormatter::extractVector(object, "attributeCollection");
+ std::vector<Attribute> attributes = JsonFormatter::extractVector<gde::Attribute>(object, "attributeCollection");
return gde::AttributeGroup(id, attributes);
}
}
Group.hpp
HttpConnection.hpp
JsonFormatter.hpp
+ Profile.hpp
+ ProfileAttribute.hpp
Study.hpp
StudyService.hpp
User.hpp
GDESession.cpp
HttpConnection.cpp
JsonFormatter.cpp
+ ProfileAttribute.cpp
+ ProfilesService.cpp
StudyService.cpp
UserService.cpp
)
#include "UserService.hpp"
#include "StudyService.hpp"
#include "AttributesService.hpp"
+#include "ProfilesService.hpp"
std::string
gde::GDESession::getServiceURI(const std::string& serviceName) const
{
return gde::AttributesService(*this).readAttributeGroup(attributeGroupId);
}
+
+ /* ProfilesService */
+const gde::Profile
+gde::GDESession::createProfile(const gde::Profile& profile)
+{
+ return gde::ProfilesService(*this).createProfile(profile);
+}
+
+bool
+gde::GDESession::deleteProfile(const gde::Profile& profile)
+{
+ return gde::ProfilesService(*this).deleteProfile(profile);
+}
+
+const gde::Profile
+gde::GDESession::readProfile(int profileId)
+{
+ return gde::ProfilesService(*this).readProfile(profileId);
+}
+
+const gde::Profile
+gde::GDESession::updateProfile(const gde::Profile& profile)
+{
+ return gde::ProfilesService(*this).updateProfile(profile);
+}
+
+const gde::ProfileAttribute
+gde::GDESession::createProfileAttribute(const std::string& name, const std::string& type, int profileId, bool mandatory)
+{
+ return gde::ProfilesService(*this).createProfileAttribute(name, type, profileId, mandatory);
+}
+
+bool
+gde::GDESession::deleteProfileAttribute(const gde::ProfileAttribute& attribute)
+{
+ return gde::ProfilesService(*this).deleteProfileAttribute(attribute);
+}
+
+const gde::ProfileAttribute
+gde::GDESession::readProfileAttribute(int attributeId)
+{
+ return gde::ProfilesService(*this).readProfileAttribute(attributeId);
+}
+
+const gde::ProfileAttribute
+gde::GDESession::updateProfileAttribute(const gde::ProfileAttribute& attribute)
+{
+ return gde::ProfilesService(*this).updateProfileAttribute(attribute);
+}
#include "Study.hpp"
#include "Attribute.hpp"
#include "AttributeGroup.hpp"
+#include "Profile.hpp"
+#include "ProfileAttribute.hpp"
#include <string>
#include <vector>
const AttributeGroup updateAttributeGroup(const AttributeGroup&);
const AttributeGroup readAttributeGroup(int);
+ /* ProfilesService */
+
+ const Profile createProfile(const Profile&);
+ bool deleteProfile(const Profile&);
+ const Profile readProfile(int);
+ const Profile updateProfile(const Profile&);
+
+ const ProfileAttribute createProfileAttribute(const std::string& name, const std::string& type, int profileId, bool mandatory);
+ bool deleteProfileAttribute(const ProfileAttribute&);
+ const ProfileAttribute readProfileAttribute(int);
+ const ProfileAttribute updateProfileAttribute(const ProfileAttribute&);
+
private:
std::string _serverAddress;
Credentials _credentials;
#include "JsonFormatter.hpp"
+#include "Attribute.hpp"
+#include "ProfileAttribute.hpp"
#include <Poco/JSON/Parser.h>
#include <Poco/DateTime.h>
}
}
-std::vector<gde::Attribute>
+template <typename T>
+std::vector<T>
gde::JsonFormatter::extractVector(Poco::JSON::Object::Ptr object, const std::string& varName)
{
try {
- std::vector<gde::Attribute> result;
+ std::vector<T> result;
Poco::JSON::Array::Ptr array = object->getArray(varName);
typedef Poco::JSON::Array::ConstIterator ArrayIterator;
for (ArrayIterator itr = array->begin(); itr != array->end(); ++itr) {
std::string json = itr->toString(); // { var:value, ... }
- result.push_back(Attribute::fromJson(json));
+ result.push_back(T::fromJson(json));
}
return result;
} catch (Poco::InvalidAccessException& e) {
// This exception is raised if Var v is empty
- return std::vector<gde::Attribute>();
+ return std::vector<T>();
}
}
template int gde::JsonFormatter::extract<int>(Poco::JSON::Object::Ptr, const std::string&);
template bool gde::JsonFormatter::extract<bool>(Poco::JSON::Object::Ptr, const std::string&);
template std::string gde::JsonFormatter::extract<std::string>(Poco::JSON::Object::Ptr, const std::string&);
+
+template std::vector<gde::Attribute> gde::JsonFormatter::extractVector<gde::Attribute>(Poco::JSON::Object::Ptr, const std::string&);
+template std::vector<gde::ProfileAttribute> gde::JsonFormatter::extractVector<gde::ProfileAttribute>(Poco::JSON::Object::Ptr, const std::string&);
#ifndef GDE_JSON_FORMATTER_HPP
#define GDE_JSON_FORMATTER_HPP
-#include "Attribute.hpp"
-
#include <string>
#include <vector>
template <typename T> static T extract(Poco::JSON::Object::Ptr, const std::string&);
static Poco::Timestamp extract(Poco::JSON::Object::Ptr, const std::string&);
- static std::vector<gde::Attribute> extractVector(Poco::JSON::Object::Ptr, const std::string&);
+ template <typename T> static std::vector<T> extractVector(Poco::JSON::Object::Ptr, const std::string&);
static std::string stringify(const Poco::JSON::Object&);
--- /dev/null
+#ifndef GDE_PROFILE_HPP
+#define GDE_PROFILE_HPP
+
+#include "ProfileAttribute.hpp"
+
+#include <string>
+#include <vector>
+
+namespace gde {
+
+ class Profile {
+ friend class ProfilesService;
+ friend class GDESession;
+
+ public:
+ Profile(const std::string& name, const std::vector<ProfileAttribute>& attributes=std::vector<ProfileAttribute>())
+ : _id(0), _name(name), _attributes(attributes)
+ {}
+ ~Profile() {}
+
+ inline int getId() const { return _id; }
+ inline void setId(int id) { this->_id = id; }
+
+ inline std::string getName() const { return _name; }
+ inline void setName(const std::string& name) { this->_name = name; }
+
+ inline const std::vector<ProfileAttribute>& getAttributes() const { return _attributes; }
+ inline void setAttributes(const std::vector<ProfileAttribute>& attributes) { this->_attributes = attributes; }
+
+ private:
+ Profile(int id, const std::string& name, const std::vector<ProfileAttribute>& attributes)
+ : _id(id), _name(name), _attributes(attributes)
+ {}
+ //Profile(const Profile&); // non copyable
+ //Profile& operator=(const Profile&); // non copyable
+
+ private:
+ int _id;
+ std::string _name;
+ std::vector<ProfileAttribute> _attributes;
+ };
+
+};
+
+#endif
--- /dev/null
+#include "ProfileAttribute.hpp"
+#include "JsonFormatter.hpp"
+
+const std::string
+gde::ProfileAttribute::toJson() const
+{
+ std::string json = "{";
+ json += JsonFormatter::format("\"id\":", getId());
+ json += JsonFormatter::format(",\"name\":", getName());
+ json += JsonFormatter::format(",\"type\":", getType());
+ json += JsonFormatter::format(",\"profileId\":", getProfileId());
+ json += JsonFormatter::format(",\"mandatory\":", getMandatory());
+ json += "}";
+ return json;
+}
+
+gde::ProfileAttribute
+gde::ProfileAttribute::fromJson(const std::string& json)
+{
+ Poco::JSON::Object::Ptr object = JsonFormatter::parse(json);
+
+ int id = JsonFormatter::extract<int>(object, "id");
+ std::string name = JsonFormatter::extract<std::string>(object, "name");
+ std::string type = JsonFormatter::extract<std::string>(object, "type");
+ int profileId = JsonFormatter::extract<int>(object, "profileId");
+ bool mandatory = JsonFormatter::extract<bool>(object, "mandatory");
+
+ return gde::ProfileAttribute(id, name, type, profileId, mandatory);
+}
--- /dev/null
+#ifndef GDE_PROFILE_ATTRIBUTE_HPP
+#define GDE_PROFILE_ATTRIBUTE_HPP
+
+#include <string>
+
+namespace gde {
+
+ class ProfileAttribute {
+ friend class ProfilesService;
+ friend class GDESession;
+
+ public:
+ ProfileAttribute(const std::string& name, const std::string& type, bool mandatory)
+ : _id(0), _name(name), _type(type), _profileId(0), _mandatory(mandatory)
+ {}
+ ~ProfileAttribute() {}
+
+ inline int getId() const { return _id; }
+ inline void setId(int id) { this->_id = id; }
+
+ inline std::string getName() const { return _name; }
+ inline void setName(const std::string& name) { this->_name = name; }
+
+ inline std::string getType() const { return _type; }
+ inline void setType(const std::string& type) { this->_type = type; }
+
+ inline int getProfileId() const { return _profileId; }
+ inline void setProfileId(int profileId) { this->_profileId = profileId; }
+
+ inline bool getMandatory() const { return _mandatory; }
+ inline void setMandatory(bool mandatory) { this->_mandatory = mandatory; }
+
+ const std::string toJson() const;
+ static ProfileAttribute fromJson(const std::string& json);
+
+ private:
+ ProfileAttribute(int id=0, const std::string& name="", const std::string& type="", int profileId=0, bool mandatory=false)
+ : _id(id), _name(name), _type(type), _profileId(profileId), _mandatory(mandatory)
+ {}
+ //ProfileAttribute(const ProfileAttribute&); // non copyable
+ //ProfileAttribute& operator=(const ProfileAttribute&); // non copyable
+
+ private:
+ int _id;
+ std::string _name;
+ std::string _type;
+ int _profileId;
+ bool _mandatory;
+ };
+
+};
+
+#endif
--- /dev/null
+#include "ProfilesService.hpp"
+#include "HttpConnection.hpp"
+#include "CommandTO.hpp"
+#include "CommandResultTO.hpp"
+#include "JsonFormatter.hpp"
+#include "Credentials.hpp"
+
+#include <vector>
+#include <typeinfo>
+
+/*
+ * WARNING: keep enum values synchronized to WEB API (AttributesService)
+ */
+enum {
+ CREATE_PROFILE = 1,
+ DELETE_PROFILE,
+ READ_PROFILE,
+ UPDATE_PROFILE,
+ CREATE_PROFILE_ATTRIBUTE,
+ DELETE_PROFILE_ATTRIBUTE,
+ READ_PROFILE_ATTRIBUTE,
+ UPDATE_PROFILE_ATTRIBUTE
+};
+
+std::string gde::ProfilesService::_servletName = "ProfilesService";
+
+std::string
+_buildAttributesJsonString(const gde::Profile& profile)
+{
+ // Solution here is not very smart. Have tried using Poco to stringify attributes,
+ // but stringification is too recursive, for example it produces:
+ // "attributes":"[ { \"id\" : 0, \"name\" : \"myAttribute\",...
+ // instead of:
+ // "attributes":[{"id":0,"name":"myAttribute",...
+ const std::vector<gde::ProfileAttribute>& attributes = profile.getAttributes();
+ std::string data = "{";
+ data += gde::JsonFormatter::format("\"id\":", profile.getId());
+ data += gde::JsonFormatter::format(", \"name\":", profile.getName());
+ data += ", \"attributes\":[";
+ for (std::vector<gde::ProfileAttribute>::const_iterator itr = attributes.begin(); itr != attributes.end(); ++itr) {
+ if (itr != attributes.begin())
+ data += ",";
+ data += itr->toJson();
+ }
+ data += "]}";
+ return data;
+}
+
+const gde::Profile
+gde::ProfilesService::createProfile(const gde::Profile& profile)
+{
+ std::string data = _buildAttributesJsonString(profile);
+ CommandTO cto(CREATE_PROFILE, data);
+
+ const Credentials& credentials = _session.getCredentials();
+ std::string uri = _session.getServiceURI(_servletName);
+ CommandResultTO crto = gde::HttpConnection(Poco::URI(uri), credentials).doPost(cto);
+
+ // build Profile object from CommandResultTO data (json format)
+ {
+ Poco::JSON::Object::Ptr object = JsonFormatter::parse(crto.getData());
+ int id = JsonFormatter::extract<int>(object, "id");
+ std::string name = JsonFormatter::extract<std::string>(object, "name");
+ std::vector<gde::ProfileAttribute> attributes = JsonFormatter::extractVector<gde::ProfileAttribute>(object, "attributes");
+ return gde::Profile(id, name, attributes);
+ }
+}
+
+bool
+gde::ProfilesService::deleteProfile(const gde::Profile& profile)
+{
+ CommandTO cto(DELETE_PROFILE);
+ cto.setParameter("profileId", profile.getId());
+
+ const Credentials& credentials = _session.getCredentials();
+ std::string uri = _session.getServiceURI(_servletName);
+ CommandResultTO crto = gde::HttpConnection(Poco::URI(uri), credentials).doPost(cto);
+ return crto.getCode() == CommandResultTO::OK;
+}
+
+const gde::Profile
+gde::ProfilesService::readProfile(int profileId)
+{
+ CommandTO cto(READ_PROFILE);
+ cto.setParameter("profileId", profileId);
+
+ const Credentials& credentials = _session.getCredentials();
+ std::string uri = _session.getServiceURI(_servletName);
+ CommandResultTO crto = gde::HttpConnection(Poco::URI(uri), credentials).doPost(cto);
+
+ // build Profile object from CommandResultTO data (json format)
+ {
+ Poco::JSON::Object::Ptr object = JsonFormatter::parse(crto.getData());
+ int id = JsonFormatter::extract<int>(object, "id");
+ std::string name = JsonFormatter::extract<std::string>(object, "name");
+ std::vector<gde::ProfileAttribute> attributes = JsonFormatter::extractVector<gde::ProfileAttribute>(object, "attributes");
+ return gde::Profile(id, name, attributes);
+ }
+}
+
+const gde::Profile
+gde::ProfilesService::updateProfile(const gde::Profile& profile)
+{
+ std::string data = _buildAttributesJsonString(profile);
+ CommandTO cto(UPDATE_PROFILE, data);
+
+ const Credentials& credentials = _session.getCredentials();
+ std::string uri = _session.getServiceURI(_servletName);
+ CommandResultTO crto = gde::HttpConnection(Poco::URI(uri), credentials).doPost(cto);
+
+ // build Profile object from CommandResultTO data (json format)
+ {
+ Poco::JSON::Object::Ptr object = JsonFormatter::parse(crto.getData());
+ int id = JsonFormatter::extract<int>(object, "id");
+ std::string name = JsonFormatter::extract<std::string>(object, "name");
+ std::vector<gde::ProfileAttribute> attributes = JsonFormatter::extractVector<gde::ProfileAttribute>(object, "attributes");
+ return gde::Profile(id, name, attributes);
+ }
+}
+
+const gde::ProfileAttribute
+gde::ProfilesService::createProfileAttribute(const std::string& name, const std::string& type, int profileId, bool mandatory)
+{
+ // build JSON string for CommandTO data
+ Poco::JSON::Object obj;
+ obj.set("name", Poco::Dynamic::Var(name));
+ obj.set("type", Poco::Dynamic::Var(type));
+ obj.set("profileId", Poco::Dynamic::Var(profileId));
+ obj.set("mandatory", Poco::Dynamic::Var(mandatory));
+ std::string data = JsonFormatter::stringify(obj);
+
+ CommandTO cto(CREATE_PROFILE_ATTRIBUTE, data);
+ const Credentials& credentials = _session.getCredentials();
+ std::string uri = _session.getServiceURI(_servletName);
+ CommandResultTO crto = gde::HttpConnection(Poco::URI(uri), credentials).doPost(cto);
+
+ // build ProfileAttribute object from CommandResultTO data (json format)
+ {
+ Poco::JSON::Object::Ptr object = JsonFormatter::parse(crto.getData());
+ int id = JsonFormatter::extract<int>(object, "id");
+ std::string name = JsonFormatter::extract<std::string>(object, "name");
+ std::string type = JsonFormatter::extract<std::string>(object, "type");
+ int profileId = JsonFormatter::extract<int>(object, "profileId");
+ bool mandatory = JsonFormatter::extract<bool>(object, "mandatory");
+ return gde::ProfileAttribute(id, name, type, profileId, mandatory);
+ }
+}
+
+bool
+gde::ProfilesService::deleteProfileAttribute(const gde::ProfileAttribute& attribute)
+{
+ CommandTO cto(DELETE_PROFILE_ATTRIBUTE);
+ cto.setParameter("profileAttributeId", attribute.getId());
+
+ const Credentials& credentials = _session.getCredentials();
+ std::string uri = _session.getServiceURI(_servletName);
+ CommandResultTO crto = gde::HttpConnection(Poco::URI(uri), credentials).doPost(cto);
+ return crto.getCode() == CommandResultTO::OK;
+}
+
+const gde::ProfileAttribute
+gde::ProfilesService::readProfileAttribute(int attributeId)
+{
+ CommandTO cto(READ_PROFILE_ATTRIBUTE);
+ cto.setParameter("profileAttributeId", attributeId);
+
+ const Credentials& credentials = _session.getCredentials();
+ std::string uri = _session.getServiceURI(_servletName);
+ CommandResultTO crto = gde::HttpConnection(Poco::URI(uri), credentials).doPost(cto);
+
+ // build ProfileAttribute object from CommandResultTO data (json format)
+ {
+ Poco::JSON::Object::Ptr object = JsonFormatter::parse(crto.getData());
+ int id = JsonFormatter::extract<int>(object, "id");
+ std::string name = JsonFormatter::extract<std::string>(object, "name");
+ std::string type = JsonFormatter::extract<std::string>(object, "type");
+ int profileId = JsonFormatter::extract<int>(object, "profileId");
+ bool mandatory = JsonFormatter::extract<bool>(object, "mandatory");
+ return gde::ProfileAttribute(id, name, type, profileId, mandatory);
+ }
+}
+
+const gde::ProfileAttribute
+gde::ProfilesService::updateProfileAttribute(const gde::ProfileAttribute& attribute)
+{
+ // build JSON string for CommandTO data
+ Poco::JSON::Object obj;
+ obj.set("id", Poco::Dynamic::Var(attribute.getId()));
+ obj.set("name", Poco::Dynamic::Var(attribute.getName()));
+ obj.set("type", Poco::Dynamic::Var(attribute.getType()));
+ obj.set("profileId", Poco::Dynamic::Var(attribute.getProfileId()));
+ obj.set("mandatory", Poco::Dynamic::Var(attribute.getMandatory()));
+ std::string data = JsonFormatter::stringify(obj);
+ CommandTO cto(UPDATE_PROFILE_ATTRIBUTE, data);
+
+ const Credentials& credentials = _session.getCredentials();
+ std::string uri = _session.getServiceURI(_servletName);
+ CommandResultTO crto = gde::HttpConnection(Poco::URI(uri), credentials).doPost(cto);
+
+ // build ProfileAttribute object from CommandResultTO data (json format)
+ {
+ Poco::JSON::Object::Ptr object = JsonFormatter::parse(crto.getData());
+ int id = JsonFormatter::extract<int>(object, "id");
+ std::string name = JsonFormatter::extract<std::string>(object, "name");
+ std::string type = JsonFormatter::extract<std::string>(object, "type");
+ int profileId = JsonFormatter::extract<int>(object, "profileId");
+ bool mandatory = JsonFormatter::extract<bool>(object, "mandatory");
+ return gde::ProfileAttribute(id, name, type, profileId, mandatory);
+ }
+}
--- /dev/null
+#ifndef GDE_PROFILES_SERVICE_HPP
+#define GDE_PROFILES_SERVICE_HPP
+
+#include "Profile.hpp"
+#include "ProfileAttribute.hpp"
+#include "GDESession.hpp"
+
+#include <string>
+#include <vector>
+
+namespace gde {
+
+ class ProfilesService {
+ friend class GDESession;
+
+ public:
+ const Profile createProfile(const Profile&);
+ bool deleteProfile(const Profile&);
+ const Profile readProfile(int);
+ const Profile updateProfile(const Profile&);
+
+ const ProfileAttribute createProfileAttribute(const std::string& name, const std::string& type, int profileId, bool mandatory);
+ bool deleteProfileAttribute(const ProfileAttribute&);
+ const ProfileAttribute readProfileAttribute(int);
+ const ProfileAttribute updateProfileAttribute(const ProfileAttribute&);
+
+ private:
+ ProfilesService(const GDESession& session) : _session(session) {}
+ ~ProfilesService() {}
+ ProfilesService(const ProfilesService&); // non copyable
+ ProfilesService& operator=(const ProfilesService&); // non copyable
+
+ private:
+ static std::string _servletName;
+ const GDESession& _session;
+
+ };
+
+};
+
+#endif
--- /dev/null
+#include <TestUtilities.hpp>
+#include <Profile.hpp>
+#include <GDESession.hpp>
+#include <ProfilesTest.hpp>
+
+void
+ProfilesTest::testCreateDeleteProfile()
+{
+ gde::GDESession session(serverAddress, credentials);
+
+ gde::Profile myProfile("myProfile");
+ CPPUNIT_ASSERT(myProfile.getId() == 0);
+ gde::Profile profile = session.createProfile(myProfile);
+ CPPUNIT_ASSERT(profile.getId() > 0);
+ CPPUNIT_ASSERT(profile.getName() == myProfile.getName());
+
+ CPPUNIT_ASSERT(session.deleteProfile(profile));
+}
+
+void
+ProfilesTest::testReadProfile()
+{
+ gde::GDESession session(serverAddress, credentials);
+
+ gde::Profile myProfile("myProfile");
+ CPPUNIT_ASSERT(myProfile.getId() == 0);
+ gde::Profile profile = session.createProfile(myProfile);
+ CPPUNIT_ASSERT(profile.getId() > 0);
+
+ {
+ const gde::Profile& prf = session.readProfile(profile.getId());
+ CPPUNIT_ASSERT(prf.getName() == myProfile.getName());
+ CPPUNIT_ASSERT(prf.getId() > 0);
+ }
+
+ CPPUNIT_ASSERT(session.deleteProfile(profile));
+}
+
+void
+ProfilesTest::testUpdateProfile()
+{
+ gde::GDESession session(serverAddress, credentials);
+
+ gde::Profile myProfile("myProfile");
+ CPPUNIT_ASSERT(myProfile.getId() == 0);
+ gde::Profile profile = session.createProfile(myProfile);
+ CPPUNIT_ASSERT(profile.getId() > 0);
+ CPPUNIT_ASSERT(profile.getName() == "myProfile");
+ profile.setName("myProfile2");
+
+ {
+ const gde::Profile& prf = session.updateProfile(profile);
+ CPPUNIT_ASSERT(prf.getName() == profile.getName());
+ CPPUNIT_ASSERT(prf.getId() == profile.getId());
+ }
+
+ CPPUNIT_ASSERT(session.deleteProfile(profile));
+}
+
+void
+ProfilesTest::testCreateDeleteProfileAttribute()
+{
+ gde::GDESession session(serverAddress, credentials);
+
+ gde::Profile profile = session.createProfile(gde::Profile("myProfile"));
+ CPPUNIT_ASSERT(profile.getId() > 0);
+
+ gde::ProfileAttribute myAttribute = session.createProfileAttribute("myAttribute", "float", profile.getId(), true);
+
+ CPPUNIT_ASSERT(myAttribute.getId() > 0);
+ CPPUNIT_ASSERT(myAttribute.getName() == "myAttribute");
+ CPPUNIT_ASSERT(myAttribute.getType() == "float");
+ CPPUNIT_ASSERT(myAttribute.getMandatory());
+
+ CPPUNIT_ASSERT(session.deleteProfile(profile));
+}
+
+void
+ProfilesTest::testUpdateProfileAttribute()
+{
+ gde::GDESession session(serverAddress, credentials);
+
+ gde::Profile profile = session.createProfile(gde::Profile("myProfile"));
+ CPPUNIT_ASSERT(profile.getId() > 0);
+
+ gde::ProfileAttribute myAttribute = session.createProfileAttribute("myAttribute", "float", profile.getId(), true);
+
+ CPPUNIT_ASSERT(myAttribute.getId() > 0);
+ CPPUNIT_ASSERT(myAttribute.getName() == "myAttribute");
+ CPPUNIT_ASSERT(myAttribute.getType() == "float");
+ CPPUNIT_ASSERT(myAttribute.getMandatory());
+
+ myAttribute.setType("std::string");
+
+ {
+ const gde::ProfileAttribute& attr = session.updateProfileAttribute(myAttribute);
+ CPPUNIT_ASSERT(attr.getId() == myAttribute.getId());
+ CPPUNIT_ASSERT(attr.getName() == "myAttribute");
+ CPPUNIT_ASSERT(attr.getType() == "std::string");
+ CPPUNIT_ASSERT(attr.getMandatory());
+ }
+
+ CPPUNIT_ASSERT(session.deleteProfile(profile));
+}
+
+void
+ProfilesTest::testReadProfileAttribute()
+{
+ gde::GDESession session(serverAddress, credentials);
+
+ gde::Profile profile = session.createProfile(gde::Profile("myProfile"));
+ CPPUNIT_ASSERT(profile.getId() > 0);
+
+ gde::ProfileAttribute myAttribute = session.createProfileAttribute("myAttribute", "float", profile.getId(), true);
+ CPPUNIT_ASSERT(myAttribute.getId() > 0);
+
+ {
+ const gde::ProfileAttribute& attr = session.readProfileAttribute(myAttribute.getId());
+ CPPUNIT_ASSERT(attr.getId() == myAttribute.getId());
+ CPPUNIT_ASSERT(attr.getName() == myAttribute.getName());
+ CPPUNIT_ASSERT(attr.getType() == myAttribute.getType());
+ CPPUNIT_ASSERT(attr.getMandatory() == myAttribute.getMandatory());
+ }
+
+ CPPUNIT_ASSERT(session.deleteProfile(profile));
+}
--- /dev/null
+#ifndef GDE_PROFILES_TEST_HPP
+#define GDE_PROFILES_TEST_HPP
+
+#include <cppunit/extensions/HelperMacros.h>
+
+class ProfilesTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(ProfilesTest);
+ CPPUNIT_TEST(testCreateDeleteProfile);
+ CPPUNIT_TEST(testReadProfile);
+ CPPUNIT_TEST(testUpdateProfile);
+
+ CPPUNIT_TEST(testCreateDeleteProfileAttribute);
+ CPPUNIT_TEST(testUpdateProfileAttribute);
+ CPPUNIT_TEST(testReadProfileAttribute);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void testCreateDeleteProfile();
+ void testReadProfile();
+ void testUpdateProfile();
+
+ void testCreateDeleteProfileAttribute();
+ void testUpdateProfileAttribute();
+ void testReadProfileAttribute();
+};
+
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ProfilesTest, "ProfilesTest");
+
+#endif