diff --git a/test/java/org/opendatakit/briefcase/model/FormStatusTest.java b/test/java/org/opendatakit/briefcase/model/FormStatusTest.java index 74345a11c..56f6dc825 100644 --- a/test/java/org/opendatakit/briefcase/model/FormStatusTest.java +++ b/test/java/org/opendatakit/briefcase/model/FormStatusTest.java @@ -5,6 +5,8 @@ import static org.junit.Assert.assertThat; import java.nio.file.Path; +import java.util.Optional; +import org.junit.Assert; import org.junit.Test; public class FormStatusTest { @@ -43,4 +45,14 @@ public void knows_how_to_build_paths_to_assets_inside_the_storage_directory() { ); } + @Test + public void gets_manifest_url_from_remoteform() { + FormStatus form = new FormStatus(null); + String supposedManifestUrl = "manifest/test/url"; + RemoteFormDefinition remoteForm = new RemoteFormDefinition("name", "1","v1", + "manifest/test/url", "/download/test/url"); + Assert.assertEquals(supposedManifestUrl, remoteForm.getManifestUrl()); + Assert.assertEquals(Optional.empty(), form.getManifestUrl()); + } + } diff --git a/test/java/org/opendatakit/briefcase/model/RetrieveAvailableFormsFailedEventTest.java b/test/java/org/opendatakit/briefcase/model/RetrieveAvailableFormsFailedEventTest.java new file mode 100644 index 000000000..0b7158dd3 --- /dev/null +++ b/test/java/org/opendatakit/briefcase/model/RetrieveAvailableFormsFailedEventTest.java @@ -0,0 +1,21 @@ +package org.opendatakit.briefcase.model; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class RetrieveAvailableFormsFailedEventTest { + + @Test + public void getReason_unknown() { + RetrieveAvailableFormsFailedEvent testEvent = new RetrieveAvailableFormsFailedEvent(null); + assertEquals("unknown", testEvent.getReason()); + } + + @Test + public void getReason_exception() { + Exception e = new Exception("fail"); + RetrieveAvailableFormsFailedEvent testEvent = new RetrieveAvailableFormsFailedEvent(e); + assertEquals("Exception: fail", testEvent.getReason()); + } +} \ No newline at end of file diff --git a/test/java/org/opendatakit/briefcase/model/ServerConnectionInfoTest.java b/test/java/org/opendatakit/briefcase/model/ServerConnectionInfoTest.java new file mode 100644 index 000000000..162161491 --- /dev/null +++ b/test/java/org/opendatakit/briefcase/model/ServerConnectionInfoTest.java @@ -0,0 +1,34 @@ +package org.opendatakit.briefcase.model; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ServerConnectionInfoTest { + + @Test + public void testEquals_False() { + char[] testPassword = {'a'}; + ServerConnectionInfo testInfo = new ServerConnectionInfo("testURL", "testName", testPassword); + Object o = new Object(); + + assertFalse(testInfo.equals(o)); + } + + @Test + public void testEquals_True() { + char[] testPassword = {'a'}; + ServerConnectionInfo testInfo = new ServerConnectionInfo("testURL", "testName", testPassword); + ServerConnectionInfo testInfo2 = new ServerConnectionInfo("testURL", "testName", testPassword); + + assertTrue(testInfo.equals(testInfo2)); + } + + @Test + public void testEquals_True_Itself() { + char[] testPassword = {'a'}; + ServerConnectionInfo testInfo = new ServerConnectionInfo("testURL", "testName", testPassword); + assertTrue(testInfo.equals(testInfo)); + } + +} \ No newline at end of file diff --git a/test/java/org/opendatakit/briefcase/model/form/FormKeyTest.java b/test/java/org/opendatakit/briefcase/model/form/FormKeyTest.java index 9d6e48221..f5597377c 100644 --- a/test/java/org/opendatakit/briefcase/model/form/FormKeyTest.java +++ b/test/java/org/opendatakit/briefcase/model/form/FormKeyTest.java @@ -2,6 +2,7 @@ import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import static org.opendatakit.briefcase.ui.pull.FormInstallerTest.getPath; import static org.opendatakit.briefcase.util.StringUtils.stripIllegalChars; @@ -9,6 +10,7 @@ import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; +import org.junit.Assert; import org.junit.Test; import org.opendatakit.briefcase.model.BriefcaseFormDefinition; import org.opendatakit.briefcase.model.FormStatus; @@ -27,4 +29,18 @@ public void regression_wrong_form_name_when_creating_keys_from_briefcase_form_de FormKey key2 = FormKey.from(new FormStatus(BriefcaseFormDefinition.resolveAgainstBriefcaseDefn(formFile.toFile(), false, briefcaseFolder.toFile()))); assertThat(key1, is(key2)); } + + @Test + public void different_and_same_key_check_if_equal() { + FormKey key1 = FormKey.of("Key_1", "1", "v1.0"); + FormKey key2 = FormKey.of("Key_1", "2", "v2.0"); + FormKey key3 = FormKey.of("Key_1", "1", "v1.0"); + String keyString = "key_4"; + FormKey keyNull = null; + Assert.assertFalse(key1.equals(key2)); + assertTrue(key1.equals(key1)); + assertTrue(key1.equals(key3)); + Assert.assertFalse(key1.equals(keyString)); + Assert.assertFalse(key1.equals(keyNull)); + } } diff --git a/test/java/org/opendatakit/briefcase/pull/aggregate/AggregateAttachmentTest.java b/test/java/org/opendatakit/briefcase/pull/aggregate/AggregateAttachmentTest.java index b0043c5ba..e054a57ba 100644 --- a/test/java/org/opendatakit/briefcase/pull/aggregate/AggregateAttachmentTest.java +++ b/test/java/org/opendatakit/briefcase/pull/aggregate/AggregateAttachmentTest.java @@ -1,14 +1,16 @@ package org.opendatakit.briefcase.pull.aggregate; -import static org.junit.Assert.assertThat; - import java.io.IOException; +import java.net.MalformedURLException; import java.net.URISyntaxException; +import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; import org.hamcrest.Matchers; import org.junit.Test; +import static org.junit.Assert.*; + public class AggregateAttachmentTest { @Test public void computes_the_string_MD5_hash_of_a_file() throws URISyntaxException, IOException { @@ -16,4 +18,22 @@ public void computes_the_string_MD5_hash_of_a_file() throws URISyntaxException, String expectedHash = "E79C0D4AD451003BA8CFDC1183AC89E9"; assertThat(AggregateAttachment.md5(file), Matchers.is(expectedHash)); } + + @Test + public void gets_download_url() throws URISyntaxException, MalformedURLException { + AggregateAttachment testAttachment = AggregateAttachment.of("file_1", "123456", "file://org/opendatakit/briefcase/pull/aggregate/lorem-ipsum-40k.txt"); + URL expectedUrl = new URL("file://org/opendatakit/briefcase/pull/aggregate/lorem-ipsum-40k.txt"); + assertEquals(expectedUrl, testAttachment.getDownloadUrl()); + } + + @Test + public void checks_equality_of_attachment() throws URISyntaxException, MalformedURLException { + AggregateAttachment testAttachment = AggregateAttachment.of("file_1", "123456", "file://org/opendatakit/briefcase/pull/aggregate/lorem-ipsum-40k.txt"); + AggregateAttachment testAttachment2 = AggregateAttachment.of("file_1", "123456", "file://org/opendatakit/briefcase/pull/aggregate/lorem-ipsum-40k.txt"); + AggregateAttachment testAttachment3 = AggregateAttachment.of("file_3", "1234567", "file://org/opendatakit/briefcase/lorem-ipsum-40k.txt"); + assertFalse(testAttachment.equals(null)); + assertTrue(testAttachment.equals(testAttachment)); + assertTrue(testAttachment.equals(testAttachment2)); + assertFalse(testAttachment.equals(testAttachment3)); + } } diff --git a/test/java/org/opendatakit/briefcase/reused/http/CommonsHttpTest.java b/test/java/org/opendatakit/briefcase/reused/http/CommonsHttpTest.java index c9aba299b..765f9df73 100644 --- a/test/java/org/opendatakit/briefcase/reused/http/CommonsHttpTest.java +++ b/test/java/org/opendatakit/briefcase/reused/http/CommonsHttpTest.java @@ -33,6 +33,7 @@ import static com.github.dreamhead.moco.Runner.running; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.opendatakit.briefcase.matchers.ExceptionMatchers.throwsException; import static org.opendatakit.briefcase.reused.http.Http.MAX_HTTP_CONNECTIONS; @@ -156,4 +157,12 @@ public void can_handle_3xx_errors() throws Exception { assertThat(response.isSuccess(), is(false)); }); } + + @Test + public void the_factories_accept_max_http_connections_with_Proxy(){ + assertEquals(CommonsHttp.class, CommonsHttp.of(MAX_HTTP_CONNECTIONS, null).getClass()); + } + + + } diff --git a/test/java/org/opendatakit/briefcase/reused/http/RequestBuilderTest.java b/test/java/org/opendatakit/briefcase/reused/http/RequestBuilderTest.java index c643a6c11..672c0c402 100644 --- a/test/java/org/opendatakit/briefcase/reused/http/RequestBuilderTest.java +++ b/test/java/org/opendatakit/briefcase/reused/http/RequestBuilderTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertThat; import static org.opendatakit.briefcase.reused.http.RequestBuilder.url; +import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -29,6 +30,8 @@ public class RequestBuilderTest { + private static final String TEST_BODY = "{\"query\": \"some-text\" }"; + @Test public void can_compose_multiple_path_parts() { List baseUrls = Arrays.asList("http://foo.com", "http://foo.com/"); @@ -86,4 +89,11 @@ public void can_resolve_paths() { is(url("http://foo.com/bar/baz")) ); } + + @Test + public void can_resolve_body(){ + Request request = RequestBuilder.get("http://foo.com").withBody(TEST_BODY).build(); + String body = RequestSpy.read(request.getBody()); + assertThat(body, is(TEST_BODY)); + } } diff --git a/test/java/org/opendatakit/briefcase/transfer/TransferFormsTest.java b/test/java/org/opendatakit/briefcase/transfer/TransferFormsTest.java index 532616abf..1bf81057c 100644 --- a/test/java/org/opendatakit/briefcase/transfer/TransferFormsTest.java +++ b/test/java/org/opendatakit/briefcase/transfer/TransferFormsTest.java @@ -16,14 +16,34 @@ package org.opendatakit.briefcase.transfer; +import static java.nio.file.Paths.get; import static java.util.Collections.singletonList; import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import org.junit.Before; import org.junit.Test; +import org.opendatakit.briefcase.model.FormStatus; import org.opendatakit.briefcase.model.FormStatusBuilder; +import org.opendatakit.briefcase.model.TestFormDefinition; public class TransferFormsTest { + + private List forms; + private Path briefcaseDir; + + @Before + public void setUp() { + briefcaseDir = get("/storage/directory"); + forms = new ArrayList(); + forms = FormStatusBuilder.buildFormStatusList(10); + } + @Test public void empty_forms_can_merge_forms() { // What we are really testing is that no UnsupportedOperationException @@ -42,4 +62,27 @@ public void forms_from_varargs_factory_can_be_cleared() { forms.clear(); assertThat(forms.isEmpty(), is(true)); } + + @Test + public void loads_all_forms() { + TransferForms transferForms = TransferForms.empty(); + transferForms.load(forms); + assertEquals(10, transferForms.size()); + } + + @Test + public void test_select_all() { + TransferForms transferForms = TransferForms.from(forms); + transferForms.selectAll(); + assertTrue(transferForms.allSelected()); + assertTrue(transferForms.someSelected()); + } + + @Test + public void get_selected_forms() { + TransferForms transferForms = TransferForms.from(forms); + transferForms.selectAll(); + transferForms.getSelectedForms(); + assertEquals(10, transferForms.size()); + } } diff --git a/test/java/org/opendatakit/briefcase/util/BriefcaseVersionManagerTest.java b/test/java/org/opendatakit/briefcase/util/BriefcaseVersionManagerTest.java index 5f55b650b..cfe7f59d7 100644 --- a/test/java/org/opendatakit/briefcase/util/BriefcaseVersionManagerTest.java +++ b/test/java/org/opendatakit/briefcase/util/BriefcaseVersionManagerTest.java @@ -57,4 +57,18 @@ public void knows_if_we_are_not_up_to_date() { assertThat(versionManager.isUpToDate(), is(false)); } + + @Test + public void version_contains_hyphen(){ + FakeHttp http = new FakeHttp(); + + http.stub( + get(url("https://api.github.com/repos/opendatakit/briefcase/releases/latest")).build(), + ResponseHelpers.ok("{\"tag_name\":\"v2.0.0\"}") + ); + + BriefcaseVersionManager versionManager = new BriefcaseVersionManager(http, "v2.0.0-test"); + + assertThat(versionManager.isUpToDate(), is(true)); + } } diff --git a/test/java/org/opendatakit/briefcase/util/XmlManipulationUtilsTest.java b/test/java/org/opendatakit/briefcase/util/XmlManipulationUtilsTest.java new file mode 100644 index 000000000..2cb347147 --- /dev/null +++ b/test/java/org/opendatakit/briefcase/util/XmlManipulationUtilsTest.java @@ -0,0 +1,48 @@ +package org.opendatakit.briefcase.util; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.opendatakit.briefcase.util.XmlManipulationUtils.*; + +import org.junit.Before; + +import org.junit.Test; +import org.kxml2.kdom.Element; +import org.kxml2.kdom.Node; + +public class XmlManipulationUtilsTest { + + private static final String ROOT_URI = "http://www.w3.org/2002/xforms"; + private static final String OPEN_ROSA_NAMESPACE = "http://openrosa.org/xforms"; + private static final String OPEN_ROSA_METADATA_TAG = "meta"; + private static final String OPEN_ROSA_INSTANCE_ID = "instanceID"; + private static final String NAMESPACE_ATTRIBUTE = "xmlns"; + private Element tree; + + @Before + public void setUp(){ + tree = new Element().createElement(null, "html"); + tree.setAttribute(null, NAMESPACE_ATTRIBUTE, ROOT_URI); + Element head = new Element().createElement(null, "head"); + Element title = new Element().createElement(null, "title"); + Element model = new Element().createElement(null, "model"); + Element instance = new Element().createElement(null, "instance"); + Element data = new Element().createElement(null, "data"); + Element meta = new Element().createElement(OPEN_ROSA_NAMESPACE, OPEN_ROSA_METADATA_TAG); + Element instanceId = new Element().createElement(OPEN_ROSA_NAMESPACE, OPEN_ROSA_INSTANCE_ID); + tree.addChild(Node.ELEMENT, head); + head.addChild(Node.ELEMENT, title); + head.addChild(Node.ELEMENT, model); + model.addChild(Node.ELEMENT, instance); + instance.addChild(Node.ELEMENT, data); + data.addChild(Node.ELEMENT, meta); + meta.addChild(Node.ELEMENT, instanceId); + } + + @Test + public void find_meta_tag_successful() { + FormInstanceMetadata metadata = getFormInstanceMetadata(tree); + assertNotNull(metadata); + } + +}