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)
	}
}
func TestBookShooting(t *testing.T) {
	updateFunc := func(shooting *booking_shooting.Shooting) (*booking_shooting.Shooting, error) {
		if err := AssertThat(int(shooting.Id), Is(12)); err != nil {
			t.Fatal(err)
		}
		if err := AssertThat(shooting.DateId.Valid, Is(true)); err != nil {
			t.Fatal(err)
		}
		if err := AssertThat(int(shooting.DateId.Int64), Is(13)); err != nil {
			t.Fatal(err)
		}
		return &booking_shooting.Shooting{}, nil
	}
	handler := New(updateFunc, createUpdateShootingUser(nil), createGet(nil, nil), createProtocol())
	resp := server_mock.NewHttpResponseWriterMock()
	req, err := createRequest(`{"id":12,"date_id":13,"user_ids":[1]}`)
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	err = handler.ServeHTTP(resp, req)
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(resp.Status(), Is(200)); err != nil {
		t.Fatal(err)
	}
}
func TestBookShooting(t *testing.T) {
	updateFunc := func(shooting *booking_shooting.Shooting) (*booking_shooting.Shooting, error) {
		if err := AssertThat(int(shooting.Id), Is(12)); err != nil {
			t.Fatal(err)
		}
		if err := AssertThat(shooting.DateId.Valid, Is(true)); err != nil {
			t.Fatal(err)
		}
		if err := AssertThat(int(shooting.DateId.Int64), Is(13)); err != nil {
			t.Fatal(err)
		}
		return nil, nil
	}
	token := "token123"
	handler := New(createHttpRequestToAuthentication(&booking_authentication.Authentication{Token: token}, nil), createGetByToken(nil, nil), updateFunc, createGet(nil, nil), createIsParticipant(false), createProtocol())
	resp := server_mock.NewHttpResponseWriterMock()
	req, err := createRequest(`{"id":12,"date_id":13}`)
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	err = handler.ServeHTTP(resp, req)
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(resp.Status(), Is(200)); err != nil {
		t.Fatal(err)
	}
}
func TestHasRoleReturnFalse(t *testing.T) {
	handler := booking_handler_mock.New()
	r := New(createVerifyLogin(false, nil), createHasRole(false, nil), createHttpRequestToAuthentication(nil, nil), booking_authorization.Administrator, handler)
	if err := AssertThat(r.ServeHTTP(server_mock.NewHttpResponseWriterMock(), &http.Request{}), NotNilValue()); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(handler.Request, NilValue()); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(handler.Response, NilValue()); err != nil {
		t.Fatal(err)
	}
}
func TestDate(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))
	handler := createHandler(db, userService)
	req, err := createRequest("/date", userService)
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	handler.ServeHTTP(resp, req)
	if err := AssertThat(resp.Status(), Is(200)); err != nil {
		t.Fatal(err)
	}
}
func TestHasRoleFailed(t *testing.T) {
	e := fmt.Errorf("myError")
	handler := booking_handler_mock.New()
	r := New(createVerifyLogin(true, nil), createHasRole(true, e), createHttpRequestToAuthentication(nil, nil), booking_authorization.Administrator, handler)
	if err := AssertThat(r.ServeHTTP(server_mock.NewHttpResponseWriterMock(), &http.Request{}), Is(e)); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(handler.Request, NilValue()); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(handler.Response, NilValue()); err != nil {
		t.Fatal(err)
	}
}
func TestVerifyLoginHandlerFound(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))
	_, err := userService.Create(&booking_user.User{Login: "******", Password: "******"})
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	handler := createHandler(db, userService)
	req, err := createRequest("/authentication/verifyLogin", userService)
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	req.Body = ioutil.NopCloser(bytes.NewBufferString(`{"login":"******","password":"******"}`))
	req.Method = "POST"
	handler.ServeHTTP(resp, req)
	if err := AssertThat(resp.Status(), Is(200)); err != nil {
		t.Fatal(err)
	}
}