Skip to content

Commit

Permalink
BIGTOP-4350: Add some unit tests for stack infra module (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
xianrenzw authored Feb 13, 2025
1 parent 7a2ba19 commit 9ff8193
Show file tree
Hide file tree
Showing 7 changed files with 454 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Loading

0 comments on commit 9ff8193

Please sign in to comment.