[mapguide-commits] r6717 - in branches/2.4/MgDev/Server/src: Services/Feature UnitTesting

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu May 31 08:30:25 PDT 2012


Author: jng
Date: 2012-05-31 08:30:24 -0700 (Thu, 31 May 2012)
New Revision: 6717

Modified:
   branches/2.4/MgDev/Server/src/Services/Feature/ServerDescribeSchema.cpp
   branches/2.4/MgDev/Server/src/UnitTesting/TestFeatureService.cpp
   branches/2.4/MgDev/Server/src/UnitTesting/TestFeatureService.h
Log:
#1403: Fix the behaviour of GETIDENTITYPROPERTIES. The internal MgFeatureService::GetIdentityProperties() API should be returning the class definition (an empty one will do) even if it has no identity properties instead of throwing a MgClassNotFoundException. From the client-side, the web tier returns the correct empty <PropertyDefinitions> element. A unit test has been added to verify this behaviour.

Modified: branches/2.4/MgDev/Server/src/Services/Feature/ServerDescribeSchema.cpp
===================================================================
--- branches/2.4/MgDev/Server/src/Services/Feature/ServerDescribeSchema.cpp	2012-05-31 15:01:00 UTC (rev 6716)
+++ branches/2.4/MgDev/Server/src/Services/Feature/ServerDescribeSchema.cpp	2012-05-31 15:30:24 UTC (rev 6717)
@@ -1171,23 +1171,27 @@
         {
             STRING className = uncachedClasses->GetItem(j);
 
+            // #1403: Identity properties or not, the class itself should be always returned
+
+            // Add class to collection
+            Ptr<MgClassDefinition> classDef = new MgClassDefinition();
+            classDef->SetName(className);
+
             // Get the class identity properties.
             Ptr<MgPropertyDefinitionCollection> idProps = GetIdentityProperties(fdoSchemas.p, resource, schemaName, className);
             if (NULL != idProps.p && idProps->GetCount() > 0)
             {
                 m_featureServiceCache->SetClassIdentityProperties(resource, schemaName, className, idProps.p);
 
-                // Add class to collection
-                Ptr<MgClassDefinition> classDef = new MgClassDefinition();
-                classDef->SetName(className);
                 Ptr<MgPropertyDefinitionCollection> propDefs = classDef->GetIdentityProperties();
                 for (int k = 0; k < idProps->GetCount(); k++)
                 {
                     Ptr<MgPropertyDefinition> idProp = idProps->GetItem(k);
                     propDefs->Add(idProp);
                 }
-                classDefs->Add(classDef);
             }
+
+            classDefs->Add(classDef);
         }
     }
 

Modified: branches/2.4/MgDev/Server/src/UnitTesting/TestFeatureService.cpp
===================================================================
--- branches/2.4/MgDev/Server/src/UnitTesting/TestFeatureService.cpp	2012-05-31 15:01:00 UTC (rev 6716)
+++ branches/2.4/MgDev/Server/src/UnitTesting/TestFeatureService.cpp	2012-05-31 15:30:24 UTC (rev 6717)
@@ -266,6 +266,10 @@
         Ptr<MgResourceIdentifier> fsres8 = new MgResourceIdentifier(L"Library://UnitTests/Data/ParcelsJoinTestSQLite.FeatureSource");
         pService->DeleteResource(fsres8);
 
+        //May or may not have been created during the test
+        Ptr<MgResourceIdentifier> fsres9 = new MgResourceIdentifier(L"Library://UnitTests/Data/GetIdentityPropertiesTest.FeatureSource");
+        if (pService->ResourceExists(fsres9)) pService->DeleteResource(fsres9);
+
         #ifdef _DEBUG
         ACE_DEBUG((LM_INFO, ACE_TEXT("TestFeatureService::TestEnd()\n")));
         MgFdoConnectionManager* pFdoConnectionManager = MgFdoConnectionManager::GetInstance();
@@ -767,7 +771,78 @@
     }
 }
 
+///----------------------------------------------------------------------------
+/// Test Case Description:
+///
+/// This test case exercises the GetIdentityProperties() internal API
+///----------------------------------------------------------------------------
+void TestFeatureService::TestCase_GetIdentityProperties()
+{
+    try
+    {
+        MgServiceManager* serviceManager = MgServiceManager::GetInstance();
+        if(serviceManager == 0)
+        {
+            throw new MgNullReferenceException(L"TestFeatureService.TestCase_GetIdentityProperties", __LINE__, __WFILE__, NULL, L"", NULL);
+        }
 
+        Ptr<MgFeatureService> pService = dynamic_cast<MgFeatureService*>(serviceManager->RequestService(MgServiceType::FeatureService));
+        if (pService == 0)
+        {
+            throw new MgServiceNotAvailableException(L"TestFeatureService.TestCase_GetIdentityProperties", __LINE__, __WFILE__, NULL, L"", NULL);
+        }
+
+        // Set the user information for the current thread to be administrator.
+        Ptr<MgUserInformation> adminUserInfo = new MgUserInformation(MgUser::Administrator, L"");
+        MgUserInformation::SetCurrentUserInfo(adminUserInfo);
+
+        // Set up our test data store
+        Ptr<MgFeatureSchema> testSchema = new MgFeatureSchema(L"UnitTest", L"GetIdentityProperties test schema");
+        Ptr<MgClassDefinition> cls = new MgClassDefinition();
+        cls->SetName(L"NoProps");
+        Ptr<MgClassDefinitionCollection> classes = testSchema->GetClasses();
+        classes->Add(cls);
+
+        STRING wkt = L"LOCAL_CS[\"Non-Earth (Meter)\",LOCAL_DATUM[\"Local Datum\",0],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]";
+
+        Ptr<MgResourceIdentifier> fsId = new MgResourceIdentifier(L"Library://UnitTests/Data/GetIdentityPropertiesTest.FeatureSource");
+        Ptr<MgCreateSdfParams> createSdf = new MgCreateSdfParams(L"Default", wkt, testSchema);
+        pService->CreateFeatureSource(fsId, createSdf);
+
+        // Now query it - as the HttpHandler does it
+        Ptr<MgStringCollection> classNames = new MgStringCollection();
+        classNames->Add(L"NoProps");
+        Ptr<MgClassDefinitionCollection> matchingClasses = pService->GetIdentityProperties(fsId, L"UnitTest", classNames);
+        CPPUNIT_ASSERT_MESSAGE("Expected class (NoProps) to be in result for GetIdentityProperties", 1 == matchingClasses->GetCount());
+
+        // Here's the kicker - We expect 0 identity properties instead of exception (#1403)
+        Ptr<MgClassDefinition> klass = matchingClasses->GetItem(0);
+        Ptr<MgPropertyDefinitionCollection> idProps = klass->GetIdentityProperties();
+        CPPUNIT_ASSERT_MESSAGE("Expected 0 identity properties in class (NoProps)", 0 == idProps->GetCount());
+
+        // Here is where exception should be thrown
+        classNames->Clear();
+        classNames->Add(L"IDontExist");
+        CPPUNIT_ASSERT_THROW_MG(pService->GetIdentityProperties(fsId, L"UnitTest", classNames), MgFdoException*);
+    }
+    catch(MgException* e)
+    {
+        STRING message = e->GetDetails(TEST_LOCALE);
+        SAFE_RELEASE(e);
+        CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+    }
+    catch(FdoException* e)
+    {
+        FDO_SAFE_RELEASE(e);
+        CPPUNIT_FAIL("FdoException occurred");
+    }
+    catch(...)
+    {
+        throw;
+    }
+}
+
+
 ///----------------------------------------------------------------------------
 /// Test Case Description:
 ///

Modified: branches/2.4/MgDev/Server/src/UnitTesting/TestFeatureService.h
===================================================================
--- branches/2.4/MgDev/Server/src/UnitTesting/TestFeatureService.h	2012-05-31 15:01:00 UTC (rev 6716)
+++ branches/2.4/MgDev/Server/src/UnitTesting/TestFeatureService.h	2012-05-31 15:30:24 UTC (rev 6717)
@@ -34,6 +34,7 @@
     CPPUNIT_TEST(TestCase_GetSchemas);
     CPPUNIT_TEST(TestCase_GetClasses);
     CPPUNIT_TEST(TestCase_GetClassDefinition);
+    CPPUNIT_TEST(TestCase_GetIdentityProperties);
     CPPUNIT_TEST(TestCase_DescribeSchema);
     CPPUNIT_TEST(TestCase_ApplySchema);
     CPPUNIT_TEST(TestCase_SelectFeatures);
@@ -82,6 +83,7 @@
     void TestCase_GetSchemas();
     void TestCase_GetClasses();
     void TestCase_GetClassDefinition();
+    void TestCase_GetIdentityProperties();
     void TestCase_DescribeSchema();
     void TestCase_ApplySchema();
     void TestCase_SelectFeatures();



More information about the mapguide-commits mailing list