Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4477 dpurdie 1
<%@LANGUAGE="VBSCRIPT"%>
2
<%
3
'=====================================================
4
'       Release Manager Admin Tests
5
'       Designed to be called via AJAX and to return
6
'       JSON formatted data to dynamic page
7
'=====================================================
8
%>
9
<%
10
Option explicit
11
' Good idea to set when using redirect
12
Response.Expires = 0   ' always load the page, dont store
5168 dpurdie 13
Response.ContentType="application/json"
4477 dpurdie 14
%>
15
<!--#include file="common/conf.asp"-->
16
<!--#include file="common/globals.asp"-->
17
<!--#include file="common/qstr.asp"-->
18
<!--#include file="common/common_subs.asp"-->
19
<!--#include file="common/formating.asp"-->
5097 dpurdie 20
<!--#include file="common/release_changed.asp"-->
4477 dpurdie 21
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="common/base64encode.vbs"></SCRIPT> 
22
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT> 
23
<%
24
'------------ Variable Definition -------------
25
Dim parOpr, newitem
26
Dim result
27
 
28
' Basic Parameters
29
parOpr = QStrPar("Opr")
30
result = -1
31
 
32
' Init the output JSON class
33
'   Operations can add data
34
'   Default data will be added at the end
35
Dim oJSON
36
Set oJSON = New aspJSON
37
 
38
'
39
'   Determine the operation to be performed
4482 dpurdie 40
'   Invoke target routine
41
'   Expect:
42
'       result                    - test result
43
'       oJSON.data("emsgSummary") - Error detail
4477 dpurdie 44
'
4482 dpurdie 45
'
4477 dpurdie 46
If (parOpr = "zipTest") Then
4482 dpurdie 47
    Call zipFile
48
ElseIf (parOpr = "eventTest") Then
49
    Call sendEvent
5168 dpurdie 50
ElseIf (parOpr = "eventTestWsh") Then
51
    Call sendEventWsh
4482 dpurdie 52
ElseIf (parOpr = "emailTest") Then
53
    Call sendEmail
54
ElseIf (parOpr = "emailWshTest") Then
55
    Call sendWshEmail
56
ElseIf (parOpr = "remExecTest") Then
57
    Call remExec
58
ElseIf (parOpr = "pkgAccessTest") Then
59
    Call pkgAccess
5168 dpurdie 60
ElseIf (parOpr = "reportEvent") Then
61
    Call reportEvent
5097 dpurdie 62
ElseIf (parOpr = "ddpTest") Then
63
    Call ddpTest
64
 
4482 dpurdie 65
Else
66
    oJSON.data("emsgSummary") = "Unknown operation requested:" & parOpr
67
End If
4477 dpurdie 68
 
4482 dpurdie 69
'
70
'   Create JSON data for the user
71
'   Important fields
72
'       result
73
'
74
'   Debug fields
75
'       Request (Array)
76
'
77
'Write single value
78
oJSON.data("result") = result
79
 
80
' DEBUG: An array of the user provided requests
81
Set oJSON.data("Request") = oJSON.Collection()
82
Set newitem = oJSON.AddToCollection(oJSON.data("Request"))
83
Dim variableName
84
for each variableName in Request.QueryString
85
    newitem.add variableName, Request.QueryString(variableName)
86
next
87
 
88
'Return the object
89
Response.Write oJSON.JSONoutput()
90
 
91
'-------------------------------------------------
5097 dpurdie 92
' Function:    ddpTest
93
' Description:
94
 
5168 dpurdie 95
Sub ddpTest
5097 dpurdie 96
 
5168 dpurdie 97
    Dim objRC: Set objRC = New ReleaseChanged
98
    Dim rv
5097 dpurdie 99
 
5168 dpurdie 100
    Call objRC.Run_ReleaseChanged(6884,693010,enumRELEASE_CHANGE_MODE_PKG_RELEASED,true)
101
    rv = objRc.last_resultCode
102
    If rv = 0 Then
103
        result = 0
104
    Else
105
        result = 1
106
        oJSON.data("emsgSummary") = "Error:("&rv&"), " & objRc.last_errorMsg
107
    End If
108
    Set objRC = Nothing
5097 dpurdie 109
End Sub
110
 
111
'-------------------------------------------------
4482 dpurdie 112
' Function:    zipFile
113
' Description: Test the File Zipping process
114
Sub zipFile
4477 dpurdie 115
    '
116
    ' Create a test file in a known directory
117
    '
118
    Dim objZIPObject, ZipFile
119
    Dim outFile, objFSO, LocalDir, objFile
120
    Set objFSO=CreateObject("Scripting.FileSystemObject")
121
    LocalDir = Request.ServerVariables("APPL_PHYSICAL_PATH") & "release_manager\temp\"
122
 
123
    If NOT objFSO.FolderExists( LocalDir ) Then
124
        result = 1
125
        oJSON.data("emsgSummary") = "Folder not found:" & LocalDir
126
    Else
127
        ' Create a known file to zip up
128
        '
129
        outFile = LocalDir & "zipTestFile.txt"
130
        Set objFile = objFSO.CreateTextFile(outFile,True)
131
        objFile.Write "test string" & vbCrLf
132
        objFile.Close
133
 
134
        ' Zip up a test file
135
        '
136
        ZipFile = LocalDir & "zipTest.zip"
137
        If objFSO.FileExists(ZipFile) Then
138
       	    objFSO.DeleteFile ZipFile, TRUE
139
        End If
140
 
141
        On Error Resume Next
142
    	Set objZIPObject = Server.CreateObject("XStandard.Zip")
143
        If Err.Number <> 0 then
144
            result = 1
145
            oJSON.data("emsgSummary") = "Create XStandard.Zip:" & Err.Description
146
        Else
147
            objZIPObject.Pack outFile, ZipFile
148
 
149
            If objZIPObject.ErrorCode <> 0 then
150
                    result = 1
151
                    oJSON.data("emsgSummary") = "Zip Error XStandard:" & objZIPObject.ErrorCode & ":" & objZIPObject.ErrorDescription
152
            Else
153
                ' All done - must have passed
154
                result = 0
155
 
156
            End If
157
        End If
158
 
159
        '
160
        ' Clean up
161
        If objFSO.FileExists(outFile) Then
162
       	    objFSO.DeleteFile outFile, TRUE
163
        End If
164
 
165
        If objFSO.FileExists(ZipFile) Then
166
       	    objFSO.DeleteFile ZipFile, TRUE
167
        End If
168
 
169
        objZIPObject = Nothing
170
 
171
    End If
172
    set objFSO = Nothing
4482 dpurdie 173
End Sub
4477 dpurdie 174
 
4482 dpurdie 175
'-------------------------------------------------
5168 dpurdie 176
' Function:    reportEvent
177
' Description:  Create an event in the machines event log
178
 
179
Sub reportEvent
180
    Report_Event enumEVENT_ERROR, "Admin Test", "", "Release Manager test: reportEvent" 
181
    If Err.number = 0 Then
182
        result = 0
183
    Else
184
        result = 1
185
        oJSON.data("emsgSummary") = "Error:("&Err.number&"):" & Err.description
186
    End If
187
End Sub
188
 
189
'-------------------------------------------------
4482 dpurdie 190
' Function:    sendEvent
191
' Description: Send an Event to the Windows Log
192
Sub sendEvent
5168 dpurdie 193
    Send_Event enumEVENT_ERROR, "Release Manager Test Log" 
194
    If Err.number = 0 Then
195
        result = 0
196
    Else
197
        result = 1
198
        oJSON.data("emsgSummary") = "Error:("&Err.number&"):" & err.description
199
    End If
200
End Sub
201
 
202
'-------------------------------------------------
203
' Function:    sendEventWsh
204
' Description: Send an Event to the Windows Log using Wsh
205
Sub sendEventWsh
4482 dpurdie 206
   Dim objWSH, rv
207
    Set objWSH = Server.CreateObject("WScript.Shell")
208
    rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onRaiseEvent", 0, TRUE)
209
    Set objWSH = Nothing
210
    If rv = 0 Then
211
        result = 0
212
    Else
213
        result = 1
214
        oJSON.data("emsgSummary") = "Error:("&rv&")"
215
    End If
216
End Sub
4477 dpurdie 217
 
4482 dpurdie 218
'-------------------------------------------------
219
' Function:     sendEmail
220
' Description:  Send an email
221
Sub sendEmail
222
   Dim Mode, Attachment, Message
223
 
224
   Attachment = Null
225
   Message = "This is a Test Email generated by the Release Manager Test."
226
   Mode = QStrPar("Mode")
227
 
228
   If Mode = "Attach" Then
229
        Attachment = Server.MapPath("images\img_reports_admin.jpg")
230
        Message = Message & " This message should have an attachment"
231
   End If
232
 
233
    Call Send_Email ( "Release Manager Notification", _
234
                       adminEmail, _
235
                       objAccessControl.UserEmail, _
236
                       "Test Email", _
237
                       Message, _
238
                       Attachment )
239
    result = Err.Number
240
    oJSON.data("emsgSummary") = Err.Description
241
    'oJSON.data("Info1") = Mode
242
    'oJSON.data("Info2") = Attachment
243
End Sub
244
 
245
'-------------------------------------------------
246
' Function:     sendWshEmail
247
' Description:  Send an email from a Wsh Script
248
Sub sendWshEmail
249
    Dim objWSH, rv
250
 
251
    Set objWSH = Server.CreateObject("WScript.Shell")
252
    rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestMail", 0, TRUE)
253
    Set objWSH = Nothing
254
    If rv = 0 Then
255
        result = 0
256
    Else
257
        result = 1
258
        oJSON.data("emsgSummary") = "Error:("&rv&")"
259
    End If
260
End Sub
261
 
262
'-------------------------------------------------
263
' Function:    remExec
264
' Description:  Test Release Manager Remote cmd Execution
265
Sub remExec
266
    Dim objWSH, rv
267
 
268
    Set objWSH = Server.CreateObject("WScript.Shell")
269
    rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestArchiveAccess", 0, TRUE)
270
    Set objWSH = Nothing
271
    If rv = 0 Then
272
        result = 0
273
    Else
274
        result = 1
275
        oJSON.data("emsgSummary") = "Error:("&rv&")"
276
    End If
277
End Sub
278
 
279
'-------------------------------------------------
280
' Function:    pkgAccess
281
' Description: Test dpkg_archive access - can we map it
4477 dpurdie 282
'
4482 dpurdie 283
Sub pkgAccess
284
    Dim objWSH, rv
4477 dpurdie 285
 
4482 dpurdie 286
    Set objWSH = Server.CreateObject("WScript.Shell")
287
    rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestMapArchive", 0, TRUE)
288
    Set objWSH = Nothing
289
    If rv = 0 Then
290
        result = 0
291
    Else
292
        result = 1
293
        oJSON.data("emsgSummary") = "Error:("&rv&")"
294
    End If
295
End Sub
4477 dpurdie 296
 
297
%>