Bring back YamlParserTest (#227)
diff --git a/dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/governance/util/UrlUtilsTest.java b/dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/common/util/UrlUtilsTest.java
similarity index 96%
rename from dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/governance/util/UrlUtilsTest.java
rename to dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/common/util/UrlUtilsTest.java
index faf4bd7..5250c17 100644
--- a/dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/governance/util/UrlUtilsTest.java
+++ b/dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/common/util/UrlUtilsTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.admin.governance.util;
+package org.apache.dubbo.admin.common.util;
import org.apache.dubbo.admin.common.util.UrlUtils;
import org.junit.Assert;
diff --git a/dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/common/util/YamlParserTest.java b/dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/common/util/YamlParserTest.java
new file mode 100644
index 0000000..9e36350
--- /dev/null
+++ b/dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/common/util/YamlParserTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dubbo.admin.common.util;
+
+import org.apache.dubbo.admin.model.dto.DynamicConfigDTO;
+import org.apache.dubbo.admin.model.store.OverrideConfig;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+public class YamlParserTest {
+
+ private String streamToString(InputStream stream) throws IOException {
+ byte[] bytes = new byte[stream.available()];
+ stream.read(bytes);
+ return new String(bytes);
+ }
+
+ @Test
+ public void parseLoadBalanceTest() throws IOException {
+ try (InputStream yamlStream = this.getClass().getResourceAsStream("/LoadBalance.yml")) {
+ DynamicConfigDTO overrideDTO = YamlParser.loadObject(streamToString(yamlStream), DynamicConfigDTO.class);
+ assertEquals("v2.7", overrideDTO.getConfigVersion());
+ assertEquals(false, overrideDTO.isEnabled());
+ List<OverrideConfig> configs = overrideDTO.getConfigs();
+ assertEquals(2, configs.size());
+
+ OverrideConfig first = configs.get(0);
+ assertEquals("0.0.0.0:20880", first.getAddresses().get(0));
+ assertEquals("provider", first.getSide());
+ Map<String, Object> parameters = first.getParameters();
+ assertEquals(1, parameters.size());
+ assertEquals(2000, parameters.get("timeout"));
+
+ OverrideConfig second = configs.get(1);
+ assertEquals("balancing", second.getType());
+ assertEquals(true, second.isEnabled());
+ parameters = second.getParameters();
+ assertEquals(2, parameters.size());
+ assertEquals("*", parameters.get("method"));
+ assertEquals("random", parameters.get("strategy"));
+ }
+ }
+
+
+}
diff --git a/dubbo-admin-backend/src/test/main/java/org/apache/dubbo/admin/common/util/YamlParserTest.java b/dubbo-admin-backend/src/test/main/java/org/apache/dubbo/admin/common/util/YamlParserTest.java
deleted file mode 100644
index 80604d7..0000000
--- a/dubbo-admin-backend/src/test/main/java/org/apache/dubbo/admin/common/util/YamlParserTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.dubbo.admin.common.util;
-
-import org.apache.dubbo.admin.model.dto.DynamicConfigDTO;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-public class YamlParserTest {
-
- private String streamToString(InputStream stream) {
- try {
- byte[] bytes = new byte[stream.available()];
- stream.read(bytes);
- return new String(bytes);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- @Test
- public void parseLoadBalanceTest() {
- InputStream yamlStream = this.getClass().getResourceAsStream("/LoadBalance.yml");
- DynamicConfigDTO overrideDTO = YamlParser.loadObject(streamToString(yamlStream), DynamicConfigDTO.class);
- if ("weight".equals(null)) {
- System.out.println("aa");
- }
- overrideDTO.getConfigs();
- }
-
-
-}
diff --git a/dubbo-admin-backend/src/test/main/resources/LoadBalance.yml b/dubbo-admin-backend/src/test/resources/LoadBalance.yml
similarity index 77%
rename from dubbo-admin-backend/src/test/main/resources/LoadBalance.yml
rename to dubbo-admin-backend/src/test/resources/LoadBalance.yml
index bbf1742..2220097 100644
--- a/dubbo-admin-backend/src/test/main/resources/LoadBalance.yml
+++ b/dubbo-admin-backend/src/test/resources/LoadBalance.yml
@@ -1,7 +1,5 @@
---
-apiVersion: v2.7
-scope: application
-key: governance-consumer
+configVersion: v2.7
enabled: false
configs:
- addresses: ["0.0.0.0:20880"]