1919 */
2020package it
2121
22+ import arrow.core.getOrElse
2223import com.atlassian.jira.component.ComponentAccessor
2324import com.atlassian.plugins.osgi.test.AtlassianPluginsTestRunner
2425import com.linkedplanet.kotlininsightclient.InsightClientTest
2526import com.linkedplanet.kotlininsightclient.api.interfaces.*
26- import com.linkedplanet.kotlininsightclient.sdk.SdkInsightAttachmentOperator
27- import com.linkedplanet.kotlininsightclient.sdk.SdkInsightHistoryOperator
28- import com.linkedplanet.kotlininsightclient.sdk.SdkInsightObjectOperator
29- import com.linkedplanet.kotlininsightclient.sdk.SdkInsightObjectTypeOperator
30- import com.linkedplanet.kotlininsightclient.sdk.SdkInsightSchemaOperator
27+ import com.linkedplanet.kotlininsightclient.sdk.*
28+ import junit.framework.TestCase.assertTrue
29+ import kotlinx.coroutines.runBlocking
30+ import org.hamcrest.CoreMatchers.equalTo
31+ import org.hamcrest.MatcherAssert.assertThat
3132import org.junit.Before
33+ import org.junit.Test
3234import org.junit.runner.RunWith
3335
3436@RunWith(AtlassianPluginsTestRunner ::class )
@@ -48,4 +50,84 @@ class InsightSdkClientTest : InsightClientTest() {
4850 val admin = userManager.getUserByName(" admin" )
4951 jiraAuthenticationContext.loggedInUser = admin
5052 }
53+
54+ data class AttributeValueTestData (
55+ val name : String ,
56+ val objectTypeId : Int ,
57+ val attributeId : Int ,
58+ val query : String ,
59+ val exceptionList : String? ,
60+ val page : Int ,
61+ val pageSize : Int ,
62+ val expectedResults : List <String >
63+ )
64+
65+
66+ @Test
67+ fun test1InsightAttributeValuesForTypes () = runBlocking {
68+ val attributeValueTestData = listOf (
69+ AttributeValueTestData (" TEXT" , 47 , 116 , " " , null , 1 , 10 , listOf (" TEXT1" )),
70+ AttributeValueTestData (" INT" , 47 , 117 , " " , null , 1 , 10 , listOf (" 1" )),
71+ AttributeValueTestData (" FLOAT" , 47 , 118 , " " , null , 1 , 10 , listOf (" 1.0" )),
72+ AttributeValueTestData (" DATE" , 47 , 119 , " " , null , 1 , 10 , listOf (" 1/Jan/25" )),
73+ AttributeValueTestData (" DATETIME" , 47 , 120 , " " , null , 1 , 10 , listOf (" 01/Jan/25 12:00 AM" )),
74+ AttributeValueTestData (" URL" , 47 , 121 , " " , null , 1 , 10 , listOf (" http://localhost:0001/" )),
75+ AttributeValueTestData (
" EMAIL" ,
47 ,
122 ,
" " ,
null ,
1 ,
10 ,
listOf (
" [email protected] " )),
76+ AttributeValueTestData (" TEXTAREA" , 47 , 123 , " " , null , 1 , 10 , listOf (" <p>TEXTAREA_1</p>" )),
77+ AttributeValueTestData (" SELECT" , 47 , 124 , " " , null , 1 , 10 , listOf (" 1" )),
78+ AttributeValueTestData (" MULTISELECT" , 47 , 125 , " " , null , 1 , 10 , listOf (" 1" , " 2" )),
79+ AttributeValueTestData (" IPADDRESS" , 47 , 126 , " " , null , 1 , 10 , listOf (" 1.1.1.1" )),
80+ AttributeValueTestData (" USER" , 47 , 127 , " " , null , 1 , 10 , listOf (" test1" )),
81+ AttributeValueTestData (" USERS" , 47 , 128 , " " , null , 1 , 10 , listOf (" test1" , " test2" )),
82+ AttributeValueTestData (" GROUP" , 47 , 129 , " " , null , 1 , 10 , listOf (" jira-software-users" )),
83+ AttributeValueTestData (" GROUPS" , 47 , 130 , " " , null , 1 , 10 , listOf (" jira-administrators" , " jira-software-users" )),
84+ AttributeValueTestData (" PROJECT" , 47 , 131 , " " , null , 1 , 10 , listOf (" Test" )),
85+ AttributeValueTestData (" PROJECTS" , 47 , 132 , " " , null , 1 , 10 , listOf (" Test" )),
86+ AttributeValueTestData (" REF" , 47 , 133 , " " , null , 1 , 10 , listOf (" Test AG" )),
87+ AttributeValueTestData (" REFS" , 47 , 134 , " " , null , 1 , 10 , listOf (" Test AG" , " Test GmbH" )),
88+ )
89+ attributeValueTestData.forEach { data ->
90+ check(data)
91+ }
92+ }
93+
94+ @Test
95+ fun test2InsightAttributeValuesWithFilter () = runBlocking {
96+ val tests = listOf (
97+ AttributeValueTestData (
98+ " GetPage1" , 5 , 24 , " " , null , 1 , 10 ,
99+ listOf (" 1" , " 2" , " 3" , " 4" , " 5" , " 6" , " 7" , " 8" , " 9" , " 10" )
100+ ),
101+ AttributeValueTestData (
102+ " GetPage2" , 5 , 24 , " " , null , 2 , 10 ,
103+ listOf (" 11" , " 12" , " 13" , " 14" , " 15" , " 16" , " 17" , " 18" , " 19" , " 20" )
104+ ),
105+ AttributeValueTestData (
106+ " Filter" , 5 , 24 , " 2" , null , 1 , 10 ,
107+ listOf (" 2" , " 12" , " 20" , " 21" , " 22" , " 23" , " 24" , " 25" , " 26" , " 27" )
108+ ),
109+ AttributeValueTestData (
110+ " ExceptionsAndFilter" , 5 , 24 , " 2" , " 2,20" , 1 , 10 ,
111+ listOf (" 12" , " 21" , " 22" , " 23" , " 24" , " 25" , " 26" , " 27" , " 28" , " 29" )
112+ ),
113+ )
114+ tests.forEach { testData ->
115+ check(testData)
116+ }
117+ }
118+
119+ private suspend fun check (attributeValueTestData : AttributeValueTestData ) {
120+ val result: List <String > = SdkInsightObjectOperator .getAttributeValues(
121+ attributeValueTestData.objectTypeId,
122+ attributeValueTestData.attributeId,
123+ attributeValueTestData.query,
124+ attributeValueTestData.exceptionList,
125+ attributeValueTestData.page,
126+ attributeValueTestData.pageSize
127+ ).getOrElse { error ->
128+ assertTrue(" ${attributeValueTestData.name} returned Either.Left!" , false )
129+ return
130+ }.results
131+ assertThat(" ${attributeValueTestData.name} test did not pass!" , result, equalTo(attributeValueTestData.expectedResults))
132+ }
51133}
0 commit comments