package org.springframework.cloud.pivotal.cloudfoundry;

import java.util.List;
import java.util.Map;

import org.junit.Assert;
import org.junit.Test;
import org.springframework.cloud.pivotal.service.common.GemfireServiceInfo;

import com.fasterxml.jackson.databind.ObjectMapper;

public class GemfireServiceInfoCreatorTest {

	private ObjectMapper mapper = new ObjectMapper();

	@Test
	public void testInfoCreator() throws Exception {
		GemfireServiceInfoCreator creator = new GemfireServiceInfoCreator();
		Map services = mapper.readValue(GemfireServiceInfoCreatorTest.class.getClassLoader().getSystemResourceAsStream("org/springframework/cloud/pivotal/cloudfoundry/test-gemfire-service.json"), Map.class);
		Map<String, Object> serviceData = (Map<String, Object>) ((List) services.get("p-gemfire")).get(0);

		GemfireServiceInfo info = creator.createServiceInfo(serviceData);
		Assert.assertNotNull(info);
	}

	@Test
	public void testAcceptService() throws Exception {
		GemfireServiceInfoCreator creator = new GemfireServiceInfoCreator();
		Map services = mapper.readValue(GemfireServiceInfoCreatorTest.class.getClassLoader().getSystemResourceAsStream("org/springframework/cloud/pivotal/cloudfoundry/test-gemfire-service.json"), Map.class);
		Map<String, Object> serviceData = (Map<String, Object>) ((List) services.get("p-gemfire")).get(0);
		boolean accepts = creator.accept(serviceData);
		Assert.assertEquals(true, accepts);
	}
	
	@Test
	public void testInfoCreatorCups() throws Exception {
		GemfireServiceInfoCreator creator = new GemfireServiceInfoCreator();
		Map services = mapper.readValue(GemfireServiceInfoCreatorTest.class.getClassLoader().getSystemResourceAsStream("org/springframework/cloud/pivotal/cloudfoundry/test-gemfire-userprovided.json"), Map.class);
		Map<String, Object> serviceData = (Map<String, Object>) ((List) services.get("user-provided")).get(0);

		GemfireServiceInfo info = creator.createServiceInfo(serviceData);
		Assert.assertNotNull(info);
	}
	@Test
	public void testAcceptCups() throws Exception {
		GemfireServiceInfoCreator creator = new GemfireServiceInfoCreator();
		Map services = mapper.readValue(GemfireServiceInfoCreatorTest.class.getClassLoader().getSystemResourceAsStream("org/springframework/cloud/pivotal/cloudfoundry/test-gemfire-userprovided.json"), Map.class);
		Map<String, Object> serviceData = (Map<String, Object>) ((List) services.get("user-provided")).get(0);
		boolean accepts = creator.accept(serviceData);
		Assert.assertEquals(true, accepts);
	}
	
}

@@ -140,24 +140,105 @@
 junit.Test;%0A
+import org.springframework.cloud.cloudfoundry.AbstractCloudFoundryConnectorTest;%0A
 import org.s
@@ -398,16 +398,58 @@
 torTest 
+extends AbstractCloudFoundryConnectorTest 
 %7B%0A%0A%09priv
@@ -644,152 +644,25 @@
 s = 
-mapper.readValue(GemfireServiceInfoCreatorTest.class.getClassLoader().getSystemResourceAsStream(%22org/springframework/cloud/pivotal/cloudfoundry/
+readServiceData(%22
 test
@@ -680,36 +680,24 @@
 rvice.json%22)
-, Map.class)
 ;%0A%09%09Map%3CStri
@@ -726,46 +726,31 @@
 a = 
-(Map%3CString, Object%3E) ((List) 
+getServiceData(
 services
 .get
@@ -737,37 +737,34 @@
 iceData(services
-.get(
+, 
 %22p-gemfire%22)).ge
@@ -759,24 +759,16 @@
 emfire%22)
-).get(0)
 ;%0A%0A%09%09Gem
@@ -1015,152 +1015,25 @@
 s = 
-mapper.readValue(GemfireServiceInfoCreatorTest.class.getClassLoader().getSystemResourceAsStream(%22org/springframework/cloud/pivotal/cloudfoundry/
+readServiceData(%22
 test
@@ -1051,36 +1051,24 @@
 rvice.json%22)
-, Map.class)
 ;%0A%09%09Map%3CStri
@@ -1097,46 +1097,31 @@
 a = 
-(Map%3CString, Object%3E) ((List) 
+getServiceData(
 services
 .get
@@ -1116,21 +1116,18 @@
 services
-.get(
+, 
 %22p-gemfi
@@ -1130,24 +1130,16 @@
 emfire%22)
-).get(0)
 ;%0A%09%09bool
@@ -1222,17 +1222,16 @@
 ts);%0A%09%7D%0A
-%09
 %0A%09@Test%0A
@@ -1376,152 +1376,25 @@
 s = 
-mapper.readValue(GemfireServiceInfoCreatorTest.class.getClassLoader().getSystemResourceAsStream(%22org/springframework/cloud/pivotal/cloudfoundry/
+readServiceData(%22
 test
@@ -1417,36 +1417,24 @@
 vided.json%22)
-, Map.class)
 ;%0A%09%09Map%3CStri
@@ -1463,46 +1463,31 @@
 a = 
-(Map%3CString, Object%3E) ((List) 
+getServiceData(
 services
 .get
@@ -1474,37 +1474,34 @@
 iceData(services
-.get(
+, 
 %22user-provided%22)
@@ -1500,24 +1500,16 @@
 ovided%22)
-).get(0)
 ;%0A%0A%09%09Gem
@@ -1604,16 +1604,17 @@
 fo);%0A%09%7D%0A
+%0A
 %09@Test%0A%09
@@ -1753,152 +1753,25 @@
 s = 
-mapper.readValue(GemfireServiceInfoCreatorTest.class.getClassLoader().getSystemResourceAsStream(%22org/springframework/cloud/pivotal/cloudfoundry/
+readServiceData(%22
 test
@@ -1802,20 +1802,8 @@
 on%22)
-, Map.class)
 ;%0A%09%09
@@ -1840,46 +1840,31 @@
 a = 
-(Map%3CString, Object%3E) ((List) 
+getServiceData(
 services
 .get
@@ -1859,21 +1859,18 @@
 services
-.get(
+, 
 %22user-pr
@@ -1881,16 +1881,8 @@
 ed%22)
-).get(0)
 ;%0A%09%09
@@ -1969,12 +1969,331 @@
 ts);%0A%09%7D%0A
-%09
+%0A%09private Map readServiceData(String resource) throws java.io.IOException %7B%0A%09%09return mapper.readValue(readTestDataFile(resource), Map.class);%0A%09%7D%0A%0A%09@SuppressWarnings(%22unchecked%22)%0A%09private Map%3CString, Object%3E getServiceData(Map services, String name) %7B%0A%09%09return (Map%3CString, Object%3E) ((List) services.get(name)).get(0);%0A%09%7D
 %0A%7D%0A

Remove compile warnings.