Skip to content

Commit ad26a69

Browse files
authored
optimize AbstractConfigTest (#13243)
* optimize AbstractConfigTest * Remove duplicate test in AbstractConfigTest * add prop based on system's prop in test
1 parent be15772 commit ad26a69

File tree

1 file changed

+54
-155
lines changed

1 file changed

+54
-155
lines changed

dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractConfigTest.java

Lines changed: 54 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -61,70 +61,6 @@ public void afterEach() {
6161
SysProps.clear();
6262
}
6363

64-
//FIXME
65-
/*@Test
66-
public void testAppendProperties1() throws Exception {
67-
try {
68-
System.setProperty("dubbo.properties.i", "1");
69-
System.setProperty("dubbo.properties.c", "c");
70-
System.setProperty("dubbo.properties.b", "2");
71-
System.setProperty("dubbo.properties.d", "3");
72-
System.setProperty("dubbo.properties.f", "4");
73-
System.setProperty("dubbo.properties.l", "5");
74-
System.setProperty("dubbo.properties.s", "6");
75-
System.setProperty("dubbo.properties.str", "dubbo");
76-
System.setProperty("dubbo.properties.bool", "true");
77-
PropertiesConfig config = new PropertiesConfig();
78-
AbstractConfig.appendProperties(config);
79-
Assertions.assertEquals(1, config.getI());
80-
Assertions.assertEquals('c', config.getC());
81-
Assertions.assertEquals((byte) 0x02, config.getB());
82-
Assertions.assertEquals(3d, config.getD());
83-
Assertions.assertEquals(4f, config.getF());
84-
Assertions.assertEquals(5L, config.getL());
85-
Assertions.assertEquals(6, config.getS());
86-
Assertions.assertEquals("dubbo", config.getStr());
87-
Assertions.assertTrue(config.isBool());
88-
} finally {
89-
System.clearProperty("dubbo.properties.i");
90-
System.clearProperty("dubbo.properties.c");
91-
System.clearProperty("dubbo.properties.b");
92-
System.clearProperty("dubbo.properties.d");
93-
System.clearProperty("dubbo.properties.f");
94-
System.clearProperty("dubbo.properties.l");
95-
System.clearProperty("dubbo.properties.s");
96-
System.clearProperty("dubbo.properties.str");
97-
System.clearProperty("dubbo.properties.bool");
98-
}
99-
}
100-
101-
@Test
102-
void testAppendProperties2() throws Exception {
103-
try {
104-
System.setProperty("dubbo.properties.two.i", "2");
105-
PropertiesConfig config = new PropertiesConfig("two");
106-
AbstractConfig.appendProperties(config);
107-
Assertions.assertEquals(2, config.getI());
108-
} finally {
109-
System.clearProperty("dubbo.properties.two.i");
110-
}
111-
}
112-
113-
@Test
114-
void testAppendProperties3() throws Exception {
115-
try {
116-
Properties p = new Properties();
117-
p.put("dubbo.properties.str", "dubbo");
118-
ConfigUtils.setProperties(p);
119-
PropertiesConfig config = new PropertiesConfig();
120-
AbstractConfig.appendProperties(config);
121-
Assertions.assertEquals("dubbo", config.getStr());
122-
} finally {
123-
System.clearProperty(Constants.DUBBO_PROPERTIES_KEY);
124-
ConfigUtils.setProperties(null);
125-
}
126-
}*/
127-
12864
@Test
12965
void testValidateProtocolConfig() {
13066
ProtocolConfig protocolConfig = new ProtocolConfig();
@@ -798,97 +734,6 @@ public void setParameters(Map<String, String> parameters) {
798734
}
799735
}
800736

801-
private static class PropertiesConfig extends AbstractConfig {
802-
private char c;
803-
private boolean bool;
804-
private byte b;
805-
private int i;
806-
private long l;
807-
private float f;
808-
private double d;
809-
private short s;
810-
private String str;
811-
812-
PropertiesConfig() {
813-
}
814-
815-
PropertiesConfig(String id) {
816-
this.setId(id);
817-
}
818-
819-
public char getC() {
820-
return c;
821-
}
822-
823-
public void setC(char c) {
824-
this.c = c;
825-
}
826-
827-
public boolean isBool() {
828-
return bool;
829-
}
830-
831-
public void setBool(boolean bool) {
832-
this.bool = bool;
833-
}
834-
835-
public byte getB() {
836-
return b;
837-
}
838-
839-
public void setB(byte b) {
840-
this.b = b;
841-
}
842-
843-
public int getI() {
844-
return i;
845-
}
846-
847-
public void setI(int i) {
848-
this.i = i;
849-
}
850-
851-
public long getL() {
852-
return l;
853-
}
854-
855-
public void setL(long l) {
856-
this.l = l;
857-
}
858-
859-
public float getF() {
860-
return f;
861-
}
862-
863-
public void setF(float f) {
864-
this.f = f;
865-
}
866-
867-
public double getD() {
868-
return d;
869-
}
870-
871-
public void setD(double d) {
872-
this.d = d;
873-
}
874-
875-
public String getStr() {
876-
return str;
877-
}
878-
879-
public void setStr(String str) {
880-
this.str = str;
881-
}
882-
883-
public short getS() {
884-
return s;
885-
}
886-
887-
public void setS(short s) {
888-
this.s = s;
889-
}
890-
}
891-
892737
private static class ParameterConfig {
893738
private int number;
894739
private String name;
@@ -1052,12 +897,66 @@ void testRefreshNested() {
1052897
}
1053898
}
1054899

900+
@Test
901+
void testRefreshNestedWithId() {
902+
try {
903+
System.setProperty("dubbo.outers.test.a1", "1");
904+
System.setProperty("dubbo.outers.test.b.b1", "11");
905+
System.setProperty("dubbo.outers.test.b.b2", "12");
906+
907+
ApplicationModel.defaultModel().modelEnvironment().initialize();
908+
909+
OuterConfig outerConfig = new OuterConfig("test");
910+
outerConfig.refresh();
911+
912+
Assertions.assertEquals(1, outerConfig.getA1());
913+
Assertions.assertEquals(11, outerConfig.getB().getB1());
914+
Assertions.assertEquals(12, outerConfig.getB().getB2());
915+
} finally {
916+
ApplicationModel.defaultModel().modelEnvironment().destroy();
917+
System.clearProperty("dubbo.outers.test.a1");
918+
System.clearProperty("dubbo.outers.test.b.b1");
919+
System.clearProperty("dubbo.outers.test.b.b2");
920+
}
921+
}
922+
923+
@Test
924+
void testRefreshNestedBySystemProperties() {
925+
try {
926+
Properties p = System.getProperties();
927+
p.put("dubbo.outer.a1", "1");
928+
p.put("dubbo.outer.b.b1", "11");
929+
p.put("dubbo.outer.b.b2", "12");
930+
931+
ApplicationModel.defaultModel().modelEnvironment().initialize();
932+
933+
OuterConfig outerConfig = new OuterConfig();
934+
outerConfig.refresh();
935+
936+
Assertions.assertEquals(1, outerConfig.getA1());
937+
Assertions.assertEquals(11, outerConfig.getB().getB1());
938+
Assertions.assertEquals(12, outerConfig.getB().getB2());
939+
} finally {
940+
ApplicationModel.defaultModel().modelEnvironment().destroy();
941+
System.clearProperty("dubbo.outer.a1");
942+
System.clearProperty("dubbo.outer.b.b1");
943+
System.clearProperty("dubbo.outer.b.b2");
944+
}
945+
}
946+
1055947
private static class OuterConfig extends AbstractConfig {
1056948
private Integer a1;
1057949

1058950
@Nested
1059951
private InnerConfig b;
1060952

953+
OuterConfig() {
954+
}
955+
956+
OuterConfig(String id) {
957+
this.setId(id);
958+
}
959+
1061960
public Integer getA1() {
1062961
return a1;
1063962
}

0 commit comments

Comments
 (0)