Skip to content

Commit 20f959f

Browse files
committed
Working on #353
1 parent 819f2e8 commit 20f959f

File tree

9 files changed

+96
-14
lines changed

9 files changed

+96
-14
lines changed

moneta-convert/moneta-convert-imf/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<dependency>
3737
<groupId>com.squareup.okhttp3</groupId>
3838
<artifactId>okhttp</artifactId>
39-
<version>4.12.0</version>
39+
<version>${okhttp.version}</version>
4040
</dependency>
4141
</dependencies>
4242
<name>Moneta Currency Conversion - IMF Provider</name>

moneta-core/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@
221221
<artifactId>money-api</artifactId>
222222
<version>${jsr.version}</version>
223223
</dependency>
224+
<dependency>
225+
<groupId>com.squareup.okhttp3</groupId>
226+
<artifactId>okhttp</artifactId>
227+
<version>${okhttp.version}</version>
228+
</dependency>
224229
<!-- OSGI support -->
225230
<dependency>
226231
<groupId>org.osgi</groupId>

moneta-core/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
requires jakarta.annotation;
3333
requires static osgi.core;
3434
requires static osgi.annotation;
35+
requires okhttp3;
3536
provides javax.money.spi.CurrencyProviderSpi with JDKCurrencyProvider, ConfigurableCurrencyUnitProvider;
3637
provides javax.money.spi.MonetaryAmountFactoryProviderSpi with MoneyAmountFactoryProvider, FastMoneyAmountFactoryProvider, RoundedMoneyAmountFactoryProvider;
3738
provides javax.money.spi.MonetaryAmountFormatProviderSpi with DefaultAmountFormatProviderSpi;

moneta-core/src/main/java/org/javamoney/moneta/spi/loader/okhttp/OkHttpLoaderService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/**
3333
* This class provides a mechanism to register resources, that may be updated
3434
* regularly. The implementation, based on the {@link UpdatePolicy}
35-
* loads/updates the resources from arbitrary locations via {@link OkHttpClient} and stores them to the
35+
* loads/updates the resources from arbitrary locations via {@link okhttp3.OkHttpClient} and stores them to the
3636
* format file cache. Default loading tasks can be configured within the <code>javamoney.properties</code>
3737
* file.
3838
* @see LoaderConfigurator

moneta-core/src/main/java/org/javamoney/moneta/spi/loader/okhttp/OkHttpResourceCache.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/**
3131
* Default implementation of {@link ResourceCache}, using the local file system.
3232
*
33-
* @author Anatole Tresch
33+
* @author Werner Keil
3434
*/
3535
class OkHttpResourceCache implements ResourceCache {
3636
/**
@@ -85,7 +85,7 @@ public OkHttpResourceCache() {
8585
* (non-Javadoc)
8686
*
8787
* @see
88-
* org.javamoney.moneta.loader.format.ResourceCache#write(java.lang.String
88+
* org.javamoney.moneta.spi.loader.ResourceCache#write(java.lang.String
8989
* , byte[])
9090
*/
9191
@Override
@@ -108,7 +108,7 @@ public void write(String resourceId, byte[] data) {
108108
* (non-Javadoc)
109109
*
110110
* @see
111-
* org.javamoney.moneta.loader.format.ResourceCache#isCached(java.lang
111+
* org.javamoney.moneta.spi.loader.ResourceCache#isCached(java.lang
112112
* .String)
113113
*/
114114
@Override
@@ -120,7 +120,7 @@ public boolean isCached(String resourceId) {
120120
* (non-Javadoc)
121121
*
122122
* @see
123-
* org.javamoney.moneta.loader.format.ResourceCache#read(java.lang.String)
123+
* org.javamoney.moneta.spi.loader.ResourceCache#read(java.lang.String)
124124
*/
125125
@Override
126126
public byte[] read(String resourceId) {
@@ -150,7 +150,7 @@ public void clear(String resourceId) {
150150

151151
@Override
152152
public String toString() {
153-
return "URLConnectionResourceCache [localDir=" + localDir + ", cachedResources=" + cachedResources + ']';
153+
return "OkHttpResourceCache [localDir=" + localDir + ", cachedResources=" + cachedResources + ']';
154154
}
155155

156156
}

moneta-core/src/main/java/org/javamoney/moneta/spi/loader/urlconnection/URLConnectionResourceCache.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2023, Werner Keil and others by the @author tag.
2+
* Copyright (c) 2012, 2024, Werner Keil and others by the @author tag.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of
@@ -86,7 +86,7 @@ public URLConnectionResourceCache() {
8686
* (non-Javadoc)
8787
*
8888
* @see
89-
* org.javamoney.moneta.loader.format.ResourceCache#write(java.lang.String
89+
* org.javamoney.moneta.spi.loader.ResourceCache#write(java.lang.String
9090
* , byte[])
9191
*/
9292
@Override
@@ -109,7 +109,7 @@ public void write(String resourceId, byte[] data) {
109109
* (non-Javadoc)
110110
*
111111
* @see
112-
* org.javamoney.moneta.loader.format.ResourceCache#isCached(java.lang
112+
* org.javamoney.moneta.spi.loader.ResourceCache#isCached(java.lang
113113
* .String)
114114
*/
115115
@Override
@@ -121,7 +121,7 @@ public boolean isCached(String resourceId) {
121121
* (non-Javadoc)
122122
*
123123
* @see
124-
* org.javamoney.moneta.loader.format.ResourceCache#read(java.lang.String)
124+
* org.javamoney.moneta.spi.loader.ResourceCache#read(java.lang.String)
125125
*/
126126
@Override
127127
public byte[] read(String resourceId) {
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright (c) 2012, 2023, Werner Keil and others by the @author tag.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.javamoney.moneta.spi.loader.okhttp;
17+
18+
import org.javamoney.moneta.spi.loader.LoadDataInformation;
19+
import org.javamoney.moneta.spi.loader.LoadDataInformationBuilder;
20+
import org.javamoney.moneta.spi.loader.LoaderService.LoaderListener;
21+
import org.javamoney.moneta.spi.loader.LoaderService.UpdatePolicy;
22+
import org.testng.annotations.BeforeMethod;
23+
import org.testng.annotations.Test;
24+
25+
import java.net.URI;
26+
import java.net.URISyntaxException;
27+
import java.util.Collections;
28+
import java.util.Map;
29+
30+
import static org.testng.Assert.assertNotNull;
31+
32+
public class LoadableHttpResourceBuilderTest {
33+
34+
private LoadDataInformation loadInformation;
35+
36+
@BeforeMethod
37+
public void setup() throws URISyntaxException {
38+
String resourceId = "resourceId";
39+
UpdatePolicy updatePolicy = UpdatePolicy.LAZY;
40+
Map<String, String> properties = Collections.emptyMap();
41+
LoaderListener loaderListener = (id, is) -> {};
42+
URI backupResource = new URI("localhost");
43+
URI[] resourceLocations = new URI[]{new URI("localhost")};
44+
45+
loadInformation = new LoadDataInformationBuilder()
46+
.withResourceId(resourceId)
47+
.withUpdatePolicy(updatePolicy)
48+
.withProperties(properties)
49+
.withLoaderListener(loaderListener)
50+
.withBackupResource(backupResource)
51+
.withResourceLocations(resourceLocations)
52+
.build();
53+
54+
}
55+
56+
@Test
57+
public void shouldCreateLoadableResource() {
58+
LoadableHttpResource resource = new LoadableHttpResourceBuilder()
59+
.withCache(new OkHttpResourceCache())
60+
.withLoadDataInformation(loadInformation).build();
61+
assertNotNull(resource);
62+
}
63+
64+
@Test(expectedExceptions = IllegalStateException.class)
65+
public void shouldReturnErrorWhenResourceCacheWasNotInformed() {
66+
new LoadableHttpResourceBuilder()
67+
.withLoadDataInformation(loadInformation).build();
68+
}
69+
70+
@Test(expectedExceptions = IllegalStateException.class)
71+
public void shouldReturnErrorWhenLoadDataInformationWasNotInformed() {
72+
new LoadableHttpResourceBuilder()
73+
.withLoadDataInformation(loadInformation).build();
74+
}
75+
}

moneta-core/src/test/java/org/javamoney/moneta/spi/loader/urlconnection/LoadableResourceBuilderTest.java renamed to moneta-core/src/test/java/org/javamoney/moneta/spi/loader/urlconnection/LoadableURLResourceBuilderTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.testng.annotations.BeforeMethod;
3030
import org.testng.annotations.Test;
3131

32-
public class LoadableResourceBuilderTest {
32+
public class LoadableURLResourceBuilderTest {
3333

3434
private LoadDataInformation loadInformation;
3535

@@ -62,13 +62,13 @@ public void shouldCreateLoadableResource() {
6262
}
6363

6464
@Test(expectedExceptions = IllegalStateException.class)
65-
public void shouldReturnErrorWhendResourceCacheWasNotInformed() {
65+
public void shouldReturnErrorWhenResourceCacheWasNotInformed() {
6666
new LoadableURLResourceBuilder()
6767
.withLoadDataInformation(loadInformation).build();
6868
}
6969

7070
@Test(expectedExceptions = IllegalStateException.class)
71-
public void shouldReturnErrorWhendLoadDataInformationWasNotInformed() {
71+
public void shouldReturnErrorWhenLoadDataInformationWasNotInformed() {
7272
new LoadableURLResourceBuilder()
7373
.withLoadDataInformation(loadInformation).build();
7474
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<basedir>.</basedir>
5050

5151
<!-- dependency versions -->
52+
<okhttp.version>4.12.0</okhttp.version>
5253
<testng.version>7.7.1</testng.version>
5354
<additionalparam>-Xdoclint:none</additionalparam>
5455

0 commit comments

Comments
 (0)