summaryrefslogtreecommitdiff
path: root/orktrack/src/net/sf/oreka/orktrack/test/ProgramTest.java
blob: 819539831940c0f12eb02fb176eaee9db2427eae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Oreka -- A media capture and retrieval platform
 * 
 * Copyright (C) 2005, orecx LLC
 *
 * http://www.orecx.com
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License.
 * Please refer to http://www.gnu.org/copyleft/gpl.html
 *
 */

package net.sf.oreka.orktrack.test;

import java.util.Iterator;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import net.sf.oreka.Direction;
import net.sf.oreka.HibernateManager;
import net.sf.oreka.orktrack.OrkTrack;
import net.sf.oreka.orktrack.ProgramManager;
import net.sf.oreka.persistent.LoginString;
import net.sf.oreka.persistent.RecProgram;
import net.sf.oreka.persistent.RecSegment;
import net.sf.oreka.persistent.User;

import org.hibernate.Session;
import org.hibernate.Transaction;

public class ProgramTest extends TestCase {
	
	public static void main (String[] args) {
		junit.textui.TestRunner.run (suite());
	}
	protected void setUp() throws Exception {
		OrkTrack.initialize("C:/oreka/log4j.properties", "C:/oreka/mysql.hbm.xml", "C:/oreka/orktrack.config.xml");
	}
	public static Test suite() {
		return new TestSuite(ProgramTest.class);
	}
	
	public void test1() throws Exception {
		

		Session hbnSession = HibernateManager.getSession();
		Transaction tx = hbnSession.beginTransaction();
	
		// create a user
		User user = new User();
		user.setFirstname("mawagade");
		hbnSession.save(user);
		LoginString ls = new LoginString();
		ls.setLoginString("1234");
		ls.setUser(user);
		hbnSession.save(ls);
		
		// create a program
		RecProgram prog1 = new RecProgram();
		prog1.setDirection(Direction.IN);
		prog1.setTargetUser(user);
		hbnSession.save(prog1);
		
		tx.commit();
		hbnSession.close();
		
		ProgramManager.instance().load();
		
		RecSegment seg = new RecSegment();
		seg.setDirection(Direction.IN);
		seg.setUser(user);
		
		hbnSession = HibernateManager.getSession();
		tx = hbnSession.beginTransaction();
		if (ProgramManager.instance().filterSegmentAgainstAllPrograms(seg, hbnSession)) {
			hbnSession.save(seg);
		}
		tx.commit();
		hbnSession.close();
		
		// verify result
		hbnSession = HibernateManager.getSession();
		tx = hbnSession.beginTransaction();
		RecProgram prog = (RecProgram)hbnSession.load(RecProgram.class, prog1.getId());
		assertTrue(prog.getRecordedSoFar() == 1);
		Iterator<RecSegment> it = prog.getRecSegments().iterator();
		assertTrue(it.next().getId() == seg.getId());
		tx.commit();
		hbnSession.close();
	}
	
//	public void testManyToMany() throws Exception {
//		
//		Session hbnSession = HibernateManager.getSession();
//		Transaction tx = hbnSession.beginTransaction();
//		
//		// Create two programs
//		RecProgram prog1 = new RecProgram();
//		hbnSession.save(prog1);
//		RecProgram prog2 = new RecProgram();
//		hbnSession.save(prog2);
//		
//		// create 1000 segments
//		for(int i=0; i<1000; i++) {
//			RecSegment seg = new RecSegment();
//			seg.getRecPrograms().add(prog1);
//			seg.getRecPrograms().add(prog2);
//			hbnSession.save(seg);
//		}
//		
//		tx.commit();
//		hbnSession.close();
//		
//		hbnSession = HibernateManager.getSession();
//		tx = hbnSession.beginTransaction();
//		
//		// create a new segment and add it to the program
//		RecProgram prog = (RecProgram)hbnSession.load(RecProgram.class, prog2.getId());
//		RecSegment seg = new RecSegment();
//		seg.getRecPrograms().add(prog);
//		hbnSession.save(seg);
//		
//		tx.commit();
//		hbnSession.close();
//	}
}