Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
synergy-api-util
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Raimbek Egemberdiev
synergy-api-util
Commits
61ec53b0
Commit
61ec53b0
authored
Nov 11, 2016
by
Raimbek Egemberdiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
converter divided to classes
parent
e2b317d8
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
514 additions
and
296 deletions
+514
-296
src/main/java/kz/arta/synergy/api/asforms/AsFormService.java
src/main/java/kz/arta/synergy/api/asforms/AsFormService.java
+16
-283
src/main/java/kz/arta/synergy/api/asforms/converter/AsfFormConverter.java
.../arta/synergy/api/asforms/converter/AsfFormConverter.java
+25
-0
src/main/java/kz/arta/synergy/api/asforms/converter/DefaultAsfFormConverter.java
...ynergy/api/asforms/converter/DefaultAsfFormConverter.java
+112
-0
src/main/java/kz/arta/synergy/api/asforms/converter/components/AbstractComponentConverter.java
...orms/converter/components/AbstractComponentConverter.java
+110
-0
src/main/java/kz/arta/synergy/api/asforms/converter/components/CommonConverter.java
...rgy/api/asforms/converter/components/CommonConverter.java
+22
-0
src/main/java/kz/arta/synergy/api/asforms/converter/components/ComponentConverter.java
.../api/asforms/converter/components/ComponentConverter.java
+22
-0
src/main/java/kz/arta/synergy/api/asforms/converter/components/EntityConverter.java
...rgy/api/asforms/converter/components/EntityConverter.java
+23
-0
src/main/java/kz/arta/synergy/api/asforms/converter/components/ListBoxConverter.java
...gy/api/asforms/converter/components/ListBoxConverter.java
+23
-0
src/main/java/kz/arta/synergy/api/asforms/converter/components/NumericInputConverter.java
...i/asforms/converter/components/NumericInputConverter.java
+32
-0
src/main/java/kz/arta/synergy/api/asforms/converter/components/TableConverter.java
...ergy/api/asforms/converter/components/TableConverter.java
+97
-0
src/main/java/kz/arta/synergy/api/asforms/converter/components/TextBoxConverter.java
...gy/api/asforms/converter/components/TextBoxConverter.java
+23
-0
src/test/java/kz/arta/synergy/api/asforms/AsFormServiceTest.java
...t/java/kz/arta/synergy/api/asforms/AsFormServiceTest.java
+9
-13
No files found.
src/main/java/kz/arta/synergy/api/asforms/AsFormService.java
View file @
61ec53b0
This diff is collapsed.
Click to expand it.
src/main/java/kz/arta/synergy/api/asforms/converter/AsfFormConverter.java
0 → 100644
View file @
61ec53b0
package
kz.arta.synergy.api.asforms.converter
;
import
kz.arta.synergy.api.asforms.converter.components.ComponentConverter
;
import
kz.arta.synergy.api.asforms.pojo.AsForm
;
import
kz.arta.synergy.api.asforms.pojo.AsFormDataContainer
;
import
kz.arta.synergy.api.asforms.pojo.AsFormWrapper
;
import
java.lang.annotation.Annotation
;
/**
* @author raimbek
* @since 11.11.2016
*/
public
interface
AsfFormConverter
{
<
T
extends
AsForm
>
AsFormWrapper
toAsfData
(
T
asForm
);
<
T
>
AsFormDataContainer
toAsfData
(
T
asForm
,
String
index
);
<
T
extends
AsForm
>
T
toAsForm
(
Class
<
T
>
asFormClass
,
AsFormWrapper
asfData
);
<
T
>
T
toAsForm
(
Class
<
T
>
asFormClass
,
AsFormDataContainer
asfData
,
String
index
);
void
registerConverter
(
Class
<?
extends
Annotation
>
annotation
,
ComponentConverter
converter
);
}
src/main/java/kz/arta/synergy/api/asforms/converter/DefaultAsfFormConverter.java
0 → 100644
View file @
61ec53b0
package
kz.arta.synergy.api.asforms.converter
;
import
kz.arta.synergy.api.asforms.annotations.*
;
import
kz.arta.synergy.api.asforms.converter.components.*
;
import
kz.arta.synergy.api.asforms.exceptions.CreateAsFormException
;
import
kz.arta.synergy.api.asforms.pojo.AsForm
;
import
kz.arta.synergy.api.asforms.pojo.AsFormData
;
import
kz.arta.synergy.api.asforms.pojo.AsFormDataContainer
;
import
kz.arta.synergy.api.asforms.pojo.AsFormWrapper
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Field
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author raimbek
* @since 11.11.2016
*/
public
class
DefaultAsfFormConverter
implements
AsfFormConverter
{
Map
<
Class
<?
extends
Annotation
>,
ComponentConverter
>
componentConverters
=
new
HashMap
<>();
public
DefaultAsfFormConverter
()
{
registerConverter
(
Cmp
.
class
,
new
CommonConverter
());
registerConverter
(
TextBox
.
class
,
new
TextBoxConverter
());
registerConverter
(
NumericInput
.
class
,
new
NumericInputConverter
());
registerConverter
(
Entity
.
class
,
new
EntityConverter
());
registerConverter
(
ListBox
.
class
,
new
ListBoxConverter
());
registerConverter
(
Table
.
class
,
new
TableConverter
(
this
));
}
@Override
public
<
T
extends
AsForm
>
AsFormWrapper
toAsfData
(
T
asForm
)
{
AsFormWrapper
asFormWrapper
=
new
AsFormWrapper
();
asFormWrapper
.
setForm
(
asForm
.
getForm
());
asFormWrapper
.
setModified
(
asForm
.
getModified
());
asFormWrapper
.
setNodeUUID
(
asForm
.
getNodeUUID
());
asFormWrapper
.
setUuid
(
asForm
.
getUuid
());
asFormWrapper
.
setData
(
toAsfData
(
asForm
,
null
).
getData
());
return
asFormWrapper
;
}
@Override
public
<
T
>
AsFormDataContainer
toAsfData
(
T
asForm
,
String
index
)
{
AsFormDataContainer
dataContainer
=
new
AsFormDataContainer
();
try
{
Field
[]
allFields
=
asForm
.
getClass
().
getDeclaredFields
();
for
(
Field
field
:
allFields
)
{
field
.
setAccessible
(
true
);
Object
o
=
field
.
get
(
asForm
);
if
(
o
==
null
)
{
continue
;
}
Annotation
[]
declaredAnnotations
=
field
.
getDeclaredAnnotations
();
for
(
Annotation
annotation
:
declaredAnnotations
)
{
if
(
componentConverters
.
containsKey
(
annotation
.
annotationType
()))
{
ComponentConverter
componentConverter
=
componentConverters
.
get
(
annotation
.
annotationType
());
AsFormData
data
=
componentConverter
.
toAsfData
(
asForm
,
field
,
annotation
,
index
);
dataContainer
.
addData
(
data
);
break
;
}
}
}
}
catch
(
IllegalAccessException
e
)
{
throw
new
CreateAsFormException
(
"Form class should be accessible"
);
}
return
dataContainer
;
}
@Override
public
<
T
extends
AsForm
>
T
toAsForm
(
Class
<
T
>
asFormClass
,
AsFormWrapper
asfData
)
{
T
asForm
=
toAsForm
(
asFormClass
,
asfData
,
null
);
asForm
.
setForm
(
asfData
.
getForm
());
asForm
.
setModified
(
asfData
.
getModified
());
asForm
.
setNodeUUID
(
asfData
.
getNodeUUID
());
asForm
.
setUuid
(
asfData
.
getUuid
());
return
asForm
;
}
@Override
public
void
registerConverter
(
Class
<?
extends
Annotation
>
annotation
,
ComponentConverter
converter
)
{
componentConverters
.
put
(
annotation
,
converter
);
}
@Override
public
<
T
>
T
toAsForm
(
Class
<
T
>
asFormClass
,
AsFormDataContainer
asfData
,
String
index
)
{
try
{
T
asFormObject
=
asFormClass
.
newInstance
();
if
(
asfData
==
null
||
asfData
.
getData
()
==
null
||
asfData
.
getData
().
isEmpty
())
{
return
asFormObject
;
}
Field
[]
allFields
=
asFormClass
.
getDeclaredFields
();
for
(
Field
field
:
allFields
)
{
Annotation
[]
declaredAnnotations
=
field
.
getDeclaredAnnotations
();
for
(
Annotation
annotation
:
declaredAnnotations
)
{
if
(
componentConverters
.
containsKey
(
annotation
.
annotationType
()))
{
ComponentConverter
componentConverter
=
componentConverters
.
get
(
annotation
.
annotationType
());
componentConverter
.
setFieldValue
(
asfData
,
asFormObject
,
field
,
annotation
,
index
);
break
;
}
}
}
return
asFormObject
;
}
catch
(
InstantiationException
e
)
{
throw
new
CreateAsFormException
(
"Form class should has accessible without params constructor"
);
}
catch
(
IllegalAccessException
e
)
{
throw
new
CreateAsFormException
(
"Form class should be accessible"
);
}
}
}
src/main/java/kz/arta/synergy/api/asforms/converter/components/AbstractComponentConverter.java
0 → 100644
View file @
61ec53b0
package
kz.arta.synergy.api.asforms.converter.components
;
import
kz.arta.synergy.api.asforms.annotations.KeyValue
;
import
kz.arta.synergy.api.asforms.exceptions.UnsupportedFieldTypeException
;
import
kz.arta.synergy.api.asforms.pojo.AsFormData
;
import
kz.arta.synergy.api.asforms.pojo.AsFormDataContainer
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Field
;
/**
* @author raimbek
* @since 11.11.2016
*/
public
abstract
class
AbstractComponentConverter
implements
ComponentConverter
{
@Override
public
<
T
>
AsFormData
toAsfData
(
T
asForm
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
IllegalAccessException
{
field
.
setAccessible
(
true
);
String
cmpId
=
getCmpId
(
annotation
);
if
(
index
!=
null
)
{
cmpId
=
cmpId
+
"-b"
+
index
;
}
AsFormData
asFormData
=
AsFormData
.
create
(
cmpId
,
getType
(
annotation
));
Object
valueObject
=
field
.
get
(
asForm
);
if
(
valueObject
instanceof
AsFormData
)
{
AsFormData
asFormDataObject
=
(
AsFormData
)
valueObject
;
asFormDataObject
.
setId
(
cmpId
);
asFormDataObject
.
setType
(
getType
(
annotation
));
return
asFormDataObject
;
}
else
{
asFormData
.
setValue
(
String
.
valueOf
(
valueObject
));
}
return
asFormData
;
}
@Override
public
<
T
>
void
setFieldValue
(
AsFormDataContainer
asfData
,
T
asFormObject
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
IllegalAccessException
{
field
.
setAccessible
(
true
);
String
cmpId
=
getCmpId
(
annotation
);
if
(
index
!=
null
)
{
cmpId
=
cmpId
+
"-b"
+
index
;
}
if
(
field
.
getType
().
isAssignableFrom
(
String
.
class
))
{
// string
String
value
=
getValueForClassField
(
field
,
asfData
,
cmpId
);
field
.
set
(
asFormObject
,
value
);
}
else
if
(
field
.
getType
().
isAssignableFrom
(
Integer
.
class
))
{
// int
String
value
=
getValueForClassField
(
field
,
asfData
,
cmpId
);
if
(
value
==
null
)
{
value
=
"0"
;
}
field
.
set
(
asFormObject
,
Integer
.
parseInt
(
value
));
}
else
if
(
field
.
getType
().
isAssignableFrom
(
Double
.
class
))
{
// double
String
value
=
getValueForClassField
(
field
,
asfData
,
cmpId
);
if
(
value
==
null
)
{
value
=
"0"
;
}
field
.
set
(
asFormObject
,
Double
.
parseDouble
(
value
));
}
else
if
(
field
.
getType
().
isAssignableFrom
(
AsFormData
.
class
))
{
// common type
AsFormData
data
=
asfData
.
getData
(
cmpId
);
if
(
data
!=
null
)
{
AsFormData
fieldAsFormData
=
new
AsFormData
();
fieldAsFormData
.
setId
(
cmpId
);
fieldAsFormData
.
setType
(
getType
(
annotation
));
fieldAsFormData
.
setValue
(
data
.
getValue
());
fieldAsFormData
.
setKey
(
data
.
getKey
());
fieldAsFormData
.
setKeys
(
data
.
getKeys
());
fieldAsFormData
.
setValues
(
data
.
getValues
());
fieldAsFormData
.
setUserID
(
data
.
getUserID
());
fieldAsFormData
.
setValueID
(
data
.
getValueID
());
fieldAsFormData
.
setLabel
(
data
.
getLabel
());
fieldAsFormData
.
setUsername
(
data
.
getUsername
());
fieldAsFormData
.
setData
(
data
.
getData
());
field
.
set
(
asFormObject
,
fieldAsFormData
);
}
}
else
{
throw
new
UnsupportedFieldTypeException
(
"This type unsupported"
);
}
}
private
String
getValueForClassField
(
Field
field
,
AsFormDataContainer
asfData
,
String
cmpId
)
{
if
(
hasKeyValueAnnotation
(
field
))
{
return
asfData
.
getKey
(
cmpId
);
}
return
asfData
.
getValue
(
cmpId
);
}
private
boolean
hasKeyValueAnnotation
(
Field
field
)
{
boolean
fetchKey
=
false
;
Annotation
[]
declaredAnnotations
=
field
.
getDeclaredAnnotations
();
for
(
Annotation
annotation
:
declaredAnnotations
)
{
if
(
annotation
instanceof
KeyValue
)
{
fetchKey
=
true
;
break
;
}
}
return
fetchKey
;
}
}
src/main/java/kz/arta/synergy/api/asforms/converter/components/CommonConverter.java
0 → 100644
View file @
61ec53b0
package
kz.arta.synergy.api.asforms.converter.components
;
import
kz.arta.synergy.api.asforms.annotations.Cmp
;
import
java.lang.annotation.Annotation
;
/**
* @author raimbek
* @since 11.11.2016
*/
public
class
CommonConverter
extends
AbstractComponentConverter
{
@Override
public
String
getType
(
Annotation
annotation
)
{
return
((
Cmp
)
annotation
).
type
();
}
@Override
public
String
getCmpId
(
Annotation
annotation
)
{
return
((
Cmp
)
annotation
).
id
();
}
}
src/main/java/kz/arta/synergy/api/asforms/converter/components/ComponentConverter.java
0 → 100644
View file @
61ec53b0
package
kz.arta.synergy.api.asforms.converter.components
;
import
kz.arta.synergy.api.asforms.pojo.AsFormData
;
import
kz.arta.synergy.api.asforms.pojo.AsFormDataContainer
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Field
;
/**
* @author raimbek
* @since 11.11.2016
*/
public
interface
ComponentConverter
{
<
T
>
AsFormData
toAsfData
(
T
asForm
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
IllegalAccessException
;
String
getType
(
Annotation
annotation
);
String
getCmpId
(
Annotation
annotation
);
<
T
>
void
setFieldValue
(
AsFormDataContainer
asfData
,
T
asFormObject
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
IllegalAccessException
;
}
src/main/java/kz/arta/synergy/api/asforms/converter/components/EntityConverter.java
0 → 100644
View file @
61ec53b0
package
kz.arta.synergy.api.asforms.converter.components
;
import
kz.arta.synergy.api.asforms.annotations.Entity
;
import
kz.arta.synergy.api.asforms.pojo.ComponentTypes
;
import
java.lang.annotation.Annotation
;
/**
* @author raimbek
* @since 11.11.2016
*/
public
class
EntityConverter
extends
AbstractComponentConverter
{
@Override
public
String
getType
(
Annotation
annotation
)
{
return
ComponentTypes
.
ENTITY
;
}
@Override
public
String
getCmpId
(
Annotation
annotation
)
{
return
((
Entity
)
annotation
).
value
();
}
}
src/main/java/kz/arta/synergy/api/asforms/converter/components/ListBoxConverter.java
0 → 100644
View file @
61ec53b0
package
kz.arta.synergy.api.asforms.converter.components
;
import
kz.arta.synergy.api.asforms.annotations.ListBox
;
import
kz.arta.synergy.api.asforms.pojo.ComponentTypes
;
import
java.lang.annotation.Annotation
;
/**
* @author raimbek
* @since 11.11.2016
*/
public
class
ListBoxConverter
extends
AbstractComponentConverter
{
@Override
public
String
getType
(
Annotation
annotation
)
{
return
ComponentTypes
.
LISTBOX
;
}
@Override
public
String
getCmpId
(
Annotation
annotation
)
{
return
((
ListBox
)
annotation
).
value
();
}
}
src/main/java/kz/arta/synergy/api/asforms/converter/components/NumericInputConverter.java
0 → 100644
View file @
61ec53b0
package
kz.arta.synergy.api.asforms.converter.components
;
import
kz.arta.synergy.api.asforms.annotations.NumericInput
;
import
kz.arta.synergy.api.asforms.pojo.AsFormData
;
import
kz.arta.synergy.api.asforms.pojo.ComponentTypes
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Field
;
/**
* @author raimbek
* @since 11.11.2016
*/
public
class
NumericInputConverter
extends
AbstractComponentConverter
{
@Override
public
<
T
>
AsFormData
toAsfData
(
T
asForm
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
IllegalAccessException
{
AsFormData
asFormData
=
super
.
toAsfData
(
asForm
,
field
,
annotation
,
index
);
asFormData
.
setKey
(
String
.
valueOf
(
field
.
get
(
asForm
)));
return
asFormData
;
}
@Override
public
String
getType
(
Annotation
annotation
)
{
return
ComponentTypes
.
NUMERIC_INPUT
;
}
@Override
public
String
getCmpId
(
Annotation
annotation
)
{
return
((
NumericInput
)
annotation
).
value
();
}
}
src/main/java/kz/arta/synergy/api/asforms/converter/components/TableConverter.java
0 → 100644
View file @
61ec53b0
package
kz.arta.synergy.api.asforms.converter.components
;
import
kz.arta.synergy.api.asforms.AsfTableUtil
;
import
kz.arta.synergy.api.asforms.annotations.Table
;
import
kz.arta.synergy.api.asforms.converter.AsfFormConverter
;
import
kz.arta.synergy.api.asforms.exceptions.UnsupportedFieldTypeException
;
import
kz.arta.synergy.api.asforms.pojo.AsFormData
;
import
kz.arta.synergy.api.asforms.pojo.AsFormDataContainer
;
import
kz.arta.synergy.api.asforms.pojo.ComponentTypes
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author raimbek
* @since 11.11.2016
*/
public
class
TableConverter
extends
AbstractComponentConverter
{
private
AsfFormConverter
asfFormConverter
;
public
TableConverter
(
AsfFormConverter
asfFormConverter
)
{
this
.
asfFormConverter
=
asfFormConverter
;
}
@Override
public
<
T
>
AsFormData
toAsfData
(
T
asForm
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
IllegalAccessException
{
Table
tableAnnotation
=
(
Table
)
annotation
;
if
(
field
.
getType
().
isAssignableFrom
(
AsFormData
.
class
))
{
AsFormData
asFormData
=
AsFormData
.
create
(
tableAnnotation
.
id
(),
ComponentTypes
.
TABLE
);
AsFormData
tableData
=
(
AsFormData
)
field
.
get
(
asForm
);
if
(
tableData
!=
null
&&
tableData
.
getData
()
!=
null
)
{
asFormData
.
setData
(
tableData
.
getData
());
}
return
asFormData
;
}
else
if
(
field
.
getType
().
isAssignableFrom
(
List
.
class
))
{
return
listToAppendableTableAsfData
(
asForm
,
field
,
tableAnnotation
.
id
());
}
else
{
throw
new
UnsupportedFieldTypeException
();
}
}
@Override
public
<
T
>
void
setFieldValue
(
AsFormDataContainer
asfData
,
T
asFormObject
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
IllegalAccessException
{
Table
tableAnnotation
=
(
Table
)
annotation
;
if
(
field
.
getType
().
isAssignableFrom
(
AsFormData
.
class
))
{
super
.
setFieldValue
(
asfData
,
asFormObject
,
field
,
tableAnnotation
,
index
);
}
else
if
(
field
.
getType
().
isAssignableFrom
(
List
.
class
))
{
List
list
=
tableToList
(
asfData
,
tableAnnotation
.
type
(),
tableAnnotation
.
id
());
field
.
setAccessible
(
true
);
field
.
set
(
asFormObject
,
list
);
}
else
{
throw
new
UnsupportedFieldTypeException
();
}
}
@Override
public
String
getType
(
Annotation
annotation
)
{
return
ComponentTypes
.
TABLE
;
}
@Override
public
String
getCmpId
(
Annotation
annotation
)
{
return
((
Table
)
annotation
).
value
();
}
private
<
T
>
AsFormData
listToAppendableTableAsfData
(
T
asForm
,
Field
field
,
String
id
)
throws
IllegalAccessException
{
AsFormData
tableData
=
AsFormData
.
create
(
id
,
ComponentTypes
.
TABLE
);
field
.
setAccessible
(
true
);
List
tableList
=
(
List
)
field
.
get
(
asForm
);
for
(
int
bIndex
=
1
;
bIndex
<=
tableList
.
size
();
bIndex
++)
{
AsFormDataContainer
asFormDataContainer
=
asfFormConverter
.
toAsfData
(
tableList
.
get
(
bIndex
-
1
),
String
.
valueOf
(
bIndex
));
for
(
AsFormData
asFormData
:
asFormDataContainer
.
getData
())
{
tableData
.
addData
(
asFormData
);
}
}
return
tableData
;
}
@SuppressWarnings
(
"unchecked"
)
private
List
tableToList
(
AsFormDataContainer
asfData
,
Class
genericType
,
String
cmpId
)
{
AsFormData
tableData
=
asfData
.
getData
(
cmpId
);
if
(
tableData
==
null
||
tableData
.
getData
()
==
null
||
tableData
.
getData
().
isEmpty
())
{
return
null
;
}
List
table
=
new
ArrayList
<>();
Set
<
String
>
indexes
=
AsfTableUtil
.
tableBIndexes
(
tableData
);
for
(
String
index
:
indexes
)
{
table
.
add
(
asfFormConverter
.
toAsForm
(
genericType
,
tableData
,
index
));
}
return
table
;
}
}
src/main/java/kz/arta/synergy/api/asforms/converter/components/TextBoxConverter.java
0 → 100644
View file @
61ec53b0
package
kz.arta.synergy.api.asforms.converter.components
;
import
kz.arta.synergy.api.asforms.annotations.TextBox
;
import
kz.arta.synergy.api.asforms.pojo.ComponentTypes
;
import
java.lang.annotation.Annotation
;
/**
* @author raimbek
* @since 11.11.2016
*/
public
class
TextBoxConverter
extends
AbstractComponentConverter
{
@Override
public
String
getType
(
Annotation
annotation
)
{
return
ComponentTypes
.
TEXT_BOX
;
}
@Override
public
String
getCmpId
(
Annotation
annotation
)
{
return
((
TextBox
)
annotation
).
value
();
}
}
src/test/java/kz/arta/synergy/api/asforms/AsFormServiceTest.java
View file @
61ec53b0
package
kz.arta.synergy.api.asforms
;
package
kz.arta.synergy.api.asforms
;
import
kz.arta.synergy.api.JsonUtils
;
import
kz.arta.synergy.api.Query
;
import
kz.arta.synergy.api.QueryContext
;
import
kz.arta.synergy.api.QueryContext
;
import
kz.arta.synergy.api.RestHttpQuery
;
import
kz.arta.synergy.api.asforms.pojo.AsFormData
;
import
kz.arta.synergy.api.asforms.pojo.AsFormData
;
import
kz.arta.synergy.api.asforms.pojo.AsFormWrapper
;
import
kz.arta.synergy.api.asforms.pojo.AsFormWrapper
;
import
kz.arta.synergy.api.asforms.pojo.ComponentTypes
;
import
kz.arta.synergy.api.asforms.pojo.ComponentTypes
;
import
kz.arta.synergy.pojo.TableCmp
;
import
kz.arta.synergy.pojo.TableCmp
;
import
kz.arta.synergy.pojo.TestForm
;
import
kz.arta.synergy.pojo.TestForm
;
import
org.mockito.Mockito
;
import
org.testng.Assert
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.Test
;
import
org.testng.annotations.Test
;
...
@@ -37,7 +41,7 @@ public class AsFormServiceTest {
...
@@ -37,7 +41,7 @@ public class AsFormServiceTest {
@BeforeClass
@BeforeClass
public
void
createAsfWrapper
()
throws
IOException
{
public
void
createAsfWrapper
()
throws
IOException
{
/*
AsFormWrapper asFormWrapper = new AsFormWrapper();
AsFormWrapper
asFormWrapper
=
new
AsFormWrapper
();
asFormWrapper
.
addData
(
AsFormData
.
textbox
(
"text_input"
,
expectedTextInputValue
));
asFormWrapper
.
addData
(
AsFormData
.
textbox
(
"text_input"
,
expectedTextInputValue
));
asFormWrapper
.
addData
(
AsFormData
.
textbox
(
"double_input"
,
expectedDoubleValue
));
asFormWrapper
.
addData
(
AsFormData
.
textbox
(
"double_input"
,
expectedDoubleValue
));
asFormWrapper
.
addData
(
AsFormData
.
textbox
(
"integer_input"
,
expectedIntegerValue
));
asFormWrapper
.
addData
(
AsFormData
.
textbox
(
"integer_input"
,
expectedIntegerValue
));
...
@@ -55,17 +59,9 @@ public class AsFormServiceTest {
...
@@ -55,17 +59,9 @@ public class AsFormServiceTest {
asFormWrapper
.
getData
().
add
(
tableData
);
asFormWrapper
.
getData
().
add
(
tableData
);
RestHttpQuery
restHttpQueryMock
=
Mockito
.
mock
(
RestHttpQuery
.
class
);
RestHttpQuery
restHttpQueryMock
=
Mockito
.
mock
(
RestHttpQuery
.
class
);
//Mockito.when(restHttpQueryMock.doGetQuery(Mockito.anyString())).thenReturn(asFormWrapper)
Mockito
.
when
(
restHttpQueryMock
.
doQuery
(
Mockito
.
any
(
Query
.
class
))).
thenReturn
(
JsonUtils
.
toJson
(
asFormWrapper
));
asFormProvider = AsFormProvider.newInstance(new QueryContext("localhost"));
asFormService
=
AsFormService
.
newInstance
(
new
QueryContext
(
"localhost"
)).
setRestHttpQuery
(
restHttpQueryMock
);
//asFormProvider.setRestHttpQuery();
testForm
=
asFormService
.
fetch
(
TestForm
.
class
,
"123456"
);
testForm = asFormProvider.fetch(TestForm.class, "123456");*/
}
@Test
public
void
testQuery
()
throws
IOException
{
asFormService
=
AsFormService
.
newInstance
(
new
QueryContext
(
"http://192.168.0.143:8080/Synergy"
,
"NppAdmin"
,
"123456"
));
TestForm
fetch
=
asFormService
.
fetch
(
TestForm
.
class
,
"2ae95419-af0e-4017-bad9-ff527591ef02"
);
System
.
out
.
println
();
}
}
@Test
@Test
...
@@ -116,6 +112,6 @@ public class AsFormServiceTest {
...
@@ -116,6 +112,6 @@ public class AsFormServiceTest {
Assert
.
assertEquals
(
textInput
.
getValue
(),
expectedTextInputValue
);
Assert
.
assertEquals
(
textInput
.
getValue
(),
expectedTextInputValue
);
AsFormData
tableCmp
=
asFormWrapper
.
getData
(
"table_cmp"
);
AsFormData
tableCmp
=
asFormWrapper
.
getData
(
"table_cmp"
);
Assert
.
assertEquals
(
tableCmp
.
getData
().
size
(),
2
);
Assert
.
assertEquals
(
tableCmp
.
getData
().
size
(),
4
);
}
}
}
}
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