Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
ejercicio2-framework-back
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Josue
ejercicio2-framework-back
Commits
eeef89c5
Commit
eeef89c5
authored
Sep 15, 2020
by
huriarte
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pruebas Unitarias para Subida de Archivos
parent
0631a1b3
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
586 additions
and
278 deletions
+586
-278
pom.xml
pom.xml
+382
-278
AgentControllerTest.java
...va/com/bytesw/bytebot/controller/AgentControllerTest.java
+105
-0
application-config.xml
src/test/resources/application-config.xml
+19
-0
application.yml
src/test/resources/application.yml
+49
-0
applicationContext-scheduler.xml
src/test/resources/applicationContext-scheduler.xml
+25
-0
init.sql
src/test/resources/init.sql
+6
-0
No files found.
pom.xml
View file @
eeef89c5
This diff is collapsed.
Click to expand it.
src/test/java/com/bytesw/bytebot/controller/AgentControllerTest.java
0 → 100644
View file @
eeef89c5
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
com
.
bytesw
.
bytebot
.
controller
;
import
com.bytesw.bytebot.service.AgentService
;
import
com.bytesw.bytebot.service.FileManagementService
;
import
com.bytesw.xdf.config.security.annotation.DummyPermissionEvaluator
;
import
java.io.IOException
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
org.mockito.Mockito
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
import
org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
;
import
org.springframework.boot.test.context.TestConfiguration
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.security.test.context.support.WithMockUser
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.mock.web.MockMultipartFile
;
import
org.springframework.test.web.servlet.request.MockMvcRequestBuilders
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
/**
* @author Hernán Uriarte Melchor
* @date 14/09/2020.
* <p>
* <p>
* Copyright (c) 2018 Byte, S.A. Todos los derechos reservados.
* <p>
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
@WebMvcTest
(
controllers
=
AgentController
.
class
)
@ActiveProfiles
(
value
=
"test"
)
@AutoConfigureMockMvc
(
secure
=
false
)
public
class
AgentControllerTest
{
public
static
String
baseService
=
"/service/agent"
;
@TestConfiguration
static
class
UserServiceTestContextConfiguration
{
@Bean
DummyPermissionEvaluator
dummyPermissionEvaluator
()
{
return
new
DummyPermissionEvaluator
();
}
}
@Autowired
private
MockMvc
mvc
;
@MockBean
private
AgentService
agentService
;
@MockBean
private
FileManagementService
fileManagementService
;
@Before
public
void
setUp
()
{
}
@Test
@WithMockUser
(
username
=
"admin"
,
roles
={
"USER"
,
"ADMIN"
})
public
void
uploadFile_whenFileXLS_isOK
()
throws
Exception
{
MockMultipartFile
xlsFile
=
new
MockMultipartFile
(
"file"
,
"my-xls-file.xls"
,
"application/vnd.ms-excel"
,
"my-xls-file"
.
getBytes
());
mvc
.
perform
(
MockMvcRequestBuilders
.
multipart
(
baseService
+
"/file-upload"
)
.
file
(
xlsFile
))
.
andExpect
(
status
().
isOk
());
}
@Test
@WithMockUser
(
username
=
"admin"
,
roles
={
"USER"
,
"ADMIN"
})
public
void
uploadFile_whenFileXLSNotAppropriate_throwException
()
throws
Exception
{
MockMultipartFile
xlsFile
=
new
MockMultipartFile
(
"file"
,
"my-xls-file.xls"
,
"application/vnd.ms-excel"
,
"my-xls-file"
.
getBytes
());
Mockito
.
when
(
fileManagementService
.
validateAndSaveFile
(
anyString
(),
eq
(
xlsFile
)
))
.
thenThrow
(
IOException
.
class
);
mvc
.
perform
(
MockMvcRequestBuilders
.
multipart
(
baseService
+
"/file-upload"
)
.
file
(
xlsFile
))
.
andExpect
(
status
().
isInternalServerError
());
}
}
src/test/resources/application-config.xml
0 → 100644
View file @
eeef89c5
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=
"http://www.springframework.org/schema/context"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
>
<!--<import resource="classpath:applicationContext-aop.xml" />-->
<import
resource=
"classpath:applicationContext-scheduler.xml"
/>
<!-- MyBatis stuff -->
<!--
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:/mybatis-config.xml" />
</bean>
-->
</beans>
src/test/resources/application.yml
0 → 100644
View file @
eeef89c5
spring.autoconfigure.exclude
:
org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration
server
:
servlet.context-path
:
/tenant-server
port
:
9443
ssl
:
key-store-type
:
JKS
key-store
:
'
classpath:keystore.jks'
key-store-password
:
changeit
key-alias
:
tomcat
security
:
require-ssl
:
true
basic
:
enabled
:
false
application
:
services
:
security
:
none
api.info
:
title
:
'
byteXDF4Java
Service'
description
:
'
API
para
el
desarrollo
de
software'
version
:
'
1.0.0'
terms-of-service-url
:
'
https://es.wikipedia.org/wiki/byteXDF4Java'
license
:
'
Open
source
licensing'
license-url
:
'
https://help.github.com/articles/open-source-licensing/'
spring
:
application
:
name
:
tenant-server
datasource
:
driver-class-name
:
org.h2.Driver
url
:
jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
username
:
sa
password
:
sa
minimum-idle
:
10
maximum-pool-size
:
10
validationQuery
:
SELECT 1
testWhileIdle
:
true
hikari.registerMbeans
:
true
jpa
:
properties.hibernate.dialect
:
org.hibernate.dialect.H2Dialect
show-sql
:
true
logging.level.root
:
info
logging.pattern.console
:
'
%d{dd-MM-yyyy
HH:mm:ss.SSS}
%magenta([%thread])
%highlight(%-5level)
%logger.%M
-
%msg%n'
logging.level.com.bytesw
:
debug
\ No newline at end of file
src/test/resources/applicationContext-scheduler.xml
0 → 100644
View file @
eeef89c5
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:oauth=
"http://www.springframework.org/schema/security/oauth2"
xmlns:sec=
"http://www.springframework.org/schema/security"
xmlns:task=
"http://www.springframework.org/schema/task"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
"
>
<bean
id=
"threadPoolTaskExecutor"
class=
"org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"
>
<property
name=
"corePoolSize"
value=
"2"
/>
<property
name=
"maxPoolSize"
value=
"5"
/>
<property
name=
"queueCapacity"
value=
"5"
/>
<property
name=
"waitForTasksToCompleteOnShutdown"
value=
"true"
/>
<property
name=
"rejectedExecutionHandler"
>
<bean
class=
"java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy"
/>
</property>
</bean>
</beans>
\ No newline at end of file
src/test/resources/init.sql
0 → 100644
View file @
eeef89c5
CREATE
TABLE
SEQUENCE_TABLE
(
SEQ_NAME
VARCHAR
(
50
)
NOT
NULL
,
SEQ_COUNT
INTEGER
DEFAULT
0
,
PRIMARY
KEY
(
SEQ_NAME
));
INSERT
SEQUENCE_TABLE
(
SEQ_NAME
,
SEQ_COUNT
)
VALUES
(
'USER_SEQ'
,
0
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment