Revision 369ea9a2
b/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/dsl/DSL.scala | ||
---|---|---|
478 | 478 |
} |
479 | 479 |
|
480 | 480 |
sealed abstract class DSLTreeNode { |
481 |
abstract def toYaml() : String
|
|
482 |
abstract def children() : List[DSLTreeNode]
|
|
481 |
def toYaml() : String |
|
482 |
def children() : List[DSLTreeNode] |
|
483 | 483 |
} |
484 | 484 |
|
485 | 485 |
case class DSLCreditPolicy ( |
b/logic/src/test/scala/gr/grnet/aquarium/logic/test/AccountsTest.scala | ||
---|---|---|
35 | 35 |
|
36 | 36 |
package gr.grnet.aquarium.logic.test |
37 | 37 |
|
38 |
import gr.grnet.aquarium.model.DB |
|
39 |
import gr.grnet.aquarium.logic.test._ |
|
40 | 38 |
import org.junit.{After, Before, Test} |
41 | 39 |
|
42 |
|
|
43 | 40 |
class AccountsTest extends FixtureLoader { |
44 |
|
|
45 | 41 |
@Before |
46 | 42 |
def before() = { |
47 |
if (!DB.getTransaction.isActive) |
|
48 |
DB.getTransaction.begin |
|
43 |
if (!TestDB.getTransaction.isActive)
|
|
44 |
TestDB.getTransaction.begin
|
|
49 | 45 |
//loadFixture("data.json") |
50 | 46 |
} |
51 | 47 |
|
... | ... | |
55 | 51 |
|
56 | 52 |
@After |
57 | 53 |
def after() = { |
58 |
DB.getTransaction.rollback() |
|
54 |
TestDB.getTransaction.rollback()
|
|
59 | 55 |
} |
60 | 56 |
} |
b/logic/src/test/scala/gr/grnet/aquarium/logic/test/BillingTest.scala | ||
---|---|---|
38 | 38 |
import org.junit._ |
39 | 39 |
import org.junit.Assert._ |
40 | 40 |
import gr.grnet.aquarium.logic.Bills |
41 |
import gr.grnet.aquarium.model.{User, DB}
|
|
41 |
import gr.grnet.aquarium.model.{User} |
|
42 | 42 |
import gr.grnet.aquarium.logic.accounting.policies.DefaultRatePolicy |
43 | 43 |
import gr.grnet.aquarium.logic.accounting.{Agreement, AccountingEvent, AccountingEntryType, AccountingEventType} |
44 | 44 |
import gr.grnet.aquarium.logic.accounting.agreements.AgreementRegistry |
... | ... | |
49 | 49 |
|
50 | 50 |
@Before |
51 | 51 |
def before() = { |
52 |
if (!DB.getTransaction.isActive) |
|
53 |
DB.getTransaction.begin |
|
52 |
if (!TestDB.getTransaction.isActive)
|
|
53 |
TestDB.getTransaction.begin
|
|
54 | 54 |
//loadFixture("data.json") |
55 | 55 |
} |
56 | 56 |
|
... | ... | |
82 | 82 |
u.agreement = TestAgreement.id |
83 | 83 |
u.credits = 100 |
84 | 84 |
|
85 |
DB.persistAndFlush(u) |
|
85 |
TestDB.persistAndFlush(u)
|
|
86 | 86 |
|
87 | 87 |
// Try with a basic event |
88 | 88 |
/*var evt = new AccountingEvent(AccountingEventType.VMTime, |
... | ... | |
99 | 99 |
|
100 | 100 |
@After |
101 | 101 |
def after() = { |
102 |
DB.getTransaction.rollback |
|
102 |
TestDB.getTransaction.rollback
|
|
103 | 103 |
} |
104 | 104 |
} |
b/logic/src/test/scala/gr/grnet/aquarium/logic/test/FixtureLoader.scala | ||
---|---|---|
139 | 139 |
//Create an object instance |
140 | 140 |
val tmpObj = loadClass[AnyRef](model).newInstance() |
141 | 141 |
//Save the object |
142 |
DB.persistAndFlush(tmpObj) |
|
142 |
TestDB.persistAndFlush(tmpObj)
|
|
143 | 143 |
|
144 | 144 |
/* Special treatment for the ID field: we allow JPA to set on persist, but |
145 | 145 |
* we reset it here to what the fixture specifies. This is to bypass |
... | ... | |
147 | 147 |
*/ |
148 | 148 |
updatePK(tmpObj.getClass.getSimpleName, tmpObj.getV("id").asInstanceOf[Long], id) |
149 | 149 |
|
150 |
val obj = DB.find(tmpObj.getClass, id).getOrElse( |
|
150 |
val obj = TestDB.find(tmpObj.getClass, id).getOrElse(
|
|
151 | 151 |
throw new Exception("Cannot find") |
152 | 152 |
).asInstanceOf[AnyRef] |
153 | 153 |
|
... | ... | |
191 | 191 |
} |
192 | 192 |
} |
193 | 193 |
|
194 |
DB.flush() |
|
194 |
TestDB.flush()
|
|
195 | 195 |
} |
196 | 196 |
|
197 | 197 |
private def updatePK(entity: String, oldid: Long, newid: Long) = { |
198 |
val q = DB.createQuery( |
|
198 |
val q = TestDB.createQuery(
|
|
199 | 199 |
"update " + entity + |
200 | 200 |
" set id=:newid where id = :oldid") |
201 | 201 |
q.setParameter("newid", newid) |
... | ... | |
205 | 205 |
|
206 | 206 |
/** Set the referenced object in a many to one relationship*/ |
207 | 207 |
private def setManyToOne(dao: AnyRef, fieldName: String, fieldValue: Double) = { |
208 |
val other = DB.find(dao.getT(fieldName), fieldValue.longValue()).getOrElse( |
|
208 |
val other = TestDB.find(dao.getT(fieldName), fieldValue.longValue()).getOrElse(
|
|
209 | 209 |
throw new Exception("Cannot find related object for " + dao.getClass + |
210 | 210 |
", field: " + fieldName + " value: " + fieldValue) |
211 | 211 |
) |
... | ... | |
246 | 246 |
//Add all values specified |
247 | 247 |
fieldValues.foreach { |
248 | 248 |
v => |
249 |
val other = DB.find(targetType, v.longValue).getOrElse( |
|
249 |
val other = TestDB.find(targetType, v.longValue).getOrElse(
|
|
250 | 250 |
throw new Exception("Cannot find entry of type "+ targetType + |
251 | 251 |
" with id=" + v.longValue) |
252 | 252 |
) |
b/logic/src/test/scala/gr/grnet/aquarium/logic/test/TestDB.scala | ||
---|---|---|
1 |
/* |
|
2 |
* Copyright 2011 GRNET S.A. All rights reserved. |
|
3 |
* |
|
4 |
* Redistribution and use in source and binary forms, with or |
|
5 |
* without modification, are permitted provided that the following |
|
6 |
* conditions are met: |
|
7 |
* |
|
8 |
* 1. Redistributions of source code must retain the above |
|
9 |
* copyright notice, this list of conditions and the following |
|
10 |
* disclaimer. |
|
11 |
* |
|
12 |
* 2. Redistributions in binary form must reproduce the above |
|
13 |
* copyright notice, this list of conditions and the following |
|
14 |
* disclaimer in the documentation and/or other materials |
|
15 |
* provided with the distribution. |
|
16 |
* |
|
17 |
* THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
18 |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
19 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
20 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
22 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
23 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
24 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
25 |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
26 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
27 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
28 |
* POSSIBILITY OF SUCH DAMAGE. |
|
29 |
* |
|
30 |
* The views and conclusions contained in the software and |
|
31 |
* documentation are those of the authors and should not be |
|
32 |
* interpreted as representing official policies, either expressed |
|
33 |
* or implied, of GRNET S.A. |
|
34 |
*/ |
|
35 |
|
|
36 |
package gr.grnet.aquarium.logic.test |
|
37 |
|
|
38 |
import org.scala_libs.jpa.{ThreadLocalEM, LocalEMF} |
|
39 |
|
|
40 |
/** |
|
41 |
* |
|
42 |
* @author Christos KK Loverdos <loverdos@gmail.com>. |
|
43 |
*/ |
|
44 |
object TestDB extends LocalEMF("aquarium-test", true) with ThreadLocalEM {} |
b/model/src/test/scala/gr/grnet/aquarium/model/test/BasicModelTest.scala | ||
---|---|---|
1 | 1 |
package gr.grnet.aquarium.model.test |
2 | 2 |
|
3 | 3 |
import gr.grnet.aquarium.model._ |
4 |
import scala.collection.JavaConversions._ |
|
5 |
import org.scala_libs.jpa.{LocalEMF, ThreadLocalEM} |
|
6 | 4 |
import org.junit._ |
7 | 5 |
import Assert._ |
8 | 6 |
|
... | ... | |
10 | 8 |
|
11 | 9 |
@Before |
12 | 10 |
def before() = { |
13 |
if (!DB.getTransaction.isActive) |
|
14 |
DB.getTransaction.begin |
|
11 |
if (!TestDB.getTransaction.isActive)
|
|
12 |
TestDB.getTransaction.begin
|
|
15 | 13 |
} |
16 | 14 |
|
17 | 15 |
@Test |
... | ... | |
19 | 17 |
|
20 | 18 |
val user = new User |
21 | 19 |
user.name = "foobar" |
22 |
DB.persist(user) |
|
23 |
DB.flush() |
|
20 |
TestDB.persist(user)
|
|
21 |
TestDB.flush()
|
|
24 | 22 |
|
25 |
val a = DB.find(classOf[User], user.id) |
|
23 |
val a = TestDB.find(classOf[User], user.id)
|
|
26 | 24 |
assert(a.exists(u => u.id == user.id)) |
27 | 25 |
} |
28 | 26 |
|
... | ... | |
33 | 31 |
val org1 = new Organization |
34 | 32 |
org1.name = "EDET" |
35 | 33 |
|
36 |
DB.persist(org1) |
|
34 |
TestDB.persist(org1)
|
|
37 | 35 |
|
38 | 36 |
val org2 = new Organization |
39 | 37 |
org2.name = "AUEB" |
40 | 38 |
org2.parent = org1 |
41 | 39 |
|
42 |
DB.persist(org2) |
|
43 |
DB.flush() |
|
40 |
TestDB.persist(org2)
|
|
41 |
TestDB.flush()
|
|
44 | 42 |
|
45 | 43 |
assertTrue(org1.id != org2.id) |
46 | 44 |
|
47 |
val results = DB.find(classOf[Organization], org1.id) |
|
45 |
val results = TestDB.find(classOf[Organization], org1.id)
|
|
48 | 46 |
assert(results.exists(o => o.id == org1.id)) |
49 | 47 |
|
50 | 48 |
//Add to entity with composite key |
51 | 49 |
val srv1 = new ServiceItem |
52 | 50 |
srv1.url = "http://foo.bar/" |
53 |
DB.persist(srv1) |
|
51 |
TestDB.persist(srv1)
|
|
54 | 52 |
|
55 | 53 |
} |
56 | 54 |
|
57 | 55 |
@After |
58 | 56 |
def after() = { |
59 |
DB.getTransaction.rollback() |
|
57 |
TestDB.getTransaction.rollback()
|
|
60 | 58 |
} |
61 | 59 |
} |
b/model/src/test/scala/gr/grnet/aquarium/model/test/TestDB.scala | ||
---|---|---|
1 |
/* |
|
2 |
* Copyright 2011 GRNET S.A. All rights reserved. |
|
3 |
* |
|
4 |
* Redistribution and use in source and binary forms, with or |
|
5 |
* without modification, are permitted provided that the following |
|
6 |
* conditions are met: |
|
7 |
* |
|
8 |
* 1. Redistributions of source code must retain the above |
|
9 |
* copyright notice, this list of conditions and the following |
|
10 |
* disclaimer. |
|
11 |
* |
|
12 |
* 2. Redistributions in binary form must reproduce the above |
|
13 |
* copyright notice, this list of conditions and the following |
|
14 |
* disclaimer in the documentation and/or other materials |
|
15 |
* provided with the distribution. |
|
16 |
* |
|
17 |
* THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
18 |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
19 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
20 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
22 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
23 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
24 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
25 |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
26 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
27 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
28 |
* POSSIBILITY OF SUCH DAMAGE. |
|
29 |
* |
|
30 |
* The views and conclusions contained in the software and |
|
31 |
* documentation are those of the authors and should not be |
|
32 |
* interpreted as representing official policies, either expressed |
|
33 |
* or implied, of GRNET S.A. |
|
34 |
*/ |
|
35 |
|
|
36 |
package gr.grnet.aquarium.model.test |
|
37 |
|
|
38 |
/* |
|
39 |
* Copyright 2011 GRNET S.A. All rights reserved. |
|
40 |
* |
|
41 |
* Redistribution and use in source and binary forms, with or |
|
42 |
* without modification, are permitted provided that the following |
|
43 |
* conditions are met: |
|
44 |
* |
|
45 |
* 1. Redistributions of source code must retain the above |
|
46 |
* copyright notice, this list of conditions and the following |
|
47 |
* disclaimer. |
|
48 |
* |
|
49 |
* 2. Redistributions in binary form must reproduce the above |
|
50 |
* copyright notice, this list of conditions and the following |
|
51 |
* disclaimer in the documentation and/or other materials |
|
52 |
* provided with the distribution. |
|
53 |
* |
|
54 |
* THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
55 |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
56 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
57 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
58 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
59 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
60 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
61 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
62 |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
63 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
64 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
65 |
* POSSIBILITY OF SUCH DAMAGE. |
|
66 |
* |
|
67 |
* The views and conclusions contained in the software and |
|
68 |
* documentation are those of the authors and should not be |
|
69 |
* interpreted as representing official policies, either expressed |
|
70 |
* or implied, of GRNET S.A. |
|
71 |
*/ |
|
72 |
|
|
73 |
import org.scala_libs.jpa.{ThreadLocalEM, LocalEMF} |
|
74 |
|
|
75 |
/** |
|
76 |
* |
|
77 |
* @author Christos KK Loverdos <loverdos@gmail.com>. |
|
78 |
*/ |
|
79 |
object TestDB extends LocalEMF("aquarium-test", true) with ThreadLocalEM {} |
b/shared/src/main/resources/META-INF/persistence.xml | ||
---|---|---|
56 | 56 |
</properties> |
57 | 57 |
</persistence-unit> |
58 | 58 |
|
59 |
<persistence-unit name="aquarium-test" transaction-type="RESOURCE_LOCAL"> |
|
60 |
|
|
61 |
<class>gr.grnet.aquarium.model.Entity</class> |
|
62 |
<class>gr.grnet.aquarium.model.Group</class> |
|
63 |
<class>gr.grnet.aquarium.model.User</class> |
|
64 |
<class>gr.grnet.aquarium.model.Organization</class> |
|
65 |
<class>gr.grnet.aquarium.model.ServiceItem</class> |
|
66 |
<class>gr.grnet.aquarium.model.RuntimeData</class> |
|
67 |
<class>gr.grnet.aquarium.model.Bill</class> |
|
68 |
<class>gr.grnet.aquarium.model.Action</class> |
|
69 |
<class>gr.grnet.aquarium.model.DefaultPermission</class> |
|
70 |
<class>gr.grnet.aquarium.model.Permission</class> |
|
71 |
<class>gr.grnet.aquarium.model.ServiceTemplate</class> |
|
72 |
<class>gr.grnet.aquarium.model.ResourceType</class> |
|
73 |
<class>gr.grnet.aquarium.model.EntityType</class> |
|
74 |
<class>gr.grnet.aquarium.model.Agreement</class> |
|
75 |
<class>gr.grnet.aquarium.model.PriceList</class> |
|
76 |
|
|
77 |
<properties> |
|
78 |
|
|
79 |
<!-- Common configuration --> |
|
80 |
<property name="javax.persistence.jdbc.driver" |
|
81 |
value="org.h2.Driver"/> |
|
82 |
<property name="javax.persistence.jdbc.url" |
|
83 |
value="jdbc:h2:aquarium-test"/> |
|
84 |
<property name="javax.persistence.jdbc.password" value=""/> |
|
85 |
<property name="javax.persistence.jdbc.user" value=""/> |
|
86 |
|
|
87 |
<!-- EclipseLink configuration --> |
|
88 |
<property name="eclipselink.target-database" |
|
89 |
value="org.eclipse.persistence.platform.database.H2Platform"/> |
|
90 |
<property name="eclipselink.logging.level" value="FINE"/> |
|
91 |
<property name="eclipselink.logging.timestamp" value="false"/> |
|
92 |
<property name="eclipselink.logging.session" value="false"/> |
|
93 |
<property name="eclipselink.logging.thread" value="false"/> |
|
94 |
<property name="eclipselink.logging.level.sql" value="FINEST"/> |
|
95 |
<property name="eclipselink.ddl-generation" value="create-tables"/> |
|
96 |
<property name="eclipselink.ddl-generation.output-mode" value="database"/> |
|
97 |
|
|
98 |
<!-- Hibernate configuration --> |
|
99 |
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> |
|
100 |
<property name="hibernate.hbm2ddl.auto" value="update"/> |
|
101 |
<property name="hibernate.show_sql" value="true"/> |
|
102 |
|
|
103 |
<!-- OpenJPA configuration --> |
|
104 |
<property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.H2Dictionary"/> |
|
105 |
<property name="openjpa.Log" value="DefaultLevel=TRACE, SQL=TRACE"/> |
|
106 |
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> |
|
107 |
|
|
108 |
</properties> |
|
109 |
</persistence-unit> |
|
59 | 110 |
</persistence> |
Also available in: Unified diff