Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package com.wso2telco.core.dbutils.dao;


import com.wso2telco.core.dbutils.Operator;
import com.wso2telco.core.dbutils.dao.SpendLimitDAO;
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class SpendLimitDAOTest {

private SpendLimitDAO spendlimit = null;

@BeforeClass
public void init() {
spendlimit=new SpendLimitDAO();
spendlimit.setGroupName("group");
spendlimit.setConsumerKey("consumerkey");
spendlimit.setOperatorId("OperatorId");
spendlimit.setMsisdn("134-678");
spendlimit.setAmount(1000.0);
spendlimit.setCurrentDateTime("2019/09/20");
spendlimit.setResponseTime(12);
}

@Test(groups = "spendlimit")
public void testGroupName_whenCorrectValues() {
String expected = "group";
String actual = spendlimit.getGroupName();
Assert.assertEquals(actual, expected);
}


@Test(groups = "spendlimit")
public void testGroupName_whenWrongValues() {
String expected = "groupWrong";
String actual = spendlimit.getGroupName();
Assert.assertNotEquals(actual, expected);
}


@Test(groups = "spendlimit")
public void testConsumerKey_whenCorrectValues() {
String expected = "consumerkey";
String actual = spendlimit.getConsumerKey();
Assert.assertEquals(actual, expected);
}

@Test(groups = "spendlimit")
public void testConsumerKey_whenWrongValues() {
String expected = "consumerkeyWrong";
String actual = spendlimit.getConsumerKey();
Assert.assertNotEquals(actual, expected);
}

@Test(groups = "spendlimit")
public void testOperator_whenCorrectValues() {
String expected = "OperatorId";
String actual = spendlimit.getOperatorId();
Assert.assertEquals(actual, expected);
}

@Test(groups = "spendlimit")
public void testOperator_whenWrongValues() {
String expected = "OperatorIdWrong";
String actual = spendlimit.getOperatorId();
Assert.assertNotEquals(actual, expected);
}


@Test(groups = "spendlimit")
public void testMsisdn_whenCorrectValues() {
String expected = "134-678";
String actual = spendlimit.getMsisdn();
Assert.assertEquals(actual, expected);
}

@Test(groups = "spendlimit")
public void testMsisdn_whenWrongValues() {
String expected = "134-678-00-wrong";
String actual = spendlimit.getMsisdn();
Assert.assertNotEquals(actual, expected);
}

@Test(groups = "spendlimit")
public void testAmount_whenCorrectValues() {
double expected = 1000.0;
double actual = spendlimit.getAmount();
Assert.assertEquals(actual, expected);
}
@Test(groups = "spendlimit")
public void testAmount_whenWrongValues() {
double expected = 0000.0;
double actual = spendlimit.getAmount();
Assert.assertNotEquals(actual, expected);
}

@Test(groups = "spendlimit")
public void testCurrentDateTime_whenCorrectValues() {
String expected = "2019/09/20";
String actual = spendlimit.getCurrentDateTime();
Assert.assertEquals(actual, expected);
}


@Test(groups = "spendlimit")
public void testCurrentDateTime_whenWrongValues() {
String expected = "2019/00/00";
String actual = spendlimit.getCurrentDateTime();
Assert.assertNotEquals(actual, expected);
}

@Test(groups = "spendlimit")
public void testResponses_whenCorrectValues() {
long expected = 12;
long actual = spendlimit.getResponseTime();
Assert.assertEquals(actual, expected);
}
@Test(groups = "spendlimit")
public void testResponses_whenWrongValues() {
long expected = 00;
long actual = spendlimit.getResponseTime();
Assert.assertNotEquals(actual, expected);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.wso2telco.core.dbutils.exception;

import com.wso2telco.dbutils.Operator;
import org.assertj.core.api.Assertions;
import org.mockito.Mockito;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.testng.asserts.Assertion;

import static org.testng.Assert.*;

public class GenaralErrorTest {



@Test
public void testMessage_whenCorrectValues() {
Assertions.assertThat(GenaralError.UNDEFINED.getMessage()).isEqualTo("Undefined Error");
Assertions.assertThat(GenaralError.AUTH_HEADER_NULL.getMessage()).isEqualTo("Auth Header is null");
Assertions.assertThat(GenaralError.INTERNAL_SERVER_ERROR.getMessage()).isEqualTo("Internal Server Error");
Assertions.assertThat(GenaralError.INVALID_AUTH_HEADER.getMessage()).isEqualTo("Auth Header needs to be Basic encodeBase64(username:password)");

}

@Test
public void testMessage_whenWrongValues() {
Assertions.assertThat(GenaralError.UNDEFINED.getMessage()).isNotEqualTo("Undefined Error_wrong");
Assertions.assertThat(GenaralError.AUTH_HEADER_NULL.getMessage()).isNotEqualTo("Auth Header is null_wrong");
Assertions.assertThat(GenaralError.INTERNAL_SERVER_ERROR.getMessage()).isNotEqualTo("Internal Server Error_wrong");
Assertions.assertThat(GenaralError.INVALID_AUTH_HEADER.getMessage()).isNotEqualTo("Auth Header needs to be Basic encodeBase64(username:password)_wrong");

}

@Test
public void testCode_whenCorrectValues() {
Assertions.assertThat(GenaralError.UNDEFINED.getCode()).isEqualTo("CORE0001");
Assertions.assertThat(GenaralError.AUTH_HEADER_NULL.getCode()).isEqualTo("CORE0300");
Assertions.assertThat(GenaralError.INTERNAL_SERVER_ERROR.getCode()).isEqualTo("CORE0299");
Assertions.assertThat(GenaralError.INVALID_AUTH_HEADER.getCode()).isEqualTo("CORE0301");

}
@Test
public void testCode_whenWrongValues() {
Assertions.assertThat(GenaralError.UNDEFINED.getCode()).isNotEqualTo("CORE0001 _wrong");
Assertions.assertThat(GenaralError.AUTH_HEADER_NULL.getCode()).isNotEqualTo("CORE0300 _wrong");
Assertions.assertThat(GenaralError.INTERNAL_SERVER_ERROR.getCode()).isNotEqualTo("CORE0299 _wrong");
Assertions.assertThat(GenaralError.INVALID_AUTH_HEADER.getCode()).isNotEqualTo("CORE0301 _wrong");

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.wso2telco.core.dbutils.exception;

import org.assertj.core.api.Assertions;
import org.testng.annotations.Test;

import static org.testng.Assert.*;

public class PolicyErrorTest {

@Test
public void testMessage_whenCorrectValues() {
Assertions.assertThat(PolicyError.TOO_MANY_ADDRESSES_SPECIFIED.getMessage()).isEqualTo("Too many addresses specified in message part %1");
Assertions.assertThat(PolicyError.DUPLICATED_ADDRESS.getMessage()).isEqualTo("Duplicated addresses");
Assertions.assertThat(PolicyError.NO_VALID_SERVICES_AVAILABLE.getMessage()).isEqualTo("No Valid Services Available");

}

@Test
public void testMessage_whenWrongValues() {
Assertions.assertThat(PolicyError.TOO_MANY_ADDRESSES_SPECIFIED.getMessage()).isNotEqualTo("Too many addresses specified in message part %1 _wrong");
Assertions.assertThat(PolicyError.DUPLICATED_ADDRESS.getMessage()).isNotEqualTo("Duplicated addresses _wrong");
Assertions.assertThat(PolicyError.NO_VALID_SERVICES_AVAILABLE.getMessage()).isNotEqualTo("No Valid Services Available _wrong");

}

@Test
public void testGetCode_whenCorrectValues() {
Assertions.assertThat(PolicyError.TOO_MANY_ADDRESSES_SPECIFIED.getCode()).isEqualTo("POL0003");
Assertions.assertThat(PolicyError.DUPLICATED_ADDRESS.getCode()).isEqualTo("POL0013");
Assertions.assertThat(PolicyError.NO_VALID_SERVICES_AVAILABLE.getCode()).isEqualTo("POL0014");

}

@Test
public void testGetCode_whenWrongValues() {
Assertions.assertThat(PolicyError.TOO_MANY_ADDRESSES_SPECIFIED.getCode()).isNotEqualTo("POL0003 _wrong");
Assertions.assertThat(PolicyError.DUPLICATED_ADDRESS.getCode()).isNotEqualTo("POL0013 _wrong");
Assertions.assertThat(PolicyError.NO_VALID_SERVICES_AVAILABLE.getCode()).isNotEqualTo("POL0014 _wrong");

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.wso2telco.core.dbutils.exception;

import org.assertj.core.api.Assertions;
import org.testng.annotations.Test;

import static org.testng.Assert.*;

public class ServiceErrorTest {


@Test
public void testGetMessage_whenCorrectValues() {
Assertions.assertThat(ServiceError.SERVICE_ERROR_OCCURED.getMessage()).isEqualTo("A service error occurred. Error code is %1");
Assertions.assertThat(ServiceError.INVALID_INPUT_VALUE.getMessage()).isEqualTo("Invalid input value for message part %1");
Assertions.assertThat(ServiceError.INVALID_ADDRESS.getMessage()).isEqualTo("No valid addresses provided in message part %1");
Assertions.assertThat(ServiceError.NO_RESOURCES.getMessage()).isEqualTo("No resources");
}

@Test
public void testGetMessage_whenWrongValues() {
Assertions.assertThat(ServiceError.SERVICE_ERROR_OCCURED.getMessage()).isNotEqualTo("A service error occurred. Error code is %1 _positive");
Assertions.assertThat(ServiceError.INVALID_INPUT_VALUE.getMessage()).isNotEqualTo("Invalid input value for message part %1 _positive");
Assertions.assertThat(ServiceError.INVALID_ADDRESS.getMessage()).isNotEqualTo("No valid addresses provided in message part %1 _positive");
Assertions.assertThat(ServiceError.NO_RESOURCES.getMessage()).isNotEqualTo("No resources _postie");
}

@Test
public void testGetCode_whenCorrectValues() {
Assertions.assertThat(ServiceError.SERVICE_ERROR_OCCURED.getCode()).isEqualTo("SVC0001");
Assertions.assertThat(ServiceError.INVALID_INPUT_VALUE.getCode()).isEqualTo("SVC0002");
Assertions.assertThat(ServiceError.INVALID_ADDRESS.getCode()).isEqualTo("SVC0004");
Assertions.assertThat(ServiceError.NO_RESOURCES.getCode()).isEqualTo("SVC1000");

}
@Test
public void testGetCode_whenWrongValues() {
Assertions.assertThat(ServiceError.SERVICE_ERROR_OCCURED.getCode()).isNotEqualTo("SVC0001 _postive");
Assertions.assertThat(ServiceError.INVALID_INPUT_VALUE.getCode()).isNotEqualTo("SVC0002 _postive");
Assertions.assertThat(ServiceError.INVALID_ADDRESS.getCode()).isNotEqualTo("SVC0004 _postive");
Assertions.assertThat(ServiceError.NO_RESOURCES.getCode()).isNotEqualTo("SVC1000 _positive");

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.wso2telco.core.dbutils.model;


import com.wso2telco.dbutils.Operator;
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import static org.testng.Assert.*;

public class FederatedIdpMappingDTOTest {

private FederatedIdpMappingDTO federatedIdpMappingDTO = null;
@BeforeTest
public void init(){
federatedIdpMappingDTO= Mockito.mock(FederatedIdpMappingDTO.class);
}

@Test
public void testOperator_whenCorrectValues() {
String expected = "Operator";
federatedIdpMappingDTO.setOperator(expected);
Mockito.when(federatedIdpMappingDTO.getOperator()).thenReturn(expected);
Assert.assertEquals(federatedIdpMappingDTO.getOperator(), expected);
}

@Test
public void testOperator_whenWrongValues() {
String expected = "Operator";
Mockito.when(federatedIdpMappingDTO.getOperator()).thenReturn("WrongOperator");
Assert.assertNotEquals(federatedIdpMappingDTO.getOperator(), expected);
}



@Test
public void testFidpAuthCode_whenCorrectValues() {
String expected = "edcxwrtuhvkfpo56jfk";
federatedIdpMappingDTO.setFidpAuthCode(expected);
Mockito.when(federatedIdpMappingDTO.getFidpAuthCode()).thenReturn(expected);
Assert.assertEquals(federatedIdpMappingDTO.getFidpAuthCode(), expected);
}


@Test
public void testFidpAuthCode_whenWrongValues() {
String expected = "edcxwrtuhvkfpo56jfk";
federatedIdpMappingDTO.setFidpAuthCode(expected);
Mockito.when(federatedIdpMappingDTO.getFidpAuthCode()).thenReturn("WrongValues");
Assert.assertNotEquals(federatedIdpMappingDTO.getFidpAuthCode(), expected);
}




@Test
public void testFidpAccessToken_whenCorrectValues() {
String expected = "edcxwrtuhvkfpo56jfk";
federatedIdpMappingDTO.setFidpAccessToken(expected);
Mockito.when(federatedIdpMappingDTO.getFidpAccessToken()).thenReturn(expected);
Assert.assertEquals(federatedIdpMappingDTO.getFidpAccessToken(), expected);
}

@Test
public void testFidpAccessToken_whenWrongValues() {
String expected = "edcxwrtuhvkfpo56jfk";
federatedIdpMappingDTO.setFidpAccessToken(expected);
Mockito.when(federatedIdpMappingDTO.getFidpAccessToken()).thenReturn("WrongToken");
Assert.assertNotEquals(federatedIdpMappingDTO.getFidpAccessToken(), expected);
}

@Test
public void testAccessToken_whenCorrectValues() {
String expected = "edcxwrtuhvkfpo56jfk";
federatedIdpMappingDTO.setAccessToken(expected);
Mockito.when(federatedIdpMappingDTO.getAccessToken()).thenReturn(expected);
Assert.assertEquals(federatedIdpMappingDTO.getAccessToken(), expected);
}

@Test
public void testAccessToken_whenWrongValues() {
String expected = "edcxwrtuhvkfpo56jfk";
federatedIdpMappingDTO.setAccessToken(expected);
Mockito.when(federatedIdpMappingDTO.getAccessToken()).thenReturn("WrongValues");
Assert.assertNotEquals(federatedIdpMappingDTO.getAccessToken(), expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.wso2telco.dbutils;

import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.Test;

import static org.testng.Assert.*;

public class JdbcExceptionTest {

@Test
public void testHandle_whenCorrectValues() {

JdbcException jdbcex=Mockito.mock(JdbcException.class);
Mockito.when(jdbcex.getMessage()).thenReturn("Error Message");
Assert.assertEquals("Error Message", jdbcex.getMessage());
}

@Test
public void testHandle_whenWrongValues() {

JdbcException jdbcex=Mockito.mock(JdbcException.class);
Mockito.when(jdbcex.getMessage()).thenReturn("Wrong Message");
Assert.assertNotEquals("Error Message", jdbcex.getMessage());
}

@Test
public void testHandleExpectedErr() {

Exception e=new RuntimeException("Hi Error");
JdbcException jdbcex=new JdbcException(e);
Assert.assertEquals("Hi Error", jdbcex.getMessage());
}
}
Loading