Select Git revision
PartitioningTests.java
Forked from
Tim Miller / SWEN90006-A1-2019
5 commits ahead of the upstream repository.
PartitioningTests.java 26.82 KiB
package swen90006.passbook;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.ArrayList;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.nio.file.Files;
import java.nio.file.FileSystems;
import org.junit.*;
import static org.junit.Assert.*;
public class PartitioningTests
{
protected PassBook pb;
//Any method annotated with "@Before" will be executed before each test,
//allowing the tester to set up some shared resources.
@Before public void setUp()
{
pb = new PassBook();
}
//Any method annotated with "@After" will be executed after each test,
//allowing the tester to release any shared resources used in the setup.
@After public void tearDown()
{
}
//Any method annotation with "@Test" is executed as a test.
//------------------------------addUser Test Cases-------------------------------------
//DuplicateUserTest Test Cases
//Existed Username in PASSBOOK
@Test public void DuplicateUserTest() throws WeakPassphraseException, DuplicateUserException {
boolean DuplicateUserException = false;
String passbookUsername = "ALexTina";
String passbookphrase = "Abcd1234";
try{
pb.addUser(passbookUsername, passbookphrase);
pb.addUser(passbookUsername, passbookphrase);
}
catch(DuplicateUserException e){
DuplicateUserException = true;
}
assertTrue (DuplicateUserException) ;
}
//Not Existed Username in PASSBOOK
@Test public void DuplicateUserTest2() throws WeakPassphraseException, DuplicateUserException {
boolean DuplicateUserException = false;
String passbookUsername = "ALexTina";
String passbookphrase = "Abcd1234";
String passbookUsername2 = "TinaAlex";
String passbookphrase2 = "1234Abcd";
try{
pb.addUser(passbookUsername, passbookphrase);
pb.addUser(passbookUsername2, passbookphrase2);
}
catch(DuplicateUserException e){
DuplicateUserException = true;
}
assertFalse (DuplicateUserException); ;
}
//WeakPassphraseException Test cases
//0 < Passphrase < 8
@Test public void WeakPassphraseException() throws DuplicateUserException{
boolean WeakPassphraseException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "Ab23";
try{
pb.addUser(passbookUsername,passbookphrase);
}
catch (WeakPassphraseException e){
WeakPassphraseException = true;
}
assertTrue(WeakPassphraseException);
}
//Passphrase = 8
@Test public void WeakPassphraseException2() throws DuplicateUserException{
boolean WeakPassphraseException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "Ab23sda2";
try{
pb.addUser(passbookUsername,passbookphrase);
}
catch (WeakPassphraseException e){
WeakPassphraseException = true;
}
assertFalse(WeakPassphraseException);
}
//Passphrase > 8
@Test public void WeakPassphraseException3() throws DuplicateUserException{
boolean WeakPassphraseException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "Ab23sda2dsaldaskljdkasl";
try{
pb.addUser(passbookUsername,passbookphrase);
}
catch (WeakPassphraseException e){
WeakPassphraseException = true;
}
assertFalse(WeakPassphraseException);
}
// passphrase.length = 8 && passphrase only contain one kind factory in Lower, Upper and Number
@Test public void Contains() throws DuplicateUserException
{
boolean WeakPassphraseException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "AAAABBBC";
try{
pb.addUser(passbookUsername,passbookphrase);
}
catch (WeakPassphraseException e){
WeakPassphraseException = true;
}
assertTrue(WeakPassphraseException);
}
// passphrase.length = 8 && passphrase only contain two kind factory in Lower, Upper and Number
@Test public void Contains2() throws DuplicateUserException
{
boolean WeakPassphraseException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "AAA2232C";
try{
pb.addUser(passbookUsername,passbookphrase);
}
catch (WeakPassphraseException e){
WeakPassphraseException = true;
}
assertTrue(WeakPassphraseException);
}
// passphrase.length = 8 && passphrase contain no kind factory in Lower, Upper and Number
@Test public void Contains3() throws DuplicateUserException
{
boolean WeakPassphraseException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "^&*($%@#";
try{
pb.addUser(passbookUsername,passbookphrase);
}
catch (WeakPassphraseException e){
WeakPassphraseException = true;
}
assertTrue(WeakPassphraseException);
}
// passphrase.length = 8 && passphrase contain all kinds factory in Lower, Upper and Number
@Test public void Contains4() throws DuplicateUserException
{
boolean WeakPassphraseException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "Ab23cd54";
try{
pb.addUser(passbookUsername,passbookphrase);
}
catch (WeakPassphraseException e){
WeakPassphraseException = true;
}
assertFalse(WeakPassphraseException);
}
// passphrase.length > 8 && passphrase only contain one kind factory in Lower, Upper and Number
@Test public void Contains5() throws DuplicateUserException
{
boolean WeakPassphraseException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "123456789212";
try{
pb.addUser(passbookUsername,passbookphrase);
}
catch (WeakPassphraseException e){
WeakPassphraseException = true;
}
assertTrue(WeakPassphraseException);
}
// passphrase.length > 8 && passphrase only contain two kind factory in Lower, Upper and Number
@Test public void Contains6() throws DuplicateUserException
{
boolean WeakPassphraseException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "AAA223293289312C";
try{
pb.addUser(passbookUsername,passbookphrase);
}
catch (WeakPassphraseException e){
WeakPassphraseException = true;
}
assertTrue(WeakPassphraseException);
}
// passphrase.length > 8 && passphrase contain no kind factory in Lower, Upper and Number
@Test public void Contains7() throws DuplicateUserException
{
boolean WeakPassphraseException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "^&*($%@#%^&*(";
try{
pb.addUser(passbookUsername,passbookphrase);
}
catch (WeakPassphraseException e){
WeakPassphraseException = true;
}
assertTrue(WeakPassphraseException);
}
// passphrase.length > 8 && passphrase contain all kinds factory in Lower, Upper and Number
@Test public void Contains8() throws DuplicateUserException
{
boolean WeakPassphraseException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "Ab23cd54vhuy67";
try{
pb.addUser(passbookUsername,passbookphrase);
}
catch (WeakPassphraseException e){
WeakPassphraseException = true;
}
assertFalse(WeakPassphraseException);
}
//------------------------------loginUser Test Cases-------------------------------------
// user is in passbook
@Test public void NoSuchUserException() throws NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, WeakPassphraseException, DuplicateUserException {
boolean NoSuchUserException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "Abc234hg";
try {
pb.addUser(passbookUsername,passbookphrase);
pb.loginUser(passbookUsername,passbookphrase);
}
catch (NoSuchUserException e){
NoSuchUserException = true;
}
assertFalse(NoSuchUserException);
}
// user is not in passbook
@Test public void NoSuchUserException2() throws NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, WeakPassphraseException, DuplicateUserException {
boolean NoSuchUserException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "Abc234hg";
String passbookUsername2 = "AlesTina";
String passbookphrase2 = "Abc234hg";
try {
pb.addUser(passbookUsername,passbookphrase);
pb.loginUser(passbookUsername2,passbookphrase2);
}
catch (NoSuchUserException e){
NoSuchUserException = true;
}
assertTrue(NoSuchUserException);
}
// username is NULL
@Test public void NoSuchUserException3() throws NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, WeakPassphraseException, DuplicateUserException {
boolean NoSuchUserException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "Abc234hg";
String passbookUsername2 = "";
String passbookphrase2 = "Abc234hg";
try {
pb.addUser(passbookUsername,passbookphrase);
pb.loginUser(passbookUsername2,passbookphrase2);
}
catch (NoSuchUserException e){
NoSuchUserException = true;
}
assertTrue(NoSuchUserException);
}
// user has login
@Test public void AlreadyLoggedInException() throws NoSuchUserException, IncorrectPassphraseException, WeakPassphraseException, DuplicateUserException {
boolean AlreadyLoggedInException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "Abc234hg";
String passbookUsername2 = "AlexTina";
String passbookphrase2 = "Abc234hg";
try{
pb.addUser(passbookUsername,passbookphrase);
pb.loginUser(passbookUsername,passbookphrase);
pb.loginUser(passbookUsername2,passbookphrase2);
}
catch (AlreadyLoggedInException e){
AlreadyLoggedInException = true;
}
assertTrue(AlreadyLoggedInException);
}
//user has not login
@Test public void AlreadyLoggedInException2() throws NoSuchUserException, IncorrectPassphraseException, WeakPassphraseException, DuplicateUserException {
boolean AlreadyLoggedInException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "Abc234hg";
try{
pb.addUser(passbookUsername,passbookphrase);
pb.loginUser(passbookUsername,passbookphrase);
}
catch (AlreadyLoggedInException e){
AlreadyLoggedInException = true;
}
assertFalse(AlreadyLoggedInException);
}
//passphrase is not equale to the saved one
@Test public void IncorrectPassphraseException() throws WeakPassphraseException, DuplicateUserException, AlreadyLoggedInException, IncorrectPassphraseException, NoSuchUserException {
boolean IncorrectPassphraseException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "Abc234hg";
String passbookUsername2 = "AlexTina";
String passbookphrase2 = "Abc23444hg";
try {
pb.addUser(passbookUsername,passbookphrase);
pb.loginUser(passbookUsername2,passbookphrase2);
}
catch (IncorrectPassphraseException e){
IncorrectPassphraseException = true;
}
assertTrue(IncorrectPassphraseException);
}
//passphrase is equale to the saved one
@Test public void IncorrectPassphraseException2() throws WeakPassphraseException, DuplicateUserException, AlreadyLoggedInException, IncorrectPassphraseException, NoSuchUserException {
boolean IncorrectPassphraseException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "Abc234hg";
String passbookUsername2 = "AlexTina";
String passbookphrase2 = "Abc234hg";
try {
pb.addUser(passbookUsername,passbookphrase);
pb.loginUser(passbookUsername2,passbookphrase2);
}
catch (IncorrectPassphraseException e){
IncorrectPassphraseException = true;
}
assertFalse(IncorrectPassphraseException);
}
//passphrase is NULL
@Test public void IncorrectPassphraseException3() throws WeakPassphraseException, DuplicateUserException, AlreadyLoggedInException, IncorrectPassphraseException, NoSuchUserException {
boolean IncorrectPassphraseException = false;
String passbookUsername = "AlexTina";
String passbookphrase = "Abc234hg";
String passbookUsername2 = "AlexTina";
String passbookphrase2 = "";
try {
pb.addUser(passbookUsername,passbookphrase);
pb.loginUser(passbookUsername2,passbookphrase2);
}
catch (IncorrectPassphraseException e){
IncorrectPassphraseException = true;
}
assertTrue(IncorrectPassphraseException);
}
//------------------------------updateDetails Test Cases-------------------------------------
//InvalidSessionIDException
// sessionID exist
@Test public void InvalidSessionIDException() throws WeakPassphraseException, DuplicateUserException, NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, MalformedURLException, InvalidSessionIDException {
boolean InvalidSessionIDException = false;
Integer sessionID ;
URL url = new URL ("http:AlexTinaAbc234hg");
String Username = "AlexTina";
String Password = "Abc234hg";
String urlUsername = "AlexTina";
String urlPassword = "Abc234hg";
pb.addUser(Username,Password);
sessionID = pb.loginUser(Username,Password);
try{
pb.updateDetails(sessionID,url,urlUsername,urlPassword);
}catch (InvalidSessionIDException e){
InvalidSessionIDException = true;
}
assertFalse(InvalidSessionIDException);
}
// sessionID not exist
@Test public void InvalidSessionIDException2() throws WeakPassphraseException, DuplicateUserException, NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, MalformedURLException, InvalidSessionIDException {
boolean InvalidSessionIDException = false;
Integer sessionID = -1 ;
URL url = new URL ("http:AlexTinaAbc234hg");
String Username = "AlexTina";
String Password = "Abc234hg";
String urlUsername = "AlexTina";
String urlPassword = "Abc234hg";
pb.addUser(Username,Password);
try{
pb.updateDetails(sessionID,url,urlUsername,urlPassword);
}catch (InvalidSessionIDException e){
InvalidSessionIDException = true;
}
assertTrue(InvalidSessionIDException);
}
//MalformedURLException
//Protocol = [http,https]
@Test public void MalformedURLException() throws MalformedURLException, WeakPassphraseException, DuplicateUserException, NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, InvalidSessionIDException {
boolean MalformedURLException = false;
Integer sessionID ;
String Username = "AlexTina";
String Password = "Abc234hg";
String urlUsername = "AlexTina";
String urlPassword = "Abc234hg";
pb.addUser(Username,Password);
sessionID = pb.loginUser(Username,Password);
try{
URL url = new URL ("http:AlexTinaAbc234hg");
pb.updateDetails(sessionID,url,urlUsername,urlPassword);
}catch (MalformedURLException e){
MalformedURLException = true;
}
assertFalse(MalformedURLException);
}
//Protocol != [http,https]
@Test public void MalformedURLException2() throws MalformedURLException, WeakPassphraseException, DuplicateUserException, NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, InvalidSessionIDException {
boolean MalformedURLException = false;
Integer sessionID ;
String Username = "AlexTina";
String Password = "Abc234hg";
String urlUsername = "AlexTina";
String urlPassword = "Abc234hg";
pb.addUser(Username,Password);
sessionID = pb.loginUser(Username,Password);
try{
URL url = new URL ("TPP:AlexTinaAbc234hg");
pb.updateDetails(sessionID,url,urlUsername,urlPassword);
}catch ( MalformedURLException e){
MalformedURLException = true;
}
assertTrue(MalformedURLException);
}
// check the urlusername or password whether are null
//urlUsername != null && urlPassword !=null
@Test public void checkRemove() throws WeakPassphraseException, DuplicateUserException, NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, InvalidSessionIDException, MalformedURLException, NoSuchURLException {
boolean NoSuchUserException = false;
Integer sessionID ;
String Username = "AlexTina";
String Password = "Abc234hg";
String urlUsername = "AlexTina";
String urlPassword = "Abc234hg";
pb.addUser(Username,Password);
sessionID = pb.loginUser(Username,Password);
try{
URL url = new URL ("http:AlexTinaAbc234hg");
pb.updateDetails(sessionID,url,urlUsername,urlPassword);
pb.retrieveDetails(sessionID,url);
}
catch (NoSuchURLException e){
NoSuchUserException = true;
}
assertFalse(NoSuchUserException);
}
//urlUsername = null || urlPassword !=null
@Test public void checkRemove2() throws WeakPassphraseException, DuplicateUserException, NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, InvalidSessionIDException, MalformedURLException, NoSuchURLException {
boolean NoSuchUserException = false;
Integer sessionID ;
String Username = "AlexTina";
String Password = "Abc234hg";
String urlUsername = null;
String urlPassword = "Abc234hg";
pb.addUser(Username,Password);
sessionID = pb.loginUser(Username,Password);
try{
URL url = new URL ("http:AlexTinaAbc234hg");
pb.updateDetails(sessionID,url,urlUsername,urlPassword);
pb.retrieveDetails(sessionID,url);
}
catch (NoSuchURLException e){
NoSuchUserException = true;
}
assertTrue(NoSuchUserException);
}
//urlUsername != null || urlPassword =null
@Test public void checkRemove3() throws WeakPassphraseException, DuplicateUserException, NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, InvalidSessionIDException, MalformedURLException, NoSuchURLException {
boolean NoSuchUserException = false;
Integer sessionID ;
String Username = "AlexTina";
String Password = "Abc234hg";
String urlUsername = "AlexTina";
String urlPassword = null;
pb.addUser(Username,Password);
sessionID = pb.loginUser(Username,Password);
try{
URL url = new URL ("http:AlexTinaAbc234hg");
pb.updateDetails(sessionID,url,urlUsername,urlPassword);
pb.retrieveDetails(sessionID,url);
}
catch (NoSuchURLException e){
NoSuchUserException = true;
}
assertTrue(NoSuchUserException);
}
//urlUsername != null || urlPassword !=null
@Test public void checkRemove4() throws WeakPassphraseException, DuplicateUserException, NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, InvalidSessionIDException, MalformedURLException, NoSuchURLException {
boolean NoSuchUserException = false;
Integer sessionID ;
String Username = "AlexTina";
String Password = "Abc234hg";
String urlUsername = null;
String urlPassword = null;
pb.addUser(Username,Password);
sessionID = pb.loginUser(Username,Password);
try{
URL url = new URL ("http:AlexTinaAbc234hg");
pb.updateDetails(sessionID,url,urlUsername,urlPassword);
pb.retrieveDetails(sessionID,url);
}
catch (NoSuchURLException e){
NoSuchUserException = true;
}
assertTrue(NoSuchUserException);
}
//------------------------------retrieveDetails Test Cases-------------------------------------
//InvalidSessionIDException
// sessionID exist
@Test public void InvalidSessionIDExceptionRE() throws WeakPassphraseException, DuplicateUserException, NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, MalformedURLException, NoSuchURLException {
boolean InvalidSessionIDException = false;
Integer sessionID ;
String Username = "AlexTina";
String Password = "Abc234hg";
String urlUsername = "AlexTina";
String urlPassword = "Abc234hg";
pb.addUser(Username,Password);
sessionID = pb.loginUser(Username,Password);
try{
URL url = new URL ("http:AlexTinaAbc234hg");
pb.updateDetails(sessionID,url,urlUsername,urlPassword);
pb.retrieveDetails(sessionID,url);
}catch (InvalidSessionIDException e){
InvalidSessionIDException = true;
}
assertFalse(InvalidSessionIDException);
}
// sessionID not exist
@Test public void InvalidSessionIDExceptionRE2() throws WeakPassphraseException, DuplicateUserException, NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, MalformedURLException, NoSuchURLException {
boolean InvalidSessionIDException = false;
Integer sessionID = -1;
String Username = "AlexTina";
String Password = "Abc234hg";
String urlUsername = "AlexTina";
String urlPassword = "Abc234hg";
pb.addUser(Username,Password);
try{
URL url = new URL ("http:AlexTinaAbc234hg");
pb.updateDetails(sessionID,url,urlUsername,urlPassword);
pb.retrieveDetails(sessionID,url);
}catch (InvalidSessionIDException e){
InvalidSessionIDException = true;
}
assertTrue(InvalidSessionIDException);
}
// NoSuchURLException
// pt!=null
@Test public void NoSuchURLException() throws WeakPassphraseException, DuplicateUserException, NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, InvalidSessionIDException, MalformedURLException, NoSuchURLException {
boolean NoSuchURLException = false;
Integer sessionID ;
String Username = "AlexTina";
String Password = "Abc234hg";
String urlUsername = "AlexTina";
String urlPassword = "Abc234hg";
pb.addUser(Username,Password);
sessionID = pb.loginUser(Username,Password);
try{
URL url = new URL ("http:AlexTinaAbc234hg");
pb.updateDetails(sessionID,url,urlUsername,urlPassword);
pb.retrieveDetails(sessionID,url);
}
catch (NoSuchURLException e){
NoSuchURLException = true;
}
assertFalse(NoSuchURLException);
}
//pt==null
@Test public void NoSuchURLException2() throws WeakPassphraseException, DuplicateUserException, NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, InvalidSessionIDException, MalformedURLException, NoSuchURLException {
boolean NoSuchURLException = false;
Integer sessionID ;
String Username = "AlexTina";
String Password = "Abc234hg";
String urlUsername = null;
String urlPassword = "Abc234hg";
pb.addUser(Username,Password);
sessionID = pb.loginUser(Username,Password);
try{
URL url = new URL ("http:AlexTinaAbc234hg");
pb.updateDetails(sessionID,url,urlUsername,urlPassword);
pb.retrieveDetails(sessionID,url);
}
catch (NoSuchURLException e){
NoSuchURLException = true;
}
assertTrue(NoSuchURLException);
}
//NoSuchURLException
// pair = null
@Test public void NoSuchURLExceptionPair() throws WeakPassphraseException, DuplicateUserException, NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, InvalidSessionIDException, MalformedURLException, NoSuchURLException {
boolean NoSuchURLException = false;
Integer sessionID ;
String Username = "AlexTina";
String Password = "Abc234hg";
String urlUsername = "AlexTina";
String urlPassword = "Abc234hg";
pb.addUser(Username,Password);
sessionID = pb.loginUser(Username,Password);
try{
URL url = new URL ("http:AlexTinaAbc234hg");
pb.retrieveDetails(sessionID,url);
}
catch (NoSuchURLException e){
NoSuchURLException = true;
}
assertTrue(NoSuchURLException);
}
//pair != null
@Test public void NoSuchURLExceptionPair2() throws WeakPassphraseException, DuplicateUserException, NoSuchUserException, AlreadyLoggedInException, IncorrectPassphraseException, InvalidSessionIDException, MalformedURLException, NoSuchURLException {
boolean NoSuchURLException = false;
Integer sessionID ;
String Username = "AlexTina";
String Password = "Abc234hg";
String urlUsername = "AlexTina";
String urlPassword = "Abc234hg";
pb.addUser(Username,Password);
sessionID = pb.loginUser(Username,Password);
try{
URL url = new URL ("http:AlexTinaAbc234hg");
pb.updateDetails(sessionID,url,urlUsername,urlPassword);
pb.retrieveDetails(sessionID,url);
}
catch (NoSuchURLException e){
NoSuchURLException = true;
}
assertFalse(NoSuchURLException);
}
@Test public void aTest()
{
//the assertEquals method used to check whether two values are
//equal, using the equals method
final int expected = 2;
final int actual = 1 + 1;
assertEquals(expected, actual);
}
//To test an exception, specify the expected exception after the @Test
@Test(expected = java.io.IOException.class)
public void anExceptionTest()
throws Throwable
{
throw new java.io.IOException();
}
//This test should fail.
//To provide additional feedback when a test fails, an error message
//can be included
}