package uk.org.taverna.scufl2.api.property;

import static org.junit.Assert.assertEquals;

import java.net.URI;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

public class TestGetProperties {

	private static final URI EXAMPLE_COM = URI.create("http://example.com/");
	private static final URI PROPERTY = EXAMPLE_COM.resolve("#property");

	@Test
	public void getProperties() throws Exception {
		PropertyResource resource = new PropertyResource();
		PropertyReference constant1 = new PropertyResource();
		PropertyReference constant2 = new PropertyResource();
		resource.getProperties().get(PROPERTY).add(constant1);
		resource.getProperties().get(PROPERTY).add(constant2);
		assertEquals(1, resource.getProperties().size());
		assertEquals(2, resource.getProperties().get(PROPERTY).size());

		Set<PropertyReference> expectedProperties = new HashSet<PropertyReference>(
				Arrays.asList(constant1, constant2));

		Set<PropertyReference> propertyReferences = resource
				.getPropertiesAsReferences(PROPERTY);

		assertEquals(expectedProperties, propertyReferences);
	}

	@Test
	public void getPropertiesAsURIs() throws Exception {
		PropertyResource resource = new PropertyResource();
		PropertyResource prop1 = new PropertyResource();
		prop1.addPropertyAsString(PROPERTY.resolve("#yo"), "Hello");
		prop1.addPropertyAsString(PROPERTY.resolve("#yo"), "There");
		PropertyResource prop2 = new PropertyResource();
		prop2.addPropertyAsString(PROPERTY.resolve("#yo"), "Yo");

		resource.getProperties().get(PROPERTY).add(prop1);
		resource.getProperties().get(PROPERTY).add(prop2);
		assertEquals(1, resource.getProperties().size());
		assertEquals(2, resource.getProperties().get(PROPERTY).size());

		Set<PropertyReference> expectedProperties = new HashSet<PropertyReference>(
				Arrays.asList(prop1, prop2));

		Set<PropertyResource> propertiesAsResources = resource
				.getPropertiesAsResources(PROPERTY);

		assertEquals(expectedProperties, propertiesAsResources);

		Set<String> expectedStrings = new HashSet<String>(Arrays.asList(
				"Hello", "There"));
		assertEquals(expectedStrings,
				prop1.getPropertiesAsStrings(PROPERTY.resolve("#yo")));
		assertEquals("Yo", prop2.getPropertyAsString(PROPERTY.resolve("#yo")));
	}

}

@@ -156,16 +156,48 @@
 ashSet;%0A
+import java.util.LinkedHashSet;%0A
 import j
@@ -545,25 +545,20 @@
 ference 
-constant1
+last
  = new P
@@ -570,71 +570,234 @@
 tyRe
-source();%0A%09%09PropertyReference constant2 = new PropertyResource(
+ference(%0A%09%09%09%09EXAMPLE_COM.resolve(%22#xx-last%22));%0A%09%09PropertyReference middle = new PropertyReference(%0A%09%09%09%09EXAMPLE_COM.resolve(%22#mm-middle%22));%0A%09%09PropertyReference first = new PropertyReference(%0A%09%09%09%09EXAMPLE_COM.resolve(%22#aa-first%22)
 );%0A%09
@@ -840,25 +840,20 @@
 TY).add(
-constant1
+last
 );%0A%09%09res
@@ -896,20 +896,71 @@
 add(
-constant2
+first);%0A%09%09resource.getProperties().get(PROPERTY).add(middle
 );%0A
+%0A
 %09%09as
@@ -1014,33 +1014,33 @@
 %0A%09%09assertEquals(
-2
+3
 , resource.getPr
@@ -1116,32 +1116,38 @@
 roperties = new 
+Linked
 HashSet%3CProperty
@@ -1180,28 +1180,27 @@
 ist(
-constant1, constant2
+first, middle, last
 ));%0A

test property order