@RequestMapping(value = "/", method = RequestMethod.POST) public String createInstance(@Valid WebInstance instance) throws JasDBException { DBSession session = sessionFactory.createSession(); session.addInstance(instance.getName()); return "redirect:/data/"; }
@Test public void addInstance() throws JasDBException, IOException { DBSession session = sessionFactory.createSession(); session.addInstance(MY_INSTANCE); List<Instance> instanceList = session.getInstances(); assertEquals(2, instanceList.size()); session.createOrGetBag(MY_INSTANCE, "testbag"); File instanceLocation = new File(storageLocation + "/.jasdb/myInstance"); assertThat(instanceLocation.exists(), is(true)); assertThat(new File(instanceLocation, "testbag.pjs").exists(), is(true)); }
@Test public void testCreateAndInsertEntities() throws JasDBException, IOException { DBSession session = sessionFactory.createSession(); session.addInstance(MY_INSTANCE); EntityBag bag = session.createOrGetBag(MY_INSTANCE, BAG_1); bag.addEntity(new SimpleEntity().addProperty("test", "value")); QueryResult result = bag.getEntities(); assertThat(result.size(), is(1l)); Entity entity = result.next(); assertThat(entity, notNullValue()); assertThat(entity.getProperty("test").getFirstValue().toString(), is("value")); }
@Test public void testCreateAndGetInstanceBag() throws JasDBException, IOException { DBSession session = sessionFactory.createSession(); session.addInstance(MY_INSTANCE); session.createOrGetBag(MY_INSTANCE, BAG_1); //default instance should be null assertNull(session.getBag(BAG_1)); assertNotNull(MY_INSTANCE, session.getBag(MY_INSTANCE, BAG_1)); }
@Test public void addSessionInstanceBound() throws JasDBException, IOException { DBSession session = sessionFactory.createSession(); assertEquals("default", session.getInstanceId()); session.createOrGetBag("testbag"); assertEquals(1, session.getBags().size()); session.addInstance(MY_INSTANCE); assertEquals("default", session.getInstanceId()); DBSession newSession = sessionFactory.createSession(MY_INSTANCE); newSession.createOrGetBag(BAG_1); newSession.createOrGetBag("bag2"); assertEquals(MY_INSTANCE, newSession.getInstanceId()); assertEquals(2, newSession.getBags().size()); assertEquals(1, session.getBags().size()); }
@Test public void testSwitchInstance() throws JasDBException, IOException { DBSession session = sessionFactory.createSession(); session.addInstance(MY_INSTANCE); assertEquals("default", session.getInstanceId()); session.switchInstance(MY_INSTANCE); assertEquals(MY_INSTANCE, session.getInstanceId()); session.addAndSwitchInstance("anotherInstance"); assertEquals("anotherInstance", session.getInstanceId()); }