|
11 | 11 | import lombok.extern.slf4j.Slf4j; |
12 | 12 | import org.junit.jupiter.api.*; |
13 | 13 | import org.mockserver.client.MockServerClient; |
| 14 | +import org.mockserver.logging.MockServerLogger; |
| 15 | +import org.mockserver.socket.tls.KeyStoreFactory; |
14 | 16 | import org.mockserver.springtest.MockServerPort; |
15 | 17 | import org.mockserver.springtest.MockServerTest; |
16 | 18 | import org.springframework.beans.factory.annotation.Autowired; |
|
23 | 25 | import org.springframework.context.annotation.ComponentScan; |
24 | 26 | import org.springframework.context.annotation.Import; |
25 | 27 |
|
| 28 | +import javax.net.ssl.HttpsURLConnection; |
| 29 | +import java.io.IOException; |
26 | 30 | import java.nio.file.Paths; |
27 | 31 | import java.util.Random; |
28 | 32 | import java.util.concurrent.TimeUnit; |
@@ -58,6 +62,14 @@ class CRServiceTests { |
58 | 62 | @MockServerPort |
59 | 63 | private Integer mockServerPort; |
60 | 64 |
|
| 65 | + @BeforeAll |
| 66 | + public void prepareFileCache() throws IOException { |
| 67 | + // ensure all connection using HTTPS will use the SSL context defined by |
| 68 | + // MockServer to allow dynamically generated certificates to be accepted |
| 69 | + HttpsURLConnection.setDefaultSSLSocketFactory(new KeyStoreFactory(new MockServerLogger()).sslContext().getSocketFactory()); |
| 70 | + |
| 71 | + } |
| 72 | + |
61 | 73 | @Test |
62 | 74 | void serverNotAvailable() { |
63 | 75 |
|
@@ -139,37 +151,48 @@ void nonParseableResult() throws CCRServiceNotAvailableException, CRServiceStora |
139 | 151 | @Test |
140 | 152 | void isPublic() { |
141 | 153 |
|
142 | | - assertDoesNotThrow(() -> crService.getParsedProfile("https://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/1.x/profiles/clarin.eu:cr1:p_1380106710826/xsd")); |
143 | | - |
144 | | - ParsedProfile parsedProfile = null; |
145 | | - |
146 | | - try { |
147 | | - |
148 | | - parsedProfile = crService.getParsedProfile("https://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/1.x/profiles/clarin.eu:cr1:p_1380106710826/xsd"); |
149 | | - } |
150 | | - catch (Exception e) { |
151 | | - |
152 | | - log.error("error in schema"); |
153 | | - log.error("", e); |
154 | | - } |
155 | | - // the profile is in the context registry |
156 | | - assertTrue(parsedProfile.header().isCrResident()); |
157 | | - // and it is public |
158 | | - assertTrue(parsedProfile.header().isPublic()); |
| 154 | + assertDoesNotThrow(() -> { |
| 155 | + ParsedProfile parsedProfile = crService.getParsedProfile("https://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/1.x/profiles/clarin.eu:cr1:p_1380106710826/xsd"); |
| 156 | + // the profile is in the context registry |
| 157 | + assertTrue(parsedProfile.header().isCrResident()); |
| 158 | + // and it is public |
| 159 | + assertTrue(parsedProfile.header().isPublic()); |
| 160 | + }); |
159 | 161 |
|
160 | | - try { |
| 162 | + this.mockServerClient |
| 163 | + .when( |
| 164 | + request() |
| 165 | + ) |
| 166 | + .respond( |
| 167 | + response() |
| 168 | + .withBody( |
| 169 | + """ |
| 170 | + <?xml version="1.0" encoding="UTF-8"?> |
| 171 | + <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cmd="http://www.clarin.eu/cmd/1" xmlns:cue="http://www.clarin.eu/cmd/cues/1" xmlns:cue_old="http://www.clarin.eu/cmdi/cues/1" xmlns:cmdp="http://www.clarin.eu/cmd/1/profiles/clarin.eu:cr1:p_1381926654571" targetNamespace="http://www.clarin.eu/cmd/1/profiles/clarin.eu:cr1:p_1381926654571" elementFormDefault="qualified"> |
| 172 | + <xs:annotation> |
| 173 | + <xs:appinfo xmlns:ann="http://www.clarin.eu"> |
| 174 | + <cmd:Header> |
| 175 | + <cmd:ID>clarin.eu:cr1:p_1381926654571</cmd:ID> |
| 176 | + <cmd:Name>Corpus</cmd:Name> |
| 177 | + <cmd:Description>Profile for the description of corpora containing basic metadata for the integration of resources into the various parts of the CLARIN-D infrastructure. Version 0.1</cmd:Description> |
| 178 | + <cmd:Status>production</cmd:Status> |
| 179 | + </cmd:Header> |
| 180 | + </xs:appinfo> |
| 181 | + </xs:annotation> |
| 182 | + <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/> |
| 183 | + <xs:import namespace="http://www.clarin.eu/cmd/1" schemaLocation="https://infra.clarin.eu/CMDI/1.x/xsd/cmd-envelop.xsd"/> |
| 184 | + </xs:schema> |
| 185 | + """ |
| 186 | + ) |
| 187 | + ); |
161 | 188 |
|
162 | | - parsedProfile = crService.getParsedProfile("file:///tmp/17661427897514518579.tmp"); |
163 | | - } |
164 | | - catch (Exception e) { |
| 189 | + assertDoesNotThrow(() -> { |
| 190 | + ParsedProfile parsedProfile = crService.getParsedProfile("https://wowasa.com/clarin.eu:cr1:p_1380106710826/xsd"); |
165 | 191 |
|
166 | | - log.error("error in schema"); |
167 | | - log.error("", e); |
168 | | - } |
169 | | - // uploaded profiles are not in the context registry |
170 | | - assertFalse(parsedProfile.header().isCrResident()); |
171 | | - // uploaded profiles can't be public, since only profiles from the context registry can be public |
172 | | - assertFalse(parsedProfile.header().isPublic()); |
| 192 | + assertFalse(parsedProfile.header().isCrResident()); |
| 193 | + // uploaded profiles can't be public, since only profiles from the context registry can be public |
| 194 | + assertFalse(parsedProfile.header().isPublic()); |
| 195 | + }); |
173 | 196 | } |
174 | 197 |
|
175 | 198 | @SpringBootConfiguration |
|
0 commit comments