use of org.eclipse.persistence.jpa.rs.resources.unversioned.PersistenceResource in project eclipselink by eclipse-ee4j.
the class TestService method testUnmarshallNonExistantLink.
@Test
public void testUnmarshallNonExistantLink() throws URISyntaxException {
PersistenceResource resource = new PersistenceResource();
resource.setPersistenceFactory(factory);
PersistenceContext context = getAuctionPersistenceContext(null);
LinkAdapter adapter = new LinkAdapter("http://localhost:9090/JPA-RS/", context);
DynamicEntity entity1 = null;
DynamicEntity entity2 = null;
try {
entity1 = (DynamicEntity) adapter.unmarshal("http://localhost:9090/JPA-RS/jpars_auction/entity/Auction/1");
} catch (Exception e) {
fail(e.toString());
}
assertTrue("id for Auction was missing", entity1.get("id").equals(1));
try {
entity2 = (DynamicEntity) adapter.unmarshal("http://localhost:9090/JPA-RS/jpars_auction/entity/Address/1+Home");
} catch (Exception e) {
fail(e.toString());
}
assertTrue("id for Address was missing", entity2.get("id").equals(1));
assertTrue("type for Address was missing", entity2.get("type").equals("Home"));
}
use of org.eclipse.persistence.jpa.rs.resources.unversioned.PersistenceResource in project eclipselink by eclipse-ee4j.
the class TestService method testMetadata.
@Test
public void testMetadata() {
PersistenceResource resource = new PersistenceResource();
resource.setPersistenceFactory(factory);
try {
resource.getContexts(TestHttpHeaders.generateHTTPHeader(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_JSON), new TestURIInfo());
} catch (JAXBException e) {
fail(e.toString());
}
}
use of org.eclipse.persistence.jpa.rs.resources.unversioned.PersistenceResource in project eclipselink by eclipse-ee4j.
the class TestService method testMarshallBid.
@Test
public void testMarshallBid() throws Exception {
PersistenceResource resource = new PersistenceResource();
resource.setPersistenceFactory(factory);
PersistenceContext context = getAuctionPersistenceContext(null);
DynamicEntity entity1 = context.newEntity("Auction");
entity1.set("name", "Computer");
DynamicEntity entity2 = context.newEntity("User");
entity2.set("name", "Bob");
context.create(null, entity2);
DynamicEntity entity3 = context.newEntity("Bid");
entity3.set("amount", 200d);
entity3.set("user", entity2);
entity3.set("auction", entity1);
context.create(null, entity3);
InputStream stream = serializeToStream(entity3, context, MediaType.APPLICATION_JSON_TYPE);
try {
entity3 = (DynamicEntity) context.unmarshalEntity("Bid", MediaType.APPLICATION_JSON_TYPE, stream);
} catch (JAXBException e) {
fail("Exception unmarsalling: " + e);
}
(new FetchGroupManager()).setObjectFetchGroup(entity3, null, null);
entity1 = entity3.get("auction");
assertNotNull("Name of auction is null.", entity1.get("name"));
assertTrue("Name of auction is incorrect.", entity1.get("name").equals("Computer"));
}
use of org.eclipse.persistence.jpa.rs.resources.unversioned.PersistenceResource in project eclipselink by eclipse-ee4j.
the class TestServiceNonRelational method testMarshallZips.
@SuppressWarnings("rawtypes")
@Test
public void testMarshallZips() throws Exception {
setContext(ZIPS_PU);
PersistenceResource resource = new PersistenceResource();
resource.setPersistenceFactory(factory);
DynamicEntity zips = context.newEntity("Zips");
zips.set("state", "ON");
zips.set("city", "Ottawa");
zips.set("pop", 6055);
zips.set("id", "1234");
List<Double> loc = new ArrayList<>();
loc.add(45.4214);
loc.add(75.6919);
zips.set("loc", loc);
context.create(null, zips);
InputStream stream = serializeToStream(zips, context, MediaType.APPLICATION_XML_TYPE);
zips = (DynamicEntity) context.unmarshalEntity("Zips", MediaType.APPLICATION_XML_TYPE, stream);
(new FetchGroupManager()).setObjectFetchGroup(zips, null, null);
String state = zips.get("state");
assertNotNull("State of place is null.", state);
assertTrue("ON".equals(state));
String id = zips.get("id");
assertNotNull("id is null.", id);
assertTrue("1234".equals(id));
assertTrue("Unexpected number of objects in loc", (((Collection) zips.get("loc")).size() == 2));
}
use of org.eclipse.persistence.jpa.rs.resources.unversioned.PersistenceResource in project eclipselink by eclipse-ee4j.
the class TestServiceNonRelational method testMarshallPerson.
@Test
public void testMarshallPerson() throws Exception {
setContext(PERSON_PU);
PersistenceResource resource = new PersistenceResource();
resource.setPersistenceFactory(factory);
DynamicEntity person = context.newEntity("Person");
person.set("firstName", "Jim");
person.set("lastName", "Smith");
person.set("age", 48);
person.set("occupation", "Engineer");
person.set("currentEmployer", "Oracle");
List<String> pastEmployers = new ArrayList<>();
pastEmployers.add("BEA");
pastEmployers.add("IBM");
pastEmployers.add("Sun");
person.set("pastEmployers", pastEmployers);
DynamicEntity address1 = context.newEntity("Addresses");
address1.set("street1", "123 Sandy Lane");
address1.set("city", "San Jose");
address1.set("state", "CA");
address1.set("zip", 94143);
DynamicEntity address2 = context.newEntity("Addresses");
address2.set("street1", "334 California Street");
address2.set("city", "San Francisco");
address2.set("state", "CA");
address2.set("zip", 94110);
List<Object> addresses = new ArrayList<>();
addresses.add(address1);
addresses.add(address2);
person.set("addresses", addresses);
context.create(null, person);
InputStream stream = serializeToStream(person, context, MediaType.APPLICATION_XML_TYPE);
person = (DynamicEntity) context.unmarshalEntity("Person", MediaType.APPLICATION_XML_TYPE, stream);
(new FetchGroupManager()).setObjectFetchGroup(person, null, null);
String firstName = person.get("firstName");
assertNotNull("firstName is null.", firstName);
assertTrue("Jim".equals(firstName));
}
Aggregations