}
sealed abstract class DSLTreeNode {
- abstract def toYaml() : String
- abstract def children() : List[DSLTreeNode]
+ def toYaml() : String
+ def children() : List[DSLTreeNode]
}
case class DSLCreditPolicy (
package gr.grnet.aquarium.logic.test
-import gr.grnet.aquarium.model.DB
-import gr.grnet.aquarium.logic.test._
import org.junit.{After, Before, Test}
-
class AccountsTest extends FixtureLoader {
-
@Before
def before() = {
- if (!DB.getTransaction.isActive)
- DB.getTransaction.begin
+ if (!TestDB.getTransaction.isActive)
+ TestDB.getTransaction.begin
//loadFixture("data.json")
}
@After
def after() = {
- DB.getTransaction.rollback()
+ TestDB.getTransaction.rollback()
}
}
\ No newline at end of file
import org.junit._
import org.junit.Assert._
import gr.grnet.aquarium.logic.Bills
-import gr.grnet.aquarium.model.{User, DB}
+import gr.grnet.aquarium.model.{User}
import gr.grnet.aquarium.logic.accounting.policies.DefaultRatePolicy
import gr.grnet.aquarium.logic.accounting.{Agreement, AccountingEvent, AccountingEntryType, AccountingEventType}
import gr.grnet.aquarium.logic.accounting.agreements.AgreementRegistry
@Before
def before() = {
- if (!DB.getTransaction.isActive)
- DB.getTransaction.begin
+ if (!TestDB.getTransaction.isActive)
+ TestDB.getTransaction.begin
//loadFixture("data.json")
}
u.agreement = TestAgreement.id
u.credits = 100
- DB.persistAndFlush(u)
+ TestDB.persistAndFlush(u)
// Try with a basic event
/*var evt = new AccountingEvent(AccountingEventType.VMTime,
@After
def after() = {
- DB.getTransaction.rollback
+ TestDB.getTransaction.rollback
}
}
\ No newline at end of file
//Create an object instance
val tmpObj = loadClass[AnyRef](model).newInstance()
//Save the object
- DB.persistAndFlush(tmpObj)
+ TestDB.persistAndFlush(tmpObj)
/* Special treatment for the ID field: we allow JPA to set on persist, but
* we reset it here to what the fixture specifies. This is to bypass
*/
updatePK(tmpObj.getClass.getSimpleName, tmpObj.getV("id").asInstanceOf[Long], id)
- val obj = DB.find(tmpObj.getClass, id).getOrElse(
+ val obj = TestDB.find(tmpObj.getClass, id).getOrElse(
throw new Exception("Cannot find")
).asInstanceOf[AnyRef]
}
}
- DB.flush()
+ TestDB.flush()
}
private def updatePK(entity: String, oldid: Long, newid: Long) = {
- val q = DB.createQuery(
+ val q = TestDB.createQuery(
"update " + entity +
" set id=:newid where id = :oldid")
q.setParameter("newid", newid)
/** Set the referenced object in a many to one relationship*/
private def setManyToOne(dao: AnyRef, fieldName: String, fieldValue: Double) = {
- val other = DB.find(dao.getT(fieldName), fieldValue.longValue()).getOrElse(
+ val other = TestDB.find(dao.getT(fieldName), fieldValue.longValue()).getOrElse(
throw new Exception("Cannot find related object for " + dao.getClass +
", field: " + fieldName + " value: " + fieldValue)
)
//Add all values specified
fieldValues.foreach {
v =>
- val other = DB.find(targetType, v.longValue).getOrElse(
+ val other = TestDB.find(targetType, v.longValue).getOrElse(
throw new Exception("Cannot find entry of type "+ targetType +
" with id=" + v.longValue)
)
--- /dev/null
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.logic.test
+
+import org.scala_libs.jpa.{ThreadLocalEM, LocalEMF}
+
+/**
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+object TestDB extends LocalEMF("aquarium-test", true) with ThreadLocalEM {}
\ No newline at end of file
package gr.grnet.aquarium.model.test
import gr.grnet.aquarium.model._
-import scala.collection.JavaConversions._
-import org.scala_libs.jpa.{LocalEMF, ThreadLocalEM}
import org.junit._
import Assert._
@Before
def before() = {
- if (!DB.getTransaction.isActive)
- DB.getTransaction.begin
+ if (!TestDB.getTransaction.isActive)
+ TestDB.getTransaction.begin
}
@Test
val user = new User
user.name = "foobar"
- DB.persist(user)
- DB.flush()
+ TestDB.persist(user)
+ TestDB.flush()
- val a = DB.find(classOf[User], user.id)
+ val a = TestDB.find(classOf[User], user.id)
assert(a.exists(u => u.id == user.id))
}
val org1 = new Organization
org1.name = "EDET"
- DB.persist(org1)
+ TestDB.persist(org1)
val org2 = new Organization
org2.name = "AUEB"
org2.parent = org1
- DB.persist(org2)
- DB.flush()
+ TestDB.persist(org2)
+ TestDB.flush()
assertTrue(org1.id != org2.id)
- val results = DB.find(classOf[Organization], org1.id)
+ val results = TestDB.find(classOf[Organization], org1.id)
assert(results.exists(o => o.id == org1.id))
//Add to entity with composite key
val srv1 = new ServiceItem
srv1.url = "http://foo.bar/"
- DB.persist(srv1)
+ TestDB.persist(srv1)
}
@After
def after() = {
- DB.getTransaction.rollback()
+ TestDB.getTransaction.rollback()
}
}
--- /dev/null
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.model.test
+
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+import org.scala_libs.jpa.{ThreadLocalEM, LocalEMF}
+
+/**
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+object TestDB extends LocalEMF("aquarium-test", true) with ThreadLocalEM {}
\ No newline at end of file
</properties>
</persistence-unit>
+ <persistence-unit name="aquarium-test" transaction-type="RESOURCE_LOCAL">
+
+ <class>gr.grnet.aquarium.model.Entity</class>
+ <class>gr.grnet.aquarium.model.Group</class>
+ <class>gr.grnet.aquarium.model.User</class>
+ <class>gr.grnet.aquarium.model.Organization</class>
+ <class>gr.grnet.aquarium.model.ServiceItem</class>
+ <class>gr.grnet.aquarium.model.RuntimeData</class>
+ <class>gr.grnet.aquarium.model.Bill</class>
+ <class>gr.grnet.aquarium.model.Action</class>
+ <class>gr.grnet.aquarium.model.DefaultPermission</class>
+ <class>gr.grnet.aquarium.model.Permission</class>
+ <class>gr.grnet.aquarium.model.ServiceTemplate</class>
+ <class>gr.grnet.aquarium.model.ResourceType</class>
+ <class>gr.grnet.aquarium.model.EntityType</class>
+ <class>gr.grnet.aquarium.model.Agreement</class>
+ <class>gr.grnet.aquarium.model.PriceList</class>
+
+ <properties>
+
+ <!-- Common configuration -->
+ <property name="javax.persistence.jdbc.driver"
+ value="org.h2.Driver"/>
+ <property name="javax.persistence.jdbc.url"
+ value="jdbc:h2:aquarium-test"/>
+ <property name="javax.persistence.jdbc.password" value=""/>
+ <property name="javax.persistence.jdbc.user" value=""/>
+
+ <!-- EclipseLink configuration -->
+ <property name="eclipselink.target-database"
+ value="org.eclipse.persistence.platform.database.H2Platform"/>
+ <property name="eclipselink.logging.level" value="FINE"/>
+ <property name="eclipselink.logging.timestamp" value="false"/>
+ <property name="eclipselink.logging.session" value="false"/>
+ <property name="eclipselink.logging.thread" value="false"/>
+ <property name="eclipselink.logging.level.sql" value="FINEST"/>
+ <property name="eclipselink.ddl-generation" value="create-tables"/>
+ <property name="eclipselink.ddl-generation.output-mode" value="database"/>
+
+ <!-- Hibernate configuration -->
+ <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
+ <property name="hibernate.hbm2ddl.auto" value="update"/>
+ <property name="hibernate.show_sql" value="true"/>
+
+ <!-- OpenJPA configuration -->
+ <property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.H2Dictionary"/>
+ <property name="openjpa.Log" value="DefaultLevel=TRACE, SQL=TRACE"/>
+ <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
+
+ </properties>
+ </persistence-unit>
</persistence>
\ No newline at end of file