#102 master - improve GSLayerEncoder21 tests

This commit is contained in:
eblondel 2013-10-18 00:58:23 +02:00
parent 9ca022093b
commit 6f8e457a77

View File

@ -19,6 +19,7 @@
*/ */
package it.geosolutions.geoserver.rest.encoder; package it.geosolutions.geoserver.rest.encoder;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import it.geosolutions.geoserver.rest.encoder.authorityurl.AuthorityURLInfo; import it.geosolutions.geoserver.rest.encoder.authorityurl.AuthorityURLInfo;
@ -49,6 +50,10 @@ public class GSLayerEncoder21Test {
"authority1", "http://www.authority1.org")); "authority1", "http://www.authority1.org"));
layerEncoder.addIdentifier(new GSIdentifierInfoEncoder("authority1", layerEncoder.addIdentifier(new GSIdentifierInfoEncoder("authority1",
"identifier1")); "identifier1"));
layerEncoder.addAuthorityURL(new GSAuthorityURLInfoEncoder(
"authority2", "http://www.authority2.org"));
layerEncoder.addIdentifier(new GSIdentifierInfoEncoder("authority2",
"identifier2"));
} }
@ -63,32 +68,54 @@ public class GSLayerEncoder21Test {
Boolean.parseBoolean(el.getValue())); Boolean.parseBoolean(el.getValue()));
}else if(key.matches("authorityURLs")){ }else if(key.matches("authorityURLs")){
String content = el.getValue(); String jsonStr = el.getValue();
content = content.substring(2); jsonStr = jsonStr.substring(2);
content = content.substring(0, content.length()-3); jsonStr = jsonStr.substring(0,
String[] props = content.split(","); jsonStr.length() - 3);
for(String prop : props){
String[] kvp = prop.split("\":"); String[] items = jsonStr.split("\\}(,)\\{");
if(kvp[0].replace("\"", "").matches(AuthorityURLInfo.name.name())){
Assert.assertEquals("authority1", kvp[1].replace("\"", "")); String[] props1 = items[0].split(",");
}else if(kvp[0].replaceAll("\"", "").matches(AuthorityURLInfo.href.name())){ String[] kvp1_1 = props1[0].split("\":");
Assert.assertEquals("http://www.authority1.org", kvp[1].replace("\"", "")); String[] kvp1_2 = props1[1].split("\":");
} Assert.assertEquals(AuthorityURLInfo.name.name(), kvp1_1[0].replace("\"", ""));
} Assert.assertEquals("authority1", kvp1_1[1].replace("\"", ""));
Assert.assertEquals(AuthorityURLInfo.href.name(), kvp1_2[0].replace("\"", ""));
Assert.assertEquals("http://www.authority1.org", kvp1_2[1].replace("\"", ""));
String[] props2 = items[1].split(",");
String[] kvp2_1 = props2[0].split("\":");
String[] kvp2_2 = props2[1].split("\":");
Assert.assertEquals(AuthorityURLInfo.name.name(), kvp2_1[0].replace("\"", ""));
Assert.assertEquals("authority2", kvp2_1[1].replace("\"", ""));
Assert.assertEquals(AuthorityURLInfo.href.name(), kvp2_2[0].replace("\"", ""));
Assert.assertEquals("http://www.authority2.org", kvp2_2[1].replace("\"", ""));
}else if(key.matches("identifiers")){ }else if(key.matches("identifiers")){
String content = el.getValue(); String jsonStr = el.getValue();
content = content.substring(2); jsonStr = jsonStr.substring(2);
content = content.substring(0, content.length()-3); jsonStr = jsonStr.substring(0,
String[] props = content.split(","); jsonStr.length() - 3);
for(String prop : props){
String[] kvp = prop.split("\":"); String[] items = jsonStr.split("\\}(,)\\{");
if(kvp[0].replace("\"", "").matches(IdentifierInfo.authority.name())){
Assert.assertEquals("authority1", kvp[1].replace("\"", "")); String[] props1 = items[0].split(",");
}else if(kvp[0].replace("\"", "").matches(IdentifierInfo.identifier.name())){ String[] kvp1_1 = props1[0].split("\":");
Assert.assertEquals("identifier1", kvp[1].replace("\"", "")); String[] kvp1_2 = props1[1].split("\":");
} Assert.assertEquals(IdentifierInfo.authority.name(), kvp1_1[0].replace("\"", ""));
} Assert.assertEquals("authority2", kvp1_1[1].replace("\"", ""));
Assert.assertEquals(IdentifierInfo.identifier.name(), kvp1_2[0].replace("\"", ""));
Assert.assertEquals("identifier2", kvp1_2[1].replace("\"", ""));
String[] props2 = items[1].split(",");
String[] kvp2_1 = props2[0].split("\":");
String[] kvp2_2 = props2[1].split("\":");
Assert.assertEquals(IdentifierInfo.authority.name(), kvp2_1[0].replace("\"", ""));
Assert.assertEquals("authority1", kvp2_1[1].replace("\"", ""));
Assert.assertEquals(IdentifierInfo.identifier.name(), kvp2_2[0].replace("\"", ""));
Assert.assertEquals("identifier1", kvp2_2[1].replace("\"", ""));
} }
} }
} }