Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
promotions-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ascend
promotions-service
Commits
30c2d8ad
Commit
30c2d8ad
authored
May 07, 2021
by
Khai Yuan Liew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AFP-60] Finish work on bulkSearchSKU endpoint + test
parent
11f308f3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
10 deletions
+37
-10
PromotionService.java
...com/nisum/ascend/promotions/service/PromotionService.java
+6
-10
PromotionsControllerTest.java
...scend/promotions/controller/PromotionsControllerTest.java
+31
-0
No files found.
src/main/java/com/nisum/ascend/promotions/service/PromotionService.java
View file @
30c2d8ad
...
@@ -4,11 +4,15 @@ import com.nisum.ascend.promotions.dto.PromotionDto;
...
@@ -4,11 +4,15 @@ import com.nisum.ascend.promotions.dto.PromotionDto;
import
com.nisum.ascend.promotions.repository.PromotionRepository
;
import
com.nisum.ascend.promotions.repository.PromotionRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.reactive.function.BodyInserters
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Flux
;
import
reactor.core.scheduler.Schedulers
;
import
reactor.core.scheduler.Schedulers
;
import
java.util.List
;
import
java.util.List
;
import
static
org
.
springframework
.
http
.
ResponseEntity
.
notFound
;
import
static
org
.
springframework
.
http
.
ResponseEntity
.
ok
;
@Service
@Service
public
class
PromotionService
{
public
class
PromotionService
{
...
@@ -25,16 +29,8 @@ public class PromotionService {
...
@@ -25,16 +29,8 @@ public class PromotionService {
public
Flux
<
PromotionDto
>
bulkSearchSKU
(
List
<
String
>
skus
){
public
Flux
<
PromotionDto
>
bulkSearchSKU
(
List
<
String
>
skus
){
// skus.stream().map(sku -> findPromotionsByProductSku(sku));
return
Flux
.
fromIterable
(
skus
)
.
flatMap
(
sku
->
findPromotionsByProductSku
(
sku
));
// return Flux.fromStream(skus.stream().map(sku -> findPromotionsByProductSku(sku)));
return
null
;
// return Flux.fromIterable(skus)
// .map(sku -> {
// return findPromotionsByProductSku(sku);
// });
}
}
}
}
src/test/java/com/nisum/ascend/promotions/controller/PromotionsControllerTest.java
View file @
30c2d8ad
...
@@ -14,7 +14,10 @@ import org.springframework.test.annotation.DirtiesContext;
...
@@ -14,7 +14,10 @@ import org.springframework.test.annotation.DirtiesContext;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.junit.jupiter.SpringExtension
;
import
org.springframework.test.context.junit.jupiter.SpringExtension
;
import
org.springframework.test.web.reactive.server.WebTestClient
;
import
org.springframework.test.web.reactive.server.WebTestClient
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
...
@@ -86,4 +89,32 @@ class PromotionsControllerTest {
...
@@ -86,4 +89,32 @@ class PromotionsControllerTest {
promos
.
forEach
(
p
->
assertEquals
(
skuWithMultiplePromos
,
p
.
getProductSku
()));
promos
.
forEach
(
p
->
assertEquals
(
skuWithMultiplePromos
,
p
.
getProductSku
()));
});
});
}
}
@Test
public
void
bulkSearchTest
(){
List
<
String
>
skus
=
Arrays
.
asList
(
"AFP-1"
,
"AFP-2"
);
webTestClient
.
post
().
uri
(
"/api/promos/bulkSearch"
)
.
contentType
(
MediaType
.
valueOf
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
body
(
Mono
.
just
(
skus
),
List
.
class
)
.
exchange
()
.
expectStatus
().
isOk
()
.
expectBodyList
(
PromotionDto
.
class
)
.
consumeWith
(
promo
->{
List
<
PromotionDto
>
promos
=
promo
.
getResponseBody
();
assert
promos
!=
null
;
promos
.
forEach
(
p
->
{
String
sku
=
p
.
getProductSku
();
String
promotionId
=
p
.
getPromotionId
();
assertTrue
(
skus
.
contains
(
sku
));
System
.
out
.
println
(
"Product SKU: "
+
sku
);
System
.
out
.
println
(
"Promotion ID: "
+
promotionId
);
}
);
});
}
}
}
\ No newline at end of file
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