/*
 * Copyright (C) 2015-2017 RWTH Aachen University - Information Systems - Intelligent Distributed Systems Group.
 * All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.rwth.idsg.xsharing.router.iv.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import de.ivu.realtime.modules.ura.data.GeoCoordinates;
import de.ivu.realtime.modules.ura.data.response.PathData;
import org.junit.Test;

import java.io.StringWriter;
import java.io.Writer;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

public class UraSerializerWrapperTest {

    @Test
    public void testSerialize() throws Exception {
        String expected = "{\"version\":null,\"status\":0,\"routeInstructions\":null,\"routeGeometry\":[[50.753,5.712],[50.653,6.012]]}";
        GeoCoordinates[] coords = new GeoCoordinates[2];
        coords[0] = new GeoCoordinates(50.753, 5.712);
        coords[1] = new GeoCoordinates(50.653, 6.012);
        PathData pathData = new PathData.Builder().withRouteGeometry(coords).build();

        ObjectMapper mapper = new ObjectMapper();
        mapper.addMixInAnnotations(PathData.class, UraPathDataMixIn.class);
        Writer stringWriter = new StringWriter();
        try {
            mapper.writeValue(stringWriter, pathData);
            String json = stringWriter.toString();
            assertNotNull(json);
            assertEquals(json, expected);
        } catch (Exception e) {
            fail();
        }
    }
}