EcmStorage implements Storage { @Override public void save(final InputStream stream) { if (stream == null) { throw new NullPointerException(); } final ContentStream contentStream = session.getObjectFactory().createContentStream(WORKSPACE_ZIP_NAME, -1, "application/zip", stream); try { final Document existingDocument = (Document) session.getObjectByPath("/" + WORKSPACE_ZIP_NAME); existingDocument.setContentStream(contentStream, true); } catch (final CmisObjectNotFoundException e) { session.getRootFolder().createDocument(CMIS_DOCUMENT_PROPERTIES, contentStream, VersioningState.NONE); } } EcmStorage(final Session session);   EcmStorage(final EcmService ecmService); @Override void save(final InputStream stream); @Override InputStream load();  }
@Test(expected = NullPointerException.class) public void testEcmStoreNullFails() { final InputStream stream = null; storage.save(stream); }
@Test public void testStoreStreamCreatesNewDocument() throws Exception { final ByteArrayInputStream input = new ByteArrayInputStream("hello".getBytes()); makeConfigurationNotExisting(); storage.save(input); final Map<String, String> properties = new HashMap<String, String>(); properties.put("cmis:objectTypeId", "cmis:document"); properties.put("cmis:name", "configuration.zip"); verify(root).createDocument(eq(properties), any(ContentStream.class), eq(VersioningState.NONE)); }
@Test public void testStoreStreamUpdatesExistingDocumentAndDoesNotTryToCreateNewOne() throws Exception { final ByteArrayInputStream input = new ByteArrayInputStream("hello".getBytes()); final Document cmisObject = Mockito.mock(Document.class); makeConfigurationExisting(cmisObject); storage.save(input); verify(cmisObject).setContentStream(any(ContentStream.class), eq(true)); verify(root, never()).createDocument(stringMap(), any(ContentStream.class), any(VersioningState.class)); }