-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ut cases for emus and shell classes in common module
- Loading branch information
Showing
5 changed files
with
623 additions
and
0 deletions.
There are no files selected for viewing
208 changes: 208 additions & 0 deletions
208
bigtop-manager-common/src/test/java/org/apache/bigtop/manager/common/enums/CommandTest.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,208 @@ | ||
/* | ||
* 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.common.enums; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class CommandTest { | ||
|
||
// Test normal path: verify that the code and name of enum values are correct | ||
@Test | ||
public void testCommandNormalPath() { | ||
assertEquals("add", Command.ADD.getCode(), "The code of ADD should be 'add'"); | ||
assertEquals("Add", Command.ADD.getName(), "The name of ADD should be 'Add'"); | ||
|
||
assertEquals("start", Command.START.getCode(), "The code of START should be 'start'"); | ||
assertEquals("Start", Command.START.getName(), "The name of START should be 'Start'"); | ||
|
||
assertEquals("stop", Command.STOP.getCode(), "The code of STOP should be 'stop'"); | ||
assertEquals("Stop", Command.STOP.getName(), "The name of STOP should be 'Stop'"); | ||
|
||
assertEquals("restart", Command.RESTART.getCode(), "The code of RESTART should be 'restart'"); | ||
assertEquals("Restart", Command.RESTART.getName(), "The name of RESTART should be 'Restart'"); | ||
|
||
assertEquals("check", Command.CHECK.getCode(), "The code of CHECK should be 'check'"); | ||
assertEquals("Check", Command.CHECK.getName(), "The name of CHECK should be 'Check'"); | ||
|
||
assertEquals("configure", Command.CONFIGURE.getCode(), "The code of CONFIGURE should be 'configure'"); | ||
assertEquals("Configure", Command.CONFIGURE.getName(), "The name of CONFIGURE should be 'Configure'"); | ||
|
||
assertEquals("custom", Command.CUSTOM.getCode(), "The code of CUSTOM should be 'custom'"); | ||
assertEquals("Custom", Command.CUSTOM.getName(), "The name of CUSTOM should be 'Custom'"); | ||
|
||
assertEquals("init", Command.INIT.getCode(), "The code of INIT should be 'init'"); | ||
assertEquals("Init", Command.INIT.getName(), "The name of INIT should be 'Init'"); | ||
|
||
assertEquals("prepare", Command.PREPARE.getCode(), "The code of PREPARE should be 'prepare'"); | ||
assertEquals("Prepare", Command.PREPARE.getName(), "The name of PREPARE should be 'Prepare'"); | ||
|
||
assertEquals("status", Command.STATUS.getCode(), "The code of STATUS should be 'status'"); | ||
assertEquals("Status", Command.STATUS.getName(), "The name of STATUS should be 'Status'"); | ||
} | ||
|
||
// Test boundary conditions: verify that the fromString method can correctly convert strings in upper case, lower | ||
// case, and mixed case | ||
@Test | ||
public void testFromStringWithVariousCases() { | ||
assertEquals(Command.ADD, Command.fromString("ADD"), "Upper case 'ADD' should be converted to ADD enum value"); | ||
assertEquals(Command.ADD, Command.fromString("add"), "Lower case 'add' should be converted to ADD enum value"); | ||
assertEquals(Command.ADD, Command.fromString("AdD"), "Mixed case 'AdD' should be converted to ADD enum value"); | ||
|
||
assertEquals( | ||
Command.START, | ||
Command.fromString("START"), | ||
"Upper case 'START' should be converted to START enum value"); | ||
assertEquals( | ||
Command.START, | ||
Command.fromString("start"), | ||
"Lower case 'start' should be converted to START enum value"); | ||
assertEquals( | ||
Command.START, | ||
Command.fromString("StArT"), | ||
"Mixed case 'StArT' should be converted to START enum value"); | ||
|
||
assertEquals( | ||
Command.STOP, Command.fromString("STOP"), "Upper case 'STOP' should be converted to STOP enum value"); | ||
assertEquals( | ||
Command.STOP, Command.fromString("stop"), "Lower case 'stop' should be converted to STOP enum value"); | ||
assertEquals( | ||
Command.STOP, Command.fromString("StOp"), "Mixed case 'StOp' should be converted to STOP enum value"); | ||
|
||
assertEquals( | ||
Command.RESTART, | ||
Command.fromString("RESTART"), | ||
"Upper case 'RESTART' should be converted to RESTART enum value"); | ||
assertEquals( | ||
Command.RESTART, | ||
Command.fromString("restart"), | ||
"Lower case 'restart' should be converted to RESTART enum value"); | ||
assertEquals( | ||
Command.RESTART, | ||
Command.fromString("ReStArT"), | ||
"Mixed case 'ReStArT' should be converted to RESTART enum value"); | ||
|
||
assertEquals( | ||
Command.CHECK, | ||
Command.fromString("CHECK"), | ||
"Upper case 'CHECK' should be converted to CHECK enum value"); | ||
assertEquals( | ||
Command.CHECK, | ||
Command.fromString("check"), | ||
"Lower case 'check' should be converted to CHECK enum value"); | ||
assertEquals( | ||
Command.CHECK, | ||
Command.fromString("ChEcK"), | ||
"Mixed case 'ChEcK' should be converted to CHECK enum value"); | ||
|
||
assertEquals( | ||
Command.CONFIGURE, | ||
Command.fromString("CONFIGURE"), | ||
"Upper case 'CONFIGURE' should be converted to CONFIGURE enum value"); | ||
assertEquals( | ||
Command.CONFIGURE, | ||
Command.fromString("configure"), | ||
"Lower case 'configure' should be converted to CONFIGURE enum value"); | ||
assertEquals( | ||
Command.CONFIGURE, | ||
Command.fromString("CoNfIgUrE"), | ||
"Mixed case 'CoNfIgUrE' should be converted to CONFIGURE enum value"); | ||
|
||
assertEquals( | ||
Command.CUSTOM, | ||
Command.fromString("CUSTOM"), | ||
"Upper case 'CUSTOM' should be converted to CUSTOM enum value"); | ||
assertEquals( | ||
Command.CUSTOM, | ||
Command.fromString("custom"), | ||
"Lower case 'custom' should be converted to CUSTOM enum value"); | ||
assertEquals( | ||
Command.CUSTOM, | ||
Command.fromString("CuStOm"), | ||
"Mixed case 'CuStOm' should be converted to CUSTOM enum value"); | ||
|
||
assertEquals( | ||
Command.INIT, Command.fromString("INIT"), "Upper case 'INIT' should be converted to INIT enum value"); | ||
assertEquals( | ||
Command.INIT, Command.fromString("init"), "Lower case 'init' should be converted to INIT enum value"); | ||
assertEquals( | ||
Command.INIT, Command.fromString("InIt"), "Mixed case 'InIt' should be converted to INIT enum value"); | ||
|
||
assertEquals( | ||
Command.PREPARE, | ||
Command.fromString("PREPARE"), | ||
"Upper case 'PREPARE' should be converted to PREPARE enum value"); | ||
assertEquals( | ||
Command.PREPARE, | ||
Command.fromString("prepare"), | ||
"Lower case 'prepare' should be converted to PREPARE enum value"); | ||
assertEquals( | ||
Command.PREPARE, | ||
Command.fromString("PrEpArE"), | ||
"Mixed case 'PrEpArE' should be converted to PREPARE enum value"); | ||
|
||
assertEquals( | ||
Command.STATUS, | ||
Command.fromString("STATUS"), | ||
"Upper case 'STATUS' should be converted to STATUS enum value"); | ||
assertEquals( | ||
Command.STATUS, | ||
Command.fromString("status"), | ||
"Lower case 'status' should be converted to STATUS enum value"); | ||
assertEquals( | ||
Command.STATUS, | ||
Command.fromString("StAtUs"), | ||
"Mixed case 'StAtUs' should be converted to STATUS enum value"); | ||
} | ||
|
||
// Test boundary conditions: verify that the fromString method throws an exception when passed an invalid string | ||
@Test | ||
public void testFromStringWithInvalidString() { | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> Command.fromString("INVALID"), | ||
"Passing invalid string 'INVALID' should throw an IllegalArgumentException"); | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> Command.fromString(""), | ||
"Passing empty string '' should throw an IllegalArgumentException"); | ||
assertThrows( | ||
NullPointerException.class, | ||
() -> Command.fromString(null), | ||
"Passing null should throw a NullPointerException"); | ||
} | ||
|
||
// Test boundary conditions: verify that the toCamelCase method can correctly convert enum values to camel case | ||
// strings | ||
@Test | ||
public void testToCamelCase() { | ||
assertEquals("Add", Command.ADD.toCamelCase(), "ADD should be converted to 'Add'"); | ||
assertEquals("Start", Command.START.toCamelCase(), "START should be converted to 'Start'"); | ||
assertEquals("Stop", Command.STOP.toCamelCase(), "STOP should be converted to 'Stop'"); | ||
assertEquals("Restart", Command.RESTART.toCamelCase(), "RESTART should be converted to 'Restart'"); | ||
assertEquals("Check", Command.CHECK.toCamelCase(), "CHECK should be converted to 'Check'"); | ||
assertEquals("Configure", Command.CONFIGURE.toCamelCase(), "CONFIGURE should be converted to 'Configure'"); | ||
assertEquals("Custom", Command.CUSTOM.toCamelCase(), "CUSTOM should be converted to 'Custom'"); | ||
assertEquals("Init", Command.INIT.toCamelCase(), "INIT should be converted to 'Init'"); | ||
assertEquals("Prepare", Command.PREPARE.toCamelCase(), "PREPARE should be converted to 'Prepare'"); | ||
assertEquals("Status", Command.STATUS.toCamelCase(), "STATUS should be converted to 'Status'"); | ||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
bigtop-manager-common/src/test/java/org/apache/bigtop/manager/common/enums/JobStateTest.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,143 @@ | ||
/* | ||
* 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.common.enums; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class JobStateTest { | ||
// Test normal path: verify that the code and name of enum values are correct | ||
@Test | ||
public void testJobStateNormalPath() { | ||
assertEquals("pending", JobState.PENDING.getCode(), "The code of PENDING should be 'pending'"); | ||
assertEquals("Pending", JobState.PENDING.getName(), "The name of PENDING should be 'Pending'"); | ||
|
||
assertEquals("processing", JobState.PROCESSING.getCode(), "The code of PROCESSING should be 'processing'"); | ||
assertEquals("Processing", JobState.PROCESSING.getName(), "The name of PROCESSING should be 'Processing'"); | ||
|
||
assertEquals("successful", JobState.SUCCESSFUL.getCode(), "The code of SUCCESSFUL should be 'successful'"); | ||
assertEquals("Successful", JobState.SUCCESSFUL.getName(), "The name of SUCCESSFUL should be 'Successful'"); | ||
|
||
assertEquals("failed", JobState.FAILED.getCode(), "The code of FAILED should be 'failed'"); | ||
assertEquals("Failed", JobState.FAILED.getName(), "The name of FAILED should be 'Failed'"); | ||
|
||
assertEquals("canceled", JobState.CANCELED.getCode(), "The code of CANCELED should be 'canceled'"); | ||
assertEquals("Canceled", JobState.CANCELED.getName(), "The name of CANCELED should be 'Canceled'"); | ||
} | ||
|
||
// Test boundary conditions: verify that the fromString method can correctly convert strings in upper case, lower | ||
// case, and mixed case | ||
@Test | ||
public void testFromStringWithVariousCases() { | ||
assertEquals( | ||
JobState.PENDING, | ||
JobState.fromString("PENDING"), | ||
"Upper case 'PENDING' should be converted to PENDING enum value"); | ||
assertEquals( | ||
JobState.PENDING, | ||
JobState.fromString("pending"), | ||
"Lower case 'pending' should be converted to PENDING enum value"); | ||
assertEquals( | ||
JobState.PENDING, | ||
JobState.fromString("PeNdiNg"), | ||
"Mixed case 'PeNdiNg' should be converted to PENDING enum value"); | ||
|
||
assertEquals( | ||
JobState.PROCESSING, | ||
JobState.fromString("PROCESSING"), | ||
"Upper case 'PROCESSING' should be converted to PROCESSING enum value"); | ||
assertEquals( | ||
JobState.PROCESSING, | ||
JobState.fromString("processing"), | ||
"Lower case 'processing' should be converted to PROCESSING enum value"); | ||
assertEquals( | ||
JobState.PROCESSING, | ||
JobState.fromString("PrOcEsSiNg"), | ||
"Mixed case 'PrOcEsSiNg' should be converted to PROCESSING enum value"); | ||
|
||
assertEquals( | ||
JobState.SUCCESSFUL, | ||
JobState.fromString("SUCCESSFUL"), | ||
"Upper case 'SUCCESSFUL' should be converted to SUCCESSFUL enum value"); | ||
assertEquals( | ||
JobState.SUCCESSFUL, | ||
JobState.fromString("successful"), | ||
"Lower case 'successful' should be converted to SUCCESSFUL enum value"); | ||
assertEquals( | ||
JobState.SUCCESSFUL, | ||
JobState.fromString("SuCcEsSfUl"), | ||
"Mixed case 'SuCcEsSfUl' should be converted to SUCCESSFUL enum value"); | ||
|
||
assertEquals( | ||
JobState.FAILED, | ||
JobState.fromString("FAILED"), | ||
"Upper case 'FAILED' should be converted to FAILED enum value"); | ||
assertEquals( | ||
JobState.FAILED, | ||
JobState.fromString("failed"), | ||
"Lower case 'failed' should be converted to FAILED enum value"); | ||
assertEquals( | ||
JobState.FAILED, | ||
JobState.fromString("FaIlEd"), | ||
"Mixed case 'FaIlEd' should be converted to FAILED enum value"); | ||
|
||
assertEquals( | ||
JobState.CANCELED, | ||
JobState.fromString("CANCELED"), | ||
"Upper case 'CANCELED' should be converted to CANCELED enum value"); | ||
assertEquals( | ||
JobState.CANCELED, | ||
JobState.fromString("canceled"), | ||
"Lower case 'canceled' should be converted to CANCELED enum value"); | ||
assertEquals( | ||
JobState.CANCELED, | ||
JobState.fromString("CaNcElEd"), | ||
"Mixed case 'CaNcElEd' should be converted to CANCELED enum value"); | ||
} | ||
|
||
// Test boundary conditions: verify that the fromString method throws an exception when passed an invalid string | ||
@Test | ||
public void testFromStringWithInvalidString() { | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> JobState.fromString("INVALID"), | ||
"Passing invalid string 'INVALID' should throw an IllegalArgumentException"); | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> JobState.fromString(""), | ||
"Passing empty string '' should throw an IllegalArgumentException"); | ||
assertThrows( | ||
NullPointerException.class, | ||
() -> JobState.fromString(null), | ||
"Passing null should throw a NullPointerException"); | ||
} | ||
|
||
// Test boundary conditions: verify that the toCamelCase method can correctly convert enum values to camel case | ||
// strings | ||
@Test | ||
public void testToCamelCase() { | ||
assertEquals("Pending", JobState.PENDING.toCamelCase(), "PENDING should be converted to 'Pending'"); | ||
assertEquals("Processing", JobState.PROCESSING.toCamelCase(), "PROCESSING should be converted to 'Processing'"); | ||
assertEquals("Successful", JobState.SUCCESSFUL.toCamelCase(), "SUCCESSFUL should be converted to 'Successful'"); | ||
assertEquals("Failed", JobState.FAILED.toCamelCase(), "FAILED should be converted to 'Failed'"); | ||
assertEquals("Canceled", JobState.CANCELED.toCamelCase(), "CANCELED should be converted to 'Canceled'"); | ||
} | ||
} |
Oops, something went wrong.