restassured_cli 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 802f2ba025cd683d386eb915a4441d585e20375b
4
- data.tar.gz: 55e93899fa4eaa01fe6f3378458655b5b5ab2fc6
3
+ metadata.gz: 9629ffd5cd2b3d78105298fbbf2c49d8e8602e44
4
+ data.tar.gz: 2095416238f22421999af9a2002d2b436c1f198f
5
5
  SHA512:
6
- metadata.gz: 30dc207df48d412bd7046e15ac7b4de01c224c227a9f6b6c61f0fa91943fe7557f66135e0a68313f03ff433afb942699ea32f0ae656ea69987736785366c42e1
7
- data.tar.gz: 52f698dc147b55aa2bcc2bf7eb7e4916e29b08212c3d6377c043e18b56faab7fbdb63c4f097cda171b236d3713ddf23f2333f2526b599e0c85d4dc838a3907cf
6
+ metadata.gz: 19a5e2efe5570c11218b7547875ca50771c9b4620a229abfc526975d85b3f725800dcb6f5bd22fab1d271c84e57eb8fabc984d1d51213cbca32f4125577e5898
7
+ data.tar.gz: befe08bc13cc45d282aa694284363695d3017561ddc9189deb2eab90ad03594875887aefe2ac353f4fe21a390c64d6263505ed742830d54a8548476f2cfd7fc0
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
- # restassured_cli release notes
1
+ # restassured_cli
2
+ ![Gem Version](https://badge.fury.io/rb/restassured_cli.png)
2
3
 
3
4
  ## About
4
5
 
5
- Command line utility (CLI) to generate test projects and sample tests using [RestAssured BDD framework](https://github.com/jayway/rest-assured), a Java DSL for easy testing of REST services.
6
+ Command line utility (CLI) to generate test projects and sample tests using [RESTAssured BDD framework](https://github.com/jayway/rest-assured), a Java DSL for easy testing of REST services. Also, released as a ruby gem at [rubygems.org](https://rubygems.org/gems/restassured_cli)
6
7
 
7
8
  ## Release notes
8
9
 
@@ -53,9 +54,6 @@ smallbusiness
53
54
  └── testing
54
55
  |── smallbusiness-perf-tests
55
56
  | └── jmeter/regression/
56
- | |── src/main/java/com/intuit/samples/smallbusiness/tests/perf/
57
- | └── src/main/resources/
58
- | └── testng-perf.xml
59
57
  |── smallbusiness-production-tests
60
58
  | |── src/main/java/com/intuit/samples/smallbusiness/tests/production/
61
59
  | └── src/main/resources/
@@ -126,7 +124,9 @@ c:\Ruby22-x64\bin\ruby.exe restassured_cli -p 1.0.0 -j 1.7 -f com.intuit.samples
126
124
 
127
125
  ## Contributing
128
126
 
129
- Bug reports and pull requests are welcome on GitHub at https://github.com/eing/restassured_cli.
127
+ For pull requests, your contributions are absolutely welcome.
128
+
129
+ For bug reports, please use https://github.com/eing/restassured_cli/issues
130
130
 
131
131
  ## Contributors (thank you!)
132
132
 
@@ -6,6 +6,9 @@ import GROUPID.tests.library.schema.Phone;
6
6
 
7
7
  import com.fasterxml.jackson.databind.node.JsonNodeFactory;
8
8
  import com.fasterxml.jackson.databind.node.ObjectNode;
9
+ import com.jayway.restassured.config.RestAssuredConfig;
10
+ import com.jayway.restassured.config.XmlConfig;
11
+ import com.jayway.restassured.path.xml.XmlPath;
9
12
  import com.jayway.restassured.filter.session.SessionFilter;
10
13
  import com.jayway.restassured.http.ContentType;
11
14
  import com.jayway.restassured.response.Response;
@@ -20,20 +23,25 @@ import javax.xml.soap.SOAPBody;
20
23
  import javax.xml.soap.SOAPBodyElement;
21
24
  import javax.xml.soap.SOAPElement;
22
25
  import javax.xml.soap.SOAPEnvelope;
26
+ import javax.xml.soap.SOAPException;
23
27
  import javax.xml.soap.SOAPMessage;
24
28
  import javax.xml.soap.SOAPPart;
25
29
  import java.io.ByteArrayOutputStream;
30
+ import java.io.IOException;
26
31
  import java.util.ArrayList;
27
32
  import java.util.HashMap;
33
+ import java.util.Map;
28
34
  import java.util.List;
29
35
 
30
36
  import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
31
37
  import static com.github.tomakehurst.wiremock.client.WireMock.any;
32
38
  import static com.github.tomakehurst.wiremock.client.WireMock.get;
39
+ import static com.github.tomakehurst.wiremock.client.WireMock.post;
33
40
  import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
34
41
  import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
35
42
  import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
36
43
  import static com.jayway.restassured.RestAssured.given;
44
+ import static com.jayway.restassured.path.json.JsonPath.from;
37
45
  import static org.hamcrest.CoreMatchers.hasItems;
38
46
  import static org.hamcrest.CoreMatchers.is;
39
47
  import static org.hamcrest.MatcherAssert.assertThat;
@@ -54,7 +62,7 @@ public class SampleComponentTest extends SampleTestBase {
54
62
  * Add stubs to WireMock server for this set of tests.
55
63
  */
56
64
  @BeforeClass
57
- public void setup() {
65
+ public void setup() throws SOAPException, IOException {
58
66
  /**
59
67
  * Create a JSON response using JsonNodeFactory instead of hardcoding in string which is error prone.
60
68
  * {
@@ -105,6 +113,34 @@ public class SampleComponentTest extends SampleTestBase {
105
113
  withHeader("Content-Type", ContentType.ANY.toString()).
106
114
  withHeader("JSESSIONID", "AS34979870H").
107
115
  withStatus(200))));
116
+
117
+ // Stub response for SOAP
118
+ MessageFactory messageFactory = MessageFactory.newInstance();
119
+ SOAPMessage soapMessage = messageFactory.createMessage();
120
+ SOAPPart soapPart = soapMessage.getSOAPPart();
121
+ SOAPEnvelope envelope = soapPart.getEnvelope();
122
+ SOAPBody soapBody = envelope.getBody();
123
+ // Add namespace declarations
124
+ soapBody.addNamespaceDeclaration("ns2", "http://namespace2.com");
125
+
126
+ SOAPElement vendorElement = soapBody.addChildElement("Vendor", "ns2");
127
+ vendorElement.addChildElement("id", "ns2").addTextNode("1290");
128
+ vendorElement.addChildElement("name", "ns2").addTextNode("John Smith");
129
+ vendorElement.addChildElement("phone", "ns2").addTextNode("650-222-3333");
130
+
131
+ soapMessage.saveChanges();
132
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
133
+ soapMessage.writeTo(out);
134
+ String soapMessageInText = new String(out.toByteArray());
135
+
136
+ wireMockServer.
137
+ givenThat(
138
+ (post(urlEqualTo("/v1/vendors")).
139
+ willReturn(aResponse().
140
+ withHeader("Content-Type", ContentType.XML.toString()).
141
+ withBody(soapMessageInText).
142
+ withStatus(200))));
143
+
108
144
  // Stub response for all other requests (setting to lowest priority)
109
145
  wireMockServer.
110
146
  givenThat(
@@ -193,6 +229,34 @@ public class SampleComponentTest extends SampleTestBase {
193
229
  logger.debug(customer.toString());
194
230
  }
195
231
 
232
+ /**
233
+ * Example of getting a list from response body.
234
+ */
235
+ @Test
236
+ public void testGetListOfAllPhones() {
237
+ //@formatter:off
238
+ Response resp = given().spec(requestSpec).get("/customers/4");
239
+ List<HashMap> phones = from(resp.asString()).getList("customer.phone", HashMap.class);
240
+ // Phones which you should be asserting on
241
+ for (HashMap<String, String> map : phones) {
242
+ logger.debug(map.toString());
243
+ }
244
+ }
245
+
246
+ /**
247
+ * Example of getting a list from response body using groovy closure.
248
+ */
249
+ @Test
250
+ public void testGetOnlyWorkPhones() {
251
+ //@formatter:off
252
+ Response resp = given().spec(requestSpec).get("/customers/4");
253
+ List<Map> phones = from(resp.asString()).get("customer.phone.findAll { phone-> phone.type == \"work\" }");
254
+ // Phones which you should be asserting on
255
+ for (Map map : phones) {
256
+ logger.debug(map.toString());
257
+ }
258
+ }
259
+
196
260
  /**
197
261
  * Example of asserting an array item.
198
262
  */
@@ -274,10 +338,10 @@ public class SampleComponentTest extends SampleTestBase {
274
338
  Construct SOAP Request Message instead of hardcoding as a string which is error prone:
275
339
  <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
276
340
  <SOAP-ENV:Header/>
277
- <SOAP-ENV:Body>
278
- <GetVendor>
279
- <id>1290</id>
280
- </GetVendor>
341
+ <SOAP-ENV:Body xmlns:ns2="http://namespace2.com">
342
+ <n2:GetVendor>
343
+ <n2:id>1290</n2:id>
344
+ </n2:GetVendor>
281
345
  </SOAP-ENV:Body>
282
346
  </SOAP-ENV:Envelope>
283
347
  */
@@ -287,17 +351,36 @@ public class SampleComponentTest extends SampleTestBase {
287
351
  SOAPEnvelope envelope = soapPart.getEnvelope();
288
352
  SOAPBody soapBody = envelope.getBody();
289
353
 
290
- Name bodyName = envelope.createName("GetVendor");
291
- SOAPBodyElement vendorElement = soapBody.addBodyElement(bodyName);
292
- SOAPElement firstnameElement = vendorElement.addChildElement(envelope.createName("id"));
293
- firstnameElement.addTextNode("1290");
354
+ // Add namespace declarations
355
+ soapBody.addNamespaceDeclaration("ns2", "http://namespace2.com");
356
+
357
+ SOAPElement vendorElement = soapBody.addChildElement("Vendor", "ns2");
358
+ vendorElement.addChildElement("id", "ns2").addTextNode("1290");
294
359
  soapMessage.saveChanges();
295
360
 
296
361
  ByteArrayOutputStream out = new ByteArrayOutputStream();
297
362
  soapMessage.writeTo(out);
298
363
  String soapMessageInText = new String(out.toByteArray());
364
+
365
+ /* Response stub returned from WireMock
366
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
367
+ <SOAP-ENV:Header/>
368
+ <SOAP-ENV:Body xmlns:ns2="http://namespace2.com">
369
+ <ns2:Vendor>
370
+ <ns2:id>1290</ns2:id>
371
+ <ns2:name>John Smith</ns2:name>
372
+ <ns2:phone>650-222-3333</ns2:phone>
373
+ </ns2:Vendor>
374
+ </SOAP-ENV:Body>
375
+ </SOAP-ENV:Envelope>
376
+ */
377
+
299
378
  //@formatter:off
300
- given().
379
+ response = given().
380
+ config(RestAssuredConfig.newConfig().
381
+ xmlConfig(XmlConfig.xmlConfig().
382
+ namespaceAware(true).
383
+ declareNamespace("ns2", "http://namespace2.com"))).
301
384
  spec(requestSpec).
302
385
  header("SOAPAction", "http://localhost/getVendor").
303
386
  contentType("application/soap+xml; charset=UTF-8;").
@@ -305,8 +388,19 @@ public class SampleComponentTest extends SampleTestBase {
305
388
  when().
306
389
  post("/v1/vendors").
307
390
  then().assertThat().
308
- statusCode(200);
391
+ contentType(ContentType.XML).
392
+ statusCode(200).
393
+ extract().response();
309
394
  //@formatter:off
395
+
396
+ // One way to assert
397
+ String responseString = response.asString();
398
+ String vendorName = new XmlPath(responseString).getString("Envelope.Body.Vendor.name");
399
+ assertThat(vendorName, is("John Smith"));
400
+
401
+ // Another way to assert
402
+ vendorName = XmlPath.with(responseString).get("Envelope.Body.Vendor.name");
403
+ assertThat(vendorName, is("John Smith"));
310
404
  }
311
405
 
312
406
  }
@@ -18,16 +18,10 @@ module Display
18
18
  def Display.results
19
19
  puts "Created project for #{$serviceName} service ..."
20
20
  puts "#{$projectName}"
21
- puts " |-- #{$serviceName}-service"
22
- puts " | |-- src/main/java/"
23
- puts " | |-- src/test/java/"
24
21
  puts " |-- testing"
25
22
  puts " |-- #{$serviceName}-perf-tests"
26
23
  puts " | |-- pom.xml"
27
24
  puts " | |-- jmeter/regression/"
28
- puts " | |-- src/main/java/#{$packageName}/tests/perf/"
29
- puts " | |-- src/main/resources/"
30
- puts " | testng-perf.xml"
31
25
  puts " |-- #{$serviceName}-production-tests"
32
26
  puts " | |-- pom.xml"
33
27
  puts " | |-- src/main/java/#{$packageName}/tests/production/"
@@ -39,6 +33,7 @@ module Display
39
33
  puts " | |-- src/main/java/#{$packageName}/tests/service/"
40
34
  puts " | |-- src/main/java/#{$packageName}/tests/serviceintegration/"
41
35
  puts " | |--src/main/resources/"
36
+ puts " | |-- default/"
42
37
  puts " | |-- ci/"
43
38
  puts " | |-- qa/"
44
39
  puts " | |-- e2e/"
@@ -50,6 +45,4 @@ module Display
50
45
  puts " | |--src/main/java/#{$packageName}/tests/library/"
51
46
  puts " |--pom.xml"
52
47
  end
53
-
54
48
  end
55
-
@@ -1,3 +1,3 @@
1
1
  module RestAssuredCLI
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'restassured_cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "restassured_cli"
8
+ spec.version = RestAssuredCLI::VERSION
9
+ spec.authors = ["Eing Ong"]
10
+ spec.email = ["EingOng@gmail.com"]
11
+
12
+ spec.summary = %q{Command Line Utility that generates test projects using RestAssured}
13
+ spec.description = %q{Command line utility (CLI) to generate test projects and sample tests for web services using RESTAssured.}
14
+ spec.homepage = "http://rubygems.org/gems/restassured_cli"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files`.split($/)
26
+ spec.bindir = "bin"
27
+ spec.executables = ['restassured_cli']
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec"
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restassured_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eing Ong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-21 00:00:00.000000000 Z
11
+ date: 2015-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -111,6 +111,7 @@ files:
111
111
  - lib/restassured_cli/source/maven/testing/sampleservice-test-runner/pom.xml
112
112
  - lib/restassured_cli/userinterface.rb
113
113
  - lib/restassured_cli/version.rb
114
+ - restassured_cli.gemspec
114
115
  - spec/restassured_cli_spec.rb
115
116
  - spec/spec_helper.rb
116
117
  homepage: http://rubygems.org/gems/restassured_cli