blob: 3d0d216a26466fddbbfbe63d8d0310ff7ef98ca7 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2010-2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* dclarke - EclipseLink 2.4 - MySports Demo Bug 344608
******************************************************************************/
package example.mysports.tests.admin.services.glassfish;
import java.io.FileInputStream;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import junit.framework.Assert;
import org.eclipse.persistence.oxm.MediaType;
import org.junit.Test;
import example.mysports.admin.services.glassfish.MOXyContextHelper;
import example.mysports.admin.services.glassfish.RESTOperations;
import example.mysports.admin.services.glassfish.Result;
public class ParseListJDBCResourcesTests {
@Test
public void unmarshalMarshal() throws Exception {
Unmarshaller unmarshaller = MOXyContextHelper.createUnmarshaller(MediaType.APPLICATION_JSON);
Marshaller marshaller = MOXyContextHelper.createMarshaller(MediaType.APPLICATION_JSON);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
Result resources = unmarshaller.unmarshal(new StreamSource(new FileInputStream(packageFile("list-jdbc-resources.json"))), Result.class).getValue();
Assert.assertNotNull(resources);
marshaller.marshal(resources, System.out);
}
@Test
public void getJDBCResourceNames() throws Exception {
Unmarshaller unmarshaller = MOXyContextHelper.createUnmarshaller(MediaType.APPLICATION_JSON);
Marshaller marshaller = MOXyContextHelper.createMarshaller(MediaType.APPLICATION_JSON);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
Result resources = unmarshaller.unmarshal(new StreamSource(new FileInputStream(packageFile("list-jdbc-resources.json"))), Result.class).getValue();
Assert.assertNotNull(resources);
String[] names = resources.getChildrenMessages();
Assert.assertNotNull(names);
Assert.assertEquals(3, names.length);
for (String name: names) {
System.out.println("JDBC Resource: \"" + name +"\"");
}
}
private String packageFile(String fileName) {
return "src/" + getClass().getPackage().getName().replace(".", "/") + "/" + fileName;
}
@Test
public void getJDBCResourceFromServer() throws JAXBException {
RESTOperations ops = new RESTOperations("localhost");
Result result = ops.get("/domain/resources/list-jdbc-resources", MediaType.APPLICATION_JSON);
System.out.println("RESULT:\n" + result);
for (String name: result.getChildrenMessages()) {
System.out.println("JDBC Resource: \"" + name +"\"");
}
}
}