Salome HOME
ProfilesService
[modules/gde.git] / projects / GDE_API_CPP / api / tests / ProfilesTest.cpp
diff --git a/projects/GDE_API_CPP/api/tests/ProfilesTest.cpp b/projects/GDE_API_CPP/api/tests/ProfilesTest.cpp
new file mode 100644 (file)
index 0000000..178a2d1
--- /dev/null
@@ -0,0 +1,126 @@
+#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));
+}