コード例 #1
0
func TestPutDate(t *testing.T) {
	resp := server_mock.NewHttpResponseWriterMock()
	db := booking_database_sqlite.New("/tmp/booking_test.db", false)
	userService := booking_user_service.New(booking_user_storage.New(db))
	dateStorage := booking_date_storage.New(db)
	err := dateStorage.Truncate()
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	handler := createHandler(db, userService)
	req, err := createRequest("/date", userService)
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	now, err := time.Parse(time.RFC3339, fmt.Sprintf("%d-01-02T15:04:05+01:00", time.Now().Year()+1))
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	start := now.Add(1 * time.Hour).Format("2006-01-02T15:04:05Z")
	end := now.Add(2 * time.Hour).Format("2006-01-02T15:04:05Z")
	req.Body = ioutil.NopCloser(bytes.NewBufferString(`{"start":"` + start + `","end":"` + end + `","user_ids":[1]}`))
	req.Method = "PUT"
	handler.ServeHTTP(resp, req)
	if err := AssertThat(resp.Status(), Is(200)); err != nil {
		t.Fatal(err)
	}
}
コード例 #2
0
func createHandler(database booking_database.Database, userService booking_user_service.Service) http.Handler {
	tokengenerator := booking_tokengenerator.New()
	modelService := booking_model_service.New(booking_model_storage.New(database), tokengenerator)
	dateStorage := booking_date_storage.New(database)
	authenticationService := booking_authentication_service.New(userService, modelService)
	shootingStorage := booking_shooting_storage.New(database)
	eventBus := eventbus.New()
	shootingValidator := booking_shooting_validator.New()
	shootingService := booking_shooting_service.New(shootingStorage, shootingValidator.ValidateShooting)
	authorizationService := booking_authorization_service.New()
	authenticationConverter := booking_authentication_converter.New()
	shootingBookService := booking_shooting_service_book.New(shootingStorage, eventBus, dateStorage)
	shootingRefuseService := booking_shooting_service_refuse.New(shootingStorage, eventBus)
	configService := booking_config_service.New(booking_config_storage.New(database))
	protocolBuilderProvider := booking_protocol_builder.New(authenticationConverter.HttpRequestToAuthentication, userService.FindUserByAuthentication, modelService.FindModelByAuthentication)
	protocoller := booking_protocol_protocoller.New(protocolBuilderProvider.NewBuilder, eventBus.Publish)
	dateUserService := booking_date_user_service.New(booking_date_user_storage.New(database))
	shootingUserService := booking_shooting_user_service.New(booking_shooting_user_storage.New(database))
	dateService := booking_date_service.New(dateStorage, shootingService.Get, shootingUserService.GetUserIdsForShooting, dateUserService.GetUserIdsForDate)
	calendarWriter := booking_calendar_writer.New(dateService.List, shootingService.GetShootingByDateId, configService.GetStringDefault, userService.ListUserOfDate)
	modelToVCard := booking_model_vcard.New()

	handlerConfiguration := New("/tmp", dateService, modelService, shootingService, userService, authenticationService, authorizationService, authenticationConverter, shootingBookService, shootingRefuseService, configService, calendarWriter, protocoller, dateUserService, shootingUserService, modelToVCard)
	return handlerConfiguration.GetHandler()
}
コード例 #3
0
func createHandler(db booking_database.Database, userService booking_user_service.Service) http.Handler {
	tokengenerator := booking_tokengenerator.New()
	modelService := booking_model_service.New(booking_model_storage.New(db), tokengenerator)
	dateService := booking_date_service.New(booking_date_storage.New(db))
	authenticationService := booking_authentication_service.New(userService, modelService)
	shootingService := booking_shooting_service.New(booking_shooting_storage.New(db), eventbus.New())
	authorizationService := booking_authorization_service.New()
	authenticationConverter := booking_authentication_converter.New()
	handlerConfiguration := New("/tmp", dateService, modelService, shootingService, userService, authenticationService, authorizationService, authenticationConverter)
	return handlerConfiguration.GetHandler()
}
コード例 #4
0
ファイル: booking_server.go プロジェクト: bborbe/booking
func createServer() (*http.Server, error) {
	port := model.Port(*portPtr)
	documentRoot := *documentRootPtr
	databaseHost := *databaseHostPtr
	databaseName := *databaseNamePtr
	databaseUser := *databaseUserPtr
	databasePassword := *databasePasswordPtr
	databaseLogging := *databaseLoggingPtr
	migrationPath := *databaseMigrationPathPtr
	database := booking_database_postgres.New(databaseHost, databaseName, databaseUser, databasePassword, databaseLogging, migrationPath)
	dateStorage := booking_date_storage.New(database)
	tokengenerator := booking_tokengenerator.New()
	modelService := booking_model_service.New(booking_model_storage.New(database), tokengenerator)
	shootingStorage := booking_shooting_storage.New(database)
	shootingValidator := booking_shooting_validator.New()
	shootingService := booking_shooting_service.New(shootingStorage, shootingValidator.ValidateShooting)
	configService := booking_config_service.New(booking_config_storage.New(database))
	userService := booking_user_service.New(booking_user_storage.New(database))
	authenticationService := booking_authentication_service.New(userService, modelService)
	authorizationService := booking_authorization_service.New()
	authenticationConverter := booking_authentication_converter.New()
	eventBus := eventbus.New()
	shootingBookService := booking_shooting_service_book.New(shootingStorage, eventBus, dateStorage)
	shootingRefuseService := booking_shooting_service_refuse.New(shootingStorage, eventBus)
	mailService := booking_mail_service.New()
	mailConfig := booking_mail_config.New(configService.GetString, configService.GetInt)
	dateFormatter := booking_date_formatter.New()
	protocolBuilderProvider := booking_protocol_builder.New(authenticationConverter.HttpRequestToAuthentication, userService.FindUserByAuthentication, modelService.FindModelByAuthentication)
	protocolStorage := booking_protocol_storage.New(database)
	protocolService := booking_protocol_service.New(protocolStorage)
	protocolEventHandler := booking_protocol_event_handler.New(protocolService.Create)
	protocoller := booking_protocol_protocoller.New(protocolBuilderProvider.NewBuilder, eventBus.Publish)
	dateUserService := booking_date_user_service.New(booking_date_user_storage.New(database))
	shootingUserService := booking_shooting_user_service.New(booking_shooting_user_storage.New(database))
	dateService := booking_date_service.New(dateStorage, shootingService.Get, shootingUserService.GetUserIdsForShooting, dateUserService.GetUserIdsForDate)
	bookedEventHander := booking_booked_event_handler.New(mailService.SendMail, mailConfig, userService.List, modelService.Get, dateService.Get, dateFormatter.FormatDate, protocoller.AddProtocolSystem)
	calendarWriter := booking_calendar_writer.New(dateService.List, shootingService.GetShootingByDateId, configService.GetStringDefault, userService.ListUserOfDate)
	modelToVCard := booking_model_vcard.New()
	// register event handler
	if err := eventBus.RegisterHandler(bookedEventHander.HandleBookedEvent); err != nil {
		return nil, err
	}
	if err := eventBus.RegisterHandler(protocolEventHandler.HandleProtocolEvent); err != nil {
		return nil, err
	}
	handlerConfiguration := booking_handler_configuration.New(documentRoot, dateService, modelService, shootingService, userService, authenticationService, authorizationService, authenticationConverter, shootingBookService, shootingRefuseService, configService, calendarWriter, protocoller, dateUserService, shootingUserService, modelToVCard)
	handler := handlerConfiguration.GetHandler()
	if glog.V(4) {
		handler = debug_handler.New(handler)
	}
	glog.V(2).Infof("create http server on %s", port.Address())
	return &http.Server{Addr: port.Address(), Handler: handler}, nil
}
コード例 #5
0
ファイル: booking_server.go プロジェクト: x4rMa/booking
func createServer(address string, documentRoot string, databaseName string, databaseUser string, databasePassword string, databaseLogging bool) *http.Server {
	logger.SetLevelThreshold(log.LogStringToLevel(*logLevelPtr))
	logger.Debugf("set log level to %s", *logLevelPtr)
	db := booking_database_postgres.New(databaseName, databaseUser, databasePassword, databaseLogging)
	dateService := booking_date_service.New(booking_date_storage.New(db))
	tokengenerator := booking_tokengenerator.New()
	modelService := booking_model_service.New(booking_model_storage.New(db), tokengenerator)
	eventbus := eventbus.New()
	shootingService := booking_shooting_service.New(booking_shooting_storage.New(db), eventbus)
	userService := booking_user_service.New(booking_user_storage.New(db))
	authenticationService := booking_authentication_service.New(userService, modelService)
	authorizationService := booking_authorization_service.New()
	authenticationConverter := booking_authentication_converter.New()
	handlerConfiguration := booking_handler_configuration.New(documentRoot, dateService, modelService, shootingService, userService, authenticationService, authorizationService, authenticationConverter)
	return &http.Server{Addr: address, Handler: handlerConfiguration.GetHandler()}
}
コード例 #6
0
func TestBookableDatesForShooting(t *testing.T) {
	var err error
	var list []booking_date.Date
	database := createDatabase()
	dateStorage := booking_date_storage.New(database)
	if err = dateStorage.Truncate(); err != nil {
		t.Fatal(err)
	}
	now, err := time.Parse(time.RFC3339, fmt.Sprintf("%d-01-02T15:04:05+01:00", time.Now().Year()+1))
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}

	// create date
	d := &booking_date.Date{
		Start: now.Add(3 * time.Hour),
		End:   now.Add(4 * time.Hour),
	}
	_, err = dateStorage.Create(d)
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}

	// eq
	{
		d := New(dateStorage, createGetShooting(&booking_shooting.Shooting{Duration: null.NewInt(int64(time.Hour), true)}, nil), createGetUserIdsForShooting(make([]int64, 0), nil), createGetUserIdsForDate(make([]int64, 0), nil))
		list, err = d.BookableDatesForShooting(1337)
		if err := AssertThat(err, NilValue()); err != nil {
			t.Fatal(err)
		}
		if err := AssertThat(list, NotNilValue()); err != nil {
			t.Fatal(err)
		}
		if err := AssertThat(len(list), Is(1)); err != nil {
			t.Fatal(err)
		}
	}
	// gt
	{
		d := New(dateStorage, createGetShooting(&booking_shooting.Shooting{Duration: null.NewInt(int64(time.Hour+time.Minute), true)}, nil), createGetUserIdsForShooting(make([]int64, 0), nil), createGetUserIdsForDate(make([]int64, 0), nil))
		list, err = d.BookableDatesForShooting(1337)
		if err := AssertThat(err, NilValue()); err != nil {
			t.Fatal(err)
		}
		if err := AssertThat(list, NotNilValue()); err != nil {
			t.Fatal(err)
		}
		if err := AssertThat(len(list), Is(0)); err != nil {
			t.Fatal(err)
		}
	}
	// lt
	{
		d := New(dateStorage, createGetShooting(&booking_shooting.Shooting{Duration: null.NewInt(int64(time.Hour-time.Minute), true)}, nil), createGetUserIdsForShooting(make([]int64, 0), nil), createGetUserIdsForDate(make([]int64, 0), nil))
		list, err = d.BookableDatesForShooting(1337)
		if err := AssertThat(err, NilValue()); err != nil {
			t.Fatal(err)
		}
		if err := AssertThat(list, NotNilValue()); err != nil {
			t.Fatal(err)
		}
		if err := AssertThat(len(list), Is(1)); err != nil {
			t.Fatal(err)
		}
	}

}