Skip to content

Commit 9ff8193

Browse files
authored
BIGTOP-4350: Add some unit tests for stack infra module (#169)
1 parent 7a2ba19 commit 9ff8193

File tree

7 files changed

+454
-0
lines changed

7 files changed

+454
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.bigtop.manager.stack.infra.v1_0_0.grafana;
20+
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.mockito.Mockito.mock;
26+
import static org.mockito.Mockito.when;
27+
28+
public class GrafanaParamsTest {
29+
30+
private GrafanaParams grafanaParams;
31+
32+
@BeforeEach
33+
public void setUp() {
34+
grafanaParams = mock(GrafanaParams.class);
35+
when(grafanaParams.stackHome()).thenReturn("/stack");
36+
when(grafanaParams.getServiceName()).thenCallRealMethod();
37+
when(grafanaParams.serviceHome()).thenCallRealMethod();
38+
when(grafanaParams.confDir()).thenCallRealMethod();
39+
when(grafanaParams.dataDir()).thenCallRealMethod();
40+
when(grafanaParams.provisioningDir()).thenCallRealMethod();
41+
when(grafanaParams.dataSourceDir()).thenCallRealMethod();
42+
when(grafanaParams.dashboardsDir()).thenCallRealMethod();
43+
when(grafanaParams.dashboardConfigDir("test")).thenCallRealMethod();
44+
}
45+
46+
@Test
47+
public void testServiceHome() {
48+
assertEquals("/stack/grafana", grafanaParams.serviceHome());
49+
}
50+
51+
@Test
52+
public void testConfDir() {
53+
assertEquals("/stack/grafana/conf", grafanaParams.confDir());
54+
}
55+
56+
@Test
57+
public void testDataDir() {
58+
assertEquals("/stack/grafana/data", grafanaParams.dataDir());
59+
}
60+
61+
@Test
62+
public void testProvisioningDir() {
63+
assertEquals("/stack/grafana/conf/provisioning", grafanaParams.provisioningDir());
64+
}
65+
66+
@Test
67+
public void testDataSourceDir() {
68+
assertEquals("/stack/grafana/conf/provisioning/datasources", grafanaParams.dataSourceDir());
69+
}
70+
71+
@Test
72+
public void testDashboardsDir() {
73+
assertEquals("/stack/grafana/conf/provisioning/dashboards", grafanaParams.dashboardsDir());
74+
}
75+
76+
@Test
77+
public void testDashboardConfigDir() {
78+
assertEquals("/stack/grafana/conf/provisioning/dashboards/test", grafanaParams.dashboardConfigDir("test"));
79+
}
80+
81+
@Test
82+
public void testGetServiceName() {
83+
assertEquals("grafana", grafanaParams.getServiceName());
84+
}
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.bigtop.manager.stack.infra.v1_0_0.grafana;
20+
21+
import org.apache.bigtop.manager.stack.core.spi.param.Params;
22+
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertThrows;
27+
28+
public class GrafanaServerScriptTest {
29+
30+
private final GrafanaServerScript grafanaServerScript = new GrafanaServerScript();
31+
32+
@Test
33+
public void testGetComponentName() {
34+
assertEquals("grafana_server", grafanaServerScript.getComponentName());
35+
}
36+
37+
@Test
38+
public void testAddParamsNull() {
39+
Params params = null;
40+
assertThrows(NullPointerException.class, () -> grafanaServerScript.add(params));
41+
}
42+
43+
@Test
44+
public void testConfigureParamsNull() {
45+
Params params = null;
46+
assertThrows(NullPointerException.class, () -> grafanaServerScript.configure(params));
47+
}
48+
49+
@Test
50+
public void testStartParamsNull() {
51+
Params params = null;
52+
assertThrows(NullPointerException.class, () -> grafanaServerScript.start(params));
53+
}
54+
55+
@Test
56+
public void testStopParamsNull() {
57+
Params params = null;
58+
assertThrows(NullPointerException.class, () -> grafanaServerScript.stop(params));
59+
}
60+
61+
@Test
62+
public void testStatusParamsNull() {
63+
Params params = null;
64+
assertThrows(NullPointerException.class, () -> grafanaServerScript.status(params));
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.bigtop.manager.stack.infra.v1_0_0.mysql;
20+
21+
import org.apache.bigtop.manager.stack.core.spi.param.Params;
22+
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertThrows;
27+
28+
public class MySQLClientScriptTest {
29+
30+
private final MySQLClientScript clientScript = new MySQLClientScript();
31+
32+
@Test
33+
public void testGetComponentName() {
34+
assertEquals("mysql_client", clientScript.getComponentName());
35+
}
36+
37+
@Test
38+
public void testAddParamsNull() {
39+
Params params = null;
40+
assertThrows(NullPointerException.class, () -> clientScript.add(params));
41+
}
42+
43+
@Test
44+
public void testConfigureParamsNull() {
45+
Params params = null;
46+
assertThrows(NullPointerException.class, () -> clientScript.configure(params));
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.bigtop.manager.stack.infra.v1_0_0.mysql;
20+
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.mockito.Mockito.mock;
26+
import static org.mockito.Mockito.when;
27+
28+
public class MySQLParamsTest {
29+
30+
private MySQLParams mySQLParams;
31+
32+
@BeforeEach
33+
public void setUp() {
34+
mySQLParams = mock(MySQLParams.class);
35+
when(mySQLParams.stackHome()).thenReturn("/stack");
36+
when(mySQLParams.getServiceName()).thenCallRealMethod();
37+
when(mySQLParams.serviceHome()).thenCallRealMethod();
38+
when(mySQLParams.confDir()).thenCallRealMethod();
39+
when(mySQLParams.user()).thenCallRealMethod();
40+
}
41+
42+
@Test
43+
public void testServiceHome() {
44+
assertEquals("/stack/mysql", mySQLParams.serviceHome());
45+
}
46+
47+
@Test
48+
public void testConfDir() {
49+
assertEquals("/stack/mysql/conf", mySQLParams.confDir());
50+
}
51+
52+
@Test
53+
public void testGetServiceName() {
54+
assertEquals("mysql", mySQLParams.getServiceName());
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.bigtop.manager.stack.infra.v1_0_0.mysql;
20+
21+
import org.apache.bigtop.manager.stack.core.spi.param.Params;
22+
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertThrows;
27+
28+
class MySQLServerScriptTest {
29+
30+
private final MySQLServerScript mysqlServerScript = new MySQLServerScript();
31+
32+
@Test
33+
void testGetComponentName() {
34+
assertEquals("mysql_server", mysqlServerScript.getComponentName());
35+
}
36+
37+
@Test
38+
public void testAddParamsNull() {
39+
Params params = null;
40+
assertThrows(NullPointerException.class, () -> mysqlServerScript.add(params));
41+
}
42+
43+
@Test
44+
public void testConfigureParamsNull() {
45+
Params params = null;
46+
assertThrows(NullPointerException.class, () -> mysqlServerScript.configure(params));
47+
}
48+
49+
@Test
50+
public void testStartParamsNull() {
51+
Params params = null;
52+
assertThrows(NullPointerException.class, () -> mysqlServerScript.start(params));
53+
}
54+
55+
@Test
56+
public void testStopParamsNull() {
57+
Params params = null;
58+
assertThrows(NullPointerException.class, () -> mysqlServerScript.stop(params));
59+
}
60+
61+
@Test
62+
public void testStatusParamsNull() {
63+
Params params = null;
64+
assertThrows(NullPointerException.class, () -> mysqlServerScript.status(params));
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.bigtop.manager.stack.infra.v1_0_0.prometheus;
20+
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.mockito.Mockito.mock;
26+
import static org.mockito.Mockito.when;
27+
28+
public class PrometheusParamsTest {
29+
30+
private PrometheusParams prometheusParams;
31+
32+
@BeforeEach
33+
public void setUp() {
34+
prometheusParams = mock(PrometheusParams.class);
35+
when(prometheusParams.stackHome()).thenReturn("/stack");
36+
when(prometheusParams.getServiceName()).thenCallRealMethod();
37+
when(prometheusParams.serviceHome()).thenCallRealMethod();
38+
when(prometheusParams.dataDir()).thenCallRealMethod();
39+
when(prometheusParams.targetsConfigFile("test_job")).thenCallRealMethod();
40+
when(prometheusParams.confDir()).thenCallRealMethod();
41+
}
42+
43+
@Test
44+
public void testServiceHome() {
45+
assertEquals("/stack/prometheus", prometheusParams.serviceHome());
46+
}
47+
48+
@Test
49+
public void testConfDir() {
50+
assertEquals("/stack/prometheus/conf", prometheusParams.confDir());
51+
}
52+
53+
@Test
54+
public void testDataDir() {
55+
assertEquals("/stack/prometheus/data", prometheusParams.dataDir());
56+
}
57+
58+
@Test
59+
public void testTargetsConfigFile() {
60+
assertEquals("/stack/prometheus/conf/test_job_targets.json", prometheusParams.targetsConfigFile("test_job"));
61+
}
62+
63+
@Test
64+
public void testGetServiceName() {
65+
assertEquals("prometheus", prometheusParams.getServiceName());
66+
}
67+
}

0 commit comments

Comments
 (0)