Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/VersioningServiceImpl.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/VersioningServiceImpl.java?rev=936922&r1=936921&r2=936922&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/VersioningServiceImpl.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/VersioningServiceImpl.java Thu Apr 22 16:04:19 2010 @@ -48,128 +48,128 @@ import org.apache.chemistry.opencmis.com */ public class VersioningServiceImpl extends AbstractWebServicesService implements VersioningService { - private final PortProvider fPortProvider; + private final PortProvider fPortProvider; - /** - * Constructor. - */ - public VersioningServiceImpl(Session session, PortProvider portProvider) { - setSession(session); - fPortProvider = portProvider; - } - - public void checkOut(String repositoryId, Holder<String> objectId, ExtensionsData extension, - Holder<Boolean> contentCopied) { - VersioningServicePort port = fPortProvider.getVersioningServicePort(); - - try { - javax.xml.ws.Holder<String> portObjectId = convertHolder(objectId); - javax.xml.ws.Holder<Boolean> portContentCopied = new javax.xml.ws.Holder<Boolean>(); - javax.xml.ws.Holder<CmisExtensionType> portExtension = convertExtensionHolder(extension); - - port.checkOut(repositoryId, portObjectId, portExtension, portContentCopied); - - setHolderValue(portObjectId, objectId); - setHolderValue(portContentCopied, contentCopied); - setExtensionValues(portExtension, extension); - } catch (CmisException e) { - throw convertException(e); - } catch (Exception e) { - throw new CmisRuntimeException("Error: " + e.getMessage(), e); - } - } - - public void cancelCheckOut(String repositoryId, String objectId, ExtensionsData extension) { - VersioningServicePort port = fPortProvider.getVersioningServicePort(); - - try { - javax.xml.ws.Holder<CmisExtensionType> portExtension = convertExtensionHolder(extension); - - port.cancelCheckOut(repositoryId, objectId, portExtension); - - setExtensionValues(portExtension, extension); - } catch (CmisException e) { - throw convertException(e); - } catch (Exception e) { - throw new CmisRuntimeException("Error: " + e.getMessage(), e); - } - } - - public void checkIn(String repositoryId, Holder<String> objectId, Boolean major, Properties properties, - ContentStream contentStream, String checkinComment, List<String> policies, Acl addACEs, Acl removeACEs, - ExtensionsData extension) { - VersioningServicePort port = fPortProvider.getVersioningServicePort(); - - try { - javax.xml.ws.Holder<String> portObjectId = convertHolder(objectId); - javax.xml.ws.Holder<CmisExtensionType> portExtension = convertExtensionHolder(extension); - - port.checkIn(repositoryId, portObjectId, major, convert(properties), convert(contentStream), - checkinComment, policies, convert(addACEs), convert(removeACEs), portExtension); - - setHolderValue(portObjectId, objectId); - setExtensionValues(portExtension, extension); - } catch (CmisException e) { - throw convertException(e); - } catch (Exception e) { - throw new CmisRuntimeException("Error: " + e.getMessage(), e); - } - } - - public List<ObjectData> getAllVersions(String repositoryId, String objectId, String versionSeriesId, String filter, - Boolean includeAllowableActions, ExtensionsData extension) { - VersioningServicePort port = fPortProvider.getVersioningServicePort(); - - try { - List<CmisObjectType> versionList = port.getAllVersions(repositoryId, versionSeriesId, filter, - includeAllowableActions, convert(extension)); - - // no list? - if (versionList == null) { - return null; - } - - // convert list - List<ObjectData> result = new ArrayList<ObjectData>(); - for (CmisObjectType version : versionList) { - result.add(convert(version)); - } - - return result; - } catch (CmisException e) { - throw convertException(e); - } catch (Exception e) { - throw new CmisRuntimeException("Error: " + e.getMessage(), e); - } - } - - public ObjectData getObjectOfLatestVersion(String repositoryId, String objectId, String versionSeriesId, - Boolean major, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, - String renditionFilter, Boolean includePolicyIds, Boolean includeACL, ExtensionsData extension) { - VersioningServicePort port = fPortProvider.getVersioningServicePort(); - - try { - return convert(port.getObjectOfLatestVersion(repositoryId, versionSeriesId, major, filter, - includeAllowableActions, convert(EnumIncludeRelationships.class, includeRelationships), - renditionFilter, includePolicyIds, includeACL, convert(extension))); - } catch (CmisException e) { - throw convertException(e); - } catch (Exception e) { - throw new CmisRuntimeException("Error: " + e.getMessage(), e); - } - } - - public Properties getPropertiesOfLatestVersion(String repositoryId, String objectId, String versionSeriesId, - Boolean major, String filter, ExtensionsData extension) { - VersioningServicePort port = fPortProvider.getVersioningServicePort(); - - try { - return convert(port.getPropertiesOfLatestVersion(repositoryId, versionSeriesId, major, filter, - convert(extension))); - } catch (CmisException e) { - throw convertException(e); - } catch (Exception e) { - throw new CmisRuntimeException("Error: " + e.getMessage(), e); - } - } + /** + * Constructor. + */ + public VersioningServiceImpl(Session session, PortProvider portProvider) { + setSession(session); + fPortProvider = portProvider; + } + + public void checkOut(String repositoryId, Holder<String> objectId, ExtensionsData extension, + Holder<Boolean> contentCopied) { + VersioningServicePort port = fPortProvider.getVersioningServicePort(); + + try { + javax.xml.ws.Holder<String> portObjectId = convertHolder(objectId); + javax.xml.ws.Holder<Boolean> portContentCopied = new javax.xml.ws.Holder<Boolean>(); + javax.xml.ws.Holder<CmisExtensionType> portExtension = convertExtensionHolder(extension); + + port.checkOut(repositoryId, portObjectId, portExtension, portContentCopied); + + setHolderValue(portObjectId, objectId); + setHolderValue(portContentCopied, contentCopied); + setExtensionValues(portExtension, extension); + } catch (CmisException e) { + throw convertException(e); + } catch (Exception e) { + throw new CmisRuntimeException("Error: " + e.getMessage(), e); + } + } + + public void cancelCheckOut(String repositoryId, String objectId, ExtensionsData extension) { + VersioningServicePort port = fPortProvider.getVersioningServicePort(); + + try { + javax.xml.ws.Holder<CmisExtensionType> portExtension = convertExtensionHolder(extension); + + port.cancelCheckOut(repositoryId, objectId, portExtension); + + setExtensionValues(portExtension, extension); + } catch (CmisException e) { + throw convertException(e); + } catch (Exception e) { + throw new CmisRuntimeException("Error: " + e.getMessage(), e); + } + } + + public void checkIn(String repositoryId, Holder<String> objectId, Boolean major, Properties properties, + ContentStream contentStream, String checkinComment, List<String> policies, Acl addACEs, Acl removeACEs, + ExtensionsData extension) { + VersioningServicePort port = fPortProvider.getVersioningServicePort(); + + try { + javax.xml.ws.Holder<String> portObjectId = convertHolder(objectId); + javax.xml.ws.Holder<CmisExtensionType> portExtension = convertExtensionHolder(extension); + + port.checkIn(repositoryId, portObjectId, major, convert(properties), convert(contentStream), + checkinComment, policies, convert(addACEs), convert(removeACEs), portExtension); + + setHolderValue(portObjectId, objectId); + setExtensionValues(portExtension, extension); + } catch (CmisException e) { + throw convertException(e); + } catch (Exception e) { + throw new CmisRuntimeException("Error: " + e.getMessage(), e); + } + } + + public List<ObjectData> getAllVersions(String repositoryId, String objectId, String versionSeriesId, String filter, + Boolean includeAllowableActions, ExtensionsData extension) { + VersioningServicePort port = fPortProvider.getVersioningServicePort(); + + try { + List<CmisObjectType> versionList = port.getAllVersions(repositoryId, versionSeriesId, filter, + includeAllowableActions, convert(extension)); + + // no list? + if (versionList == null) { + return null; + } + + // convert list + List<ObjectData> result = new ArrayList<ObjectData>(); + for (CmisObjectType version : versionList) { + result.add(convert(version)); + } + + return result; + } catch (CmisException e) { + throw convertException(e); + } catch (Exception e) { + throw new CmisRuntimeException("Error: " + e.getMessage(), e); + } + } + + public ObjectData getObjectOfLatestVersion(String repositoryId, String objectId, String versionSeriesId, + Boolean major, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, + String renditionFilter, Boolean includePolicyIds, Boolean includeACL, ExtensionsData extension) { + VersioningServicePort port = fPortProvider.getVersioningServicePort(); + + try { + return convert(port.getObjectOfLatestVersion(repositoryId, versionSeriesId, major, filter, + includeAllowableActions, convert(EnumIncludeRelationships.class, includeRelationships), + renditionFilter, includePolicyIds, includeACL, convert(extension))); + } catch (CmisException e) { + throw convertException(e); + } catch (Exception e) { + throw new CmisRuntimeException("Error: " + e.getMessage(), e); + } + } + + public Properties getPropertiesOfLatestVersion(String repositoryId, String objectId, String versionSeriesId, + Boolean major, String filter, ExtensionsData extension) { + VersioningServicePort port = fPortProvider.getVersioningServicePort(); + + try { + return convert(port.getPropertiesOfLatestVersion(repositoryId, versionSeriesId, major, filter, + convert(extension))); + } catch (CmisException e) { + throw convertException(e); + } catch (Exception e) { + throw new CmisRuntimeException("Error: " + e.getMessage(), e); + } + } }
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AclMergeTest.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AclMergeTest.java?rev=936922&r1=936921&r2=936922&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AclMergeTest.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AclMergeTest.java Thu Apr 22 16:04:19 2010 @@ -41,105 +41,105 @@ import org.apache.chemistry.opencmis.com */ public class AclMergeTest extends TestCase { - public void testIsACLMergeRequired() throws Exception { - AtomPubService service = new AtomPubService(); + public void testIsACLMergeRequired() throws Exception { + AtomPubService service = new AtomPubService(); - assertFalse(service.publicIsACLMergeRequired(null, null)); - assertFalse(service.publicIsACLMergeRequired(new AccessControlListImpl(), null)); - assertFalse(service.publicIsACLMergeRequired(null, new AccessControlListImpl())); - assertFalse(service.publicIsACLMergeRequired(new AccessControlListImpl(), new AccessControlListImpl())); - } - - public void testAclMerge() throws Exception { - AtomPubService service = new AtomPubService(); - - // original - Map<String, String[]> originalAceData = new HashMap<String, String[]>(); - - originalAceData.put("p1", new String[] { "perm:read", "perm:write", "perm:delete" }); - originalAceData.put("p2", new String[] { "perm:read" }); - originalAceData.put("p3", new String[] { "perm:all" }); - - Acl originalACEs = createACL(originalAceData); - - // add - Map<String, String[]> addAceData = new HashMap<String, String[]>(); - - addAceData.put("p2", new String[] { "perm:write" }); - addAceData.put("p4", new String[] { "perm:all" }); - - Acl addACEs = createACL(addAceData); - - // remove - Map<String, String[]> removeAceData = new HashMap<String, String[]>(); - - removeAceData.put("p1", new String[] { "perm:write" }); - removeAceData.put("p3", new String[] { "perm:all" }); - - Acl removeACEs = createACL(removeAceData); - - Acl newACL = service.publicMergeACLs(originalACEs, addACEs, removeACEs); - - assertEquals(3, newACL.getAces().size()); - - for (Ace ace : newACL.getAces()) { - String principal = ace.getPrincipal().getId(); - assertNotNull(principal); - - if (principal.equals("p1")) { - assertEquals(2, ace.getPermissions().size()); - assertTrue(ace.getPermissions().contains("perm:read")); - assertTrue(ace.getPermissions().contains("perm:delete")); - assertFalse(ace.getPermissions().contains("perm:write")); - } else if (principal.equals("p2")) { - assertEquals(2, ace.getPermissions().size()); - assertTrue(ace.getPermissions().contains("perm:read")); - assertTrue(ace.getPermissions().contains("perm:write")); - } else if (principal.equals("p3")) { - fail("Principal should be deleted!"); - } else if (principal.equals("p4")) { - assertEquals(1, ace.getPermissions().size()); - assertTrue(ace.getPermissions().contains("perm:all")); - } - } - } - - /** - * Creates an ACL structure from a Map. - */ - private Acl createACL(Map<String, String[]> aceData) { - AccessControlListImpl result = new AccessControlListImpl(); - - List<Ace> aces = new ArrayList<Ace>(); - - for (Map.Entry<String, String[]> e : aceData.entrySet()) { - ArrayList<String> permissions = new ArrayList<String>(); - - for (String s : e.getValue()) { - permissions.add(s); - } - - AccessControlEntryImpl ace = new AccessControlEntryImpl(new AccessControlPrincipalDataImpl(e.getKey()), - permissions); - - aces.add(ace); - } - - result.setAces(aces); - - return result; - } - - /** - * A class to make a few protected methods publicly available. - */ - private static class AtomPubService extends AbstractAtomPubService { - public Acl publicMergeACLs(Acl originalACEs, Acl addACEs, Acl removeACEs) { - return mergeAcls(originalACEs, addACEs, removeACEs); - } - - public boolean publicIsACLMergeRequired(Acl addACEs, Acl removeACEs) { - return isAclMergeRequired(addACEs, removeACEs); - } - } + assertFalse(service.publicIsACLMergeRequired(null, null)); + assertFalse(service.publicIsACLMergeRequired(new AccessControlListImpl(), null)); + assertFalse(service.publicIsACLMergeRequired(null, new AccessControlListImpl())); + assertFalse(service.publicIsACLMergeRequired(new AccessControlListImpl(), new AccessControlListImpl())); + } + + public void testAclMerge() throws Exception { + AtomPubService service = new AtomPubService(); + + // original + Map<String, String[]> originalAceData = new HashMap<String, String[]>(); + + originalAceData.put("p1", new String[] { "perm:read", "perm:write", "perm:delete" }); + originalAceData.put("p2", new String[] { "perm:read" }); + originalAceData.put("p3", new String[] { "perm:all" }); + + Acl originalACEs = createACL(originalAceData); + + // add + Map<String, String[]> addAceData = new HashMap<String, String[]>(); + + addAceData.put("p2", new String[] { "perm:write" }); + addAceData.put("p4", new String[] { "perm:all" }); + + Acl addACEs = createACL(addAceData); + + // remove + Map<String, String[]> removeAceData = new HashMap<String, String[]>(); + + removeAceData.put("p1", new String[] { "perm:write" }); + removeAceData.put("p3", new String[] { "perm:all" }); + + Acl removeACEs = createACL(removeAceData); + + Acl newACL = service.publicMergeACLs(originalACEs, addACEs, removeACEs); + + assertEquals(3, newACL.getAces().size()); + + for (Ace ace : newACL.getAces()) { + String principal = ace.getPrincipal().getId(); + assertNotNull(principal); + + if (principal.equals("p1")) { + assertEquals(2, ace.getPermissions().size()); + assertTrue(ace.getPermissions().contains("perm:read")); + assertTrue(ace.getPermissions().contains("perm:delete")); + assertFalse(ace.getPermissions().contains("perm:write")); + } else if (principal.equals("p2")) { + assertEquals(2, ace.getPermissions().size()); + assertTrue(ace.getPermissions().contains("perm:read")); + assertTrue(ace.getPermissions().contains("perm:write")); + } else if (principal.equals("p3")) { + fail("Principal should be deleted!"); + } else if (principal.equals("p4")) { + assertEquals(1, ace.getPermissions().size()); + assertTrue(ace.getPermissions().contains("perm:all")); + } + } + } + + /** + * Creates an ACL structure from a Map. + */ + private Acl createACL(Map<String, String[]> aceData) { + AccessControlListImpl result = new AccessControlListImpl(); + + List<Ace> aces = new ArrayList<Ace>(); + + for (Map.Entry<String, String[]> e : aceData.entrySet()) { + ArrayList<String> permissions = new ArrayList<String>(); + + for (String s : e.getValue()) { + permissions.add(s); + } + + AccessControlEntryImpl ace = new AccessControlEntryImpl(new AccessControlPrincipalDataImpl(e.getKey()), + permissions); + + aces.add(ace); + } + + result.setAces(aces); + + return result; + } + + /** + * A class to make a few protected methods publicly available. + */ + private static class AtomPubService extends AbstractAtomPubService { + public Acl publicMergeACLs(Acl originalACEs, Acl addACEs, Acl removeACEs) { + return mergeAcls(originalACEs, addACEs, removeACEs); + } + + public boolean publicIsACLMergeRequired(Acl addACEs, Acl removeACEs) { + return isAclMergeRequired(addACEs, removeACEs); + } + } } Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java?rev=936922&r1=936921&r2=936922&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java Thu Apr 22 16:04:19 2010 @@ -48,113 +48,113 @@ import org.apache.chemistry.opencmis.com */ public class AtomParserTest extends TestCase { - private static final byte[] CONTENT = "This is my test content!".getBytes(); - private static final String CONTENT_TYPE = "text/plain"; + private static final byte[] CONTENT = "This is my test content!".getBytes(); + private static final String CONTENT_TYPE = "text/plain"; - public void testParser() throws Exception { - ByteArrayOutputStream bao = new ByteArrayOutputStream(); + public void testParser() throws Exception { + ByteArrayOutputStream bao = new ByteArrayOutputStream(); - // set up an object - CmisPropertiesType properties = new CmisPropertiesType(); + // set up an object + CmisPropertiesType properties = new CmisPropertiesType(); - CmisPropertyString propName = new CmisPropertyString(); - propName.setPropertyDefinitionId(PropertyIds.NAME); - propName.getValue().add("TestName"); - properties.getProperty().add(propName); - - CmisPropertyInteger propInt = new CmisPropertyInteger(); - propInt.setPropertyDefinitionId("IntProp"); - propInt.getValue().add(BigInteger.valueOf(1)); - propInt.getValue().add(BigInteger.valueOf(2)); - propInt.getValue().add(BigInteger.valueOf(3)); - properties.getProperty().add(propInt); - - CmisPropertyDecimal propDec = new CmisPropertyDecimal(); - propDec.setPropertyDefinitionId("DecProp"); - propDec.getValue().add( - new BigDecimal("3.14159253589793238462643383279502884197" - + "169399375105820974944592307816406286208998628034825342117067982148086513")); - properties.getProperty().add(propDec); - - CmisObjectType object1 = new CmisObjectType(); - object1.setProperties(properties); - - // write the entry - AtomEntryWriter aew = new AtomEntryWriter(object1, CONTENT_TYPE, new ByteArrayInputStream(CONTENT)); - aew.write(bao); - - byte[] entryContent = bao.toByteArray(); - assertTrue(entryContent.length > 0); - - String entryContentStr = new String(entryContent, "UTF-8"); - System.out.println(entryContentStr); - - // parse it - AtomPubParser parser = new AtomPubParser(new ByteArrayInputStream(entryContent)); - parser.parse(); - AtomBase parseResult = parser.getResults(); - - assertTrue(parseResult instanceof AtomEntry); - AtomEntry entry = (AtomEntry) parseResult; - - assertNotNull(entry); - assertTrue(entry.getElements().size() > 0); - - // find the object - CmisObjectType object2 = null; - for (AtomElement element : entry.getElements()) { - if (element.getObject() instanceof CmisObjectType) { - assertNull(object2); - object2 = (CmisObjectType) element.getObject(); - } - } - - assertNotNull(object2); - assertNotNull(object2.getProperties()); - - // compare properteis - for (CmisProperty property1 : object1.getProperties().getProperty()) { - boolean found = false; - - for (CmisProperty property2 : object2.getProperties().getProperty()) { - if (property1.getPropertyDefinitionId().equals(property2.getPropertyDefinitionId())) { - found = true; - - assertEquals(property1, property2); - break; - } - } - - assertTrue(found); - } - } - - protected void assertEquals(CmisProperty expected, CmisProperty actual) throws Exception { - if ((expected == null) && (actual == null)) { - return; - } - - if ((expected == null) || (actual == null)) { - fail("Property is null!"); - } - - assertEquals(expected.getPropertyDefinitionId(), actual.getPropertyDefinitionId()); - assertEquals(expected.getClass(), actual.getClass()); - - Method m1 = expected.getClass().getMethod("getValue", new Class<?>[0]); - List<?> values1 = (List<?>) m1.invoke(expected, new Object[0]); - assertNotNull(values1); - assertFalse(values1.isEmpty()); - - Method m2 = actual.getClass().getMethod("getValue", new Class<?>[0]); - List<?> values2 = (List<?>) m2.invoke(actual, new Object[0]); - assertNotNull(values2); - assertFalse(values2.isEmpty()); - - assertEquals(values1.size(), values2.size()); - - for (int i = 0; i < values1.size(); i++) { - assertEquals(values1.get(i), values2.get(i)); - } - } + CmisPropertyString propName = new CmisPropertyString(); + propName.setPropertyDefinitionId(PropertyIds.NAME); + propName.getValue().add("TestName"); + properties.getProperty().add(propName); + + CmisPropertyInteger propInt = new CmisPropertyInteger(); + propInt.setPropertyDefinitionId("IntProp"); + propInt.getValue().add(BigInteger.valueOf(1)); + propInt.getValue().add(BigInteger.valueOf(2)); + propInt.getValue().add(BigInteger.valueOf(3)); + properties.getProperty().add(propInt); + + CmisPropertyDecimal propDec = new CmisPropertyDecimal(); + propDec.setPropertyDefinitionId("DecProp"); + propDec.getValue().add( + new BigDecimal("3.14159253589793238462643383279502884197" + + "169399375105820974944592307816406286208998628034825342117067982148086513")); + properties.getProperty().add(propDec); + + CmisObjectType object1 = new CmisObjectType(); + object1.setProperties(properties); + + // write the entry + AtomEntryWriter aew = new AtomEntryWriter(object1, CONTENT_TYPE, new ByteArrayInputStream(CONTENT)); + aew.write(bao); + + byte[] entryContent = bao.toByteArray(); + assertTrue(entryContent.length > 0); + + String entryContentStr = new String(entryContent, "UTF-8"); + System.out.println(entryContentStr); + + // parse it + AtomPubParser parser = new AtomPubParser(new ByteArrayInputStream(entryContent)); + parser.parse(); + AtomBase parseResult = parser.getResults(); + + assertTrue(parseResult instanceof AtomEntry); + AtomEntry entry = (AtomEntry) parseResult; + + assertNotNull(entry); + assertTrue(entry.getElements().size() > 0); + + // find the object + CmisObjectType object2 = null; + for (AtomElement element : entry.getElements()) { + if (element.getObject() instanceof CmisObjectType) { + assertNull(object2); + object2 = (CmisObjectType) element.getObject(); + } + } + + assertNotNull(object2); + assertNotNull(object2.getProperties()); + + // compare properteis + for (CmisProperty property1 : object1.getProperties().getProperty()) { + boolean found = false; + + for (CmisProperty property2 : object2.getProperties().getProperty()) { + if (property1.getPropertyDefinitionId().equals(property2.getPropertyDefinitionId())) { + found = true; + + assertEquals(property1, property2); + break; + } + } + + assertTrue(found); + } + } + + protected void assertEquals(CmisProperty expected, CmisProperty actual) throws Exception { + if ((expected == null) && (actual == null)) { + return; + } + + if ((expected == null) || (actual == null)) { + fail("Property is null!"); + } + + assertEquals(expected.getPropertyDefinitionId(), actual.getPropertyDefinitionId()); + assertEquals(expected.getClass(), actual.getClass()); + + Method m1 = expected.getClass().getMethod("getValue", new Class<?>[0]); + List<?> values1 = (List<?>) m1.invoke(expected, new Object[0]); + assertNotNull(values1); + assertFalse(values1.isEmpty()); + + Method m2 = actual.getClass().getMethod("getValue", new Class<?>[0]); + List<?> values2 = (List<?>) m2.invoke(actual, new Object[0]); + assertNotNull(values2); + assertFalse(values2.isEmpty()); + + assertEquals(values1.size(), values2.size()); + + for (int i = 0; i < values1.size(); i++) { + assertEquals(values1.get(i), values2.get(i)); + } + } } Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomPubTestBindingFactory.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomPubTestBindingFactory.java?rev=936922&r1=936921&r2=936922&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomPubTestBindingFactory.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomPubTestBindingFactory.java Thu Apr 22 16:04:19 2010 @@ -31,18 +31,18 @@ import org.apache.chemistry.opencmis.com */ public class AtomPubTestBindingFactory { - public static CmisBinding createBinding(String atomPubUrl, String user, String password) { - // gather parameters - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put(SessionParameter.USER, user); - parameters.put(SessionParameter.PASSWORD, password); + public static CmisBinding createBinding(String atomPubUrl, String user, String password) { + // gather parameters + Map<String, String> parameters = new HashMap<String, String>(); + parameters.put(SessionParameter.USER, user); + parameters.put(SessionParameter.PASSWORD, password); - parameters.put(SessionParameter.ATOMPUB_URL, atomPubUrl); + parameters.put(SessionParameter.ATOMPUB_URL, atomPubUrl); - // get factory and create provider - CmisBindingFactory factory = CmisBindingFactory.newInstance(); - CmisBinding binding = factory.createCmisAtomPubBinding(parameters); + // get factory and create provider + CmisBindingFactory factory = CmisBindingFactory.newInstance(); + CmisBinding binding = factory.createCmisAtomPubBinding(parameters); - return binding; - } + return binding; + } } Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadOnlyTests.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadOnlyTests.java?rev=936922&r1=936921&r2=936922&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadOnlyTests.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadOnlyTests.java Thu Apr 22 16:04:19 2010 @@ -30,36 +30,36 @@ import org.apache.chemistry.opencmis.com */ public class SimpleReadOnlyTests extends AbstractSimpleReadOnlyTests { - private Set<String> fTests; + private Set<String> fTests; - public SimpleReadOnlyTests() { - fTests = new HashSet<String>(); - fTests.add(TEST_REPOSITORY_INFO); - fTests.add(TEST_TYPES); - fTests.add(TEST_NAVIGATION); - fTests.add(TEST_CONTENT_STREAM); - fTests.add(TEST_QUERY); - fTests.add(TEST_CHECKEDOUT); - fTests.add(TEST_CONTENT_CHANGES); - } + public SimpleReadOnlyTests() { + fTests = new HashSet<String>(); + fTests.add(TEST_REPOSITORY_INFO); + fTests.add(TEST_TYPES); + fTests.add(TEST_NAVIGATION); + fTests.add(TEST_CONTENT_STREAM); + fTests.add(TEST_QUERY); + fTests.add(TEST_CHECKEDOUT); + fTests.add(TEST_CONTENT_CHANGES); + } - @Override - protected CmisBinding createBinding() { - // Add the default Java cookie manager from Java 1.6 to optimize - // authentication - // by reusing the common case where a token is stored in a cookie. - // Note: Enable cookie management requires Java 1.6, uncomment the - // following two lines to - // enable cookie management for the tests. - // java.net.CookieManager cm = new java.net.CookieManager(null, - // CookiePolicy.ACCEPT_ALL); - // java.net.CookieHandler.setDefault(cm); + @Override + protected CmisBinding createBinding() { + // Add the default Java cookie manager from Java 1.6 to optimize + // authentication + // by reusing the common case where a token is stored in a cookie. + // Note: Enable cookie management requires Java 1.6, uncomment the + // following two lines to + // enable cookie management for the tests. + // java.net.CookieManager cm = new java.net.CookieManager(null, + // CookiePolicy.ACCEPT_ALL); + // java.net.CookieHandler.setDefault(cm); - return AtomPubTestBindingFactory.createBinding(getAtomPubURL(), getUsername(), getPassword()); - } + return AtomPubTestBindingFactory.createBinding(getAtomPubURL(), getUsername(), getPassword()); + } - @Override - protected Set<String> getEnabledTests() { - return fTests; - } + @Override + protected Set<String> getEnabledTests() { + return fTests; + } } Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadWriteTests.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadWriteTests.java?rev=936922&r1=936921&r2=936922&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadWriteTests.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadWriteTests.java Thu Apr 22 16:04:19 2010 @@ -30,36 +30,36 @@ import org.apache.chemistry.opencmis.com */ public class SimpleReadWriteTests extends AbstractSimpleReadWriteTests { - private Set<String> fTests; + private Set<String> fTests; - public SimpleReadWriteTests() { - fTests = new HashSet<String>(); - fTests.add(TEST_CREATE_FOLDER); - fTests.add(TEST_CREATE_DOCUMENT); - fTests.add(TEST_SET_AND_DELETE_CONTENT); - fTests.add(TEST_UPDATE_PROPERTIES); - fTests.add(TEST_DELETE_TREE); - fTests.add(TEST_MOVE_OBJECT); - fTests.add(TEST_VERSIONING); - } + public SimpleReadWriteTests() { + fTests = new HashSet<String>(); + fTests.add(TEST_CREATE_FOLDER); + fTests.add(TEST_CREATE_DOCUMENT); + fTests.add(TEST_SET_AND_DELETE_CONTENT); + fTests.add(TEST_UPDATE_PROPERTIES); + fTests.add(TEST_DELETE_TREE); + fTests.add(TEST_MOVE_OBJECT); + fTests.add(TEST_VERSIONING); + } - @Override - protected CmisBinding createBinding() { - // Add the default Java cookie manager from Java 1.6 to optimize - // authentication - // by reusing the common case where a token is stored in a cookie. - // Note: Enable cookie management requires Java 1.6, uncomment the - // following two lines to - // enable cookie management for the tests. - // java.net.CookieManager cm = new java.net.CookieManager(null, - // CookiePolicy.ACCEPT_ALL); - // java.net.CookieHandler.setDefault(cm); + @Override + protected CmisBinding createBinding() { + // Add the default Java cookie manager from Java 1.6 to optimize + // authentication + // by reusing the common case where a token is stored in a cookie. + // Note: Enable cookie management requires Java 1.6, uncomment the + // following two lines to + // enable cookie management for the tests. + // java.net.CookieManager cm = new java.net.CookieManager(null, + // CookiePolicy.ACCEPT_ALL); + // java.net.CookieHandler.setDefault(cm); - return AtomPubTestBindingFactory.createBinding(getAtomPubURL(), getUsername(), getPassword()); - } + return AtomPubTestBindingFactory.createBinding(getAtomPubURL(), getUsername(), getPassword()); + } - @Override - protected Set<String> getEnabledTests() { - return fTests; - } + @Override + protected Set<String> getEnabledTests() { + return fTests; + } } Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/cache/CacheTest.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/cache/CacheTest.java?rev=936922&r1=936921&r2=936922&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/cache/CacheTest.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/cache/CacheTest.java Thu Apr 22 16:04:19 2010 @@ -34,180 +34,180 @@ import org.apache.chemistry.opencmis.cli */ public class CacheTest extends TestCase { - public final static String MAP_CACHE_LEVEL = "org.apache.chemistry.opencmis.client.bindings.cache.impl.MapCacheLevelImpl"; - public final static String LRU_CACHE_LEVEL = "org.apache.chemistry.opencmis.client.bindings.cache.impl.LruCacheLevelImpl"; + public final static String MAP_CACHE_LEVEL = "org.apache.chemistry.opencmis.client.bindings.cache.impl.MapCacheLevelImpl"; + public final static String LRU_CACHE_LEVEL = "org.apache.chemistry.opencmis.client.bindings.cache.impl.LruCacheLevelImpl"; - public void testCache() throws Exception { - Cache cache; + public void testCache() throws Exception { + Cache cache; - cache = new CacheImpl(); - cache.initialize(new String[] { MAP_CACHE_LEVEL, LRU_CACHE_LEVEL, MAP_CACHE_LEVEL, MAP_CACHE_LEVEL }); + cache = new CacheImpl(); + cache.initialize(new String[] { MAP_CACHE_LEVEL, LRU_CACHE_LEVEL, MAP_CACHE_LEVEL, MAP_CACHE_LEVEL }); - String value1 = "value1"; - String value2 = "value2"; - String value3 = "value3"; - Object valueObj; - - // put and get - cache.put(value1, "l1", "l2a", "l3", "l4"); - cache.put(value2, "l1", "l2b", "l3", "l4"); - cache.put(value3, "l1", "l2c", "l3", "l4"); - - valueObj = cache.get("l1", "l2a", "l3", "l4"); - assertTrue(valueObj instanceof String); - assertTrue(value1 == valueObj); - - valueObj = cache.get("l1", "l2b", "l3", "l4"); - assertTrue(valueObj instanceof String); - assertTrue(value2 == valueObj); - - valueObj = cache.get("l1", "l2c", "l3", "l4"); - assertTrue(valueObj instanceof String); - assertTrue(value3 == valueObj); - - // remove leaf - cache.remove("l1", "l2", "l3", "l4"); - valueObj = cache.get("l1", "l2", "l3", "l4"); - assertNull(valueObj); - - // put and get - cache.put(value1, "l1", "l2", "l3", "l4"); - valueObj = cache.get("l1", "l2", "l3", "l4"); - assertTrue(valueObj instanceof String); - assertTrue(value1 == valueObj); - - // remove branch - cache.remove("l1", "l2"); - valueObj = cache.get("l1", "l2", "l3", "l4"); - assertNull(valueObj); - } - - public void testCacheBadUsage() throws Exception { - Cache cache; - - cache = new CacheImpl(); - cache.initialize(new String[] { MAP_CACHE_LEVEL, LRU_CACHE_LEVEL, MAP_CACHE_LEVEL, MAP_CACHE_LEVEL }); - - // insufficient number of keys - try { - cache.put("value", "l1", "l2", "l3"); - } catch (IllegalArgumentException e) { - } - - // too many number of keys - try { - cache.put("value", "l1", "l2", "l3", "l4", "l5"); - } catch (IllegalArgumentException e) { - } - - // no keys - assertNull(cache.get((String[]) null)); - } - - public void testCacheConfig() throws Exception { - Cache cache; - - // empty config - try { - cache = new CacheImpl(); - cache.initialize(new String[] {}); - } catch (IllegalArgumentException e) { - } - - // null config - try { - cache = new CacheImpl(); - cache.initialize(null); - } catch (IllegalArgumentException e) { - } - - // unknown class - try { - cache = new CacheImpl(); - cache.initialize(new String[] { "this.is.not.a.valid.class" }); - } catch (IllegalArgumentException e) { - } - - // not a CacheLevel class - try { - cache = new CacheImpl(); - cache.initialize(new String[] { "org.apache.chemistry.opencmis.client.provider.cache.CacheTest" }); - } catch (IllegalArgumentException e) { - } - } - - public void testMapCache() throws Exception { - Cache cache; - - cache = new CacheImpl(); - cache.initialize(new String[] { MAP_CACHE_LEVEL + " " + MapCacheLevelImpl.CAPACITY + "=10," - + MapCacheLevelImpl.LOAD_FACTOR + "=0.5" }); - - for (int i = 0; i < 100; i++) { - cache.put("value" + i, "key" + i); - } - - for (int i = 0; i < 100; i++) { - Object valueObj = cache.get("key" + i); - assertTrue(valueObj instanceof String); - assertEquals("value" + i, valueObj); - } - } - - public void testURLCache() throws Exception { - Cache cache; - - cache = new CacheImpl(); - cache.initialize(new String[] { LRU_CACHE_LEVEL + " " + LruCacheLevelImpl.MAX_ENTRIES + "=10" }); - - for (int i = 0; i < 100; i++) { - cache.put("value" + i, "key" + i); - } - - for (int i = 0; i < 90; i++) { - Object valueObj = cache.get("key" + i); - assertNull(valueObj); - } - - for (int i = 90; i < 100; i++) { - Object valueObj = cache.get("key" + i); - assertTrue(valueObj instanceof String); - assertEquals("value" + i, valueObj); - } - } - - public void XtestFallback() throws Exception { - Cache cache; - - cache = new CacheImpl(); - cache.initialize(new String[] { MAP_CACHE_LEVEL + " " + MapCacheLevelImpl.CAPACITY + "=10," - + MapCacheLevelImpl.LOAD_FACTOR + "=0.5" }); - - cache.put("value1", new String[] { null }); - cache.put("value2", "key2"); - - assertEquals("value1", cache.get(new String[] { null })); - assertEquals("value2", cache.get("key2")); - assertEquals("value1", cache.get("key3")); - } - - public void testContentTypeCache() throws Exception { - ContentTypeCacheLevelImpl cl = new ContentTypeCacheLevelImpl(); - cl.initialize(null); - - String type1 = "type1"; - - cl.put(type1, "text/plain; param1=test; charset=UTF-8"); - - assertEquals(type1, cl.get("text/plain; param1=test; charset=UTF-8")); - assertEquals(type1, cl.get("text/plain; param1=test; charset=utf-8")); - assertEquals(type1, cl.get("text/plain; charset=utf-8; param1=test")); - assertEquals(type1, cl.get("text/plain; charset=utf-8; param1=test;")); - assertEquals(type1, cl.get("text/plain;charset=utf-8;param1=test")); - assertEquals(type1, cl.get("text/plain;\tcharset=utf-8; param1=test")); - assertEquals(type1, cl.get("text/plain; charset=\"utf-8\"; param1=test;")); - - assertNull(cl.get("text/plain; param1=blah; charset=UTF-8")); - assertNull(cl.get("text/plain; param1=test; charset=us-ascii")); - } + String value1 = "value1"; + String value2 = "value2"; + String value3 = "value3"; + Object valueObj; + + // put and get + cache.put(value1, "l1", "l2a", "l3", "l4"); + cache.put(value2, "l1", "l2b", "l3", "l4"); + cache.put(value3, "l1", "l2c", "l3", "l4"); + + valueObj = cache.get("l1", "l2a", "l3", "l4"); + assertTrue(valueObj instanceof String); + assertTrue(value1 == valueObj); + + valueObj = cache.get("l1", "l2b", "l3", "l4"); + assertTrue(valueObj instanceof String); + assertTrue(value2 == valueObj); + + valueObj = cache.get("l1", "l2c", "l3", "l4"); + assertTrue(valueObj instanceof String); + assertTrue(value3 == valueObj); + + // remove leaf + cache.remove("l1", "l2", "l3", "l4"); + valueObj = cache.get("l1", "l2", "l3", "l4"); + assertNull(valueObj); + + // put and get + cache.put(value1, "l1", "l2", "l3", "l4"); + valueObj = cache.get("l1", "l2", "l3", "l4"); + assertTrue(valueObj instanceof String); + assertTrue(value1 == valueObj); + + // remove branch + cache.remove("l1", "l2"); + valueObj = cache.get("l1", "l2", "l3", "l4"); + assertNull(valueObj); + } + + public void testCacheBadUsage() throws Exception { + Cache cache; + + cache = new CacheImpl(); + cache.initialize(new String[] { MAP_CACHE_LEVEL, LRU_CACHE_LEVEL, MAP_CACHE_LEVEL, MAP_CACHE_LEVEL }); + + // insufficient number of keys + try { + cache.put("value", "l1", "l2", "l3"); + } catch (IllegalArgumentException e) { + } + + // too many number of keys + try { + cache.put("value", "l1", "l2", "l3", "l4", "l5"); + } catch (IllegalArgumentException e) { + } + + // no keys + assertNull(cache.get((String[]) null)); + } + + public void testCacheConfig() throws Exception { + Cache cache; + + // empty config + try { + cache = new CacheImpl(); + cache.initialize(new String[] {}); + } catch (IllegalArgumentException e) { + } + + // null config + try { + cache = new CacheImpl(); + cache.initialize(null); + } catch (IllegalArgumentException e) { + } + + // unknown class + try { + cache = new CacheImpl(); + cache.initialize(new String[] { "this.is.not.a.valid.class" }); + } catch (IllegalArgumentException e) { + } + + // not a CacheLevel class + try { + cache = new CacheImpl(); + cache.initialize(new String[] { "org.apache.chemistry.opencmis.client.provider.cache.CacheTest" }); + } catch (IllegalArgumentException e) { + } + } + + public void testMapCache() throws Exception { + Cache cache; + + cache = new CacheImpl(); + cache.initialize(new String[] { MAP_CACHE_LEVEL + " " + MapCacheLevelImpl.CAPACITY + "=10," + + MapCacheLevelImpl.LOAD_FACTOR + "=0.5" }); + + for (int i = 0; i < 100; i++) { + cache.put("value" + i, "key" + i); + } + + for (int i = 0; i < 100; i++) { + Object valueObj = cache.get("key" + i); + assertTrue(valueObj instanceof String); + assertEquals("value" + i, valueObj); + } + } + + public void testURLCache() throws Exception { + Cache cache; + + cache = new CacheImpl(); + cache.initialize(new String[] { LRU_CACHE_LEVEL + " " + LruCacheLevelImpl.MAX_ENTRIES + "=10" }); + + for (int i = 0; i < 100; i++) { + cache.put("value" + i, "key" + i); + } + + for (int i = 0; i < 90; i++) { + Object valueObj = cache.get("key" + i); + assertNull(valueObj); + } + + for (int i = 90; i < 100; i++) { + Object valueObj = cache.get("key" + i); + assertTrue(valueObj instanceof String); + assertEquals("value" + i, valueObj); + } + } + + public void XtestFallback() throws Exception { + Cache cache; + + cache = new CacheImpl(); + cache.initialize(new String[] { MAP_CACHE_LEVEL + " " + MapCacheLevelImpl.CAPACITY + "=10," + + MapCacheLevelImpl.LOAD_FACTOR + "=0.5" }); + + cache.put("value1", new String[] { null }); + cache.put("value2", "key2"); + + assertEquals("value1", cache.get(new String[] { null })); + assertEquals("value2", cache.get("key2")); + assertEquals("value1", cache.get("key3")); + } + + public void testContentTypeCache() throws Exception { + ContentTypeCacheLevelImpl cl = new ContentTypeCacheLevelImpl(); + cl.initialize(null); + + String type1 = "type1"; + + cl.put(type1, "text/plain; param1=test; charset=UTF-8"); + + assertEquals(type1, cl.get("text/plain; param1=test; charset=UTF-8")); + assertEquals(type1, cl.get("text/plain; param1=test; charset=utf-8")); + assertEquals(type1, cl.get("text/plain; charset=utf-8; param1=test")); + assertEquals(type1, cl.get("text/plain; charset=utf-8; param1=test;")); + assertEquals(type1, cl.get("text/plain;charset=utf-8;param1=test")); + assertEquals(type1, cl.get("text/plain;\tcharset=utf-8; param1=test")); + assertEquals(type1, cl.get("text/plain; charset=\"utf-8\"; param1=test;")); + + assertNull(cl.get("text/plain; param1=blah; charset=UTF-8")); + assertNull(cl.get("text/plain; param1=test; charset=us-ascii")); + } }
