Skip to content

Commit

Permalink
#135: grails tests passing again
Browse files Browse the repository at this point in the history
  • Loading branch information
ypujante committed Mar 17, 2013
1 parent fc435c3 commit d943eff
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@ app.grails.version=2.2.1
app.name=console
app.servlet.version=2.5
app.version=dev
plugins.external-domain-classes=1.0.0
plugins.hibernate=2.2.1
plugins.jquery=1.6.1.1
plugins.shiro=1.1-SNAPSHOT
plugins.tomcat=2.2.1
19 changes: 5 additions & 14 deletions console/org.linkedin.glu.console-webapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {

compile spec.external.groovy

runtime spec.external.hsqldb
runtime spec.external.slf4jLog4j
runtime spec.external.log4j
}
Expand All @@ -55,13 +56,13 @@ def facets = """
</component>
"""

ideaModule {
whenConfigured { module ->
idea.module.iml {
whenMerged { module ->
['grails-app/utils', 'grails-app/controllers', 'grails-app/domain', 'grails-app/services', 'grails-app/realms', 'grails-app/taglib', 'grails-app/conf'].each {
module.sourceFolders << new org.gradle.plugins.idea.model.Path("file://\$MODULE_DIR\$/${it}")
module.sourceFolders << new org.gradle.plugins.ide.idea.model.Path("file://\$MODULE_DIR\$/${it}")
}
['test/unit', 'test/integration'].each {
module.testSourceFolders << new org.gradle.plugins.idea.model.Path("file://\$MODULE_DIR\$/${it}")
module.testSourceFolders << new org.gradle.plugins.ide.idea.model.Path("file://\$MODULE_DIR\$/${it}")
}
}

Expand All @@ -78,18 +79,12 @@ project.clean << {
fileTree(dir: 'lib').each { it.delete() }
}

workaroundDir = new File(buildDir, "distributions/lib")

task lib(dependsOn: jar) << {
fileTree(dir: 'lib').each { it.delete() }
copy {
from configurations.runtime
into 'lib'
}
// workaround against /org/apache/tools/ant/antlib.xml:37: Problem: failed to create
// task or type componentdef
ant.move(file: file('lib/ant-1.8.1.jar'), todir: workaroundDir)
ant.move(file: file('lib/ant-launcher-1.8.1.jar'), todir: workaroundDir)

// issue is that we end up with duplicate files (with slightly different names!) because grails
// add them!
Expand Down Expand Up @@ -136,10 +131,6 @@ task war(dependsOn: lib) << {
ant.exec(dir: '.', executable: "grails") {
arg(line: "-Dgrails.project.war.file=${warFile} -Dbuild.version=${project.version} war")
}

ant.war(destfile: warFile, update: true) {
lib(dir: workaroundDir, includes: '*.jar')
}
}

task([type: SingleArtifactTask, dependsOn: 'war'], 'package-war') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2010-2010 LinkedIn, Inc
* Portions Copyright (c) 2011 Yan Pujante
* Portions Copyright (c) 2011-2013 Yan Pujante
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand Down Expand Up @@ -99,7 +99,7 @@ class BootStrap {
].each { username, roles ->
User.withTransaction { status ->
User user = new User(username: username)
user.setRoles(roles)
user.updateRoles(roles)
if(!user.save())
throw new RuntimeException("could not create ${username} user")

Expand All @@ -121,7 +121,7 @@ class BootStrap {

User.withTransaction { status ->
def userInstance = new User(username: "admin")
userInstance.setRoles([RoleName.USER, RoleName.RELEASE, RoleName.ADMIN])
userInstance.updateRoles([RoleName.USER, RoleName.RELEASE, RoleName.ADMIN])
if(!userInstance.save())
throw new RuntimeException("could not create admin user")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,53 +27,62 @@ grails.project.source.level = 1.6
// run: [maxMemory:1024, minMemory:64, debug:false, maxPerm:256]
//]

//def externalDomainClassesInPlacePluginPath = new File("../external-domain-classes")
//grails.plugin.location.'external-domain-classes' =
// externalDomainClassesInPlacePluginPath.canonicalPath

grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// specify dependency exclusions here; for example, uncomment this to disable ehcache:
// excludes 'ehcache'
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility

repositories {
inherits true // Whether to inherit repository definitions from plugins

grailsPlugins()
grailsHome()
grailsCentral()

mavenLocal()
mavenCentral()

// uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
//mavenRepo "http://snapshots.repository.codehaus.org"
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}

dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.

// runtime 'mysql:mysql-connector-java:5.1.22'
}

plugins {
runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.8.3"
runtime ":resources:1.1.6"

// Uncomment these (or add new ones) to enable additional resources capabilities
//runtime ":zipped-resources:1.0"
//runtime ":cached-resources:1.0"
//runtime ":yui-minify-resources:0.1.5"

build ":tomcat:$grailsVersion"

runtime ":database-migration:1.3.2"

compile ':cache:1.0.1'
}
// inherit Grails' default dependencies
inherits("global") {
// specify dependency exclusions here; for example, uncomment this to disable ehcache:
// excludes 'ehcache'
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility

repositories {
inherits true // Whether to inherit repository definitions from plugins

grailsPlugins()
grailsHome()
grailsCentral()

mavenLocal()
mavenCentral()

mavenRepo new File("../../local-maven-repo").canonicalFile.toURI().toString()

// uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
//mavenRepo "http://snapshots.repository.codehaus.org"
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}

dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.

// runtime 'mysql:mysql-connector-java:5.1.22'
}

plugins {

runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.8.3"
runtime ":resources:1.1.6"
runtime ":external-domain-classes:1.0.0"

// Uncomment these (or add new ones) to enable additional resources capabilities
//runtime ":zipped-resources:1.0"
//runtime ":cached-resources:1.0"
//runtime ":yui-minify-resources:0.1.5"

build ":tomcat:$grailsVersion"

runtime ":database-migration:1.3.2"

compile ':cache:1.0.1'
compile ":shiro:1.1.4"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2010-2010 LinkedIn, Inc
* Portions Copyright (c) 2011 Yan Pujante
* Portions Copyright (c) 2011-2013 Yan Pujante
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand Down Expand Up @@ -112,7 +112,7 @@ class UserController extends ControllerBase
return
}
}
userInstance.setRoles(role)
userInstance.updateRoles(role)
if(!userInstance.hasErrors() && userInstance.save([flush: true]))
{
flash.success = "User ${userInstance.username} updated"
Expand Down Expand Up @@ -156,7 +156,7 @@ class UserController extends ControllerBase
return
}

userInstance.setRoles(RoleName.USER)
userInstance.updateRoles(RoleName.USER)

DbUserCredentials ucr = new DbUserCredentials(username: params.username,
password: params.password)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2010-2010 LinkedIn, Inc
* Portions Copyright (c) 2013 Yan Pujante
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand Down Expand Up @@ -94,7 +95,7 @@ class User
* Set the roles to be exactly what is provided: conceptually remove all the roles and add only
* the new ones.
*/
def setRoles(newRoles)
def updateRoles(newRoles)
{
newRoles = newRoles?.collect { RoleName.valueOf(it.toString()) } ?: []

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2010-2010 LinkedIn, Inc
* Portions Copyright (c) 2013 Yan Pujante
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand Down Expand Up @@ -182,7 +183,7 @@ class ShiroLdapRealm
if(!User.findByUsername(username))
{
User user = new User(username: username)
user.setRoles([RoleName.USER])
user.updateRoles([RoleName.USER])
if(!user.save())
{
def msg = "Could not create user ${username} => ${user.errors.toString()}".toString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2010-2010 LinkedIn, Inc
* Portions Copyright (c) 2013 Yan Pujante
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand Down Expand Up @@ -75,7 +76,7 @@ class UserIntegrationTests extends GroovyTestCase
assertFalseUsingGroovyTruth(user.impliesRole(RoleName.RESTRICTED))

// we test the setRoles method
user.setRoles([RoleName.USER, RoleName.ADMIN, RoleName.RELEASE])
user.updateRoles([RoleName.USER, RoleName.ADMIN, RoleName.RELEASE])
assertNotNull(user.save())

assertEquals('user1', user.username)
Expand All @@ -88,7 +89,7 @@ class UserIntegrationTests extends GroovyTestCase
assertFalseUsingGroovyTruth(user.impliesRole(RoleName.RESTRICTED))

// we test the setRoles method
user.setRoles([RoleName.USER, RoleName.RESTRICTED])
user.updateRoles([RoleName.USER, RoleName.RESTRICTED])
assertNotNull(user.save())

assertEquals('user1', user.username)
Expand Down
4 changes: 3 additions & 1 deletion docs/manual/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import org.apache.tools.ant.filters.ReplaceTokens

def sphinxDir = new File(buildDir, "sphinx")

def htmlDocDir = new File(sphinxDir, "build/html")
ext {
htmlDocDir = new File(sphinxDir, "build/html")
}

def syncDir = new File(userConfig.doc.sync.dir ?: "${rootDir}/../linkedin.github.com/glu/docs/latest/html").canonicalFile

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 Yan Pujante
* Copyright (c) 2011-2013 Yan Pujante
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand All @@ -17,23 +17,31 @@
package org.linkedin.glu.orchestration.engine.delta

import org.linkedin.util.annotations.Initializable
import org.slf4j.Logger
import org.slf4j.LoggerFactory

/**
* @author yan@pongasoft.com */
public class CustomDeltaDefinitionStorageImpl implements CustomDeltaDefinitionStorage
{
public static final String MODULE = CustomDeltaDefinitionStorageImpl.class.getName();
public static final Logger log = LoggerFactory.getLogger(MODULE);

@Initializable(required = true)
CustomDeltaDefinitionSerializer customDeltaDefinitionSerializer

@Override
boolean save(UserCustomDeltaDefinition definition)
{
definition = autoWire(definition)
definition.save([flush: true])
}

@Override
boolean delete(UserCustomDeltaDefinition definition)
{
definition = autoWire(definition)

// TODO MED YP: somehow definition.delete([flush: true]) is not working and giving the following
// messsage: org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are
// not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into
Expand All @@ -46,7 +54,7 @@ public class CustomDeltaDefinitionStorageImpl implements CustomDeltaDefinitionSt
@Override
UserCustomDeltaDefinition findByUsernameAndName(String username, String name)
{
UserCustomDeltaDefinition.findByUsernameAndName(username, name)
autoWire(UserCustomDeltaDefinition.findByUsernameAndName(username, name))
}

@Override
Expand All @@ -60,7 +68,7 @@ public class CustomDeltaDefinitionStorageImpl implements CustomDeltaDefinitionSt

if(includeDetails)
{
list = UserCustomDeltaDefinition.findAllByUsername(username, params)
list = autoWire(UserCustomDeltaDefinition.findAllByUsername(username, params))
}
else
{
Expand All @@ -84,7 +92,7 @@ public class CustomDeltaDefinitionStorageImpl implements CustomDeltaDefinitionSt

if(includeDetails)
{
list = UserCustomDeltaDefinition.findAllByShareable(true, params)
list = autoWire(UserCustomDeltaDefinition.findAllByShareable(true, params))
}
else
{
Expand All @@ -97,6 +105,24 @@ public class CustomDeltaDefinitionStorageImpl implements CustomDeltaDefinitionSt
]
}

/**
* This method is a workaround for 2.x which breaks auto-wiring
*/
protected UserCustomDeltaDefinition autoWire(UserCustomDeltaDefinition ucdd)
{
ucdd.customDeltaDefinitionSerializer = customDeltaDefinitionSerializer
return ucdd
}

/**
* This method is a workaround for 2.x which breaks auto-wiring
*/
protected Collection<UserCustomDeltaDefinition> autoWire(Collection<UserCustomDeltaDefinition> list)
{
list.each { autoWire(it) }
return list
}

protected def processParams(params)
{
if(params.offset == null)
Expand Down
Loading

0 comments on commit d943eff

Please sign in to comment.