Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
af3
AF3
Commits
19cd384b
Commit
19cd384b
authored
Sep 13, 2017
by
Filip Reaboi
Browse files
Test wrapped in runAsCommand(){}
refs 2978
parent
f06010b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
org.fortiss.af3.component/trunk/test-src/test/org/fortiss/af3/component/library/SmokeComponentLibraryTest.java
View file @
19cd384b
...
...
@@ -35,6 +35,7 @@ import org.fortiss.af3.project.model.FileProject;
import
org.fortiss.tooling.kernel.extension.data.ITopLevelElement
;
import
org.fortiss.tooling.kernel.extension.data.Prototype
;
import
org.fortiss.tooling.kernel.model.ILibraryPackage
;
import
org.fortiss.tooling.kernel.service.ICommandStackService
;
import
org.fortiss.tooling.kernel.service.ILibraryService
;
import
org.fortiss.tooling.kernel.service.IPersistencyService
;
import
org.junit.Before
;
...
...
@@ -54,12 +55,15 @@ public class SmokeComponentLibraryTest extends LibraryTestBase {
/** The top component. */
private
Component
top
;
/** */
FileProject
project
;
/** Setup a fake context for the verification. */
@Before
public
void
setUp
()
throws
Exception
{
// Bring up persistenc
y
service for this test
// Bring up persistenc
e
service for this test
IPersistencyService
.
getInstance
().
getClass
();
FileProject
project
=
project
=
loadProjectFromPlugin
(
AF3ComponentActivator
.
PLUGIN_ID
,
"test-data/LibraryTests.af3_20"
,
true
);
...
...
@@ -72,60 +76,67 @@ public class SmokeComponentLibraryTest extends LibraryTestBase {
/** Test saving a component into the library. */
@Test
public
void
testSaveToLibrary
()
{
Prototype
prot
=
findPrototypeComposableWith
(
Component
.
class
,
"Div"
);
assertNull
(
prot
);
Component
div
=
top
.
findSubComponent
(
"Div"
);
addElementToLibrary
(
"default"
,
"default"
,
div
);
prot
=
findPrototypeComposableWith
(
Component
.
class
,
"Div"
);
assertNotNull
(
prot
);
assertTrue
(
prot
.
getPrototype
()
instanceof
ComponentRef
);
ComponentRef
prototypeCopy
=
(
ComponentRef
)
prot
.
getPrototypeCopy
();
assertEquals
(
"default.Div"
,
prototypeCopy
.
getURI
());
prototypeCopy
.
setName
(
"DivCopy"
);
top
.
getContainedElements
().
add
(
prototypeCopy
);
assertEquals
(
"DivCopy"
,
prototypeCopy
.
getName
());
Component
divCopy
=
top
.
findSubComponent
(
"DivCopy"
);
assertTrue
(
divCopy
instanceof
ComponentRef
);
CodeSpecification
cs
=
divCopy
.
getCodeSpecification
();
assertEquals
(
1
,
cs
.
getBody
().
getStatements
().
size
());
ILibraryPackage
pack
=
findLibraryPackage
(
"default"
,
"default"
);
LibraryComponent
libCom
=
(
LibraryComponent
)
pack
.
getLibraryElements
().
get
(
0
);
final
Component
compFromLib
=
libCom
.
getComponent
();
final
CodeSpecification
csLib
=
compFromLib
.
getCodeSpecification
();
assertEquals
(
1
,
csLib
.
getBody
().
getStatements
().
size
());
// changes in the library are propagated
final
ITopLevelElement
libTopLevel
=
IPersistencyService
.
getInstance
().
getTopLevelElementFor
(
csLib
);
libTopLevel
.
runAsCommand
(
new
Runnable
()
{
@Override
public
void
run
()
{
csLib
.
getBody
().
getStatements
().
clear
();
}
});
assertEquals
(
0
,
csLib
.
getBody
().
getStatements
().
size
());
assertTrue
(
ILibraryService
.
getInstance
().
isDirty
(
prototypeCopy
));
CodeSpecification
csNew
=
divCopy
.
getCodeSpecification
();
assertEquals
(
0
,
csNew
.
getBody
().
getStatements
().
size
());
// the name of the library component should not be synchronized
libTopLevel
.
runAsCommand
(
new
Runnable
()
{
@Override
public
void
run
()
{
compFromLib
.
setName
(
"NewName"
);
}
});
sleep
();
assertEquals
(
"DivCopy"
,
divCopy
.
getName
());
ICommandStackService
.
getInstance
().
runAsCommand
(
project
,
()
->
{
Prototype
prot
=
findPrototypeComposableWith
(
Component
.
class
,
"Div"
);
assertNull
(
prot
);
Component
div
=
top
.
findSubComponent
(
"Div"
);
addElementToLibrary
(
"default"
,
"default"
,
div
);
prot
=
findPrototypeComposableWith
(
Component
.
class
,
"Div"
);
assertNotNull
(
prot
);
assertTrue
(
prot
.
getPrototype
()
instanceof
ComponentRef
);
ComponentRef
prototypeCopy
=
(
ComponentRef
)
prot
.
getPrototypeCopy
();
assertEquals
(
"default.Div"
,
prototypeCopy
.
getURI
());
prototypeCopy
.
setName
(
"DivCopy"
);
top
.
getContainedElements
().
add
(
prototypeCopy
);
assertEquals
(
"DivCopy"
,
prototypeCopy
.
getName
());
Component
divCopy
=
top
.
findSubComponent
(
"DivCopy"
);
assertTrue
(
divCopy
instanceof
ComponentRef
);
CodeSpecification
cs
=
divCopy
.
getCodeSpecification
();
assertEquals
(
1
,
cs
.
getBody
().
getStatements
().
size
());
ILibraryPackage
pack
=
findLibraryPackage
(
"default"
,
"default"
);
LibraryComponent
libCom
=
(
LibraryComponent
)
pack
.
getLibraryElements
().
get
(
0
);
final
Component
compFromLib
=
libCom
.
getComponent
();
final
CodeSpecification
csLib
=
compFromLib
.
getCodeSpecification
();
assertEquals
(
1
,
csLib
.
getBody
().
getStatements
().
size
());
// changes in the library are propagated
final
ITopLevelElement
libTopLevel
=
IPersistencyService
.
getInstance
().
getTopLevelElementFor
(
csLib
);
libTopLevel
.
runAsCommand
(
new
Runnable
()
{
@Override
public
void
run
()
{
csLib
.
getBody
().
getStatements
().
clear
();
}
});
assertEquals
(
0
,
csLib
.
getBody
().
getStatements
().
size
());
assertTrue
(
ILibraryService
.
getInstance
().
isDirty
(
prototypeCopy
));
CodeSpecification
csNew
=
divCopy
.
getCodeSpecification
();
assertEquals
(
0
,
csNew
.
getBody
().
getStatements
().
size
());
// the name of the library component should not be synchronized
libTopLevel
.
runAsCommand
(
new
Runnable
()
{
@Override
public
void
run
()
{
compFromLib
.
setName
(
"NewName"
);
}
});
sleep
();
assertEquals
(
"DivCopy"
,
divCopy
.
getName
());
});
}
}
Write
Preview
Supports
Markdown
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!
Cancel
Please
register
or
sign in
to comment