Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/PagingListTest.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/PagingListTest.java?rev=936836&r1=936835&r2=936836&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/PagingListTest.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/PagingListTest.java Thu Apr 22 13:27:21 2010 @@ -20,188 +20,148 @@ package org.apache.chemistry.opencmis.cl import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.math.BigInteger; import java.util.ArrayList; import java.util.List; -import java.util.NoSuchElementException; -import org.apache.chemistry.opencmis.client.api.PagingList; -import org.apache.chemistry.opencmis.client.runtime.util.AbstractPagingList; -import org.junit.Before; +import org.apache.chemistry.opencmis.client.api.PagingIterable; +import org.apache.chemistry.opencmis.client.api.PagingIterator; +import org.apache.chemistry.opencmis.client.runtime.util.AbstractPageFetch; +import org.apache.chemistry.opencmis.client.runtime.util.DefaultPagingIterable; import org.junit.Test; public class PagingListTest { - private static final int ITEMS = 201; - private static final int MAX_ITEMS_PER_PAGE = 20; - - private static final String PREFIX_1 = "1$"; - private static final String PREFIX_2 = "2$"; - - private String[] sourceData; - private PagingList<String> testList; - private PagingList<String> testCacheList; - - @Before - public void setUp() throws Exception { - sourceData = new String[ITEMS]; - for (int i = 0; i < sourceData.length; i++) { - sourceData[i] = PREFIX_1 + i; - } - - testList = new TestPagingList(0); - testCacheList = new TestPagingList(2); + private String[] data10 = { "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", + "A8", "A9" }; + private String[] data1 = { "A0" }; + private String[] data0 = { }; + + private PagingIterable<String> getIterable(final String[] data, final long pageSize) { + return new DefaultPagingIterable<String>( + new AbstractPageFetch<String>() { + + @Override + protected PageFetchResult<String> fetchPage(long skipCount) { + Boolean hasMoreItems = Boolean.TRUE; + List<String> page = new ArrayList<String>(); + + System.out.print("(" + skipCount + "|" + pageSize + + ") "); + + int from = (int) skipCount; + int to = (int) (skipCount + pageSize); + + if (to >= data.length) { + to = data.length; + hasMoreItems = Boolean.FALSE; + } + + for (int i = from; i < to; i++) { + page.add(data[i]); + } + + PageFetchResult<String> result = new AbstractPageFetch.PageFetchResult<String>( + page, + BigInteger + .valueOf(data.length), + hasMoreItems); + + return result; + } + }); } @Test - public void testPagingList() { - // test setup - assertNotNull(testList); - - // test number of items per pages - assertEquals(MAX_ITEMS_PER_PAGE, testList.getMaxItemsPerPage()); - - // we haven't fetched data yet -> number of item should be unknown - assertEquals(-1, testList.getNumItems()); - - // fetch first page and check it - List<String> page = testList.get(0); - assertPage(page, 0, MAX_ITEMS_PER_PAGE, PREFIX_1); - - // number of item should be known now - assertEquals(sourceData.length, testList.getNumItems()); - - // number of pages should be known too - assertEquals(11, testList.size()); - - // check all pages - for (int i = 0; i < testList.size(); i++) { - page = testList.get(i); - - int pageSize = (i == testList.size() - 1 ? ITEMS % MAX_ITEMS_PER_PAGE : MAX_ITEMS_PER_PAGE); - assertPage(page, i, pageSize, PREFIX_1); - } - } - - @Test - public void testPagingListIterator() { - // test setup - assertNotNull(testList); - - // test iterator - int pageNumber = 0; - for (List<String> page : testList) { - assertTrue(pageNumber < testList.size()); - - int pageSize = (pageNumber == testList.size() - 1 ? ITEMS % MAX_ITEMS_PER_PAGE : MAX_ITEMS_PER_PAGE); - - assertPage(page, pageNumber, pageSize, PREFIX_1); - - pageNumber++; - } - } + public void loopAll() { + this.loopAll(this.data10, 100); // tolerate out of bound + this.loopAll(this.data10, 10); + this.loopAll(this.data10, 9); + this.loopAll(this.data10, 8); + + this.loopAll(this.data10, 2); + this.loopAll(this.data10, 1); + // this.loopAll(0); pageSize must be > 0 - @Test - public void testPagingListExceptions() { - // test setup - assertNotNull(testList); - - // check negative page numbers - try { - testList.get(-1); - fail("Should throw a IllegalArgumentException!"); - } catch (IllegalArgumentException e) { - } + this.loopAll(this.data1, 1); + this.loopAll(this.data1, 5); - // check page numbers greater than the last page - try { - testList.get(12); - fail("Should throw a NoSuchElementException!"); - } catch (NoSuchElementException e) { - } - } + this.loopAll(this.data0, 1); + this.loopAll(this.data0, 5); +} @Test - public void testPagingCache() { - // test setup - assertNotNull(testList); - - // read first page, should be cached now - List<String> firstPage = testCacheList.get(0); - assertPage(firstPage, 0, MAX_ITEMS_PER_PAGE, PREFIX_1); - - // change original data - for (int i = 0; i < sourceData.length; i++) { - sourceData[i] = PREFIX_2 + i; - } + public void loopSkip() { + this.loopSkip(this.data10, 0, 5); + this.loopSkip(this.data10, 1, 5); + this.loopSkip(this.data10, 2, 5); + this.loopSkip(this.data10, 3, 5); + + this.loopSkip(this.data10, 8, 5); + this.loopSkip(this.data10, 9, 5); + this.loopSkip(this.data10, 10, 5); +// this.loopSkip(100, 5); skip out of bound + +// this.loopSkip(0, 0); + this.loopSkip(this.data10, 0, 1); + this.loopSkip(this.data10, 0, 10); + this.loopSkip(this.data10, 0, 100); + +// this.loopSkip(0, 0); + this.loopSkip(this.data10, 10, 1); + this.loopSkip(this.data10, 10, 10); + this.loopSkip(this.data10, 10, 100); - // get second page with new content - List<String> secondPage = testCacheList.get(1); - assertPage(secondPage, 1, MAX_ITEMS_PER_PAGE, PREFIX_2); - - // fetch first page again, should have the old values since it is cached - firstPage = testCacheList.get(0); - assertPage(firstPage, 0, MAX_ITEMS_PER_PAGE, PREFIX_1); - - // read a few more pages - testCacheList.get(2); - testCacheList.get(3); - - // fetch first page again, should have the new values since it is not - // cached anymore - firstPage = testCacheList.get(0); - assertPage(firstPage, 0, MAX_ITEMS_PER_PAGE, PREFIX_2); - } + this.loopSkip(this.data1, 0, 5); + this.loopSkip(this.data1, 1, 5); - void assertPage(List<String> page, int pageNumber, int size, String prefix) { - assertNotNull(page); + this.loopSkip(this.data0, 0, 5); +} - // the first page should be full - assertEquals(size, page.size()); + private void loopSkip(String [] data, int skipCount, int pageSize) { + System.out.println("\nloopSkip (" + skipCount + ", " + pageSize + ")"); - // check page content - int counter = 0; - for (String s : page) { - assertEquals(prefix + ((pageNumber * MAX_ITEMS_PER_PAGE) + counter), s); - counter++; + PagingIterable<String> p = this.getIterable(data, pageSize); + assertNotNull(p); + PagingIterator<String> i = (PagingIterator<String>) p.iterator(); + assertNotNull(i); + assertEquals(data.length, i.getTotalNumItems()); + + PagingIterable<String> pp = p.skipTo(skipCount); + assertNotNull(pp); + PagingIterator<String> ii = (PagingIterator<String>) pp.iterator(); + assertNotNull(ii); + assertEquals(data.length, ii.getTotalNumItems()); + + int count = 0; + for (String s : pp) { + assertNotNull(s); + assertEquals("A" + (count + skipCount), s); + System.out.print(s + " "); + count++; + } + System.out.print("\n"); + assertEquals(data.length - skipCount, count); + } + + private void loopAll(String [] data, int pageSize) { + System.out.println("\nloopAll (" + pageSize + ")"); + + PagingIterable<String> p = this.getIterable(data, pageSize); + assertNotNull(p); + PagingIterator<String> i = (PagingIterator<String>) p.iterator(); + assertNotNull(i); + assertEquals(data.length, i.getTotalNumItems()); + + int count = 0; + for (String s : p) { + assertNotNull(s); + System.out.print(s + " "); + count++; } + System.out.print("\n"); + assertEquals(data.length, count); } - // --- Test PagingList --- - - class TestPagingList extends AbstractPagingList<String> { - - public TestPagingList(int cacheSize) { - setCacheSize(cacheSize); - } - - @Override - protected FetchResult fetchPage(int pageNumber) { - int skipCount = pageNumber * getMaxItemsPerPage(); - int lastIndex = skipCount + getMaxItemsPerPage() - 1; - if (lastIndex >= sourceData.length) { - lastIndex = sourceData.length - 1; - } - - if (skipCount >= sourceData.length) { - throw new NoSuchElementException(); - } - - List<String> page = new ArrayList<String>(); - for (int i = skipCount; i <= lastIndex; i++) { - page.add(sourceData[i]); - } - - return new FetchResult(page, BigInteger.valueOf(sourceData.length), - skipCount + getMaxItemsPerPage() < sourceData.length); - } - - @Override - public int getMaxItemsPerPage() { - return MAX_ITEMS_PER_PAGE; - } - } }
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/ReadOnlyDiscoverIT.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/ReadOnlyDiscoverIT.java?rev=936836&r1=936835&r2=936836&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/ReadOnlyDiscoverIT.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/ReadOnlyDiscoverIT.java Thu Apr 22 13:27:21 2010 @@ -18,10 +18,13 @@ */ package org.apache.chemistry.opencmis.fit.runtime; +import org.apache.chemistry.opencmis.client.api.PagingIterable; +import org.apache.chemistry.opencmis.client.api.QueryResult; import org.apache.chemistry.opencmis.commons.enums.CapabilityChanges; import org.apache.chemistry.opencmis.commons.enums.CapabilityQuery; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.junit.Assert; import org.junit.Test; public class ReadOnlyDiscoverIT extends AbstractSessionTest { @@ -30,22 +33,21 @@ public class ReadOnlyDiscoverIT extends @Test public void query() { - CapabilityQuery query = this.session.getRepositoryInfo().getCapabilities().getQueryCapability(); + CapabilityQuery query = this.session.getRepositoryInfo() + .getCapabilities().getQueryCapability(); switch (query) { case NONE: ReadOnlyDiscoverIT.log.info("queries not supported"); break; default: - // PagingList<QueryResult> resultSet = - // this.session.query(FixtureData.QUERY.toString(), false, 2); - // Assert.assertNotNull(resultSet); - // //Assert.assertFalse(resultSet.isEmpty()); - // for (List<QueryResult> lo : resultSet) { - // for (QueryResult o : lo) { - // Assert.assertNotNull(o); - // } - // } + PagingIterable<QueryResult> resultSet = this.session.query( + FixtureData.QUERY.toString(), false, 2); + Assert.assertNotNull(resultSet); + // Assert.assertFalse(resultSet.isEmpty()); + for (QueryResult o : resultSet) { + Assert.assertNotNull(o); + } break; } @@ -54,7 +56,8 @@ public class ReadOnlyDiscoverIT extends @Test public void changes() { - CapabilityChanges changes = this.session.getRepositoryInfo().getCapabilities().getChangesCapability(); + CapabilityChanges changes = this.session.getRepositoryInfo() + .getCapabilities().getChangesCapability(); switch (changes) { case NONE: Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/ReadOnlyNavigationIT.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/ReadOnlyNavigationIT.java?rev=936836&r1=936835&r2=936836&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/ReadOnlyNavigationIT.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/ReadOnlyNavigationIT.java Thu Apr 22 13:27:21 2010 @@ -22,8 +22,10 @@ import java.util.List; import junit.framework.Assert; +import org.apache.chemistry.opencmis.client.api.CmisObject; import org.apache.chemistry.opencmis.client.api.FileableCmisObject; import org.apache.chemistry.opencmis.client.api.Folder; +import org.apache.chemistry.opencmis.client.api.PagingIterable; import org.apache.chemistry.opencmis.client.api.Tree; import org.junit.Test; @@ -35,15 +37,12 @@ public class ReadOnlyNavigationIT extend Folder folder = (Folder) this.session.getObjectByPath(path); Assert.assertNotNull("folder not found: " + path, folder); - // PagingList<CmisObject> pl = folder.getChildren(1); - // Assert.assertNotNull(pl); - // // Assert.assertFalse(pl.isEmpty()); - // - // for (List<CmisObject> cl : pl) { - // for (CmisObject o : cl) { - // Assert.assertNotNull(o); - // } - // } + PagingIterable<CmisObject> pl = folder.getChildren(1); + Assert.assertNotNull(pl); + + for (CmisObject o : pl) { + Assert.assertNotNull(o); + } } @Test @@ -52,15 +51,12 @@ public class ReadOnlyNavigationIT extend Folder folder = (Folder) this.session.getObjectByPath(path); Assert.assertNotNull("folder not found: " + path, folder); - // PagingList<CmisObject> pl = folder.getChildren(1000); - // Assert.assertNotNull(pl); - // // Assert.assertFalse(pl.isEmpty()); - // - // for (List<CmisObject> cl : pl) { - // for (CmisObject o : cl) { - // Assert.assertNotNull(o); - // } - // } + PagingIterable<CmisObject> pl = folder.getChildren(1000); + Assert.assertNotNull(pl); + + for (CmisObject o : pl) { + Assert.assertNotNull(o); + } } @Test @@ -69,15 +65,12 @@ public class ReadOnlyNavigationIT extend Folder folder = (Folder) this.session.getObjectByPath(path); Assert.assertNotNull("folder not found: " + path, folder); - // PagingList<CmisObject> pl = folder.getChildren(2); - // Assert.assertNotNull(pl); - // // Assert.assertFalse(pl.isEmpty()); - // - // for (List<CmisObject> cl : pl) { - // for (CmisObject o : cl) { - // Assert.assertNotNull(o); - // } - // } + PagingIterable<CmisObject> pl = folder.getChildren(2); + Assert.assertNotNull(pl); + + for (CmisObject o : pl) { + Assert.assertNotNull(o); + } } @Test @@ -182,11 +175,10 @@ public class ReadOnlyNavigationIT extend Folder folder = (Folder) this.session.getObjectByPath(path); Assert.assertNotNull("folder not found: " + path, folder); - // PagingList<CmisObject> pl = folder.getChildren(2); - // Assert.assertNotNull(pl); - // // Assert.assertFalse(pl.isEmpty()); - // - // List<CmisObject> firstPage = pl.get(0); - // Assert.assertNotNull(firstPage); + PagingIterable<CmisObject> pl = folder.getChildren(2); + Assert.assertNotNull(pl); + + CmisObject firstObject = pl.iterator().next(); + Assert.assertNotNull(firstObject); } } Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/ReadOnlyTypeIT.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/ReadOnlyTypeIT.java?rev=936836&r1=936835&r2=936836&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/ReadOnlyTypeIT.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/ReadOnlyTypeIT.java Thu Apr 22 13:27:21 2010 @@ -25,6 +25,7 @@ import junit.framework.Assert; import org.apache.chemistry.opencmis.client.api.DocumentType; import org.apache.chemistry.opencmis.client.api.FolderType; import org.apache.chemistry.opencmis.client.api.ObjectType; +import org.apache.chemistry.opencmis.client.api.PagingIterable; import org.apache.chemistry.opencmis.client.api.PolicyType; import org.apache.chemistry.opencmis.client.api.RelationshipType; import org.apache.chemistry.opencmis.client.api.Tree; //import org.apache.chemistry.opencmis.client.api.util.PagingList; @@ -36,7 +37,8 @@ public class ReadOnlyTypeIT extends Abst @Test public void readOptionalBaseTypePolicy() { try { - ObjectType otd = this.session.getTypeDefinition(ObjectType.POLICY_BASETYPE_ID); + ObjectType otd = this.session + .getTypeDefinition(ObjectType.POLICY_BASETYPE_ID); Assert.assertTrue(otd instanceof PolicyType); Assert.assertEquals(ObjectType.POLICY_BASETYPE_ID, otd.getId()); Assert.assertEquals(null, otd.getBaseType()); @@ -48,10 +50,12 @@ public class ReadOnlyTypeIT extends Abst @Test public void readOptionalBaseTypeRelation() { try { - ObjectType otd = this.session.getTypeDefinition(ObjectType.RELATIONSHIP_BASETYPE_ID); + ObjectType otd = this.session + .getTypeDefinition(ObjectType.RELATIONSHIP_BASETYPE_ID); Assert.assertNotNull(otd); Assert.assertTrue(otd instanceof RelationshipType); - Assert.assertEquals(ObjectType.RELATIONSHIP_BASETYPE_ID, otd.getId()); + Assert.assertEquals(ObjectType.RELATIONSHIP_BASETYPE_ID, otd + .getId()); Assert.assertEquals(null, otd.getBaseType()); } catch (CmisObjectNotFoundException e) { // policies not supported @@ -60,7 +64,8 @@ public class ReadOnlyTypeIT extends Abst @Test public void readBaseTypeDocument() { - ObjectType otd = this.session.getTypeDefinition(ObjectType.DOCUMENT_BASETYPE_ID); + ObjectType otd = this.session + .getTypeDefinition(ObjectType.DOCUMENT_BASETYPE_ID); Assert.assertNotNull(otd); Assert.assertTrue(otd instanceof DocumentType); Assert.assertEquals(ObjectType.DOCUMENT_BASETYPE_ID, otd.getId()); @@ -70,7 +75,8 @@ public class ReadOnlyTypeIT extends Abst @Test public void readBaseTypeFolder() { - ObjectType otf = this.session.getTypeDefinition(ObjectType.FOLDER_BASETYPE_ID); + ObjectType otf = this.session + .getTypeDefinition(ObjectType.FOLDER_BASETYPE_ID); Assert.assertNotNull(otf); Assert.assertTrue(otf instanceof FolderType); Assert.assertEquals(ObjectType.FOLDER_BASETYPE_ID, otf.getId()); @@ -79,50 +85,52 @@ public class ReadOnlyTypeIT extends Abst @Test public void readTypeChildrenDocument() { - ObjectType otd = this.session.getTypeDefinition(ObjectType.DOCUMENT_BASETYPE_ID); + ObjectType otd = this.session + .getTypeDefinition(ObjectType.DOCUMENT_BASETYPE_ID); Assert.assertNotNull(otd); - // PagingList<ObjectType> pc = this.session.getTypeChildren(otd.getId(), - // true, 2); - // Assert.assertNotNull(pc); - // - // for (List<ObjectType> children : pc) { - // for (ObjectType ot1 : children) { - // ObjectType ot2 = this.session.getTypeDefinition(ot1.getId()); - // Assert.assertEquals(ot1.getId(), ot2.getId()); - // } - // } + PagingIterable<ObjectType> pc = this.session.getTypeChildren(otd + .getId(), true, 2); + Assert.assertNotNull(pc); + + for (ObjectType ot1 : pc) { + ObjectType ot2 = this.session.getTypeDefinition(ot1.getId()); + Assert.assertEquals(ot1.getId(), ot2.getId()); + } } @Test public void readTypeChildrenFolder() { - ObjectType otd = this.session.getTypeDefinition(ObjectType.FOLDER_BASETYPE_ID); + ObjectType otd = this.session + .getTypeDefinition(ObjectType.FOLDER_BASETYPE_ID); Assert.assertNotNull(otd); - // PagingList<ObjectType> pc = this.session.getTypeChildren(otd.getId(), - // true, 2); - // Assert.assertNotNull(pc); - // - // for (List<ObjectType> children : pc) { - // for (ObjectType ot1 : children) { - // ObjectType ot2 = this.session.getTypeDefinition(ot1.getId()); - // Assert.assertEquals(ot1, ot2); - // } - // } + PagingIterable<ObjectType> pc = this.session.getTypeChildren(otd + .getId(), true, 2); + Assert.assertNotNull(pc); + + for (ObjectType ot1 : pc) { + ObjectType ot2 = this.session.getTypeDefinition(ot1.getId()); + Assert.assertEquals(ot1, ot2); + } } @Test public void readTypeDescandantsDocument() { - ObjectType otd = this.session.getTypeDefinition(ObjectType.DOCUMENT_BASETYPE_ID); + ObjectType otd = this.session + .getTypeDefinition(ObjectType.DOCUMENT_BASETYPE_ID); Assert.assertNotNull(otd); - List<Tree<ObjectType>> desc = this.session.getTypeDescendants(otd.getId(), 1, true); + List<Tree<ObjectType>> desc = this.session.getTypeDescendants(otd + .getId(), 1, true); Assert.assertNotNull(desc); Assert.assertFalse(desc.isEmpty()); } @Test public void readTypeDescandantsFolder() { - ObjectType otd = this.session.getTypeDefinition(ObjectType.FOLDER_BASETYPE_ID); + ObjectType otd = this.session + .getTypeDefinition(ObjectType.FOLDER_BASETYPE_ID); Assert.assertNotNull(otd); - List<Tree<ObjectType>> desc = this.session.getTypeDescendants(otd.getId(), 1, true); + List<Tree<ObjectType>> desc = this.session.getTypeDescendants(otd + .getId(), 1, true); Assert.assertNotNull(desc); desc.isEmpty(); } Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectIT.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectIT.java?rev=936836&r1=936835&r2=936836&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectIT.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectIT.java Thu Apr 22 13:27:21 2010 @@ -41,7 +41,8 @@ public class WriteObjectIT extends Abstr @Test public void createFolder() { - ObjectId parentId = this.session.createObjectId(Fixture.getTestRootId()); + ObjectId parentId = this.session + .createObjectId(Fixture.getTestRootId()); String folderName = UUID.randomUUID().toString(); String typeId = FixtureData.FOLDER_TYPE_ID.value(); @@ -66,13 +67,15 @@ public class WriteObjectIT extends Abstr properties.put(PropertyIds.NAME, folderName); properties.put(PropertyIds.OBJECT_TYPE_ID, typeId); - ObjectId id = this.session.createFolder(properties, parentId, null, null, null); + ObjectId id = this.session.createFolder(properties, parentId, null, + null, null); assertNotNull(id); } @Test public void createDocument() throws IOException { - ObjectId parentId = this.session.createObjectId(Fixture.getTestRootId()); + ObjectId parentId = this.session + .createObjectId(Fixture.getTestRootId()); String folderName = UUID.randomUUID().toString(); String typeId = FixtureData.DOCUMENT_TYPE_ID.value(); @@ -106,12 +109,12 @@ public class WriteObjectIT extends Abstr byte[] buf1 = content1.getBytes("UTF-8"); ByteArrayInputStream in1 = new ByteArrayInputStream(buf1); - ContentStream contentStream = this.session.getObjectFactory().createContentStream(filename, buf1.length, - mimetype, in1); + ContentStream contentStream = this.session.getObjectFactory() + .createContentStream(filename, buf1.length, mimetype, in1); assertNotNull(contentStream); - ObjectId id = this.session.createDocument(properties, parentId, contentStream, VersioningState.NONE, null, - null, null); + ObjectId id = this.session.createDocument(properties, parentId, + contentStream, VersioningState.NONE, null, null, null); assertNotNull(id); // verify content @@ -128,12 +131,16 @@ public class WriteObjectIT extends Abstr public void createDocumentFromSource() throws IOException { try { // verify content - String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + FixtureData.DOCUMENT1_NAME; - Document srcDocument = (Document) this.session.getObjectByPath(path); + String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + + FixtureData.DOCUMENT1_NAME; + Document srcDocument = (Document) this.session + .getObjectByPath(path); assertNotNull("Document not found: " + path, srcDocument); - String srcContent = this.getContentAsString(srcDocument.getContentStream()); + String srcContent = this.getContentAsString(srcDocument + .getContentStream()); - ObjectId parentFolder = session.createObjectId(Fixture.getTestRootId()); + ObjectId parentFolder = session.createObjectId(Fixture + .getTestRootId()); /* * List<Property<?>> srcProperties = srcDocument.getProperties(); * assertNotNull(srcProperties); List<Property<?>> dstProperties = @@ -151,11 +158,14 @@ public class WriteObjectIT extends Abstr Map<String, Object> properties = new HashMap<String, Object>(); properties.put(PropertyIds.NAME, name); - ObjectId dstDocumentId = this.session.createDocumentFromSource(srcDocument, properties, parentFolder, + ObjectId dstDocumentId = this.session.createDocumentFromSource( + srcDocument, properties, parentFolder, VersioningState.NONE, null, null, null); assertNotNull(dstDocumentId); - Document dstDocument = (Document) this.session.getObject(dstDocumentId); - String dstContent = this.getContentAsString(dstDocument.getContentStream()); + Document dstDocument = (Document) this.session + .getObject(dstDocumentId); + String dstContent = this.getContentAsString(dstDocument + .getContentStream()); assertEquals(srcContent, dstContent); } catch (CmisNotSupportedException e) { @@ -168,7 +178,8 @@ public class WriteObjectIT extends Abstr public void deleteAndCreateContent() throws IOException { // verify content - String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + FixtureData.DOCUMENT1_NAME; + String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + + FixtureData.DOCUMENT1_NAME; Document document = (Document) this.session.getObjectByPath(path); assertNotNull("Document not found: " + path, document); @@ -189,7 +200,8 @@ public class WriteObjectIT extends Abstr byte[] buf1 = content1.getBytes("UTF-8"); ByteArrayInputStream in1 = new ByteArrayInputStream(buf1); - contentStream = this.session.getObjectFactory().createContentStream(filename, buf1.length, mimetype, in1); + contentStream = this.session.getObjectFactory().createContentStream( + filename, buf1.length, mimetype, in1); assertNotNull(contentStream); document.setContentStream(contentStream, true); @@ -206,7 +218,8 @@ public class WriteObjectIT extends Abstr @Test public void updateProperties() { // verify content - String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + FixtureData.DOCUMENT1_NAME; + String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + + FixtureData.DOCUMENT1_NAME; Document document = (Document) this.session.getObjectByPath(path); assertNotNull("Document not found: " + path, document); Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/sample/AbstractSampleIT.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/sample/AbstractSampleIT.java?rev=936836&r1=936835&r2=936836&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/sample/AbstractSampleIT.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/sample/AbstractSampleIT.java Thu Apr 22 13:27:21 2010 @@ -27,7 +27,7 @@ import static org.junit.Assert.assertTru import java.util.List; import org.apache.chemistry.opencmis.client.api.ObjectType; -import org.apache.chemistry.opencmis.client.api.PagingList; +import org.apache.chemistry.opencmis.client.api.PagingIterable; import org.apache.chemistry.opencmis.client.api.Session; import org.apache.chemistry.opencmis.client.api.Tree; import org.apache.chemistry.opencmis.commons.api.RepositoryInfo; @@ -95,7 +95,8 @@ public abstract class AbstractSampleIT { String folderBaseId = "cmis:folder"; // check document type definition - ObjectType documentType = getSession().getTypeDefinition(documentBaseId); + ObjectType documentType = getSession() + .getTypeDefinition(documentBaseId); checkBaseType(documentBaseId, BaseTypeId.CMIS_DOCUMENT, documentType); // check folder type definition @@ -103,20 +104,13 @@ public abstract class AbstractSampleIT { checkBaseType(folderBaseId, BaseTypeId.CMIS_FOLDER, folderType); // get base types via getTypesChildren - PagingList<ObjectType> baseTypes = getSession().getTypeChildren(null, true, 10); + PagingIterable<ObjectType> baseTypes = getSession().getTypeChildren( + null, true, 10); assertNotNull(baseTypes); - List<ObjectType> baseTypePage = baseTypes.get(0); - assertNotNull(baseTypePage); - assertTrue(baseTypePage.size() >= 2); - assertTrue(baseTypePage.size() <= 4); - - assertEquals(1, baseTypes.size()); - assertEquals(baseTypePage.size(), baseTypes.getNumItems()); - boolean hasDocumentBaseType = false; boolean hasFolderBaseType = false; - for (ObjectType ot : baseTypePage) { + for (ObjectType ot : baseTypes) { checkBaseType(null, null, ot); if (ot.getId().equals(documentBaseId)) { @@ -132,7 +126,8 @@ public abstract class AbstractSampleIT { assertTrue(hasFolderBaseType); // get base types via getTypeDescendants - List<Tree<ObjectType>> baseTypeDesc = getSession().getTypeDescendants(null, -1, true); + List<Tree<ObjectType>> baseTypeDesc = getSession().getTypeDescendants( + null, -1, true); assertNotNull(baseTypeDesc); hasDocumentBaseType = false; @@ -157,7 +152,8 @@ public abstract class AbstractSampleIT { /** * Checks a base type. */ - private void checkBaseType(String id, BaseTypeId baseType, ObjectType objectType) { + private void checkBaseType(String id, BaseTypeId baseType, + ObjectType objectType) { assertNotNull(objectType); if (id != null) { assertEquals(id, objectType.getId());
