-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev/weird test #16
base: main
Are you sure you want to change the base?
Dev/weird test #16
Changes from all commits
f260fe8
c824a77
c2da063
1c963ce
d6bb674
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,26 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
package it.move2.agent.application | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
import it.move2.job.EmploymentType | ||||||||||||||||||||||||||||||||||||||||||||||
import it.move2.job.JobOffer | ||||||||||||||||||||||||||||||||||||||||||||||
import it.move2.job.Skill | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
class JobFixture { | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
static jobOffer(args = [:]) { | ||||||||||||||||||||||||||||||||||||||||||||||
new JobOffer( | ||||||||||||||||||||||||||||||||||||||||||||||
'id' in args.keySet() ? args.id as String : 'test-id', | ||||||||||||||||||||||||||||||||||||||||||||||
'title' in args.keySet() ? args.title as String : 'test-title', | ||||||||||||||||||||||||||||||||||||||||||||||
'companyName' in args.keySet() ? args.companyName as String : 'test-company', | ||||||||||||||||||||||||||||||||||||||||||||||
'experience' in args.keySet() ? args.experience as String : 'test-experience', | ||||||||||||||||||||||||||||||||||||||||||||||
'skills' in args.keySet() ? args.skills as List<Skill> : [], | ||||||||||||||||||||||||||||||||||||||||||||||
'employmentType' in args.keySet() ? args.employmentType as List<EmploymentType> : [], | ||||||||||||||||||||||||||||||||||||||||||||||
'remote' in args.keySet() ? args.remote as boolean : true | ||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+9
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about simplifying this code?
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
static List<JobOffer> createListJobOffers(int count) { | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name of the function "createListJobOffers" may not reflect the intent well, as it may be associated with creating a list and storing it in a database, which is not the case here. I propose the same naming convention as above ie: jobOffersList |
||||||||||||||||||||||||||||||||||||||||||||||
return (1..count).collect { _ -> | ||||||||||||||||||||||||||||||||||||||||||||||
jobOffer() | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+21
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can simplify things a bit
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||
package it.move2.agent.application | ||||||
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper | ||||||
import it.move2.agent.configuration.PublisherConfiguration | ||||||
import it.move2.agent.ports.Queue | ||||||
import it.move2.job.JobOffer | ||||||
import spock.lang.Specification | ||||||
import spock.lang.Subject | ||||||
|
||||||
class PublisherTest extends Specification { | ||||||
|
||||||
private PublisherConfiguration configuration | ||||||
private ObjectMapper objectMapper | ||||||
private Queue queue | ||||||
|
||||||
@Subject | ||||||
Publisher publisher | ||||||
|
||||||
def setup() { | ||||||
configuration = new PublisherConfiguration(2) | ||||||
objectMapper = new ObjectMapper() | ||||||
queue = Mock(Queue) | ||||||
publisher = new Publisher(configuration, objectMapper, queue) | ||||||
} | ||||||
|
||||||
def "publish should chunk job offers and publish them to the queue"() { | ||||||
given: | ||||||
List<JobOffer> jobOffers = JobFixture.createListJobOffers(10) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use static import import static it.move2.agent.application.JobFixture.createListJobOffers
Suggested change
|
||||||
|
||||||
when: | ||||||
publisher.publish(jobOffers) | ||||||
|
||||||
then: | ||||||
5 * queue.pub(_) | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,62 @@ | ||||||
package it.move2.agent.application | ||||||
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper | ||||||
import it.move2.agent.configuration.PublisherConfiguration | ||||||
import it.move2.agent.ports.JobBoard | ||||||
import it.move2.agent.ports.Queue | ||||||
import spock.lang.Specification | ||||||
import spock.lang.Subject | ||||||
|
||||||
class UpdaterTest extends Specification { | ||||||
private JobBoard jobBoard1 | ||||||
private JobBoard jobBoard2 | ||||||
private Queue queue | ||||||
private ObjectMapper objectMapper | ||||||
private Publisher publisher | ||||||
|
||||||
@Subject | ||||||
private Updater updater | ||||||
|
||||||
def setup() { | ||||||
jobBoard1 = Mock() | ||||||
jobBoard2 = Mock() | ||||||
queue = Mock() | ||||||
objectMapper = new ObjectMapper() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using the same ObjectMapper that is used in the code from the Bootstrap class? Currently, this ObjectMapper is configured a bit different in tests than in the production version, which may not reveal all the bugs. |
||||||
publisher = new Publisher(new PublisherConfiguration(2), objectMapper, queue) | ||||||
|
||||||
updater = new Updater([jobBoard1, jobBoard2], publisher) | ||||||
} | ||||||
|
||||||
def "should publish jobs from all job boards"() { | ||||||
given: | ||||||
def jobs1 = [JobFixture.jobOffer(), JobFixture.jobOffer()] | ||||||
def jobs2 = [JobFixture.jobOffer(), JobFixture.jobOffer()] | ||||||
|
||||||
jobBoard1.getJobs() >> jobs1 | ||||||
jobBoard2.getJobs() >> jobs2 | ||||||
|
||||||
when: | ||||||
updater.execute() | ||||||
|
||||||
then: | ||||||
noExceptionThrown() | ||||||
|
||||||
and: | ||||||
2 * queue.pub(_) >> {} | ||||||
} | ||||||
|
||||||
def "should not publish jobs when error occurs"() { | ||||||
given: | ||||||
def jobs1 = [JobFixture.jobOffer(), JobFixture.jobOffer()] | ||||||
|
||||||
jobBoard1.getJobs() >> jobs1 | ||||||
jobBoard2.getJobs() >> { throw new RuntimeException("Test error message") } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is error handling carried out in the application? I haven't seen anything throwing an exception. |
||||||
|
||||||
when: | ||||||
updater.execute() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
then: | ||||||
thrown(RuntimeException) | ||||||
0 * queue.pub(_) >> {} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest filling these fields with additional data instead of empty lists.