Created
December 27, 2011 19:52
-
-
Save livando/1524955 to your computer and use it in GitHub Desktop.
EM ingest metadata service test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.visualdata.rest; | |
import static org.junit.Assert.assertEquals; | |
import static org.junit.Assert.assertNotNull; | |
import java.util.Iterator; | |
import org.apache.commons.httpclient.HttpClient; | |
import org.apache.commons.httpclient.NameValuePair; | |
import org.apache.commons.httpclient.methods.PostMethod; | |
import org.dom4j.Element; | |
import org.junit.Test; | |
import com.openedit.util.XmlUtil; | |
public class IngestMetadataTest { | |
//TODO: update server + env as appropriate | |
private static final String LOCAL = "http://localhost:8080/"; | |
private static final String DEV = ""; | |
private static final String QA = ""; | |
private static final String ENV = LOCAL; | |
//This will remain contstant | |
private static final String BASE = ENV + "entermedia/services/rest/"; | |
private static final String INGEST = BASE + "ingest_metadata.xml"; | |
private static final String LOGIN = BASE + "login.xml"; | |
XmlUtil util = new XmlUtil(); | |
HttpClient fieldClient; | |
public HttpClient getClient() throws Exception { | |
if (fieldClient == null) { | |
fieldClient = new HttpClient(); | |
PostMethod method = new PostMethod(LOGIN); | |
method.addParameter(new NameValuePair("accountname", "admin")); | |
method.addParameter(new NameValuePair("password", "admin")); | |
int statusCode = fieldClient.executeMethod(method); | |
assertEquals(200, statusCode); | |
Element root = util.getXml(method.getResponseBodyAsStream(), "UTF-8"); | |
assertNotNull(root); | |
String ok = root.attributeValue("stat"); | |
assertEquals("ok", ok); | |
} | |
return fieldClient; | |
} | |
@Test | |
public void testGetAttributes() throws Exception { | |
PostMethod method = new PostMethod(INGEST); | |
int statusCode = getClient().executeMethod(method); | |
assertEquals(200, statusCode); | |
Element root = util.getXml(method.getResponseBodyAsStream(), "UTF-8"); | |
Element assets = (Element) root.elementIterator("assets").next(); | |
for (Iterator<Element> i = assets.elementIterator("asset"); i.hasNext();) { | |
Element element = i.next(); | |
assertEquals("Audio", element.attributeValue("name")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment