Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Khalid Ali
bookshare-backend
Commits
1b1ea997
Commit
1b1ea997
authored
Dec 17, 2018
by
Khalid Ali
Browse files
Attempt to test the PUT request on the controller.
parent
71694bce
Changes
3
Show whitespace changes
Inline
Side-by-side
src/main/java/com/gmu/bookshare/model/ListingDto.java
View file @
1b1ea997
...
...
@@ -40,7 +40,7 @@ public class ListingDto {
return
dateFormat
.
parse
(
this
.
createDate
);
}
public
void
setCreateDate
(
Date
date
)
{
public
void
setCreateDate
Converted
(
Date
date
)
{
this
.
createDate
=
dateFormat
.
format
(
date
);
}
}
src/main/java/com/gmu/bookshare/web/BookshareApiController.java
View file @
1b1ea997
...
...
@@ -73,7 +73,7 @@ public class BookshareApiController {
private
ListingDto
convertToDto
(
ListingEntity
listingEntity
)
{
ListingDto
listingDto
=
modelMapper
.
map
(
listingEntity
,
ListingDto
.
class
);
listingDto
.
setCreateDate
(
listingEntity
.
getCreateDate
());
listingDto
.
setCreateDate
Converted
(
listingEntity
.
getCreateDate
());
return
listingDto
;
}
...
...
src/test/java/com/gmu/bookshare/BookshareRestControllerIntegrationTest.java
View file @
1b1ea997
package
com.gmu.bookshare
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectWriter
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.gmu.bookshare.entity.ListingEntity
;
import
com.gmu.bookshare.model.ListingDto
;
import
com.gmu.bookshare.service.BidService
;
import
com.gmu.bookshare.service.ListingService
;
import
com.gmu.bookshare.service.ShareUserService
;
import
com.gmu.bookshare.web.BookshareApiController
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.modelmapper.ModelMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
...
...
@@ -22,6 +27,7 @@ import static org.hamcrest.Matchers.is;
import
static
org
.
hamcrest
.
collection
.
IsCollectionWithSize
.
hasSize
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
put
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
jsonPath
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
...
...
@@ -32,6 +38,9 @@ public class BookshareRestControllerIntegrationTest {
@Autowired
private
MockMvc
mvc
;
@Autowired
private
ModelMapper
modelMapper
;
@MockBean
private
ListingService
listingService
;
...
...
@@ -58,4 +67,54 @@ public class BookshareRestControllerIntegrationTest {
.
andExpect
(
jsonPath
(
"$"
,
hasSize
(
1
)))
.
andExpect
(
jsonPath
(
"$[0].isbn"
,
is
(
alex
.
getIsbn
())));
}
@Test
public
void
givenListing_whenPutListings_thenReturnCorrectHttpStatus
()
throws
Exception
{
ListingEntity
listingInDB
=
new
ListingEntity
(
123456
,
3
,
14.99
,
new
Date
(),
192838079872L
,
2879878394L
,
"Title Calc 3"
);
ListingEntity
listingNotInDB
=
new
ListingEntity
(
123456
,
3
,
14.99
,
new
Date
(),
192838079872L
,
2879878394L
,
"Title Calc 3"
);
ListingDto
listingDtoInDB
=
modelMapper
.
map
(
listingInDB
,
ListingDto
.
class
);
listingDtoInDB
.
setCreateDateConverted
(
listingInDB
.
getCreateDate
());
ListingDto
listingDtoNotInDB
=
modelMapper
.
map
(
listingNotInDB
,
ListingDto
.
class
);
listingDtoNotInDB
.
setCreateDateConverted
(
listingNotInDB
.
getCreateDate
());
// ListingDto listingDtoInDB = new ListingDto();
// listingDtoInDB.setIsbn(123456);
// listingDtoInDB.setCondition(3);
// listingDtoInDB.setPrice(14.99);
// listingDtoInDB.setCreateDateConverted(new Date());
// listingDtoInDB.setTitle("Title Calc 3");
// listingDtoInDB.setId(listingInDB.getId());
//
// ListingDto listingDtoNotInDB = new ListingDto();
// listingDtoInDB.setIsbn(123456);
// listingDtoInDB.setCondition(3);
// listingDtoInDB.setPrice(14.99);
// listingDtoInDB.setCreateDateConverted(new Date());
// listingDtoInDB.setTitle("Title Calc 3");
// listingDtoInDB.setId(listingNotInDB.getId());
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
SerializationFeature
.
WRAP_ROOT_VALUE
,
false
);
ObjectWriter
ow
=
mapper
.
writer
().
withDefaultPrettyPrinter
();
String
requestJson
=
ow
.
writeValueAsString
(
listingDtoInDB
);
String
requestJson2
=
ow
.
writeValueAsString
(
listingDtoNotInDB
);
given
(
listingService
.
updateListing
(
listingInDB
)).
willReturn
(
listingInDB
);
given
(
listingService
.
updateListing
(
listingNotInDB
)).
willReturn
(
null
);
mvc
.
perform
(
put
(
"/bs/api/listing/"
+
listingInDB
.
getId
())
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
requestJson
))
.
andExpect
(
status
().
isOk
());
mvc
.
perform
(
put
(
"/bs/api/listing/"
+
listingNotInDB
.
getId
())
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
requestJson2
))
.
andExpect
(
status
().
isNotFound
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment