-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BIGTOP-4350: Add some unit tests for stack infra module (#169)
- Loading branch information
Showing
7 changed files
with
454 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaParamsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...st/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScriptTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...c/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLClientScriptTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...fra/src/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLParamsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...c/test/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLServerScriptTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...st/java/org/apache/bigtop/manager/stack/infra/v1_0_0/prometheus/PrometheusParamsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
Oops, something went wrong.