private Employee getEmployee() { return session.get(Employee.class, ids.get(0)); }
@Test public void SelfReferenceTest() { AType atype = session.get(AType.class, id); assertNotNull(atype); assertEquals(session.getLID(id), atype.id); assertNotNull(atype.asBType); assertEquals(session.getLID(id), atype.asBType.id); }
private Company getCompany() { return session.get(Company.class, ids.get(1)); }
@SuppressWarnings("unchecked") private <RT> RT getAsProjectionValue(NODE node, Class<RT> type) { if (node.isResource()) { if (type.equals(String.class)) { // TODO : always return LID ? return (RT) session.getLID(node.asResource()).getId(); } else { return session.get(type, node.asResource()); } } else { return converterRegistry.fromString(node.getValue(), type); } }
@Test public void GetTerm() { System.out.println("Get term"); Term term = session.get(Term.class, termId); assertNotNull(term); }
@Test public void Local() { LID lid = session.getLID(new BID("foobar")); LIDResource resource1 = session.get(LIDResource.class, lid); assertNotNull(resource1); LID id = resource1.id; assertNotNull(id); // assertTrue(id instanceof LID); assertTrue(Integer.parseInt(id.getId()) > 0); } }
@Test public void GetNote() { System.out.println("Get note1"); Note note = session.get(Note.class, note1Id); assertNotNull(note); }
@Test public void Bnode() { LID lid = session.getLID(new BID("foobar")); IDResource resource1 = session.get(IDResource.class, lid); assertNotNull(resource1); ID id = resource1.id; assertNotNull(id); assertTrue(id instanceof BID); assertEquals(new BID("foobar"), id); }
@Test public void Get_Null_Result() { assertNull(session.get(Note.class, new BID())); }
@Test public void test() { Session session = SessionUtil.openSession(Company.class, Department.class, Employee.class); Company company = new Company(); Department department = new Department(); Employee employee = new Employee(); employee.department = department; department.company = company; session.save(company); session.save(department); session.save(employee); session.flush(); session.clear(); department = session.get(Department.class, department.id); assertFalse(department.employees.isEmpty()); assertTrue(department.employees.iterator().next() instanceof Employee); company = session.get(Company.class, company.id); assertFalse(company.departments.isEmpty()); assertTrue(company.departments.iterator().next() instanceof Department); }
@Test public void MultiProperties() { MiniRepository repository = new MiniRepository(); Session session = SessionUtil.openSession(repository, MultiPropertyTest.class); MultiPropertyTest test = new MultiPropertyTest(); test.names.add("Tom"); test.names.add("Jane"); test.namesList.add("Tom"); test.namesList.add("Jane"); test.namesArray = new String[] { "Tom", "Jane" }; session.save(test); session.clear(); List<STMT> stmts = IteratorAdapter.asList(repository.findStatements(null, NAME, null, null, false)); assertEquals(2, stmts.size()); stmts = IteratorAdapter.asList(repository.findStatements(null, NAME2, null, null, false)); assertEquals(2, stmts.size()); stmts = IteratorAdapter.asList(repository.findStatements(null, NAME3, null, null, false)); assertEquals(2, stmts.size()); MultiPropertyTest test2 = session.get(MultiPropertyTest.class, test.id); assertEquals(test.names, test2.names); // ordering is not preseved assertEquals(Sets.newHashSet(test.namesList), Sets.newHashSet(test2.namesList)); // ordering is not preseved assertEquals(Sets.newHashSet(test.namesArray), Sets.newHashSet(test2.namesArray)); }
@Test(expected = IllegalArgumentException.class) public void Error() { MiniRepository repository = new MiniRepository(); UID id = new UID("http://example2.com/abc"); UID type = new UID(TEST.NS, "IdMappingTest"); repository.add(new STMT(id, RDF.type, type)); Session session = SessionUtil.openSession(repository, IdMappingTest.class); session.get(IdMappingTest.class, id); }
@Test public void UpdateProjection() { EmployeeInfo einfo = session.get(EmployeeInfo.class, ids.get(0)); assertEquals("John Doe", einfo.name); assertEquals("Example", einfo.companyName); einfo.name = "Jane Doe"; einfo.companyName = "Ignore this"; session.save(einfo); newSession(); Employee employee = getEmployee(); assertEquals("Jane Doe", employee.name); // Nothing else should have changed assertEquals(30, employee.age); assertNotNull(employee.company); assertEquals("Example", employee.company.name); }
entity = session.get(Entity.class, entity.id); assertEquals(2, entity.properties.size()); // XXX by design assertEquals(1, entity.properties2.size());
@Test public void ConstructorInjection() { Session session = SessionUtil.openSession(Entity.class); Entity entity = new Entity(new BID(), "Jon", "Doe"); session.save(entity); session.clear(); entity = session.get(Entity.class, entity.id); assertEquals("Jon", entity.firstName); assertEquals("Doe", entity.lastName); } }
@Test public void ConstructorInjection() { Session session = SessionUtil.openSession(Child.class, Parent.class); Parent parent = new Parent(); Child child = new Child(parent); session.saveAll(parent, child); session.flush(); session.clear(); Child child2 = session.get(Child.class, child.id); assertNotNull(child2); assertEquals(child.id, child2.id); assertEquals(child.parent.id, child2.parent.id); }
@Test public void Success() { MiniRepository repository = new MiniRepository(); Session session = SessionUtil.openSession(repository, IdMappingTest.class); IdMappingTest instance = new IdMappingTest(); instance.id = "abc"; session.save(instance); session.clear(); UID id = new UID("http://example.com/abc"); assertTrue(repository.exists(id, null, null, null)); IdMappingTest instance2 = session.get(IdMappingTest.class, id); assertEquals(instance.id, instance2.id); }
@Test public void Array() { MiniRepository repository = new MiniRepository(); Session session = SessionUtil.openSession(repository, ArrayTest.class); ArrayTest test = new ArrayTest(); test.array = new String[] { "a", "b", "c" }; test.numbers = new int[] { 1, 2, 3 }; session.save(test); session.clear(); ArrayTest test2 = session.get(ArrayTest.class, new LID(test.id)); assertEquals(test.id, test2.id); assertArrayEquals(test.array, test2.array); assertArrayEquals(test.numbers, test2.numbers); }
@Test @Ignore // inverse properties are not stored public void testInverseIDMapping() { Song song = new Song(); MusicStore musicStore = new MusicStore(); SongPlayback songPlayback = new SongPlayback(); ID songLID = session.save(song); ID musicStoreLID = session.save(musicStore); session.flush(); song = session.get(Song.class, songLID); musicStore = session.get(MusicStore.class, musicStoreLID); session.clear(); songPlayback.datetime = new DateTime(); songPlayback.song = song.id; songPlayback.store = musicStore.id; session.save(songPlayback); session.flush(); session.clear(); MiniConnection conn = repository.openConnection(); assertTrue(conn.exists(null, new UID("http://www.foo.com#musicStore"), null, null, true)); assertTrue(conn.exists(null, new UID("http://www.foo.com#playback"), null, null, true)); conn.close(); } }
@Test public void ConstructorInjection() { Session session = SessionUtil.openSession(Child.class, Parent.class); Parent parent = new Parent(); Child child = new Child(new BID(), parent); session.saveAll(parent, child); session.flush(); session.clear(); Child child2 = session.get(Child.class, child.id); assertNotNull(child2); assertEquals(child.id, child2.id); assertEquals(child.parent.id, child2.parent.id); }