}
/* Package Creation */
@Test @RunAsClient
public void testCreatePackageFromJAXB(@ArquillianResource URL baseURL) throws Exception {
Package p = createTestPackage("TestCreatePackageFromJAXB");
p.setDescription("desc for testCreatePackageFromJAXB");
JAXBContext context = JAXBContext.newInstance(p.getClass());
Marshaller marshaller = context.createMarshaller();
StringWriter sw = new StringWriter();
marshaller.marshal(p, sw);
String xml = sw.toString();
URL url = new URL(baseURL, "rest/packages");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestProperty("Authorization",
"Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
connection.setRequestMethod("POST");
connection.setRequestProperty("Accept", MediaType.APPLICATION_XML);
connection.setRequestProperty("Content-Type", MediaType.APPLICATION_XML);
connection.setRequestProperty("Content-Length", Integer.toString(xml.getBytes().length));
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
//Send request
DataOutputStream wr = new DataOutputStream (
connection.getOutputStream ());
wr.writeBytes (xml);
wr.flush ();
wr.close ();
assertEquals (200, connection.getResponseCode());
assertEquals(MediaType.APPLICATION_XML, connection.getContentType());
//System.out.println(IOUtils.toString(connection.getInputStream()));
Package result = unmarshalPackageXML(connection.getInputStream());
assertEquals("TestCreatePackageFromJAXB", result.getTitle());
assertEquals("desc for testCreatePackageFromJAXB", result.getDescription());
assertNotNull(result.getPublished());
assertEquals(new URL(baseURL, "rest/packages/TestCreatePackageFromJAXB/source").toExternalForm(), result.getSourceLink().toString());
assertEquals(new URL(baseURL, "rest/packages/TestCreatePackageFromJAXB/binary").toExternalForm(), result.getBinaryLink().toString());
PackageMetadata pm = result.getMetadata();
assertFalse(pm.isArchived());
assertNotNull(pm.getCreated());
assertNotNull(pm.getUuid());
}