|
| 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 | +} |
0 commit comments