11package com .baeldung .spring .cloud .bootstrap .gateway ;
22
3+ import com .baeldung .spring .cloud .bootstrap .gateway .client .book .Book ;
4+ import com .baeldung .spring .cloud .bootstrap .gateway .client .rating .Rating ;
35import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
46import io .restassured .RestAssured ;
57import io .restassured .authentication .FormAuthConfig ;
@@ -80,7 +82,9 @@ public void whenAdminAccessDiscoveryResource_thenSuccess() {
8082 @ Test
8183 public void whenAddnewRating_thenSuccess () {
8284
83- final Rating rating = new Rating (1L , 4 );
85+ final Rating rating = new Rating ();
86+ rating .setBookId (1L );
87+ rating .setStars (4 );
8488
8589 // request the protected resource
8690 final Response ratingResponse = RestAssured .given ()
@@ -98,7 +102,9 @@ public void whenAddnewRating_thenSuccess() {
98102
99103 @ Test
100104 public void whenAddnewBook_thenSuccess () {
101- final Book book = new Book ("Baeldung" , "How to spring cloud" );
105+ final Book book = new Book ();
106+ book .setTitle ("How to spring cloud" );
107+ book .setAuthor ("Baeldung" );
102108
103109 // request the protected resource
104110 final Response bookResponse = RestAssured .given ()
@@ -115,83 +121,17 @@ public void whenAddnewBook_thenSuccess() {
115121
116122 }
117123
118- @ JsonIgnoreProperties (ignoreUnknown = true )
119- public static class Book {
120-
121- private Long id ;
122- private String author ;
123- private String title ;
124-
125- public Book () {
126- }
127-
128- public Book (String author , String title ) {
129- this .author = author ;
130- this .title = title ;
131- }
132-
133- public String getAuthor () {
134- return author ;
135- }
136-
137- public void setAuthor (String author ) {
138- this .author = author ;
139- }
140-
141- public String getTitle () {
142- return title ;
143- }
144-
145- public void setTitle (String title ) {
146- this .title = title ;
147- }
148-
149- public Long getId () {
150- return id ;
151- }
152-
153- public void setId (Long id ) {
154- this .id = id ;
155- }
156- }
157-
158- @ JsonIgnoreProperties (ignoreUnknown = true )
159- public static class Rating {
160- private Long id ;
161- private Long bookId ;
162- private int stars ;
163-
164- public Rating () {
165- }
166-
167- public Rating (Long bookId , int stars ) {
168- this .bookId = bookId ;
169- this .stars = stars ;
170- }
171-
172- public Long getId () {
173- return id ;
174- }
175-
176- public void setId (Long id ) {
177- this .id = id ;
178- }
179-
180- public Long getBookId () {
181- return bookId ;
182- }
183-
184- public void setBookId (Long bookId ) {
185- this .bookId = bookId ;
186- }
187-
188- public int getStars () {
189- return stars ;
190- }
191-
192- public void setStars (int stars ) {
193- this .stars = stars ;
194- }
124+ @ Test
125+ public void accessCombinedEndpoint () {
126+ final Response response = RestAssured .given ()
127+ .auth ()
128+ .form ("user" , "password" , formConfig )
129+ .get (ROOT_URI + "/combined?bookId=1" );
130+ Assert .assertEquals (HttpStatus .OK .value (), response .getStatusCode ());
131+ Assert .assertNotNull (response .getBody ());
132+ final Book result = response .as (Book .class );
133+ Assert .assertEquals (new Long (1 ), result .getId ());
134+ Assert .assertNotNull (result .getRatings ());
135+ Assert .assertTrue (result .getRatings ().size () > 0 );
195136 }
196-
197137}
0 commit comments