/*
 * Copyright 2018 B2i Healthcare Pte Ltd, http://b2i.sg
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.b2international.snowowl.fhir.tests.serialization.parameterized;

import org.junit.Assert;
import org.junit.Test;

import com.b2international.snowowl.fhir.core.model.dt.Code;
import com.b2international.snowowl.fhir.core.model.dt.Parameters;
import com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir;
import com.b2international.snowowl.fhir.tests.FhirTest;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

/**
 * Basic FHIR parameter serialization tests.
 * Example: String parameterName = "test" -> {"name":"parameterName", "valueString":"test"}
 * @since 6.4
 */
public class ParameterSerializationTest extends FhirTest {
	
	@Test
	public void stringParameterTest() throws Exception {
		
		@SuppressWarnings("unused")
		@JsonPropertyOrder({"parameterName"})
		class StringTestParameterObject {
			
			private String parameterName = "test";

			public String getParameterName() {
				return parameterName;
			}

			public void setParameterName(String parameterName) {
				this.parameterName = parameterName;
			}
		}
		
		String expected = buildExpectedJson("{\"name\":\"parameterName\",\"valueString\":\"test\"}");
		Fhir fhirParameters = new Parameters.Fhir(new StringTestParameterObject());
		
		printPrettyJson(fhirParameters);
		Assert.assertEquals(expected, objectMapper.writeValueAsString(fhirParameters));
	}
	
	@Test
	public void integerParameterTest() throws Exception {
		
		@SuppressWarnings("unused")
		@JsonPropertyOrder({"parameterName"})
		class Test {
			
			private Integer parameterName = 1;

			public Integer getParameterName() {
				return parameterName;
			}

			public void setParameterName(Integer parameterName) {
				this.parameterName = parameterName;
			}
		}
		
		String expected = buildExpectedJson("{\"name\":\"parameterName\",\"valueInteger\":1}");
		
		Fhir fhirParameters = new Parameters.Fhir(new Test());
		printPrettyJson(fhirParameters);
		Assert.assertEquals(expected, objectMapper.writeValueAsString(fhirParameters));
	}
	
	@Test
	public void codeParameterTest() throws Exception {
		
		@SuppressWarnings("unused")
		@JsonPropertyOrder({"parameterName"})
		class Test {
			
			private Code parameterName = new Code("test");

			public Code getParameterName() {
				return parameterName;
			}

			public void setParameterName(Code parameterName) {
				this.parameterName = parameterName;
			}
		}
		
		String expected = buildExpectedJson("{\"name\":\"parameterName\",\"valueCode\":\"test\"}");
		
		Fhir fhirParameters = new Parameters.Fhir(new Test());
		printPrettyJson(fhirParameters);
		Assert.assertEquals(expected, objectMapper.writeValueAsString(fhirParameters));
	}
	
	private String buildExpectedJson(String parameterString) {
		return "{\"resourceType\":\"Parameters\","
					+ "\"parameter\":["
						+ parameterString
					+ "]"
				+ "}";
	}
}

@@ -693,16 +693,46 @@
 rized;%0A%0A
+import java.util.Collection;%0A%0A
 import o
@@ -748,16 +748,16 @@
 Assert;%0A
-
 import o
@@ -832,16 +832,148 @@
 t.Code;%0A
+import com.b2international.snowowl.fhir.core.model.dt.FhirDataType;%0Aimport com.b2international.snowowl.fhir.core.model.dt.FhirType;%0A
 import c
@@ -1157,16 +1157,16 @@
 irTest;%0A
-
 import c
@@ -1215,16 +1215,55 @@
 tyOrder;
+%0Aimport com.google.common.collect.Sets;
 %0A%0A/**%0A *
@@ -3467,16 +3467,780 @@
 );%0A%09%7D%0A%09%0A
+%09@Test%0A%09public void collectionParameterTest() throws Exception %7B%0A%09%09%0A%09%09@SuppressWarnings(%22unused%22)%0A%09%09@JsonPropertyOrder(%7B%22parameterName%22%7D)%0A%09%09class Test %7B%0A%09%09%09%0A%09%09%09@FhirType(FhirDataType.PART)%0A%09%09%09private Collection%3CCode%3E parameterName = Sets.newHashSet(new Code(%22first%22), new Code(%22second%22));%0A%0A%09%09%09public Collection%3CCode%3E getParameterName() %7B%0A%09%09%09%09return parameterName;%0A%09%09%09%7D%0A%0A%09%09%09public void setParameterName(Collection%3CCode%3E parameterName) %7B%0A%09%09%09%09this.parameterName = parameterName;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09String expected = buildExpectedJson(%22%7B%5C%22name%5C%22:%5C%22parameterName%5C%22,%5C%22valueCode%5C%22:%5C%22test%5C%22%7D%22);%0A%09%09%0A%09%09Fhir fhirParameters = new Parameters.Fhir(new Test());%0A%09%09printPrettyJson(fhirParameters);%0A%09%09Assert.assertEquals(expected, objectMapper.writeValueAsString(fhirParameters));%0A%09%7D%0A%09%0A
 %09private

Test case for collection serialization added.