package com.epam.ta.reportportal.ws.converter.converters;

import com.epam.ta.reportportal.entity.activity.Activity;
import com.epam.ta.reportportal.entity.activity.ActivityDetails;
import com.epam.ta.reportportal.entity.activity.HistoryField;
import com.epam.ta.reportportal.ws.model.ActivityResource;
import org.junit.Test;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Collections;
import java.util.Date;

import static org.junit.Assert.assertEquals;

/**
 * @author <a href="mailto:ihar_kahadouski@epam.com">Ihar Kahadouski</a>
 */
public class ActivityConverterTest {

	@Test(expected = NullPointerException.class)
	public void testNull() {
		ActivityConverter.TO_RESOURCE.apply(null);
	}

	@Test
	public void testConvert() {
		Activity activity = new Activity();
		activity.setId(1L);
		activity.setAction("LAUNCH_STARTED");
		activity.setCreatedAt(LocalDateTime.now());
		final ActivityDetails details = new ActivityDetails();
		details.setObjectName("objectName");
		details.setHistory(Collections.singletonList(HistoryField.of("filed", "old", "new")));
		activity.setDetails(details);
		activity.setUsername("username");
		activity.setActivityEntityType(Activity.ActivityEntityType.LAUNCH);
		activity.setProjectId(2L);
		activity.setUserId(3L);
		validate(activity, ActivityConverter.TO_RESOURCE.apply(activity));
	}

	private void validate(Activity db, ActivityResource resource) {
		assertEquals(Date.from(db.getCreatedAt().atZone(ZoneId.of("UTC")).toInstant()), resource.getLastModifiedDate());
		assertEquals(String.valueOf(db.getId()), resource.getActivityId());
		assertEquals(db.getActivityEntityType(), Activity.ActivityEntityType.fromString(resource.getObjectType()).get());
		assertEquals(String.valueOf(db.getUserId()), resource.getUserRef());
		assertEquals(String.valueOf(db.getProjectId()), resource.getProjectRef());
		assertEquals(db.getAction(), resource.getActionType());
		assertEquals(String.valueOf(db.getId()), resource.getActivityId());
	}
}
@@ -1521,20 +1521,16 @@
 Modified
-Date
 ());%0A%09%09a
@@ -1537,39 +1537,24 @@
 ssertEquals(
-String.valueOf(
 db.getId()),
@@ -1543,33 +1543,32 @@
 quals(db.getId()
-)
 , resource.getAc
@@ -1561,32 +1561,24 @@
 resource.get
-Activity
 Id());%0A%09%09ass
@@ -1751,19 +1751,16 @@
 .getUser
-Ref
 ());%0A%09%09a
@@ -1767,39 +1767,24 @@
 ssertEquals(
-String.valueOf(
 db.getProjec
@@ -1784,25 +1784,24 @@
 tProjectId()
-)
 , resource.g
@@ -1813,11 +1813,10 @@
 ject
-Ref
+Id
 ());
@@ -1878,78 +1878,8 @@
 ));%0A
-%09%09assertEquals(String.valueOf(db.getId()), resource.getActivityId());%0A
 %09%7D%0A%7D

update model