package sg.ncl.service.data.data.jpa;

import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Created by dcszwang on 10/6/2016.
 */
public class DataResourceEntityTest {

    @Test
    public void testGetId() {
        DataResourceEntity entity = new DataResourceEntity();
        assertThat(entity.getId()).isNull();
    }

    @Test
    public void testSetId() {
        DataResourceEntity entity = new DataResourceEntity();
        Long id = Long.parseLong(RandomStringUtils.randomNumeric(10));
        entity.setId(id);
        assertThat(entity.getId()).isEqualTo(id);
    }

    @Test
    public void testGetLink() {
        DataResourceEntity entity = new DataResourceEntity();
        assertThat(entity.getUri()).isNull();
    }

    @Test
    public void testSetLink() {
        DataResourceEntity entity = new DataResourceEntity();
        String link = RandomStringUtils.randomAlphanumeric(20);
        entity.setUri(link);
        assertThat(entity.getUri()).isEqualTo(link);
    }

    @Test
    public void testToString() {
        DataResourceEntity entity = new DataResourceEntity();
        entity.setId(Long.parseLong(RandomStringUtils.randomNumeric(10)));
        entity.setUri(RandomStringUtils.randomAlphanumeric(20));

        final String toString = entity.toString();

        assertThat(toString).contains(entity.getId().toString());
        assertThat(toString).contains(entity.getUri());
    }

    @Test
    public void testEqualsNot() {
        DataResourceEntity entity = new DataResourceEntity();
        assertThat(entity.equals(null)).isFalse();
    }

    @Test
    public void testEqualsUri() {
        String link = RandomStringUtils.randomAlphanumeric(20);
        DataResourceEntity entity1 = new DataResourceEntity();
        DataResourceEntity entity2 = new DataResourceEntity();
        entity1.setUri(link);
        entity2.setUri(link);
        assertThat(entity1.equals(entity2)).isTrue();
    }

    @Test
    public void testHashCode() {
        String link = RandomStringUtils.randomAlphanumeric(20);
        DataResourceEntity entity = new DataResourceEntity();
        entity.setUri(link);
        assertThat(entity.hashCode()).isEqualTo(link.hashCode());
    }
}

@@ -1066,32 +1066,403 @@
 o(link);%0A    %7D%0A%0A
+    @Test%0A    public void testIsMalicious() %7B%0A        DataResourceEntity entity = new DataResourceEntity();%0A        assertThat(entity.isMalicious()).isFalse();%0A    %7D%0A%0A    @Test%0A    public void testSetIsMalicious() %7B%0A        DataResourceEntity entity = new DataResourceEntity();%0A        entity.setMalicious(true);%0A        assertThat(entity.isMalicious()).isTrue();%0A    %7D%0A%0A
     @Test%0A    pu
@@ -2028,32 +2028,143 @@
 False();%0A    %7D%0A%0A
+    // test two data resource objects%0A    // identical uri%0A    // different malicious%0A    // expected is false%0A
     @Test%0A    pu
@@ -2183,19 +2183,37 @@
 stEquals
-Uri
+NotDifferentMalicious
 () %7B%0A   
@@ -2451,32 +2451,542 @@
 2.setUri(link);%0A
+        entity1.setMalicious(true);%0A        entity2.setMalicious(false);%0A        assertThat(entity1.equals(entity2)).isFalse();%0A    %7D%0A%0A    @Test%0A    public void testEqualsDataResource() %7B%0A        String link = RandomStringUtils.randomAlphanumeric(20);%0A        DataResourceEntity entity1 = new DataResourceEntity();%0A        DataResourceEntity entity2 = new DataResourceEntity();%0A        entity1.setUri(link);%0A        entity2.setUri(link);%0A        entity1.setMalicious(true);%0A        entity2.setMalicious(true);%0A
         assertTh

update test case to reflect on newly added columns