Chuan Chuan Law

DevOps | Software Automation | Continuous Integration

Tag: Curl

How To Publish Artifacts To Artifactory Using Curl

We can publish an artifact onto Artifactory using unconventional way such as Curl.

This is how we can do that:

  • Generate a pom file using a bash script, so the artifact will have versioning, etc.
#!/usr/bin/env bash
cat  << EOF
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>1.0.0</modelVersion>
  <groupId>com.org.test</groupId>
  <artifactId>apple</artifactId>
  <version>apple</version>
  <packaging>tar</packaging>
</project>
EOF
  • Post onto Artifactory using Curl

curl -i -X PUT -u username:password –data-binary @”apple.tar” “https://artifactory/snapshot/com/org/test/apple/apple.tar”

Code For Web Services Regression Tests

This is to replace my July post with the link to the source code in GitHub which I have remove for security reasons.

However, below is how the code looks like:

#!/usr/bin/ruby

class WebServices
def main_method
f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @adauthenticate.xml -s -v -D – http://webservices.pageup.com.au/nas/ADAuthenticate/ADAuthenticate.asmx 2>/dev/null>result.xml”).readlines
evalresult(“authenticate”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @bulkData.xml -s -v -D – http://webservices.pageup.com.au/nas/BulkData/BulkData.asmx?op=GetAvailableImportItemTypes 2>/dev/null>result.xml”).readlines
evalresult(“bulkData”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @htmlToPdf.xml -s -v -D – http://webservices.pageup.com.au/nas/HTMLToPDF/HTMLToPDF.asmx?op=GetToken 2>/dev/null>result.xml”).readlines
evalresult(“HTMLToPDF”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @htmlToRtf.xml -s -v -D – http://webservices.pageup.com.au/nas/HTMLToRTF/HTMLToRTF.ASMX?op=URLToRTF 2>/dev/null>result.xml”).readlines
evalresult(“HTMLToRTF”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @jobSource.xml -s -v -D – http://webservices.pageup.com.au/nas/JobSourceWS/JobSourceWS.asmx?op=GetToken 2>/dev/null>result.xml”).readlines
evalresult(“jobSource”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @jobSource2.xml -s -v -D – http://webservices.pageup.com.au/nas/JobSourceWS/JobSourceWS.asmx?op=UpdateJobSource  2>/dev/null>result.xml”).readlines
evalresult(“updateJobSource”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @mediaOrder.xml -s -v -D – http://webservices.pageup.com.au/nas/MEDIAORDERWS/MediaOrderWS.asmx?op=GetToken 2>/dev/null>result.xml”).readlines
evalresult(“MediaOrder”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @pageUpPeople.xml -s -v -D – http://webservices.pageup.com.au/nas/PageUpPeopleWS//PageUpPeople.asmx?op=GetApplicant 2>/dev/null>result.xml”).readlines
evalresult(“PageUpPeople”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @pdfReportGenerator.xml -s -v -D – http://webservices.pageup.com.au/nas/PDFReportGenerator/PDFReportGenerator.asmx?op=Generate360ReportWS 2>/dev/null>result.xml”).readlines
evalresult(“PDFReportGenerator”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @pdfToHtml.xml -s -v -D – http://webservices.pageup.com.au/nas/PDFtoHTML/PDFtoHTML.asmx?op=PDFToHTML 2>/dev/null>result.xml”).readlines
evalresult(“PDFToHTML”)

f=IO.popen(“curl http://webservices.pageuppeople.com/nas/JobsRest/JobListing.svc/218/caw/en  2>/dev/null>result.xml”).readlines
evalresult(“JobRest”)

end

def evalresult(webserviceType)
f=File.new(“/Users/chuan/webservicesTest/result.xml”)
text = f.read

if (webserviceType==”authenticate”) then
print “Authenticate: ”
if (text =~/HTTP/1.1 200 OK/ && text =~/Success/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”bulkData”) then
print “Bulk Data: ”
if (text =~/HTTP/1.1 200 OK/ && text =~/OrgUnit/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”HTMLToPDF”) then
print “HTML To PDF: ”
if (text =~/HTTP/1.1 200 OK/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”jobSource”) then
print “Job Source: ”
if (text =~/HTTP/1.1 200 OK/) then
print  “Successn”
token=text.scan(/(.*)</GetTokenResult>/)
token_string=token.to_s
token_string.gsub!(/[^a-zA-Z0-9-]/,””)
File.open(‘jobSource2.xml’, ‘w’) do |f1|
f1.puts ”
f1.puts ‘  ‘
f1.puts ‘    ‘
f1.puts ”      #{token_string}”
f1.puts ‘     test’
f1.puts ‘
‘                    f1.puts   ‘
‘                    f1.puts ‘
‘                     end
else
print  “Failn”
end
end

if (webserviceType==”updateJobSource”) then
print “Job Source – Update Job Source: ”
if (text =~/HTTP/1.1 200 OK/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”MediaOrder”) then
print “Media Order: ”
if (text =~/HTTP/1.1 200 OK/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”PageUpPeople”) then
print “PageUpPeople: ”
if (text =~/HTTP/1.1 200 OK/ && text =~/tester145127@pup.com/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”PDFReportGenerator”) then
print “PDFReportGenerator: ”
if (text =~/HTTP/1.1 200 OK/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”PDFToHTML”) then
print “PDFToHTML: ”
if (text =~/HTTP/1.1 200 OK/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”JobRest”) then
print “JobRest: ”
if (text =~/Account management/) then
print  “Successn”
else
print  “Failn”
end
end

end

end

WebServices.new.main_method

Regression Testing Web Services

The mechanism I use to regression test web services is the same as the mechanism I test API, which is by using:

  • Curl
  • Ruby
Curl is main tool to call the web services and it sits inside the Ruby script which is used to do other functions such as checking the output, etc.
For example, the Curl command below will pass the XML file to the JobSource web service and pipe the output to another XML file:

 f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @jobSource2.xml -s -v -D – http://webservices.pageup.com.au/JobSourceWS/JobSourceWS.asmx?op=UpdateJobSource  2>/dev/null>result.xml”).readlines

© 2019 Chuan Chuan Law

Theme by Anders NorenUp ↑