Sha256: 4ab1edab7601cd3994fdfa699e8ec9fbd5e9f8cea3455378809064e2060276c2

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

package org.embulk.filter.typecast.cast;

import org.embulk.EmbulkTestRuntime;
import org.embulk.spi.DataException;
import org.embulk.spi.time.Timestamp;
import org.embulk.spi.time.TimestampFormatter;
import org.embulk.spi.time.TimestampParser;
import org.joda.time.DateTimeZone;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.msgpack.value.Value;
import org.msgpack.value.ValueFactory;

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

public class TestTimestampCast
{
    @Rule
    public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
    public Timestamp timestamp;

    @Before
    public void createResource()
    {
        timestamp = Timestamp.ofEpochSecond(1463084053, 500000000);
    }

    @Test(expected = DataException.class)
    public void asBoolean()
    {
        TimestampCast.asBoolean(timestamp);
    }

    @Test
    public void asLong()
    {
        assertEquals(timestamp.getEpochSecond(), TimestampCast.asLong(timestamp));
    }

    @Test
    public void asDouble()
    {
        double unixtimestamp = timestamp.getEpochSecond() + timestamp.getNano() / 1000000000.0;
        assertEquals(unixtimestamp, TimestampCast.asDouble(timestamp), 0.0);
    }

    @Test
    public void asString()
    {
        TimestampFormatter formatter = new TimestampFormatter("%Y-%m-%d %H:%M:%S.%6N", DateTimeZone.UTC);
        assertEquals("2016-05-12 20:14:13.500000", TimestampCast.asString(timestamp, formatter));
    }

    @Test(expected = DataException.class)
    public void asJson()
    {
        TimestampCast.asJson(timestamp);
    }

    @Test
    public void asTimestamp()
    {
        assertEquals(timestamp, TimestampCast.asTimestamp(timestamp));
    }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
embulk-filter-typecast-0.2.0 src/test/java/org/embulk/filter/typecast/cast/TestTimestampCast.java