<commit_before>package org.sagebionetworks.bridge.dynamodb;

import static org.junit.Assert.assertEquals;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;

import org.joda.time.DateTime;
import org.junit.Test;
import org.sagebionetworks.bridge.dynamodb.DynamoTask;
import org.sagebionetworks.bridge.json.BridgeObjectMapper;
import org.sagebionetworks.bridge.models.schedules.Activity;
import org.sagebionetworks.bridge.models.schedules.Task;
import org.sagebionetworks.bridge.models.schedules.TaskStatus;

public class DynamoTaskTest {

    @Test
    public void equalsHashCode() {
        EqualsVerifier.forClass(DynamoTask.class).suppress(Warning.NONFINAL_FIELDS).allFieldsShouldBeUsed().verify();
    }

    @Test
    public void canRoundtripSerialize() throws Exception {
        DynamoTask task = new DynamoTask();
        task.setActivity(new Activity("Label", "task:foo"));
        task.setScheduledOn(DateTime.parse("2015-05-04T02:10:00.000-07:00").getMillis());
        task.setExpiresOn(DateTime.parse("2015-05-12T02:10:00.000-07:00").getMillis());
        task.setGuid("AAA-BBB-CCC");
        task.setSchedulePlanGuid("DDD-EEE-FFF");
        task.setHealthCode("FFF-GGG-HHH");
        
        String output = BridgeObjectMapper.get().writeValueAsString(task);
        assertEquals("{\"guid\":\"AAA-BBB-CCC\",\"scheduledOn\":\"2015-05-04T09:10:00.000Z\",\"expiresOn\":\"2015-05-12T09:10:00.000Z\",\"activity\":{\"label\":\"Label\",\"ref\":\"task:foo\",\"activityType\":\"task\",\"type\":\"Activity\"},\"status\":\"scheduled\",\"type\":\"Task\"}", output);
        
        // zero out the health code field, because that will not be serialized
        task.setHealthCode(null);

        DynamoTask newTask = BridgeObjectMapper.get().readValue(output, DynamoTask.class);
        newTask.setSchedulePlanGuid(task.getSchedulePlanGuid());
        assertEquals(task, newTask);
    }
    
    @Test
    public void hasValidStatusBasedOnTimestamps() throws Exception {
        Task task = new DynamoTask();
        assertEquals(TaskStatus.AVAILABLE, task.getStatus());

        task.setScheduledOn(DateTime.now().plusHours(1).getMillis());
        assertEquals(TaskStatus.SCHEDULED, task.getStatus());
        
        task.setScheduledOn(DateTime.now().minusHours(3).getMillis());
        task.setExpiresOn(DateTime.now().minusHours(1).getMillis());
        assertEquals(TaskStatus.EXPIRED, task.getStatus());
        
        task.setScheduledOn(null);<commit_msg>Fixing tests (dates not fixed)<commit_after>package org.sagebionetworks.bridge.dynamodb;

import static org.junit.Assert.assertEquals;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Test;
import org.sagebionetworks.bridge.dynamodb.DynamoTask;
import org.sagebionetworks.bridge.json.BridgeObjectMapper;
import org.sagebionetworks.bridge.models.schedules.Activity;
import org.sagebionetworks.bridge.models.schedules.Task;
import org.sagebionetworks.bridge.models.schedules.TaskStatus;

public class DynamoTaskTest {

    @Test
    public void equalsHashCode() {
        EqualsVerifier.forClass(DynamoTask.class).suppress(Warning.NONFINAL_FIELDS).allFieldsShouldBeUsed().verify();
    }

    @Test
    public void canRoundtripSerialize() throws Exception {
        DateTime scheduledOn = DateTime.now().plusWeeks(1).withZone(DateTimeZone.UTC);
        DateTime expiresOn = DateTime.now().plusWeeks(1).plusDays(4).withZone(DateTimeZone.UTC);
        
        DynamoTask task = new DynamoTask();
        task.setActivity(new Activity("Label", "task:foo"));
        task.setScheduledOn(scheduledOn.getMillis());
        task.setExpiresOn(expiresOn.getMillis());
        task.setGuid("AAA-BBB-CCC");
        task.setSchedulePlanGuid("DDD-EEE-FFF");
        task.setHealthCode("FFF-GGG-HHH");
        
        String output = BridgeObjectMapper.get().writeValueAsString(task);
        assertEquals("{\"guid\":\"AAA-BBB-CCC\",\"scheduledOn\":\""+scheduledOn.toString()+"\",\"expiresOn\":\""+expiresOn.toString()+"\",\"activity\":{\"label\":\"Label\",\"ref\":\"task:foo\",\"activityType\":\"task\",\"type\":\"Activity\"},\"status\":\"scheduled\",\"type\":\"Task\"}", output);
        
        // zero out the health code field, because that will not be serialized
        task.setHealthCode(null);

        DynamoTask newTask = BridgeObjectMapper.get().readValue(output, DynamoTask.class);
        newTask.setSchedulePlanGuid(task.getSchedulePlanGuid());
        assertEquals(task, newTask);
    }
    
    @Test
    public void hasValidStatusBasedOnTimestamps() throws Exception {
        Task task = new DynamoTask();
        assertEquals(TaskStatus.AVAILABLE, task.getStatus());

        task.setScheduledOn(DateTime.now().plusHours(1).getMillis());
        assertEquals(TaskStatus.SCHEDULED, task.getStatus());
        
        task.setScheduledOn(DateTime.now().minusHours(3).getMillis());
        task.setExpiresOn(DateTime.now().minusHours(1).getMillis());
        assertEquals(TaskStatus.EXPIRED, task.getStatus());
        
        task.setScheduledOn(null);
{'fraction_non_alphanumeric': 0.15139826422372227, 'fraction_numerical': 0.01639344262295082, 'mean_word_length': 3.8740601503759398, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1562763', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1603, 'n_words': 199}