Search in sources :

Example 1 with PropertiesFactory

use of com.ctrip.framework.apollo.util.factory.PropertiesFactory in project apollo by ctripcorp.

the class DefaultConfigTest method setUp.

@Before
public void setUp() throws Exception {
    MockInjector.setInstance(ConfigUtil.class, new MockConfigUtil());
    propertiesFactory = mock(PropertiesFactory.class);
    when(propertiesFactory.getPropertiesInstance()).thenAnswer(new Answer<Properties>() {

        @Override
        public Properties answer(InvocationOnMock invocation) {
            return new Properties();
        }
    });
    MockInjector.setInstance(PropertiesFactory.class, propertiesFactory);
    someResourceDir = new File(ClassLoaderUtil.getClassPath() + "/META-INF/config");
    someResourceDir.mkdirs();
    someNamespace = "someName";
    configRepository = mock(ConfigRepository.class);
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) PropertiesFactory(com.ctrip.framework.apollo.util.factory.PropertiesFactory) OrderedProperties(com.ctrip.framework.apollo.util.OrderedProperties) Properties(java.util.Properties) File(java.io.File) Before(org.junit.Before)

Example 2 with PropertiesFactory

use of com.ctrip.framework.apollo.util.factory.PropertiesFactory in project apollo by ctripcorp.

the class LocalFileConfigRepositoryTest method setUp.

@Before
public void setUp() throws Exception {
    someBaseDir = new File("src/test/resources/config-cache");
    someBaseDir.mkdir();
    someNamespace = "someName";
    someProperties = new Properties();
    defaultKey = "defaultKey";
    defaultValue = "defaultValue";
    someProperties.setProperty(defaultKey, defaultValue);
    someSourceType = ConfigSourceType.REMOTE;
    upstreamRepo = mock(ConfigRepository.class);
    when(upstreamRepo.getConfig()).thenReturn(someProperties);
    when(upstreamRepo.getSourceType()).thenReturn(someSourceType);
    MockInjector.setInstance(ConfigUtil.class, new MockConfigUtil());
    PropertiesFactory propertiesFactory = mock(PropertiesFactory.class);
    when(propertiesFactory.getPropertiesInstance()).thenAnswer(new Answer<Properties>() {

        @Override
        public Properties answer(InvocationOnMock invocation) {
            return new Properties();
        }
    });
    MockInjector.setInstance(PropertiesFactory.class, propertiesFactory);
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) PropertiesFactory(com.ctrip.framework.apollo.util.factory.PropertiesFactory) Properties(java.util.Properties) File(java.io.File) Before(org.junit.Before)

Example 3 with PropertiesFactory

use of com.ctrip.framework.apollo.util.factory.PropertiesFactory in project apollo by ctripcorp.

the class YamlParserTest method testOrderProperties.

@Test
public void testOrderProperties() throws IOException {
    String yamlContent = loadYaml("orderedcase.yaml");
    Properties nonOrderedProperties = parser.yamlToProperties(yamlContent);
    PropertiesFactory propertiesFactory = mock(PropertiesFactory.class);
    when(propertiesFactory.getPropertiesInstance()).thenAnswer(new Answer<Properties>() {

        @Override
        public Properties answer(InvocationOnMock invocation) {
            return new OrderedProperties();
        }
    });
    MockInjector.setInstance(PropertiesFactory.class, propertiesFactory);
    parser = new YamlParser();
    Properties orderedProperties = parser.yamlToProperties(yamlContent);
    assertTrue(orderedProperties instanceof OrderedProperties);
    checkPropertiesEquals(nonOrderedProperties, orderedProperties);
    String[] propertyNames = orderedProperties.stringPropertyNames().toArray(new String[0]);
    assertEquals("k2", propertyNames[0]);
    assertEquals("k4", propertyNames[1]);
    assertEquals("k1", propertyNames[2]);
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) PropertiesFactory(com.ctrip.framework.apollo.util.factory.PropertiesFactory) OrderedProperties(com.ctrip.framework.apollo.util.OrderedProperties) Properties(java.util.Properties) OrderedProperties(com.ctrip.framework.apollo.util.OrderedProperties) Test(org.junit.Test)

Aggregations

PropertiesFactory (com.ctrip.framework.apollo.util.factory.PropertiesFactory)3 Properties (java.util.Properties)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 OrderedProperties (com.ctrip.framework.apollo.util.OrderedProperties)2 File (java.io.File)2 Before (org.junit.Before)2 Test (org.junit.Test)1