From 9ff8193516d7035080f86b15e8e85d1280f21041 Mon Sep 17 00:00:00 2001 From: xianrenzw <139131974+xianrenzw@users.noreply.github.com> Date: Thu, 13 Feb 2025 16:34:28 +0800 Subject: [PATCH] BIGTOP-4350: Add some unit tests for stack infra module (#169) --- .../v1_0_0/grafana/GrafanaParamsTest.java | 85 +++++++++++++++++++ .../grafana/GrafanaServerScriptTest.java | 66 ++++++++++++++ .../v1_0_0/mysql/MySQLClientScriptTest.java | 48 +++++++++++ .../infra/v1_0_0/mysql/MySQLParamsTest.java | 56 ++++++++++++ .../v1_0_0/mysql/MySQLServerScriptTest.java | 66 ++++++++++++++ .../prometheus/PrometheusParamsTest.java | 67 +++++++++++++++ .../PrometheusServerScriptTest.java | 66 ++++++++++++++ 7 files changed, 454 insertions(+) create mode 100644 bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaParamsTest.java create mode 100644 bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScriptTest.java create mode 100644 bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLClientScriptTest.java create mode 100644 bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLParamsTest.java create mode 100644 bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLServerScriptTest.java create mode 100644 bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/prometheus/PrometheusParamsTest.java create mode 100644 bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/prometheus/PrometheusServerScriptTest.java diff --git a/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaParamsTest.java b/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaParamsTest.java new file mode 100644 index 000000000..5e72eaade --- /dev/null +++ b/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaParamsTest.java @@ -0,0 +1,85 @@ +/* + * 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 + * + * https://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.bigtop.manager.stack.infra.v1_0_0.grafana; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class GrafanaParamsTest { + + private GrafanaParams grafanaParams; + + @BeforeEach + public void setUp() { + grafanaParams = mock(GrafanaParams.class); + when(grafanaParams.stackHome()).thenReturn("/stack"); + when(grafanaParams.getServiceName()).thenCallRealMethod(); + when(grafanaParams.serviceHome()).thenCallRealMethod(); + when(grafanaParams.confDir()).thenCallRealMethod(); + when(grafanaParams.dataDir()).thenCallRealMethod(); + when(grafanaParams.provisioningDir()).thenCallRealMethod(); + when(grafanaParams.dataSourceDir()).thenCallRealMethod(); + when(grafanaParams.dashboardsDir()).thenCallRealMethod(); + when(grafanaParams.dashboardConfigDir("test")).thenCallRealMethod(); + } + + @Test + public void testServiceHome() { + assertEquals("/stack/grafana", grafanaParams.serviceHome()); + } + + @Test + public void testConfDir() { + assertEquals("/stack/grafana/conf", grafanaParams.confDir()); + } + + @Test + public void testDataDir() { + assertEquals("/stack/grafana/data", grafanaParams.dataDir()); + } + + @Test + public void testProvisioningDir() { + assertEquals("/stack/grafana/conf/provisioning", grafanaParams.provisioningDir()); + } + + @Test + public void testDataSourceDir() { + assertEquals("/stack/grafana/conf/provisioning/datasources", grafanaParams.dataSourceDir()); + } + + @Test + public void testDashboardsDir() { + assertEquals("/stack/grafana/conf/provisioning/dashboards", grafanaParams.dashboardsDir()); + } + + @Test + public void testDashboardConfigDir() { + assertEquals("/stack/grafana/conf/provisioning/dashboards/test", grafanaParams.dashboardConfigDir("test")); + } + + @Test + public void testGetServiceName() { + assertEquals("grafana", grafanaParams.getServiceName()); + } +} diff --git a/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScriptTest.java b/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScriptTest.java new file mode 100644 index 000000000..ba51b436f --- /dev/null +++ b/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScriptTest.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 + * + * https://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.bigtop.manager.stack.infra.v1_0_0.grafana; + +import org.apache.bigtop.manager.stack.core.spi.param.Params; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class GrafanaServerScriptTest { + + private final GrafanaServerScript grafanaServerScript = new GrafanaServerScript(); + + @Test + public void testGetComponentName() { + assertEquals("grafana_server", grafanaServerScript.getComponentName()); + } + + @Test + public void testAddParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> grafanaServerScript.add(params)); + } + + @Test + public void testConfigureParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> grafanaServerScript.configure(params)); + } + + @Test + public void testStartParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> grafanaServerScript.start(params)); + } + + @Test + public void testStopParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> grafanaServerScript.stop(params)); + } + + @Test + public void testStatusParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> grafanaServerScript.status(params)); + } +} diff --git a/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLClientScriptTest.java b/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLClientScriptTest.java new file mode 100644 index 000000000..4aeb1175a --- /dev/null +++ b/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLClientScriptTest.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.bigtop.manager.stack.infra.v1_0_0.mysql; + +import org.apache.bigtop.manager.stack.core.spi.param.Params; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class MySQLClientScriptTest { + + private final MySQLClientScript clientScript = new MySQLClientScript(); + + @Test + public void testGetComponentName() { + assertEquals("mysql_client", clientScript.getComponentName()); + } + + @Test + public void testAddParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> clientScript.add(params)); + } + + @Test + public void testConfigureParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> clientScript.configure(params)); + } +} diff --git a/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLParamsTest.java b/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLParamsTest.java new file mode 100644 index 000000000..e7b6bb8d2 --- /dev/null +++ b/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLParamsTest.java @@ -0,0 +1,56 @@ +/* + * 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 + * + * https://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.bigtop.manager.stack.infra.v1_0_0.mysql; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class MySQLParamsTest { + + private MySQLParams mySQLParams; + + @BeforeEach + public void setUp() { + mySQLParams = mock(MySQLParams.class); + when(mySQLParams.stackHome()).thenReturn("/stack"); + when(mySQLParams.getServiceName()).thenCallRealMethod(); + when(mySQLParams.serviceHome()).thenCallRealMethod(); + when(mySQLParams.confDir()).thenCallRealMethod(); + when(mySQLParams.user()).thenCallRealMethod(); + } + + @Test + public void testServiceHome() { + assertEquals("/stack/mysql", mySQLParams.serviceHome()); + } + + @Test + public void testConfDir() { + assertEquals("/stack/mysql/conf", mySQLParams.confDir()); + } + + @Test + public void testGetServiceName() { + assertEquals("mysql", mySQLParams.getServiceName()); + } +} diff --git a/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLServerScriptTest.java b/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLServerScriptTest.java new file mode 100644 index 000000000..80209fcea --- /dev/null +++ b/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLServerScriptTest.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 + * + * https://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.bigtop.manager.stack.infra.v1_0_0.mysql; + +import org.apache.bigtop.manager.stack.core.spi.param.Params; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class MySQLServerScriptTest { + + private final MySQLServerScript mysqlServerScript = new MySQLServerScript(); + + @Test + void testGetComponentName() { + assertEquals("mysql_server", mysqlServerScript.getComponentName()); + } + + @Test + public void testAddParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> mysqlServerScript.add(params)); + } + + @Test + public void testConfigureParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> mysqlServerScript.configure(params)); + } + + @Test + public void testStartParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> mysqlServerScript.start(params)); + } + + @Test + public void testStopParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> mysqlServerScript.stop(params)); + } + + @Test + public void testStatusParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> mysqlServerScript.status(params)); + } +} diff --git a/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/prometheus/PrometheusParamsTest.java b/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/prometheus/PrometheusParamsTest.java new file mode 100644 index 000000000..cdfc5ca0d --- /dev/null +++ b/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/prometheus/PrometheusParamsTest.java @@ -0,0 +1,67 @@ +/* + * 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 + * + * https://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.bigtop.manager.stack.infra.v1_0_0.prometheus; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class PrometheusParamsTest { + + private PrometheusParams prometheusParams; + + @BeforeEach + public void setUp() { + prometheusParams = mock(PrometheusParams.class); + when(prometheusParams.stackHome()).thenReturn("/stack"); + when(prometheusParams.getServiceName()).thenCallRealMethod(); + when(prometheusParams.serviceHome()).thenCallRealMethod(); + when(prometheusParams.dataDir()).thenCallRealMethod(); + when(prometheusParams.targetsConfigFile("test_job")).thenCallRealMethod(); + when(prometheusParams.confDir()).thenCallRealMethod(); + } + + @Test + public void testServiceHome() { + assertEquals("/stack/prometheus", prometheusParams.serviceHome()); + } + + @Test + public void testConfDir() { + assertEquals("/stack/prometheus/conf", prometheusParams.confDir()); + } + + @Test + public void testDataDir() { + assertEquals("/stack/prometheus/data", prometheusParams.dataDir()); + } + + @Test + public void testTargetsConfigFile() { + assertEquals("/stack/prometheus/conf/test_job_targets.json", prometheusParams.targetsConfigFile("test_job")); + } + + @Test + public void testGetServiceName() { + assertEquals("prometheus", prometheusParams.getServiceName()); + } +} diff --git a/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/prometheus/PrometheusServerScriptTest.java b/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/prometheus/PrometheusServerScriptTest.java new file mode 100644 index 000000000..5b4026136 --- /dev/null +++ b/bigtop-manager-stack/bigtop-manager-stack-infra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/prometheus/PrometheusServerScriptTest.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 + * + * https://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.bigtop.manager.stack.infra.v1_0_0.prometheus; + +import org.apache.bigtop.manager.stack.core.spi.param.Params; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class PrometheusServerScriptTest { + + private final PrometheusServerScript prometheusServerScript = new PrometheusServerScript(); + + @Test + public void testGetComponentName() { + assertEquals("prometheus_server", prometheusServerScript.getComponentName()); + } + + @Test + public void testAddParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> prometheusServerScript.add(params)); + } + + @Test + public void testConfigureParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> prometheusServerScript.configure(params)); + } + + @Test + public void testStartParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> prometheusServerScript.start(params)); + } + + @Test + public void testStopParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> prometheusServerScript.stop(params)); + } + + @Test + public void testStatusParamsNull() { + Params params = null; + assertThrows(NullPointerException.class, () -> prometheusServerScript.status(params)); + } +}