-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Galactus22625/Jira-Unit-Tests
Jira unit tests
- Loading branch information
Showing
8 changed files
with
328 additions
and
1 deletion.
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
...rg/opensearch/dataprepper/plugins/source/saas/jira/exception/BadRequestExceptionTest.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,54 @@ | ||
package org.opensearch.dataprepper.plugins.source.saas.jira.exception; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class BadRequestExceptionTest { | ||
private String message; | ||
private Throwable throwable; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
message = "Bad Request"; | ||
throwable = mock(Throwable.class); | ||
} | ||
|
||
@Nested | ||
class MessageOnlyConstructor { | ||
private BadRequestException createObjectUnderTest() { | ||
return new BadRequestException(message); | ||
} | ||
|
||
@Test | ||
void getMessage_returns_message() { | ||
assertEquals(createObjectUnderTest().getMessage(), message); | ||
} | ||
|
||
@Test | ||
void getCause_returns_null() { | ||
assertNull(createObjectUnderTest().getCause()); | ||
} | ||
} | ||
|
||
@Nested | ||
class MessageThrowableConstructor { | ||
private BadRequestException createObjectUnderTest() { | ||
return new BadRequestException(message, throwable); | ||
} | ||
|
||
@Test | ||
void getMessage_returns_message() { | ||
assertEquals(createObjectUnderTest().getMessage(), message); | ||
} | ||
|
||
@Test | ||
void getCause_returns_throwable() { | ||
assertEquals(createObjectUnderTest().getCause(), throwable); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
.../opensearch/dataprepper/plugins/source/saas/jira/exception/UnAuthorizedExceptionTest.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,54 @@ | ||
package org.opensearch.dataprepper.plugins.source.saas.jira.exception; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class UnAuthorizedExceptionTest { | ||
private String message; | ||
private Throwable throwable; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
message = "UnAuthorized Exception"; | ||
throwable = mock(Throwable.class); | ||
} | ||
|
||
@Nested | ||
class MessageOnlyConstructor { | ||
private UnAuthorizedException createObjectUnderTest() { | ||
return new UnAuthorizedException(message); | ||
} | ||
|
||
@Test | ||
void getMessage_returns_message() { | ||
assertEquals(createObjectUnderTest().getMessage(), message); | ||
} | ||
|
||
@Test | ||
void getCause_returns_null() { | ||
assertNull(createObjectUnderTest().getCause()); | ||
} | ||
} | ||
|
||
@Nested | ||
class MessageThrowableConstructor { | ||
private UnAuthorizedException createObjectUnderTest() { | ||
return new UnAuthorizedException(message, throwable); | ||
} | ||
|
||
@Test | ||
void getMessage_returns_message() { | ||
assertEquals(createObjectUnderTest().getMessage(), message); | ||
} | ||
|
||
@Test | ||
void getCause_returns_throwable() { | ||
assertEquals(createObjectUnderTest().getCause(), throwable); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...va/org/opensearch/dataprepper/plugins/source/saas/jira/rest/auth/JiraAuthFactoryTest.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,43 @@ | ||
package org.opensearch.dataprepper.plugins.source.saas.jira.rest.auth; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.opensearch.dataprepper.plugins.source.saas.jira.JiraSourceConfig; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
import static org.mockito.Mockito.when; | ||
import static org.opensearch.dataprepper.plugins.source.saas.jira.utils.Constants.OAUTH2; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class JiraAuthFactoryTest { | ||
|
||
@Mock | ||
private JiraSourceConfig sourceConfig; | ||
|
||
private JiraAuthFactory jiraAuthFactory; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
jiraAuthFactory = new JiraAuthFactory(sourceConfig); | ||
} | ||
|
||
@Test | ||
void testGetObjectOauth2(){ | ||
when(sourceConfig.getAuthType()).thenReturn(OAUTH2); | ||
assertInstanceOf(JiraOauthConfig.class, jiraAuthFactory.getObject()); | ||
} | ||
|
||
@Test | ||
void testGetObjectBasicAuth(){ | ||
assertInstanceOf(JiraBasicAuthConfig.class, jiraAuthFactory.getObject()); | ||
} | ||
|
||
@Test | ||
void testGetObjectType(){ | ||
assertEquals(JiraAuthConfig.class, jiraAuthFactory.getObjectType()); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...java/org/opensearch/dataprepper/plugins/source/saas/jira/utils/AddressValidationTest.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,93 @@ | ||
package org.opensearch.dataprepper.plugins.source.saas.jira.utils; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
import org.opensearch.dataprepper.plugins.source.saas.jira.exception.BadRequestException; | ||
|
||
import java.net.InetAddress; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.UnknownHostException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class AddressValidationTest { | ||
|
||
@Test | ||
void testInitialization () { | ||
AddressValidation addressValidation = new AddressValidation(); | ||
assertNotNull(addressValidation); | ||
} | ||
|
||
@Test | ||
void testGetInetAddress(){ | ||
String testUrl = "https://www.amazon.com"; | ||
System.out.print("Test output"); | ||
System.out.print(AddressValidation.getInetAddress(testUrl)); | ||
} | ||
|
||
@Test | ||
void testGetInetAddressWithMalformedUrl(){ | ||
String testUrl = "XXXXXXXXXXXXXXXXXXXXXX"; | ||
assertThrows(BadRequestException.class, () -> AddressValidation.getInetAddress(testUrl)); | ||
} | ||
|
||
@Test | ||
void testGetInetAddressWithUnknownHost(){ | ||
String testUrl = "https://www.thisurldoesntexist1384276t5917278481073.com"; | ||
assertThrows(BadRequestException.class, () -> AddressValidation.getInetAddress(testUrl)); | ||
} | ||
|
||
@Test | ||
void testGetInetAddressWithNullUrl(){ | ||
String testUrl = null; | ||
assertThrows(BadRequestException.class, () -> AddressValidation.getInetAddress(testUrl)); | ||
} | ||
|
||
|
||
@Test | ||
void testValidateInetAddressAnyLocalAddress() throws UnknownHostException { | ||
InetAddress wildcardAddress = InetAddress.getByName("0.0.0.0"); | ||
assertThrows(BadRequestException.class, () -> AddressValidation.validateInetAddress(wildcardAddress)); | ||
} | ||
|
||
@Test | ||
void testValidateInetAddressMulticastAddress() throws UnknownHostException { | ||
InetAddress multicastAddress = InetAddress.getByName("224.0.0.1"); | ||
assertThrows(BadRequestException.class, () -> AddressValidation.validateInetAddress(multicastAddress)); | ||
} | ||
|
||
@Test | ||
void testValidateInetAddressLinkLocalAddress() throws UnknownHostException { | ||
InetAddress linkLocalAddress = InetAddress.getByName("169.254.1.1"); | ||
assertThrows(BadRequestException.class, () -> AddressValidation.validateInetAddress(linkLocalAddress)); | ||
} | ||
|
||
@Test | ||
void testValidateInetAddressSiteLocalAddress() throws UnknownHostException { | ||
InetAddress siteLocalAddress = InetAddress.getByName("10.0.0.1"); | ||
assertThrows(BadRequestException.class, () -> AddressValidation.validateInetAddress(siteLocalAddress)); | ||
} | ||
|
||
@Test | ||
void testValidateInetAddressLoopbackAddress() throws UnknownHostException { | ||
InetAddress loopbackAddress = InetAddress.getByName("127.0.0.1"); | ||
assertThrows(BadRequestException.class, () -> AddressValidation.validateInetAddress(loopbackAddress)); | ||
} | ||
|
||
@Test | ||
void testValidateInetAddressValidAddress() throws UnknownHostException, MalformedURLException { | ||
InetAddress validAddress = InetAddress.getByName(new URL("https://www.amazon.com").getHost()); | ||
assertDoesNotThrow(() -> AddressValidation.validateInetAddress(validAddress)); | ||
} | ||
|
||
@Test | ||
void testValidateInetAddressNullAddress() throws UnknownHostException { | ||
InetAddress nullAddress = null; | ||
assertThrows(NullPointerException.class, () -> AddressValidation.validateInetAddress(nullAddress)); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...rc/test/java/org/opensearch/dataprepper/plugins/source/saas/jira/utils/ConstantsTest.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,17 @@ | ||
package org.opensearch.dataprepper.plugins.source.saas.jira.utils; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class ConstantsTest { | ||
private Constants constants; | ||
|
||
@Test | ||
public void testInitialization() { | ||
constants = new Constants(); | ||
assertNotNull(Constants.SOLUTION_FOR_JIRA_ISSUE_TYPE_FILTER); | ||
assertNotNull(constants); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...est/java/org/opensearch/dataprepper/plugins/source/saas/jira/utils/ExceptionUtilTest.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,39 @@ | ||
package org.opensearch.dataprepper.plugins.source.saas.jira.utils; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class ExceptionUtilTest { | ||
|
||
String errorCode; | ||
String errorMessage; | ||
|
||
private ExceptionUtil exceptionUtil; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
errorCode = "123"; | ||
errorMessage = "Test Error Message"; | ||
} | ||
|
||
@Test | ||
void testInitialization() { | ||
exceptionUtil = new ExceptionUtil(); | ||
assertNotNull(exceptionUtil); | ||
} | ||
|
||
@Test | ||
void errorCodeEnumHandlingTest(){ | ||
assertTrue(ExceptionUtil.getErrorMessage(ErrorCodeEnum.FIELD_SIZE_OVER_MAX_LIMIT).contains("Field Size is more than max limit")); | ||
assertTrue(ExceptionUtil.getErrorMessage(ErrorCodeEnum.ERROR_JIRA_PROJECT_KEY_FILTER).contains("IRA Project Key Filter list size is too large")); | ||
} | ||
|
||
@Test | ||
void errorMessageHandlingTest(){ | ||
assertTrue(ExceptionUtil.getErrorMessage(errorCode, errorMessage).contains(errorCode)); | ||
assertTrue(ExceptionUtil.getErrorMessage(errorCode, errorMessage).contains(errorMessage)); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...t/java/org/opensearch/dataprepper/plugins/source/saas/jira/utils/JiraContentTypeTest.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,26 @@ | ||
package org.opensearch.dataprepper.plugins.source.saas.jira.utils; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class JiraContentTypeTest { | ||
@Test | ||
void testEnumConstants() { | ||
assertNotNull(JiraContentType.PROJECT); | ||
assertNotNull(JiraContentType.ISSUE); | ||
assertNotNull(JiraContentType.COMMENT); | ||
assertNotNull(JiraContentType.ATTACHMENT); | ||
assertNotNull(JiraContentType.WORKLOG); | ||
} | ||
|
||
@Test | ||
void testTypeValues() { | ||
assertEquals("PROJECT", JiraContentType.PROJECT.getType()); | ||
assertEquals("ISSUE", JiraContentType.ISSUE.getType()); | ||
assertEquals("COMMENT", JiraContentType.COMMENT.getType()); | ||
assertEquals("ATTACHMENT", JiraContentType.ATTACHMENT.getType()); | ||
assertEquals("WORKLOG", JiraContentType.WORKLOG.getType()); | ||
} | ||
} |