Skip to content

Instantly share code, notes, and snippets.

Agnaldo de Oliveira agnaldo4j

View GitHub Profile
@agnaldo4j
agnaldo4j / HttpBoot.scala
Created Jul 18, 2013
Jetty embarcado com Scala em 34 linhas.
View HttpBoot.scala
import org.eclipse.jetty.server.{Server, Handler}
import org.eclipse.jetty.server.handler.{HandlerList, ResourceHandler}
import org.eclipse.jetty.servlet.{ServletHolder, ServletContextHandler}
import org.eclipse.jetty.webapp.WebAppContext
object HttpBoot {
def main(args: Array[String]) {
val context = buildContext()
val handlers = buildHandlerList(context)
@agnaldo4j
agnaldo4j / UserPersistence.scala
Created Jul 16, 2013
Exemplo simples de GRUD com Scala, Salat, Casbah e MongoDB.
View UserPersistence.scala
package com.codesimples.persistence.target
import scala.collection.JavaConversions._
import com.codesimples.model.target.User
import com.novus.salat._
import com.novus.salat.global._
import com.mongodb.casbah.Imports._
@agnaldo4j
agnaldo4j / HibernateSessionFactory.scala
Created Jul 6, 2013
Exemplo de criação de SessionFactory com Scala e Hibernate 4.2.
View HibernateSessionFactory.scala
package
import org.hibernate.service.{ServiceRegistryBuilder, ServiceRegistry}
import org.hibernate.cfg.Configuration
import org.hibernate.{Session, SessionFactory}
import scala.collection.JavaConversions._
object HibernateSessionFactory {
def buildSessionFactory(dbDriver:String = "org.postgresql.Driver",
@agnaldo4j
agnaldo4j / Boot.scala
Created Jan 21, 2013
Jetty embarcado com scala e serviço de rest. outros exemplos de Jetty embarcado http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty#Setting_a_Web_Application_Context
View Boot.scala
package com.softsimples.social
import filter.SecurityFilter
import org.eclipse.jetty.server.{Server, Handler}
import org.eclipse.jetty.server.handler.{HandlerList, ResourceHandler}
import org.eclipse.jetty.servlet.{ServletHolder, ServletContextHandler}
import servlet.{WebSocketHandlerServlet, SocialCollectorHandler}
import com.sun.jersey.spi.container.servlet.ServletContainer
object Boot {
@agnaldo4j
agnaldo4j / clone_with_push_settings.sh
Created Dec 25, 2012
Exemplo para clonar repositorio com permissoes de push. Primeiro passo para auto deploy via hooks
View clone_with_push_settings.sh
git clone --bare -l [repository]
@agnaldo4j
agnaldo4j / AutotestConfig.st
Created Dec 24, 2012
Instalacao de ferramenta de autotest.
View AutotestConfig.st
Gofer it
squeaksource: 'MetacelloRepository';
package: 'ConfigurationOfAutotest';
load.
ConfigurationOfAutotest project latestVersion load: #OB.
@agnaldo4j
agnaldo4j / Boot.scala
Created Oct 31, 2015
Implementação de servidor jetty embarcado com Java WebSocket API e Scalatra. :-)
View Boot.scala
def main(args: Array[String]) {
val port = restApiConfig.getInt("port")
println(restApiConfig.getString("resourceBase"))
val server = new Server(port)
val context = new WebAppContext()
context setContextPath "/"
context.setResourceBase(restApiConfig.getString("resourceBase"))
context.setInitParameter(ScalatraListener.LifeCycleKey, "com.opportunity.simple.restapi.ScalatraBootstrap")
context.addEventListener(new ScalatraListener)
@agnaldo4j
agnaldo4j / UserAPI.scala
Created Oct 25, 2015
Separação tecnologia da implementação da regra do negócio. Com isso mudar de tecnologia de persistência e framework web fica bem mais fácil
View UserAPI.scala
post("/") {
contentType = "application/json"
authenticated { jsonObject =>
val entityManager = entityManagerFactory.createEntityManager()
val userRepository = new UserRepository(entityManager)
val userPersistenceAdapter = new NewUserPersistenceAdapterJPA(userRepository)
val usecase = new NewUserUsecase(userPersistenceAdapter)
val savedUser = usecase.save( User( jsonObject ) )
@agnaldo4j
agnaldo4j / UserSpec.scala
Last active Oct 31, 2015
Estrutura testes de integração para API. Objetivo esconder ferramentaria e simplificar os testes
View UserSpec.scala
package com.opportunity.simple.restapi.user
import com.opportunity.simple.restapi.basic.BasicBehaviour
class UserSpec extends BasicBehaviour {
"The user endpoint" should {
args(sequential=true)
"Create new user" ! userEndpointForTest().executeTestCreateNewUser()
"Try create a user with same email" ! userEndpointForTest().executeTestTryCreateAUserWithSameEmail()
You can’t perform that action at this time.