@BeforeClass public static void setUp() throws Exception { layoutMapper = new LayoutMapper(); YamlMapFactoryBean yamlMapFactoryBean = new YamlMapFactoryBean(); yamlMapFactoryBean.setResources(new FileSystemResource(LayoutMapperTest.class.getResource("layout.yml").getPath())); // String layout = "" + // "category:\n" + // " _default_: \"category/_layout\"\n" + // "food:\n" + // " detail: \"food/_layout\"\n" + // "boo:\n" + // " _default_: \"boo/_layout\"\n" + // " index: \"_boo\"\n" + // " foo:\n" + // " detail: \"boo/_detail\"" + // ""; // yamlMapFactoryBean.setResources(new ByteArrayResource(layout.getBytes("UTF-8"))); yamlMapFactoryBean.afterPropertiesSet(); ReflectionTestUtils.setField(layoutMapper, "layout", yamlMapFactoryBean.getObject()); ReflectionTestUtils.invokeMethod(layoutMapper, "init"); }
@SuppressWarnings("unchecked") public static IBMMQConfigurationProperties getIBMMQProperties() throws Exception { YamlMapFactoryBean factoryBean = new YamlMapFactoryBean(); factoryBean.setResources(new ClassPathResource("application.yml")); Map<String, Object> mapObject = factoryBean.getObject(); Map<String, Object> ibmMQPropertyMap = (Map<String, Object>) mapObject .get("ibmmq"); IBMMQConfigurationProperties configurationProperties = new IBMMQConfigurationProperties(); configurationProperties.setHost((String) ibmMQPropertyMap.get("host")); configurationProperties.setPort((Integer) ibmMQPropertyMap.get("port")); configurationProperties .setUsername((String) ibmMQPropertyMap.get("username")); configurationProperties .setPassword((String) ibmMQPropertyMap.get("password")); configurationProperties .setQueueManager((String) ibmMQPropertyMap.get("queueManager")); configurationProperties .setChannel((String) ibmMQPropertyMap.get("channel")); return configurationProperties; }
public static Map<String, Object> convertYamlToMap(String yamlFile) { YamlMapFactoryBean yamlMapFactoryBean = new YamlMapFactoryBean(); yamlMapFactoryBean.setResources(new ClassPathResource(yamlFile)); yamlMapFactoryBean.setResolutionMethod(ResolutionMethod.FIRST_FOUND); return yamlMapFactoryBean.getObject(); }
@SuppressWarnings("unchecked") public Config() { YamlMapFactoryBean yamlMapFactoryBean = new YamlMapFactoryBean(); yamlMapFactoryBean.setResources(new ClassPathResource("config.yml")); this.dataMap = (Map<String, Object>) yamlMapFactoryBean.getObject().get("config"); this.consulMap = (Map<String, Object>) this.dataMap.get("consul"); this.repoMap = (Map<String, Object>) this.dataMap.get("repo"); }