|
23 | 23 | import java.io.BufferedReader;
|
24 | 24 | import java.io.FileInputStream;
|
25 | 25 | import java.io.FileNotFoundException;
|
| 26 | +import java.io.FileOutputStream; |
26 | 27 | import java.io.InputStreamReader;
|
| 28 | +import java.nio.charset.StandardCharsets; |
27 | 29 | import java.util.Date;
|
| 30 | +import org.json.JSONObject; |
28 | 31 | import org.junit.Before;
|
29 | 32 | import org.junit.Test;
|
30 | 33 | import org.junit.runner.RunWith;
|
@@ -82,6 +85,36 @@ public void read_validContainer_returnsContainer() throws Exception {
|
82 | 85 | assertThat(container).isEqualTo(configContainer);
|
83 | 86 | }
|
84 | 87 |
|
| 88 | + @Test |
| 89 | + public void read_validContainerWithPersonalization_returnsContainer() throws Exception { |
| 90 | + ConfigContainer configWithPersonalization = |
| 91 | + ConfigContainer.newBuilder(configContainer) |
| 92 | + .withPersonalizationMetadata( |
| 93 | + new JSONObject(ImmutableMap.of(Personalization.ARM_KEY, "arm_value"))) |
| 94 | + .build(); |
| 95 | + storageClient.write(configWithPersonalization); |
| 96 | + Preconditions.checkArgument(getFileAsString().equals(configWithPersonalization.toString())); |
| 97 | + |
| 98 | + ConfigContainer container = storageClient.read(); |
| 99 | + assertThat(container).isEqualTo(configWithPersonalization); |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + public void read_validContainerWithoutPersonalization_returnsContainer() throws Exception { |
| 104 | + // Configs written by SDK versions <20.0.1 do not contain personalization metadata. |
| 105 | + // Since the serialized configContainer contains personalization metadata, we manually remove it |
| 106 | + // and write the config to disk directly to test. |
| 107 | + JSONObject configJSON = new JSONObject(configContainer.toString()); |
| 108 | + configJSON.remove(ConfigContainer.PERSONALIZATION_METADATA_KEY); |
| 109 | + |
| 110 | + try (FileOutputStream outputStream = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE)) { |
| 111 | + outputStream.write(configJSON.toString().getBytes(StandardCharsets.UTF_8)); |
| 112 | + } |
| 113 | + |
| 114 | + ConfigContainer container = storageClient.read(); |
| 115 | + assertThat(container).isEqualTo(configContainer); |
| 116 | + } |
| 117 | + |
85 | 118 | @Test
|
86 | 119 | public void read_emptyFile_returnsNull() throws Exception {
|
87 | 120 | ConfigContainer container = storageClient.read();
|
|
0 commit comments