package com.b2international.snowowl.snomed.api.rest.components;

import static com.b2international.snowowl.snomed.api.rest.SnomedComponentApiAssert.assertComponentCanBeUpdated;
import static com.b2international.snowowl.snomed.api.rest.SnomedComponentApiAssert.assertComponentHasProperty;
import static com.b2international.snowowl.snomed.api.rest.SnomedComponentApiAssert.assertConceptExists;

import java.util.Map;

import org.junit.Test;

import com.b2international.snowowl.snomed.api.rest.AbstractSnomedApiTest;
import com.b2international.snowowl.snomed.api.rest.SnomedComponentType;
import com.b2international.snowowl.snomed.core.domain.DefinitionStatus;
import com.google.common.collect.ImmutableMap;

public class SnomedReleasedConceptApiTest extends AbstractSnomedApiTest {

	@Test
	public void automaticRestorationOfEffectiveTime() {
		final String conceptId = "63961392103";
		assertConceptExists(testBranchPath, conceptId);
		
		assertComponentHasProperty(testBranchPath, SnomedComponentType.CONCEPT, conceptId, "effectiveTime", "20150131");
		
		updateDefinitionStatus(conceptId, DefinitionStatus.FULLY_DEFINED);

		assertComponentHasProperty(testBranchPath, SnomedComponentType.CONCEPT, conceptId, "effectiveTime", null);

		updateDefinitionStatus(conceptId, DefinitionStatus.PRIMITIVE);

		assertComponentHasProperty(testBranchPath, SnomedComponentType.CONCEPT, conceptId, "effectiveTime", "20150131");
	}

	private void updateDefinitionStatus(final String conceptId,
			final DefinitionStatus definitionStatus) {
		final Map<?, ?> updateRequestBody = ImmutableMap.builder()
				.put("definitionStatus", definitionStatus.toString())
				.put("commitComment", "Changed concept definition status")
				.build();
		assertComponentCanBeUpdated(testBranchPath, SnomedComponentType.CONCEPT, conceptId, updateRequestBody);
	}

}

@@ -54,24 +54,128 @@
 omponents;%0A%0A
+import static com.b2international.snowowl.snomed.api.rest.SnomedBranchingApiAssert.givenBranchWithPath;%0A
 import stati
@@ -934,24 +934,63 @@
 iveTime() %7B%0A
+%09%09givenBranchWithPath(testBranchPath);%0A
 %09%09final Stri
@@ -1176,27 +1176,27 @@
 ime%22, %2220150
-131
+204
 %22);%0A%09%09%0A%09%09upd
@@ -1548,11 +1548,11 @@
 0150
-131
+204
 %22);%0A

Test fix for restoration of effective times.