-
Notifications
You must be signed in to change notification settings - Fork 132
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
Jared Koester
committed
Feb 21, 2023
1 parent
3b33898
commit a1159a0
Showing
6 changed files
with
171 additions
and
10 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,21 @@ | |
|
||
import static org.junit.Assert.*; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.onebusaway.container.refresh.RefreshService; | ||
import org.onebusaway.util.rest.RestApiLibrary; | ||
import org.onebusaway.util.services.configuration.ConfigurationServiceClient; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ConfigurationServiceImplTest { | ||
|
||
|
@@ -67,6 +73,67 @@ public void testGetConfigurationFlagForAgency() throws Exception { | |
|
||
hideScheduleInfo = service.getConfigurationFlagForAgency("1", "hideScheduleInfo"); | ||
assertEquals("expected true", true, hideScheduleInfo); | ||
|
||
} | ||
|
||
@Test | ||
public void testMergeConfig(){ | ||
HashMap<String, Object> old = new HashMap<>(); | ||
ArrayList<HashMap> items = new ArrayList<>(); | ||
HashMap<String, String> item1 = new HashMap<>(); | ||
item1.put("component", "admin"); | ||
item1.put("key", "test"); | ||
item1.put("value","hello World"); | ||
items.add(item1); | ||
old.put("config", items); | ||
|
||
} | ||
|
||
@Test | ||
public void testWriteConfig(){ | ||
|
||
// ConfigFileStructure cfs = new ConfigFileStructure(); | ||
// cfs.oba = new HashMap<String, String>(); | ||
// cfs.oba.put("env", "jared"); | ||
// cfs.config = new ArrayList<ConfigItem>(Arrays.asList(new ConfigItem("testing","jared","hello world!"))); | ||
|
||
|
||
try { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
ConfigFileStructure cfs = mapper.readValue(new File("/opt/nyc/oba/config.json"), ConfigFileStructure.class); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
String output = mapper.writeValueAsString(cfs); | ||
System.out.println(output); | ||
String pretty = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(cfs); | ||
System.out.println(pretty); | ||
mapper.writerWithDefaultPrettyPrinter().writeValue(new File("/Users/jkoester/Desktop/configOutput.json"), cfs); | ||
This comment has been minimized.
Sorry, something went wrong.
aaronbrethorst
Member
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
throw new RuntimeException(e); | ||
} | ||
|
||
} | ||
|
||
@Test | ||
public void testReadConfig(){ | ||
ObjectMapper mapper = new ObjectMapper(); | ||
try { | ||
|
||
String jsonString = "{\"oba\":{\"env\":\"jared\"},\"config\":[{\"component\":\"testing\",\"key\":\"jared\",\"value\":\"hello world!\"}]}"; | ||
ConfigFileStructure cfs = mapper.readValue(new File("/opt/nyc/oba/config.json"), ConfigFileStructure.class); | ||
|
||
|
||
// compact print | ||
System.out.println(cfs); | ||
|
||
// pretty print | ||
String prettyFile = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(cfs); | ||
|
||
System.out.println(prettyFile); | ||
|
||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void addToSettings(ArrayList settings, String component, String key, String value) { | ||
|
@@ -78,4 +145,23 @@ private void addToSettings(ArrayList settings, String component, String key, Str | |
settings.add(kv1); | ||
} | ||
|
||
private static class ConfigItem{ | ||
public String component; | ||
public String key; | ||
public String value; | ||
|
||
public ConfigItem(String c, String k, String v){ | ||
this.component = c; | ||
this.key = k; | ||
this.value = v; | ||
} | ||
public ConfigItem(){ | ||
|
||
} | ||
} | ||
private static class ConfigFileStructure{ | ||
public HashMap<String, String> oba; | ||
public ArrayList<ConfigItem> config; | ||
} | ||
|
||
} |
this breaks running tests.