|
3 | 3 | // SPDX-License-Identifier: Apache-2.0
|
4 | 4 | package org.lfenergy.compas.scl.validator.xsd.resourceresolver;
|
5 | 5 |
|
| 6 | +import org.junit.jupiter.api.BeforeEach; |
6 | 7 | import org.junit.jupiter.api.Test;
|
| 8 | +import org.lfenergy.compas.scl.validator.exception.SclValidatorException; |
7 | 9 |
|
8 | 10 | import java.io.IOException;
|
9 | 11 | import java.nio.charset.StandardCharsets;
|
10 | 12 |
|
11 | 13 | import static org.junit.jupiter.api.Assertions.*;
|
| 14 | +import static org.lfenergy.compas.scl.validator.exception.SclValidatorErrorCode.RESOURCE_RESOLVER_FAILED; |
12 | 15 |
|
13 | 16 | class ResourceInputTest {
|
| 17 | + |
| 18 | + private ResourceInput resourceInput; |
| 19 | + |
| 20 | + @BeforeEach |
| 21 | + void beforeEach() { |
| 22 | + var inputStream = this.getClass().getResourceAsStream("/scl/example.scd"); |
| 23 | + resourceInput = new ResourceInput("1", "2", inputStream); |
| 24 | + } |
| 25 | + |
14 | 26 | @Test
|
15 | 27 | void allGetters_WhenCalled_ThenCorrectValueIsReturned() throws IOException {
|
16 |
| - var firstInputStream = this.getClass().getResourceAsStream("/scl/example.scd"); |
17 | 28 | var secondInputStream = this.getClass().getResourceAsStream("/scl/example.scd");
|
18 | 29 |
|
19 |
| - var input = new ResourceInput("1", "2", firstInputStream); |
20 |
| - |
21 |
| - assertEquals("1", input.getPublicId()); |
22 |
| - assertEquals("2", input.getSystemId()); |
23 |
| - assertNull(input.getBaseURI()); |
24 |
| - assertNull(input.getByteStream()); |
25 |
| - assertFalse(input.getCertifiedText()); |
26 |
| - assertNull(input.getCharacterStream()); |
27 |
| - assertNull(input.getEncoding()); |
| 30 | + assertEquals("1", resourceInput.getPublicId()); |
| 31 | + assertEquals("2", resourceInput.getSystemId()); |
| 32 | + assertNull(resourceInput.getBaseURI()); |
| 33 | + assertNull(resourceInput.getByteStream()); |
| 34 | + assertFalse(resourceInput.getCertifiedText()); |
| 35 | + assertNull(resourceInput.getCharacterStream()); |
| 36 | + assertNull(resourceInput.getEncoding()); |
28 | 37 |
|
29 | 38 | var expectedStringData = new String(secondInputStream.readAllBytes(), StandardCharsets.UTF_8);
|
30 |
| - assertEquals(expectedStringData.hashCode(), input.getStringData().hashCode()); |
| 39 | + assertEquals(expectedStringData.hashCode(), resourceInput.getStringData().hashCode()); |
| 40 | + } |
| 41 | + @Test |
| 42 | + void getStringData_WhenCalledWithInvalidInputStream_ThenExceptionIsThrown() { |
| 43 | + var input = new ResourceInput("1", "2", null); |
| 44 | + |
| 45 | + var exception = assertThrows(SclValidatorException.class, input::getStringData); |
| 46 | + assertEquals(RESOURCE_RESOLVER_FAILED, exception.getErrorCode()); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void setPublicId_WhenCalled_ThenCorrectValueIsSet() { |
| 51 | + resourceInput.setPublicId("10"); |
| 52 | + assertEquals("10", resourceInput.getPublicId()); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + void setSystemId_WhenCalled_ThenCorrectValueIsSet() { |
| 57 | + resourceInput.setSystemId("10"); |
| 58 | + assertEquals("10", resourceInput.getSystemId()); |
31 | 59 | }
|
32 | 60 | }
|
0 commit comments