/**
 * Copyright © CENRA (2016)
 *
 * remi.clement@espaces-naturels.fr
 * 
 * This software is a multi-platform and portable application based on 
 * the scientifical toolbox to monitor wetlands. With this toolbox it’s 
 * possible to calculate indicators «RhoMéO» to monitor quality, 
 * fonctionalities and urban and agricultural pressures of wetlands. 
 * Indicators are calculated using naturalist data entered and/or imported,
 * and geographic data downloaded from a geographic server.
 * 
 * This software is governed by the CeCILL license under French law and
 * abiding by the rules of distribution of free software.  You can  use, 
 * modify and/ or redistribute the software under the terms of the CeCILL
 * license as circulated by CEA, CNRS and INRIA at the following URL
 * "http://www.cecill.info". 
 * 
 * As a counterpart to the access to the source code and  rights to copy,
 * modify and redistribute granted by the license, users are provided only
 * with a limited warranty  and the software's author,  the holder of the
 * economic rights,  and the successive licensors  have only  limited
 * liability. 
 * 
 * In this respect, the user's attention is drawn to the risks associated
 * with loading,  using,  modifying and/or developing or reproducing the
 * software by the user in light of its specific status of free software,
 * that may mean  that it is complicated to manipulate,  and  that  also
 * therefore means  that it is reserved for developers  and  experienced
 * professionals having in-depth computer knowledge. Users are therefore
 * encouraged to load and test the software's suitability as regards their
 * requirements in conditions enabling the security of their systems and/or 
 * data to be ensured and,  more generally, to use and operate it in the 
 * same conditions as regards security. 
 * 
 * The fact that you are presently reading this means that you have had
 * knowledge of the CeCILL license and that you accept its terms.
*/
package fr.cenra.rhomeo.core.data;

import com.fasterxml.jackson.databind.ObjectMapper;
import fr.cenra.rhomeo.api.Version;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.time.ZonedDateTime;

import static org.junit.Assert.*;

/**
 * Verify that the update json file on the server can be read properly.
 */
public class UpdateInfoTest {
    /**
     * Read json update file and ensures its content is conformed and readable.
     *
     * @throws IOException
     */
    @Test
    public void deserializeTest() throws IOException {
        try (final InputStream is = this.getClass().getResourceAsStream("update.json")) {
            final UpdateInfo update = new ObjectMapper().readValue(is, UpdateInfo.class);
            assertNotNull(update);
            assertEquals(new Version("0.1"), update.getVersion());
            assertEquals(ZonedDateTime.parse("2016-04-29T15:00:00+01:00"), update.getDate());
            assertNotNull(update.getReleaseNote());
            assertEquals(1, update.getReleaseNote().length);
            assertEquals("Première version de l'application permettant la gestion de sites", update.getReleaseNote()[0]);
            assertEquals(new URL("http://testwin32").toExternalForm(), update.getWin32().toExternalForm());
            assertEquals("testwin32MD5", update.getWin32MD5());
            assertEquals(new URL("http://testdeb64").toExternalForm(), update.getDeb64().toExternalForm());
            assertEquals("testdeb64MD5", update.getDeb64MD5());
            assertEquals(new URL("http://testrpm64").toExternalForm(), update.getRpm64().toExternalForm());
            assertEquals("testrpm64MD5", update.getRpm64MD5());
            assertEquals(new URL("http://testmacOS64").toExternalForm(), update.getMacOS64().toExternalForm());
            assertEquals("testmacOS64MD5", update.getMacOS64MD5());
        }
    }
}
