File: java_simpletest.jsp

package info (click to toggle)
gridengine 8.1.9%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 56,880 kB
  • sloc: ansic: 432,689; java: 87,068; cpp: 31,958; sh: 29,429; jsp: 7,757; perl: 6,336; xml: 5,828; makefile: 4,701; csh: 3,928; ruby: 2,221; tcl: 1,676; lisp: 669; yacc: 519; python: 503; lex: 361; javascript: 200
file content (207 lines) | stat: -rw-r--r-- 8,465 bytes parent folder | download | duplicates (9)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
 *
 *  The Contents of this file are made available subject to the terms of
 *  the Sun Industry Standards Source License Version 1.2
 *
 *  Sun Microsystems Inc., March, 2001
 *
 *
 *  Sun Industry Standards Source License Version 1.2
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.2 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *   Copyright: 2001 by Sun Microsystems, Inc.
 *
 *   All Rights Reserved.
 *
 ************************************************************************/
/*___INFO__MARK_END__*/
/**
 *  Generated from java_simpletest.jsp
 *  !!! DO NOT EDIT THIS FILE !!!
 */
<%
com.sun.grid.cull.JavaHelper jh = (com.sun.grid.cull.JavaHelper)params.get("javaHelper");
com.sun.grid.cull.CullDefinition cullDef = (com.sun.grid.cull.CullDefinition)params.get("cullDef");
com.sun.grid.cull.CullObject cullObj = (com.sun.grid.cull.CullObject)params.get("cullObj");
String classname = jh.getClassName(cullObj);


%>
package com.sun.grid.jgdi.configuration;

import junit.framework.*;
import com.sun.grid.jgdi.configuration.*;
import java.io.File;
import java.util.List;
import java.util.LinkedList;
import com.sun.grid.jgdi.configuration.Util;
import com.sun.grid.jgdi.configuration.xml.XMLUtil;
import com.sun.grid.jgdi.BaseTestCase;
import com.sun.grid.jgdi.JGDI;
import com.sun.grid.jgdi.TestValueFactory;

/**
 *
 */
public class <%=classname%>TestCase extends BaseTestCase {
   
   public  <%=classname%>TestCase(java.lang.String testName) {
      super(testName);
   }
   
   public static Test suite() {
      TestSuite suite = new TestSuite(<%=classname%>TestCase.class);
      return suite;
   }
   
<%
   // --------------------------------------------------------------------------
   // If the add/get/delete operation is available we use the TestValueFactory  
   // to add, get and delete all objects                                        
   // --------------------------------------------------------------------------
   if (cullObj.hasAddOperation() &&                                             
       cullObj.hasGetOperation() &&                                             
       cullObj.hasDeleteOperation()) {                                          
%>  
   
   public void test<%=classname%>AddGetDelete() throws Exception {
   
      Object[] testValues = TestValueFactory.getTestValues(<%=classname%>.class);
      assertTrue("We have no test values for <%=classname%>", (testValues.length > 0));

      JGDI jgdi = createJGDI();
      try {
         List<Util.Difference> differences = new LinkedList<Util.Difference>();
         for (int i = 0; i < testValues.length; i++) {
            <%=classname%> testObj = (<%=classname%>)testValues[i];
            logger.info("adding testObj " + testObj);
            jgdi.add<%=classname%>(testObj);
            try {
              logger.info("fetching and diffing testObj " + testObj);
              <%=classname%> retObj = jgdi.get<%=classname%>(<%
              for (int i = 0; i < cullObj.getPrimaryKeyCount(); i++) {
                 com.sun.grid.cull.CullAttr attr = cullObj.getPrimaryKeyAttr(i);          
                 String attrName = jh.getAttrName(attr);                     
                 String gsname =  Character.toUpperCase( attrName.charAt(0) ) +
                                  attrName.substring(1);                     
                 if(i>0) {                                                   
                  %>,<%                                                      
                 }                                                           
                 %>testObj.get<%=gsname%>()<%                              
              }                                                                 
              %>);
              
              Util.getDifferences(testObj, retObj, differences);
              if (!differences.isEmpty()) {
                 logger.warning("org <%=classname%> is not equal to stored <%=classname%> ------------------------"); 
                 for (Util.Difference diff: differences) {
                    logger.warning(diff.toString());
                 }
              }
              //assertTrue("retobj is not equals to the testobj", differences.isEmpty());
              differences.clear();
              
            } finally {
              jgdi.delete<%=classname%>(testObj);
              
              <%=classname%> retObj = jgdi.get<%=classname%>(<%
              for (int i = 0; i < cullObj.getPrimaryKeyCount(); i++) {                 
                 com.sun.grid.cull.CullAttr attr = cullObj.getPrimaryKeyAttr(i);          
                 String attrName = jh.getAttrName(attr);                     
                 String gsname =  Character.toUpperCase( attrName.charAt(0) ) +
                                  attrName.substring(1);                     
                 if (i>0) {                                                   
                  %>,<%                                                      
                 }                                                           
                  %>testObj.get<%=gsname%>()<%                              
              }                                                                 
              %>);
              
              logger.info("deleting testObj " + testObj);
              assertNull(testObj + " has not been deleted", retObj);
            }
         }
      } finally {
        jgdi.close();
      }
   }
<%
   }
   // If the object has the get list operation we can test
   // the serialization of all objects into a xml object
   if (cullObj.hasGetListOperation()) {
%>
   public void test<%=classname%>ListXML() throws Exception {
      JGDI jgdi = createJGDI();
      try {
         for (<%=classname%> obj : jgdi.get<%=classname%>List()) {
            File file = File.createTempFile("<%=classname%>", ".xml");
            try {
               XMLUtil.write(obj, file);
               <%=classname%> obj1 = (<%=classname%>)XMLUtil.read(file);
               
// begin debug: check differences
//               List<Util.Difference> differences = new LinkedList<Util.Difference>();
//               Util.getDifferences(obj, obj1, differences);
//               if (!differences.isEmpty()) {
//                  logger.warning("org <%=classname%> is not equal to filed/reread obj1 <%=classname%> ------------------------"); 
//                  for (Util.Difference diff : differences) {
//                     logger.warning(diff.toString());
//                  }
//               }
//               differences.clear();
// end debug: check differences
               
               assertTrue("serialized xml object of class <%=classname%> is invalid", 
                          obj.equalsCompletely(obj1) );
            } finally {
              file.delete();
            }
         }
      } finally {
         jgdi.close();
      }
   }
<%
   }

   if (cullObj.hasGetOperation() && cullObj.getPrimaryKeyCount() == 0) {
%>
   public void testGetXML() throws Exception {
   
      JGDI jgdi = createJGDI();
      try {
         <%=classname%> obj = jgdi.get<%=classname%>();
         
         File file = File.createTempFile("<%=classname%>", ".xml");
         try {
            XMLUtil.write(obj, file);
            <%=classname%> obj1 = (<%=classname%>)XMLUtil.read(file);
            assertTrue("serialialized xml object of class <%=classname%> is invalid", 
                       obj.equalsCompletely(obj1) );
         } finally {
           file.delete();
         }
      } finally {
         jgdi.close();
      }
   }

<%
   } 
%>
}