From 958b3c763fb52d1bf2ad88c177e7e4f426aab354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Date: Wed, 4 Dec 2013 10:44:37 +0100 Subject: [PATCH] Object creation mixed relationship properties with document properties Added a Unit test to show the problem. We surely don't want the relationship cmis:properties to be read as properties. This bug caused some problems with other operations like checkout. --- .../data/atom/test-document-relationships.xml | 179 +++++++++++++++++++++ qa/libcmis/test-atom.cxx | 34 ++++ src/libcmis/object.cxx | 4 +- 3 files changed, 215 insertions(+), 2 deletions(-) create mode 100644 qa/libcmis/data/atom/test-document-relationships.xml diff --git qa/libcmis/data/atom/test-document-relationships.xml qa/libcmis/data/atom/test-document-relationships.xml new file mode 100644 index 0000000..bacfda8 --- /dev/null +++ qa/libcmis/data/atom/test-document-relationships.xml @@ -0,0 +1,179 @@ + + + + unknown + + Some obscure Id + 2013-01-28T14:10:06Z + Test Document + 2013-01-28T14:10:06Z + 2013-01-28T14:10:06Z + + + + + 12345 + + + DocumentLevel2 + + + + + + + + + + + + true + + + + + false + + + unknown + + + unknown + + + + blue + + + + + true + + + + Test Document + + + text/plain + + + My Doc StringProperty 6 + + + 2013-01-28T14:10:06.736Z + + + 1359382206736 + + + + + + + test-document + + + false + + + true + + + cmis:document + + + + data.txt + + + 2013-01-28T14:10:06.736Z + + + + true + true + false + true + false + true + false + false + true + true + true + false + false + true + true + true + true + true + false + false + false + false + false + false + false + false + false + false + false + + + test-document + Test Document + + + + + workspace://SpacesStore/5d8908d9-1b4a-4265-b1de-5d7244fcea70;2.2 + + + R:cm:original + + + admin + + + workspace://SpacesStore/5d8908d9-1b4a-4265-b1de-5d7244fcea70;pwc + + + 75|workspace://SpacesStore/3885d9a2-0540-41ab-810a-38ccb1b160d6|workspace://SpacesStore/5d8908d9-1b4a-4265-b1de-5d7244fcea70|{http://www.alfresco.org/model/content/1.0}original + + + admin + + + assoc:75 + + + 2010-05-01T00:00:00+02:00 + + + + cmis:relationship + + + 75|workspace://SpacesStore/3885d9a2-0540-41ab-810a-38ccb1b160d6|workspace://SpacesStore/5d8908d9-1b4a-4265-b1de-5d7244fcea70|{http://www.alfresco.org/model/content/1.0}original + + + + 2010-05-01T00:00:00+02:00 + + + + + + + + + + + + + + + + + diff --git qa/libcmis/test-atom.cxx qa/libcmis/test-atom.cxx index 57864d9..af16616 100644 --- qa/libcmis/test-atom.cxx +++ qa/libcmis/test-atom.cxx @@ -64,6 +64,7 @@ class AtomTest : public CppUnit::TestFixture void getTypeChildrenTest( ); void getObjectTest( ); void getDocumentTest( ); + void getDocumentRelationshipsTest( ); void getUnexistantObjectTest( ); void getFolderTest( ); void getFolderBadTypeTest( ); @@ -101,6 +102,7 @@ class AtomTest : public CppUnit::TestFixture CPPUNIT_TEST( getTypeChildrenTest ); CPPUNIT_TEST( getObjectTest ); CPPUNIT_TEST( getDocumentTest ); + CPPUNIT_TEST( getDocumentRelationshipsTest ); CPPUNIT_TEST( getUnexistantObjectTest ); CPPUNIT_TEST( getFolderTest ); CPPUNIT_TEST( getFolderBadTypeTest ); @@ -441,6 +443,38 @@ void AtomTest::getDocumentTest( ) CPPUNIT_ASSERT_MESSAGE( "Content length is missing", 12345 == document->getContentLength( ) ); } +void AtomTest::getDocumentRelationshipsTest( ) +{ + curl_mockup_reset( ); + curl_mockup_addResponse( "http://mockup/mock/id", "id=test-document", "GET", DATA_DIR "/atom/test-document-relationships.xml" ); + curl_mockup_addResponse( "http://mockup/mock/type", "id=DocumentLevel2", "GET", DATA_DIR "/atom/type-docLevel2.xml" ); + curl_mockup_setCredentials( SERVER_USERNAME, SERVER_PASSWORD ); + + AtomPubSession session = getTestSession( SERVER_USERNAME, SERVER_PASSWORD ); + + string expectedId( "test-document" ); + libcmis::ObjectPtr actual = session.getObject( expectedId ); + + // Do we have a document? + libcmis::DocumentPtr document = boost::dynamic_pointer_cast< libcmis::Document >( actual ); + CPPUNIT_ASSERT_MESSAGE( "Fetched object should be an instance of libcmis::DocumentPtr", + NULL != document ); + + // Test the document properties + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong document ID", expectedId, document->getId( ) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong document name", string( "Test Document" ), document->getName( ) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong document type", string( "text/plain" ), document->getContentType( ) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong base type", string( "cmis:document" ), document->getBaseType( ) ); + + CPPUNIT_ASSERT_MESSAGE( "CreatedBy is missing", !document->getCreatedBy( ).empty( ) ); + CPPUNIT_ASSERT_MESSAGE( "CreationDate is missing", !document->getCreationDate( ).is_not_a_date_time() ); + CPPUNIT_ASSERT_MESSAGE( "LastModifiedBy is missing", !document->getLastModifiedBy( ).empty( ) ); + CPPUNIT_ASSERT_MESSAGE( "LastModificationDate is missing", !document->getLastModificationDate( ).is_not_a_date_time() ); + CPPUNIT_ASSERT_MESSAGE( "ChangeToken is missing", !document->getChangeToken( ).empty( ) ); + + CPPUNIT_ASSERT_MESSAGE( "Content length is missing", 12345 == document->getContentLength( ) ); +} + void AtomTest::getFolderTest( ) { curl_mockup_reset( ); diff --git src/libcmis/object.cxx src/libcmis/object.cxx index 538c98e..d5e0c7a 100644 --- src/libcmis/object.cxx +++ src/libcmis/object.cxx @@ -105,10 +105,10 @@ namespace libcmis xmlXPathFreeObject( xpathObj ); // First get the type id as it will give us the property definitions - string typeIdReq( "//cmis:propertyId[@propertyDefinitionId='cmis:objectTypeId']/cmis:value/text()" ); + string typeIdReq( "/*/cmis:properties/cmis:propertyId[@propertyDefinitionId='cmis:objectTypeId']/cmis:value/text()" ); m_typeId = libcmis::getXPathValue( xpathCtx, typeIdReq ); - string propertiesReq( "//cmis:properties/*" ); + string propertiesReq( "/*/cmis:properties/*" ); xpathObj = xmlXPathEvalExpression( BAD_CAST( propertiesReq.c_str() ), xpathCtx ); if ( NULL != xpathObj && NULL != xpathObj->nodesetval ) { -- 1.8.4.4