Skip to content

Commit ff8d29b

Browse files
committed
fix in test
1 parent eebe377 commit ff8d29b

File tree

1 file changed

+51
-28
lines changed

1 file changed

+51
-28
lines changed

curation-cr/src/test/java/eu/clarin/cmdi/curation/cr/CRServiceTests.java

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import lombok.extern.slf4j.Slf4j;
1212
import org.junit.jupiter.api.*;
1313
import org.mockserver.client.MockServerClient;
14+
import org.mockserver.logging.MockServerLogger;
15+
import org.mockserver.socket.tls.KeyStoreFactory;
1416
import org.mockserver.springtest.MockServerPort;
1517
import org.mockserver.springtest.MockServerTest;
1618
import org.springframework.beans.factory.annotation.Autowired;
@@ -23,6 +25,8 @@
2325
import org.springframework.context.annotation.ComponentScan;
2426
import org.springframework.context.annotation.Import;
2527

28+
import javax.net.ssl.HttpsURLConnection;
29+
import java.io.IOException;
2630
import java.nio.file.Paths;
2731
import java.util.Random;
2832
import java.util.concurrent.TimeUnit;
@@ -58,6 +62,14 @@ class CRServiceTests {
5862
@MockServerPort
5963
private Integer mockServerPort;
6064

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+
6173
@Test
6274
void serverNotAvailable() {
6375

@@ -139,37 +151,48 @@ void nonParseableResult() throws CCRServiceNotAvailableException, CRServiceStora
139151
@Test
140152
void isPublic() {
141153

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+
});
159161

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+
);
161188

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");
165191

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+
});
173196
}
174197

175198
@SpringBootConfiguration

0 commit comments

Comments
 (0)