-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
131 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,24 @@ | ||
| package edu.group5.app; | ||
|
|
||
| import java.util.HashMap; | ||
|
|
||
| import edu.group5.app.control.OrgAPIWrapper; | ||
| import tools.jackson.core.type.TypeReference; | ||
| import tools.jackson.databind.ObjectMapper; | ||
|
|
||
| /** | ||
| * Hello world! | ||
| */ | ||
| public class App { | ||
| public static void main(String[] args) { | ||
| public static void main(String[] args) throws InterruptedException { | ||
| OrgAPIWrapper orgWrap = new OrgAPIWrapper("https://app.innsamlingskontrollen.no/api/public/v1/all"); | ||
| System.out.println(); | ||
| System.out.println(); | ||
| orgWrap.importData(); | ||
| Object[] imports = orgWrap.getData(); | ||
| ObjectMapper objectMapper = new ObjectMapper(); | ||
| HashMap<String, Object> map = objectMapper.convertValue(imports[0], new TypeReference<HashMap<String, Object>>() { | ||
| }); | ||
| System.out.println(map.get("org_number")); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/test/java/edu/group5/app/control/OrgAPIWrapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package edu.group5.app.control; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import tools.jackson.core.exc.StreamReadException; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.lang.IllegalArgumentException; | ||
|
|
||
| public class OrgAPIWrapperTest { | ||
| String testURL; | ||
| String wrongURL; | ||
| String wrongURL2; | ||
|
|
||
| @BeforeEach | ||
| void init() { | ||
| this.testURL = "https://app.innsamlingskontrollen.no/api/public/v1/all"; | ||
| this.wrongURL = "This is not a URL"; | ||
| this.wrongURL2 = "https://www.google.com"; | ||
| } | ||
|
|
||
| @Test | ||
| public void nullURLThrowsException() { | ||
| IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, | ||
| () -> new OrgAPIWrapper(null)); | ||
| assertEquals("url can't be null", exception.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| public void emptyURLThrowsException() { | ||
| IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new OrgAPIWrapper("")); | ||
| assertEquals("url can't be blank", exception.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| public void faultyURLThrowsException() { | ||
| IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, | ||
| () -> new OrgAPIWrapper(this.wrongURL)); | ||
| assertEquals("url has to be valid", exception.getMessage()); | ||
| } | ||
|
|
||
| // @Test | ||
| // public void noConnectionReturnsFalseImport() { | ||
| // assertDoesNotThrow(() -> { | ||
| // OrgAPIWrapper api = new OrgAPIWrapper(this.testURL); | ||
| // assertFalse(api.importData()); | ||
| // }); | ||
| // } | ||
|
|
||
| @Test | ||
| public void importsNonEmptyData() { | ||
| assertDoesNotThrow(() -> { | ||
| OrgAPIWrapper api = new OrgAPIWrapper(testURL); | ||
| assertTrue(api.importData()); | ||
| assertFalse(api.getData().length == 0); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void nonParseableSiteThrowsExceptionWhenImporting() { | ||
| assertDoesNotThrow(() -> { | ||
| OrgAPIWrapper api = new OrgAPIWrapper(this.wrongURL2); | ||
| StreamReadException exception = assertThrows(StreamReadException.class, () -> api.importData()); | ||
| assertEquals("The URL leads to a website that can't be parsed", exception.getMessage()); | ||
| }); | ||
| } | ||
|
|
||
| } |