Skip to content

Commit 1477174

Browse files
committed
issue #285
1 parent 4805ac9 commit 1477174

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

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

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import eu.clarin.cmdi.curation.cr.exception.CRServiceStorageException;
88
import eu.clarin.cmdi.curation.cr.exception.NoCRCacheEntryException;
99
import eu.clarin.cmdi.curation.cr.exception.PPHCacheException;
10+
import eu.clarin.cmdi.curation.cr.profile_parser.ParsedProfile;
1011
import lombok.extern.slf4j.Slf4j;
1112
import org.junit.jupiter.api.*;
1213
import org.mockserver.client.MockServerClient;
@@ -57,7 +58,7 @@ class CRServiceTests {
5758
@MockServerPort
5859
private Integer mockServerPort;
5960

60-
//@Test
61+
@Test
6162
void serverNotAvailable() {
6263

6364
this.mockServerClient
@@ -68,24 +69,24 @@ void serverNotAvailable() {
6869
response().withStatusCode(200)
6970
);
7071

72+
// we're making the proxy server inaccessible by incrementing the port to call
7173
httpConfig.setProxyPort(this.mockServerPort + 1);
7274

73-
try {
74-
assertDoesNotThrow(() -> this.crCache.getEntry("http://www.wowasa.com/clarin.eu:cr1:p_1403526079381/xsd"));
75-
assertThrows(NoCRCacheEntryException.class, () -> crService.getParsedProfile("http://www.wowasa.com/clarin.eu:cr1:p_1403526079381/xsd"));
76-
// should be cached
77-
assertNotNull(cacheManager.getCache("crCache").get("http://www.wowasa.com/clarin.eu:cr1:p_1403526079381/xsd"));
78-
// even with a local file it should throw an exception
79-
assertDoesNotThrow(() -> this.crCache.getEntry(Paths.get("tmp", "77777").toUri().toString()));
80-
}
81-
catch (Exception e) {
82-
83-
}
84-
75+
// we are using a proxy server which responds with ok status, but since we call it on the wrong port, the server is not accessible
76+
// no exception should be thrown in crCache but a null value should be cached for the profile
77+
assertDoesNotThrow(() -> this.crCache.getEntry("http://www.wowasa.com/clarin.eu:cr1:p_1403526079381/xsd"));
78+
// the attempt to get the parsed profile should result in an exception, since we can't create a ParsedProfile from null
79+
assertThrows(NoCRCacheEntryException.class, () -> crService.getParsedProfile("http://www.wowasa.com/clarin.eu:cr1:p_1403526079381/xsd"));
80+
// there should by a cache entry (we're testing for the existence of a cache entry, not for its value!)
81+
assertNotNull(cacheManager.getCache("crCache").get("http://www.wowasa.com/clarin.eu:cr1:p_1403526079381/xsd"));
82+
// even with a non-existent local file it shouldn't throw an exception
83+
assertDoesNotThrow(() -> this.crCache.getEntry(Paths.get("tmp", "77777").toUri().toString()));
84+
85+
// resetting to the correct proxy server port
8586
httpConfig.setProxyPort(this.mockServerPort);
8687
}
8788

88-
//@Test
89+
@Test
8990
void connectionTimeout() throws NoCRCacheEntryException, CRServiceStorageException, CCRServiceNotAvailableException, PPHCacheException {
9091

9192
this.mockServerClient
@@ -98,17 +99,16 @@ void connectionTimeout() throws NoCRCacheEntryException, CRServiceStorageExcepti
9899
.withDelay(TimeUnit.SECONDS, 6)
99100
);
100101

102+
// we are using a proxy server which responds with ok status after 6 seconds, which is more than the standard connection timeout of 5 seconds
103+
// no exception should be thrown in crCache but a null value should be cached for the profile
101104
assertDoesNotThrow(() -> this.crCache.getEntry("http://www.wowasa.com/clarin.eu:cr1:p_1403526079382/xsd"));
102-
assertThrows(NoCRCacheEntryException.class, () -> this.crService.getParsedProfile("http://www.wowasa.com/clarin.eu:cr1:p_1403526079382/xsd"));
103-
104-
assertFalse(this.crService.isPublicSchema("http://www.wowasa.com/clarin.eu:cr1:p_1403526079382/xsd"));
105-
// should be cached
105+
// the attempt to get the parsed profile should result in an exception, since we can't create a ParsedProfile from null
106+
assertThrows(NoCRCacheEntryException.class, () -> crService.getParsedProfile("http://www.wowasa.com/clarin.eu:cr1:p_1403526079382/xsd"));
107+
// there should by a cache entry (we're testing for the existence of a cache entry, not for its value!)
106108
assertNotNull(cacheManager.getCache("crCache").get("http://www.wowasa.com/clarin.eu:cr1:p_1403526079382/xsd"));
107-
108-
109109
}
110110

111-
//@Test
111+
@Test
112112
void nonParseableResult() throws CCRServiceNotAvailableException, CRServiceStorageException, PPHCacheException, NoCRCacheEntryException {
113113

114114
this.mockServerClient
@@ -136,41 +136,40 @@ void nonParseableResult() throws CCRServiceNotAvailableException, CRServiceStora
136136

137137
}
138138

139-
//@Test
139+
@Test
140140
void isPublic() {
141141

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+
142146
try {
143-
assertDoesNotThrow(() -> crService.getParsedProfile("https://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/1.x/profiles/clarin.eu:cr1:p_1403526079380/xsd"));
144-
assertTrue(crService.getParsedProfile("https://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/1.x/profiles/clarin.eu:cr1:p_1403526079380/xsd").header().isPublic());
145-
// assertDoesNotThrow(() -> crService.getParsedProfile("https://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/1.x/profiles/clarin.eu:cr1:p_9990106710826/xsd"));
146-
// assertFalse(crService.getParsedProfile("https://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/1.x/profiles/clarin.eu:cr1:p_9990106710826/xsd").header().isPublic());
147-
assertFalse(crService.getParsedProfile(this.crConfig.getCrCache().resolve("https___catalog_clarin_eu_ds_ComponentRegistry_rest_registry_1_x_profiles_clarin_eu_cr1_p_1403526079380_xsd.xsd").toUri().toString()).header().isPublic());
147+
148+
parsedProfile = crService.getParsedProfile("https://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/1.x/profiles/clarin.eu:cr1:p_1380106710826/xsd");
148149
}
149150
catch (Exception e) {
150151

151152
log.error("error in schema");
152153
log.error("", e);
153154
}
154-
}
155-
156-
@Test
157-
void cacheUsage() {
155+
// the profile is in the context registry
156+
assertTrue(parsedProfile.header().isCrResident());
157+
// and it is public
158+
assertTrue(parsedProfile.header().isPublic());
158159

159160
try {
160161

161-
crService.getParsedProfile("https://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/1.x/profiles/clarin.eu:cr1:p_1403526079380/xsd");
162-
// crService.getParsedProfile("https://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/1.x/profiles/clarin.eu:cr1:p_9990106710826/xsd");
163-
164-
crService.getParsedProfile(this.crConfig.getCrCache().resolve("https___catalog_clarin_eu_ds_ComponentRegistry_rest_registry_1_x_profiles_clarin_eu_cr1_p_1403526079380_xsd.xsd").toUri().toString());
165-
166-
assertNotNull(cacheManager.getCache("crCache").get("https://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/1.x/profiles/clarin.eu:cr1:p_1403526079380/xsd"));
167-
// assertNotNull(cacheManager.getCache("crCache").get("https://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/1.x/profiles/clarin.eu:cr1:p_9990106710826/xsd"));
168-
}
162+
parsedProfile = crService.getParsedProfile("file:///tmp/17661427897514518579.tmp");
163+
}
169164
catch (Exception e) {
170165

171166
log.error("error in schema");
172167
log.error("", e);
173168
}
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());
174173
}
175174

176175
@SpringBootConfiguration

0 commit comments

Comments
 (0)