summaryrefslogtreecommitdiffstats
path: root/config-application-package/src/test/java/com/yahoo/config/model/application/provider/PreGeneratedFileRegistryTestCase.java
blob: 19e288e30f5e568ddbf4eafe7a3748c18c8eb85e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model.application.provider;

import com.yahoo.config.application.api.FileRegistry;
import org.junit.Test;

import java.io.StringReader;
import java.util.Arrays;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * @author tonytv
 */
public class PreGeneratedFileRegistryTestCase {
    @Test
    public void importAndExport() {
        FileRegistry fileRegistry = new MockFileRegistry();
        String serializedRegistry = PreGeneratedFileRegistry.exportRegistry(fileRegistry);

        PreGeneratedFileRegistry importedRegistry =
                PreGeneratedFileRegistry.importRegistry(
                        new StringReader(serializedRegistry));

        assertTrue(importedRegistry.getPaths().containsAll(
                Arrays.asList(
                        MockFileRegistry.entry1.relativePath,
                        MockFileRegistry.entry2.relativePath)));

        assertEquals(2, importedRegistry.getPaths().size());

        checkConsistentEntry(MockFileRegistry.entry1, importedRegistry);
        checkConsistentEntry(MockFileRegistry.entry2, importedRegistry);

        assertEquals(fileRegistry.fileSourceHost(),
                importedRegistry.fileSourceHost());
    }

    void checkConsistentEntry(FileRegistry.Entry entry, FileRegistry registry) {
        assertEquals(entry.reference, registry.addFile(entry.relativePath));
    }
}