-
Notifications
You must be signed in to change notification settings - Fork 16
Conversation
src/test/java/com/org/jenkins/custom/jenkins/distribution/service/PackageControllerTest.java
Outdated
Show resolved
Hide resolved
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.
These are high level tests. I would prefer to see low level unit tests for methods of each class, IMO it would be easier to review and easier to maintain, specifically unit tests for WarGenerator
and PackagerDownloadService
. Please provide unit tests for those classes.
src/test/java/com/org/jenkins/custom/jenkins/distribution/service/PackageControllerTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/org/jenkins/custom/jenkins/distribution/service/PackageControllerTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/org/jenkins/custom/jenkins/distribution/service/PackageControllerTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/org/jenkins/custom/jenkins/distribution/service/PackageControllerTest.java
Outdated
Show resolved
Hide resolved
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.
Left some comments that can be addressed with Martin's review
...a/com/org/jenkins/custom/jenkins/distribution/service/generators/PackageConfigGenerator.java
Outdated
Show resolved
Hide resolved
src/test/java/com/org/jenkins/custom/jenkins/distribution/service/SpringMVCSetup.java
Show resolved
Hide resolved
As mentioned previously running war generator inside JUNIT results in a lot of dependency issues Oleg tried to resolve some of them but they continued to persist. Hence we cannot write unit tests for these methods |
private final static Logger LOGGER = Logger.getLogger(PackagerController.class.getName()); | ||
|
||
@Autowired | ||
public PackagerController(final PackageConfigGenerator packageConfGen, final PackagerDownloadService packagerDownServ) { |
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.
Needed to autowire this in order for it to be mocked so that it gets dependency gets injected during testing.
@@ -47,7 +55,7 @@ | |||
String yamlResponse = ""; | |||
HttpStatus httpStatus; | |||
try { | |||
yamlResponse = generatePackageConfig(new JSONObject(postPayload)); | |||
yamlResponse = packagerConfGen.generatePackageConfig(new JSONObject(postPayload)); |
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.
PMD complained with short names :)
@@ -0,0 +1 @@ | |||
This will serve as the dummy war file. |
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.
Added a text file because the jacoco plugin errored out for dummy war files
@@ -29,23 +31,26 @@ public void setup() { | |||
@Test | |||
public void return_status_200() throws Exception { | |||
|
|||
MockMvc pluginMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); |
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.
Maven was returning null on running these tests since the web app context was not available in the @before annotation, so injected it in the test.
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.
Please clean up the class and test method names:
PackageControllerTest.java
: must match the Java class name it tests (PackagerController.java
)- Test method names: it is best to match the methods they test in the class under test. Here is one example:
- Class under test method name:
getPackageConfig
, I expect to see agetPackageConfigTest
method for the success path. - For the error paths, expand on the name, for example:
getPackageConfig404When<condition>
- When there are multiple error paths, there would be multiple test methods with different s
- Class under test method name:
The test methods cover all the conditions. This is good. |
@@ -16,7 +16,7 @@ | |||
private static final String TEMP_PREFIX = "CDS"; | |||
|
|||
|
|||
public static File generateWAR(final String versionName, final String configuration) throws IOException, InterruptedException { | |||
public File generateWAR(final String versionName, final String configuration) throws IOException, InterruptedException { |
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.
Just question: did you remove static to make it easier to test?
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.
yes
This PR adds controller tests for the package generation controller. We already have the package generation class unit tested so this class only makes sure the file is being downloaded and generated correctly