/** To-one relationship, resolved on first access. */ public Event getEvent() { long __key = this.event_id; if (event__resolvedKey == null || !event__resolvedKey.equals(__key)) { if (daoSession == null) { throw new DaoException("Entity is detached from DAO context"); } EventDao targetDao = daoSession.getEventDao(); Event eventNew = targetDao.load(__key); synchronized (this) { event = eventNew; event__resolvedKey = __key; } } return event; }
@Test @Transactional public void testNotificationSave() { OnmsEvent event = new OnmsEvent(); event.setDistPoller(m_distPollerDao.load("localhost")); event.setEventCreateTime(new Date()); event.setEventDescr("event dao test"); event.setEventHost("localhost"); event.setEventLog("Y"); event.setEventDisplay("Y"); event.setEventLogGroup("event dao test log group"); event.setEventLogMsg("event dao test log msg"); event.setEventSeverity(7); event.setEventSource("EventDaoTest"); event.setEventTime(new Date()); event.setEventUei("uei://org/opennms/test/NotificationDaoTest"); // OnmsAlarm alarm = new OnmsAlarm(); // event.setAlarm(alarm); OnmsNode node = m_nodeDao.findAll().iterator().next(); OnmsIpInterface iface = node.getIpInterfaces().iterator().next(); OnmsMonitoredService service = iface.getMonitoredServices().iterator().next(); event.setNode(node); event.setServiceType(service.getServiceType()); event.setIpAddr(iface.getIpAddress()); m_eventDao.save(event); OnmsEvent newEvent = m_eventDao.load(event.getId()); assertEquals("uei://org/opennms/test/NotificationDaoTest", newEvent.getEventUei()); OnmsNotification notification = new OnmsNotification(); notification.setEvent(newEvent); notification.setTextMsg("Tests are fun!"); m_notificationDao.save(notification); OnmsNotification newNotification = m_notificationDao.load(notification.getNotifyId()); assertEquals( "uei://org/opennms/test/NotificationDaoTest", newNotification.getEvent().getEventUei()); }
@Before public void setUp() { calendarUsers = new CalendarUser[numInitialNumUsers]; events = new Event[numInitialNumEvents]; eventAttendees = new EventAttendee[numInitialNumEventAttendees]; this.calendarUserDao.deleteAll(); this.eventDao.deleteAll(); this.eventAttendeeDao.deleteAll(); for (int i = 0; i < numInitialNumUsers; i++) { calendarUsers[i] = new CalendarUser(); calendarUsers[i].setEmail("user" + i + "@example.com"); calendarUsers[i].setPassword("user" + i); calendarUsers[i].setName("User" + i); calendarUsers[i].setId(calendarUserDao.createUser(calendarUsers[i])); } for (int i = 0; i < numInitialNumEvents; i++) { events[i] = new Event(); events[i].setSummary("Event Summary - " + i); events[i].setDescription("Event Description - " + i); events[i].setOwner(calendarUsers[random.nextInt(numInitialNumUsers)]); switch (i) { // Updated by Assignment 3 case 0: events[i].setNumLikes(0); break; case 1: events[i].setNumLikes(9); break; case 2: events[i].setNumLikes(10); break; case 3: events[i].setNumLikes(10); break; } // NumLikes에 따른 EventLevel 반영 events[i].setId(eventDao.createEvent(events[i])); } for (int i = 0; i < numInitialNumEventAttendees; i++) { eventAttendees[i] = new EventAttendee(); eventAttendees[i].setEvent(events[i % numInitialNumEvents]); eventAttendees[i].setAttendee(calendarUsers[i]); eventAttendees[i].setId(eventAttendeeDao.createEventAttendee(eventAttendees[i])); } }
@Test public void test() throws Exception { SqlSession session = SessionFactory.getSession(); EventDao eventDao = session.getMapper(EventDao.class); try { Event event = TestEventDao.createEvent(); String where = "KEY='" + event.getKey() + "' "; Map<String, Object> map = new HashMap<String, Object>(); map.put("where", where); int count = eventDao.create(event); assertEquals(1, count); assertNotNull(event.getKey()); Event readRecord = eventDao.read(map); assertNotNull(readRecord.getKey()); compareRecords(event, readRecord); modifyRecord(event); count = eventDao.update(event); assertEquals(1, count); readRecord = eventDao.read(map); assertNotNull(readRecord.getKey()); compareRecords(event, readRecord); count = eventDao.delete(map); assertEquals(1, count); readRecord = eventDao.read(map); assertNull(readRecord); } finally { if (session != null) { session.rollback(); session.close(); } } }