{"action":"created","comment":{"url":"https://api.github.com/repos/codice/ddf/pulls/comments/52860618","id":52860618,"diff_hunk":"@@ -0,0 +1,179 @@\n+/**\n+ * Copyright (c) Codice Foundation\n+ * <p>\n+ * This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser\n+ * General Public License as published by the Free Software Foundation, either version 3 of the\n+ * License, or any later version.\n+ * <p>\n+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\n+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details. A copy of the GNU Lesser General Public License\n+ * is distributed along with this program and can be found at\n+ * <http://www.gnu.org/licenses/lgpl.html>.\n+ */\n+package org.codice.ddf.catalog.migratable.impl;\n+\n+import static org.mockito.Matchers.anyObject;\n+import static org.mockito.Mockito.doThrow;\n+import static org.mockito.Mockito.times;\n+import static org.mockito.Mockito.verify;\n+import static org.mockito.Mockito.when;\n+import static org.powermock.api.mockito.PowerMockito.whenNew;\n+\n+import java.io.BufferedOutputStream;\n+import java.io.File;\n+import java.io.FileOutputStream;\n+import java.io.IOException;\n+import java.io.ObjectOutputStream;\n+import java.io.OutputStream;\n+import java.nio.file.Path;\n+import java.nio.file.Paths;\n+import java.util.ArrayList;\n+import java.util.Collections;\n+import java.util.List;\n+\n+import org.codice.ddf.migration.MigrationException;\n+import org.junit.Before;\n+import org.junit.Test;\n+import org.junit.runner.RunWith;\n+import org.mockito.Mock;\n+import org.powermock.core.classloader.annotations.PrepareForTest;\n+import org.powermock.modules.junit4.PowerMockRunner;\n+\n+import ddf.catalog.data.Result;\n+import ddf.catalog.data.impl.MetacardImpl;\n+import ddf.catalog.data.impl.ResultImpl;\n+\n+@RunWith(PowerMockRunner.class)\n+@PrepareForTest({MigrationFileWriter.class, File.class})\n+public class MigrationFileWriterTest {\n+\n+    private static final int RESULT_COUNT = 5;\n+\n+    private static final Path DDF_BASE_PATH = Paths.get(\"ddf\");\n+\n+    @Mock\n+    private Path mockPath;\n+\n+    @Mock\n+    private File mockFile;\n+\n+    @Mock\n+    private FileOutputStream mockFileOutputStream;\n+\n+    @Mock\n+    private BufferedOutputStream mockBufferedOutputStream;\n+\n+    @Mock\n+    private ObjectOutputStream mockObjectOutputStream;\n+\n+    private MigrationFileWriter fileWriter;\n+\n+    @Before\n+    public void setup() throws Exception {\n+        fileWriter = new MigrationFileWriter() {\n+            @Override\n+            ObjectOutputStream createObjectStream(OutputStream source) {\n+                return mockObjectOutputStream;\n+            }\n+\n+            @Override\n+            BufferedOutputStream createBufferedStream(OutputStream source) {\n+                return mockBufferedOutputStream;\n+            }\n+\n+            @Override\n+            FileOutputStream createFileStream(File file) {\n+                return mockFileOutputStream;\n+            }\n+        };\n+\n+        when(mockPath.toFile()).thenReturn(mockFile);\n+    }\n+\n+    private List<Result> loadList() {\n+        final List<Result> results = new ArrayList<>();\n+        for (int i = 0; i < RESULT_COUNT; i++) {\n+            results.add(new ResultImpl(new MetacardImpl()));\n+        }\n+        return results;\n+    }\n+\n+    @Test\n+    public void testInitCallsMkDir() throws Exception {\n+        when(mockFile.exists()).thenReturn(false);\n+        when(mockFile.mkdir()).thenReturn(true);\n+\n+        fileWriter.init(mockPath);\n+\n+        verify(mockFile).mkdir();\n+    }\n+\n+    @Test(expected = MigrationException.class)\n+    public void testInitFailsToCreateDirectory() throws Exception {\n+\n+        when(mockFile.exists()).thenReturn(false);\n+        when(mockFile.mkdir()).thenReturn(false);\n+\n+        fileWriter.init(mockPath);\n+    }\n+\n+    @Test\n+    public void testWriteSuccess() throws Exception {\n+        final List<Result> results = loadList();\n+        when(mockFile.exists()).thenReturn(true);\n+\n+        fileWriter.writeMetacards(mockFile, results);\n+\n+        verify(mockObjectOutputStream, times(RESULT_COUNT)).writeObject(anyObject());\n+        verify(mockBufferedOutputStream, times(1)).flush();\n+    }\n+\n+    @Test\n+    public void testWriteSuccessMakeFile() throws Exception {\n+        final List<Result> results = loadList();\n+        when(mockFile.exists()).thenReturn(false);\n+\n+        fileWriter.writeMetacards(mockFile, results);\n+\n+        verify(mockFile).createNewFile();\n+        verify(mockObjectOutputStream, times(RESULT_COUNT)).writeObject(anyObject());","path":"catalog/core/catalog-core-migratable/src/test/java/org/codice/ddf/catalog/migratable/impl/MigrationFileWriterTest.java","position":140,"original_position":140,"commit_id":"5cc81a2d46660bbb9ddecea66d3f9635ba4468b3","original_commit_id":"5cc81a2d46660bbb9ddecea66d3f9635ba4468b3","user":{"login":"lessarderic","id":11377558,"avatar_url":"https://avatars.githubusercontent.com/u/11377558?v=3","gravatar_id":"","url":"https://api.github.com/users/lessarderic","html_url":"https://github.com/lessarderic","followers_url":"https://api.github.com/users/lessarderic/followers","following_url":"https://api.github.com/users/lessarderic/following{/other_user}","gists_url":"https://api.github.com/users/lessarderic/gists{/gist_id}","starred_url":"https://api.github.com/users/lessarderic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lessarderic/subscriptions","organizations_url":"https://api.github.com/users/lessarderic/orgs","repos_url":"https://api.github.com/users/lessarderic/repos","events_url":"https://api.github.com/users/lessarderic/events{/privacy}","received_events_url":"https://api.github.com/users/lessarderic/received_events","type":"User","site_admin":false},"body":"If the goal of this method is to verify that the file is created, we don't need the 2 other verifies.","created_at":"2016-02-15T05:29:08Z","updated_at":"2016-02-15T05:29:08Z","html_url":"https://github.com/codice/ddf/pull/526#discussion_r52860618","pull_request_url":"https://api.github.com/repos/codice/ddf/pulls/526","_links":{"self":{"href":"https://api.github.com/repos/codice/ddf/pulls/comments/52860618"},"html":{"href":"https://github.com/codice/ddf/pull/526#discussion_r52860618"},"pull_request":{"href":"https://api.github.com/repos/codice/ddf/pulls/526"}}},"pull_request":{"url":"https://api.github.com/repos/codice/ddf/pulls/526","id":58635333,"html_url":"https://github.com/codice/ddf/pull/526","diff_url":"https://github.com/codice/ddf/pull/526.diff","patch_url":"https://github.com/codice/ddf/pull/526.patch","issue_url":"https://api.github.com/repos/codice/ddf/issues/526","number":526,"state":"open","locked":false,"title":"DDF-1824: Added ability for catalog (metacard) export","user":{"login":"Lambeaux","id":7215534,"avatar_url":"https://avatars.githubusercontent.com/u/7215534?v=3","gravatar_id":"","url":"https://api.github.com/users/Lambeaux","html_url":"https://github.com/Lambeaux","followers_url":"https://api.github.com/users/Lambeaux/followers","following_url":"https://api.github.com/users/Lambeaux/following{/other_user}","gists_url":"https://api.github.com/users/Lambeaux/gists{/gist_id}","starred_url":"https://api.github.com/users/Lambeaux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lambeaux/subscriptions","organizations_url":"https://api.github.com/users/Lambeaux/orgs","repos_url":"https://api.github.com/users/Lambeaux/repos","events_url":"https://api.github.com/users/Lambeaux/events{/privacy}","received_events_url":"https://api.github.com/users/Lambeaux/received_events","type":"User","site_admin":false},"body":"- New files introduced\r\n- All objects unit tested\r\n- Single iTest added\r\n- Some comments need addressing","created_at":"2016-02-08T16:50:15Z","updated_at":"2016-02-15T05:29:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"48d036ca1df3c95a29233f9c06d5e698d56be918","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/codice/ddf/pulls/526/commits","review_comments_url":"https://api.github.com/repos/codice/ddf/pulls/526/comments","review_comment_url":"https://api.github.com/repos/codice/ddf/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codice/ddf/issues/526/comments","statuses_url":"https://api.github.com/repos/codice/ddf/statuses/5cc81a2d46660bbb9ddecea66d3f9635ba4468b3","head":{"label":"Lambeaux:DDF-1824","ref":"DDF-1824","sha":"5cc81a2d46660bbb9ddecea66d3f9635ba4468b3","user":{"login":"Lambeaux","id":7215534,"avatar_url":"https://avatars.githubusercontent.com/u/7215534?v=3","gravatar_id":"","url":"https://api.github.com/users/Lambeaux","html_url":"https://github.com/Lambeaux","followers_url":"https://api.github.com/users/Lambeaux/followers","following_url":"https://api.github.com/users/Lambeaux/following{/other_user}","gists_url":"https://api.github.com/users/Lambeaux/gists{/gist_id}","starred_url":"https://api.github.com/users/Lambeaux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lambeaux/subscriptions","organizations_url":"https://api.github.com/users/Lambeaux/orgs","repos_url":"https://api.github.com/users/Lambeaux/repos","events_url":"https://api.github.com/users/Lambeaux/events{/privacy}","received_events_url":"https://api.github.com/users/Lambeaux/received_events","type":"User","site_admin":false},"repo":{"id":47577497,"name":"ddf","full_name":"Lambeaux/ddf","owner":{"login":"Lambeaux","id":7215534,"avatar_url":"https://avatars.githubusercontent.com/u/7215534?v=3","gravatar_id":"","url":"https://api.github.com/users/Lambeaux","html_url":"https://github.com/Lambeaux","followers_url":"https://api.github.com/users/Lambeaux/followers","following_url":"https://api.github.com/users/Lambeaux/following{/other_user}","gists_url":"https://api.github.com/users/Lambeaux/gists{/gist_id}","starred_url":"https://api.github.com/users/Lambeaux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lambeaux/subscriptions","organizations_url":"https://api.github.com/users/Lambeaux/orgs","repos_url":"https://api.github.com/users/Lambeaux/repos","events_url":"https://api.github.com/users/Lambeaux/events{/privacy}","received_events_url":"https://api.github.com/users/Lambeaux/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Lambeaux/ddf","description":"The Distributed Data Framework - Distribution, SDK, and Test","fork":true,"url":"https://api.github.com/repos/Lambeaux/ddf","forks_url":"https://api.github.com/repos/Lambeaux/ddf/forks","keys_url":"https://api.github.com/repos/Lambeaux/ddf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Lambeaux/ddf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Lambeaux/ddf/teams","hooks_url":"https://api.github.com/repos/Lambeaux/ddf/hooks","issue_events_url":"https://api.github.com/repos/Lambeaux/ddf/issues/events{/number}","events_url":"https://api.github.com/repos/Lambeaux/ddf/events","assignees_url":"https://api.github.com/repos/Lambeaux/ddf/assignees{/user}","branches_url":"https://api.github.com/repos/Lambeaux/ddf/branches{/branch}","tags_url":"https://api.github.com/repos/Lambeaux/ddf/tags","blobs_url":"https://api.github.com/repos/Lambeaux/ddf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Lambeaux/ddf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Lambeaux/ddf/git/refs{/sha}","trees_url":"https://api.github.com/repos/Lambeaux/ddf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Lambeaux/ddf/statuses/{sha}","languages_url":"https://api.github.com/repos/Lambeaux/ddf/languages","stargazers_url":"https://api.github.com/repos/Lambeaux/ddf/stargazers","contributors_url":"https://api.github.com/repos/Lambeaux/ddf/contributors","subscribers_url":"https://api.github.com/repos/Lambeaux/ddf/subscribers","subscription_url":"https://api.github.com/repos/Lambeaux/ddf/subscription","commits_url":"https://api.github.com/repos/Lambeaux/ddf/commits{/sha}","git_commits_url":"https://api.github.com/repos/Lambeaux/ddf/git/commits{/sha}","comments_url":"https://api.github.com/repos/Lambeaux/ddf/comments{/number}","issue_comment_url":"https://api.github.com/repos/Lambeaux/ddf/issues/comments{/number}","contents_url":"https://api.github.com/repos/Lambeaux/ddf/contents/{+path}","compare_url":"https://api.github.com/repos/Lambeaux/ddf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Lambeaux/ddf/merges","archive_url":"https://api.github.com/repos/Lambeaux/ddf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Lambeaux/ddf/downloads","issues_url":"https://api.github.com/repos/Lambeaux/ddf/issues{/number}","pulls_url":"https://api.github.com/repos/Lambeaux/ddf/pulls{/number}","milestones_url":"https://api.github.com/repos/Lambeaux/ddf/milestones{/number}","notifications_url":"https://api.github.com/repos/Lambeaux/ddf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Lambeaux/ddf/labels{/name}","releases_url":"https://api.github.com/repos/Lambeaux/ddf/releases{/id}","deployments_url":"https://api.github.com/repos/Lambeaux/ddf/deployments","created_at":"2015-12-07T20:30:44Z","updated_at":"2016-01-11T17:33:30Z","pushed_at":"2016-02-11T20:01:38Z","git_url":"git://github.com/Lambeaux/ddf.git","ssh_url":"git@github.com:Lambeaux/ddf.git","clone_url":"https://github.com/Lambeaux/ddf.git","svn_url":"https://github.com/Lambeaux/ddf","homepage":"","size":129709,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"codice:master","ref":"master","sha":"bc737ed4a3e95631da9cc3eb423bda512991f9dd","user":{"login":"codice","id":2386734,"avatar_url":"https://avatars.githubusercontent.com/u/2386734?v=3","gravatar_id":"","url":"https://api.github.com/users/codice","html_url":"https://github.com/codice","followers_url":"https://api.github.com/users/codice/followers","following_url":"https://api.github.com/users/codice/following{/other_user}","gists_url":"https://api.github.com/users/codice/gists{/gist_id}","starred_url":"https://api.github.com/users/codice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codice/subscriptions","organizations_url":"https://api.github.com/users/codice/orgs","repos_url":"https://api.github.com/users/codice/repos","events_url":"https://api.github.com/users/codice/events{/privacy}","received_events_url":"https://api.github.com/users/codice/received_events","type":"Organization","site_admin":false},"repo":{"id":15173563,"name":"ddf","full_name":"codice/ddf","owner":{"login":"codice","id":2386734,"avatar_url":"https://avatars.githubusercontent.com/u/2386734?v=3","gravatar_id":"","url":"https://api.github.com/users/codice","html_url":"https://github.com/codice","followers_url":"https://api.github.com/users/codice/followers","following_url":"https://api.github.com/users/codice/following{/other_user}","gists_url":"https://api.github.com/users/codice/gists{/gist_id}","starred_url":"https://api.github.com/users/codice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codice/subscriptions","organizations_url":"https://api.github.com/users/codice/orgs","repos_url":"https://api.github.com/users/codice/repos","events_url":"https://api.github.com/users/codice/events{/privacy}","received_events_url":"https://api.github.com/users/codice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codice/ddf","description":"The Distributed Data Framework - Federated Open Geospatial Consortium (OGC) filter powered metadata catalog with SAML Web SSO secured container","fork":false,"url":"https://api.github.com/repos/codice/ddf","forks_url":"https://api.github.com/repos/codice/ddf/forks","keys_url":"https://api.github.com/repos/codice/ddf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codice/ddf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codice/ddf/teams","hooks_url":"https://api.github.com/repos/codice/ddf/hooks","issue_events_url":"https://api.github.com/repos/codice/ddf/issues/events{/number}","events_url":"https://api.github.com/repos/codice/ddf/events","assignees_url":"https://api.github.com/repos/codice/ddf/assignees{/user}","branches_url":"https://api.github.com/repos/codice/ddf/branches{/branch}","tags_url":"https://api.github.com/repos/codice/ddf/tags","blobs_url":"https://api.github.com/repos/codice/ddf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codice/ddf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codice/ddf/git/refs{/sha}","trees_url":"https://api.github.com/repos/codice/ddf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codice/ddf/statuses/{sha}","languages_url":"https://api.github.com/repos/codice/ddf/languages","stargazers_url":"https://api.github.com/repos/codice/ddf/stargazers","contributors_url":"https://api.github.com/repos/codice/ddf/contributors","subscribers_url":"https://api.github.com/repos/codice/ddf/subscribers","subscription_url":"https://api.github.com/repos/codice/ddf/subscription","commits_url":"https://api.github.com/repos/codice/ddf/commits{/sha}","git_commits_url":"https://api.github.com/repos/codice/ddf/git/commits{/sha}","comments_url":"https://api.github.com/repos/codice/ddf/comments{/number}","issue_comment_url":"https://api.github.com/repos/codice/ddf/issues/comments{/number}","contents_url":"https://api.github.com/repos/codice/ddf/contents/{+path}","compare_url":"https://api.github.com/repos/codice/ddf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codice/ddf/merges","archive_url":"https://api.github.com/repos/codice/ddf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codice/ddf/downloads","issues_url":"https://api.github.com/repos/codice/ddf/issues{/number}","pulls_url":"https://api.github.com/repos/codice/ddf/pulls{/number}","milestones_url":"https://api.github.com/repos/codice/ddf/milestones{/number}","notifications_url":"https://api.github.com/repos/codice/ddf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codice/ddf/labels{/name}","releases_url":"https://api.github.com/repos/codice/ddf/releases{/id}","deployments_url":"https://api.github.com/repos/codice/ddf/deployments","created_at":"2013-12-13T20:38:28Z","updated_at":"2016-02-02T16:34:27Z","pushed_at":"2016-02-15T00:03:11Z","git_url":"git://github.com/codice/ddf.git","ssh_url":"git@github.com:codice/ddf.git","clone_url":"https://github.com/codice/ddf.git","svn_url":"https://github.com/codice/ddf","homepage":"","size":137537,"stargazers_count":32,"watchers_count":32,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":68,"mirror_url":null,"open_issues_count":11,"forks":68,"open_issues":11,"watchers":32,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codice/ddf/pulls/526"},"html":{"href":"https://github.com/codice/ddf/pull/526"},"issue":{"href":"https://api.github.com/repos/codice/ddf/issues/526"},"comments":{"href":"https://api.github.com/repos/codice/ddf/issues/526/comments"},"review_comments":{"href":"https://api.github.com/repos/codice/ddf/pulls/526/comments"},"review_comment":{"href":"https://api.github.com/repos/codice/ddf/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codice/ddf/pulls/526/commits"},"statuses":{"href":"https://api.github.com/repos/codice/ddf/statuses/5cc81a2d46660bbb9ddecea66d3f9635ba4468b3"}}}}