|
| 1 | +/* |
| 2 | + * Copyright 2023 Inrupt Inc. |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + * of this software and associated documentation files (the "Software"), to deal in |
| 6 | + * the Software without restriction, including without limitation the rights to use, |
| 7 | + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 8 | + * Software, and to permit persons to whom the Software is furnished to do so, |
| 9 | + * subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in |
| 12 | + * all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 15 | + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
| 16 | + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 17 | + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 18 | + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 19 | + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | + */ |
| 21 | +package com.inrupt.client.webid; |
| 22 | + |
| 23 | +import static org.junit.jupiter.api.Assertions.*; |
| 24 | + |
| 25 | +import com.inrupt.client.solid.SolidSyncClient; |
| 26 | + |
| 27 | +import java.net.URI; |
| 28 | + |
| 29 | +import org.junit.jupiter.api.AfterAll; |
| 30 | +import org.junit.jupiter.api.BeforeAll; |
| 31 | +import org.junit.jupiter.api.Test; |
| 32 | + |
| 33 | +class WebIdProfileTest { |
| 34 | + |
| 35 | + private static final URI AGENT = URI.create("http://xmlns.test/foaf/0.1/Agent"); |
| 36 | + private static final URI SEE_ALSO = URI.create("https://storage.example.test/storage-id/extendedProfile"); |
| 37 | + private static final URI ISSUER = URI.create("https://login.example.test"); |
| 38 | + private static final URI STORAGE = URI.create("https://storage.example.test/storage-id/"); |
| 39 | + |
| 40 | + private static final WebIdMockHttpService mockHttpServer = new WebIdMockHttpService(); |
| 41 | + private static final SolidSyncClient client = SolidSyncClient.getClient(); |
| 42 | + private static String baseUrl; |
| 43 | + |
| 44 | + @BeforeAll |
| 45 | + static void setup() { |
| 46 | + baseUrl = mockHttpServer.start(); |
| 47 | + } |
| 48 | + |
| 49 | + @AfterAll |
| 50 | + static void teardown() { |
| 51 | + mockHttpServer.stop(); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void testGetProfileSlash() { |
| 56 | + final URI uri = URI.create(baseUrl + "/webId"); |
| 57 | + try (final WebIdProfile profile = client.read(uri, WebIdProfile.class)) { |
| 58 | + assertEquals(uri, profile.getIdentifier()); |
| 59 | + assertTrue(profile.getTypes().contains(AGENT)); |
| 60 | + assertTrue(profile.getRelatedResources().contains(SEE_ALSO)); |
| 61 | + assertTrue(profile.getOidcIssuers().contains(ISSUER)); |
| 62 | + assertTrue(profile.getStorages().contains(STORAGE)); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + @SuppressWarnings("deprecation") |
| 68 | + void testGetProfileSlashDeprecatedMethods() { |
| 69 | + final URI uri = URI.create(baseUrl + "/webId"); |
| 70 | + try (final WebIdProfile profile = client.read(uri, WebIdProfile.class)) { |
| 71 | + assertEquals(uri, profile.getIdentifier()); |
| 72 | + assertTrue(profile.getType().contains(AGENT)); |
| 73 | + assertTrue(profile.getSeeAlso().contains(SEE_ALSO)); |
| 74 | + assertTrue(profile.getOidcIssuer().contains(ISSUER)); |
| 75 | + assertTrue(profile.getStorage().contains(STORAGE)); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + void testGetProfileHash() { |
| 81 | + final URI uri = URI.create(baseUrl + "/webIdHash#me"); |
| 82 | + try (final WebIdProfile profile = client.read(uri, WebIdProfile.class)) { |
| 83 | + assertEquals(uri, profile.getIdentifier()); |
| 84 | + assertTrue(profile.getTypes().contains(AGENT)); |
| 85 | + assertTrue(profile.getRelatedResources().contains(SEE_ALSO)); |
| 86 | + assertTrue(profile.getOidcIssuers().contains(ISSUER)); |
| 87 | + assertTrue(profile.getStorages().contains(STORAGE)); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments