-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add checkFalse and checkTrue for assertions to replace checkBoolean
- Loading branch information
Showing
6 changed files
with
102 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 70 additions & 1 deletion
71
src/test/java/com/endava/cats/fuzzer/http/EmptyJsonArrayBodyFuzzerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,76 @@ | ||
package com.endava.cats.fuzzer.http; | ||
|
||
import com.endava.cats.fuzzer.executor.SimpleExecutor; | ||
import com.endava.cats.http.HttpMethod; | ||
import com.endava.cats.http.ResponseCodeFamily; | ||
import com.endava.cats.io.ServiceCaller; | ||
import com.endava.cats.model.CatsResponse; | ||
import com.endava.cats.model.FuzzingData; | ||
import com.endava.cats.report.TestCaseExporter; | ||
import com.endava.cats.report.TestCaseListener; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.mockito.InjectSpy; | ||
import io.swagger.v3.oas.models.media.StringSchema; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
import java.util.List; | ||
|
||
@QuarkusTest | ||
class EmptyJsonArrayBodyTest { | ||
class EmptyJsonArrayBodyFuzzerTest { | ||
private ServiceCaller serviceCaller; | ||
@InjectSpy | ||
private TestCaseListener testCaseListener; | ||
private EmptyJsonArrayBodyFuzzer emptyJsonArrayBodyFuzzer; | ||
|
||
@BeforeEach | ||
void setup() { | ||
serviceCaller = Mockito.mock(ServiceCaller.class); | ||
SimpleExecutor simpleExecutor = new SimpleExecutor(testCaseListener, serviceCaller); | ||
emptyJsonArrayBodyFuzzer = new EmptyJsonArrayBodyFuzzer(simpleExecutor); | ||
ReflectionTestUtils.setField(testCaseListener, "testCaseExporter", Mockito.mock(TestCaseExporter.class)); | ||
} | ||
|
||
@Test | ||
void shouldNotRunForEmptyPayload() { | ||
emptyJsonArrayBodyFuzzer.fuzz(Mockito.mock(FuzzingData.class)); | ||
|
||
Mockito.verifyNoInteractions(testCaseListener); | ||
} | ||
|
||
@Test | ||
void givenAHttpMethodWithPayload_whenApplyingTheMalformedJsonFuzzer_thenTheResultsAreCorrectlyReported() { | ||
FuzzingData data = FuzzingData.builder().method(HttpMethod.POST).reqSchema(new StringSchema()).requestContentTypes(List.of("application/json")).build(); | ||
ReflectionTestUtils.setField(data, "processedPayload", "{\"id\": 1}"); | ||
|
||
CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(400).build(); | ||
Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse); | ||
Mockito.doNothing().when(testCaseListener).reportResult(Mockito.any(), Mockito.eq(data), Mockito.any(), Mockito.any(), Mockito.anyBoolean()); | ||
|
||
emptyJsonArrayBodyFuzzer.fuzz(data); | ||
Mockito.verify(testCaseListener, Mockito.times(1)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.eq(catsResponse), Mockito.eq(ResponseCodeFamily.FOURXX), Mockito.anyBoolean()); | ||
} | ||
|
||
@Test | ||
void shouldHaveToString() { | ||
Assertions.assertThat(emptyJsonArrayBodyFuzzer).hasToString(emptyJsonArrayBodyFuzzer.getClass().getSimpleName()); | ||
} | ||
|
||
@Test | ||
void shouldHaveDescription() { | ||
Assertions.assertThat(emptyJsonArrayBodyFuzzer.description()).isNotBlank(); | ||
} | ||
|
||
@Test | ||
void shouldSkipForNonHttpBodyMethods() { | ||
Assertions.assertThat(emptyJsonArrayBodyFuzzer.skipForHttpMethods()).contains(HttpMethod.GET, HttpMethod.DELETE); | ||
} | ||
|
||
@Test | ||
void shouldHaveNullPayload() { | ||
Assertions.assertThat(emptyJsonArrayBodyFuzzer.getPayload(null)).isEqualTo("[]"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters