KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > audit > test > AuditUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cmp2.audit.test;
23
24 import junit.framework.Test;
25
26 import org.jboss.test.JBossTestCase;
27 import org.jboss.test.cmp2.audit.interfaces.AuditSession;
28 import org.jboss.test.cmp2.audit.interfaces.AuditSessionHome;
29
30 /**
31  * Tests of audit fields
32  *
33  * @author Adrian.Brock@HappeningTimes.com
34  * @version $Revision: 42494 $
35  */

36 public class AuditUnitTestCase
37    extends JBossTestCase
38 {
39    public static Test suite() throws Exception JavaDoc
40    {
41     return JBossTestCase.getDeploySetup(AuditUnitTestCase.class, "cmp2-audit.jar");
42    }
43
44    public AuditUnitTestCase(String JavaDoc name)
45    {
46     super(name);
47    }
48
49    public void testCreateAudit()
50       throws Exception JavaDoc
51    {
52       AuditSession audit = getAuditSession();
53
54       long beginTime = System.currentTimeMillis();
55       audit.createAudit("createAudit");
56       long endTime = System.currentTimeMillis();
57
58       String JavaDoc failure = audit.fullAuditCheck("createAudit", "audituser1", beginTime, endTime);
59       if (failure != null)
60          fail(failure);
61    }
62
63    public void testUpdateAudit()
64       throws Exception JavaDoc
65    {
66       AuditSession audit = getAuditSession();
67
68       long beginCreateTime = System.currentTimeMillis();
69       audit.createAudit("updateAudit");
70       long endCreateTime = System.currentTimeMillis();
71       long beginUpdateTime = System.currentTimeMillis();
72       audit.updateAudit("updateAudit", "updateAuditString");
73       long endUpdateTime = System.currentTimeMillis();
74
75       String JavaDoc failure = audit.createAuditCheck("updateAudit", "audituser1", beginCreateTime, endCreateTime);
76       if (failure != null)
77          fail(failure);
78       failure = audit.updateAuditCheck("updateAudit", "audituser2", beginUpdateTime, endUpdateTime);
79       if (failure != null)
80          fail(failure);
81    }
82
83    public void testUpdateAuditWithClear()
84       throws Exception JavaDoc
85    {
86       AuditSession audit = getAuditSession();
87
88       long beginCreateTime = System.currentTimeMillis();
89       audit.createAudit("testUpdateAuditWithClear");
90       long endCreateTime = System.currentTimeMillis();
91       long beginUpdateTime = System.currentTimeMillis();
92       audit.updateAudit("testUpdateAuditWithClear", "testUpdateAuditWithClearUpdate");
93       long endUpdateTime = System.currentTimeMillis();
94
95       String JavaDoc failure = audit.createAuditCheck("testUpdateAuditWithClear", "audituser1", beginCreateTime, endCreateTime);
96       if (failure != null)
97          fail(failure);
98       failure = audit.updateAuditCheck("testUpdateAuditWithClear", "audituser2", beginUpdateTime, endUpdateTime);
99       if (failure != null)
100          fail(failure);
101    }
102
103    public void testUpdateAuditChangedNames()
104       throws Exception JavaDoc
105    {
106       AuditSession audit = getAuditSession();
107
108       long beginCreateTime = System.currentTimeMillis();
109       audit.createAuditChangedNames("updateAudit");
110       long endCreateTime = System.currentTimeMillis();
111       long beginUpdateTime = System.currentTimeMillis();
112       audit.updateAuditChangedNames("updateAudit", "updateAuditString");
113       long endUpdateTime = System.currentTimeMillis();
114
115       String JavaDoc failure = audit.createAuditChangedNamesCheck("updateAudit", "audituser1", beginCreateTime, endCreateTime);
116       if (failure != null)
117          fail(failure);
118       failure = audit.updateAuditChangedNamesCheck("updateAudit", "audituser2", beginUpdateTime, endUpdateTime);
119       if (failure != null)
120          fail(failure);
121    }
122
123    public void testUpdateAuditMapped()
124       throws Exception JavaDoc
125    {
126       AuditSession audit = getAuditSession();
127
128       long beginCreateTime = System.currentTimeMillis();
129       audit.createAuditMapped("updateAudit");
130       long endCreateTime = System.currentTimeMillis();
131       long beginUpdateTime = System.currentTimeMillis();
132       audit.updateAuditMapped("updateAudit", "updateAuditString");
133       long endUpdateTime = System.currentTimeMillis();
134
135       String JavaDoc failure = audit.createAuditMappedCheck("updateAudit", "audituser1", beginCreateTime, endCreateTime);
136       if (failure != null)
137          fail(failure);
138       failure = audit.updateAuditMappedCheck("updateAudit", "audituser2", beginUpdateTime, endUpdateTime);
139       if (failure != null)
140          fail(failure);
141    }
142
143    public void testCreateAuditMappedChangedFields()
144       throws Exception JavaDoc
145    {
146       AuditSession audit = getAuditSession();
147
148       long beginCreateTime = System.currentTimeMillis();
149       audit.createAuditMappedChangedFields("createAuditChangedFields", "myUser", 1234);
150       long endCreateTime = System.currentTimeMillis();
151
152       String JavaDoc failure = audit.createAuditMappedCheck("createAuditChangedFields", "myUser", 1234, 1234);
153       if (failure != null)
154          fail(failure);
155       failure = audit.updateAuditMappedCheck("createAuditChangedFields", "audituser1", beginCreateTime, endCreateTime);
156       if (failure != null)
157          fail(failure);
158    }
159
160    public void testUpdateAuditMappedChangedFields()
161       throws Exception JavaDoc
162    {
163       AuditSession audit = getAuditSession();
164
165       long beginCreateTime = System.currentTimeMillis();
166       audit.createAuditMapped("updateAuditChangedFields");
167       long endCreateTime = System.currentTimeMillis();
168       audit.updateAuditMappedChangedFields("updateAuditChangedFields", "updateAuditString", "anotherUser", 4567);
169
170       String JavaDoc failure = audit.createAuditMappedCheck("updateAuditChangedFields", "audituser1", beginCreateTime, endCreateTime);
171       if (failure != null)
172          fail(failure);
173       failure = audit.updateAuditMappedCheck("updateAuditChangedFields", "anotherUser", 4567, 4567);
174       if (failure != null)
175          fail(failure);
176    }
177
178    private AuditSession getAuditSession()
179    {
180       try
181       {
182          return ((AuditSessionHome) getInitialContext().lookup("cmp2/audit/AuditSession")).create();
183       }
184       catch(Exception JavaDoc e)
185       {
186          fail("Exception in getAuditSession: " + e.getMessage());
187          return null;
188       }
189    }
190 }
191
Popular Tags