collect_app/src/test/java/org/odk/collect/android/utilities/FormDownloaderTest.java
@Test
    public void downloadingFormWithoutMedia_Succeeds() throws Exception {
        String basicNoMedia = "<h:html xmlns=\"http://www.w3.org/2002/xforms\" xmlns:h=\"http://www.w3.org/1999/xhtml\">\n" +
                "    <h:head>\n" +
                "        <h:title>basic</h:title>\n" +
                "        <model>\n" +
                "            <instance>\n" +
                "                <data id=\"basic\">\n" +
                "                    <q1/>\n" +
                "                </data>\n" +
                "            </instance>\n" +
                "            <bind nodeset=\"/data/q1\" type=\"string\"/>\n" +
                "        </model>\n" +
                "    </h:head>\n" +
                "    <h:body>\n" +
                "        <input ref=\"/data/q1\">\n" +
                "            <label>Question</label>\n" +
                "        </input>\n" +
                "    </h:body>\n" +
                "</h:html>";
        File temp = File.createTempFile("basicNoMedia", ".xml");
        temp.deleteOnExit();

        BufferedWriter out = new BufferedWriter(new FileWriter(temp));
        out.write(basicNoMedia);
        out.close();

        FormDownloader downloader = spy(new FormDownloader());
        FormDetails test1 = new FormDetails("No media", "https://testserver/no-media.xml",
                null, "test1", "2019121201",
                "hash", null, false, false);
        FormDownloader.FileResult result = new FormDownloader.FileResult(temp, true);
        doReturn(result).when(downloader).downloadXform(test1.getFormName(), test1.getDownloadUrl());
        doReturn(true).when(downloader).installEverything(any(), any(), any());

        List<FormDetails> forms = new ArrayList<>();
        forms.add(test1);

        HashMap<FormDetails, String> messages = downloader.downloadForms(forms);
        assertThat(messages.get(test1), is("Success"));
    }
/**
     * Verifies that a form without media can successfully go through the download process. Regression
     * test for https://github.com/opendatakit/collect/issues/3535.
     *
     * The focus of this test is the form parsing behavior triggered by a download and how it
     * relates to a media folder that may or may not have been created. The downloading of forms and
     * saving of parsed form  values are mocked (and those concerns should be separated).
     */
Verifies that a form without media can successfully go through the download process.

The focus of this test is the form parsing behavior triggered by a download and how it
relates to a media folder that may or may not have been created. The downloading of forms and
saving of parsed form  values are mocked (and those concerns should be separated).
Verifies that a form without media can successfully go through the download process . The focus of this test is the form parsing behavior triggered by a download and how it relates to a media folder that may or may not have been created . The downloading of forms and saving of parsed form values are mocked ( and those concerns should be separated ) .
@Test
    public void downloadingFormWithoutMedia_Succeeds() throws Exception {
        String basicNoMedia = "<h:html xmlns=\"http://www.w3.org/2002/xforms\" xmlns:h=\"http://www.w3.org/1999/xhtml\">\n" +
                "    <h:head>\n" +
                "        <h:title>basic</h:title>\n" +
                "        <model>\n" +
                "            <instance>\n" +
                "                <data id=\"basic\">\n" +
                "                    <q1/>\n" +
                "                </data>\n" +
                "            </instance>\n" +
                "            <bind nodeset=\"/data/q1\" type=\"string\"/>\n" +
                "        </model>\n" +
                "    </h:head>\n" +
                "    <h:body>\n" +
                "        <input ref=\"/data/q1\">\n" +
                "            <label>Question</label>\n" +
                "        </input>\n" +
                "    </h:body>\n" +
                "</h:html>";
        File temp = File.createTempFile("basicNoMedia", ".xml");
        temp.deleteOnExit();
        BufferedWriter out = new BufferedWriter(new FileWriter(temp));
        out.write(basicNoMedia);
        out.close();
        FormDownloader downloader = spy(new FormDownloader());
        FormDetails test1 = new FormDetails("No media", "https://testserver/no-media.xml",
                null, "test1", "2019121201",
                "hash", null, false, false);
        FormDownloader.FileResult result = new FormDownloader.FileResult(temp, true);
        doReturn(result).when(downloader).downloadXform(test1.getFormName(), test1.getDownloadUrl());
        doReturn(true).when(downloader).installEverything(any(), any(), any());
        List<FormDetails> forms = new ArrayList<>();
        forms.add(test1);
        HashMap<FormDetails, String> messages = downloader.downloadForms(forms);
        assertThat(messages.get(test1), is("Success"));
    }
@ Test public void downloadingFormWithoutMedia_Succeeds ( ) throws Exception { String basicNoMedia = "<h:html xmlns=\"http://www.w3.org/2002/xforms\" xmlns:h=\"http://www.w3.org/1999/xhtml\">\n" + "    <h:head>\n" + "        <h:title>basic</h:title>\n" + "        <model>\n" + "            <instance>\n" + "                <data id=\"basic\">\n" + "                    <q1/>\n" + "                </data>\n" + "            </instance>\n" + "            <bind nodeset=\"/data/q1\" type=\"string\"/>\n" + "        </model>\n" + "    </h:head>\n" + "    <h:body>\n" + "        <input ref=\"/data/q1\">\n" + "            <label>Question</label>\n" + "        </input>\n" + "    </h:body>\n" + "</h:html>" ; File temp = File . createTempFile ( "basicNoMedia" , ".xml" ) ; temp . deleteOnExit ( ) ; BufferedWriter out = new BufferedWriter ( new FileWriter ( temp ) ) ; out . write ( basicNoMedia ) ; out . close ( ) ; FormDownloader downloader = spy ( new FormDownloader ( ) ) ; FormDetails test1 = new FormDetails ( "No media" , "https://testserver/no-media.xml" , null , "test1" , "2019121201" , "hash" , null , false , false ) ; FormDownloader . FileResult result = new FormDownloader . FileResult ( temp , true ) ; doReturn ( result ) . when ( downloader ) . downloadXform ( test1 . getFormName ( ) , test1 . getDownloadUrl ( ) ) ; doReturn ( true ) . when ( downloader ) . installEverything ( any ( ) , any ( ) , any ( ) ) ; List < FormDetails > forms = new ArrayList < > ( ) ; forms . add ( test1 ) ; HashMap < FormDetails , String > messages = downloader . downloadForms ( forms ) ; assertThat ( messages . get ( test1 ) , is ( "Success" ) ) ; }
Verifies that a form without media can successfully go through the download process.
Verifies that a form without media can successfully go through the download process .