This is the codeAbility Sharing Platform! Learn more about the
codeAbility Sharing Platform
.
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
codeAbility Sharing Platform
Manage
Activity
Members
Labels
Plan
Issues
43
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
development
sharing
codeAbility Sharing Platform
Commits
f22cdb92
Commit
f22cdb92
authored
3 years ago
by
Daniel Crazzolara
Browse files
Options
Downloads
Patches
Plain Diff
Added tests
parent
47f0f5a7
2 merge requests
!91
Bringing JHipster7.6.0 to production
,
!81
Bugfix/#224 export to artemis public visibility
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/at/ac/uibk/gitsearch/service/SearchServiceIT.java
+67
-10
67 additions, 10 deletions
...st/java/at/ac/uibk/gitsearch/service/SearchServiceIT.java
with
67 additions
and
10 deletions
src/test/java/at/ac/uibk/gitsearch/service/SearchServiceIT.java
+
67
−
10
View file @
f22cdb92
...
...
@@ -12,20 +12,29 @@ import static org.hamcrest.Matchers.is;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
mockito
.
Mockito
.
*
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.
util.Collection
;
import
java.
util.Collection
s
;
import
java.util.
List
;
import
java.
io.InputStream
;
import
java.
nio.charset.StandardCharset
s
;
import
java.util.
*
;
import
at.ac.uibk.gitsearch.repository.gitlab.GitLabRepository
;
import
at.ac.uibk.gitsearch.security.jwt.TokenProvider
;
import
at.ac.uibk.gitsearch.web.rest.WithUnauthenticatedMockUser
;
import
org.codeability.sharing.plugins.api.SharingPluginConfig
;
import
org.codeability.sharing.plugins.api.search.SearchInputDTO
;
import
org.codeability.sharing.plugins.api.search.SearchInputMetadataDTO
;
import
org.codeability.sharing.plugins.api.search.SearchResultDTO
;
import
org.codeability.sharing.plugins.api.search.SearchResultsDTO
;
import
org.elasticsearch.client.RestHighLevelClient
;
import
org.elasticsearch.node.NodeValidationException
;
import
org.gitlab4j.api.GitLabApi
;
import
org.gitlab4j.api.GitLabApiException
;
import
org.gitlab4j.api.RepositoryApi
;
import
org.junit.Assert
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.BeforeAll
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -41,6 +50,8 @@ import at.ac.uibk.gitsearch.repository.search.testESService.ElasticSearchTestSer
import
at.ac.uibk.gitsearch.service.PluginManagementService.ConnectorConfigWrapper
;
import
at.ac.uibk.gitsearch.service.dto.AutoCompleteEntry
;
import
javax.ws.rs.NotFoundException
;
@SpringBootTest
(
classes
=
GitsearchApp
.
class
)
@WithMockUser
(
value
=
TEST_USER_LOGIN
,
authorities
=
"sharing"
)
public
class
SearchServiceIT
{
...
...
@@ -51,7 +62,13 @@ public class SearchServiceIT {
@MockBean
PluginManagementService
pluginManagementService
;
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
SearchServiceIT
.
class
);
@MockBean
GitLabRepository
gitLabRepository
;
@MockBean
RepositoryApi
mockedRepositoryApi
;
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
SearchServiceIT
.
class
);
@Autowired
private
SearchService
searchService
;
...
...
@@ -63,11 +80,15 @@ public class SearchServiceIT {
@BeforeEach
public
void
initMock
()
{
Collection
<
ConnectorConfigWrapper
>
mockConfigs
=
Collections
.
singletonList
(
new
ConnectorConfigWrapper
(
new
SharingPluginConfig
(
"mockedPlugin"
,
new
SharingPluginConfig
.
Action
[]
{
new
SharingPluginConfig
.
Action
(
"mockedAction"
,
"http://unused/unused-transferURL"
,
"mocked Action"
,
"true"
)
}),
"http://unused/hopefully-unused"
)
);
Collection
<
ConnectorConfigWrapper
>
mockConfigs
=
new
ArrayList
<>();
mockConfigs
.
add
(
new
ConnectorConfigWrapper
(
new
SharingPluginConfig
(
"mockedPlugin"
,
new
SharingPluginConfig
.
Action
[]
{
new
SharingPluginConfig
.
Action
(
"mockedAction"
,
"http://unused/unused-transferURL"
,
"mocked Action"
,
"true"
)
}),
"http://unused/hopefully-unused"
));
mockConfigs
.
add
(
new
ConnectorConfigWrapper
(
new
SharingPluginConfig
(
"Artemis Sharing Connector"
,
new
SharingPluginConfig
.
Action
[]
{
new
SharingPluginConfig
.
Action
(
"Import"
,
"http://unused/unused-transferURL"
,
"Export to Artemis"
,
"true"
)
}),
"http://unused/hopefully-unused"
));
when
(
pluginManagementService
.
getRegisteredPluginConfigs
()).
thenReturn
(
mockConfigs
);
}
...
...
@@ -250,4 +271,40 @@ public class SearchServiceIT {
final
List
<
AutoCompleteEntry
>
contributorAutoComplete
=
searchService
.
getContributorCreatorAutoComplete
(
"Bast"
,
10
);
assertThat
(
contributorAutoComplete
,
contains
(
hasProperty
(
"target"
,
is
(
"Daniel Bastta"
))));
}
@Test
public
void
testArtemisExportActionFilteringForAuthorizedUser
()
throws
IOException
,
GitLabApiException
{
GitLabApi
mockedGitLabApi
=
mock
(
GitLabApi
.
class
);
when
(
gitLabRepository
.
getGitLabApi
(
any
(
Optional
.
class
))).
thenReturn
(
mockedGitLabApi
);
doReturn
(
mockedRepositoryApi
).
when
(
mockedGitLabApi
).
getRepositoryApi
();
doReturn
(
new
ByteArrayInputStream
(
" "
.
getBytes
())).
when
(
mockedRepositoryApi
).
getRepositoryArchive
(
eq
(
333
),
anyString
(),
anyString
());
final
SearchInputMetadataDTO
searchMetadata
=
new
SearchInputMetadataDTO
(
null
,
null
,
null
,
null
,
null
,
null
);
SearchInputDTO
searchQuery
=
new
SearchInputDTO
(
null
,
searchMetadata
,
null
,
null
,
null
,
0
);
SearchResultsDTO
results
=
searchService
.
searchResultPage
(
searchQuery
);
Optional
<
SearchResultDTO
>
result
=
results
.
getSearchResult
().
stream
().
filter
(
entry
->
entry
.
getExerciseId
().
equals
(
"333"
)).
findFirst
();
if
(
result
.
isEmpty
())
{
throw
new
NotFoundException
(
"Exercise with publicVisibility and id '333' couldn't be found in the test data"
);
}
Assertions
.
assertTrue
(
result
.
get
().
getSupportedActions
().
stream
().
anyMatch
(
action
->
action
.
getPlugin
().
equals
(
"Artemis Sharing Connector"
)));
}
@Test
@WithMockUser
(
value
=
"User without authorities"
)
public
void
testArtemisExportActionFilteringForUnauthorizedUser
()
throws
IOException
{
final
SearchInputMetadataDTO
searchMetadata
=
new
SearchInputMetadataDTO
(
null
,
null
,
null
,
null
,
null
,
null
);
SearchInputDTO
searchQuery
=
new
SearchInputDTO
(
null
,
searchMetadata
,
null
,
null
,
null
,
0
);
SearchResultsDTO
results
=
searchService
.
searchResultPage
(
searchQuery
);
Optional
<
SearchResultDTO
>
result
=
results
.
getSearchResult
().
stream
().
filter
(
entry
->
entry
.
getExerciseId
().
equals
(
"333"
)).
findFirst
();
if
(
result
.
isEmpty
())
{
throw
new
NotFoundException
(
"Exercise with publicVisibility and id '333' couldn't be found in the test data"
);
}
Assertions
.
assertFalse
(
result
.
get
().
getSupportedActions
().
stream
().
anyMatch
(
action
->
action
.
getPlugin
().
equals
(
"Artemis Sharing Connector"
)));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment