diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8c7c6b8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,88 @@
+
+# Created by https://www.gitignore.io/api/maven,eclipse
+
+### Eclipse ###
+
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.settings/
+.loadpath
+.recommenders
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# PyDev specific (Python IDE for Eclipse)
+*.pydevproject
+
+# CDT-specific (C/C++ Development Tooling)
+.cproject
+
+# CDT- autotools
+.autotools
+
+# Java annotation processor (APT)
+.factorypath
+
+# PDT-specific (PHP Development Tools)
+.buildpath
+
+# sbteclipse plugin
+.target
+
+# Tern plugin
+.tern-project
+
+# TeXlipse plugin
+.texlipse
+
+# STS (Spring Tool Suite)
+.springBeans
+
+# Code Recommenders
+.recommenders/
+
+# Annotation Processing
+.apt_generated/
+
+# Scala IDE specific (Scala & Java development for Eclipse)
+.cache-main
+.scala_dependencies
+.worksheet
+
+### Eclipse Patch ###
+# Eclipse Core
+.project
+
+# JDT-specific (Eclipse Java Development Tools)
+.classpath
+
+# Annotation Processing
+.apt_generated
+
+.sts4-cache/
+
+### Maven ###
+target/
+report/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+.mvn/wrapper/maven-wrapper.jar
+
+
+# End of https://www.gitignore.io/api/maven,eclipse
diff --git a/COPYRIGHT b/COPYRIGHT
new file mode 100644
index 0000000..d7eb3f1
--- /dev/null
+++ b/COPYRIGHT
@@ -0,0 +1,17 @@
+
+ Copyright (c) 2018-2019 Linagora
+
+ This program/library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 2.1 of the License, or (at your
+ option) any later version.
+
+ This program/library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program/library; If not, see http://www.gnu.org/licenses/
+ for the GNU Lesser General Public License version 2.1.
+
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index 0a04128..60d7ac2 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,165 +1,502 @@
- GNU LESSER GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
- Copyright (C) 2007 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
-
- This version of the GNU Lesser General Public License incorporates
-the terms and conditions of version 3 of the GNU General Public
-License, supplemented by the additional permissions listed below.
-
- 0. Additional Definitions.
-
- As used herein, "this License" refers to version 3 of the GNU Lesser
-General Public License, and the "GNU GPL" refers to version 3 of the GNU
-General Public License.
-
- "The Library" refers to a covered work governed by this License,
-other than an Application or a Combined Work as defined below.
-
- An "Application" is any work that makes use of an interface provided
-by the Library, but which is not otherwise based on the Library.
-Defining a subclass of a class defined by the Library is deemed a mode
-of using an interface provided by the Library.
-
- A "Combined Work" is a work produced by combining or linking an
-Application with the Library. The particular version of the Library
-with which the Combined Work was made is also called the "Linked
-Version".
-
- The "Minimal Corresponding Source" for a Combined Work means the
-Corresponding Source for the Combined Work, excluding any source code
-for portions of the Combined Work that, considered in isolation, are
-based on the Application, and not on the Linked Version.
-
- The "Corresponding Application Code" for a Combined Work means the
-object code and/or source code for the Application, including any data
-and utility programs needed for reproducing the Combined Work from the
-Application, but excluding the System Libraries of the Combined Work.
-
- 1. Exception to Section 3 of the GNU GPL.
-
- You may convey a covered work under sections 3 and 4 of this License
-without being bound by section 3 of the GNU GPL.
-
- 2. Conveying Modified Versions.
-
- If you modify a copy of the Library, and, in your modifications, a
-facility refers to a function or data to be supplied by an Application
-that uses the facility (other than as an argument passed when the
-facility is invoked), then you may convey a copy of the modified
-version:
-
- a) under this License, provided that you make a good faith effort to
- ensure that, in the event an Application does not supply the
- function or data, the facility still operates, and performs
- whatever part of its purpose remains meaningful, or
-
- b) under the GNU GPL, with none of the additional permissions of
- this License applicable to that copy.
-
- 3. Object Code Incorporating Material from Library Header Files.
-
- The object code form of an Application may incorporate material from
-a header file that is part of the Library. You may convey such object
-code under terms of your choice, provided that, if the incorporated
-material is not limited to numerical parameters, data structure
-layouts and accessors, or small macros, inline functions and templates
-(ten or fewer lines in length), you do both of the following:
-
- a) Give prominent notice with each copy of the object code that the
- Library is used in it and that the Library and its use are
- covered by this License.
-
- b) Accompany the object code with a copy of the GNU GPL and this license
- document.
-
- 4. Combined Works.
-
- You may convey a Combined Work under terms of your choice that,
-taken together, effectively do not restrict modification of the
-portions of the Library contained in the Combined Work and reverse
-engineering for debugging such modifications, if you also do each of
-the following:
-
- a) Give prominent notice with each copy of the Combined Work that
- the Library is used in it and that the Library and its use are
- covered by this License.
-
- b) Accompany the Combined Work with a copy of the GNU GPL and this license
- document.
-
- c) For a Combined Work that displays copyright notices during
- execution, include the copyright notice for the Library among
- these notices, as well as a reference directing the user to the
- copies of the GNU GPL and this license document.
-
- d) Do one of the following:
-
- 0) Convey the Minimal Corresponding Source under the terms of this
- License, and the Corresponding Application Code in a form
- suitable for, and under terms that permit, the user to
- recombine or relink the Application with a modified version of
- the Linked Version to produce a modified Combined Work, in the
- manner specified by section 6 of the GNU GPL for conveying
- Corresponding Source.
-
- 1) Use a suitable shared library mechanism for linking with the
- Library. A suitable mechanism is one that (a) uses at run time
- a copy of the Library already present on the user's computer
- system, and (b) will operate properly with a modified version
- of the Library that is interface-compatible with the Linked
- Version.
-
- e) Provide Installation Information, but only if you would otherwise
- be required to provide such information under section 6 of the
- GNU GPL, and only to the extent that such information is
- necessary to install and execute a modified version of the
- Combined Work produced by recombining or relinking the
- Application with a modified version of the Linked Version. (If
- you use option 4d0, the Installation Information must accompany
- the Minimal Corresponding Source and Corresponding Application
- Code. If you use option 4d1, you must provide the Installation
- Information in the manner specified by section 6 of the GNU GPL
- for conveying Corresponding Source.)
-
- 5. Combined Libraries.
-
- You may place library facilities that are a work based on the
-Library side by side in a single library together with other library
-facilities that are not Applications and are not covered by this
-License, and convey such a combined library under terms of your
-choice, if you do both of the following:
-
- a) Accompany the combined library with a copy of the same work based
- on the Library, uncombined with any other library facilities,
- conveyed under the terms of this License.
-
- b) Give prominent notice with the combined library that part of it
- is a work based on the Library, and explaining where to find the
- accompanying uncombined form of the same work.
-
- 6. Revised Versions of the GNU Lesser General Public License.
-
- The Free Software Foundation may publish revised and/or new versions
-of the GNU Lesser General Public License from time to time. Such new
-versions will be similar in spirit to the present version, but may
-differ in detail to address new problems or concerns.
-
- Each version is given a distinguishing version number. If the
-Library as you received it specifies that a certain numbered version
-of the GNU Lesser General Public License "or any later version"
-applies to it, you have the option of following the terms and
-conditions either of that published version or of any later version
-published by the Free Software Foundation. If the Library as you
-received it does not specify a version number of the GNU Lesser
-General Public License, you may choose any version of the GNU Lesser
-General Public License ever published by the Free Software Foundation.
-
- If the Library as you received it specifies that a proxy can decide
-whether future versions of the GNU Lesser General Public License shall
-apply, that proxy's public statement of acceptance of any version is
-permanent authorization for you to choose that version for the
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ , 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..58992fe
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,120 @@
+
+
+
+ 4.0.0
+
+
+ org.ow2.petals
+ petals-client-tools-parent
+ 1.1.1-SNAPSHOT
+
+
+ petals-esb-deployer
+ 0.0.1-SNAPSHOT
+ jar
+
+ petals-esb-deployer
+ https://doc.petalslink.com/display/petalscomponents/Petals+ESB+Deployer+1.0.0
+
+
+
+ org.ow2.petals
+ petals-admin-api
+ 2.1.1-SNAPSHOT
+
+
+
+ org.ow2.petals
+ petals-jbi-descriptor
+ 2.4.0
+
+
+
+ commons-io
+ commons-io
+ 2.6
+
+
+
+ org.jvnet.jaxb2_commons
+ jaxb2-basics-runtime
+
+
+
+ junit
+ junit
+ test
+
+
+
+ org.ow2.petals
+ petals-admin-mock
+ 2.1.1-SNAPSHOT
+ test
+
+
+
+ org.mockito
+ mockito-core
+ test
+
+
+
+ xmlunit
+ xmlunit
+ 1.6
+ test
+
+
+
+
+
+
+ org.jvnet.jaxb2.maven2
+ maven-jaxb2-plugin
+
+ ${basedir}/src/main/resources/
+
+ topology-model.xsd
+ component-repository.xsd
+ service-unit-model.xsd
+ bus-model.xsd
+ model.xsd
+
+
+ binding.xjb
+
+
+
+
+ com.github.spotbugs
+ spotbugs-maven-plugin
+ 3.1.8
+
+
+ com.github.spotbugs
+ spotbugs
+ 3.1.9
+
+
+
+
+
+
diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java
new file mode 100644
index 0000000..c36c299
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2018-2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.runtimemodel;
+
+import java.net.URL;
+
+import org.ow2.petals.deployer.runtimemodel.interfaces.Similar;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class RuntimeComponent implements Similar {
+
+ private final String id;
+
+ private URL url;
+
+ /**
+ *
+ * @param id
+ * must not be {code null}
+ */
+ public RuntimeComponent(final String id) {
+ this.id = id;
+ }
+
+ /**
+ *
+ * @param id
+ * must not be {code null}
+ * @param url
+ */
+ public RuntimeComponent(final String id, final URL url) {
+ this(id);
+ this.url = url;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public URL getUrl() {
+ return url;
+ }
+
+ public void setUrl(final URL url) {
+ this.url = url;
+ }
+
+ @Override
+ public boolean isSimilarTo(Object o) {
+ return o instanceof RuntimeComponent && this.getId().equals(((RuntimeComponent) o).getId());
+ }
+}
diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java
new file mode 100644
index 0000000..1bf059f
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java
@@ -0,0 +1,194 @@
+/**
+ * Copyright (c) 2018-2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.runtimemodel;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedComponentException;
+import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedServiceUnitException;
+import org.ow2.petals.deployer.runtimemodel.interfaces.Similar;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class RuntimeContainer implements Similar {
+
+ private final String id;
+
+ private int port;
+
+ private String user;
+
+ private String password;
+
+ private String hostname;
+
+ private final Map serviceUnits = new HashMap<>();
+
+ private final Map components = new HashMap<>();
+
+ /**
+ *
+ * @param id
+ * must not be {code null}
+ * @param port
+ * @param user
+ * must not be {code null}
+ * @param password
+ * must not be {code null}
+ * @param hostname
+ * must not be {code null}
+ */
+ public RuntimeContainer(final String id, final int port, final String user, final String password,
+ final String hostname) {
+ assert id != null;
+ assert user != null;
+ assert password != null;
+ assert hostname != null;
+ this.id = id;
+ this.port = port;
+ this.user = user;
+ this.password = password;
+ this.hostname = hostname;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getHostname() {
+ return hostname;
+ }
+
+ /**
+ *
+ * @param hostname
+ * must not be {code null}
+ */
+ public void setHostname(final String hostname) {
+ assert hostname != null;
+ this.hostname = hostname;
+ }
+
+ public RuntimeServiceUnit getServiceUnit(final String id) {
+ return serviceUnits.get(id);
+ }
+
+ /**
+ *
+ * @param serviceUnit
+ * must not be {code null}
+ * @throws DuplicatedServiceUnitException
+ * Service unit is already in the list
+ */
+ public void addServiceUnit(final RuntimeServiceUnit serviceUnit) throws DuplicatedServiceUnitException {
+ assert serviceUnit != null;
+ if (serviceUnits.put(serviceUnit.getId(), serviceUnit) != null) {
+ throw new DuplicatedServiceUnitException("Service unit " + serviceUnit.getId() + " is already in the list");
+ }
+ }
+
+ public Collection getServiceUnits() {
+ return serviceUnits.values();
+ }
+
+ /**
+ *
+ * @param component
+ * must not be {code null}
+ * @throws DuplicatedComponentException
+ * Component is already in the list
+ */
+ public void addComponent(final RuntimeComponent component) throws DuplicatedComponentException {
+ assert component != null;
+ if (components.put(component.getId(), component) != null) {
+ throw new DuplicatedComponentException("Component " + component.getId() + " is already in the list");
+ }
+ }
+
+ public RuntimeComponent getComponent(final String id) {
+ return components.get(id);
+ }
+
+ public Collection getComponents() {
+ return components.values();
+ }
+
+ @Override
+ public boolean isSimilarTo(Object o) {
+ if (!(o instanceof RuntimeContainer)) {
+ return false;
+ }
+ RuntimeContainer otherContainer = (RuntimeContainer) o;
+
+ return this.getId().equals(otherContainer.getId()) && this.getPort() == otherContainer.getPort()
+ && this.getUser().equals(otherContainer.getUser())
+ && this.getPassword().equals(otherContainer.getPassword())
+ && this.getHostname().equals(otherContainer.getHostname())
+ && compareRuntimeServiceUnitMaps(otherContainer) && compareRuntimeComponentMaps(otherContainer);
+ }
+
+ private boolean compareRuntimeServiceUnitMaps(final RuntimeContainer otherCont) {
+ for (final RuntimeServiceUnit thisContSu : this.getServiceUnits()) {
+ final RuntimeServiceUnit otherContSu = otherCont.getServiceUnit(thisContSu.getId());
+ if (thisContSu == null || !thisContSu.isSimilarTo(otherContSu)) {
+ return false;
+ }
+ }
+
+ for (final RuntimeServiceUnit otherContSu : otherCont.getServiceUnits()) {
+ if (this.getServiceUnit(otherContSu.getId()) == null) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private boolean compareRuntimeComponentMaps(final RuntimeContainer otherCont) {
+ for (final RuntimeComponent thisContComp : this.getComponents()) {
+ final RuntimeComponent otherContComp = otherCont.getComponent(thisContComp.getId());
+ if (otherContComp == null || !thisContComp.isSimilarTo(otherContComp)) {
+ return false;
+ }
+ }
+
+ for (final RuntimeComponent otherContComp : otherCont.getComponents()) {
+ if (this.getComponent(otherContComp.getId()) == null) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java
new file mode 100644
index 0000000..3e998dd
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java
@@ -0,0 +1,85 @@
+/**
+ * Copyright (c) 2018-2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.runtimemodel;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedContainerException;
+import org.ow2.petals.deployer.runtimemodel.interfaces.Similar;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class RuntimeModel implements Similar {
+
+ private final Map containers = new HashMap<>();
+
+ /**
+ * @param container
+ * must not be {code null}
+ * @throws DuplicatedContainerException
+ */
+ public void addContainer(final RuntimeContainer container) throws DuplicatedContainerException {
+ if (containers.put(container.getId(), container) != null) {
+ throw new DuplicatedContainerException("Container " + container.getId() + " is already in the list");
+ }
+ }
+
+ /**
+ * Return the RuntimeContainer with identifier id, or {code null} if not in the model.
+ *
+ * @param id
+ * @return RuntimeContainer or null
+ */
+ public RuntimeContainer getContainer(final String id) {
+ return containers.get(id);
+ }
+
+ public Collection getContainers() {
+ return containers.values();
+ }
+
+ @Override
+ public boolean isSimilarTo(Object o) {
+ if (!(o instanceof RuntimeModel)) {
+ return false;
+ }
+ RuntimeModel otherModel = (RuntimeModel) o;
+
+ final Collection thisModelContainers = this.getContainers();
+ final Collection otherModelContainers = otherModel.getContainers();
+
+ for (final RuntimeContainer thisModelCont : thisModelContainers) {
+ final RuntimeContainer otherModelCont = otherModel.getContainer(thisModelCont.getId());
+ if (otherModelCont == null || !thisModelCont.isSimilarTo(otherModelCont)) {
+ return false;
+ }
+ }
+
+ for (final RuntimeContainer otherModelCont : otherModelContainers) {
+ if (this.getContainer(otherModelCont.getId()) == null) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java
new file mode 100644
index 0000000..c2c9b44
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java
@@ -0,0 +1,69 @@
+/**
+ * Copyright (c) 2018-2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.runtimemodel;
+
+import java.net.URL;
+
+import org.ow2.petals.deployer.runtimemodel.interfaces.Similar;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class RuntimeServiceUnit implements Similar {
+
+ private final String id;
+
+ private URL url;
+
+ /**
+ *
+ * @param id
+ * must not be {code null}
+ */
+ public RuntimeServiceUnit(final String id) {
+ this.id = id;
+ }
+
+ /**
+ *
+ * @param id
+ * must not be {code null}
+ */
+ public RuntimeServiceUnit(final String id, final URL url) {
+ this(id);
+ this.url = url;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public URL getUrl() {
+ return url;
+ }
+
+ public void setUrl(final URL url) {
+ this.url = url;
+ }
+
+ @Override
+ public boolean isSimilarTo(Object o) {
+ return o instanceof RuntimeServiceUnit && this.getId().equals(((RuntimeServiceUnit) o).getId());
+ }
+}
diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedComponentException.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedComponentException.java
new file mode 100644
index 0000000..d4924f7
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedComponentException.java
@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.runtimemodel.exceptions;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class DuplicatedComponentException extends RuntimeModelException {
+
+ private static final long serialVersionUID = -5826228789271638203L;
+
+ public DuplicatedComponentException(final String message) {
+ super(message);
+ }
+
+}
diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedContainerException.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedContainerException.java
new file mode 100644
index 0000000..d935090
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedContainerException.java
@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.runtimemodel.exceptions;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class DuplicatedContainerException extends RuntimeModelException {
+
+ private static final long serialVersionUID = -6281782979104342739L;
+
+ public DuplicatedContainerException(final String message) {
+ super(message);
+ }
+
+}
diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedServiceUnitException.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedServiceUnitException.java
new file mode 100644
index 0000000..0a159df
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedServiceUnitException.java
@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.runtimemodel.exceptions;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class DuplicatedServiceUnitException extends RuntimeModelException {
+
+ private static final long serialVersionUID = -8251466267062830623L;
+
+ public DuplicatedServiceUnitException(final String message) {
+ super(message);
+ }
+
+}
diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/RuntimeModelException.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/RuntimeModelException.java
new file mode 100644
index 0000000..a8e980e
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/RuntimeModelException.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.runtimemodel.exceptions;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class RuntimeModelException extends Exception {
+
+ private static final long serialVersionUID = -2799783010070052000L;
+
+ public RuntimeModelException(final String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/interfaces/Similar.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/interfaces/Similar.java
new file mode 100644
index 0000000..a918041
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/interfaces/Similar.java
@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.runtimemodel.interfaces;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public interface Similar {
+
+ /**
+ * Return true if current object and o are similar.
+ *
+ * RuntimeModel deployed to Petals, and RuntimeModel exported from the deployed Petals will return {code true} when
+ * compared using isSimilarTo method. {code o1.isSimilarTo(o2)} will always yield the same result as {code
+ * o2.isSimilarTo(o1)}.
+ *
+ * @param o
+ * object compared to current object
+ * @return true if similar
+ */
+ public boolean isSimilarTo(Object o);
+}
diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java
new file mode 100644
index 0000000..94b51a3
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java
@@ -0,0 +1,105 @@
+/**
+ * Copyright (c) 2018-2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.ow2.petals.deployer.model.bus.xml._1.BusModel;
+import org.ow2.petals.deployer.model.bus.xml._1.ComponentInstance;
+import org.ow2.petals.deployer.model.bus.xml._1.ContainerInstance;
+import org.ow2.petals.deployer.model.bus.xml._1.ProvisionedMachine;
+import org.ow2.petals.deployer.model.bus.xml._1.ServiceUnitInstance;
+import org.ow2.petals.deployer.model.component_repository.xml._1.Component;
+import org.ow2.petals.deployer.model.component_repository.xml._1.ComponentRepository;
+import org.ow2.petals.deployer.model.service_unit.xml._1.ServiceUnit;
+import org.ow2.petals.deployer.model.service_unit.xml._1.ServiceUnitModel;
+import org.ow2.petals.deployer.model.topology.xml._1.Container;
+import org.ow2.petals.deployer.model.xml._1.Model;
+import org.ow2.petals.deployer.runtimemodel.RuntimeComponent;
+import org.ow2.petals.deployer.runtimemodel.RuntimeContainer;
+import org.ow2.petals.deployer.runtimemodel.RuntimeModel;
+import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit;
+import org.ow2.petals.deployer.runtimemodel.exceptions.RuntimeModelException;
+
+/**
+ * This is an utility class and should not be instanciated.
+ *
+ * @author Alexandre Lagane - Linagora
+ */
+public class ModelConverter {
+
+ private ModelConverter() {
+ }
+
+ public static RuntimeModel convertModelToRuntimeModel(final Model model)
+ throws MalformedURLException, RuntimeModelException {
+ final RuntimeModel runtimeModel = new RuntimeModel();
+
+ final Container cont = model.getTopologyModel().getTopology().get(0).getContainer().get(0);
+
+ final BusModel busModel = model.getBusModel();
+
+ final ContainerInstance contInst = busModel.getBus().get(0).getContainerInstance().get(0);
+
+ final String contId = cont.getId();
+ final String hostname = ((ProvisionedMachine) busModel.getMachine().get(0)).getHostname();
+ Integer contPort = contInst.getJmxPort();
+ if (contPort == null) {
+ contPort = cont.getDefaultJmxPort();
+ }
+ String contUser = contInst.getJmxUser();
+ if (contUser == null) {
+ contUser = cont.getDefaultJmxUser();
+ }
+ String contPassword = contInst.getJmxPassword();
+ if (contPassword == null) {
+ contPassword = cont.getDefaultJmxPassword();
+ }
+
+ final RuntimeContainer runtimeCont = new RuntimeContainer(contId, contPort, contUser, contPassword, hostname);
+ runtimeModel.addContainer(runtimeCont);
+
+ final ComponentRepository compRepo = model.getComponentRepository();
+ final Map compById = new HashMap<>();
+ for (final Component comp : compRepo.getComponent()) {
+ compById.put(comp.getId(), comp);
+ }
+ for (final ComponentInstance compInst : contInst.getComponentInstance()) {
+ final String compId = compInst.getRef();
+ final Component compRef = compById.get(compId);
+ runtimeCont.addComponent(new RuntimeComponent(compId, new URL(compRef.getUrl())));
+ }
+
+ final ServiceUnitModel suModel = model.getServiceUnitModel();
+ final Map suById = new HashMap<>();
+ for (final ServiceUnit su : suModel.getServiceUnit()) {
+ suById.put(su.getId(), su);
+ }
+ for (final ServiceUnitInstance suInst : contInst.getServiceUnitInstance()) {
+ final String suId = suInst.getRef();
+ final ServiceUnit suRef = suById.get(suId);
+ runtimeCont.addServiceUnit(new RuntimeServiceUnit(suId, new URL(suRef.getUrl())));
+ }
+
+ return runtimeModel;
+ }
+}
diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java
new file mode 100644
index 0000000..af87f19
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java
@@ -0,0 +1,93 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils;
+
+import java.net.URL;
+import java.util.logging.Logger;
+
+import org.ow2.petals.deployer.model.xml._1.Model;
+import org.ow2.petals.deployer.runtimemodel.RuntimeModel;
+import org.ow2.petals.deployer.utils.exceptions.ModelDeploymentException;
+
+/**
+ * The main class used for deploying XML models.
+ *
+ * @author Alexandre Lagane - Linagora
+ */
+public class ModelDeployer {
+
+ /**
+ * Connection timeout in milliseconds to get model or artifacts from URL.
+ */
+ public static final int CONNECTION_TIMEOUT = 5000;
+
+ /**
+ * Reading timeout in milliseconds to read model or artifacts from URL.
+ */
+ public static final int READ_TIMEOUT = 5000;
+
+ private final static Logger LOG = Logger.getLogger(ModelDeployer.class.getName());
+
+ private final RuntimeModelDeployer runtimeModelDeployer;
+
+ private static ModelDeployer instance;
+
+ public ModelDeployer() {
+ this(null);
+ }
+
+ /**
+ * Used only for testing purposes, to mock runtimeModelDeployer.
+ *
+ * @param runtimeModelDeployer
+ */
+ protected ModelDeployer(RuntimeModelDeployer runtimeModelDeployer) {
+ this.runtimeModelDeployer = runtimeModelDeployer != null ? runtimeModelDeployer : new RuntimeModelDeployer();
+ instance = this;
+ }
+
+ /**
+ * Download and deploy the model at the url. The model must be an XML model with XSD {code model.xsd} in resources
+ * directory.
+ *
+ * @param url
+ * @throws ModelDeploymentException
+ */
+ public void deployModel(final URL url) throws ModelDeploymentException {
+ final Model model = XmlModelBuilder.readModelFromUrl(url);
+
+ deployModel(model);
+ }
+
+ public void deployModel(Model model) throws ModelDeploymentException {
+ RuntimeModel runtimeModel;
+ try {
+ runtimeModel = ModelConverter.convertModelToRuntimeModel(model);
+
+ runtimeModelDeployer.deployRuntimeModel(runtimeModel);
+ } catch (Exception e) {
+ throw new ModelDeploymentException(e);
+ }
+
+ }
+
+ public static ModelDeployer getInstance() {
+ return instance != null ? instance : new ModelDeployer();
+ }
+}
diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java
new file mode 100644
index 0000000..f8a2ead
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java
@@ -0,0 +1,188 @@
+/**
+ * Copyright (c) 2018-2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import org.apache.commons.io.FileUtils;
+import org.ow2.petals.admin.api.PetalsAdministration;
+import org.ow2.petals.admin.api.PetalsAdministrationFactory;
+import org.ow2.petals.admin.api.artifact.Component.ComponentType;
+import org.ow2.petals.admin.api.artifact.lifecycle.ArtifactLifecycleFactory;
+import org.ow2.petals.admin.api.artifact.lifecycle.ComponentLifecycle;
+import org.ow2.petals.admin.api.artifact.lifecycle.ServiceAssemblyLifecycle;
+import org.ow2.petals.admin.api.exception.ArtifactAdministrationException;
+import org.ow2.petals.admin.api.exception.ArtifactDeployedException;
+import org.ow2.petals.admin.api.exception.ArtifactNotDeployedException;
+import org.ow2.petals.admin.api.exception.ArtifactNotFoundException;
+import org.ow2.petals.admin.api.exception.ArtifactStartedException;
+import org.ow2.petals.admin.api.exception.ConnectionFailedException;
+import org.ow2.petals.admin.api.exception.ContainerAdministrationException;
+import org.ow2.petals.deployer.runtimemodel.RuntimeComponent;
+import org.ow2.petals.deployer.runtimemodel.RuntimeContainer;
+import org.ow2.petals.deployer.runtimemodel.RuntimeModel;
+import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit;
+import org.ow2.petals.deployer.utils.exceptions.ComponentDeploymentException;
+import org.ow2.petals.deployer.utils.exceptions.RuntimeModelDeployerException;
+import org.ow2.petals.deployer.utils.exceptions.UncheckedException;
+import org.ow2.petals.jbi.descriptor.JBIDescriptorException;
+import org.ow2.petals.jbi.descriptor.original.JBIDescriptorBuilder;
+import org.ow2.petals.jbi.descriptor.original.generated.Jbi;
+import org.ow2.petals.jbi.descriptor.original.generated.ServiceAssembly;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class RuntimeModelDeployer {
+
+ private final static Logger LOG = Logger.getLogger(RuntimeModelDeployer.class.getName());
+
+ private final PetalsAdministration petalsAdmin;
+
+ private final ArtifactLifecycleFactory artifactLifecycleFactory;
+
+ private final JBIDescriptorBuilder jdb;
+
+ public RuntimeModelDeployer() {
+ this(null, null);
+ }
+
+ /**
+ * Used only for testing purposes, to mock petalsAdmin and artifactLifecycleFactory.
+ *
+ * @param petalsAdmin
+ * @param artifactLifecycleFactory
+ */
+ protected RuntimeModelDeployer(final PetalsAdministration petalsAdmin,
+ final ArtifactLifecycleFactory artifactLifecycleFactory) {
+ try {
+ this.petalsAdmin = petalsAdmin != null ? petalsAdmin
+ : PetalsAdministrationFactory.getInstance().newPetalsAdministrationAPI();
+ this.artifactLifecycleFactory = artifactLifecycleFactory != null ? artifactLifecycleFactory
+ : this.petalsAdmin.newArtifactLifecycleFactory();
+ this.jdb = JBIDescriptorBuilder.getInstance();
+ } catch (JBIDescriptorException e) {
+ throw new UncheckedException(e);
+ }
+ }
+
+ public void deployRuntimeModel(final RuntimeModel model)
+ throws ConnectionFailedException, ContainerAdministrationException, ArtifactStartedException,
+ ArtifactNotDeployedException, ArtifactNotFoundException, IOException, JBIDescriptorException,
+ ArtifactAdministrationException, RuntimeModelDeployerException {
+ final RuntimeContainer container = model.getContainers().iterator().next();
+ final Collection serviceUnits = container.getServiceUnits();
+
+ LOG.fine("Deploying model (" + serviceUnits.size() + " service units)");
+
+ final String hostname = container.getHostname();
+ final int port = container.getPort();
+ final String user = container.getUser();
+ final String password = container.getPassword();
+
+ petalsAdmin.connect(hostname, port, user, password);
+
+ final Set deployedComponents = new HashSet();
+ final Set deployedServiceUnits = new HashSet();
+
+ for (final RuntimeServiceUnit serviceUnit : serviceUnits) {
+ deployRuntimeServiceUnit(serviceUnit, model, deployedComponents, deployedServiceUnits);
+ }
+
+ LOG.fine("Model deployed");
+ }
+
+ private void deployRuntimeServiceUnit(final RuntimeServiceUnit serviceUnit, final RuntimeModel model,
+ final Set deployedComponents, final Set deployedServiceUnits)
+ throws IOException, JBIDescriptorException, ArtifactStartedException, ArtifactNotDeployedException,
+ ArtifactNotFoundException, ArtifactAdministrationException, RuntimeModelDeployerException {
+ final String suId = serviceUnit.getId();
+ final File suFile = Files.createTempFile(suId, ".zip").toFile();
+ FileUtils.copyURLToFile(serviceUnit.getUrl(), suFile, ModelDeployer.CONNECTION_TIMEOUT,
+ ModelDeployer.READ_TIMEOUT);
+ final Jbi jbi = jdb.buildJavaJBIDescriptorFromArchive(suFile);
+ final ServiceAssembly jbiSa = jbi.getServiceAssembly();
+
+ if (!deployedServiceUnits.contains(suId)) {
+ LOG.fine("Deploying service assembly");
+ for (final org.ow2.petals.jbi.descriptor.original.generated.ServiceUnit jbiSu : jbiSa.getServiceUnit()) {
+ final String compName = jbiSu.getTarget().getComponentName();
+ if (!deployedComponents.contains(compName)) {
+ final RuntimeComponent component = model.getContainers().iterator().next().getComponent(compName);
+ if (component != null) {
+ deployRuntimeComponent(component);
+ deployedComponents.add(compName);
+ } else {
+ throw new ComponentDeploymentException("Component " + compName + " (needed by service unit "
+ + jbiSu.getIdentification().getName() + ") not found in the model");
+ }
+ }
+ }
+ final ServiceAssemblyLifecycle saLifecycle = artifactLifecycleFactory.createServiceAssemblyLifecycle(
+ new org.ow2.petals.admin.api.artifact.ServiceAssembly(jbiSa.getIdentification().getName()));
+ saLifecycle.deploy(suFile.toURI().toURL());
+ saLifecycle.start();
+ for (final org.ow2.petals.jbi.descriptor.original.generated.ServiceUnit jbiSu : jbiSa.getServiceUnit()) {
+ final String suName = jbiSu.getIdentification().getName();
+ if (!deployedServiceUnits.contains(suName)) {
+ deployedServiceUnits.add(suName);
+ LOG.fine("Service unit " + suName + " deployed and started");
+ } else {
+ throw new RuntimeModelDeployerException("Service unit " + suName + " already deployed");
+ }
+ }
+ }
+ }
+
+ private void deployRuntimeComponent(final RuntimeComponent component)
+ throws IOException, JBIDescriptorException, ArtifactDeployedException, ArtifactAdministrationException {
+ final String compId = component.getId();
+ final File compFile = Files.createTempFile(compId, "zip").toFile();
+ FileUtils.copyURLToFile(component.getUrl(), compFile, ModelDeployer.CONNECTION_TIMEOUT,
+ ModelDeployer.READ_TIMEOUT);
+ final Jbi jbi = jdb.buildJavaJBIDescriptorFromArchive(compFile);
+
+ LOG.fine("Deploying component " + component.getId());
+ final ComponentLifecycle compLifecycle = artifactLifecycleFactory
+ .createComponentLifecycle(new org.ow2.petals.admin.api.artifact.Component(compId,
+ convertComponentTypeFromJbiToPetalsAdmin(jbi.getComponent().getType())));
+
+ compLifecycle.deploy(compFile.toURI().toURL());
+ compLifecycle.start();
+ LOG.fine("Component " + compId + " deployed and started");
+ }
+
+ public ComponentType convertComponentTypeFromJbiToPetalsAdmin(
+ final org.ow2.petals.jbi.descriptor.original.generated.ComponentType jbiType) {
+ switch (jbiType) {
+ case BINDING_COMPONENT:
+ return ComponentType.BC;
+ case SERVICE_ENGINE:
+ return ComponentType.SE;
+ default:
+ return null;
+ }
+ }
+}
diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java
new file mode 100644
index 0000000..6f15b11
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java
@@ -0,0 +1,107 @@
+/**
+ * Copyright (c) 2018-2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils;
+
+import java.util.logging.Logger;
+
+import org.ow2.petals.admin.api.ArtifactAdministration;
+import org.ow2.petals.admin.api.PetalsAdministration;
+import org.ow2.petals.admin.api.PetalsAdministrationFactory;
+import org.ow2.petals.admin.api.artifact.Artifact;
+import org.ow2.petals.admin.api.exception.ArtifactAdministrationException;
+import org.ow2.petals.admin.api.exception.ContainerAdministrationException;
+import org.ow2.petals.admin.api.exception.DuplicatedServiceException;
+import org.ow2.petals.admin.api.exception.MissingServiceException;
+import org.ow2.petals.deployer.runtimemodel.RuntimeComponent;
+import org.ow2.petals.deployer.runtimemodel.RuntimeContainer;
+import org.ow2.petals.deployer.runtimemodel.RuntimeModel;
+import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit;
+import org.ow2.petals.deployer.runtimemodel.exceptions.RuntimeModelException;
+import org.ow2.petals.jbi.descriptor.JBIDescriptorException;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class RuntimeModelExporter {
+
+ private static final Logger LOG = Logger.getLogger(RuntimeModelExporter.class.getName());
+
+ private final PetalsAdministration petalsAdmin;
+
+ private final ArtifactAdministration artifactAdmin;
+
+ public RuntimeModelExporter() throws DuplicatedServiceException, MissingServiceException, JBIDescriptorException {
+ this(null);
+ }
+
+ public RuntimeModelExporter(final PetalsAdministration petalsAdmin) {
+ this.petalsAdmin = petalsAdmin != null ? petalsAdmin
+ : PetalsAdministrationFactory.getInstance().newPetalsAdministrationAPI();
+ artifactAdmin = this.petalsAdmin.newArtifactAdministration();
+ }
+
+ /**
+ * If topologyPassphrase is null, the exported RuntimeModel will not contain JMX usernames and JMX passwords.
+ *
+ * @param hostname
+ * @param port
+ * @param user
+ * @param password
+ * @param topologyPassphrase
+ * @return the RuntimeModel of the container corresponding to other parameters
+ * @throws RuntimeModelException
+ * @throws ArtifactAdministrationException
+ * @throws ContainerAdministrationException
+ */
+ public RuntimeModel exportRuntimeModel(final String hostname, final int port, final String user,
+ final String password, final String topologyPassphrase)
+ throws RuntimeModelException, ArtifactAdministrationException, ContainerAdministrationException {
+ petalsAdmin.connect(hostname, port, user, password);
+
+ final RuntimeModel model = new RuntimeModel();
+
+ final RuntimeContainer cont = new RuntimeContainer(petalsAdmin.newContainerAdministration()
+ .getTopology(topologyPassphrase, false).getContainers().get(0).getContainerName(), port, user, password,
+ hostname);
+ model.addContainer(cont);
+
+ for (final Artifact artifact : artifactAdmin.listArtifacts()) {
+ switch (artifact.getType()) {
+ case "BC":
+ case "SE":
+ cont.addComponent(
+ new RuntimeComponent(((org.ow2.petals.admin.api.artifact.Component) artifact).getName()));
+ break;
+ case "SU":
+ cont.addServiceUnit(new RuntimeServiceUnit(
+ ((org.ow2.petals.admin.api.artifact.ServiceUnit) artifact).getName()));
+ break;
+ case "SA":
+ // already get service units in "SU" case
+ break;
+ case "SL":
+ default:
+ throw new UnsupportedOperationException(
+ "Export model with artifact of type " + artifact.getType() + " is not implemented yet");
+ }
+ }
+
+ return model;
+ }
+}
diff --git a/src/main/java/org/ow2/petals/deployer/utils/XmlModelBuilder.java b/src/main/java/org/ow2/petals/deployer/utils/XmlModelBuilder.java
new file mode 100644
index 0000000..e45656a
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/utils/XmlModelBuilder.java
@@ -0,0 +1,108 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.util.logging.Logger;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.commons.io.FileUtils;
+import org.ow2.petals.deployer.model.xml._1.Model;
+import org.ow2.petals.deployer.model.xml._1.ObjectFactory;
+import org.ow2.petals.deployer.utils.exceptions.ModelParsingException;
+import org.ow2.petals.deployer.utils.exceptions.UncheckedException;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ *
+ */
+public class XmlModelBuilder {
+
+ private final static Logger LOG = Logger.getLogger(XmlModelBuilder.class.getName());
+
+ private final static Marshaller MARSHALLER;
+
+ private final static Unmarshaller UNMARSHALLER;
+
+ private final static ObjectFactory OF = new ObjectFactory();
+
+ static {
+ try {
+ final JAXBContext jaxbContext = JAXBContext.newInstance(Model.class);
+ MARSHALLER = jaxbContext.createMarshaller();
+ MARSHALLER.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ UNMARSHALLER = jaxbContext.createUnmarshaller();
+ } catch (JAXBException e) {
+ throw new UncheckedException(e);
+ }
+ }
+
+ /**
+ * Read the model at the url. The model must be an XML model (with schema defined in {code model.xsd} in resources
+ * directory)
+ *
+ * @param url
+ * @return the read model
+ * @throws ModelParsingException
+ */
+ public static Model readModelFromUrl(final URL url) throws ModelParsingException {
+ LOG.fine("Downloadind XML model");
+ File modelFile;
+ try {
+ modelFile = Files.createTempFile("model", ".xml").toFile();
+ } catch (IOException e) {
+ throw new UncheckedException(e);
+ }
+ try {
+ FileUtils.copyURLToFile(url, modelFile, ModelDeployer.CONNECTION_TIMEOUT, ModelDeployer.READ_TIMEOUT);
+
+ LOG.fine("Parsing XML model");
+ return UNMARSHALLER.unmarshal(new StreamSource(modelFile), Model.class).getValue();
+ } catch (IOException | JAXBException e) {
+ throw new ModelParsingException(e);
+ }
+
+ }
+
+ /**
+ * Write model to file. The same file is returned if model is successfully written.
+ *
+ * @param model
+ * @param file
+ * @return file if successfully written else null
+ * @throws ModelParsingException
+ */
+ public static File writeModelToFile(Model model, File file) throws ModelParsingException {
+ try {
+ MARSHALLER.marshal(OF.createModel(model), file);
+ return file;
+ } catch (JAXBException e) {
+ throw new ModelParsingException(e);
+ }
+
+ }
+}
diff --git a/src/main/java/org/ow2/petals/deployer/utils/exceptions/ComponentDeploymentException.java b/src/main/java/org/ow2/petals/deployer/utils/exceptions/ComponentDeploymentException.java
new file mode 100644
index 0000000..6605730
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/utils/exceptions/ComponentDeploymentException.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils.exceptions;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class ComponentDeploymentException extends RuntimeModelDeployerException {
+
+ private static final long serialVersionUID = 3893935147643008477L;
+
+ public ComponentDeploymentException(final String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelDeploymentException.java b/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelDeploymentException.java
new file mode 100644
index 0000000..4d63f9f
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelDeploymentException.java
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils.exceptions;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class ModelDeploymentException extends Exception {
+
+ private static final long serialVersionUID = 7599724111843987402L;
+
+ public ModelDeploymentException(final Throwable cause) {
+ super(cause);
+ }
+
+ public ModelDeploymentException(final String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelParsingException.java b/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelParsingException.java
new file mode 100644
index 0000000..181bad6
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelParsingException.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils.exceptions;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class ModelParsingException extends ModelDeploymentException {
+
+ private static final long serialVersionUID = 6061886715747572320L;
+
+ public ModelParsingException(final Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/src/main/java/org/ow2/petals/deployer/utils/exceptions/RuntimeModelDeployerException.java b/src/main/java/org/ow2/petals/deployer/utils/exceptions/RuntimeModelDeployerException.java
new file mode 100644
index 0000000..08864b7
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/utils/exceptions/RuntimeModelDeployerException.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2018-2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils.exceptions;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class RuntimeModelDeployerException extends Exception {
+
+ private static final long serialVersionUID = -3352449083809006549L;
+
+ public RuntimeModelDeployerException(final String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/org/ow2/petals/deployer/utils/exceptions/UncheckedException.java b/src/main/java/org/ow2/petals/deployer/utils/exceptions/UncheckedException.java
new file mode 100644
index 0000000..909a767
--- /dev/null
+++ b/src/main/java/org/ow2/petals/deployer/utils/exceptions/UncheckedException.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils.exceptions;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class UncheckedException extends RuntimeException {
+
+ private static final long serialVersionUID = 1339368144114468807L;
+
+ public UncheckedException(final Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/src/main/resources/binding.xjb b/src/main/resources/binding.xjb
new file mode 100644
index 0000000..ff83e04
--- /dev/null
+++ b/src/main/resources/binding.xjb
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/bus-model.xsd b/src/main/resources/bus-model.xsd
new file mode 100644
index 0000000..ba3b96d
--- /dev/null
+++ b/src/main/resources/bus-model.xsd
@@ -0,0 +1,169 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ The machines on which parts of a Petals ESB bus will be running.
+
+
+
+
+
+
+ The list of Petals ESB busses to deploy.
+
+
+
+
+
+
+
+
+
+
+
+ The instances of Petals ESB containers forming the Petals ESB bus.
+
+
+
+
+
+
+
+ The reference topology from the topology model.
+
+
+
+
+
+
+
+
+
+
+ The component instances required by service units.
+
+
+
+
+
+
+ The service unit instances to deploy on the container.
+
+
+
+
+
+
+
+ Reference to a container from the topology model.
+
+
+
+
+
+
+ JMX port of the current Petals ESB container. A deployment property can be used. Each
+ container (from topology model) without a default JMX port must have one defined in this model.
+
+
+
+
+
+
+ JMX username of the current Petals ESB container. A deployment property can be used. Each
+ container (from topology model) without a default JMX username must have one defined in this model.
+
+
+
+
+
+
+ JMX password of the current Petals ESB container. A deployment property can be used. Each
+ container (from topology model) without a default JMX password must have one defined in this model.
+
+
+
+
+
+
+ The reference of the machine on which the container is running.
+
+
+
+
+
+
+
+
+
+ Reference to a component from a component repository.
+
+
+
+
+
+
+
+
+
+ Reference to a service unit from a service unit model.
+
+
+
+
+
+
+
+
+
+
+
+
+ Hostname, IP address or deployment property name of the provisioned machine.
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Identifier of the machine. It must be unique in the model.
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/component-repository.xsd b/src/main/resources/component-repository.xsd
new file mode 100644
index 0000000..b9bab6f
--- /dev/null
+++ b/src/main/resources/component-repository.xsd
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+ The list of components of this repository.
+
+
+
+
+
+
+
+
+
+
+
+ The URL of the associated archive.
+
+
+
+
+
+
+
+ The identifier of this component in the model. It must be the same than the one defined in
+ the JBI descriptor of the component and must be unique in the model.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/drawio-model.xml b/src/main/resources/drawio-model.xml
new file mode 100644
index 0000000..fab42b4
--- /dev/null
+++ b/src/main/resources/drawio-model.xml
@@ -0,0 +1,19 @@
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/model.xsd b/src/main/resources/model.xsd
new file mode 100644
index 0000000..6a716be
--- /dev/null
+++ b/src/main/resources/model.xsd
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Model defining Petals ESB buses to deploy. Documentation can be found here
+ https://doc.petalslink.com/display/petalscomponents/Petals+ESB+Deployer+1.0.0
+
+
+
+
+
+
+ This model defines a set of service units to deploy on your Petals ESB bus. This model
+ will be mainly written by development teams because they have the knowledge of service units to
+ deploy.
+
+
+
+
+
+
+ This model defines a set of binding components, service engines and shared libraries that
+ can be used to perform the deployment of a Petals ESB bus. Such models are included in Petals ESB
+ distribution packs, and you can write your own.
+
+
+
+
+
+
+ This model defines a set of topologies, used by Petals ESB buses. This model will be
+ mainly written by the Petals ESB bus architect.
+
+
+
+
+
+
+ This model defines your Petals ESB bus placing Petals ESB components on their containers:
+ - service unit on its Petals ESB container
+ - Petals ESB container on its machine
+ This model will be
+ mainly written by the Petals ESB bus architect in agreement with operators.
+
+
+
+
+
+
+
diff --git a/src/main/resources/service-unit-model.xsd b/src/main/resources/service-unit-model.xsd
new file mode 100644
index 0000000..d658f67
--- /dev/null
+++ b/src/main/resources/service-unit-model.xsd
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+ Model defining Petals ESB buses to deploy. Documentation can be found here
+ https://doc.petalslink.com/display/petalscomponents/Petals+ESB+Deployer+1.0.0
+
+
+
+
+
+
+ The list of service units to deploy. There must be at least one service unit in the model.
+
+
+
+
+
+
+
+
+
+
+
+ The map of placeholder required by the service unit. The key of the map is the key of the
+ placeholder, and the value of the map is the default value of the placeholder. If there is no default
+ value, the value must be null.
+
+
+
+
+
+
+
+ Identifier of the service unit. It must be the same than the one defined in the JBI
+ descriptor on the archive and must be
+ unique in the model.
+
+
+
+
+
diff --git a/src/main/resources/topology-model.xsd b/src/main/resources/topology-model.xsd
new file mode 100644
index 0000000..10a929d
--- /dev/null
+++ b/src/main/resources/topology-model.xsd
@@ -0,0 +1,87 @@
+
+
+
+
+
+
+
+
+
+ The list of topologies in the model. Their id must be unique in the model. There must be
+ at least one topology in the model.
+
+
+
+
+
+
+
+
+
+
+
+ Petals ESB containers of the topology. Their id must be unique in the topology. There must
+ be at least one container in the topology.
+
+
+
+
+
+
+
+ Identifier of the topology.
+
+
+
+
+
+
+
+
+
+ Identifier of the Petals ESB container as used as name in the file topology.xml.
+
+
+
+
+
+
+ Default JMX port value. A deployment property can be used.
+
+
+
+
+
+
+ Default JMX username value. A deployment property can be used.
+
+
+
+
+
+
+ Default JMX password value. A deployment property can be used.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponentTest.java b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponentTest.java
new file mode 100644
index 0000000..b680028
--- /dev/null
+++ b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponentTest.java
@@ -0,0 +1,67 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.deployer.runtimemodel;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URL;
+
+import org.junit.Test;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class RuntimeComponentTest {
+
+ @Test
+ public void runtimeComponentGetters() throws Exception {
+ URL url = new URL("file:/comp.zip");
+
+ RuntimeComponent comp = new RuntimeComponent("comp");
+ assertEquals("comp", comp.getId());
+ assertNull(comp.getUrl());
+
+ comp.setUrl(url);
+ assertEquals(url, comp.getUrl());
+
+ comp = new RuntimeComponent("comp", url);
+ assertEquals("comp", comp.getId());
+ assertEquals(url, comp.getUrl());
+ }
+
+ @Test
+ public void similarRuntimeComponents() throws Exception {
+ RuntimeComponent comp1 = new RuntimeComponent("comp", new URL("file:/comp.zip"));
+ RuntimeComponent comp2 = new RuntimeComponent("comp", new URL("file:/other-comp.zip"));
+
+ assertTrue(comp1.isSimilarTo(comp2));
+ assertTrue(comp2.isSimilarTo(comp1));
+ }
+
+ @Test
+ public void notSimilarRuntimeComponents() throws Exception {
+ RuntimeComponent comp = new RuntimeComponent("comp", new URL("file:/comp.zip"));
+ RuntimeComponent compWithDifferentId = new RuntimeComponent("differentId", new URL("file:/comp.zip"));
+
+ assertFalse(comp.isSimilarTo(compWithDifferentId));
+ assertFalse(compWithDifferentId.isSimilarTo(comp));
+ }
+}
diff --git a/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainerTest.java b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainerTest.java
new file mode 100644
index 0000000..60235f9
--- /dev/null
+++ b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainerTest.java
@@ -0,0 +1,244 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.runtimemodel;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collection;
+
+import org.junit.Test;
+import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedComponentException;
+import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedServiceUnitException;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class RuntimeContainerTest {
+
+ @Test
+ public void runtimeContainerGetters() throws Exception {
+ RuntimeContainer cont = new RuntimeContainer("cont", 7700, "user", "password", "localhost");
+
+ assertEquals("cont", cont.getId());
+ assertEquals(7700, cont.getPort());
+ assertEquals("user", cont.getUser());
+ assertEquals("password", cont.getPassword());
+ assertEquals("localhost", cont.getHostname());
+
+ cont.setHostname("192.168.1.42");
+ assertEquals("192.168.1.42", cont.getHostname());
+
+ Collection components = cont.getComponents();
+
+ assertEquals(0, components.size());
+ assertNull(cont.getComponent("comp1"));
+ assertNull(cont.getComponent("comp2"));
+
+ RuntimeComponent mockComp1 = mock(RuntimeComponent.class);
+ when(mockComp1.getId()).thenReturn("comp1");
+ cont.addComponent(mockComp1);
+
+ assertEquals(1, components.size());
+ assertSame(mockComp1, cont.getComponent("comp1"));
+ assertNull(cont.getComponent("comp2"));
+
+ RuntimeComponent mockComp2 = mock(RuntimeComponent.class);
+ when(mockComp2.getId()).thenReturn("comp2");
+ cont.addComponent(mockComp2);
+
+ assertEquals(2, components.size());
+ assertSame(mockComp1, cont.getComponent("comp1"));
+ assertSame(mockComp2, cont.getComponent("comp2"));
+
+ Collection serviceUnits = cont.getServiceUnits();
+
+ assertEquals(0, serviceUnits.size());
+ assertNull(cont.getServiceUnit("su1"));
+ assertNull(cont.getServiceUnit("su2"));
+
+ RuntimeServiceUnit mockSu1 = mock(RuntimeServiceUnit.class);
+ when(mockSu1.getId()).thenReturn("su1");
+ cont.addServiceUnit(mockSu1);
+
+ assertEquals(1, serviceUnits.size());
+ assertSame(mockSu1, cont.getServiceUnit("su1"));
+ assertNull(cont.getServiceUnit("su2"));
+
+ RuntimeServiceUnit mockSu2 = mock(RuntimeServiceUnit.class);
+ when(mockSu2.getId()).thenReturn("su2");
+ cont.addServiceUnit(mockSu2);
+
+ assertEquals(2, serviceUnits.size());
+ assertSame(mockSu1, cont.getServiceUnit("su1"));
+ assertSame(mockSu2, cont.getServiceUnit("su2"));
+ }
+
+ @Test
+ public void duplicatedComponentException() throws Exception {
+ RuntimeContainer cont = new RuntimeContainer("cont", 7700, "user", "password", "localhost");
+
+ RuntimeComponent mockComp = mock(RuntimeComponent.class);
+ when(mockComp.getId()).thenReturn("comp");
+ cont.addComponent(mockComp);
+
+ RuntimeComponent mockCompWithSameId = mock(RuntimeComponent.class);
+ when(mockCompWithSameId.getId()).thenReturn("comp");
+ try {
+ cont.addComponent(mockCompWithSameId);
+ fail("Should have caught DuplicatedComponentException");
+ } catch (DuplicatedComponentException e) {
+ }
+ }
+
+ @Test
+ public void duplicatedServiceUnitException() throws Exception {
+ RuntimeContainer cont = new RuntimeContainer("cont", 7700, "user", "password", "localhost");
+
+ RuntimeServiceUnit mockSu = mock(RuntimeServiceUnit.class);
+ when(mockSu.getId()).thenReturn("su");
+ cont.addServiceUnit(mockSu);
+
+ RuntimeServiceUnit mockSuWithSameId = mock(RuntimeServiceUnit.class);
+ when(mockSuWithSameId.getId()).thenReturn("su");
+ try {
+ cont.addServiceUnit(mockSuWithSameId);
+ fail("Should have caught DuplicatedServiceUnitException");
+ } catch (DuplicatedServiceUnitException e) {
+ }
+ }
+
+ @Test
+ public void similarContainers() throws Exception {
+ RuntimeContainer cont1 = new RuntimeContainer("cont", 7700, "user", "password", "localhost");
+ RuntimeContainer cont2 = new RuntimeContainer("cont", 7700, "user", "password", "localhost");
+
+ assertTrue(cont1.isSimilarTo(cont2));
+ assertTrue(cont2.isSimilarTo(cont1));
+
+ RuntimeComponent mockComp1Cont1 = mock(RuntimeComponent.class);
+ RuntimeComponent mockComp2Cont1 = mock(RuntimeComponent.class);
+ RuntimeComponent mockComp1Cont2 = mock(RuntimeComponent.class);
+ RuntimeComponent mockComp2Cont2 = mock(RuntimeComponent.class);
+
+ when(mockComp1Cont1.getId()).thenReturn("comp1");
+ when(mockComp1Cont1.isSimilarTo(any())).thenReturn(false);
+ when(mockComp1Cont1.isSimilarTo(mockComp1Cont2)).thenReturn(true);
+
+ when(mockComp2Cont1.getId()).thenReturn("comp2");
+ when(mockComp2Cont1.isSimilarTo(any())).thenReturn(false);
+ when(mockComp2Cont1.isSimilarTo(mockComp2Cont2)).thenReturn(true);
+
+ when(mockComp1Cont2.getId()).thenReturn("comp1");
+ when(mockComp1Cont2.isSimilarTo(any())).thenReturn(false);
+ when(mockComp1Cont2.isSimilarTo(mockComp1Cont1)).thenReturn(true);
+
+ when(mockComp2Cont2.getId()).thenReturn("comp2");
+ when(mockComp2Cont2.isSimilarTo(any())).thenReturn(false);
+ when(mockComp2Cont2.isSimilarTo(mockComp2Cont1)).thenReturn(true);
+
+ cont1.addComponent(mockComp1Cont1);
+ assertFalse(cont1.isSimilarTo(cont2));
+ assertFalse(cont2.isSimilarTo(cont1));
+
+ cont1.addComponent(mockComp2Cont1);
+ assertFalse(cont1.isSimilarTo(cont2));
+ assertFalse(cont2.isSimilarTo(cont1));
+
+ cont2.addComponent(mockComp2Cont2);
+ assertFalse(cont1.isSimilarTo(cont2));
+ assertFalse(cont2.isSimilarTo(cont1));
+
+ cont2.addComponent(mockComp1Cont2);
+ assertTrue(cont1.isSimilarTo(cont2));
+ assertTrue(cont2.isSimilarTo(cont1));
+
+ RuntimeServiceUnit mockSu1Cont1 = mock(RuntimeServiceUnit.class);
+ RuntimeServiceUnit mockSu2Cont1 = mock(RuntimeServiceUnit.class);
+ RuntimeServiceUnit mockSu1Cont2 = mock(RuntimeServiceUnit.class);
+ RuntimeServiceUnit mockSu2Cont2 = mock(RuntimeServiceUnit.class);
+
+ when(mockSu1Cont1.getId()).thenReturn("su1");
+ when(mockSu1Cont1.isSimilarTo(any())).thenReturn(false);
+ when(mockSu1Cont1.isSimilarTo(mockSu1Cont2)).thenReturn(true);
+
+ when(mockSu2Cont1.getId()).thenReturn("su2");
+ when(mockSu2Cont1.isSimilarTo(any())).thenReturn(false);
+ when(mockSu2Cont1.isSimilarTo(mockSu2Cont2)).thenReturn(true);
+
+ when(mockSu1Cont2.getId()).thenReturn("su1");
+ when(mockSu1Cont2.isSimilarTo(any())).thenReturn(false);
+ when(mockSu1Cont2.isSimilarTo(mockSu1Cont1)).thenReturn(true);
+
+ when(mockSu2Cont2.getId()).thenReturn("su2");
+ when(mockSu2Cont2.isSimilarTo(any())).thenReturn(false);
+ when(mockSu2Cont2.isSimilarTo(mockSu2Cont1)).thenReturn(true);
+
+ cont1.addServiceUnit(mockSu1Cont1);
+ assertFalse(cont1.isSimilarTo(cont2));
+ assertFalse(cont2.isSimilarTo(cont1));
+
+ cont1.addServiceUnit(mockSu2Cont1);
+ assertFalse(cont1.isSimilarTo(cont2));
+ assertFalse(cont2.isSimilarTo(cont1));
+
+ cont2.addServiceUnit(mockSu2Cont2);
+ assertFalse(cont1.isSimilarTo(cont2));
+ assertFalse(cont2.isSimilarTo(cont1));
+
+ cont2.addServiceUnit(mockSu1Cont2);
+ assertTrue(cont1.isSimilarTo(cont2));
+ assertTrue(cont2.isSimilarTo(cont1));
+ }
+
+ @Test
+ public void notSimilarContainers() {
+ RuntimeContainer cont = new RuntimeContainer("cont", 7700, "user", "password", "localhost");
+
+ RuntimeContainer contWithDifferentId = new RuntimeContainer("otherId", 7700, "user", "password", "localhost");
+ assertFalse(cont.isSimilarTo(contWithDifferentId));
+ assertFalse(contWithDifferentId.isSimilarTo(cont));
+
+ RuntimeContainer contWithDifferentPort = new RuntimeContainer("cont", 9999, "user", "password", "localhost");
+ assertFalse(cont.isSimilarTo(contWithDifferentPort));
+ assertFalse(contWithDifferentPort.isSimilarTo(cont));
+
+ RuntimeContainer contWithDifferentUser = new RuntimeContainer("cont", 7700, "otherUser", "password",
+ "localhost");
+ assertFalse(cont.isSimilarTo(contWithDifferentUser));
+ assertFalse(contWithDifferentUser.isSimilarTo(cont));
+
+ RuntimeContainer contWithDifferentPassword = new RuntimeContainer("cont", 7700, "user", "otherPassword",
+ "localhost");
+ assertFalse(cont.isSimilarTo(contWithDifferentPassword));
+ assertFalse(contWithDifferentPassword.isSimilarTo(cont));
+
+ RuntimeContainer contWithDifferentHostname = new RuntimeContainer("cont", 7700, "user", "password",
+ "192.168.1.42");
+ assertFalse(cont.isSimilarTo(contWithDifferentHostname));
+ assertFalse(contWithDifferentHostname.isSimilarTo(cont));
+ }
+}
diff --git a/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java
new file mode 100644
index 0000000..f3ebdce
--- /dev/null
+++ b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java
@@ -0,0 +1,129 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.runtimemodel;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collection;
+
+import org.junit.Test;
+import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedContainerException;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class RuntimeModelTest {
+
+ @Test
+ public void runtimeModelGetters() throws Exception {
+ RuntimeModel model = new RuntimeModel();
+ Collection containers = model.getContainers();
+
+ assertEquals(0, containers.size());
+ assertNull(model.getContainer("cont1"));
+ assertNull(model.getContainer("cont2"));
+
+ RuntimeContainer mockCont1 = mock(RuntimeContainer.class);
+ when(mockCont1.getId()).thenReturn("cont1");
+ model.addContainer(mockCont1);
+
+ assertEquals(1, containers.size());
+ assertSame(mockCont1, model.getContainer("cont1"));
+ assertNull(model.getContainer("cont2"));
+
+ RuntimeContainer mockCont2 = mock(RuntimeContainer.class);
+ when(mockCont2.getId()).thenReturn("cont2");
+ model.addContainer(mockCont2);
+
+ assertEquals(2, containers.size());
+ assertSame(mockCont1, model.getContainer("cont1"));
+ assertSame(mockCont2, model.getContainer("cont2"));
+ }
+
+ @Test
+ public void runtimeModelDuplicatedContainerException() throws Exception {
+ RuntimeModel model = new RuntimeModel();
+
+ RuntimeContainer mockCont = mock(RuntimeContainer.class);
+ when(mockCont.getId()).thenReturn("cont");
+ model.addContainer(mockCont);
+
+ RuntimeContainer mockContWithSameId = mock(RuntimeContainer.class);
+ when(mockContWithSameId.getId()).thenReturn("cont");
+ try {
+ model.addContainer(mockContWithSameId);
+ fail("Should have caught DuplicatedContainerException");
+ } catch (DuplicatedContainerException e) {
+ }
+ }
+
+ @Test
+ public void similarRuntimeModels() throws Exception {
+ RuntimeModel model1 = new RuntimeModel();
+ RuntimeModel model2 = new RuntimeModel();
+
+ assertTrue(model1.isSimilarTo(model2));
+ assertTrue(model2.isSimilarTo(model1));
+
+ RuntimeContainer mockCont1Model1 = mock(RuntimeContainer.class);
+ RuntimeContainer mockCont2Model1 = mock(RuntimeContainer.class);
+ RuntimeContainer mockCont1Model2 = mock(RuntimeContainer.class);
+ RuntimeContainer mockCont2Model2 = mock(RuntimeContainer.class);
+
+ when(mockCont1Model1.getId()).thenReturn("cont1");
+ when(mockCont1Model1.isSimilarTo(any())).thenReturn(false);
+ when(mockCont1Model1.isSimilarTo(mockCont1Model2)).thenReturn(true);
+
+ when(mockCont2Model1.getId()).thenReturn("cont2");
+ when(mockCont2Model1.isSimilarTo(any())).thenReturn(false);
+ when(mockCont2Model1.isSimilarTo(mockCont2Model2)).thenReturn(true);
+
+ when(mockCont1Model2.getId()).thenReturn("cont1");
+ when(mockCont1Model2.isSimilarTo(any())).thenReturn(false);
+ when(mockCont1Model2.isSimilarTo(mockCont1Model1)).thenReturn(true);
+
+ when(mockCont2Model2.getId()).thenReturn("cont2");
+ when(mockCont2Model2.isSimilarTo(any())).thenReturn(false);
+ when(mockCont2Model2.isSimilarTo(mockCont2Model1)).thenReturn(true);
+
+ model1.addContainer(mockCont1Model1);
+ assertFalse(model1.isSimilarTo(model2));
+ assertFalse(model2.isSimilarTo(model1));
+
+ model1.addContainer(mockCont2Model1);
+ assertFalse(model1.isSimilarTo(model2));
+ assertFalse(model2.isSimilarTo(model1));
+
+ model2.addContainer(mockCont1Model2);
+ assertFalse(model1.isSimilarTo(model2));
+ assertFalse(model2.isSimilarTo(model1));
+
+ model2.addContainer(mockCont2Model2);
+ assertTrue(model1.isSimilarTo(model2));
+ assertTrue(model2.isSimilarTo(model1));
+ }
+}
diff --git a/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnitTest.java b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnitTest.java
new file mode 100644
index 0000000..1bfaeb4
--- /dev/null
+++ b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnitTest.java
@@ -0,0 +1,67 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.deployer.runtimemodel;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URL;
+
+import org.junit.Test;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class RuntimeServiceUnitTest {
+
+ @Test
+ public void runtimeServiceUnitGetters() throws Exception {
+ URL url = new URL("file:/su.zip");
+
+ RuntimeServiceUnit su = new RuntimeServiceUnit("su");
+ assertEquals("su", su.getId());
+ assertNull(su.getUrl());
+
+ su.setUrl(url);
+ assertEquals(url, su.getUrl());
+
+ su = new RuntimeServiceUnit("su", url);
+ assertEquals("su", su.getId());
+ assertEquals(url, su.getUrl());
+ }
+
+ @Test
+ public void similarRuntimeComponents() throws Exception {
+ RuntimeServiceUnit su = new RuntimeServiceUnit("su", new URL("file:/su.zip"));
+ RuntimeServiceUnit suWithDifferentUrl = new RuntimeServiceUnit("su", new URL("file:/other-url.zip"));
+
+ assertTrue(su.isSimilarTo(suWithDifferentUrl));
+ assertTrue(suWithDifferentUrl.isSimilarTo(su));
+ }
+
+ @Test
+ public void notSimilarRuntimeComponents() throws Exception {
+ RuntimeServiceUnit su = new RuntimeServiceUnit("su", new URL("file:/su.zip"));
+ RuntimeServiceUnit suWithDifferentId = new RuntimeServiceUnit("differentId", new URL("file:/su.zip"));
+
+ assertFalse(su.isSimilarTo(suWithDifferentId));
+ assertFalse(suWithDifferentId.isSimilarTo(su));
+ }
+}
diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java
new file mode 100644
index 0000000..9ce0196
--- /dev/null
+++ b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java
@@ -0,0 +1,76 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collection;
+
+import org.junit.Test;
+import org.ow2.petals.deployer.model.xml._1.Model;
+import org.ow2.petals.deployer.runtimemodel.RuntimeComponent;
+import org.ow2.petals.deployer.runtimemodel.RuntimeContainer;
+import org.ow2.petals.deployer.runtimemodel.RuntimeModel;
+import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class ModelConverterTest {
+
+ @Test
+ public void convertModelToRuntimeModel() throws Exception {
+ final Model model = ModelUtils.generateTestModel();
+
+ final RuntimeModel runtimeModel = ModelConverter.convertModelToRuntimeModel(model);
+
+ final Collection containers = runtimeModel.getContainers();
+ assertEquals(1, containers.size());
+
+ final RuntimeContainer cont = containers.iterator().next();
+ assertEquals(ModelUtils.CONTAINER_NAME, cont.getId());
+ assertEquals(ModelUtils.CONTAINER_HOST, cont.getHostname());
+ assertEquals(ModelUtils.CONTAINER_JMX_PORT, cont.getPort());
+ assertEquals(ModelUtils.CONTAINER_USER, cont.getUser());
+ assertEquals(ModelUtils.CONTAINER_PWD, cont.getPassword());
+
+ final Collection serviceUnits = cont.getServiceUnits();
+ assertEquals(3, serviceUnits.size());
+
+ RuntimeServiceUnit su = cont.getServiceUnit("su-SOAP-Hello_Service1-provide");
+ assertEquals("su-SOAP-Hello_Service1-provide", su.getId());
+ assertEquals("file:/artifacts/sa-SOAP-Hello_Service1-provide", su.getUrl().toString());
+
+ su = cont.getServiceUnit("su-SOAP-Hello_Service2-provide");
+ assertEquals("su-SOAP-Hello_Service2-provide", su.getId());
+ assertEquals("file:/artifacts/sa-SOAP-Hello_Service2-provide", su.getUrl().toString());
+
+ su = cont.getServiceUnit("su-SOAP-Hello_PortType-consume");
+ assertEquals("su-SOAP-Hello_PortType-consume", su.getId());
+ assertEquals("file:/artifacts/sa-SOAP-Hello_PortType-consume", su.getUrl().toString());
+
+ final Collection components = cont.getComponents();
+ assertEquals(1, components.size());
+
+ final RuntimeComponent comp = cont.getComponent("petals-bc-soap");
+ assertEquals("petals-bc-soap", comp.getId());
+ assertEquals("file:/artifacts/petals-bc-soap-5.0.0", comp.getUrl().toString());
+ }
+
+}
diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelDeployerTest.java b/src/test/java/org/ow2/petals/deployer/utils/ModelDeployerTest.java
new file mode 100644
index 0000000..88e4120
--- /dev/null
+++ b/src/test/java/org/ow2/petals/deployer/utils/ModelDeployerTest.java
@@ -0,0 +1,50 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.net.URL;
+
+import org.junit.Test;
+import org.ow2.petals.deployer.runtimemodel.RuntimeModel;
+
+public class ModelDeployerTest {
+
+ private RuntimeModelDeployer runtimeModelDeployerMock = mock(RuntimeModelDeployer.class);
+
+ private ModelDeployer modelDeployer = new ModelDeployer(runtimeModelDeployerMock);
+
+ @Test
+ public void deployModelFile() throws Exception {
+ URL modelUrl = Thread.currentThread().getContextClassLoader().getResource("model.xml").toURI().toURL();
+ modelDeployer.deployModel(modelUrl);
+
+ verify(runtimeModelDeployerMock).deployRuntimeModel(any(RuntimeModel.class));
+ }
+
+ @Test
+ public void deployModel() throws Exception {
+ modelDeployer.deployModel(ModelUtils.generateTestModel());
+
+ verify(runtimeModelDeployerMock).deployRuntimeModel(any(RuntimeModel.class));
+ }
+}
diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java b/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java
new file mode 100644
index 0000000..18e37d8
--- /dev/null
+++ b/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java
@@ -0,0 +1,175 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+import org.ow2.petals.admin.topology.Container.State;
+import org.ow2.petals.deployer.model.bus.xml._1.Bus;
+import org.ow2.petals.deployer.model.bus.xml._1.BusModel;
+import org.ow2.petals.deployer.model.bus.xml._1.ComponentInstance;
+import org.ow2.petals.deployer.model.bus.xml._1.ContainerInstance;
+import org.ow2.petals.deployer.model.bus.xml._1.ProvisionedMachine;
+import org.ow2.petals.deployer.model.bus.xml._1.ServiceUnitInstance;
+import org.ow2.petals.deployer.model.component_repository.xml._1.Component;
+import org.ow2.petals.deployer.model.component_repository.xml._1.ComponentRepository;
+import org.ow2.petals.deployer.model.service_unit.xml._1.ServiceUnit;
+import org.ow2.petals.deployer.model.service_unit.xml._1.ServiceUnitModel;
+import org.ow2.petals.deployer.model.topology.xml._1.Container;
+import org.ow2.petals.deployer.model.topology.xml._1.Topology;
+import org.ow2.petals.deployer.model.topology.xml._1.TopologyModel;
+import org.ow2.petals.deployer.model.xml._1.Model;
+import org.ow2.petals.deployer.runtimemodel.RuntimeComponent;
+import org.ow2.petals.deployer.runtimemodel.RuntimeContainer;
+import org.ow2.petals.deployer.runtimemodel.RuntimeModel;
+import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit;
+import org.ow2.petals.deployer.utils.exceptions.UncheckedException;
+
+public class ModelUtils {
+
+ final public static String CONTAINER_NAME = "sample-0";
+
+ final public static String CONTAINER_HOST = "localhost";
+
+ final public static int CONTAINER_JMX_PORT = 7700;
+
+ final public static String CONTAINER_USER = "petals";
+
+ final public static String CONTAINER_PWD = "petals";
+
+ final public static State CONTAINER_STATE = State.REACHABLE;
+
+ public static Model generateTestModel() throws MalformedURLException, IOException, URISyntaxException {
+ final Model model = new Model();
+
+ /* Component Repository */
+
+ final ComponentRepository compRepo = new ComponentRepository();
+ model.setComponentRepository(compRepo);
+
+ final Component bcSoap = new Component();
+ bcSoap.setId("petals-bc-soap");
+ bcSoap.setUrl("file:/artifacts/petals-bc-soap-5.0.0");
+ compRepo.getComponent().add(bcSoap);
+
+ /* Service Unit Model */
+
+ final ServiceUnitModel suModel = new ServiceUnitModel();
+ model.setServiceUnitModel(suModel);
+
+ final List serviceUnits = suModel.getServiceUnit();
+
+ final ServiceUnit suProv1 = new ServiceUnit();
+ suProv1.setId("su-SOAP-Hello_Service1-provide");
+ suProv1.setUrl("file:/artifacts/sa-SOAP-Hello_Service1-provide");
+ serviceUnits.add(suProv1);
+
+ final ServiceUnit suProv2 = new ServiceUnit();
+ suProv2.setId("su-SOAP-Hello_Service2-provide");
+ suProv2.setUrl("file:/artifacts/sa-SOAP-Hello_Service2-provide");
+ serviceUnits.add(suProv2);
+
+ final ServiceUnit suCons = new ServiceUnit();
+ suCons.setId("su-SOAP-Hello_PortType-consume");
+ suCons.setUrl("file:/artifacts/sa-SOAP-Hello_PortType-consume");
+ serviceUnits.add(suCons);
+
+ /* Topology Model */
+
+ final TopologyModel topoModel = new TopologyModel();
+ model.setTopologyModel(topoModel);
+
+ final Topology topo = new Topology();
+ topo.setId("topo1");
+ topoModel.getTopology().add(topo);
+
+ final Container cont = new Container();
+ cont.setId(CONTAINER_NAME);
+ cont.setDefaultJmxPort(CONTAINER_JMX_PORT);
+ cont.setDefaultJmxUser(CONTAINER_USER);
+ cont.setDefaultJmxPassword(CONTAINER_PWD);
+ topo.getContainer().add(cont);
+
+ /* Bus Model */
+
+ final BusModel busModel = new BusModel();
+ model.setBusModel(busModel);
+
+ final ProvisionedMachine machine = new ProvisionedMachine();
+ machine.setId("main");
+ machine.setHostname("localhost");
+ busModel.getMachine().add(machine);
+
+ final Bus bus = new Bus();
+ bus.setTopologyRef(topo.getId());
+ busModel.getBus().add(bus);
+
+ final ContainerInstance contInst = new ContainerInstance();
+ contInst.setRef(cont.getId());
+ contInst.setMachineRef(machine.getId());
+ bus.getContainerInstance().add(contInst);
+
+ final ComponentInstance bcSoapInst = new ComponentInstance();
+ bcSoapInst.setRef(bcSoap.getId());
+ contInst.getComponentInstance().add(bcSoapInst);
+
+ final List suInstances = contInst.getServiceUnitInstance();
+
+ ServiceUnitInstance suInst = new ServiceUnitInstance();
+ suInst.setRef(suProv1.getId());
+ suInstances.add(suInst);
+
+ suInst = new ServiceUnitInstance();
+ suInst.setRef(suProv2.getId());
+ suInstances.add(suInst);
+
+ suInst = new ServiceUnitInstance();
+ suInst.setRef(suCons.getId());
+ suInstances.add(suInst);
+
+ return model;
+ }
+
+ public static RuntimeModel generateTestRuntimeModel() {
+ try {
+ final RuntimeModel model = new RuntimeModel();
+
+ final RuntimeContainer cont = new RuntimeContainer(CONTAINER_NAME, CONTAINER_JMX_PORT, CONTAINER_USER,
+ CONTAINER_PWD, CONTAINER_HOST);
+ model.addContainer(cont);
+
+ cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_Service1-provide",
+ new URL("file:/artifacts/sa-SOAP-Hello_Service1-provide")));
+ cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_Service2-provide",
+ new URL("file:/artifacts/sa-SOAP-Hello_Service2-provide")));
+ cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_PortType-consume",
+ new URL("file:/artifacts/sa-SOAP-Hello_PortType-consume")));
+
+ cont.addComponent(new RuntimeComponent("petals-bc-soap", new URL("file:/artifacts/petals-bc-soap-5.0.0")));
+
+ return model;
+ } catch (final Exception e) {
+ throw new UncheckedException(e);
+ }
+ }
+}
diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java
new file mode 100644
index 0000000..4de6bc6
--- /dev/null
+++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java
@@ -0,0 +1,81 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URL;
+
+import org.junit.Test;
+import org.ow2.petals.deployer.runtimemodel.RuntimeComponent;
+import org.ow2.petals.deployer.runtimemodel.RuntimeContainer;
+import org.ow2.petals.deployer.runtimemodel.RuntimeModel;
+import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit;
+
+public class RuntimeModelComparatorTest {
+
+ @Test
+ public void equivalentRuntimeModels() throws Exception {
+ final RuntimeModel model = ModelUtils.generateTestRuntimeModel();
+
+ final RuntimeModel similarModel = ModelUtils.generateTestRuntimeModel();
+
+ assertTrue(model.isSimilarTo(similarModel));
+ assertTrue(similarModel.isSimilarTo(model));
+ }
+
+ @Test
+ public void differentServiceUnitListsRuntimeModels() throws Exception {
+ final RuntimeModel model = ModelUtils.generateTestRuntimeModel();
+
+ final RuntimeModel modelWithDifferentServiceUnitList = ModelUtils.generateTestRuntimeModel();
+ modelWithDifferentServiceUnitList.getContainers().iterator().next()
+ .addServiceUnit(new RuntimeServiceUnit("my-test-su", new URL("file:/artifact/my-test-su.zip")));
+
+ assertFalse(model.isSimilarTo(modelWithDifferentServiceUnitList));
+ assertFalse(modelWithDifferentServiceUnitList.isSimilarTo(model));
+ }
+
+ @Test
+ public void differentComponentListsRuntimeModels() throws Exception {
+ final RuntimeModel model = ModelUtils.generateTestRuntimeModel();
+
+ final RuntimeModel modelWithDifferentComponentList = ModelUtils.generateTestRuntimeModel();
+ modelWithDifferentComponentList.getContainers().iterator().next()
+ .addComponent(new RuntimeComponent("my-test-comp", new URL("file:/artifact/my-test-comp.zip")));
+
+ assertFalse(model.isSimilarTo(modelWithDifferentComponentList));
+ assertFalse(modelWithDifferentComponentList.isSimilarTo(model));
+ }
+
+ @Test
+ public void differentContainersRuntimeModels() throws Exception {
+ final RuntimeModel model = ModelUtils.generateTestRuntimeModel();
+
+ final RuntimeModel modelWithDifferentContainer = ModelUtils.generateTestRuntimeModel();
+ modelWithDifferentContainer.getContainers().clear();
+ final RuntimeContainer differentCont = new RuntimeContainer("different-cont", 7700, "other", "azerty",
+ "localhost");
+ modelWithDifferentContainer.addContainer(differentCont);
+
+ assertFalse(model.isSimilarTo(modelWithDifferentContainer));
+ assertFalse(modelWithDifferentContainer.isSimilarTo(model));
+ }
+}
diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java
new file mode 100644
index 0000000..c717ffd
--- /dev/null
+++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java
@@ -0,0 +1,109 @@
+/**
+ * Copyright (c) 2018-2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+
+package org.ow2.petals.deployer.utils;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.ow2.petals.admin.junit.ArtifactLifecycleFactoryMock;
+import org.ow2.petals.admin.junit.PetalsAdministrationApi;
+import org.ow2.petals.admin.topology.Container.PortType;
+import org.ow2.petals.deployer.runtimemodel.RuntimeComponent;
+import org.ow2.petals.deployer.runtimemodel.RuntimeContainer;
+import org.ow2.petals.deployer.runtimemodel.RuntimeModel;
+import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class RuntimeModelDeployerTest {
+
+ @Rule
+ public PetalsAdministrationApi petalsAdminApiRule = new PetalsAdministrationApi();
+
+ @BeforeClass
+ public static void setupLogger() throws Exception {
+ final Logger deployerLogger = Logger.getLogger(RuntimeModelDeployer.class.getName());
+ deployerLogger.setLevel(Level.FINER);
+ final Handler consoleHandler = new ConsoleHandler();
+ consoleHandler.setLevel(Level.FINER);
+ final Formatter formatter = new Formatter() {
+ @Override
+ public String format(final LogRecord record) {
+ return record.getMessage() + "\n";
+ }
+ };
+ consoleHandler.setFormatter(formatter);
+ deployerLogger.addHandler(consoleHandler);
+ }
+
+ @Test
+ public void deployRuntimeModel() throws Exception {
+ petalsAdminApiRule.registerDomain();
+ org.ow2.petals.admin.topology.Container cont = createContainerSample();
+ petalsAdminApiRule.registerContainer(cont);
+ final ArtifactLifecycleFactoryMock artifactLifecycleFactoryMock = new ArtifactLifecycleFactoryMock(cont);
+ final RuntimeModelDeployer modelDeployer = new RuntimeModelDeployer(petalsAdminApiRule.getSingleton(),
+ artifactLifecycleFactoryMock);
+
+ final RuntimeModel model = generateRuntimeModel();
+ modelDeployer.deployRuntimeModel(model);
+
+ final RuntimeModelExporter modelExporter = new RuntimeModelExporter(petalsAdminApiRule.getSingleton());
+ final RuntimeModel exportedModel = modelExporter.exportRuntimeModel(ModelUtils.CONTAINER_HOST,
+ ModelUtils.CONTAINER_JMX_PORT, ModelUtils.CONTAINER_USER, ModelUtils.CONTAINER_PWD, null);
+
+ assertTrue(model.isSimilarTo(exportedModel));
+ }
+
+ public static org.ow2.petals.admin.topology.Container createContainerSample() {
+ final Map ports = new HashMap<>();
+ ports.put(PortType.JMX, ModelUtils.CONTAINER_JMX_PORT);
+ return new org.ow2.petals.admin.topology.Container(ModelUtils.CONTAINER_NAME, ModelUtils.CONTAINER_HOST, ports,
+ ModelUtils.CONTAINER_USER, ModelUtils.CONTAINER_PWD, ModelUtils.CONTAINER_STATE);
+ }
+
+ public RuntimeModel generateRuntimeModel() throws Exception {
+ final RuntimeModel model = new RuntimeModel();
+ final RuntimeContainer cont = new RuntimeContainer(ModelUtils.CONTAINER_NAME, ModelUtils.CONTAINER_JMX_PORT,
+ ModelUtils.CONTAINER_USER, ModelUtils.CONTAINER_PWD, "localhost");
+ model.addContainer(cont);
+ cont.addComponent(new RuntimeComponent("petals-bc-soap",
+ ZipUtils.createZipFromResourceDirectory("artifacts/petals-bc-soap-5.0.0").toURI().toURL()));
+ cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_Service1-provide",
+ ZipUtils.createZipFromResourceDirectory("artifacts/sa-SOAP-Hello_Service1-provide").toURI().toURL()));
+ cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_Service2-provide",
+ ZipUtils.createZipFromResourceDirectory("artifacts/sa-SOAP-Hello_Service2-provide").toURI().toURL()));
+ cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_PortType-consume",
+ ZipUtils.createZipFromResourceDirectory("artifacts/sa-SOAP-Hello_PortType-consume").toURI().toURL()));
+
+ return model;
+ }
+}
diff --git a/src/test/java/org/ow2/petals/deployer/utils/XmlModelBuilderTest.java b/src/test/java/org/ow2/petals/deployer/utils/XmlModelBuilderTest.java
new file mode 100644
index 0000000..c608673
--- /dev/null
+++ b/src/test/java/org/ow2/petals/deployer/utils/XmlModelBuilderTest.java
@@ -0,0 +1,50 @@
+/**
+ * Copyright (c) 2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.deployer.utils;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.FileReader;
+import java.net.URL;
+import java.nio.file.Files;
+
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Test;
+import org.ow2.petals.deployer.model.xml._1.Model;
+import org.xml.sax.InputSource;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ *
+ */
+public class XmlModelBuilderTest {
+
+ @Test
+ public void test() throws Exception {
+ URL initialModelUrl = Thread.currentThread().getContextClassLoader().getResource("model.xml");
+ File initialModelFile = new File(initialModelUrl.getFile());
+ Model model = XmlModelBuilder.readModelFromUrl(initialModelUrl);
+ File marshalledModelFile = Files.createTempFile("marshalled-model", ".xml").toFile();
+ XmlModelBuilder.writeModelToFile(model, marshalledModelFile);
+
+ assertTrue(XMLUnit.compareXML(new InputSource(new FileReader(initialModelFile)),
+ new InputSource(new FileReader(marshalledModelFile))).similar());
+ }
+
+}
diff --git a/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java b/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java
new file mode 100644
index 0000000..e09d81b
--- /dev/null
+++ b/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java
@@ -0,0 +1,78 @@
+/**
+ * Copyright (c) 2018-2019 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+
+ */
+package org.ow2.petals.deployer.utils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * @author Alexandre Lagane - Linagora
+ */
+public class ZipUtils {
+
+ private static final int DEFAULT_BUFFER_SIZE = 1024;
+
+ /**
+ * Return a zip archive of a directory (the directory is considered the root of the archive).
+ *
+ * The created zip archive is a temporary file.
+ *
+ * @param resourcePath
+ * The path to the directory in resources
+ * @return The zip file created
+ * @throws IOException
+ * @throws URISyntaxException
+ */
+ public static File createZipFromResourceDirectory(final String resourcePath)
+ throws IOException, URISyntaxException {
+ final File zip = Files.createTempFile(null, null).toFile();
+ final File resource = new File(
+ Thread.currentThread().getContextClassLoader().getResource(resourcePath).toURI());
+ final ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip));
+ for (final File file : resource.listFiles()) {
+ addDirectoryToZip("", file, zos);
+ }
+ zos.close();
+ return zip;
+ }
+
+ private static void addDirectoryToZip(final String prefix, final File file, final ZipOutputStream zos)
+ throws IOException {
+ if (file.isDirectory()) {
+ for (final File child : file.listFiles()) {
+ addDirectoryToZip(prefix + file.getName() + "/", child, zos);
+ }
+ } else {
+ zos.putNextEntry(new ZipEntry(prefix + file.getName()));
+ final FileInputStream fis = new FileInputStream(file);
+ byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
+ while (fis.available() > 0) {
+ int read = fis.read(buffer, 0, buffer.length);
+ zos.write(buffer, 0, read);
+ }
+ fis.close();
+ }
+ }
+}
diff --git a/src/test/resources/artifacts/petals-bc-soap-5.0.0/META-INF/jbi.xml b/src/test/resources/artifacts/petals-bc-soap-5.0.0/META-INF/jbi.xml
new file mode 100644
index 0000000..3bdaf6a
--- /dev/null
+++ b/src/test/resources/artifacts/petals-bc-soap-5.0.0/META-INF/jbi.xml
@@ -0,0 +1,217 @@
+
+
+
+
+
+ petals-bc-soap
+ The PEtALS SOAP JBI binding component based on Axis2 and Jetty.
+
+ org.ow2.petals.binding.soap.SoapComponent
+
+ velocity-1.5.jar
+ axis2-mtompolicy-1.7.7.jar
+ xml-resolver-1.2.jar
+ easycommons-stream-1.4.0.jar
+ serializer-2.7.1.jar
+ jcip-annotations-1.0.jar
+ jetty-servlet-9.4.11.v20180605.jar
+ commons-httpclient-3.1.jar
+ petals-cdk-steplog-1.1.1.jar
+ esapi-2.0GA.jar
+ petals-bc-soap-5.0.0.jar
+ woodstox-core-asl-4.2.0.jar
+ httpclient-4.5.2.jar
+ petals-cdk-api-2.6.1.jar
+ commons-lang-2.1.jar
+ rampart-core-1.7.1.jar
+ xalan-2.7.1.jar
+ petals-probes-api-1.3.0.jar
+ wsdl4j-1.6.2.jar
+ jaxb2-basics-runtime-0.11.1.jar
+ axis2-transport-jms-1.7.7.jar
+ easycommons-util-2.5.0.jar
+ bcprov-jdk15on-1.59.jar
+ javax.servlet-api-3.1.0.jar
+ jetty-security-9.4.11.v20180605.jar
+ mex-1.7.6-impl.jar
+ wss4j-1.6.16.jar
+ axiom-impl-1.2.20.jar
+ geronimo-jms_1.1_spec-1.1.jar
+ petals-probes-1.3.0.jar
+ easywsdl-ext-wsdl4complexwsdl-2.7.0.jar
+ easywsdl-wsdl-2.7.0.jar
+ jetty-server-9.4.11.v20180605.jar
+ rampart-trust-1.7.1.jar
+ petals-cdk-core-5.7.1.jar
+ jetty-io-9.4.11.v20180605.jar
+ addressing-1.7.7.mar
+ commons-codec-1.9.jar
+ stax2-api-3.1.1.jar
+ commons-fileupload-1.3.3.jar
+ xmltooling-1.3.2-1.jar
+ rampart-1.7.1.mar
+ petals-cdk-jbidescriptor-2.6.1.jar
+ axiom-dom-1.2.20.jar
+ opensaml-2.5.1-1.jar
+ xmlschema-core-2.2.1.jar
+ woden-core-1.0M10.jar
+ commons-collections-3.1.jar
+ rampart-policy-1.7.1.jar
+ jaxb-impl-2.2.11.jar
+ easywsdl-schema-2.7.0.jar
+ openws-1.4.2-1.jar
+ petals-cdk-clientserver-api-1.2.1.jar
+ axiom-api-1.2.20.jar
+ geronimo-jta_1.1_spec-1.1.jar
+ petals-bc-soap-clientserver-api-1.2.0.jar
+ jetty-http-9.4.11.v20180605.jar
+ axis2-transport-base-1.7.7.jar
+ petals-jbi-descriptor-2.4.0.jar
+ axis2-kernel-1.7.7.jar
+ apache-mime4j-core-0.7.2.jar
+ neethi-3.0.3.jar
+ jaxen-1.1.6.jar
+ petals-basis-api-1.1.0.jar
+ axis2-transport-http-1.7.7.jar
+ joda-time-1.6.2.jar
+ jaxb-core-2.2.11.jar
+ xmlunit-1.6.jar
+ jsr311-api-1.1.1.jar
+ xmlsec-1.5.8.jar
+ commons-io-2.6.jar
+ jetty-util-9.4.11.v20180605.jar
+ javax.mail-1.5.6.jar
+ commons-httpclient-contrib-3.1.jar
+ httpcore-4.4.4.jar
+
+ org.ow2.petals.binding.soap.SoapBootstrap
+
+ velocity-1.5.jar
+ axis2-mtompolicy-1.7.7.jar
+ xml-resolver-1.2.jar
+ easycommons-stream-1.4.0.jar
+ serializer-2.7.1.jar
+ jcip-annotations-1.0.jar
+ jetty-servlet-9.4.11.v20180605.jar
+ commons-httpclient-3.1.jar
+ petals-cdk-steplog-1.1.1.jar
+ esapi-2.0GA.jar
+ petals-bc-soap-5.0.0.jar
+ woodstox-core-asl-4.2.0.jar
+ httpclient-4.5.2.jar
+ petals-cdk-api-2.6.1.jar
+ commons-lang-2.1.jar
+ rampart-core-1.7.1.jar
+ xalan-2.7.1.jar
+ petals-probes-api-1.3.0.jar
+ wsdl4j-1.6.2.jar
+ jaxb2-basics-runtime-0.11.1.jar
+ axis2-transport-jms-1.7.7.jar
+ easycommons-util-2.5.0.jar
+ bcprov-jdk15on-1.59.jar
+ javax.servlet-api-3.1.0.jar
+ jetty-security-9.4.11.v20180605.jar
+ mex-1.7.6-impl.jar
+ wss4j-1.6.16.jar
+ axiom-impl-1.2.20.jar
+ geronimo-jms_1.1_spec-1.1.jar
+ petals-probes-1.3.0.jar
+ easywsdl-ext-wsdl4complexwsdl-2.7.0.jar
+ easywsdl-wsdl-2.7.0.jar
+ jetty-server-9.4.11.v20180605.jar
+ rampart-trust-1.7.1.jar
+ petals-cdk-core-5.7.1.jar
+ jetty-io-9.4.11.v20180605.jar
+ addressing-1.7.7.mar
+ commons-codec-1.9.jar
+ stax2-api-3.1.1.jar
+ commons-fileupload-1.3.3.jar
+ xmltooling-1.3.2-1.jar
+ rampart-1.7.1.mar
+ petals-cdk-jbidescriptor-2.6.1.jar
+ axiom-dom-1.2.20.jar
+ opensaml-2.5.1-1.jar
+ xmlschema-core-2.2.1.jar
+ woden-core-1.0M10.jar
+ commons-collections-3.1.jar
+ rampart-policy-1.7.1.jar
+ jaxb-impl-2.2.11.jar
+ easywsdl-schema-2.7.0.jar
+ openws-1.4.2-1.jar
+ petals-cdk-clientserver-api-1.2.1.jar
+ axiom-api-1.2.20.jar
+ geronimo-jta_1.1_spec-1.1.jar
+ petals-bc-soap-clientserver-api-1.2.0.jar
+ jetty-http-9.4.11.v20180605.jar
+ axis2-transport-base-1.7.7.jar
+ petals-jbi-descriptor-2.4.0.jar
+ axis2-kernel-1.7.7.jar
+ apache-mime4j-core-0.7.2.jar
+ neethi-3.0.3.jar
+ jaxen-1.1.6.jar
+ petals-basis-api-1.1.0.jar
+ axis2-transport-http-1.7.7.jar
+ joda-time-1.6.2.jar
+ jaxb-core-2.2.11.jar
+ xmlunit-1.6.jar
+ jsr311-api-1.1.1.jar
+ xmlsec-1.5.8.jar
+ commons-io-2.6.jar
+ jetty-util-9.4.11.v20180605.jar
+ javax.mail-1.5.6.jar
+ commons-httpclient-contrib-3.1.jar
+ httpcore-4.4.4.jar
+
+
+
+
+
+
+
+
+
+
+
+
+ org.ow2.petals.binding.soap.listener.outgoing.JBIListener
+ 8084
+
+ true
+ petals
+ services
+ 2
+ 50
+ 4
+ 50
+
+ false
+ 8083
+
+
+
+
+
+
+
+
+ 4
+ 50
+ true
+
+
diff --git a/src/test/resources/artifacts/sa-SOAP-Hello_PortType-consume/META-INF/jbi.xml b/src/test/resources/artifacts/sa-SOAP-Hello_PortType-consume/META-INF/jbi.xml
new file mode 100644
index 0000000..32d540d
--- /dev/null
+++ b/src/test/resources/artifacts/sa-SOAP-Hello_PortType-consume/META-INF/jbi.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+ sa-SOAP-Hello_PortType-consume
+
+
+
+
+
+
+ su-SOAP-Hello_PortType-consume
+
+
+
+
+ su-SOAP-Hello_PortType-consume.zip
+ petals-bc-soap
+
+
+
+
\ No newline at end of file
diff --git a/src/test/resources/artifacts/sa-SOAP-Hello_Service1-provide/META-INF/jbi.xml b/src/test/resources/artifacts/sa-SOAP-Hello_Service1-provide/META-INF/jbi.xml
new file mode 100644
index 0000000..61c8e1c
--- /dev/null
+++ b/src/test/resources/artifacts/sa-SOAP-Hello_Service1-provide/META-INF/jbi.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+ sa-SOAP-Hello_Service1-provide
+
+
+
+
+
+
+ su-SOAP-Hello_Service1-provide
+
+
+
+
+ su-SOAP-Hello_Service1-provide.zip
+ petals-bc-soap
+
+
+
+
\ No newline at end of file
diff --git a/src/test/resources/artifacts/sa-SOAP-Hello_Service2-provide/META-INF/jbi.xml b/src/test/resources/artifacts/sa-SOAP-Hello_Service2-provide/META-INF/jbi.xml
new file mode 100644
index 0000000..53ffa5d
--- /dev/null
+++ b/src/test/resources/artifacts/sa-SOAP-Hello_Service2-provide/META-INF/jbi.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+ sa-SOAP-Hello_Service2-provide
+
+
+
+
+
+
+ su-SOAP-Hello_Service2-provide
+
+
+
+
+ su-SOAP-Hello_Service2-provide.zip
+ petals-bc-soap
+
+
+
+
\ No newline at end of file
diff --git a/src/test/resources/model.xml b/src/test/resources/model.xml
new file mode 100644
index 0000000..1802395
--- /dev/null
+++ b/src/test/resources/model.xml
@@ -0,0 +1,54 @@
+
+
+
+
+
+ file:/artifacts/sa-SOAP-Hello_Service1-provide
+
+
+ file:/artifacts/sa-SOAP-Hello_Service2-provide
+
+
+ file:/artifacts/sa-SOAP-Hello_PortType-consume
+
+
+
+
+ file:/artifacts/petals-bc-soap-5.0.0
+
+
+
+
+
+
+
+
+
+ localhost
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file