forked from secureCodeBox/defectdojo-client-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
secureCodeBox#121 Use URI Instead of String
This has theadvantage that URLs are validated in place and we can normalize theresulting URL to remove double slashes from path. Signed-off-by: Sven Strittmatter <[email protected]>
- Loading branch information
1 parent
eb975b1
commit 3309da3
Showing
3 changed files
with
77 additions
and
17 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
56 changes: 56 additions & 0 deletions
56
...st/java/io/securecodebox/persistence/defectdojo/service/GenericDefectDojoServiceTest.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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.securecodebox.persistence.defectdojo.service; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import io.securecodebox.persistence.defectdojo.exception.PersistenceException; | ||
import io.securecodebox.persistence.defectdojo.model.Model; | ||
import io.securecodebox.persistence.defectdojo.model.PaginatedResult; | ||
import lombok.NonNull; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
/** | ||
* Tests for {@link GenericDefectDojoService} | ||
*/ | ||
final class GenericDefectDojoServiceTest extends WireMockBaseTestCase { | ||
private static final class TestModel implements Model { | ||
@Override | ||
public boolean equalsQueryString(@NonNull Map<String, Object> queryParams) { | ||
// Stub this to false because we do not test this method here. | ||
return false; | ||
} | ||
} | ||
private final GenericDefectDojoService<TestModel> sut =new GenericDefectDojoService<>(conf()) { | ||
|
||
@Override | ||
protected String getUrlPath() { | ||
return "snafu"; | ||
} | ||
|
||
@Override | ||
protected Class<TestModel> getModelClass() { | ||
return TestModel.class; | ||
} | ||
|
||
@Override | ||
protected PaginatedResult<TestModel> deserializeList(@NonNull String response) { | ||
try { | ||
return this.objectMapper.readValue(response, new TypeReference<>() { | ||
}); | ||
} catch (JsonProcessingException e) { | ||
throw new PersistenceException("Can't process JSON response!", e); | ||
} | ||
} | ||
}; | ||
|
||
@Test | ||
void createBaseUrl() { | ||
assertThat(sut.createBaseUrl(), is(URI.create("http://localhost:8888/api/v2/snafu/"))); | ||
} | ||
} |